Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Runtime / WorkItem.cs / 1305376 / WorkItem.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.Runtime { using System; using System.Runtime; using System.Reflection; using System.Runtime.DurableInstancing; using System.Runtime.Serialization; using System.Diagnostics.CodeAnalysis; using System.Activities.Debugger; using System.Collections.Generic; using System.Activities.Tracking; [DataContract] abstract class WorkItem { static AsyncCallback associateCallback; static AsyncCallback trackingCallback; // We use a protected field here because it works well with // ref style Cleanup exception handling. protected Exception workflowAbortException; [DataMember] ActivityInstance activityInstance; Exception exceptionToPropagate; // Used by subclasses in the pooled case. protected WorkItem() { } protected WorkItem(ActivityInstance activityInstance) { this.activityInstance = activityInstance; this.activityInstance.IncrementBusyCount(); } public ActivityInstance ActivityInstance { get { return this.activityInstance; } } public Exception WorkflowAbortException { get { return this.workflowAbortException; } } public Exception ExceptionToPropagate { get { return this.exceptionToPropagate; } set { Fx.Assert(value != null, "We should never set this back to null explicitly. Use the ExceptionPropagated method below."); this.exceptionToPropagate = value; } } public abstract ActivityInstance PropertyManagerOwner { get; } public virtual ActivityInstance OriginalExceptionSource { get { return this.ActivityInstance; } } [DataMember(EmitDefaultValue = false)] public bool IsEmpty { get; protected set; } public bool ExitNoPersistRequired { get; protected set; } protected bool IsPooled { get; set; } public abstract bool IsValid { get; } public void Dispose(ActivityExecutor executor) { if (FxTrace.ShouldTraceVerboseToTraceSource) { TraceCompleted(); } if (this.IsPooled) { this.ReleaseToPool(executor); } } protected virtual void ClearForReuse() { this.exceptionToPropagate = null; this.workflowAbortException = null; this.activityInstance = null; } protected virtual void Reinitialize(ActivityInstance activityInstance) { this.activityInstance = activityInstance; this.activityInstance.IncrementBusyCount(); } // this isn't just public for performance reasons. We avoid the virtual call // by going through Dispose() protected virtual void ReleaseToPool(ActivityExecutor executor) { Fx.Assert("This should never be called ... only overridden versions should get called."); } static void OnAssociateComplete(IAsyncResult result) { if (result.CompletedSynchronously) { return; } CallbackData data = (CallbackData)result.AsyncState; try { data.Executor.EndAssociateKeys(result); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } data.WorkItem.workflowAbortException = e; } data.Executor.FinishWorkItem(data.WorkItem); } static void OnTrackingComplete(IAsyncResult result) { if (result.CompletedSynchronously) { return; } CallbackData data = (CallbackData)result.AsyncState; try { data.Executor.EndTrackPendingRecords(result); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } data.WorkItem.workflowAbortException = e; } data.Executor.FinishWorkItemAfterTracking(data.WorkItem); } public void ExceptionPropagated() { // We just null this out, but using this API helps with // readability over the property setter this.exceptionToPropagate = null; } public void Release(ActivityExecutor executor) { this.activityInstance.DecrementBusyCount(); if (this.ExitNoPersistRequired) { executor.ExitNoPersist(); } } public abstract void TraceScheduled(); protected void TraceRuntimeWorkItemScheduled() { if (TD.ScheduleRuntimeWorkItemIsEnabled()) { TD.ScheduleRuntimeWorkItem(this.ActivityInstance.Activity.GetType().ToString(), this.ActivityInstance.Activity.DisplayName, this.ActivityInstance.Id); } } public abstract void TraceStarting(); protected void TraceRuntimeWorkItemStarting() { if (TD.StartRuntimeWorkItemIsEnabled()) { TD.StartRuntimeWorkItem(this.ActivityInstance.Activity.GetType().ToString(), this.ActivityInstance.Activity.DisplayName, this.ActivityInstance.Id); } } public abstract void TraceCompleted(); protected void TraceRuntimeWorkItemCompleted() { if (TD.CompleteRuntimeWorkItemIsEnabled()) { TD.CompleteRuntimeWorkItem(this.ActivityInstance.Activity.GetType().ToString(), this.ActivityInstance.Activity.DisplayName, this.ActivityInstance.Id); } } public abstract bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager); public abstract void PostProcess(ActivityExecutor executor); public bool FlushBookmarkScopeKeys(ActivityExecutor executor) { Fx.Assert(executor.BookmarkScopeManager.HasKeysToUpdate, "We should not have been called if we don't have pending keys."); try { // disassociation is local-only so we don't need to yield ICollectionkeysToDisassociate = executor.BookmarkScopeManager.GetKeysToDisassociate(); if (keysToDisassociate != null && keysToDisassociate.Count > 0) { executor.DisassociateKeys(keysToDisassociate); } // if we have keys to associate, provide them for an asynchronous association ICollection keysToAssociate = executor.BookmarkScopeManager.GetKeysToAssociate(); // It could be that we only had keys to Disassociate. We should only do BeginAssociateKeys // if we have keysToAssociate. if (keysToAssociate != null && keysToAssociate.Count > 0) { if (associateCallback == null) { associateCallback = Fx.ThunkCallback(new AsyncCallback(OnAssociateComplete)); } IAsyncResult result = executor.BeginAssociateKeys(keysToAssociate, associateCallback, new CallbackData(executor, this)); if (result.CompletedSynchronously) { executor.EndAssociateKeys(result); } else { return false; } } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } this.workflowAbortException = e; } return true; } public bool FlushTracking(ActivityExecutor executor) { Fx.Assert(executor.HasPendingTrackingRecords, "We should not have been called if we don't have pending tracking records"); try { if (trackingCallback == null) { trackingCallback = Fx.ThunkCallback(new AsyncCallback(OnTrackingComplete)); } IAsyncResult result = executor.BeginTrackPendingRecords( trackingCallback, new CallbackData(executor, this)); if (result.CompletedSynchronously) { executor.EndTrackPendingRecords(result); } else { // Completed async so we'll return false return false; } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } this.workflowAbortException = e; } return true; } class CallbackData { public CallbackData(ActivityExecutor executor, WorkItem workItem) { this.Executor = executor; this.WorkItem = workItem; } public ActivityExecutor Executor { get; private set; } public WorkItem WorkItem { get; private set; } } } } // 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
- HtmlInputReset.cs
- ISAPIRuntime.cs
- ConcurrentDictionary.cs
- SchemaType.cs
- CompoundFileStorageReference.cs
- LineUtil.cs
- TextEditor.cs
- OleDbEnumerator.cs
- WebPartTracker.cs
- ExtendedPropertyDescriptor.cs
- VisualProxy.cs
- Control.cs
- RemoteCryptoRsaServiceProvider.cs
- WebPartDeleteVerb.cs
- SqlDataSourceParameterParser.cs
- LocalizationParserHooks.cs
- Rect3DValueSerializer.cs
- DetailsViewPagerRow.cs
- ThreadExceptionDialog.cs
- FileLogRecord.cs
- AnnotationAdorner.cs
- FileFormatException.cs
- PageStatePersister.cs
- DataGridColumnsPage.cs
- CopyAttributesAction.cs
- ComponentCommands.cs
- BeginSelectCardRequest.cs
- DataGridViewRowEventArgs.cs
- RequestNavigateEventArgs.cs
- HyperLinkStyle.cs
- ContextStaticAttribute.cs
- QilTernary.cs
- NativeMethods.cs
- UserControlCodeDomTreeGenerator.cs
- SurrogateSelector.cs
- JsonFormatWriterGenerator.cs
- WaitHandleCannotBeOpenedException.cs
- TextTreeTextBlock.cs
- SqlBinder.cs
- ToolboxItemCollection.cs
- EventProviderBase.cs
- EdmTypeAttribute.cs
- QilVisitor.cs
- FlowDocumentReaderAutomationPeer.cs
- StateElementCollection.cs
- HttpSessionStateWrapper.cs
- QilGeneratorEnv.cs
- UITypeEditor.cs
- InternalCache.cs
- WindowsIdentity.cs
- MasterPageCodeDomTreeGenerator.cs
- CompositeScriptReferenceEventArgs.cs
- ChtmlTextBoxAdapter.cs
- DataGridViewRowCancelEventArgs.cs
- unsafenativemethodstextservices.cs
- HyperlinkAutomationPeer.cs
- SqlErrorCollection.cs
- ValidationPropertyAttribute.cs
- GridPatternIdentifiers.cs
- SqlDataSourceCache.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- TdsParser.cs
- RepeatBehavior.cs
- LinqDataSourceHelper.cs
- IconEditor.cs
- MimeTypeMapper.cs
- DesignerWithHeader.cs
- BamlBinaryReader.cs
- ErrorFormatter.cs
- HighlightVisual.cs
- GridPattern.cs
- TransformDescriptor.cs
- ParameterToken.cs
- ListParagraph.cs
- MULTI_QI.cs
- ObjectParameterCollection.cs
- Rect3D.cs
- StandardCommands.cs
- Image.cs
- PolyBezierSegment.cs
- RegistryKey.cs
- PromptBuilder.cs
- StreamGeometry.cs
- FixedSOMTable.cs
- EmbeddedMailObjectsCollection.cs
- HttpContextWrapper.cs
- DisposableCollectionWrapper.cs
- ResourceProperty.cs
- RuleProcessor.cs
- SchemaHelper.cs
- SQLRoleProvider.cs
- HttpDictionary.cs
- PropertyPushdownHelper.cs
- DependsOnAttribute.cs
- RenderDataDrawingContext.cs
- EdmItemError.cs
- Serializer.cs
- Grant.cs
- XmlSchemaSimpleTypeList.cs
- DoubleAnimationUsingPath.cs