You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
@@ -0,0 +1,443 @@
|
||||
namespace System.Workflow.ComponentModel
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Design.Serialization;
|
||||
using System.Workflow.ComponentModel.Serialization;
|
||||
|
||||
#region Class ActivityCollectionItemList
|
||||
[DesignerSerializer(typeof(ActivityCollectionMarkupSerializer), typeof(WorkflowMarkupSerializer))]
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public sealed class ActivityCollection : List<Activity>, IList<Activity>, IList
|
||||
{
|
||||
private Activity owner = null;
|
||||
|
||||
internal event EventHandler<ActivityCollectionChangeEventArgs> ListChanging;
|
||||
public event EventHandler<ActivityCollectionChangeEventArgs> ListChanged;
|
||||
|
||||
public ActivityCollection(Activity owner)
|
||||
{
|
||||
if (owner == null)
|
||||
throw new ArgumentNullException("owner");
|
||||
if (!(owner is Activity))
|
||||
throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(Activity).FullName), "owner");
|
||||
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
private void FireListChanging(ActivityCollectionChangeEventArgs eventArgs)
|
||||
{
|
||||
if (this.ListChanging != null)
|
||||
this.ListChanging(this, eventArgs);
|
||||
}
|
||||
|
||||
private void FireListChanged(ActivityCollectionChangeEventArgs eventArgs)
|
||||
{
|
||||
if (this.ListChanged != null)
|
||||
this.ListChanged(this, eventArgs);
|
||||
}
|
||||
|
||||
internal Activity Owner
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.owner;
|
||||
}
|
||||
}
|
||||
|
||||
internal void InnerAdd(Activity activity)
|
||||
{
|
||||
base.Add(activity);
|
||||
}
|
||||
|
||||
#region IList<Activity> Members
|
||||
|
||||
void IList<Activity>.RemoveAt(int index)
|
||||
{
|
||||
if (index < 0 || index >= base.Count)
|
||||
throw new ArgumentOutOfRangeException("Index");
|
||||
|
||||
Activity item = base[index];
|
||||
|
||||
ActivityCollectionChangeEventArgs args = new ActivityCollectionChangeEventArgs(index, item, null, this.owner, ActivityCollectionChangeAction.Remove);
|
||||
FireListChanging(args);
|
||||
base.RemoveAt(index);
|
||||
FireListChanged(args);
|
||||
}
|
||||
|
||||
void IList<Activity>.Insert(int index, Activity item)
|
||||
{
|
||||
if (index < 0 || index > base.Count)
|
||||
throw new ArgumentOutOfRangeException("index");
|
||||
if (item == null)
|
||||
throw new ArgumentNullException("item");
|
||||
|
||||
ActivityCollectionChangeEventArgs args = new ActivityCollectionChangeEventArgs(index, null, item, this.owner, ActivityCollectionChangeAction.Add);
|
||||
FireListChanging(args);
|
||||
base.Insert(index, item);
|
||||
FireListChanged(args);
|
||||
}
|
||||
|
||||
Activity IList<Activity>.this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return base[index];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
throw new ArgumentNullException("item");
|
||||
|
||||
Activity oldItem = base[index];
|
||||
ActivityCollectionChangeEventArgs args = new ActivityCollectionChangeEventArgs(index, oldItem, value, this.owner, ActivityCollectionChangeAction.Replace);
|
||||
FireListChanging(args);
|
||||
base[index] = value;
|
||||
FireListChanged(args);
|
||||
}
|
||||
}
|
||||
int IList<Activity>.IndexOf(Activity item)
|
||||
{
|
||||
return base.IndexOf(item);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICollection<Activity> Members
|
||||
bool ICollection<Activity>.IsReadOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ICollection<Activity>.Contains(Activity item)
|
||||
{
|
||||
return base.Contains(item);
|
||||
}
|
||||
|
||||
bool ICollection<Activity>.Remove(Activity item)
|
||||
{
|
||||
if (!base.Contains(item))
|
||||
return false;
|
||||
|
||||
int index = base.IndexOf(item);
|
||||
if (index >= 0)
|
||||
{
|
||||
ActivityCollectionChangeEventArgs args = new ActivityCollectionChangeEventArgs(index, item, null, this.owner, ActivityCollectionChangeAction.Remove);
|
||||
FireListChanging(args);
|
||||
base.Remove(item);
|
||||
FireListChanged(args);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ICollection<Activity>.Clear()
|
||||
{
|
||||
ICollection<Activity> children = base.GetRange(0, base.Count);
|
||||
ActivityCollectionChangeEventArgs args = new ActivityCollectionChangeEventArgs(-1, children, null, this.owner, ActivityCollectionChangeAction.Remove);
|
||||
FireListChanging(args);
|
||||
base.Clear();
|
||||
FireListChanged(args);
|
||||
}
|
||||
|
||||
void ICollection<Activity>.Add(Activity item)
|
||||
{
|
||||
if (item == null)
|
||||
throw new ArgumentNullException("item");
|
||||
|
||||
ActivityCollectionChangeEventArgs args = new ActivityCollectionChangeEventArgs(base.Count, null, item, this.owner, ActivityCollectionChangeAction.Add);
|
||||
FireListChanging(args);
|
||||
base.Add(item);
|
||||
FireListChanged(args);
|
||||
}
|
||||
|
||||
int ICollection<Activity>.Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Count;
|
||||
}
|
||||
}
|
||||
void ICollection<Activity>.CopyTo(Activity[] array, int arrayIndex)
|
||||
{
|
||||
base.CopyTo(array, arrayIndex);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable<Activity> Members
|
||||
|
||||
IEnumerator<Activity> IEnumerable<Activity>.GetEnumerator()
|
||||
{
|
||||
return base.GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Member Implementations
|
||||
public new int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((ICollection<Activity>)this).Count;
|
||||
}
|
||||
}
|
||||
|
||||
public new void Add(Activity item)
|
||||
{
|
||||
((IList<Activity>)this).Add(item);
|
||||
}
|
||||
|
||||
public new void Clear()
|
||||
{
|
||||
((IList<Activity>)this).Clear();
|
||||
}
|
||||
|
||||
public new void Insert(int index, Activity item)
|
||||
{
|
||||
((IList<Activity>)this).Insert(index, item);
|
||||
}
|
||||
|
||||
public new bool Remove(Activity item)
|
||||
{
|
||||
return ((IList<Activity>)this).Remove(item);
|
||||
}
|
||||
|
||||
public new void RemoveAt(int index)
|
||||
{
|
||||
((IList<Activity>)this).RemoveAt(index);
|
||||
}
|
||||
|
||||
public new Activity this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((IList<Activity>)this)[index];
|
||||
}
|
||||
set
|
||||
{
|
||||
((IList<Activity>)this)[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Activity this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
for (int index = 0; index < this.Count; index++)
|
||||
if ((this[index].Name.Equals(key) || this[index].QualifiedName.Equals(key)))
|
||||
return this[index];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public new int IndexOf(Activity item)
|
||||
{
|
||||
return ((IList<Activity>)this).IndexOf(item);
|
||||
}
|
||||
|
||||
public new bool Contains(Activity item)
|
||||
{
|
||||
return ((IList<Activity>)this).Contains(item);
|
||||
}
|
||||
|
||||
public new IEnumerator<Activity> GetEnumerator()
|
||||
{
|
||||
return ((IList<Activity>)this).GetEnumerator();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IList Members
|
||||
|
||||
int IList.Add(object value)
|
||||
{
|
||||
if (!(value is Activity))
|
||||
throw new Exception(SR.GetString(SR.Error_InvalidListItem, this.GetType().GetGenericArguments()[0].FullName));
|
||||
((IList<Activity>)this).Add((Activity)value);
|
||||
return this.Count - 1;
|
||||
}
|
||||
|
||||
void IList.Clear()
|
||||
{
|
||||
((IList<Activity>)this).Clear();
|
||||
}
|
||||
|
||||
bool IList.Contains(object value)
|
||||
{
|
||||
if (!(value is Activity))
|
||||
throw new Exception(SR.GetString(SR.Error_InvalidListItem, this.GetType().GetGenericArguments()[0].FullName));
|
||||
return (((IList<Activity>)this).Contains((Activity)value));
|
||||
}
|
||||
|
||||
int IList.IndexOf(object value)
|
||||
{
|
||||
if (!(value is Activity))
|
||||
throw new Exception(SR.GetString(SR.Error_InvalidListItem, this.GetType().GetGenericArguments()[0].FullName));
|
||||
return ((IList<Activity>)this).IndexOf((Activity)value);
|
||||
}
|
||||
|
||||
void IList.Insert(int index, object value)
|
||||
{
|
||||
if (!(value is Activity))
|
||||
throw new Exception(SR.GetString(SR.Error_InvalidListItem, this.GetType().GetGenericArguments()[0].FullName));
|
||||
((IList<Activity>)this).Insert(index, (Activity)value);
|
||||
}
|
||||
|
||||
bool IList.IsFixedSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool IList.IsReadOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((IList<Activity>)this).IsReadOnly;
|
||||
}
|
||||
}
|
||||
|
||||
void IList.Remove(object value)
|
||||
{
|
||||
if (!(value is Activity))
|
||||
throw new Exception(SR.GetString(SR.Error_InvalidListItem, this.GetType().GetGenericArguments()[0].FullName));
|
||||
((IList<Activity>)this).Remove((Activity)value);
|
||||
}
|
||||
object IList.this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((IList<Activity>)this)[index];
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (!(value is Activity))
|
||||
throw new Exception(SR.GetString(SR.Error_InvalidListItem, this.GetType().GetGenericArguments()[0].FullName));
|
||||
((IList<Activity>)this)[index] = (Activity)value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICollection Members
|
||||
|
||||
void ICollection.CopyTo(Array array, int index)
|
||||
{
|
||||
for (int loop = 0; loop < this.Count; loop++)
|
||||
array.SetValue(this[loop], loop + index);
|
||||
}
|
||||
bool ICollection.IsSynchronized
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
object ICollection.SyncRoot
|
||||
{
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable Members
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return (IEnumerator)((IList<Activity>)this).GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public enum ActivityCollectionChangeAction
|
||||
{
|
||||
Add = 0x00,
|
||||
Remove = 0x01,
|
||||
Replace = 0x02
|
||||
}
|
||||
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public sealed class ActivityCollectionChangeEventArgs : EventArgs
|
||||
{
|
||||
private int index = 0;
|
||||
private ICollection<Activity> addedItems = null;
|
||||
private ICollection<Activity> removedItems = null;
|
||||
private object owner = null;
|
||||
private ActivityCollectionChangeAction action = ActivityCollectionChangeAction.Add;
|
||||
|
||||
public ActivityCollectionChangeEventArgs(int index, ICollection<Activity> removedItems, ICollection<Activity> addedItems, object owner, ActivityCollectionChangeAction action)
|
||||
{
|
||||
this.index = index;
|
||||
this.removedItems = removedItems;
|
||||
this.addedItems = addedItems;
|
||||
this.action = action;
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public ActivityCollectionChangeEventArgs(int index, Activity removedActivity, Activity addedActivity, object owner, ActivityCollectionChangeAction action)
|
||||
{
|
||||
this.index = index;
|
||||
if (removedActivity != null)
|
||||
{
|
||||
this.removedItems = new List<Activity>();
|
||||
((List<Activity>)this.removedItems).Add(removedActivity);
|
||||
}
|
||||
if (addedActivity != null)
|
||||
{
|
||||
this.addedItems = new List<Activity>();
|
||||
((List<Activity>)this.addedItems).Add(addedActivity);
|
||||
}
|
||||
this.action = action;
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public IList<Activity> RemovedItems
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this.removedItems != null) ? new List<Activity>(this.removedItems).AsReadOnly() : new List<Activity>().AsReadOnly();
|
||||
}
|
||||
}
|
||||
|
||||
public IList<Activity> AddedItems
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this.addedItems != null) ? new List<Activity>(this.addedItems).AsReadOnly() : new List<Activity>().AsReadOnly();
|
||||
}
|
||||
}
|
||||
|
||||
public object Owner
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.owner;
|
||||
}
|
||||
}
|
||||
|
||||
public int Index
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.index;
|
||||
}
|
||||
}
|
||||
|
||||
public ActivityCollectionChangeAction Action
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.action;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
b7fb7591d13c88ae4bc9450ebf34053fe4404190
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,464 @@
|
||||
#pragma warning disable 1634, 1691
|
||||
|
||||
namespace System.Workflow.ComponentModel
|
||||
{
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Workflow.ComponentModel.Design;
|
||||
using System.Runtime.Serialization;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Workflow.ComponentModel.Serialization;
|
||||
#endregion
|
||||
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public sealed class ActivityExecutionContextManager
|
||||
{
|
||||
#region Data members and constructor
|
||||
|
||||
private ActivityExecutionContext ownerContext = null;
|
||||
private List<ActivityExecutionContext> executionContexts = new List<ActivityExecutionContext>();
|
||||
|
||||
internal ActivityExecutionContextManager(ActivityExecutionContext ownerContext)
|
||||
{
|
||||
this.ownerContext = ownerContext;
|
||||
|
||||
// Populate the child collection.
|
||||
IList<Activity> activeContexts = (IList<Activity>)this.ownerContext.Activity.ContextActivity.GetValue(Activity.ActiveExecutionContextsProperty);
|
||||
if (activeContexts != null)
|
||||
{
|
||||
foreach (Activity activeContextActivity in activeContexts)
|
||||
this.executionContexts.Add(new ActivityExecutionContext(activeContextActivity));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public members
|
||||
|
||||
public ReadOnlyCollection<ActivityExecutionContext> ExecutionContexts
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.ownerContext == null)
|
||||
#pragma warning suppress 56503
|
||||
throw new ObjectDisposedException("ActivityExecutionContextManager");
|
||||
|
||||
return new ReadOnlyCollection<ActivityExecutionContext>(this.executionContexts);
|
||||
}
|
||||
}
|
||||
|
||||
public ActivityExecutionContext CreateExecutionContext(Activity activity)
|
||||
{
|
||||
if (this.ownerContext == null)
|
||||
throw new ObjectDisposedException("ActivityExecutionContextManager");
|
||||
|
||||
if (activity == null)
|
||||
throw new ArgumentNullException("activity");
|
||||
|
||||
if (!this.ownerContext.IsValidChild(activity, true))
|
||||
throw new ArgumentException(SR.GetString(SR.AEC_InvalidActivity), "activity");
|
||||
|
||||
Activity copiedActivity = activity.Clone();
|
||||
((IDependencyObjectAccessor)copiedActivity).InitializeInstanceForRuntime(this.ownerContext.Activity.WorkflowCoreRuntime);
|
||||
|
||||
//Reset the cloned tree for execution.
|
||||
Queue<Activity> activityQueue = new Queue<Activity>();
|
||||
activityQueue.Enqueue(copiedActivity);
|
||||
|
||||
while (activityQueue.Count != 0)
|
||||
{
|
||||
Activity clonedActivity = activityQueue.Dequeue();
|
||||
if (clonedActivity.ExecutionStatus != ActivityExecutionStatus.Initialized)
|
||||
{
|
||||
clonedActivity.ResetAllKnownDependencyProperties();
|
||||
CompositeActivity compositeActivity = clonedActivity as CompositeActivity;
|
||||
|
||||
if (compositeActivity != null)
|
||||
{
|
||||
for (int i = 0; i < compositeActivity.EnabledActivities.Count; ++i)
|
||||
{
|
||||
activityQueue.Enqueue(compositeActivity.EnabledActivities[i]);
|
||||
}
|
||||
|
||||
ISupportAlternateFlow alternateFlow = compositeActivity as ISupportAlternateFlow;
|
||||
|
||||
if (alternateFlow != null)
|
||||
{
|
||||
for (int i = 0; i < alternateFlow.AlternateFlowActivities.Count; ++i)
|
||||
{
|
||||
activityQueue.Enqueue(alternateFlow.AlternateFlowActivities[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get active context activities and add it to this one
|
||||
IList<Activity> activeContexts = (IList<Activity>)this.ownerContext.Activity.ContextActivity.GetValue(Activity.ActiveExecutionContextsProperty);
|
||||
if (activeContexts == null)
|
||||
{
|
||||
activeContexts = new List<Activity>();
|
||||
this.ownerContext.Activity.ContextActivity.SetValue(Activity.ActiveExecutionContextsProperty, activeContexts);
|
||||
}
|
||||
activeContexts.Add(copiedActivity);
|
||||
|
||||
// prepare the copied activity as a context activity
|
||||
ActivityExecutionContextInfo contextInfo = new ActivityExecutionContextInfo(activity.QualifiedName, this.ownerContext.WorkflowCoreRuntime.GetNewContextActivityId(), Guid.NewGuid(), this.ownerContext.ContextId);
|
||||
copiedActivity.SetValue(Activity.ActivityExecutionContextInfoProperty, contextInfo);
|
||||
copiedActivity.SetValue(Activity.ActivityContextGuidProperty, contextInfo.ContextGuid);
|
||||
ActivityExecutionContext newExecutionContext = null;
|
||||
try
|
||||
{
|
||||
// inform workflow runtime
|
||||
this.ownerContext.Activity.WorkflowCoreRuntime.RegisterContextActivity(copiedActivity);
|
||||
|
||||
// return the new context
|
||||
newExecutionContext = new ActivityExecutionContext(copiedActivity);
|
||||
this.executionContexts.Add(newExecutionContext);
|
||||
newExecutionContext.InitializeActivity(newExecutionContext.Activity);
|
||||
return newExecutionContext;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (newExecutionContext != null)
|
||||
{
|
||||
this.CompleteExecutionContext(newExecutionContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
activeContexts.Remove(copiedActivity);
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void CompleteExecutionContext(ActivityExecutionContext childContext)
|
||||
{
|
||||
if (this.ownerContext == null)
|
||||
throw new ObjectDisposedException("ActivityExecutionContextManager");
|
||||
|
||||
CompleteExecutionContext(childContext, false);
|
||||
}
|
||||
|
||||
public void CompleteExecutionContext(ActivityExecutionContext childContext, bool forcePersist)
|
||||
{
|
||||
if (this.ownerContext == null)
|
||||
throw new ObjectDisposedException("ActivityExecutionContextManager");
|
||||
|
||||
if (childContext == null)
|
||||
throw new ArgumentNullException("childContext");
|
||||
|
||||
if (childContext.Activity == null)
|
||||
throw new ArgumentException("childContext", SR.GetString(SR.Error_MissingActivityProperty));
|
||||
|
||||
if (childContext.Activity.ContextActivity == null)
|
||||
throw new ArgumentException("childContext", SR.GetString(SR.Error_MissingContextActivityProperty));
|
||||
|
||||
if (!this.executionContexts.Contains(childContext))
|
||||
throw new ArgumentException();
|
||||
|
||||
if (childContext.Activity.ContextActivity.ExecutionStatus != ActivityExecutionStatus.Closed && childContext.Activity.ContextActivity.ExecutionStatus != ActivityExecutionStatus.Initialized)
|
||||
throw new InvalidOperationException(SR.GetString(System.Globalization.CultureInfo.CurrentCulture, SR.Error_CannotCompleteContext));
|
||||
|
||||
// make sure that this is in the active contexts collections
|
||||
ActivityExecutionContextInfo childContextInfo = childContext.Activity.ContextActivity.GetValue(Activity.ActivityExecutionContextInfoProperty) as ActivityExecutionContextInfo;
|
||||
IList<Activity> activeContexts = (IList<Activity>)this.ownerContext.Activity.ContextActivity.GetValue(Activity.ActiveExecutionContextsProperty);
|
||||
if (activeContexts == null || !activeContexts.Contains(childContext.Activity.ContextActivity))
|
||||
throw new ArgumentException();
|
||||
|
||||
// add it to completed contexts collection
|
||||
bool needsCompensation = childContext.Activity.NeedsCompensation;
|
||||
if (needsCompensation || forcePersist)
|
||||
{
|
||||
// add it to completed contexts
|
||||
List<ActivityExecutionContextInfo> completedContexts = this.ownerContext.Activity.ContextActivity.GetValue(Activity.CompletedExecutionContextsProperty) as List<ActivityExecutionContextInfo>;
|
||||
if (completedContexts == null)
|
||||
{
|
||||
completedContexts = new List<ActivityExecutionContextInfo>();
|
||||
this.ownerContext.Activity.ContextActivity.SetValue(Activity.CompletedExecutionContextsProperty, completedContexts);
|
||||
}
|
||||
|
||||
if (needsCompensation)
|
||||
childContextInfo.Flags = PersistFlags.NeedsCompensation;
|
||||
if (forcePersist)
|
||||
childContextInfo.Flags |= PersistFlags.ForcePersist;
|
||||
|
||||
childContextInfo.SetCompletedOrderId(this.ownerContext.Activity.IncrementCompletedOrderId());
|
||||
completedContexts.Add(childContextInfo);
|
||||
|
||||
// ask runtime to save the context activity
|
||||
this.ownerContext.Activity.WorkflowCoreRuntime.SaveContextActivity(childContext.Activity);
|
||||
}
|
||||
|
||||
// remove it from active contexts
|
||||
activeContexts.Remove(childContext.Activity.ContextActivity);
|
||||
this.executionContexts.Remove(childContext);
|
||||
|
||||
//Case for those context which has compensatable child context, when those context
|
||||
//are completed at the end of Compensation chain we need to uninitialize the context
|
||||
//activity associated to them.
|
||||
if (childContext.Activity.ContextActivity.CanUninitializeNow && childContext.Activity.ContextActivity.ExecutionResult != ActivityExecutionResult.Uninitialized)
|
||||
{
|
||||
childContext.Activity.ContextActivity.Uninitialize(this.ownerContext.Activity.RootActivity.WorkflowCoreRuntime);
|
||||
childContext.Activity.ContextActivity.SetValue(Activity.ExecutionResultProperty, ActivityExecutionResult.Uninitialized);
|
||||
}
|
||||
|
||||
// unregister it from runtime
|
||||
this.ownerContext.Activity.WorkflowCoreRuntime.UnregisterContextActivity(childContext.Activity);
|
||||
|
||||
if (!(needsCompensation || forcePersist))
|
||||
{
|
||||
childContext.Activity.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public ActivityExecutionContext GetExecutionContext(Activity activity)
|
||||
{
|
||||
if (this.ownerContext == null)
|
||||
throw new ObjectDisposedException("ActivityExecutionContextManager");
|
||||
|
||||
if (activity == null)
|
||||
throw new ArgumentNullException("activity");
|
||||
|
||||
ActivityExecutionContextInfo contextInfo = activity.GetValue(Activity.ActivityExecutionContextInfoProperty) as ActivityExecutionContextInfo;
|
||||
|
||||
// Returns the first context for an activity with the same qualified name.
|
||||
foreach (ActivityExecutionContext context in ExecutionContexts)
|
||||
{
|
||||
if (contextInfo == null) //Template being passed.
|
||||
{
|
||||
if (context.Activity.ContextActivity.QualifiedName == activity.QualifiedName)
|
||||
return context;
|
||||
}
|
||||
else //Context Sensitive Activity
|
||||
{
|
||||
if (context.ContextGuid.Equals(contextInfo.ContextGuid))
|
||||
return context;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public IEnumerable<Guid> PersistedExecutionContexts
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.ownerContext == null)
|
||||
#pragma warning suppress 56503
|
||||
throw new ObjectDisposedException("ActivityExecutionContextManager");
|
||||
|
||||
List<ActivityExecutionContextInfo> completedContexts = this.ownerContext.Activity.ContextActivity.GetValue(Activity.CompletedExecutionContextsProperty) as List<ActivityExecutionContextInfo>;
|
||||
completedContexts = (completedContexts == null) ? new List<ActivityExecutionContextInfo>() : completedContexts;
|
||||
|
||||
List<Guid> persistedContexts = new List<Guid>();
|
||||
foreach (ActivityExecutionContextInfo contextInfo in completedContexts)
|
||||
if ((contextInfo.Flags & PersistFlags.ForcePersist) != 0)
|
||||
persistedContexts.Add(contextInfo.ContextGuid);
|
||||
|
||||
return persistedContexts;
|
||||
}
|
||||
}
|
||||
|
||||
public ActivityExecutionContext GetPersistedExecutionContext(Guid contextGuid)
|
||||
{
|
||||
if (this.ownerContext == null)
|
||||
throw new ObjectDisposedException("ActivityExecutionContextManager");
|
||||
|
||||
// Check if child execution context exists.
|
||||
IList<ActivityExecutionContextInfo> completedContexts = this.ownerContext.Activity.ContextActivity.GetValue(Activity.CompletedExecutionContextsProperty) as IList<ActivityExecutionContextInfo>;
|
||||
if (completedContexts == null)
|
||||
throw new ArgumentException();
|
||||
|
||||
ActivityExecutionContextInfo contextInfo = null;
|
||||
foreach (ActivityExecutionContextInfo completedContextInfo in completedContexts)
|
||||
{
|
||||
if (completedContextInfo.ContextGuid == contextGuid && ((completedContextInfo.Flags & PersistFlags.ForcePersist) != 0))
|
||||
{
|
||||
contextInfo = completedContextInfo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (contextInfo == null)
|
||||
throw new ArgumentException();
|
||||
|
||||
// The caller would have to close the AEC with forcepersist the next time
|
||||
// around.
|
||||
contextInfo.Flags &= ~PersistFlags.ForcePersist;
|
||||
return DiscardPersistedExecutionContext(contextInfo);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
internal void Dispose()
|
||||
{
|
||||
if (this.ownerContext != null)
|
||||
{
|
||||
foreach (ActivityExecutionContext executionContext in this.ExecutionContexts)
|
||||
((IDisposable)executionContext).Dispose();
|
||||
this.ownerContext = null;
|
||||
}
|
||||
}
|
||||
|
||||
#region Internal members
|
||||
|
||||
internal ReadOnlyCollection<ActivityExecutionContextInfo> CompletedExecutionContexts
|
||||
{
|
||||
get
|
||||
{
|
||||
List<ActivityExecutionContextInfo> completedContexts = this.ownerContext.Activity.ContextActivity.GetValue(Activity.CompletedExecutionContextsProperty) as List<ActivityExecutionContextInfo>;
|
||||
completedContexts = (completedContexts == null) ? new List<ActivityExecutionContextInfo>() : completedContexts;
|
||||
return completedContexts.AsReadOnly();
|
||||
}
|
||||
}
|
||||
|
||||
internal ActivityExecutionContext DiscardPersistedExecutionContext(ActivityExecutionContextInfo contextInfo)
|
||||
{
|
||||
if (contextInfo == null)
|
||||
throw new ArgumentNullException("contextInfo");
|
||||
|
||||
// check if child execution context
|
||||
IList<ActivityExecutionContextInfo> completedContexts = this.ownerContext.Activity.ContextActivity.GetValue(Activity.CompletedExecutionContextsProperty) as IList<ActivityExecutionContextInfo>;
|
||||
if (completedContexts == null || !completedContexts.Contains(contextInfo))
|
||||
throw new ArgumentException();
|
||||
|
||||
// revoke from persistence service
|
||||
Activity revokedActivity = this.ownerContext.WorkflowCoreRuntime.LoadContextActivity(contextInfo, this.ownerContext.Activity.ContextActivity.GetActivityByName(contextInfo.ActivityQualifiedName));
|
||||
((IDependencyObjectAccessor)revokedActivity).InitializeInstanceForRuntime(this.ownerContext.Activity.WorkflowCoreRuntime);
|
||||
|
||||
// add it back to active contexts
|
||||
IList<Activity> activeContexts = (IList<Activity>)this.ownerContext.Activity.ContextActivity.GetValue(Activity.ActiveExecutionContextsProperty);
|
||||
if (activeContexts == null)
|
||||
{
|
||||
activeContexts = new List<Activity>();
|
||||
this.ownerContext.Activity.ContextActivity.SetValue(Activity.ActiveExecutionContextsProperty, activeContexts);
|
||||
}
|
||||
activeContexts.Add(revokedActivity);
|
||||
|
||||
// inform workflow runtime
|
||||
this.ownerContext.Activity.WorkflowCoreRuntime.RegisterContextActivity(revokedActivity);
|
||||
|
||||
// return the new context
|
||||
ActivityExecutionContext revokedContext = new ActivityExecutionContext(revokedActivity);
|
||||
this.executionContexts.Add(revokedContext);
|
||||
System.Workflow.Runtime.WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 0, "Revoking context {0}:{1}", revokedContext.ContextId, revokedContext.Activity.ContextActivity.QualifiedName);
|
||||
|
||||
// remove it from completed contexts
|
||||
completedContexts.Remove(contextInfo);
|
||||
return revokedContext;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region Class ActivityExecutionContextInfo
|
||||
|
||||
[Serializable]
|
||||
[Flags]
|
||||
internal enum PersistFlags : byte
|
||||
{
|
||||
NeedsCompensation = 1,
|
||||
ForcePersist = 2
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal sealed class ActivityExecutionContextInfo
|
||||
{
|
||||
private string qualifiedID = string.Empty;
|
||||
private int contextId = -1;
|
||||
private Guid contextGuid = Guid.Empty; //
|
||||
private int parentContextId = -1;
|
||||
private int completedOrderId = -1;
|
||||
private PersistFlags flags = 0;
|
||||
|
||||
internal ActivityExecutionContextInfo(string qualifiedName, int contextId, Guid contextGuid, int parentContextId)
|
||||
{
|
||||
this.qualifiedID = qualifiedName;
|
||||
this.contextId = contextId;
|
||||
this.contextGuid = contextGuid;
|
||||
this.parentContextId = parentContextId;
|
||||
}
|
||||
|
||||
internal int ContextId
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.contextId;
|
||||
}
|
||||
}
|
||||
|
||||
public Guid ContextGuid
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.contextGuid;
|
||||
}
|
||||
}
|
||||
|
||||
public string ActivityQualifiedName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.qualifiedID;
|
||||
}
|
||||
}
|
||||
|
||||
public int CompletedOrderId
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.completedOrderId;
|
||||
}
|
||||
}
|
||||
|
||||
internal int ParentContextId
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.parentContextId;
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetCompletedOrderId(int completedOrderId)
|
||||
{
|
||||
this.completedOrderId = completedOrderId;
|
||||
}
|
||||
|
||||
internal PersistFlags Flags
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.flags;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.flags = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return contextGuid.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
ActivityExecutionContextInfo otherContextInfo = obj as ActivityExecutionContextInfo;
|
||||
|
||||
if (otherContextInfo != null)
|
||||
{
|
||||
return this.ContextGuid.Equals(otherContextInfo.ContextGuid);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Security.Permissions;
|
||||
|
||||
namespace System.Workflow.ComponentModel
|
||||
{
|
||||
#region ActivityExecutor
|
||||
|
||||
internal abstract class ActivityExecutor
|
||||
{
|
||||
public abstract ActivityExecutionStatus Execute(Activity activity, ActivityExecutionContext executionContext);
|
||||
public abstract ActivityExecutionStatus Cancel(Activity activity, ActivityExecutionContext executionContext);
|
||||
public abstract ActivityExecutionStatus HandleFault(Activity activity, ActivityExecutionContext executionContext, Exception exception);
|
||||
public abstract ActivityExecutionStatus Compensate(Activity activity, ActivityExecutionContext executionContext);
|
||||
}
|
||||
|
||||
internal class ActivityExecutor<T> : ActivityExecutor where T : Activity
|
||||
{
|
||||
#region System.Workflow.ComponentModel.ActivityExecutor Methods
|
||||
|
||||
public sealed override ActivityExecutionStatus Execute(Activity activity, ActivityExecutionContext executionContext)
|
||||
{
|
||||
return this.Execute((T)activity, executionContext);
|
||||
}
|
||||
public sealed override ActivityExecutionStatus Cancel(Activity activity, ActivityExecutionContext executionContext)
|
||||
{
|
||||
return this.Cancel((T)activity, executionContext);
|
||||
}
|
||||
public sealed override ActivityExecutionStatus HandleFault(Activity activity, ActivityExecutionContext executionContext, Exception exception)
|
||||
{
|
||||
return this.HandleFault((T)activity, executionContext, exception);
|
||||
}
|
||||
public sealed override ActivityExecutionStatus Compensate(Activity activity, ActivityExecutionContext executionContext)
|
||||
{
|
||||
return this.Compensate((T)activity, executionContext);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ActivityExecutor<T> Members
|
||||
protected virtual ActivityExecutionStatus Execute(T activity, ActivityExecutionContext executionContext)
|
||||
{
|
||||
if (activity == null)
|
||||
throw new ArgumentNullException("activity");
|
||||
if (executionContext == null)
|
||||
throw new ArgumentNullException("executionContext");
|
||||
|
||||
return activity.Execute(executionContext);
|
||||
}
|
||||
protected virtual ActivityExecutionStatus Cancel(T activity, ActivityExecutionContext executionContext)
|
||||
{
|
||||
if (activity == null)
|
||||
throw new ArgumentNullException("activity");
|
||||
if (executionContext == null)
|
||||
throw new ArgumentNullException("executionContext");
|
||||
|
||||
return activity.Cancel(executionContext);
|
||||
}
|
||||
protected virtual ActivityExecutionStatus HandleFault(T activity, ActivityExecutionContext executionContext, Exception exception)
|
||||
{
|
||||
if (activity == null)
|
||||
throw new ArgumentNullException("activity");
|
||||
if (executionContext == null)
|
||||
throw new ArgumentNullException("executionContext");
|
||||
|
||||
return activity.HandleFault(executionContext, exception);
|
||||
}
|
||||
protected virtual ActivityExecutionStatus Compensate(T activity, ActivityExecutionContext executionContext)
|
||||
{
|
||||
if (activity == null)
|
||||
throw new ArgumentNullException("activity");
|
||||
if (executionContext == null)
|
||||
throw new ArgumentNullException("executionContext");
|
||||
|
||||
System.Diagnostics.Debug.Assert(activity is ICompensatableActivity, "should not get Compensate, if activity is not compensatable");
|
||||
return ((ICompensatableActivity)activity).Compensate(executionContext);
|
||||
}
|
||||
|
||||
#endregion ActivityExecutor
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CompositeActivityExecutor<T>
|
||||
internal class CompositeActivityExecutor<T> : ActivityExecutor<T>, ISupportWorkflowChanges where T : CompositeActivity
|
||||
{
|
||||
//@@undone:mayankm Once all ActivityExecutor is removed this method should not be virtual.
|
||||
void ISupportWorkflowChanges.OnActivityAdded(ActivityExecutionContext executionContext, Activity addedActivity)
|
||||
{
|
||||
if (executionContext == null)
|
||||
throw new ArgumentNullException("executionContext");
|
||||
if (addedActivity == null)
|
||||
throw new ArgumentNullException("addedActivity");
|
||||
|
||||
CompositeActivity compositeActivity = executionContext.Activity as CompositeActivity;
|
||||
if (compositeActivity == null)
|
||||
throw new ArgumentException(SR.Error_InvalidActivityExecutionContext, "executionContext");
|
||||
|
||||
compositeActivity.OnActivityChangeAdd(executionContext, addedActivity);
|
||||
}
|
||||
|
||||
void ISupportWorkflowChanges.OnActivityRemoved(ActivityExecutionContext executionContext, Activity removedActivity)
|
||||
{
|
||||
if (executionContext == null)
|
||||
throw new ArgumentNullException("executionContext");
|
||||
if (removedActivity == null)
|
||||
throw new ArgumentNullException("removedActivity");
|
||||
|
||||
CompositeActivity compositeActivity = executionContext.Activity as CompositeActivity;
|
||||
if (compositeActivity == null)
|
||||
throw new ArgumentException(SR.Error_InvalidActivityExecutionContext, "executionContext");
|
||||
|
||||
compositeActivity.OnActivityChangeRemove(executionContext, removedActivity);
|
||||
}
|
||||
|
||||
void ISupportWorkflowChanges.OnWorkflowChangesCompleted(ActivityExecutionContext executionContext)
|
||||
{
|
||||
if (executionContext == null)
|
||||
throw new ArgumentNullException("executionContext");
|
||||
|
||||
CompositeActivity compositeActivity = executionContext.Activity as CompositeActivity;
|
||||
|
||||
if (compositeActivity == null)
|
||||
throw new ArgumentException(SR.Error_InvalidActivityExecutionContext, "executionContext");
|
||||
|
||||
compositeActivity.OnWorkflowChangesCompleted(executionContext);
|
||||
}
|
||||
|
||||
// Refer Bug 9339 (VB Compilation Failure - Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.)
|
||||
//An unhandled exception of type 'System.TypeLoadException' occurred
|
||||
// "Signature of the body and declaration in a method implementation do not match"
|
||||
protected override ActivityExecutionStatus Execute(T activity, ActivityExecutionContext executionContext)
|
||||
{
|
||||
return base.Execute(activity, executionContext);
|
||||
}
|
||||
|
||||
protected override ActivityExecutionStatus Cancel(T activity, ActivityExecutionContext executionContext)
|
||||
{
|
||||
return base.Cancel(activity, executionContext);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ActivityExecutors Class
|
||||
|
||||
internal static class ActivityExecutors
|
||||
{
|
||||
private static Hashtable typeToExecutorMapping = new Hashtable();
|
||||
private static Hashtable executors = new Hashtable();
|
||||
|
||||
internal static ActivityExecutor[] GetActivityExecutors(Activity activity)
|
||||
{
|
||||
if (activity == null)
|
||||
throw new ArgumentNullException("activity");
|
||||
|
||||
Type activityType = activity.GetType();
|
||||
ActivityExecutor[] activityExecutors = executors[activityType] as ActivityExecutor[];
|
||||
if (activityExecutors != null)
|
||||
return activityExecutors;
|
||||
|
||||
lock (executors.SyncRoot)
|
||||
{
|
||||
activityExecutors = executors[activityType] as ActivityExecutor[];
|
||||
if (activityExecutors != null)
|
||||
return activityExecutors;
|
||||
|
||||
object[] activityExecutorsObjects = null;
|
||||
try
|
||||
{
|
||||
//activityExecutorsObjects = ComponentDispenser.CreateComponents(activityType, typeof(ActivityExecutorAttribute));
|
||||
activityExecutorsObjects = ComponentDispenser.CreateActivityExecutors(activity);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new InvalidOperationException(SR.GetString(SR.ExecutorCreationFailedErrorMessage, activityType.FullName), e);
|
||||
}
|
||||
|
||||
if (activityExecutorsObjects == null || activityExecutorsObjects.Length == 0)
|
||||
throw new InvalidOperationException(SR.GetString(SR.ExecutorCreationFailedErrorMessage, activityType.FullName));
|
||||
|
||||
activityExecutors = new ActivityExecutor[activityExecutorsObjects.Length];
|
||||
for (int index = 0; index < activityExecutorsObjects.Length; index++)
|
||||
{
|
||||
if (!typeToExecutorMapping.Contains(activityExecutorsObjects[index].GetType()))
|
||||
{
|
||||
lock (typeToExecutorMapping.SyncRoot)
|
||||
{
|
||||
if (!typeToExecutorMapping.Contains(activityExecutorsObjects[index].GetType()))
|
||||
{
|
||||
System.Threading.Thread.MemoryBarrier();
|
||||
typeToExecutorMapping[activityExecutorsObjects[index].GetType()] = activityExecutorsObjects[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
activityExecutors[index] = (ActivityExecutor)typeToExecutorMapping[activityExecutorsObjects[index].GetType()];
|
||||
}
|
||||
|
||||
System.Threading.Thread.MemoryBarrier();
|
||||
executors[activityType] = activityExecutors;
|
||||
}
|
||||
return activityExecutors;
|
||||
}
|
||||
|
||||
public static ActivityExecutor GetActivityExecutorFromType(Type executorType)
|
||||
{
|
||||
if (executorType == null)
|
||||
throw new ArgumentNullException("executorType");
|
||||
if (!typeof(ActivityExecutor).IsAssignableFrom(executorType))
|
||||
throw new ArgumentException(
|
||||
SR.GetString(SR.Error_NonActivityExecutor, executorType.FullName), "executorType");
|
||||
|
||||
ActivityExecutor activityExecutor = typeToExecutorMapping[executorType] as ActivityExecutor;
|
||||
if (activityExecutor != null)
|
||||
return activityExecutor;
|
||||
|
||||
lock (typeToExecutorMapping.SyncRoot)
|
||||
{
|
||||
activityExecutor = typeToExecutorMapping[executorType] as ActivityExecutor;
|
||||
if (activityExecutor != null)
|
||||
return activityExecutor;
|
||||
|
||||
System.Threading.Thread.MemoryBarrier();
|
||||
typeToExecutorMapping[executorType] = Activator.CreateInstance(executorType);
|
||||
}
|
||||
return (ActivityExecutor)typeToExecutorMapping[executorType];
|
||||
}
|
||||
|
||||
public static ActivityExecutor GetActivityExecutor(Activity activity)
|
||||
{
|
||||
if (activity == null)
|
||||
throw new ArgumentNullException("activity");
|
||||
|
||||
return GetActivityExecutors(activity)[0];
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,360 @@
|
||||
namespace System.Workflow.ComponentModel
|
||||
{
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public interface IActivityEventListener<T> where T : EventArgs
|
||||
{
|
||||
void OnEvent(object sender, T e);
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal sealed class ActivityExecutorDelegateInfo<T> where T : EventArgs
|
||||
{
|
||||
private string activityQualifiedName = null;
|
||||
private IActivityEventListener<T> eventListener = null;
|
||||
private EventHandler<T> delegateValue = null;
|
||||
private int contextId = -1;
|
||||
private bool wantInTransact = false;
|
||||
private string subscribedActivityQualifiedName = null;
|
||||
|
||||
public ActivityExecutorDelegateInfo(EventHandler<T> delegateValue, Activity contextActivity)
|
||||
: this(false, delegateValue, contextActivity)
|
||||
{
|
||||
}
|
||||
public ActivityExecutorDelegateInfo(IActivityEventListener<T> eventListener, Activity contextActivity)
|
||||
: this(false, eventListener, contextActivity)
|
||||
{
|
||||
}
|
||||
public ActivityExecutorDelegateInfo(EventHandler<T> delegateValue, Activity contextActivity, bool wantInTransact)
|
||||
: this(delegateValue, contextActivity)
|
||||
{
|
||||
this.wantInTransact = wantInTransact;
|
||||
}
|
||||
public ActivityExecutorDelegateInfo(IActivityEventListener<T> eventListener, Activity contextActivity, bool wantInTransact)
|
||||
: this(eventListener, contextActivity)
|
||||
{
|
||||
this.wantInTransact = wantInTransact;
|
||||
}
|
||||
internal ActivityExecutorDelegateInfo(bool useCurrentContext, EventHandler<T> delegateValue, Activity contextActivity)
|
||||
{
|
||||
this.delegateValue = delegateValue;
|
||||
Activity target = delegateValue.Target as Activity;
|
||||
|
||||
if (contextActivity.WorkflowCoreRuntime != null)
|
||||
{
|
||||
if (useCurrentContext)
|
||||
this.contextId = contextActivity.WorkflowCoreRuntime.CurrentActivity.ContextActivity.ContextId;
|
||||
else
|
||||
this.contextId = contextActivity.ContextId;
|
||||
|
||||
this.activityQualifiedName = (target ?? contextActivity.WorkflowCoreRuntime.CurrentActivity).QualifiedName;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.contextId = 1;
|
||||
this.activityQualifiedName = (target ?? contextActivity.RootActivity).QualifiedName;
|
||||
}
|
||||
}
|
||||
internal ActivityExecutorDelegateInfo(bool useCurrentContext, IActivityEventListener<T> eventListener, Activity contextActivity)
|
||||
{
|
||||
this.eventListener = eventListener;
|
||||
Activity target = eventListener as Activity;
|
||||
if (contextActivity.WorkflowCoreRuntime != null)
|
||||
{
|
||||
if (useCurrentContext)
|
||||
this.contextId = contextActivity.WorkflowCoreRuntime.CurrentActivity.ContextActivity.ContextId;
|
||||
else
|
||||
this.contextId = contextActivity.ContextId;
|
||||
|
||||
this.activityQualifiedName = (target ?? contextActivity.WorkflowCoreRuntime.CurrentActivity).QualifiedName;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.contextId = 1;
|
||||
this.activityQualifiedName = (target ?? contextActivity.RootActivity).QualifiedName;
|
||||
}
|
||||
}
|
||||
public string ActivityQualifiedName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.activityQualifiedName;
|
||||
}
|
||||
}
|
||||
public string SubscribedActivityQualifiedName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.subscribedActivityQualifiedName;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.subscribedActivityQualifiedName = value;
|
||||
}
|
||||
|
||||
}
|
||||
public int ContextId
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.contextId;
|
||||
}
|
||||
}
|
||||
public EventHandler<T> HandlerDelegate
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.delegateValue;
|
||||
}
|
||||
}
|
||||
|
||||
public IActivityEventListener<T> EventListener
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.eventListener;
|
||||
}
|
||||
}
|
||||
|
||||
internal void InvokeDelegate(Activity currentContextActivity, T e, bool sync, bool transacted)
|
||||
{
|
||||
Activity targetContextActivity = currentContextActivity.WorkflowCoreRuntime.GetContextActivityForId(this.contextId);
|
||||
if (targetContextActivity == null)
|
||||
{
|
||||
targetContextActivity = FindExecutorForActivityUp(currentContextActivity, this.activityQualifiedName);
|
||||
if (targetContextActivity == null)
|
||||
targetContextActivity = FindExecutorForActivityDown(currentContextActivity, this.activityQualifiedName);
|
||||
}
|
||||
if (targetContextActivity != null)
|
||||
InvokeDelegate(currentContextActivity, targetContextActivity, e, sync, transacted);
|
||||
}
|
||||
public void InvokeDelegate(Activity currentContextActivity, T e, bool transacted)
|
||||
{
|
||||
// If in atomic and subscriber in same scope, or not in atomic scope at all
|
||||
Activity targetContextActivity = FindExecutorForActivityUp(currentContextActivity, this.activityQualifiedName);
|
||||
if (targetContextActivity == null)
|
||||
targetContextActivity = FindExecutorForActivityDown(currentContextActivity, this.activityQualifiedName);
|
||||
|
||||
if (targetContextActivity != null)
|
||||
InvokeDelegate(currentContextActivity, targetContextActivity, e, false, transacted);
|
||||
}
|
||||
private void InvokeDelegate(Activity currentContextActivity, Activity targetContextActivity, T e, bool sync, bool transacted)
|
||||
{
|
||||
ActivityExecutorDelegateOperation delegateOperation = null;
|
||||
if (this.delegateValue != null)
|
||||
delegateOperation = new ActivityExecutorDelegateOperation(this.activityQualifiedName, this.delegateValue, e, this.ContextId);
|
||||
else
|
||||
delegateOperation = new ActivityExecutorDelegateOperation(this.activityQualifiedName, this.eventListener, e, this.ContextId);
|
||||
|
||||
bool mayInvokeDelegateNow = MayInvokeDelegateNow(currentContextActivity);
|
||||
if (mayInvokeDelegateNow && sync)
|
||||
{
|
||||
Activity targetActivity = targetContextActivity.GetActivityByName(this.activityQualifiedName);
|
||||
using (currentContextActivity.WorkflowCoreRuntime.SetCurrentActivity(targetActivity))
|
||||
{
|
||||
delegateOperation.SynchronousInvoke = true;
|
||||
delegateOperation.Run(currentContextActivity.WorkflowCoreRuntime);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If in atomic and subscriber not in same scope
|
||||
// Queue it on the subscriber's baseExecutor
|
||||
Activity targetActivity = targetContextActivity.GetActivityByName(this.activityQualifiedName);
|
||||
currentContextActivity.WorkflowCoreRuntime.ScheduleItem(delegateOperation, ActivityExecutionContext.IsInAtomicTransaction(targetActivity), transacted, !mayInvokeDelegateNow);
|
||||
}
|
||||
}
|
||||
private bool MayInvokeDelegateNow(Activity currentContextActivity)
|
||||
{
|
||||
// Ok to invoke right away if
|
||||
// subscriber wants to participate in the current transaction
|
||||
if ((this.activityQualifiedName == null) || (this.wantInTransact))
|
||||
return true;
|
||||
|
||||
// If not in atomic scope at all,
|
||||
if (!ActivityExecutionContext.IsInAtomicTransaction(currentContextActivity.WorkflowCoreRuntime.CurrentActivity))
|
||||
return true;
|
||||
|
||||
// Has not started executing yet, queue it up for now
|
||||
// Not letting it leak out for recv case any more
|
||||
Activity targetContextActivity = currentContextActivity.WorkflowCoreRuntime.GetContextActivityForId(this.contextId);
|
||||
if (targetContextActivity == null)
|
||||
return false;
|
||||
|
||||
// or in atomic and subscriber in same scope,
|
||||
// or in an atomic scope that's not in executing state, e.g. need to fire Scope closed status
|
||||
Activity targetActivity = targetContextActivity.GetActivityByName(this.activityQualifiedName, true);
|
||||
|
||||
if (targetActivity == null)
|
||||
return false;
|
||||
|
||||
if (ActivityExecutionContext.IsInAtomicTransaction(targetActivity) &&
|
||||
ActivityExecutionContext.IsInAtomicTransaction(currentContextActivity.WorkflowCoreRuntime.CurrentActivity))
|
||||
return true;
|
||||
|
||||
// If the activity receiving the subscription is the scope itself
|
||||
if (targetActivity.MetaEquals(currentContextActivity))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
private Activity FindExecutorForActivityUp(Activity contextActivity, string activityQualifiedName)
|
||||
{
|
||||
while (contextActivity != null)
|
||||
{
|
||||
Activity activityToFind = contextActivity.GetActivityByName(activityQualifiedName, true);
|
||||
if (activityToFind != null && activityToFind.ExecutionStatus != ActivityExecutionStatus.Initialized)
|
||||
return contextActivity;
|
||||
contextActivity = contextActivity.ParentContextActivity;
|
||||
}
|
||||
return contextActivity;
|
||||
}
|
||||
private Activity FindExecutorForActivityDown(Activity contextActivity, string activityQualifiedName)
|
||||
{
|
||||
Queue<Activity> contextActivities = new Queue<Activity>();
|
||||
contextActivities.Enqueue(contextActivity);
|
||||
while (contextActivities.Count > 0)
|
||||
{
|
||||
Activity contextActivity2 = contextActivities.Dequeue();
|
||||
Activity activityToFind = contextActivity2.GetActivityByName(activityQualifiedName, true);
|
||||
if (activityToFind != null && activityToFind.ExecutionStatus != ActivityExecutionStatus.Initialized)
|
||||
return contextActivity2;
|
||||
|
||||
IList<Activity> nestedContextActivities = (IList<Activity>)contextActivity2.GetValue(Activity.ActiveExecutionContextsProperty);
|
||||
if (nestedContextActivities != null)
|
||||
{
|
||||
foreach (Activity nestedContextActivity in nestedContextActivities)
|
||||
contextActivities.Enqueue(nestedContextActivity);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
ActivityExecutorDelegateInfo<T> otherObject = obj as ActivityExecutorDelegateInfo<T>;
|
||||
if (otherObject == null)
|
||||
return false;
|
||||
|
||||
return (
|
||||
(otherObject.delegateValue == null && this.delegateValue == null) ||
|
||||
(otherObject.delegateValue != null && otherObject.delegateValue.Equals(this.delegateValue))
|
||||
) &&
|
||||
(
|
||||
(otherObject.eventListener == null && this.eventListener == null) ||
|
||||
(otherObject.eventListener != null && otherObject.eventListener.Equals(this.eventListener))
|
||||
) &&
|
||||
otherObject.activityQualifiedName == this.activityQualifiedName &&
|
||||
otherObject.contextId == this.contextId &&
|
||||
otherObject.wantInTransact == this.wantInTransact;
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.delegateValue != null ? this.delegateValue.GetHashCode() : this.eventListener.GetHashCode() ^
|
||||
this.activityQualifiedName.GetHashCode();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
private sealed class ActivityExecutorDelegateOperation : SchedulableItem
|
||||
{
|
||||
private string activityQualifiedName = null;
|
||||
private IActivityEventListener<T> eventListener = null;
|
||||
private EventHandler<T> delegateValue = null;
|
||||
private T args = null;
|
||||
|
||||
[NonSerialized]
|
||||
private bool synchronousInvoke = false;
|
||||
|
||||
public ActivityExecutorDelegateOperation(string activityQualifiedName, EventHandler<T> delegateValue, T e, int contextId)
|
||||
: base(contextId, activityQualifiedName)
|
||||
{
|
||||
this.activityQualifiedName = activityQualifiedName;
|
||||
this.delegateValue = delegateValue;
|
||||
this.args = e;
|
||||
}
|
||||
public ActivityExecutorDelegateOperation(string activityQualifiedName, IActivityEventListener<T> eventListener, T e, int contextId)
|
||||
: base(contextId, activityQualifiedName)
|
||||
{
|
||||
this.activityQualifiedName = activityQualifiedName;
|
||||
this.eventListener = eventListener;
|
||||
this.args = e;
|
||||
}
|
||||
internal bool SynchronousInvoke
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.synchronousInvoke;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.synchronousInvoke = value;
|
||||
}
|
||||
}
|
||||
public override bool Run(IWorkflowCoreRuntime workflowCoreRuntime)
|
||||
{
|
||||
// get context activity
|
||||
Activity contextActivity = workflowCoreRuntime.GetContextActivityForId(this.ContextId);
|
||||
|
||||
// Work around for ActivityExecutionStatusChangedEventArgs
|
||||
ActivityExecutionStatusChangedEventArgs activityStatusChangeEventArgs = this.args as ActivityExecutionStatusChangedEventArgs;
|
||||
if (activityStatusChangeEventArgs != null)
|
||||
{
|
||||
activityStatusChangeEventArgs.BaseExecutor = workflowCoreRuntime;
|
||||
if (activityStatusChangeEventArgs.Activity == null)
|
||||
{
|
||||
// status change for an activity that has been deleted dynamically since.
|
||||
activityStatusChangeEventArgs.BaseExecutor = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// get activity, if null, or if activity has already closed or just initialized, or if primary has closed and
|
||||
// the target of the notification is not ActivityExecutionFilter, then
|
||||
Activity activity = contextActivity.GetActivityByName(this.activityQualifiedName);
|
||||
if (activity == null ||
|
||||
((activity.ExecutionStatus == ActivityExecutionStatus.Closed || activity.ExecutionStatus == ActivityExecutionStatus.Initialized) && !this.synchronousInvoke) ||
|
||||
(activity.HasPrimaryClosed && !(this.eventListener is ActivityExecutionFilter))
|
||||
)
|
||||
return false;
|
||||
|
||||
// call the delegate
|
||||
try
|
||||
{
|
||||
using (workflowCoreRuntime.SetCurrentActivity(activity))
|
||||
{
|
||||
using (ActivityExecutionContext activityExecutionContext = new ActivityExecutionContext(activity))
|
||||
{
|
||||
if (this.delegateValue != null)
|
||||
this.delegateValue(activityExecutionContext, this.args);
|
||||
else
|
||||
this.eventListener.OnEvent(activityExecutionContext, this.args);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (activity != null)
|
||||
System.Workflow.Runtime.WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 1, "Subscription handler of Activity {0} threw {1}", activity.QualifiedName, e.ToString());
|
||||
else
|
||||
System.Workflow.Runtime.WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 1, "Subscription handler threw {0}", e.ToString());
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Work around for activity status change Event Args
|
||||
if (activityStatusChangeEventArgs != null)
|
||||
activityStatusChangeEventArgs.BaseExecutor = null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return "SubscriptionEvent(" + "(" + this.ContextId.ToString(CultureInfo.CurrentCulture) + ")" + this.activityQualifiedName + ", " + this.args.ToString() + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,360 @@
|
||||
namespace System.Workflow.ComponentModel
|
||||
{
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public interface IActivityEventListener<T> where T : EventArgs
|
||||
{
|
||||
void OnEvent(object sender, T e);
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal sealed class ActivityExecutorDelegateInfo<T> where T : EventArgs
|
||||
{
|
||||
private string activityQualifiedName = null;
|
||||
private IActivityEventListener<T> eventListener = null;
|
||||
private EventHandler<T> delegateValue = null;
|
||||
private int contextId = -1;
|
||||
private bool wantInTransact = false;
|
||||
private string subscribedActivityQualifiedName = null;
|
||||
|
||||
public ActivityExecutorDelegateInfo(EventHandler<T> delegateValue, Activity contextActivity)
|
||||
: this(false, delegateValue, contextActivity)
|
||||
{
|
||||
}
|
||||
public ActivityExecutorDelegateInfo(IActivityEventListener<T> eventListener, Activity contextActivity)
|
||||
: this(false, eventListener, contextActivity)
|
||||
{
|
||||
}
|
||||
public ActivityExecutorDelegateInfo(EventHandler<T> delegateValue, Activity contextActivity, bool wantInTransact)
|
||||
: this(delegateValue, contextActivity)
|
||||
{
|
||||
this.wantInTransact = wantInTransact;
|
||||
}
|
||||
public ActivityExecutorDelegateInfo(IActivityEventListener<T> eventListener, Activity contextActivity, bool wantInTransact)
|
||||
: this(eventListener, contextActivity)
|
||||
{
|
||||
this.wantInTransact = wantInTransact;
|
||||
}
|
||||
internal ActivityExecutorDelegateInfo(bool useCurrentContext, EventHandler<T> delegateValue, Activity contextActivity)
|
||||
{
|
||||
this.delegateValue = delegateValue;
|
||||
Activity target = delegateValue.Target as Activity;
|
||||
|
||||
if (contextActivity.WorkflowCoreRuntime != null)
|
||||
{
|
||||
if (useCurrentContext)
|
||||
this.contextId = contextActivity.WorkflowCoreRuntime.CurrentActivity.ContextActivity.ContextId;
|
||||
else
|
||||
this.contextId = contextActivity.ContextId;
|
||||
|
||||
this.activityQualifiedName = (target ?? contextActivity.WorkflowCoreRuntime.CurrentActivity).QualifiedName;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.contextId = 1;
|
||||
this.activityQualifiedName = (target ?? contextActivity.RootActivity).QualifiedName;
|
||||
}
|
||||
}
|
||||
internal ActivityExecutorDelegateInfo(bool useCurrentContext, IActivityEventListener<T> eventListener, Activity contextActivity)
|
||||
{
|
||||
this.eventListener = eventListener;
|
||||
Activity target = eventListener as Activity;
|
||||
if (contextActivity.WorkflowCoreRuntime != null)
|
||||
{
|
||||
if (useCurrentContext)
|
||||
this.contextId = contextActivity.WorkflowCoreRuntime.CurrentActivity.ContextActivity.ContextId;
|
||||
else
|
||||
this.contextId = contextActivity.ContextId;
|
||||
|
||||
this.activityQualifiedName = (target ?? contextActivity.WorkflowCoreRuntime.CurrentActivity).QualifiedName;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.contextId = 1;
|
||||
this.activityQualifiedName = (target ?? contextActivity.RootActivity).QualifiedName;
|
||||
}
|
||||
}
|
||||
public string ActivityQualifiedName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.activityQualifiedName;
|
||||
}
|
||||
}
|
||||
public string SubscribedActivityQualifiedName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.subscribedActivityQualifiedName;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.subscribedActivityQualifiedName = value;
|
||||
}
|
||||
|
||||
}
|
||||
public int ContextId
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.contextId;
|
||||
}
|
||||
}
|
||||
public EventHandler<T> HandlerDelegate
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.delegateValue;
|
||||
}
|
||||
}
|
||||
|
||||
public IActivityEventListener<T> EventListener
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.eventListener;
|
||||
}
|
||||
}
|
||||
|
||||
internal void InvokeDelegate(Activity currentContextActivity, T e, bool [....], bool transacted)
|
||||
{
|
||||
Activity targetContextActivity = currentContextActivity.WorkflowCoreRuntime.GetContextActivityForId(this.contextId);
|
||||
if (targetContextActivity == null)
|
||||
{
|
||||
targetContextActivity = FindExecutorForActivityUp(currentContextActivity, this.activityQualifiedName);
|
||||
if (targetContextActivity == null)
|
||||
targetContextActivity = FindExecutorForActivityDown(currentContextActivity, this.activityQualifiedName);
|
||||
}
|
||||
if (targetContextActivity != null)
|
||||
InvokeDelegate(currentContextActivity, targetContextActivity, e, [....], transacted);
|
||||
}
|
||||
public void InvokeDelegate(Activity currentContextActivity, T e, bool transacted)
|
||||
{
|
||||
// If in atomic and subscriber in same scope, or not in atomic scope at all
|
||||
Activity targetContextActivity = FindExecutorForActivityUp(currentContextActivity, this.activityQualifiedName);
|
||||
if (targetContextActivity == null)
|
||||
targetContextActivity = FindExecutorForActivityDown(currentContextActivity, this.activityQualifiedName);
|
||||
|
||||
if (targetContextActivity != null)
|
||||
InvokeDelegate(currentContextActivity, targetContextActivity, e, false, transacted);
|
||||
}
|
||||
private void InvokeDelegate(Activity currentContextActivity, Activity targetContextActivity, T e, bool [....], bool transacted)
|
||||
{
|
||||
ActivityExecutorDelegateOperation delegateOperation = null;
|
||||
if (this.delegateValue != null)
|
||||
delegateOperation = new ActivityExecutorDelegateOperation(this.activityQualifiedName, this.delegateValue, e, this.ContextId);
|
||||
else
|
||||
delegateOperation = new ActivityExecutorDelegateOperation(this.activityQualifiedName, this.eventListener, e, this.ContextId);
|
||||
|
||||
bool mayInvokeDelegateNow = MayInvokeDelegateNow(currentContextActivity);
|
||||
if (mayInvokeDelegateNow && [....])
|
||||
{
|
||||
Activity targetActivity = targetContextActivity.GetActivityByName(this.activityQualifiedName);
|
||||
using (currentContextActivity.WorkflowCoreRuntime.SetCurrentActivity(targetActivity))
|
||||
{
|
||||
delegateOperation.SynchronousInvoke = true;
|
||||
delegateOperation.Run(currentContextActivity.WorkflowCoreRuntime);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If in atomic and subscriber not in same scope
|
||||
// Queue it on the subscriber's baseExecutor
|
||||
Activity targetActivity = targetContextActivity.GetActivityByName(this.activityQualifiedName);
|
||||
currentContextActivity.WorkflowCoreRuntime.ScheduleItem(delegateOperation, ActivityExecutionContext.IsInAtomicTransaction(targetActivity), transacted, !mayInvokeDelegateNow);
|
||||
}
|
||||
}
|
||||
private bool MayInvokeDelegateNow(Activity currentContextActivity)
|
||||
{
|
||||
// Ok to invoke right away if
|
||||
// subscriber wants to participate in the current transaction
|
||||
if ((this.activityQualifiedName == null) || (this.wantInTransact))
|
||||
return true;
|
||||
|
||||
// If not in atomic scope at all,
|
||||
if (!ActivityExecutionContext.IsInAtomicTransaction(currentContextActivity.WorkflowCoreRuntime.CurrentActivity))
|
||||
return true;
|
||||
|
||||
// Has not started executing yet, queue it up for now
|
||||
// Not letting it leak out for recv case any more
|
||||
Activity targetContextActivity = currentContextActivity.WorkflowCoreRuntime.GetContextActivityForId(this.contextId);
|
||||
if (targetContextActivity == null)
|
||||
return false;
|
||||
|
||||
// or in atomic and subscriber in same scope,
|
||||
// or in an atomic scope that's not in executing state, e.g. need to fire Scope closed status
|
||||
Activity targetActivity = targetContextActivity.GetActivityByName(this.activityQualifiedName, true);
|
||||
|
||||
if (targetActivity == null)
|
||||
return false;
|
||||
|
||||
if (ActivityExecutionContext.IsInAtomicTransaction(targetActivity) &&
|
||||
ActivityExecutionContext.IsInAtomicTransaction(currentContextActivity.WorkflowCoreRuntime.CurrentActivity))
|
||||
return true;
|
||||
|
||||
// If the activity receiving the subscription is the scope itself
|
||||
if (targetActivity.MetaEquals(currentContextActivity))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
private Activity FindExecutorForActivityUp(Activity contextActivity, string activityQualifiedName)
|
||||
{
|
||||
while (contextActivity != null)
|
||||
{
|
||||
Activity activityToFind = contextActivity.GetActivityByName(activityQualifiedName, true);
|
||||
if (activityToFind != null && activityToFind.ExecutionStatus != ActivityExecutionStatus.Initialized)
|
||||
return contextActivity;
|
||||
contextActivity = contextActivity.ParentContextActivity;
|
||||
}
|
||||
return contextActivity;
|
||||
}
|
||||
private Activity FindExecutorForActivityDown(Activity contextActivity, string activityQualifiedName)
|
||||
{
|
||||
Queue<Activity> contextActivities = new Queue<Activity>();
|
||||
contextActivities.Enqueue(contextActivity);
|
||||
while (contextActivities.Count > 0)
|
||||
{
|
||||
Activity contextActivity2 = contextActivities.Dequeue();
|
||||
Activity activityToFind = contextActivity2.GetActivityByName(activityQualifiedName, true);
|
||||
if (activityToFind != null && activityToFind.ExecutionStatus != ActivityExecutionStatus.Initialized)
|
||||
return contextActivity2;
|
||||
|
||||
IList<Activity> nestedContextActivities = (IList<Activity>)contextActivity2.GetValue(Activity.ActiveExecutionContextsProperty);
|
||||
if (nestedContextActivities != null)
|
||||
{
|
||||
foreach (Activity nestedContextActivity in nestedContextActivities)
|
||||
contextActivities.Enqueue(nestedContextActivity);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
ActivityExecutorDelegateInfo<T> otherObject = obj as ActivityExecutorDelegateInfo<T>;
|
||||
if (otherObject == null)
|
||||
return false;
|
||||
|
||||
return (
|
||||
(otherObject.delegateValue == null && this.delegateValue == null) ||
|
||||
(otherObject.delegateValue != null && otherObject.delegateValue.Equals(this.delegateValue))
|
||||
) &&
|
||||
(
|
||||
(otherObject.eventListener == null && this.eventListener == null) ||
|
||||
(otherObject.eventListener != null && otherObject.eventListener.Equals(this.eventListener))
|
||||
) &&
|
||||
otherObject.activityQualifiedName == this.activityQualifiedName &&
|
||||
otherObject.contextId == this.contextId &&
|
||||
otherObject.wantInTransact == this.wantInTransact;
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.delegateValue != null ? this.delegateValue.GetHashCode() : this.eventListener.GetHashCode() ^
|
||||
this.activityQualifiedName.GetHashCode();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
private sealed class ActivityExecutorDelegateOperation : SchedulableItem
|
||||
{
|
||||
private string activityQualifiedName = null;
|
||||
private IActivityEventListener<T> eventListener = null;
|
||||
private EventHandler<T> delegateValue = null;
|
||||
private T args = null;
|
||||
|
||||
[NonSerialized]
|
||||
private bool synchronousInvoke = false;
|
||||
|
||||
public ActivityExecutorDelegateOperation(string activityQualifiedName, EventHandler<T> delegateValue, T e, int contextId)
|
||||
: base(contextId, activityQualifiedName)
|
||||
{
|
||||
this.activityQualifiedName = activityQualifiedName;
|
||||
this.delegateValue = delegateValue;
|
||||
this.args = e;
|
||||
}
|
||||
public ActivityExecutorDelegateOperation(string activityQualifiedName, IActivityEventListener<T> eventListener, T e, int contextId)
|
||||
: base(contextId, activityQualifiedName)
|
||||
{
|
||||
this.activityQualifiedName = activityQualifiedName;
|
||||
this.eventListener = eventListener;
|
||||
this.args = e;
|
||||
}
|
||||
internal bool SynchronousInvoke
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.synchronousInvoke;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.synchronousInvoke = value;
|
||||
}
|
||||
}
|
||||
public override bool Run(IWorkflowCoreRuntime workflowCoreRuntime)
|
||||
{
|
||||
// get context activity
|
||||
Activity contextActivity = workflowCoreRuntime.GetContextActivityForId(this.ContextId);
|
||||
|
||||
// Work around for ActivityExecutionStatusChangedEventArgs
|
||||
ActivityExecutionStatusChangedEventArgs activityStatusChangeEventArgs = this.args as ActivityExecutionStatusChangedEventArgs;
|
||||
if (activityStatusChangeEventArgs != null)
|
||||
{
|
||||
activityStatusChangeEventArgs.BaseExecutor = workflowCoreRuntime;
|
||||
if (activityStatusChangeEventArgs.Activity == null)
|
||||
{
|
||||
// status change for an activity that has been deleted dynamically since.
|
||||
activityStatusChangeEventArgs.BaseExecutor = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// get activity, if null, or if activity has already closed or just initialized, or if primary has closed and
|
||||
// the target of the notification is not ActivityExecutionFilter, then
|
||||
Activity activity = contextActivity.GetActivityByName(this.activityQualifiedName);
|
||||
if (activity == null ||
|
||||
((activity.ExecutionStatus == ActivityExecutionStatus.Closed || activity.ExecutionStatus == ActivityExecutionStatus.Initialized) && !this.synchronousInvoke) ||
|
||||
(activity.HasPrimaryClosed && !(this.eventListener is ActivityExecutionFilter))
|
||||
)
|
||||
return false;
|
||||
|
||||
// call the delegate
|
||||
try
|
||||
{
|
||||
using (workflowCoreRuntime.SetCurrentActivity(activity))
|
||||
{
|
||||
using (ActivityExecutionContext activityExecutionContext = new ActivityExecutionContext(activity))
|
||||
{
|
||||
if (this.delegateValue != null)
|
||||
this.delegateValue(activityExecutionContext, this.args);
|
||||
else
|
||||
this.eventListener.OnEvent(activityExecutionContext, this.args);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (activity != null)
|
||||
System.Workflow.Runtime.WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 1, "Subscription handler of Activity {0} threw {1}", activity.QualifiedName, e.ToString());
|
||||
else
|
||||
System.Workflow.Runtime.WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 1, "Subscription handler threw {0}", e.ToString());
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Work around for activity status change Event Args
|
||||
if (activityStatusChangeEventArgs != null)
|
||||
activityStatusChangeEventArgs.BaseExecutor = null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return "SubscriptionEvent(" + "(" + this.ContextId.ToString(CultureInfo.CurrentCulture) + ")" + this.activityQualifiedName + ", " + this.args.ToString() + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
namespace System.Workflow.ComponentModel
|
||||
{
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
[Serializable]
|
||||
internal abstract class SchedulableItem
|
||||
{
|
||||
private int contextId = -1;
|
||||
string activityId = null;
|
||||
protected SchedulableItem(int contextId, string activityId)
|
||||
{
|
||||
this.contextId = contextId;
|
||||
this.activityId = activityId;
|
||||
}
|
||||
|
||||
public int ContextId
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.contextId;
|
||||
}
|
||||
}
|
||||
|
||||
public string ActivityId
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.activityId;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract bool Run(IWorkflowCoreRuntime workflowCoreRuntime);
|
||||
}
|
||||
|
||||
internal enum ActivityOperationType : byte
|
||||
{
|
||||
Execute = 0,
|
||||
Cancel = 1,
|
||||
Compensate = 2,
|
||||
HandleFault = 3
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal sealed class ActivityExecutorOperation : SchedulableItem
|
||||
{
|
||||
private string activityName;
|
||||
private ActivityOperationType operation;
|
||||
private Exception exceptionToDeliver;
|
||||
|
||||
public ActivityExecutorOperation(Activity activity, ActivityOperationType opt, int contextId)
|
||||
: base(contextId, activity.QualifiedName)
|
||||
{
|
||||
this.activityName = activity.QualifiedName;
|
||||
this.operation = opt;
|
||||
}
|
||||
public ActivityExecutorOperation(Activity activity, ActivityOperationType opt, int contextId, Exception e)
|
||||
: this(activity, opt, contextId)
|
||||
{
|
||||
this.exceptionToDeliver = e;
|
||||
}
|
||||
public override bool Run(IWorkflowCoreRuntime workflowCoreRuntime)
|
||||
{
|
||||
// get state reader
|
||||
Activity contextActivity = workflowCoreRuntime.GetContextActivityForId(this.ContextId);
|
||||
Activity activity = contextActivity.GetActivityByName(this.activityName);
|
||||
|
||||
using (workflowCoreRuntime.SetCurrentActivity(activity))
|
||||
{
|
||||
using (ActivityExecutionContext activityExecutionContext = new ActivityExecutionContext(activity))
|
||||
{
|
||||
ActivityExecutor activityExecutor = ActivityExecutors.GetActivityExecutor(activity);
|
||||
switch (this.operation)
|
||||
{
|
||||
case ActivityOperationType.Execute:
|
||||
if (activity.ExecutionStatus == ActivityExecutionStatus.Executing)
|
||||
{
|
||||
try
|
||||
{
|
||||
workflowCoreRuntime.RaiseActivityExecuting(activity);
|
||||
|
||||
ActivityExecutionStatus newStatus = activityExecutor.Execute(activity, activityExecutionContext);
|
||||
if (newStatus == ActivityExecutionStatus.Closed)
|
||||
activityExecutionContext.CloseActivity();
|
||||
else if (newStatus != ActivityExecutionStatus.Executing)
|
||||
throw new InvalidOperationException(SR.GetString(SR.InvalidExecutionStatus, activity.QualifiedName, newStatus.ToString(), ActivityExecutionStatus.Executing.ToString()));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.Workflow.Runtime.WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 1, "Execute of Activity {0} threw {1}", activity.QualifiedName, e.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ActivityOperationType.Cancel:
|
||||
if (activity.ExecutionStatus == ActivityExecutionStatus.Canceling)
|
||||
{
|
||||
try
|
||||
{
|
||||
ActivityExecutionStatus newStatus = activityExecutor.Cancel(activity, activityExecutionContext);
|
||||
if (newStatus == ActivityExecutionStatus.Closed)
|
||||
activityExecutionContext.CloseActivity();
|
||||
else if (newStatus != ActivityExecutionStatus.Canceling)
|
||||
throw new InvalidOperationException(SR.GetString(SR.InvalidExecutionStatus, activity.QualifiedName, newStatus.ToString(), ActivityExecutionStatus.Canceling.ToString()));
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.Workflow.Runtime.WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 1, "Cancel of Activity {0} threw {1}", activity.QualifiedName, e.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ActivityOperationType.Compensate:
|
||||
if (activity.ExecutionStatus == ActivityExecutionStatus.Compensating)
|
||||
{
|
||||
try
|
||||
{
|
||||
ActivityExecutionStatus newStatus = activityExecutor.Compensate(activity, activityExecutionContext);
|
||||
if (newStatus == ActivityExecutionStatus.Closed)
|
||||
activityExecutionContext.CloseActivity();
|
||||
else if (newStatus != ActivityExecutionStatus.Compensating)
|
||||
throw new InvalidOperationException(SR.GetString(SR.InvalidExecutionStatus, activity.QualifiedName, newStatus.ToString(), ActivityExecutionStatus.Compensating.ToString()));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.Workflow.Runtime.WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 1, "Compensate of Activity {0} threw {1}", activity.QualifiedName, e.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ActivityOperationType.HandleFault:
|
||||
if (activity.ExecutionStatus == ActivityExecutionStatus.Faulting)
|
||||
{
|
||||
try
|
||||
{
|
||||
ActivityExecutionStatus newStatus = activityExecutor.HandleFault(activity, activityExecutionContext, this.exceptionToDeliver);
|
||||
if (newStatus == ActivityExecutionStatus.Closed)
|
||||
activityExecutionContext.CloseActivity();
|
||||
else if (newStatus != ActivityExecutionStatus.Faulting)
|
||||
throw new InvalidOperationException(SR.GetString(SR.InvalidExecutionStatus, activity.QualifiedName, newStatus.ToString(), ActivityExecutionStatus.Faulting.ToString()));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.Workflow.Runtime.WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 1, "Compensate of Activity {0} threw {1}", activity.QualifiedName, e.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return "ActivityOperation(" + "(" + this.ContextId.ToString(CultureInfo.CurrentCulture) + ")" + this.activityName + ", " + ActivityOperationToString(this.operation) + ")";
|
||||
}
|
||||
private string ActivityOperationToString(ActivityOperationType operationType)
|
||||
{
|
||||
string retVal = string.Empty;
|
||||
switch (operationType)
|
||||
{
|
||||
case ActivityOperationType.Execute:
|
||||
retVal = "Execute";
|
||||
break;
|
||||
case ActivityOperationType.Cancel:
|
||||
retVal = "Cancel";
|
||||
break;
|
||||
case ActivityOperationType.HandleFault:
|
||||
retVal = "HandleFault";
|
||||
break;
|
||||
case ActivityOperationType.Compensate:
|
||||
retVal = "Compensate";
|
||||
break;
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
// ****************************************************************************
|
||||
// Copyright (C) 2000-2001 Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// CONTENTS
|
||||
// Activity interface
|
||||
//
|
||||
// DESCRIPTION
|
||||
//
|
||||
// REVISIONS
|
||||
// Date Ver By Remarks
|
||||
// ~~~~~~~~~~ ~~~ ~~~~~~~~ ~~~~~~~~~~~~~~
|
||||
// 03/19/04 1.0 MayankM interfaces
|
||||
// ****************************************************************************
|
||||
namespace System.Workflow.ComponentModel
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.Design;
|
||||
using System.CodeDom;
|
||||
using System.ComponentModel.Design.Serialization;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Reflection;
|
||||
using System.Security.Principal;
|
||||
using System.Security.Cryptography;
|
||||
using Microsoft.CSharp;
|
||||
using System.Workflow.ComponentModel.Compiler;
|
||||
using System.Workflow.ComponentModel.Design;
|
||||
using System.Workflow.ComponentModel.Serialization;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Threading;
|
||||
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public interface IDynamicPropertyTypeProvider
|
||||
{
|
||||
Type GetPropertyType(IServiceProvider serviceProvider, string propertyName);
|
||||
AccessTypes GetAccessType(IServiceProvider serviceProvider, string propertyName);
|
||||
}
|
||||
|
||||
internal interface ISupportWorkflowChanges
|
||||
{
|
||||
void OnActivityAdded(ActivityExecutionContext rootContext, Activity addedActivity);
|
||||
void OnActivityRemoved(ActivityExecutionContext rootContext, Activity removedActivity);
|
||||
void OnWorkflowChangesCompleted(ActivityExecutionContext rootContext);
|
||||
}
|
||||
internal interface ISupportAlternateFlow
|
||||
{
|
||||
IList<Activity> AlternateFlowActivities { get; }
|
||||
}
|
||||
|
||||
[AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = false)]
|
||||
internal sealed class ActivityExecutorAttribute : Attribute
|
||||
{
|
||||
private string executorTypeName = string.Empty;
|
||||
|
||||
public ActivityExecutorAttribute(Type executorType)
|
||||
{
|
||||
if (executorType != null)
|
||||
this.executorTypeName = executorType.AssemblyQualifiedName;
|
||||
}
|
||||
|
||||
public ActivityExecutorAttribute(string executorTypeName)
|
||||
{
|
||||
this.executorTypeName = executorTypeName;
|
||||
}
|
||||
|
||||
public string ExecutorTypeName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.executorTypeName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public enum ActivityExecutionStatus : byte
|
||||
{
|
||||
Initialized = 0,
|
||||
Executing = 1,
|
||||
Canceling = 2,
|
||||
Closed = 3,
|
||||
Compensating = 4,
|
||||
Faulting = 5
|
||||
}
|
||||
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public enum ActivityExecutionResult : byte
|
||||
{
|
||||
None = 0,
|
||||
Succeeded = 1,
|
||||
Canceled = 2,
|
||||
Compensated = 3,
|
||||
Faulted = 4,
|
||||
Uninitialized = 5
|
||||
}
|
||||
|
||||
internal interface IDependencyObjectAccessor
|
||||
{
|
||||
//This method is invoked during the definition creation time
|
||||
void InitializeDefinitionForRuntime(DependencyObject parentDependencyObject);
|
||||
|
||||
//This is invoked for every instance (not necessarily activating)
|
||||
void InitializeInstanceForRuntime(IWorkflowCoreRuntime workflowCoreRuntime);
|
||||
|
||||
//This is invoked for every activating instance
|
||||
void InitializeActivatingInstanceForRuntime(DependencyObject parentDependencyObject, IWorkflowCoreRuntime workflowCoreRuntime);
|
||||
|
||||
T[] GetInvocationList<T>(DependencyProperty dependencyEvent);
|
||||
}
|
||||
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public interface IStartWorkflow
|
||||
{
|
||||
Guid StartWorkflow(Type workflowType, Dictionary<string, object> namedArgumentValues);
|
||||
}
|
||||
|
||||
internal interface IWorkflowCoreRuntime : IServiceProvider
|
||||
{
|
||||
// context information
|
||||
Activity RootActivity { get; }
|
||||
Activity CurrentActivity { get; }
|
||||
Activity CurrentAtomicActivity { get; }
|
||||
IDisposable SetCurrentActivity(Activity activity);
|
||||
|
||||
void ScheduleItem(SchedulableItem item, bool isInAtomicTransaction, bool transacted, bool queueInTransaction);
|
||||
void ActivityStatusChanged(Activity activity, bool transacted, bool committed);
|
||||
void RaiseException(Exception e, Activity activity, string responsibleActivity);
|
||||
|
||||
void RaiseActivityExecuting(Activity activity);
|
||||
void RaiseHandlerInvoking(Delegate delegateHandler);
|
||||
void RaiseHandlerInvoked();
|
||||
|
||||
Guid StartWorkflow(Type workflowType, Dictionary<string, object> namedArgumentValues);
|
||||
|
||||
// context activity related
|
||||
int GetNewContextActivityId();
|
||||
void RegisterContextActivity(Activity activity);
|
||||
void UnregisterContextActivity(Activity activity);
|
||||
Activity LoadContextActivity(ActivityExecutionContextInfo contextInfo, Activity outerContextActivity);
|
||||
void SaveContextActivity(Activity contextActivity);
|
||||
Activity GetContextActivityForId(int id);
|
||||
Object GetService(Activity currentActivity, Type serviceType);
|
||||
void PersistInstanceState(Activity activity);
|
||||
|
||||
//Dynamic change notifications
|
||||
bool OnBeforeDynamicChange(IList<WorkflowChangeAction> changes);
|
||||
void OnAfterDynamicChange(bool updateSucceeded, IList<WorkflowChangeAction> changes);
|
||||
bool IsDynamicallyUpdated { get; }
|
||||
|
||||
// root level access
|
||||
Guid InstanceID { get; }
|
||||
bool SuspendInstance(string suspendDescription);
|
||||
void TerminateInstance(Exception e);
|
||||
bool Resume();
|
||||
void CheckpointInstanceState(Activity currentActivity);
|
||||
void RequestRevertToCheckpointState(Activity currentActivity, EventHandler<EventArgs> callbackHandler, EventArgs callbackData, bool suspendOnRevert, string suspendReason);
|
||||
void DisposeCheckpointState();
|
||||
|
||||
// User Tracking
|
||||
void Track(string key, object data);
|
||||
|
||||
// Timer Events
|
||||
WaitCallback ProcessTimersCallback { get; }
|
||||
}
|
||||
|
||||
internal interface ITimerService
|
||||
{
|
||||
void ScheduleTimer(WaitCallback callback, Guid workflowInstanceId, DateTime whenUtc, Guid timerId);
|
||||
void CancelTimer(Guid timerId);
|
||||
}
|
||||
|
||||
[Serializable()]
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public sealed class WorkflowTerminatedException : Exception
|
||||
{
|
||||
private WorkflowTerminatedException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
|
||||
public WorkflowTerminatedException()
|
||||
: base(SR.GetString(SR.Error_WorkflowTerminated))
|
||||
{
|
||||
}
|
||||
|
||||
public WorkflowTerminatedException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
public WorkflowTerminatedException(string message, Exception exception)
|
||||
: base(message, exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public interface ICompensatableActivity
|
||||
{
|
||||
ActivityExecutionStatus Compensate(ActivityExecutionContext executionContext);
|
||||
}
|
||||
|
||||
#region Class AlternateFlowActivityAttribute
|
||||
|
||||
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = false)]
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public sealed class AlternateFlowActivityAttribute : Attribute
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Class SupportsTransactionAttribute
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
|
||||
internal sealed class SupportsTransactionAttribute : Attribute
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Class SupportsSynchronizationAttribute
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
|
||||
internal sealed class SupportsSynchronizationAttribute : Attribute
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Class PersistOnCloseAttribute
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public sealed class PersistOnCloseAttribute : Attribute
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
namespace System.Workflow.ComponentModel
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
[Serializable]
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public sealed class ActivityExecutionStatusChangedEventArgs : EventArgs
|
||||
{
|
||||
private ActivityExecutionStatus status = ActivityExecutionStatus.Initialized;
|
||||
private ActivityExecutionResult activityExecutionResult = ActivityExecutionResult.None;
|
||||
private string activityQualifiedName = null;
|
||||
private int stateId = -1;
|
||||
|
||||
[NonSerialized]
|
||||
private IWorkflowCoreRuntime workflowCoreRuntime = null;
|
||||
|
||||
internal ActivityExecutionStatusChangedEventArgs(ActivityExecutionStatus executionStatus, ActivityExecutionResult executionResult, Activity activity)
|
||||
{
|
||||
this.status = executionStatus;
|
||||
this.activityExecutionResult = executionResult;
|
||||
this.activityQualifiedName = activity.QualifiedName;
|
||||
this.stateId = activity.ContextActivity.ContextId;
|
||||
}
|
||||
|
||||
public ActivityExecutionStatus ExecutionStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.status;
|
||||
}
|
||||
}
|
||||
public ActivityExecutionResult ExecutionResult
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.activityExecutionResult;
|
||||
}
|
||||
}
|
||||
public Activity Activity
|
||||
{
|
||||
get
|
||||
{
|
||||
Activity activity = null;
|
||||
if (this.workflowCoreRuntime != null)
|
||||
{
|
||||
Activity contextActivity = this.workflowCoreRuntime.GetContextActivityForId(this.stateId);
|
||||
if (contextActivity != null)
|
||||
activity = contextActivity.GetActivityByName(this.activityQualifiedName);
|
||||
}
|
||||
return activity;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
internal IWorkflowCoreRuntime BaseExecutor
|
||||
{
|
||||
set
|
||||
{
|
||||
this.workflowCoreRuntime = value;
|
||||
}
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return "ActivityStatusChange('" + "(" + this.stateId.ToString(CultureInfo.CurrentCulture) + ")" + this.activityQualifiedName + "', " + Activity.ActivityExecutionStatusEnumToString(this.ExecutionStatus) + ", " + Activity.ActivityExecutionResultEnumToString(this.ExecutionResult) + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Workflow.ComponentModel.Serialization;
|
||||
|
||||
[assembly: InternalsVisibleTo("System.Workflow.Runtime, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
|
||||
[assembly: InternalsVisibleTo("System.WorkflowServices, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
|
||||
[assembly: InternalsVisibleTo("Microsoft.Workflow.Compiler, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
|
||||
[assembly: InternalsVisibleTo("System.ServiceModel.Activities, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
|
||||
|
||||
[assembly: XmlnsDefinition(StandardXomlKeys.WorkflowXmlNs, "System.Workflow.ComponentModel")]
|
||||
[assembly: XmlnsDefinition(StandardXomlKeys.WorkflowXmlNs, "System.Workflow.ComponentModel.Compiler")]
|
||||
[assembly: XmlnsDefinition(StandardXomlKeys.Definitions_XmlNs, "System.Workflow.ComponentModel.Serialization")]
|
||||
[assembly: XmlnsDefinition(StandardXomlKeys.WorkflowXmlNs, "System.Workflow.ComponentModel.Design")]
|
||||
|
||||
[assembly: XmlnsPrefix(StandardXomlKeys.WorkflowXmlNs, StandardXomlKeys.WorkflowPrefix)]
|
||||
[assembly: XmlnsPrefix(StandardXomlKeys.Definitions_XmlNs, StandardXomlKeys.Definitions_XmlNs_Prefix)]
|
||||
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.Activity.#ActivityContextGuidProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.Activity.#CancelingEvent")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.Activity.#ClosedEvent")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.Activity.#CompensatingEvent")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.Activity.#ExecutingEvent")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.Activity.#FaultingEvent")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.Activity.#StatusChangedEvent")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.ActivityExecutionContext.#CurrentExceptionProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.CompensateActivity.#TargetActivityNameProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.FaultHandlerActivity.#FaultTypeProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.SuspendActivity.#ErrorProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.TerminateActivity.#ErrorProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.ThrowActivity.#FaultProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.ThrowActivity.#FaultTypeProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.WorkflowChanges.#ConditionProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.WorkflowParameterBinding.#ParameterNameProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.WorkflowParameterBinding.#ValueProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.WorkflowTransactionOptions.#IsolationLevelProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.WorkflowTransactionOptions.#TimeoutDurationProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.Serialization.ActivityCodeDomSerializer.#MarkupFileNameProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.Serialization.ActivityMarkupSerializer.#EndColumnProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.Serialization.ActivityMarkupSerializer.#EndLineProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.Serialization.ActivityMarkupSerializer.#StartColumnProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.Serialization.ActivityMarkupSerializer.#StartLineProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.Serialization.WorkflowMarkupSerializer.#ClrNamespacesProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.Serialization.WorkflowMarkupSerializer.#EventsProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.Serialization.WorkflowMarkupSerializer.#XClassProperty")]
|
||||
[module: SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "System.Workflow.ComponentModel.Serialization.WorkflowMarkupSerializer.#XCodeProperty")]
|
||||
@@ -0,0 +1,83 @@
|
||||
namespace System.Workflow.ComponentModel
|
||||
{
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.ComponentModel;
|
||||
using System.Collections;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Workflow.ComponentModel.Design;
|
||||
using System.Workflow.ComponentModel.Compiler;
|
||||
|
||||
|
||||
[ToolboxItem(false)]
|
||||
[Designer(typeof(CancellationHandlerActivityDesigner), typeof(IDesigner))]
|
||||
[ToolboxBitmap(typeof(CancellationHandlerActivity), "Resources.CancellationHandler.bmp")]
|
||||
[ActivityValidator(typeof(CancellationHandlerValidator))]
|
||||
[AlternateFlowActivity]
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public sealed class CancellationHandlerActivity : CompositeActivity, IActivityEventListener<ActivityExecutionStatusChangedEventArgs>
|
||||
{
|
||||
public CancellationHandlerActivity()
|
||||
{
|
||||
}
|
||||
|
||||
public CancellationHandlerActivity(string name)
|
||||
: base(name)
|
||||
{
|
||||
}
|
||||
|
||||
protected internal override void Initialize(IServiceProvider provider)
|
||||
{
|
||||
if (this.Parent == null)
|
||||
throw new InvalidOperationException(SR.GetString(SR.Error_MustHaveParent));
|
||||
|
||||
base.Initialize(provider);
|
||||
}
|
||||
|
||||
protected internal override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
|
||||
{
|
||||
return SequenceHelper.Execute(this, executionContext);
|
||||
}
|
||||
|
||||
protected internal override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
|
||||
{
|
||||
return SequenceHelper.Cancel(this, executionContext);
|
||||
}
|
||||
|
||||
void IActivityEventListener<ActivityExecutionStatusChangedEventArgs>.OnEvent(Object sender, ActivityExecutionStatusChangedEventArgs e)
|
||||
{
|
||||
SequenceHelper.OnEvent(this, sender, e);
|
||||
}
|
||||
|
||||
protected internal override void OnActivityChangeRemove(ActivityExecutionContext executionContext, Activity removedActivity)
|
||||
{
|
||||
SequenceHelper.OnActivityChangeRemove(this, executionContext, removedActivity);
|
||||
}
|
||||
|
||||
protected internal override void OnWorkflowChangesCompleted(ActivityExecutionContext executionContext)
|
||||
{
|
||||
SequenceHelper.OnWorkflowChangesCompleted(this, executionContext);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class CancellationHandlerValidator : CompositeActivityValidator
|
||||
{
|
||||
public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
|
||||
{
|
||||
ValidationErrorCollection validationErrors = base.Validate(manager, obj);
|
||||
|
||||
CancellationHandlerActivity cancellationHandlerActivity = obj as CancellationHandlerActivity;
|
||||
if (cancellationHandlerActivity == null)
|
||||
throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(CancellationHandlerActivity).FullName), "obj");
|
||||
|
||||
if (cancellationHandlerActivity.EnabledActivities.Count == 0)
|
||||
validationErrors.Add(new ValidationError(SR.GetString(SR.Warning_EmptyBehaviourActivity, typeof(CancellationHandlerActivity).FullName, cancellationHandlerActivity.QualifiedName), ErrorNumbers.Warning_EmptyBehaviourActivity, true));
|
||||
|
||||
// cancellation handlers can not contain fault handlers, compensation handler and cancellation handler
|
||||
if (((ISupportAlternateFlow)cancellationHandlerActivity).AlternateFlowActivities.Count > 0)
|
||||
validationErrors.Add(new ValidationError(SR.GetString(SR.Error_ModelingConstructsCanNotContainModelingConstructs), ErrorNumbers.Error_ModelingConstructsCanNotContainModelingConstructs));
|
||||
|
||||
return validationErrors;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
namespace System.Workflow.ComponentModel.Design
|
||||
{
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Collections;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Workflow.ComponentModel.Design;
|
||||
|
||||
[ActivityDesignerTheme(typeof(CancellationDesignerTheme))]
|
||||
internal sealed class CancellationHandlerActivityDesigner : SequentialActivityDesigner
|
||||
{
|
||||
#region Properties and Methods
|
||||
public override bool CanExpandCollapse
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public override ReadOnlyCollection<DesignerView> Views
|
||||
{
|
||||
get
|
||||
{
|
||||
List<DesignerView> views = new List<DesignerView>();
|
||||
foreach (DesignerView view in base.Views)
|
||||
{
|
||||
// disable the fault handlers, cancellation handler and compensation handler
|
||||
if ((view.ViewId != 2) &&
|
||||
(view.ViewId != 3) &&
|
||||
(view.ViewId != 4)
|
||||
)
|
||||
views.Add(view);
|
||||
}
|
||||
return new ReadOnlyCollection<DesignerView>(views);
|
||||
}
|
||||
}
|
||||
public override bool CanInsertActivities(HitTestInfo insertLocation, ReadOnlyCollection<Activity> activitiesToInsert)
|
||||
{
|
||||
foreach (Activity activity in activitiesToInsert)
|
||||
{
|
||||
if (Helpers.IsFrameworkActivity(activity))
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.CanInsertActivities(insertLocation, activitiesToInsert);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region CompensationDesignerTheme
|
||||
internal sealed class CancellationDesignerTheme : CompositeDesignerTheme
|
||||
{
|
||||
public CancellationDesignerTheme(WorkflowTheme theme)
|
||||
: base(theme)
|
||||
{
|
||||
this.ShowDropShadow = false;
|
||||
this.ConnectorStartCap = LineAnchor.None;
|
||||
this.ConnectorEndCap = LineAnchor.ArrowAnchor;
|
||||
this.ForeColor = Color.FromArgb(0xFF, 0x00, 0x00, 0x00);
|
||||
this.BorderColor = Color.FromArgb(0xFF, 0xE0, 0xE0, 0xE0);
|
||||
this.BorderStyle = DashStyle.Dash;
|
||||
this.BackColorStart = Color.FromArgb(0x35, 0xFF, 0xB0, 0x90);
|
||||
this.BackColorEnd = Color.FromArgb(0x35, 0xFF, 0xB0, 0x90);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
namespace System.Workflow.ComponentModel
|
||||
{
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Drawing;
|
||||
using System.Workflow.ComponentModel;
|
||||
using System.Workflow.ComponentModel.Design;
|
||||
using System.Workflow.ComponentModel.Compiler;
|
||||
|
||||
#endregion
|
||||
|
||||
[SRDescription(SR.CompensatableTransactionalContextActivityDescription)]
|
||||
[ToolboxItem(typeof(ActivityToolboxItem))]
|
||||
[ToolboxBitmap(typeof(CompensatableTransactionScopeActivity), "Resources.Sequence.png")]
|
||||
[Designer(typeof(CompensatableTransactionScopeActivityDesigner), typeof(IDesigner))]
|
||||
[PersistOnClose]
|
||||
[SupportsTransaction]
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public sealed class CompensatableTransactionScopeActivity : CompositeActivity, IActivityEventListener<ActivityExecutionStatusChangedEventArgs>, ICompensatableActivity
|
||||
{
|
||||
internal static readonly DependencyProperty TransactionOptionsProperty = DependencyProperty.Register("TransactionOptions", typeof(WorkflowTransactionOptions), typeof(CompensatableTransactionScopeActivity), new PropertyMetadata(DependencyPropertyOptions.Metadata, new Attribute[] { new DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content) }));
|
||||
public CompensatableTransactionScopeActivity()
|
||||
{
|
||||
this.SetValueBase(TransactionOptionsProperty, new WorkflowTransactionOptions());
|
||||
}
|
||||
|
||||
public CompensatableTransactionScopeActivity(string name)
|
||||
: base(name)
|
||||
{
|
||||
this.SetValueBase(TransactionOptionsProperty, new WorkflowTransactionOptions());
|
||||
}
|
||||
|
||||
//[SRDisplayName(SR.Transaction)]
|
||||
[SRDescription(SR.TransactionDesc)]
|
||||
[MergableProperty(false)]
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
|
||||
[ReadOnly(true)]
|
||||
public WorkflowTransactionOptions TransactionOptions
|
||||
{
|
||||
get
|
||||
{
|
||||
return (WorkflowTransactionOptions)this.GetValue(TransactionOptionsProperty);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
SetValue(TransactionOptionsProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
protected internal override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
|
||||
{
|
||||
return SequenceHelper.Execute(this, executionContext);
|
||||
}
|
||||
|
||||
protected internal override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
|
||||
{
|
||||
return SequenceHelper.Cancel(this, executionContext);
|
||||
}
|
||||
|
||||
void IActivityEventListener<ActivityExecutionStatusChangedEventArgs>.OnEvent(Object sender, ActivityExecutionStatusChangedEventArgs e)
|
||||
{
|
||||
SequenceHelper.OnEvent(this, sender, e);
|
||||
}
|
||||
|
||||
protected internal override void OnActivityChangeRemove(ActivityExecutionContext executionContext, Activity removedActivity)
|
||||
{
|
||||
SequenceHelper.OnActivityChangeRemove(this, executionContext, removedActivity);
|
||||
}
|
||||
|
||||
protected internal override void OnWorkflowChangesCompleted(ActivityExecutionContext executionContext)
|
||||
{
|
||||
SequenceHelper.OnWorkflowChangesCompleted(this, executionContext);
|
||||
}
|
||||
|
||||
ActivityExecutionStatus ICompensatableActivity.Compensate(ActivityExecutionContext executionContext)
|
||||
{
|
||||
return ActivityExecutionStatus.Closed;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
namespace System.Workflow.ComponentModel.Design
|
||||
{
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Workflow.ComponentModel.Design;
|
||||
|
||||
|
||||
#region Class CompensatableTransactionScopeActivityDesigner
|
||||
|
||||
internal sealed class CompensatableTransactionScopeActivityDesigner : SequenceDesigner
|
||||
{
|
||||
public override ReadOnlyCollection<DesignerView> Views
|
||||
{
|
||||
get
|
||||
{
|
||||
List<DesignerView> views = new List<DesignerView>();
|
||||
foreach (DesignerView view in base.Views)
|
||||
{
|
||||
// disable the exceptions view and cancellation handler view
|
||||
Type activityType = view.UserData[SecondaryView.UserDataKey_ActivityType] as Type;
|
||||
if (activityType != null &&
|
||||
!typeof(CancellationHandlerActivity).IsAssignableFrom(activityType) &&
|
||||
!typeof(FaultHandlersActivity).IsAssignableFrom(activityType))
|
||||
{
|
||||
views.Add(view);
|
||||
}
|
||||
}
|
||||
return new ReadOnlyCollection<DesignerView>(views);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
namespace System.Workflow.ComponentModel
|
||||
{
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.ComponentModel;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Workflow.ComponentModel;
|
||||
using System.Workflow.ComponentModel.Design;
|
||||
using System.Workflow.ComponentModel.Compiler;
|
||||
|
||||
[SRDescription(SR.CompensateActivityDescription)]
|
||||
[ToolboxItem(typeof(ActivityToolboxItem))]
|
||||
[Designer(typeof(CompensateDesigner), typeof(IDesigner))]
|
||||
[ToolboxBitmap(typeof(CompensateActivity), "Resources.Compensate.png")]
|
||||
[ActivityValidator(typeof(CompensateValidator))]
|
||||
[SRCategory(SR.Standard)]
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public sealed class CompensateActivity : Activity, IPropertyValueProvider, IActivityEventListener<ActivityExecutionStatusChangedEventArgs>
|
||||
{
|
||||
public CompensateActivity()
|
||||
{
|
||||
}
|
||||
public CompensateActivity(string name)
|
||||
: base(name)
|
||||
{
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty TargetActivityNameProperty = DependencyProperty.Register("TargetActivityName", typeof(string), typeof(CompensateActivity), new PropertyMetadata("", DependencyPropertyOptions.Metadata));
|
||||
|
||||
[SRCategory(SR.Activity)]
|
||||
[SRDescription(SR.CompensatableActivityDescr)]
|
||||
[TypeConverter(typeof(PropertyValueProviderTypeConverter))]
|
||||
[MergableProperty(false)]
|
||||
[DefaultValue("")]
|
||||
public string TargetActivityName
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.GetValue(TargetActivityNameProperty) as string;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.SetValue(TargetActivityNameProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
#region Protected Methods
|
||||
protected internal override void Initialize(IServiceProvider provider)
|
||||
{
|
||||
if (this.Parent == null)
|
||||
throw new InvalidOperationException(SR.GetString(SR.Error_MustHaveParent));
|
||||
|
||||
base.Initialize(provider);
|
||||
}
|
||||
|
||||
protected internal override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
|
||||
{
|
||||
if (executionContext == null)
|
||||
throw new ArgumentNullException("executionContext");
|
||||
|
||||
return CompensateTargetActivity(executionContext);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IActivityEventListener<ActivityExecutionStatusChangedEventArgs> Members
|
||||
void IActivityEventListener<ActivityExecutionStatusChangedEventArgs>.OnEvent(object sender, ActivityExecutionStatusChangedEventArgs e)
|
||||
{
|
||||
if (sender == null)
|
||||
throw new ArgumentNullException("sender");
|
||||
|
||||
if (e == null)
|
||||
throw new ArgumentNullException("e");
|
||||
|
||||
ActivityExecutionContext context = sender as ActivityExecutionContext;
|
||||
if (context == null)
|
||||
throw new ArgumentException(SR.Error_SenderMustBeActivityExecutionContext, "sender");
|
||||
|
||||
if (e.ExecutionStatus == ActivityExecutionStatus.Closed)
|
||||
{
|
||||
// Remove status change subscription.
|
||||
e.Activity.UnregisterForStatusChange(Activity.ClosedEvent, this);
|
||||
|
||||
// Do it again if there are any more.
|
||||
ActivityExecutionStatus status = CompensateTargetActivity(context);
|
||||
if (status == ActivityExecutionStatus.Closed)
|
||||
context.CloseActivity();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Execution Helpers
|
||||
private ActivityExecutionStatus CompensateTargetActivity(ActivityExecutionContext context)
|
||||
{
|
||||
Activity targetActivity = null;
|
||||
Activity commonParentActivity = context.Activity;
|
||||
do
|
||||
{
|
||||
commonParentActivity = commonParentActivity.Parent;
|
||||
targetActivity = commonParentActivity.GetActivityByName(this.TargetActivityName, true);
|
||||
} while (targetActivity == null);
|
||||
|
||||
if (targetActivity is ICompensatableActivity &&
|
||||
targetActivity.ExecutionStatus == ActivityExecutionStatus.Closed &&
|
||||
targetActivity.ExecutionResult == ActivityExecutionResult.Succeeded)
|
||||
{
|
||||
// same execution context
|
||||
targetActivity.RegisterForStatusChange(Activity.ClosedEvent, this);
|
||||
context.CompensateActivity(targetActivity);
|
||||
return context.Activity.ExecutionStatus;
|
||||
}
|
||||
else if (targetActivity.ExecutionStatus == ActivityExecutionStatus.Initialized)
|
||||
{
|
||||
// Template activity
|
||||
|
||||
// walk through active contexts
|
||||
ActivityExecutionContextManager contextManager = context.ExecutionContextManager;
|
||||
foreach (ActivityExecutionContext activeContext in contextManager.ExecutionContexts)
|
||||
{
|
||||
if (targetActivity.GetActivityByName(activeContext.Activity.QualifiedName, true) != null)
|
||||
{
|
||||
if (activeContext.Activity.ExecutionStatus == ActivityExecutionStatus.Compensating ||
|
||||
activeContext.Activity.ExecutionStatus == ActivityExecutionStatus.Faulting ||
|
||||
activeContext.Activity.ExecutionStatus == ActivityExecutionStatus.Canceling
|
||||
)
|
||||
return context.Activity.ExecutionStatus;
|
||||
}
|
||||
}
|
||||
|
||||
// walk through all completed execution contexts
|
||||
for (int index = contextManager.CompletedExecutionContexts.Count - 1; index >= 0; index--)
|
||||
{
|
||||
//only compensate direct child during explicit compensation
|
||||
ActivityExecutionContextInfo completedActivityInfo = contextManager.CompletedExecutionContexts[index];
|
||||
if (((completedActivityInfo.Flags & PersistFlags.NeedsCompensation) != 0))
|
||||
{
|
||||
ActivityExecutionContext revokedExecutionContext = contextManager.DiscardPersistedExecutionContext(completedActivityInfo);
|
||||
if (revokedExecutionContext.Activity is ICompensatableActivity)
|
||||
{
|
||||
revokedExecutionContext.Activity.RegisterForStatusChange(Activity.ClosedEvent, this);
|
||||
revokedExecutionContext.CompensateActivity(revokedExecutionContext.Activity);
|
||||
}
|
||||
return context.Activity.ExecutionStatus;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// currently faulting, canceling, or compensating
|
||||
if (CompensationUtils.TryCompensateLastCompletedChildActivity(context, targetActivity, this))
|
||||
return context.Activity.ExecutionStatus;
|
||||
}
|
||||
return ActivityExecutionStatus.Closed;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IPropertyValueProvider Members
|
||||
|
||||
ICollection IPropertyValueProvider.GetPropertyValues(ITypeDescriptorContext context)
|
||||
{
|
||||
if (context == null)
|
||||
throw new ArgumentNullException("context");
|
||||
return GetCompensatableTargets(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Validation Helpers
|
||||
internal static StringCollection GetCompensatableTargets(CompensateActivity compensate)
|
||||
{
|
||||
StringCollection targetList = new StringCollection();
|
||||
CompositeActivity parent = compensate.Parent;
|
||||
while (parent != null)
|
||||
{
|
||||
if ((parent is CompensationHandlerActivity) || (parent is FaultHandlersActivity) || (parent is CancellationHandlerActivity))
|
||||
{
|
||||
parent = parent.Parent;
|
||||
if (parent != null)
|
||||
{
|
||||
if (Helpers.IsCustomActivity(parent))
|
||||
targetList.Add(parent.UserData[UserDataKeys.CustomActivityDefaultName] as string);
|
||||
else
|
||||
targetList.Add(parent.Name);
|
||||
|
||||
foreach (Activity activity in parent.EnabledActivities)
|
||||
{
|
||||
if (activity is ICompensatableActivity)
|
||||
targetList.Add(activity.Name);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
parent = parent.Parent;
|
||||
}
|
||||
return targetList;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region Validator
|
||||
internal sealed class CompensateValidator : ActivityValidator
|
||||
{
|
||||
public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
|
||||
{
|
||||
ValidationErrorCollection validationErrors = base.Validate(manager, obj);
|
||||
|
||||
CompensateActivity compensate = obj as CompensateActivity;
|
||||
if (compensate == null)
|
||||
throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(CompensateActivity).FullName), "obj");
|
||||
|
||||
// Compensate must be in a CompensationHandler or FaultHandler
|
||||
CompositeActivity parent = compensate.Parent;
|
||||
while (parent != null)
|
||||
{
|
||||
if (parent is CompensationHandlerActivity || parent is FaultHandlerActivity || parent is CancellationHandlerActivity)
|
||||
break;
|
||||
|
||||
parent = parent.Parent;
|
||||
}
|
||||
|
||||
if (parent == null)
|
||||
validationErrors.Add(new ValidationError(SR.GetString(SR.Error_CompensateBadNesting), ErrorNumbers.Error_CompensateBadNesting));
|
||||
|
||||
ValidationError error = null;
|
||||
StringCollection targets = CompensateActivity.GetCompensatableTargets(compensate);
|
||||
if (String.IsNullOrEmpty(compensate.TargetActivityName))
|
||||
{
|
||||
error = ValidationError.GetNotSetValidationError("TargetActivityName");
|
||||
}
|
||||
else if (!targets.Contains(compensate.TargetActivityName))
|
||||
{
|
||||
error = new ValidationError(SR.GetString(SR.Error_CompensateBadTargetTX, "TargetActivityName", compensate.TargetActivityName, compensate.QualifiedName), ErrorNumbers.Error_CompensateBadTargetTX, false, "TargetActivityName");
|
||||
}
|
||||
if (error != null)
|
||||
validationErrors.Add(error);
|
||||
|
||||
return validationErrors;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
namespace System.Workflow.ComponentModel
|
||||
{
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.CodeDom;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Diagnostics;
|
||||
using System.Workflow.ComponentModel;
|
||||
using System.Workflow.ComponentModel.Design;
|
||||
|
||||
#region Class CompensateDesigner
|
||||
[ActivityDesignerTheme(typeof(CompensateDesignerTheme))]
|
||||
internal sealed class CompensateDesigner : ActivityDesigner
|
||||
{
|
||||
#region Properties and Methods
|
||||
public override bool CanBeParentedTo(CompositeActivityDesigner parentActivityDesigner)
|
||||
{
|
||||
Activity parentActivity = parentActivityDesigner.Activity;
|
||||
while (parentActivity != null)
|
||||
{
|
||||
if (parentActivity is CancellationHandlerActivity || parentActivity is CompensationHandlerActivity || parentActivity is FaultHandlerActivity)
|
||||
return true;
|
||||
|
||||
parentActivity = parentActivity.Parent;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CompensateDesignerTheme
|
||||
internal sealed class CompensateDesignerTheme : ActivityDesignerTheme
|
||||
{
|
||||
public CompensateDesignerTheme(WorkflowTheme theme)
|
||||
: base(theme)
|
||||
{
|
||||
this.ForeColor = Color.FromArgb(0xFF, 0x00, 0x00, 0x00);
|
||||
this.BorderColor = Color.FromArgb(0xFF, 0x73, 0x51, 0x08);
|
||||
this.BorderStyle = DashStyle.Solid;
|
||||
this.BackColorStart = Color.FromArgb(0xFF, 0xF7, 0xF7, 0x9C);
|
||||
this.BackColorEnd = Color.FromArgb(0xFF, 0xDE, 0xAA, 0x00);
|
||||
this.BackgroundStyle = LinearGradientMode.Horizontal;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
namespace System.Workflow.ComponentModel
|
||||
{
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.ComponentModel;
|
||||
using System.Collections;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Workflow.ComponentModel.Design;
|
||||
using System.Workflow.ComponentModel.Compiler;
|
||||
|
||||
|
||||
[ToolboxItem(false)]
|
||||
[Designer(typeof(CompensationHandlerActivityDesigner), typeof(IDesigner))]
|
||||
[ToolboxBitmap(typeof(CompensationHandlerActivity), "Resources.Compensation.png")]
|
||||
[ActivityValidator(typeof(CompensationValidator))]
|
||||
[AlternateFlowActivityAttribute]
|
||||
[SRCategory(SR.Standard)]
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public sealed class CompensationHandlerActivity : CompositeActivity, IActivityEventListener<ActivityExecutionStatusChangedEventArgs>
|
||||
{
|
||||
public CompensationHandlerActivity()
|
||||
{
|
||||
}
|
||||
|
||||
public CompensationHandlerActivity(string name)
|
||||
: base(name)
|
||||
{
|
||||
}
|
||||
|
||||
protected internal override void Initialize(IServiceProvider provider)
|
||||
{
|
||||
if (this.Parent == null)
|
||||
throw new InvalidOperationException(SR.GetString(SR.Error_MustHaveParent));
|
||||
|
||||
base.Initialize(provider);
|
||||
}
|
||||
|
||||
protected internal override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
|
||||
{
|
||||
return SequenceHelper.Execute(this, executionContext);
|
||||
}
|
||||
|
||||
protected internal override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
|
||||
{
|
||||
return SequenceHelper.Cancel(this, executionContext);
|
||||
}
|
||||
|
||||
void IActivityEventListener<ActivityExecutionStatusChangedEventArgs>.OnEvent(Object sender, ActivityExecutionStatusChangedEventArgs e)
|
||||
{
|
||||
SequenceHelper.OnEvent(this, sender, e);
|
||||
}
|
||||
|
||||
protected internal override void OnActivityChangeRemove(ActivityExecutionContext executionContext, Activity removedActivity)
|
||||
{
|
||||
SequenceHelper.OnActivityChangeRemove(this, executionContext, removedActivity);
|
||||
}
|
||||
|
||||
protected internal override void OnWorkflowChangesCompleted(ActivityExecutionContext executionContext)
|
||||
{
|
||||
SequenceHelper.OnWorkflowChangesCompleted(this, executionContext);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class CompensationValidator : CompositeActivityValidator
|
||||
{
|
||||
public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
|
||||
{
|
||||
ValidationErrorCollection validationErrors = base.Validate(manager, obj);
|
||||
|
||||
CompensationHandlerActivity compensation = obj as CompensationHandlerActivity;
|
||||
if (compensation == null)
|
||||
throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(CompensationHandlerActivity).FullName), "obj");
|
||||
|
||||
// check parent must be compensatable
|
||||
if (!(compensation.Parent is ICompensatableActivity))
|
||||
validationErrors.Add(new ValidationError(SR.GetString(SR.Error_ParentDoesNotSupportCompensation), ErrorNumbers.Error_FaultHandlerActivityParentNotFaultHandlersActivity));
|
||||
|
||||
if (compensation.EnabledActivities.Count == 0)
|
||||
validationErrors.Add(new ValidationError(SR.GetString(SR.Warning_EmptyBehaviourActivity, typeof(CompensationHandlerActivity).FullName, compensation.QualifiedName), ErrorNumbers.Warning_EmptyBehaviourActivity, true));
|
||||
|
||||
// compensation handlers can not contain fault handlers, compensation handler and cancellation handler
|
||||
else if (((ISupportAlternateFlow)compensation).AlternateFlowActivities.Count > 0)
|
||||
validationErrors.Add(new ValidationError(SR.GetString(SR.Error_ModelingConstructsCanNotContainModelingConstructs), ErrorNumbers.Error_ModelingConstructsCanNotContainModelingConstructs));
|
||||
|
||||
return validationErrors;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
namespace System.Workflow.ComponentModel.Design
|
||||
{
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Collections;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Workflow.ComponentModel.Design;
|
||||
|
||||
|
||||
#region CompensationDesigner
|
||||
[ActivityDesignerTheme(typeof(CompensationDesignerTheme))]
|
||||
internal sealed class CompensationHandlerActivityDesigner : SequentialActivityDesigner
|
||||
{
|
||||
#region Members, Constructor and Destructor
|
||||
public override ReadOnlyCollection<DesignerView> Views
|
||||
{
|
||||
get
|
||||
{
|
||||
List<DesignerView> views = new List<DesignerView>();
|
||||
foreach (DesignerView view in base.Views)
|
||||
{
|
||||
// disable the fault handlers, cancellation handler and compensation handler
|
||||
if ((view.ViewId != 2) &&
|
||||
(view.ViewId != 3) &&
|
||||
(view.ViewId != 4)
|
||||
)
|
||||
views.Add(view);
|
||||
}
|
||||
return new ReadOnlyCollection<DesignerView>(views);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties and Methods
|
||||
public override bool CanExpandCollapse
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public override bool CanInsertActivities(HitTestInfo insertLocation, ReadOnlyCollection<Activity> activitiesToInsert)
|
||||
{
|
||||
foreach (Activity activity in activitiesToInsert)
|
||||
{
|
||||
if (Helpers.IsFrameworkActivity(activity))
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.CanInsertActivities(insertLocation, activitiesToInsert);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CompensationDesignerTheme
|
||||
internal sealed class CompensationDesignerTheme : CompositeDesignerTheme
|
||||
{
|
||||
public CompensationDesignerTheme(WorkflowTheme theme)
|
||||
: base(theme)
|
||||
{
|
||||
this.ShowDropShadow = false;
|
||||
this.ConnectorStartCap = LineAnchor.None;
|
||||
this.ConnectorEndCap = LineAnchor.ArrowAnchor;
|
||||
this.ForeColor = Color.FromArgb(0xFF, 0x00, 0x00, 0x00);
|
||||
this.BorderColor = Color.FromArgb(0xFF, 0xE0, 0xE0, 0xE0);
|
||||
this.BorderStyle = DashStyle.Dash;
|
||||
this.BackColorStart = Color.FromArgb(0x35, 0xB0, 0xE0, 0xFF);
|
||||
this.BackColorEnd = Color.FromArgb(0x35, 0xB0, 0xE0, 0xFF);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
namespace System.Workflow.ComponentModel
|
||||
{
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.CodeDom;
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing.Design;
|
||||
using System.ComponentModel.Design;
|
||||
using System.ComponentModel.Design.Serialization;
|
||||
using System.Workflow.ComponentModel.Design;
|
||||
using System.Workflow.ComponentModel.Compiler;
|
||||
|
||||
#endregion
|
||||
|
||||
[SRDescription(SR.FaultHandlerActivityDescription)]
|
||||
[ToolboxItem(typeof(ActivityToolboxItem))]
|
||||
[ToolboxBitmap(typeof(FaultHandlerActivity), "Resources.Exception.png")]
|
||||
[SRCategory(SR.Standard)]
|
||||
[Designer(typeof(FaultHandlerActivityDesigner), typeof(IDesigner))]
|
||||
[ActivityValidator(typeof(FaultHandlerActivityValidator))]
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public sealed class FaultHandlerActivity : CompositeActivity, IActivityEventListener<ActivityExecutionStatusChangedEventArgs>, ITypeFilterProvider, IDynamicPropertyTypeProvider
|
||||
{
|
||||
public static readonly DependencyProperty FaultTypeProperty = DependencyProperty.Register("FaultType", typeof(Type), typeof(FaultHandlerActivity), new PropertyMetadata(DependencyPropertyOptions.Metadata));
|
||||
internal static readonly DependencyProperty FaultProperty = DependencyProperty.Register("Fault", typeof(Exception), typeof(FaultHandlerActivity));
|
||||
|
||||
public FaultHandlerActivity()
|
||||
{
|
||||
}
|
||||
|
||||
public FaultHandlerActivity(string name)
|
||||
: base(name)
|
||||
{
|
||||
}
|
||||
|
||||
[Editor(typeof(TypeBrowserEditor), typeof(UITypeEditor))]
|
||||
[SRDescription(SR.ExceptionTypeDescr)]
|
||||
[MergableProperty(false)]
|
||||
public Type FaultType
|
||||
{
|
||||
get
|
||||
{
|
||||
return (Type)base.GetValue(FaultTypeProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
base.SetValue(FaultTypeProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
[SRDescription(SR.FaultDescription)]
|
||||
[MergableProperty(false)]
|
||||
[ReadOnly(true)]
|
||||
public Exception Fault
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.GetValue(FaultProperty) as Exception;
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetException(Exception e)
|
||||
{
|
||||
this.SetValue(FaultProperty, e);
|
||||
}
|
||||
|
||||
protected internal override void Initialize(IServiceProvider provider)
|
||||
{
|
||||
if (this.Parent == null)
|
||||
throw new InvalidOperationException(SR.GetString(SR.Error_MustHaveParent));
|
||||
|
||||
base.Initialize(provider);
|
||||
}
|
||||
|
||||
protected internal override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
|
||||
{
|
||||
return SequenceHelper.Execute(this, executionContext);
|
||||
}
|
||||
|
||||
protected internal override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
|
||||
{
|
||||
return SequenceHelper.Cancel(this, executionContext);
|
||||
}
|
||||
|
||||
void IActivityEventListener<ActivityExecutionStatusChangedEventArgs>.OnEvent(Object sender, ActivityExecutionStatusChangedEventArgs e)
|
||||
{
|
||||
SequenceHelper.OnEvent(this, sender, e);
|
||||
}
|
||||
|
||||
protected internal override void OnActivityChangeRemove(ActivityExecutionContext executionContext, Activity removedActivity)
|
||||
{
|
||||
SequenceHelper.OnActivityChangeRemove(this, executionContext, removedActivity);
|
||||
}
|
||||
|
||||
protected internal override void OnWorkflowChangesCompleted(ActivityExecutionContext executionContext)
|
||||
{
|
||||
SequenceHelper.OnWorkflowChangesCompleted(this, executionContext);
|
||||
}
|
||||
|
||||
#region ITypeFilterProvider Members
|
||||
|
||||
bool ITypeFilterProvider.CanFilterType(Type type, bool throwOnError)
|
||||
{
|
||||
bool isAssignable = TypeProvider.IsAssignable(typeof(Exception), type);
|
||||
|
||||
if (throwOnError && !isAssignable)
|
||||
throw new Exception(SR.GetString(SR.Error_ExceptionTypeNotException, type, "Type"));
|
||||
|
||||
return isAssignable;
|
||||
}
|
||||
|
||||
string ITypeFilterProvider.FilterDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
return SR.GetString(SR.FilterDescription_FaultHandlerActivity);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDynamicPropertyTypeProvider Members
|
||||
Type IDynamicPropertyTypeProvider.GetPropertyType(IServiceProvider serviceProvider, string propertyName)
|
||||
{
|
||||
if (propertyName == null)
|
||||
throw new ArgumentNullException("propertyName");
|
||||
|
||||
Type returnType = null;
|
||||
if (string.Equals(propertyName, "Fault", StringComparison.Ordinal))
|
||||
{
|
||||
returnType = this.FaultType;
|
||||
if (returnType == null)
|
||||
returnType = typeof(Exception);
|
||||
}
|
||||
|
||||
return returnType;
|
||||
}
|
||||
|
||||
AccessTypes IDynamicPropertyTypeProvider.GetAccessType(IServiceProvider serviceProvider, string propertyName)
|
||||
{
|
||||
if (propertyName == null)
|
||||
throw new ArgumentNullException("propertyName");
|
||||
|
||||
if (propertyName.Equals("Fault", StringComparison.Ordinal))
|
||||
return AccessTypes.Write;
|
||||
else
|
||||
return AccessTypes.Read;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
internal sealed class FaultHandlerActivityValidator : CompositeActivityValidator
|
||||
{
|
||||
public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
|
||||
{
|
||||
ValidationErrorCollection validationErrors = base.Validate(manager, obj);
|
||||
|
||||
FaultHandlerActivity exceptionHandler = obj as FaultHandlerActivity;
|
||||
if (exceptionHandler == null)
|
||||
throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(FaultHandlerActivity).FullName), "obj");
|
||||
|
||||
// check parent must be exception handler
|
||||
if (!(exceptionHandler.Parent is FaultHandlersActivity))
|
||||
validationErrors.Add(new ValidationError(SR.GetString(SR.Error_FaultHandlerActivityParentNotFaultHandlersActivity), ErrorNumbers.Error_FaultHandlerActivityParentNotFaultHandlersActivity));
|
||||
|
||||
// validate exception property
|
||||
ITypeProvider typeProvider = manager.GetService(typeof(ITypeProvider)) as ITypeProvider;
|
||||
if (typeProvider == null)
|
||||
throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(ITypeProvider).FullName));
|
||||
|
||||
// Validate the required Type property
|
||||
ValidationError error = null;
|
||||
if (exceptionHandler.FaultType == null)
|
||||
{
|
||||
error = new ValidationError(SR.GetString(SR.Error_TypePropertyInvalid, "FaultType"), ErrorNumbers.Error_PropertyNotSet);
|
||||
error.PropertyName = "FaultType";
|
||||
validationErrors.Add(error);
|
||||
}
|
||||
else if (!TypeProvider.IsAssignable(typeof(Exception), exceptionHandler.FaultType))
|
||||
{
|
||||
error = new ValidationError(SR.GetString(SR.Error_TypeTypeMismatch, new object[] { "FaultType", typeof(Exception).FullName }), ErrorNumbers.Error_TypeTypeMismatch);
|
||||
error.PropertyName = "FaultType";
|
||||
validationErrors.Add(error);
|
||||
}
|
||||
|
||||
// Generate a warning for unrechable code, if the catch type is all and this is not the last exception handler.
|
||||
/*if (exceptionHandler.FaultType == typeof(System.Exception) && exceptionHandler.Parent is FaultHandlersActivity && ((FaultHandlersActivity)exceptionHandler.Parent).Activities.IndexOf(exceptionHandler) != ((FaultHandlersActivity)exceptionHandler.Parent).Activities.Count - 1)
|
||||
{
|
||||
error = new ValidationError(SR.GetString(SR.Error_FaultHandlerActivityAllMustBeLast), ErrorNumbers.Error_FaultHandlerActivityAllMustBeLast, true);
|
||||
error.PropertyName = "FaultType";
|
||||
validationErrors.Add(error);
|
||||
}*/
|
||||
|
||||
if (exceptionHandler.EnabledActivities.Count == 0)
|
||||
validationErrors.Add(new ValidationError(SR.GetString(SR.Warning_EmptyBehaviourActivity, typeof(FaultHandlerActivity).FullName, exceptionHandler.QualifiedName), ErrorNumbers.Warning_EmptyBehaviourActivity, true));
|
||||
|
||||
// fault handler can not contain fault handlers, compensation handler and cancellation handler
|
||||
if (((ISupportAlternateFlow)exceptionHandler).AlternateFlowActivities.Count > 0)
|
||||
validationErrors.Add(new ValidationError(SR.GetString(SR.Error_ModelingConstructsCanNotContainModelingConstructs), ErrorNumbers.Error_ModelingConstructsCanNotContainModelingConstructs));
|
||||
|
||||
return validationErrors;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user