Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Statements / Compensate.cs / 1305376 / Compensate.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Statements { using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Runtime; using System.Activities.Validation; using System.Linq; using System.Activities.Expressions; public sealed class Compensate : NativeActivity { static Constraint compensateWithNoTarget = Compensate.CompensateWithNoTarget(); InternalCompensate internalCompensate; DefaultCompensation defaultCompensation; VariablecurrentCompensationToken; public Compensate() : base() { this.currentCompensationToken = new Variable (); } [DefaultValue(null)] public InArgument Target { get; set; } DefaultCompensation DefaultCompensation { get { if (this.defaultCompensation == null) { this.defaultCompensation = new DefaultCompensation() { Target = new InArgument (this.currentCompensationToken), }; } return this.defaultCompensation; } } InternalCompensate InternalCompensate { get { if (this.internalCompensate == null) { this.internalCompensate = new InternalCompensate() { Target = new InArgument (new ArgumentValue { ArgumentName = "Target" }), }; } return this.internalCompensate; } } protected override void CacheMetadata(NativeActivityMetadata metadata) { RuntimeArgument targetArgument = new RuntimeArgument("Target", typeof(CompensationToken), ArgumentDirection.In); metadata.Bind(this.Target, targetArgument); metadata.SetArgumentsCollection(new Collection { targetArgument }); metadata.SetImplementationVariablesCollection(new Collection { this.currentCompensationToken }); Fx.Assert(DefaultCompensation != null, "DefaultCompensation must be valid"); Fx.Assert(InternalCompensate != null, "InternalCompensate must be valid"); metadata.SetImplementationChildrenCollection( new Collection { DefaultCompensation, InternalCompensate }); } internal override IList InternalGetConstraints() { return new List (1) { compensateWithNoTarget }; } static Constraint CompensateWithNoTarget() { DelegateInArgument element = new DelegateInArgument { Name = "element" }; DelegateInArgument validationContext = new DelegateInArgument { Name = "validationContext" }; Variable assertFlag = new Variable { Name = "assertFlag" }; Variable > elements = new Variable >() { Name = "elements" }; Variable index = new Variable () { Name = "index" }; return new Constraint { Body = new ActivityAction { Argument1 = element, Argument2 = validationContext, Handler = new Sequence { Variables = { assertFlag, elements, index }, Activities = { new If { Condition = new InArgument ((env)=>element.Get(env).Target != null), Then = new Assign { To = assertFlag, Value = true }, Else = new Sequence { Activities = { new Assign > { To = elements, Value = new GetParentChain { ValidationContext = validationContext, }, }, new While(env => (assertFlag.Get(env)!=true) && index.Get(env) < elements.Get(env).Count()) { Body = new Sequence { Activities = { new If(env => (elements.Get(env).ElementAt(index.Get(env))).GetType() == typeof(CompensationParticipant)) { Then = new Assign { To = assertFlag, Value = true }, }, new Assign { To=index, Value=new InArgument (env => index.Get(env)+1) }, } } } } } }, new AssertValidation { Assertion = new InArgument (assertFlag), Message = new InArgument (SR.CompensateWithNoTargetConstraint) } } } } }; } protected override void Execute(NativeActivityContext context) { CompensationExtension compensationExtension = context.GetExtension (); if (compensationExtension == null) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.CompensateWithoutCompensableActivity(this.DisplayName))); } if (Target.IsEmpty) { CompensationToken ambientCompensationToken = (CompensationToken)context.Properties.Find(CompensationToken.PropertyName); CompensationTokenData ambientTokenData = ambientCompensationToken == null ? null : compensationExtension.Get(ambientCompensationToken.CompensationId); if (ambientTokenData != null && ambientTokenData.IsTokenValidInSecondaryRoot) { this.currentCompensationToken.Set(context, ambientCompensationToken); if (ambientTokenData.ExecutionTracker.Count > 0) { context.ScheduleActivity(DefaultCompensation); } } else { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.InvalidCompensateActivityUsage(this.DisplayName))); } } else { CompensationToken compensationToken = Target.Get(context); CompensationTokenData tokenData = compensationToken == null ? null : compensationExtension.Get(compensationToken.CompensationId); if (compensationToken == null) { throw FxTrace.Exception.Argument("Target", SR.InvalidCompensationToken(this.DisplayName)); } if (compensationToken.CompensateCalled) { // No-Op return; } if (tokenData == null || tokenData.CompensationState != CompensationState.Completed) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.CompensableActivityAlreadyConfirmedOrCompensated)); } // A valid in-arg was passed... tokenData.CompensationState = CompensationState.Compensating; compensationToken.CompensateCalled = true; context.ScheduleActivity(InternalCompensate); } } protected override void Cancel(NativeActivityContext context) { // Suppress Cancel } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ContentPlaceHolder.cs
- TextDecorationLocationValidation.cs
- BinaryExpression.cs
- RSACryptoServiceProvider.cs
- TransactionInterop.cs
- PointAnimation.cs
- WebBrowserUriTypeConverter.cs
- StringFunctions.cs
- OpacityConverter.cs
- BinaryUtilClasses.cs
- XmlSchemaValidator.cs
- SqlCacheDependencyDatabase.cs
- ContainerActivationHelper.cs
- PKCS1MaskGenerationMethod.cs
- ContextMenuAutomationPeer.cs
- COM2PictureConverter.cs
- ScriptRegistrationManager.cs
- SimpleLine.cs
- PointLight.cs
- COM2ExtendedTypeConverter.cs
- PeerContact.cs
- Debugger.cs
- DispatchChannelSink.cs
- Vector3D.cs
- JulianCalendar.cs
- PropertyChangingEventArgs.cs
- ExtentCqlBlock.cs
- Invariant.cs
- PointIndependentAnimationStorage.cs
- XmlNodeChangedEventManager.cs
- CacheVirtualItemsEvent.cs
- CustomLineCap.cs
- IncomingWebResponseContext.cs
- Serializer.cs
- DataServiceException.cs
- Timer.cs
- PriorityBindingExpression.cs
- ProcessStartInfo.cs
- ExpressionEditorAttribute.cs
- CallInfo.cs
- InstallerTypeAttribute.cs
- XamlStyleSerializer.cs
- TableStyle.cs
- TypedTableGenerator.cs
- ManagementPath.cs
- SimpleFileLog.cs
- XamlTemplateSerializer.cs
- ExtractedStateEntry.cs
- FreezableDefaultValueFactory.cs
- LocationReferenceEnvironment.cs
- RoleBoolean.cs
- BindingNavigator.cs
- DataList.cs
- TemplateKeyConverter.cs
- BitStack.cs
- ValueType.cs
- MappingItemCollection.cs
- Span.cs
- RepeatButtonAutomationPeer.cs
- ExternalDataExchangeService.cs
- SchemaDeclBase.cs
- WebServiceReceive.cs
- EntityProviderServices.cs
- WizardPanel.cs
- ObjectHandle.cs
- ToolStripLocationCancelEventArgs.cs
- BitmapEffectDrawingContextWalker.cs
- CharAnimationBase.cs
- VerticalAlignConverter.cs
- NonVisualControlAttribute.cs
- IDQuery.cs
- MetadataArtifactLoaderCompositeResource.cs
- RouteUrlExpressionBuilder.cs
- PropertyEmitterBase.cs
- ManualResetEvent.cs
- DataDocumentXPathNavigator.cs
- ProfessionalColors.cs
- EntityWithKeyStrategy.cs
- ControlPersister.cs
- EllipseGeometry.cs
- DefaultEventAttribute.cs
- FreeFormPanel.cs
- RepeaterItemEventArgs.cs
- FormsAuthenticationUserCollection.cs
- DictionaryChange.cs
- HMACRIPEMD160.cs
- InvalidCommandTreeException.cs
- OdbcDataAdapter.cs
- AxisAngleRotation3D.cs
- UInt32Converter.cs
- Bidi.cs
- Int16.cs
- TableLayoutStyle.cs
- ErrorRuntimeConfig.cs
- DataGridSortCommandEventArgs.cs
- Quad.cs
- SynchronizationScope.cs
- XComponentModel.cs
- GeneralTransformGroup.cs
- HashMembershipCondition.cs