Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / TransactionBridge / Microsoft / Transactions / Wsat / InputOutput / Completion.cs / 1 / Completion.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- // This file implements completion-related messaging using System; using System.Diagnostics; using System.IdentityModel.Claims; using System.IdentityModel.Policy; using System.ServiceModel; using System.ServiceModel.Channels; using System.Xml; using Microsoft.Transactions.Wsat.InputOutput; using Microsoft.Transactions.Wsat.Messaging; using Microsoft.Transactions.Wsat.Protocol; using Microsoft.Transactions.Wsat.StateMachines; using DiagnosticUtility = Microsoft.Transactions.Bridge.DiagnosticUtility; using Fault = Microsoft.Transactions.Wsat.Messaging.Fault; namespace Microsoft.Transactions.Wsat.InputOutput { class CompletionCoordinator : ICompletionCoordinator { ProtocolState state; AsyncCallback sendComplete; AsyncCallback politeSendComplete; public CompletionCoordinator(ProtocolState state) { this.state = state; this.sendComplete = DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(SendComplete)); this.politeSendComplete = DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(PoliteSendComplete)); } // // ICompletionCoordinator // CompletionEnlistment CheckMessage(Message message, bool reply) { Guid enlistmentId; if (!Ports.TryGetEnlistment(message, out enlistmentId)) { DebugTrace.Trace(TraceLevel.Warning, "Could not read enlistment header from message"); if (reply) this.SendFault(message, this.state.Faults.InvalidParameters); return null; } TransactionEnlistment enlistment = state.Lookup.FindEnlistment(enlistmentId); if (enlistment == null) { DebugTrace.Trace(TraceLevel.Warning, "Could not find enlistment {0}", enlistmentId); if (reply) this.SendFault(message, this.state.Faults.InvalidState); return null; } CompletionEnlistment completion = enlistment as CompletionEnlistment; if (completion == null) { DebugTrace.Trace(TraceLevel.Warning, "Completion message received for non-completion enlistment {0}", enlistmentId); if (reply) this.SendFault(message, this.state.Faults.InvalidParameters); return null; } if (!state.Service.Security.CheckIdentity(completion.ParticipantProxy, message)) { if (EnlistmentIdentityCheckFailedRecord.ShouldTrace) { EnlistmentIdentityCheckFailedRecord.Trace(completion.EnlistmentId); } // no fault reply is sent in order to replicate the security // infrastructure behavior - see MB55336 return null; } return completion; } public void Commit(Message message) { CompletionEnlistment completion = CheckMessage(message, true); if (completion != null) { completion.StateMachine.Enqueue(new MsgCompletionCommitEvent(completion)); } } public void Rollback(Message message) { CompletionEnlistment completion = CheckMessage(message, true); if (completion != null) { completion.StateMachine.Enqueue(new MsgCompletionRollbackEvent(completion)); } } public void Fault(Message message, MessageFault fault) { CompletionEnlistment completion = CheckMessage(message, false); if (completion != null) { state.Perf.FaultsReceivedCountPerInterval.Increment(); } if (DebugTrace.Info) { DebugTrace.Trace(TraceLevel.Info, "Ignoring {0} fault from completion participant at {1}: {2}", Library.GetFaultCodeName(fault), Ports.TryGetFromAddress(message), Library.GetFaultCodeReason(fault)); } } // // Sending messages // void SendComplete(IAsyncResult ar) { if (!ar.CompletedSynchronously) { CompletionEnlistment completion = (CompletionEnlistment) ar.AsyncState; OnSendComplete(ar, completion, completion.ParticipantProxy); } } void PoliteSendComplete(IAsyncResult ar) { if (!ar.CompletedSynchronously) { CompletionParticipantProxy proxy = (CompletionParticipantProxy) ar.AsyncState; OnSendComplete(ar, null, proxy); } } void OnSendComplete(IAsyncResult ar, CompletionEnlistment completion, CompletionParticipantProxy proxy) { try { proxy.EndSendMessage(ar); } catch(WsatSendFailureException e) { DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Warning); state.Perf.MessageSendFailureCountPerInterval.Increment(); if (completion != null) { // Don't bother to enqueue a send failure. The completion state machine doesn't care DebugTrace.TraceSendFailure(completion.EnlistmentId, e); } else { DebugTrace.TraceSendFailure(e); } } } // // Messages // public void SendCommitted(CompletionEnlistment completion) { if (DebugTrace.Info) { DebugTrace.TxTrace( TraceLevel.Info, completion.EnlistmentId, "Sending Committed to completion participant at {0}", Ports.TryGetAddress(completion.ParticipantProxy)); } IAsyncResult ar = completion.ParticipantProxy.BeginSendCommitted(this.sendComplete, completion); if (ar.CompletedSynchronously) { OnSendComplete(ar, completion, completion.ParticipantProxy); } } public void SendCommitted(EndpointAddress sendTo) { if (sendTo != null) { CompletionParticipantProxy proxy = state.TryCreateCompletionParticipantProxy(sendTo); if (proxy != null) { try { if (DebugTrace.Info) { DebugTrace.Trace(TraceLevel.Info, "Sending Committed to unrecognized completion participant at {0}", Ports.TryGetAddress(proxy)); } IAsyncResult ar = proxy.BeginSendCommitted(this.politeSendComplete, proxy); if (ar.CompletedSynchronously) { OnSendComplete(ar, null, proxy); } } finally { proxy.Release(); } } } } public void SendAborted(CompletionEnlistment completion) { if (DebugTrace.Info) { DebugTrace.TxTrace( TraceLevel.Info, completion.EnlistmentId, "Sending Aborted to completion participant at {0}", Ports.TryGetAddress(completion.ParticipantProxy)); } IAsyncResult ar = completion.ParticipantProxy.BeginSendAborted(this.sendComplete, completion); if (ar.CompletedSynchronously) { OnSendComplete(ar, completion, completion.ParticipantProxy); } } public void SendAborted(EndpointAddress sendTo) { if (sendTo != null) { CompletionParticipantProxy proxy = state.TryCreateCompletionParticipantProxy(sendTo); if (proxy != null) { try { if (DebugTrace.Info) { DebugTrace.Trace(TraceLevel.Info, "Sending Aborted to unrecognized completion participant at {0}", Ports.TryGetAddress(proxy)); } IAsyncResult ar = proxy.BeginSendAborted(this.politeSendComplete, proxy); if (ar.CompletedSynchronously) { OnSendComplete(ar, null, proxy); } } finally { proxy.Release(); } } } } void SendFault(Message message, Fault fault) { SendFault(Library.GetFaultToHeader(message.Headers, this.state.ProtocolVersion), message.Headers.MessageId, fault); } public void SendFault(EndpointAddress faultTo, UniqueId messageID, Fault fault) { if (faultTo != null) { state.FaultSender.TrySendCompletionParticipantFault(faultTo, messageID, fault); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ExpressionPrefixAttribute.cs
- ListBox.cs
- BitmapData.cs
- TableLayoutPanelDesigner.cs
- SamlDelegatingWriter.cs
- DirectoryInfo.cs
- PatternMatcher.cs
- WebPartConnectVerb.cs
- DesignerCategoryAttribute.cs
- PrintEvent.cs
- ToolStripItemClickedEventArgs.cs
- ImageSource.cs
- IsolatedStorageException.cs
- InputLanguageManager.cs
- MobileErrorInfo.cs
- Comparer.cs
- HttpStreamMessageEncoderFactory.cs
- ServicesExceptionNotHandledEventArgs.cs
- FilterException.cs
- SqlRemoveConstantOrderBy.cs
- MouseGestureConverter.cs
- MgmtResManager.cs
- HMACRIPEMD160.cs
- SerTrace.cs
- SqlStatistics.cs
- ReadOnlyCollection.cs
- GeneralTransform.cs
- WindowsListViewItemCheckBox.cs
- HoistedLocals.cs
- DoubleCollection.cs
- HttpCacheVary.cs
- StickyNoteContentControl.cs
- HighlightComponent.cs
- MailMessageEventArgs.cs
- NetworkInformationException.cs
- TypeToken.cs
- CircleHotSpot.cs
- StringAnimationUsingKeyFrames.cs
- XamlSerializationHelper.cs
- DictationGrammar.cs
- BindToObject.cs
- OuterGlowBitmapEffect.cs
- Viewport2DVisual3D.cs
- XmlSchemaCollection.cs
- DesignTimeDataBinding.cs
- ArraySegment.cs
- MessageQueueEnumerator.cs
- FixedDSBuilder.cs
- ArrangedElement.cs
- DrawingAttributesDefaultValueFactory.cs
- AttributeInfo.cs
- OpCodes.cs
- TextTrailingWordEllipsis.cs
- WebCategoryAttribute.cs
- HtmlInputButton.cs
- HttpMethodAttribute.cs
- ListenerAdapterBase.cs
- NullReferenceException.cs
- BoundField.cs
- TemplateControlCodeDomTreeGenerator.cs
- Pts.cs
- XsdBuildProvider.cs
- ParallelQuery.cs
- EventProperty.cs
- Wizard.cs
- MultitargetingHelpers.cs
- ByteKeyFrameCollection.cs
- PrintDialog.cs
- StringBuilder.cs
- Parser.cs
- mactripleDES.cs
- StrokeCollection2.cs
- PaintValueEventArgs.cs
- HandleExceptionArgs.cs
- ApplyImportsAction.cs
- LowerCaseStringConverter.cs
- TextEncodedRawTextWriter.cs
- pingexception.cs
- StrokeSerializer.cs
- PeerResolver.cs
- ObjectHandle.cs
- WindowsToolbarItemAsMenuItem.cs
- SiteMapHierarchicalDataSourceView.cs
- Int32RectConverter.cs
- ListView.cs
- DocobjHost.cs
- lengthconverter.cs
- RightsManagementPermission.cs
- AppDomainUnloadedException.cs
- MobileListItem.cs
- RuntimeDelegateArgument.cs
- ResetableIterator.cs
- PropertyEmitter.cs
- MarkedHighlightComponent.cs
- RecordsAffectedEventArgs.cs
- SafeHandle.cs
- ViewValidator.cs
- ComplexTypeEmitter.cs
- MailWebEventProvider.cs
- Point3DAnimation.cs