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
- RSAPKCS1SignatureFormatter.cs
- IssuedTokenServiceElement.cs
- PathFigureCollection.cs
- X509DefaultServiceCertificateElement.cs
- SQLDateTime.cs
- DataGridViewCellValidatingEventArgs.cs
- ValidationHelper.cs
- SafeNativeMethods.cs
- DbConnectionHelper.cs
- ProviderConnectionPointCollection.cs
- OrderPreservingPipeliningMergeHelper.cs
- DataColumnMapping.cs
- PolyBezierSegment.cs
- ReadOnlyCollection.cs
- RecognizedPhrase.cs
- InternalBufferOverflowException.cs
- BitmapEncoder.cs
- ObjRef.cs
- ListDictionaryInternal.cs
- SendSecurityHeader.cs
- FixedDocumentSequencePaginator.cs
- XmlSchemaCompilationSettings.cs
- HtmlInputButton.cs
- MetadataHelper.cs
- DataList.cs
- IsolatedStorage.cs
- Models.cs
- NotifyIcon.cs
- WindowsMenu.cs
- TextInfo.cs
- LightweightCodeGenerator.cs
- UnsafeNativeMethodsCLR.cs
- WSSecurityPolicy.cs
- MatrixUtil.cs
- WindowInteropHelper.cs
- TemporaryBitmapFile.cs
- ColumnPropertiesGroup.cs
- UrlPath.cs
- SerializationAttributes.cs
- ClientSideQueueItem.cs
- CodeDOMUtility.cs
- ADMembershipProvider.cs
- XmlSchemaAppInfo.cs
- PointConverter.cs
- TraceData.cs
- SystemPens.cs
- MasterPage.cs
- ConfigurationElement.cs
- HtmlInputButton.cs
- ZipIOCentralDirectoryBlock.cs
- ToolZoneDesigner.cs
- DataControlImageButton.cs
- Image.cs
- ParameterReplacerVisitor.cs
- DataTableCollection.cs
- DataExpression.cs
- ErrorLog.cs
- EntityReference.cs
- WindowsSpinner.cs
- SizeAnimationUsingKeyFrames.cs
- CodeCatchClause.cs
- WeakReferenceList.cs
- ThicknessConverter.cs
- CatchDesigner.xaml.cs
- CodePropertyReferenceExpression.cs
- FileUtil.cs
- IList.cs
- ObjectViewQueryResultData.cs
- SiteMap.cs
- Certificate.cs
- ResourcePart.cs
- EncryptedType.cs
- DataGridViewCellStyleEditor.cs
- InfocardClientCredentials.cs
- AttachedPropertyDescriptor.cs
- HtmlControlPersistable.cs
- FunctionUpdateCommand.cs
- XmlNamespaceMapping.cs
- ToolboxSnapDragDropEventArgs.cs
- ConstraintCollection.cs
- InternalUserCancelledException.cs
- StylusPointCollection.cs
- FieldCollectionEditor.cs
- MimeXmlReflector.cs
- OdbcErrorCollection.cs
- VectorKeyFrameCollection.cs
- HealthMonitoringSectionHelper.cs
- XsdBuildProvider.cs
- _ShellExpression.cs
- DBBindings.cs
- PartialCachingAttribute.cs
- CodeAccessPermission.cs
- TextEncodedRawTextWriter.cs
- SqlRecordBuffer.cs
- Registry.cs
- CapabilitiesRule.cs
- OleDbDataReader.cs
- SymmetricAlgorithm.cs
- CheckBoxFlatAdapter.cs
- DropShadowBitmapEffect.cs