Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Statements / Confirm.cs / 1305376 / Confirm.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Statements { using System; using System.Collections.Generic; using System.ComponentModel; using System.Runtime; using System.Activities.Validation; using System.Collections.ObjectModel; using System.Linq; using System.Activities.Expressions; public sealed class Confirm : NativeActivity { static Constraint confirmWithNoTarget = Confirm.ConfirmWithNoTarget(); InternalConfirm internalConfirm; DefaultConfirmation defaultConfirmation; VariablecurrentCompensationToken; public Confirm() : base() { this.currentCompensationToken = new Variable (); } public InArgument Target { get; set; } DefaultConfirmation DefaultConfirmation { get { if (this.defaultConfirmation == null) { this.defaultConfirmation = new DefaultConfirmation() { Target = new InArgument (this.currentCompensationToken), }; } return this.defaultConfirmation; } } InternalConfirm InternalConfirm { get { if (this.internalConfirm == null) { this.internalConfirm = new InternalConfirm() { Target = new InArgument (new ArgumentValue { ArgumentName = "Target" }), }; } return this.internalConfirm; } } 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(DefaultConfirmation != null, "DefaultConfirmation must be valid"); Fx.Assert(InternalConfirm != null, "InternalConfirm must be valid"); metadata.SetImplementationChildrenCollection( new Collection { DefaultConfirmation, InternalConfirm }); } internal override IList InternalGetConstraints() { return new List (1) { confirmWithNoTarget }; } static Constraint ConfirmWithNoTarget() { 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.ConfirmWithNoTargetConstraint) } } } } }; } protected override void Execute(NativeActivityContext context) { CompensationExtension compensationExtension = context.GetExtension (); if (compensationExtension == null) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.ConfirmWithoutCompensableActivity(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(DefaultConfirmation); } } else { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.InvalidConfirmActivityUsage(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.ConfirmCalled) { // 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.Confirming; compensationToken.ConfirmCalled = true; context.ScheduleActivity(InternalConfirm); } } 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
- HMACSHA384.cs
- DigestComparer.cs
- ChtmlTextWriter.cs
- SpellCheck.cs
- CodeArrayCreateExpression.cs
- XamlStream.cs
- LoginUtil.cs
- VectorCollectionConverter.cs
- SqlDataRecord.cs
- util.cs
- _CommandStream.cs
- HtmlObjectListAdapter.cs
- TypeListConverter.cs
- StandardRuntimeEnumValidator.cs
- NetCodeGroup.cs
- Tuple.cs
- TemplatedWizardStep.cs
- SoapExtensionTypeElementCollection.cs
- KnownBoxes.cs
- QueryTask.cs
- ZoneIdentityPermission.cs
- WindowsRichEditRange.cs
- LinearKeyFrames.cs
- DbProviderFactoriesConfigurationHandler.cs
- SendSecurityHeaderElement.cs
- TreeViewEvent.cs
- VoiceObjectToken.cs
- DataGridViewHeaderCell.cs
- SecurityPolicySection.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- FontWeight.cs
- TransformCryptoHandle.cs
- EventHandlerList.cs
- SRef.cs
- MenuEventArgs.cs
- SqlNodeAnnotations.cs
- TimeSpanValidatorAttribute.cs
- PageParserFilter.cs
- TabletDeviceInfo.cs
- GradientSpreadMethodValidation.cs
- ErasingStroke.cs
- ResourcePermissionBaseEntry.cs
- AbstractSvcMapFileLoader.cs
- UIElement3DAutomationPeer.cs
- SortableBindingList.cs
- DispatcherEventArgs.cs
- MediaCommands.cs
- TextModifierScope.cs
- RTLAwareMessageBox.cs
- SettingsContext.cs
- OperationInvokerTrace.cs
- ResponseStream.cs
- StringValidatorAttribute.cs
- InstanceLockLostException.cs
- SizeValueSerializer.cs
- ManagementDateTime.cs
- GridItem.cs
- GenericTypeParameterConverter.cs
- APCustomTypeDescriptor.cs
- ClientScriptManager.cs
- CapabilitiesUse.cs
- MdiWindowListStrip.cs
- DynamicActivityProperty.cs
- IWorkflowDebuggerService.cs
- DecimalAnimationBase.cs
- OrderedDictionary.cs
- RawStylusInputCustomData.cs
- UiaCoreTypesApi.cs
- XmlSerializerOperationFormatter.cs
- Menu.cs
- wmiutil.cs
- EntityContainerEntitySet.cs
- VBCodeProvider.cs
- ApplicationInfo.cs
- AncillaryOps.cs
- XPathNodeInfoAtom.cs
- TreeView.cs
- UInt32Converter.cs
- AuthenticationModulesSection.cs
- ProgressBarBrushConverter.cs
- OleDbSchemaGuid.cs
- Dictionary.cs
- WebEventTraceProvider.cs
- SynchronizationContextHelper.cs
- COAUTHINFO.cs
- Material.cs
- TdsEnums.cs
- Point4DConverter.cs
- TextTreeObjectNode.cs
- WindowsAltTab.cs
- SoapCodeExporter.cs
- ImageAutomationPeer.cs
- TrustSection.cs
- ServiceMetadataPublishingElement.cs
- OptimalTextSource.cs
- XmlCharType.cs
- WorkflowDesignerMessageFilter.cs
- StaticFileHandler.cs
- Panel.cs
- ProbeRequestResponseAsyncResult.cs