Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / TransactionBridge / Microsoft / Transactions / Wsat / Messaging / Completion.cs / 1 / Completion.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- // Define the interfaces and infrastructure needed to receive completion messages using System; using System.ServiceModel.Channels; using System.Diagnostics; using System.ServiceModel; using Microsoft.Transactions.Wsat.Protocol; using DiagnosticUtility = Microsoft.Transactions.Bridge.DiagnosticUtility; namespace Microsoft.Transactions.Wsat.Messaging { interface ICompletionCoordinator { void Commit(Message message); void Rollback(Message message); void Fault(Message message, MessageFault messageFault); } interface ICompletionParticipant { void Committed(Message message); void Aborted(Message message); void Fault(Message message, MessageFault messageFault); } //===================================================================================================== // CompletionCoordinatorDispatcher Classes //===================================================================================================== class CompletionCoordinatorDispatcher : DatagramMessageDispatcher { CoordinationService service; ICompletionCoordinator dispatch; public CompletionCoordinatorDispatcher(CoordinationService service, ICompletionCoordinator dispatch) : base(service.ProtocolVersion) { this.service = service; this.dispatch = dispatch; } protected override DatagramProxy CreateFaultProxy (EndpointAddress to) { return this.service.CreateCompletionParticipantProxy(to); } public void Commit(Message message) { try { if (DebugTrace.Verbose) { DebugTrace.Trace(TraceLevel.Verbose, "Dispatching completion Commit message"); if (DebugTrace.Pii) DebugTrace.TracePii(TraceLevel.Verbose, "Sender is {0}", CoordinationServiceSecurity.GetSenderName(message)); } CommitMessage.ReadFrom (message, this.service.ProtocolVersion); this.dispatch.Commit (message); } catch (CommunicationException e) { DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Warning); this.OnMessageException (message, e); } #pragma warning suppress 56500 // Only catch Exception for InvokeFinalHandler catch (Exception e) { DebugTrace.Trace ( TraceLevel.Error, "Unhandled exception {0} dispatching completion Commit message: {1}", e.GetType().Name, e ); // Contractually the dispatch object can only throw CommunicationException. // Our implementation is very careful to only throw this type of exception // (e.g. when deserializing a malformed message body or header...) // Any other exception indicates that things have gone seriously wrong, // so we cannot be trusted to process further messages. This is a QFE-worthy event. DiagnosticUtility.InvokeFinalHandler(e); } } public void Rollback(Message message) { try { if (DebugTrace.Verbose) { DebugTrace.Trace(TraceLevel.Verbose, "Dispatching completion Rollback message"); if (DebugTrace.Pii) DebugTrace.TracePii(TraceLevel.Verbose, "Sender is {0}", CoordinationServiceSecurity.GetSenderName(message)); } RollbackMessage.ReadFrom (message, this.service.ProtocolVersion); this.dispatch.Rollback (message); } catch (CommunicationException e) { DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Warning); this.OnMessageException (message, e); } #pragma warning suppress 56500 // Only catch Exception for InvokeFinalHandler catch (Exception e) { DebugTrace.Trace ( TraceLevel.Error, "Unhandled exception {0} dispatching completion Rollback message: {1}", e.GetType().Name, e ); // Contractually the dispatch object can only throw CommunicationException. // Our implementation is very careful to only throw this type of exception // (e.g. when deserializing a malformed message body or header...) // Any other exception indicates that things have gone seriously wrong, // so we cannot be trusted to process further messages. This is a QFE-worthy event. DiagnosticUtility.InvokeFinalHandler(e); } } public void WsaFault(Message message) { Fault(message); } public void WscoorFault(Message message) { Fault(message); } public void WsatFault(Message message) { Fault(message); } void Fault(Message message) { try { MessageFault fault = MessageFault.CreateFault (message, CoordinationBinding.MaxFaultSize); if (DebugTrace.Verbose) { FaultCode code = Library.GetBaseFaultCode (fault); DebugTrace.Trace(TraceLevel.Verbose, "Dispatching participant completion fault {0}", code == null ? "unknown" : code.Name); if (DebugTrace.Pii) DebugTrace.TracePii(TraceLevel.Verbose, "Sender is {0}", CoordinationServiceSecurity.GetSenderName(message)); } this.dispatch.Fault(message, fault); } catch (CommunicationException e) { DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Warning); this.OnMessageException(message, e); } #pragma warning suppress 56500 // Only catch Exception for InvokeFinalHandler catch (Exception e) { DebugTrace.Trace ( TraceLevel.Error, "Unhandled exception {0} dispatching completion fault from participant: {1}", e.GetType().Name, e ); // Contractually the dispatch object can only throw CommunicationException. // Our implementation is very careful to only throw this type of exception // (e.g. when deserializing a malformed message body or header...) // Any other exception indicates that things have gone seriously wrong, // so we cannot be trusted to process further messages. This is a QFE-worthy event. DiagnosticUtility.InvokeFinalHandler(e); } } public static IWSCompletionCoordinator Instance(CoordinationService service, ICompletionCoordinator dispatch) { ProtocolVersionHelper.AssertProtocolVersion(service.ProtocolVersion, typeof(CompletionCoordinatorDispatcher), "Instance"); //assert valid protocol version switch (service.ProtocolVersion) { case ProtocolVersion.Version10: return new CompletionCoordinatorDispatcher10(service, dispatch); case ProtocolVersion.Version11: return new CompletionCoordinatorDispatcher11(service, dispatch); default: return null; // inaccessible path because we have asserted the protocol version } } } [ServiceBehavior ( InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)] class CompletionCoordinatorDispatcher10 : IWSCompletionCoordinator10 { CompletionCoordinatorDispatcher completionCoordinatorDispatcher; public CompletionCoordinatorDispatcher10(CoordinationService service, ICompletionCoordinator dispatch) { ProtocolVersionHelper.AssertProtocolVersion10(service.ProtocolVersion, typeof(CompletionCoordinatorDispatcher10), "constr"); this.completionCoordinatorDispatcher = new CompletionCoordinatorDispatcher(service, dispatch); } public Type ContractType { get { return typeof(IWSCompletionCoordinator10); } } public void Commit (Message message) { this.completionCoordinatorDispatcher.Commit(message); } public void Rollback (Message message) { this.completionCoordinatorDispatcher.Rollback(message); } public void WsaFault(Message message) { this.completionCoordinatorDispatcher.WsaFault(message); } public void WscoorFault(Message message) { this.completionCoordinatorDispatcher.WscoorFault(message); } public void WsatFault(Message message) { this.completionCoordinatorDispatcher.WsatFault(message); } } [ServiceBehavior ( InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)] class CompletionCoordinatorDispatcher11 : IWSCompletionCoordinator11 { CompletionCoordinatorDispatcher completionCoordinatorDispatcher; public CompletionCoordinatorDispatcher11(CoordinationService service, ICompletionCoordinator dispatch) { ProtocolVersionHelper.AssertProtocolVersion11(service.ProtocolVersion, typeof(CompletionCoordinatorDispatcher11), "constr"); this.completionCoordinatorDispatcher = new CompletionCoordinatorDispatcher(service, dispatch); } public Type ContractType { get { return typeof(IWSCompletionCoordinator11); } } public void Commit (Message message) { this.completionCoordinatorDispatcher.Commit(message); } public void Rollback (Message message) { this.completionCoordinatorDispatcher.Rollback(message); } public void WsaFault(Message message) { this.completionCoordinatorDispatcher.WsaFault(message); } public void WscoorFault(Message message) { this.completionCoordinatorDispatcher.WscoorFault(message); } public void WsatFault(Message message) { this.completionCoordinatorDispatcher.WsatFault(message); } } //====================================================================================================== class CompletionParticipantDispatcher : DatagramMessageDispatcher { CoordinationService service; ICompletionParticipant dispatch; public CompletionParticipantDispatcher (CoordinationService service, ICompletionParticipant dispatch) : base(service.ProtocolVersion) { this.service = service; this.dispatch = dispatch; } protected override DatagramProxy CreateFaultProxy (EndpointAddress to) { return this.service.CreateCompletionCoordinatorProxy (to, null); } public void Committed (Message message) { try { if (DebugTrace.Verbose) { DebugTrace.Trace(TraceLevel.Verbose, "Dispatching completion Committed message"); if (DebugTrace.Pii) DebugTrace.TracePii(TraceLevel.Verbose, "Sender is {0}", CoordinationServiceSecurity.GetSenderName(message)); } CommittedMessage.ReadFrom(message, this.service.ProtocolVersion); this.dispatch.Committed(message); } catch (CommunicationException e) { DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Warning); this.OnMessageException(message, e); } #pragma warning suppress 56500 // Only catch Exception for InvokeFinalHandler catch (Exception e) { DebugTrace.Trace ( TraceLevel.Error, "Unhandled exception {0} dispatching completion Committed message: {1}", e.GetType().Name, e ); // Contractually the dispatch object can only throw CommunicationException. // Our implementation is very careful to only throw this type of exception // (e.g. when deserializing a malformed message body or header...) // Any other exception indicates that things have gone seriously wrong, // so we cannot be trusted to process further messages. This is a QFE-worthy event. DiagnosticUtility.InvokeFinalHandler(e); } } public void Aborted(Message message) { try { if (DebugTrace.Verbose) { DebugTrace.Trace(TraceLevel.Verbose, "Dispatching completion Aborted message"); if (DebugTrace.Pii) DebugTrace.TracePii(TraceLevel.Verbose, "Sender is {0}", CoordinationServiceSecurity.GetSenderName(message)); } AbortedMessage.ReadFrom (message, this.service.ProtocolVersion); this.dispatch.Aborted(message); } catch (CommunicationException e) { DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Warning); this.OnMessageException (message, e); } #pragma warning suppress 56500 // Only catch Exception for InvokeFinalHandler catch (Exception e) { DebugTrace.Trace ( TraceLevel.Error, "Unhandled exception {0} dispatching completion Aborted message: {1}", e.GetType().Name, e ); // Contractually the dispatch object can only throw CommunicationException. // Our implementation is very careful to only throw this type of exception // (e.g. when deserializing a malformed message body or header...) // Any other exception indicates that things have gone seriously wrong, // so we cannot be trusted to process further messages. This is a QFE-worthy event. DiagnosticUtility.InvokeFinalHandler (e); } } public void WsaFault(Message message) { Fault(message); } public void WscoorFault(Message message) { Fault(message); } public void WsatFault(Message message) { Fault(message); } void Fault(Message message) { try { MessageFault fault = MessageFault.CreateFault(message, CoordinationBinding.MaxFaultSize); if (DebugTrace.Verbose) { FaultCode code = Library.GetBaseFaultCode(fault); DebugTrace.Trace(TraceLevel.Verbose, "Dispatching coordinator completion fault {0}", code == null ? "unknown" : code.Name); if (DebugTrace.Pii) DebugTrace.TracePii(TraceLevel.Verbose, "Sender is {0}", CoordinationServiceSecurity.GetSenderName(message)); } this.dispatch.Fault(message, fault); } catch (CommunicationException e) { DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Warning); this.OnMessageException(message, e); } #pragma warning suppress 56500 // Only catch Exception for InvokeFinalHandler catch (Exception e) { DebugTrace.Trace ( TraceLevel.Error, "Unhandled exception {0} dispatching completion fault from coordinator: {1}", e.GetType().Name, e ); // Contractually the dispatch object can only throw CommunicationException. // Our implementation is very careful to only throw this type of exception // (e.g. when deserializing a malformed message body or header...) // Any other exception indicates that things have gone seriously wrong, // so we cannot be trusted to process further messages. This is a QFE-worthy event. DiagnosticUtility.InvokeFinalHandler(e); } } public static IWSCompletionParticipant Instance(CoordinationService service, ICompletionParticipant dispatch) { ProtocolVersionHelper.AssertProtocolVersion(service.ProtocolVersion, typeof(CompletionParticipantDispatcher), "Instance"); //assert valid protocol version switch (service.ProtocolVersion) { case ProtocolVersion.Version10: return new CompletionParticipantDispatcher10(service, dispatch); case ProtocolVersion.Version11: return new CompletionParticipantDispatcher11(service, dispatch); default: return null; //inaccessible path because we have asserted the protocol version } } } [ServiceBehavior ( InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)] class CompletionParticipantDispatcher10 : IWSCompletionParticipant10 { CompletionParticipantDispatcher completionParticipantDispatcher; public CompletionParticipantDispatcher10(CoordinationService service, ICompletionParticipant dispatch) { ProtocolVersionHelper.AssertProtocolVersion10(service.ProtocolVersion, typeof(CompletionParticipantDispatcher10), "constr"); this.completionParticipantDispatcher = new CompletionParticipantDispatcher(service, dispatch); } public Type ContractType { get { return typeof(IWSCompletionParticipant10); } } public void Committed (Message message) { this.completionParticipantDispatcher.Committed(message); } public void Aborted(Message message) { this.completionParticipantDispatcher.Aborted(message); } public void WsaFault(Message message) { this.completionParticipantDispatcher.WsaFault(message); } public void WscoorFault(Message message) { this.completionParticipantDispatcher.WscoorFault(message); } public void WsatFault(Message message) { this.completionParticipantDispatcher.WsatFault(message); } } [ServiceBehavior ( InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)] class CompletionParticipantDispatcher11 : IWSCompletionParticipant11 { CompletionParticipantDispatcher completionParticipantDispatcher; public CompletionParticipantDispatcher11(CoordinationService service, ICompletionParticipant dispatch) { ProtocolVersionHelper.AssertProtocolVersion11(service.ProtocolVersion, typeof(CompletionParticipantDispatcher11), "constr"); this.completionParticipantDispatcher = new CompletionParticipantDispatcher(service, dispatch); } public Type ContractType { get { return typeof(IWSCompletionParticipant11); } } public void Committed (Message message) { this.completionParticipantDispatcher.Committed(message); } public void Aborted(Message message) { this.completionParticipantDispatcher.Aborted(message); } public void WsaFault(Message message) { this.completionParticipantDispatcher.WsaFault(message); } public void WscoorFault(Message message) { this.completionParticipantDispatcher.WscoorFault(message); } public void WsatFault(Message message) { this.completionParticipantDispatcher.WsatFault(message); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataGridState.cs
- XmlWriterTraceListener.cs
- OverflowException.cs
- Deflater.cs
- DeferrableContent.cs
- FloaterParaClient.cs
- Script.cs
- ObjectResult.cs
- ParserStreamGeometryContext.cs
- SqlRowUpdatingEvent.cs
- IItemContainerGenerator.cs
- TemplateControlCodeDomTreeGenerator.cs
- DiscoveryExceptionDictionary.cs
- TemplateParser.cs
- MatrixAnimationUsingKeyFrames.cs
- CachedPathData.cs
- PagesSection.cs
- DetailsViewDeletedEventArgs.cs
- StorageInfo.cs
- Imaging.cs
- XmlRawWriterWrapper.cs
- COM2IVsPerPropertyBrowsingHandler.cs
- UnsafeNativeMethods.cs
- TreeNodeEventArgs.cs
- XmlWriter.cs
- VerticalAlignConverter.cs
- AssemblyResourceLoader.cs
- WebPartEventArgs.cs
- SmtpSection.cs
- SimpleWorkerRequest.cs
- ToolboxItem.cs
- ToolStripDesignerUtils.cs
- DataColumnPropertyDescriptor.cs
- LinearGradientBrush.cs
- MetadataCache.cs
- XmlLanguageConverter.cs
- HttpContext.cs
- InputScopeNameConverter.cs
- SelectionEditingBehavior.cs
- SettingsBindableAttribute.cs
- RegionData.cs
- CommentEmitter.cs
- WebBrowserContainer.cs
- PasswordRecovery.cs
- StringConcat.cs
- ExpressionWriter.cs
- BufferBuilder.cs
- DeviceSpecificChoiceCollection.cs
- XamlTypeMapper.cs
- CommonGetThemePartSize.cs
- StringExpressionSet.cs
- IssuanceLicense.cs
- Trace.cs
- MessageAction.cs
- GridViewColumnHeader.cs
- RtType.cs
- IsolatedStoragePermission.cs
- TripleDESCryptoServiceProvider.cs
- PopOutPanel.cs
- ValidationHelper.cs
- InstanceLockedException.cs
- DataViewManager.cs
- XXXOnTypeBuilderInstantiation.cs
- RenderContext.cs
- SessionPageStatePersister.cs
- PinnedBufferMemoryStream.cs
- MemoryStream.cs
- RijndaelManagedTransform.cs
- BatchWriter.cs
- AmbientLight.cs
- AlphaSortedEnumConverter.cs
- TextTrailingWordEllipsis.cs
- ConnectionPoint.cs
- DataTableCollection.cs
- OpenTypeMethods.cs
- ObjectParameterCollection.cs
- Crc32.cs
- TargetConverter.cs
- DefaultValueAttribute.cs
- KnownTypes.cs
- MessageContractExporter.cs
- MultiView.cs
- SystemFonts.cs
- PlaceHolder.cs
- XmlCollation.cs
- CollaborationHelperFunctions.cs
- RepeaterItemCollection.cs
- MonthCalendar.cs
- XmlSchemaAttributeGroup.cs
- NetworkInterface.cs
- ResourceDictionary.cs
- InternalDuplexBindingElement.cs
- TextTreePropertyUndoUnit.cs
- HwndSource.cs
- XamlUtilities.cs
- DrawingGroup.cs
- CodeTypeDeclaration.cs
- Win32.cs
- TableLayoutColumnStyleCollection.cs
- SystemParameters.cs