Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / TransactionBridge / Microsoft / Transactions / Wsat / StateMachines / StateMachine.cs / 1 / StateMachine.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
// This file contains definitions and default implementations for the various
// state machines in the protocol provider
using System;
using System.Collections;
using System.Diagnostics;
using System.Text;
using Microsoft.Transactions.Bridge;
using Microsoft.Transactions.Wsat.InputOutput;
using Microsoft.Transactions.Wsat.Messaging;
using Microsoft.Transactions.Wsat.Protocol;
namespace Microsoft.Transactions.Wsat.StateMachines
{
abstract partial class StateMachine : ITimerRecipient
{
protected TransactionEnlistment enlistment;
protected ProtocolState state;
protected SynchronizationManager synchronization;
State current;
StateMachineHistory history;
protected StateMachine(TransactionEnlistment enlistment)
{
this.enlistment = enlistment;
this.state = enlistment.State;
this.synchronization = new SynchronizationManager(this);
if (DebugTrace.Warning || DiagnosticUtility.ShouldTraceWarning)
{
this.history = new StateMachineHistory();
}
}
public override string ToString()
{
return this.GetType().Name;
}
public State State
{
get { return this.current; }
}
public abstract State AbortedState
{
get;
}
public TransactionEnlistment Enlistment
{
get { return this.enlistment; }
}
public StateMachineHistory History
{
get { return this.history; }
}
public Guid UniqueId
{
get { return this.enlistment.EnlistmentId; }
}
public void Enqueue (SynchronizationEvent e)
{
this.synchronization.Enqueue (e);
}
public void Dispatch (SynchronizationEvent e)
{
if (this.history != null)
{
this.history.AddEvent (e.ToString());
}
e.Execute(this);
}
public void ChangeState (State newState)
{
if (this.history != null)
{
this.history.AddState (newState.ToString());
}
// Deliver leave event
if (this.current != null)
{
if (DebugTrace.Info)
{
DebugTrace.TxTrace(TraceLevel.Info, this.enlistment.EnlistmentId, "Leaving [{0}]", this.current);
}
this.current.Leave (this);
}
if (DebugTrace.Info)
{
DebugTrace.TxTrace (TraceLevel.Info, this.enlistment.EnlistmentId, "Entering [{0}]", newState);
}
// Set current state
this.current = newState;
// Deliver enter event
this.current.Enter (this);
}
public void TraceInvalidEvent (SynchronizationEvent e, bool fatal)
{
// Debug tracing
if (DebugTrace.Error)
{
if (this.history != null)
{
DebugTrace.TxTrace (
TraceLevel.Error,
e.Enlistment.EnlistmentId,
"The {0} was not expected by the {1} state. The state machine history history follows:\n\n{2}",
e, this.current, this.history.ToString()
);
}
else
{
DebugTrace.TxTrace (
TraceLevel.Error,
e.Enlistment.EnlistmentId,
"The {0} was not expected by the {1} state",
e, this.current
);
}
}
// Diagnostic tracing
if (fatal)
{
FatalUnexpectedStateMachineEventRecord.TraceAndLog (
this.enlistment.EnlistmentId,
this.enlistment.Enlistment.RemoteTransactionId,
this.ToString(),
this.current.ToString(),
this.history,
e.ToString(),
null
// It would have been nice to have added context-sensitive details here.
// Maybe next time... See MB 19006 for more details
);
}
else
{
NonFatalUnexpectedStateMachineEventRecord.TraceAndLog (
this.enlistment.EnlistmentId,
this.enlistment.Enlistment.RemoteTransactionId,
this.ToString(),
this.current.ToString(),
this.history,
e.ToString(),
null
// It would have been nice to have added context-sensitive details here.
// Maybe next time... See MB 19006 for more details
);
}
}
public virtual void Cleanup()
{
this.enlistment.OnStateMachineComplete();
}
}
abstract class ParticipantStateMachine : StateMachine
{
ParticipantEnlistment participant;
public ParticipantStateMachine (ParticipantEnlistment participant) : base (participant)
{
this.participant = participant;
}
protected override void OnTimer(TimerProfile profile)
{
base.OnTimer(profile);
this.synchronization.Enqueue(new TimerParticipantEvent(participant, profile));
}
}
class DurableStateMachine : ParticipantStateMachine
{
public DurableStateMachine (ParticipantEnlistment participant) : base (participant) {}
public override State AbortedState
{
get { return state.States.DurableAborted; }
}
}
class VolatileStateMachine : ParticipantStateMachine
{
public VolatileStateMachine (ParticipantEnlistment participant) : base (participant) {}
public override State AbortedState
{
get { return state.States.VolatileAborted; }
}
}
class SubordinateStateMachine : StateMachine
{
public SubordinateStateMachine(ParticipantEnlistment participant) : base(participant) { }
public override State AbortedState
{
get { return state.States.SubordinateFinished; }
}
}
class CompletionStateMachine : StateMachine
{
public CompletionStateMachine (CompletionEnlistment completion) : base (completion) { }
public override State AbortedState
{
get { return state.States.CompletionAborted; }
}
}
class CoordinatorStateMachine : StateMachine
{
CoordinatorEnlistment coordinator;
public CoordinatorStateMachine (CoordinatorEnlistment coordinator) : base (coordinator)
{
this.coordinator = coordinator;
}
public override State AbortedState
{
get { return state.States.CoordinatorAborted; }
}
protected override void OnTimer(TimerProfile profile)
{
base.OnTimer(profile);
this.synchronization.Enqueue (new TimerCoordinatorEvent (this.coordinator, profile));
}
}
class TransactionContextStateMachine : StateMachine
{
TransactionContextManager contextManager;
public TransactionContextStateMachine(TransactionContextManager contextManager)
:
base(contextManager)
{
this.contextManager = contextManager;
}
public override State AbortedState
{
get { return state.States.TransactionContextFinished; }
}
public TransactionContextManager ContextManager
{
get { return this.contextManager; }
}
}
}
// 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
- Profiler.cs
- VisualTarget.cs
- SvcMapFile.cs
- DataGridState.cs
- DPAPIProtectedConfigurationProvider.cs
- EditingCommands.cs
- Hex.cs
- FormViewPageEventArgs.cs
- MetadataArtifactLoaderCompositeResource.cs
- WebPartEditorOkVerb.cs
- Border.cs
- TraceListeners.cs
- Grid.cs
- AudioLevelUpdatedEventArgs.cs
- ScaleTransform3D.cs
- ElementMarkupObject.cs
- LocalizedNameDescriptionPair.cs
- FormViewDeletedEventArgs.cs
- TextLine.cs
- PointLightBase.cs
- ZipIOFileItemStream.cs
- MobileListItem.cs
- WebPartVerbCollection.cs
- ImpersonateTokenRef.cs
- InvokeHandlers.cs
- CommandLibraryHelper.cs
- Int16Converter.cs
- QilList.cs
- AsyncOperation.cs
- WebResponse.cs
- UIElement3D.cs
- COAUTHIDENTITY.cs
- AccessControlEntry.cs
- SqlProvider.cs
- Debug.cs
- Configuration.cs
- AttributeQuery.cs
- CallbackValidatorAttribute.cs
- PageRanges.cs
- SelectionPatternIdentifiers.cs
- ProfileModule.cs
- FlowPosition.cs
- SpeechAudioFormatInfo.cs
- WCFBuildProvider.cs
- SqlClientWrapperSmiStreamChars.cs
- SqlInternalConnectionTds.cs
- HostingEnvironmentException.cs
- ErrorEventArgs.cs
- ListViewDeletedEventArgs.cs
- ExpressionBuilderCollection.cs
- XmlObjectSerializerWriteContextComplex.cs
- UnknownExceptionActionHelper.cs
- LinkedResourceCollection.cs
- CatalogPartDesigner.cs
- LongCountAggregationOperator.cs
- SocketInformation.cs
- Size3DConverter.cs
- SafeNativeMethods.cs
- Keywords.cs
- ThreadStartException.cs
- VarInfo.cs
- ListBindingHelper.cs
- BindingNavigator.cs
- ItemCheckedEvent.cs
- MessageQueuePermissionAttribute.cs
- DataServiceProviderMethods.cs
- DBSqlParserTable.cs
- PiiTraceSource.cs
- DrawingAttributes.cs
- UpdatePanelTrigger.cs
- DataPager.cs
- Pen.cs
- InputProcessorProfiles.cs
- XmlAnyAttributeAttribute.cs
- MachineSettingsSection.cs
- ObjectQueryExecutionPlan.cs
- LocalizableResourceBuilder.cs
- WebEventCodes.cs
- DateTimeStorage.cs
- DetailsViewDeleteEventArgs.cs
- x509utils.cs
- WindowsAuthenticationEventArgs.cs
- CalendarDay.cs
- ObjectConverter.cs
- PrintingPermissionAttribute.cs
- ListViewCancelEventArgs.cs
- CharEntityEncoderFallback.cs
- ViewGenerator.cs
- XmlSchemaObject.cs
- TaiwanLunisolarCalendar.cs
- SocketSettings.cs
- SettingsBindableAttribute.cs
- ChildrenQuery.cs
- DeferredReference.cs
- WindowsListBox.cs
- StrokeNode.cs
- ReadOnlyDictionary.cs
- WebPartTransformerCollection.cs
- WrappedIUnknown.cs
- ProfileBuildProvider.cs