Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Statements / ForEach.cs / 1305376 / ForEach.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.Statements { using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Runtime; using System.Runtime.Serialization; using System.Windows.Markup; using System.Activities; using System.Activities.Validation; [ContentProperty("Body")] public sealed class ForEach: NativeActivity { Variable > valueEnumerator; CompletionCallback onChildComplete; public ForEach() : base() { this.valueEnumerator = new Variable >(); } [DefaultValue(null)] public ActivityAction Body { get; set; } [RequiredArgument] [DefaultValue(null)] public InArgument > Values { get; set; } CompletionCallback OnChildComplete { get { if (this.onChildComplete == null) { this.onChildComplete = new CompletionCallback(GetStateAndExecute); } return this.onChildComplete; } } protected override void CacheMetadata(NativeActivityMetadata metadata) { RuntimeArgument valuesArgument = new RuntimeArgument("Values", typeof(IEnumerable ), ArgumentDirection.In, true); metadata.Bind(this.Values, valuesArgument); metadata.AddArgument(valuesArgument); metadata.AddDelegate(this.Body); metadata.AddImplementationVariable(this.valueEnumerator); } protected override void Execute(NativeActivityContext context) { IEnumerable values = this.Values.Get(context); if (values == null) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.ForEachRequiresNonNullValues(this.DisplayName))); } IEnumerator valueEnumerator = values.GetEnumerator(); this.valueEnumerator.Set(context, valueEnumerator); if (this.Body == null || this.Body.Handler == null) { while (valueEnumerator.MoveNext()) { // do nothing }; valueEnumerator.Dispose(); return; } InternalExecute(context, null, valueEnumerator); } void GetStateAndExecute(NativeActivityContext context, ActivityInstance completedInstance) { IEnumerator valueEnumerator = this.valueEnumerator.Get(context); Fx.Assert(valueEnumerator != null, "GetStateAndExecute"); InternalExecute(context, completedInstance, valueEnumerator); } void InternalExecute(NativeActivityContext context, ActivityInstance completedInstance, IEnumerator valueEnumerator) { Fx.Assert(this.Body != null && this.Body.Handler != null, "Body and Body.Handler should not be null"); if (!valueEnumerator.MoveNext()) { if (completedInstance != null) { if (completedInstance.State == ActivityInstanceState.Canceled || (context.IsCancellationRequested && completedInstance.State == ActivityInstanceState.Faulted)) { context.MarkCanceled(); } } valueEnumerator.Dispose(); return; } // After making sure there is another value, let's check for cancelation if (context.IsCancellationRequested) { context.MarkCanceled(); valueEnumerator.Dispose(); return; } context.ScheduleAction(this.Body, valueEnumerator.Current, this.OnChildComplete); } } } // 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
- OperandQuery.cs
- XamlValidatingReader.cs
- FunctionMappingTranslator.cs
- UriTemplateMatchException.cs
- TreeViewBindingsEditor.cs
- SimpleNameService.cs
- GradientStop.cs
- BooleanAnimationBase.cs
- DateTimeParse.cs
- Storyboard.cs
- SpellerStatusTable.cs
- ObjectHelper.cs
- ColorConverter.cs
- PathParser.cs
- FlowLayoutPanel.cs
- ProfilePropertySettingsCollection.cs
- EdmRelationshipRoleAttribute.cs
- ActivityExecutor.cs
- TextProperties.cs
- WebBrowserNavigatingEventHandler.cs
- XmlDataLoader.cs
- FontSizeConverter.cs
- SiteMapNodeItemEventArgs.cs
- InstanceCreationEditor.cs
- WmlPageAdapter.cs
- XmlAnyElementAttribute.cs
- CodeAttributeArgument.cs
- ComponentEvent.cs
- PeerOutputChannel.cs
- MetaModel.cs
- PackageStore.cs
- PenThreadWorker.cs
- Rijndael.cs
- ListViewSortEventArgs.cs
- QilPatternFactory.cs
- CompositeDispatchFormatter.cs
- ToolStripManager.cs
- LockCookie.cs
- UserControlCodeDomTreeGenerator.cs
- ReferenceEqualityComparer.cs
- DataBoundControl.cs
- SqlDataSourceFilteringEventArgs.cs
- LinkConverter.cs
- OdbcConnectionStringbuilder.cs
- SqlDataSourceQueryConverter.cs
- DoubleIndependentAnimationStorage.cs
- StateMachineWorkflowDesigner.cs
- PenLineJoinValidation.cs
- DictionaryEntry.cs
- JsonReaderDelegator.cs
- StyleSheetDesigner.cs
- UnsafeNativeMethods.cs
- _NtlmClient.cs
- TypedOperationInfo.cs
- KeysConverter.cs
- PositiveTimeSpanValidator.cs
- OdbcErrorCollection.cs
- ResourcesBuildProvider.cs
- IriParsingElement.cs
- CheckPair.cs
- MessageBuffer.cs
- PackWebRequest.cs
- Table.cs
- GridViewUpdateEventArgs.cs
- NegotiationTokenAuthenticatorState.cs
- IntersectQueryOperator.cs
- SecurityPermission.cs
- InvalidChannelBindingException.cs
- ConditionalAttribute.cs
- Rfc2898DeriveBytes.cs
- IssuedTokenParametersElement.cs
- DispatchWrapper.cs
- TextUtf8RawTextWriter.cs
- EventEntry.cs
- RegexCapture.cs
- StorageInfo.cs
- URLMembershipCondition.cs
- ReachSerializableProperties.cs
- HandlerBase.cs
- SQLMembershipProvider.cs
- WindowsListView.cs
- EncoderExceptionFallback.cs
- QueryableFilterUserControl.cs
- FormClosedEvent.cs
- ImageListStreamer.cs
- HybridObjectCache.cs
- SelectionHighlightInfo.cs
- Selector.cs
- StringInfo.cs
- MediaCommands.cs
- ChildTable.cs
- SimplePropertyEntry.cs
- LogicalExpressionEditor.cs
- DataGridViewRowConverter.cs
- SqlErrorCollection.cs
- EventListener.cs
- CachedFontFace.cs
- XmlDocument.cs
- AutomationPatternInfo.cs
- ConfigurationLocation.cs