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,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
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.ComponentModel;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Workflow.ComponentModel.Design;
|
||||
|
||||
#region Class FaultHandlerDesigner
|
||||
[ActivityDesignerTheme(typeof(FaultHandlerActivityDesignerTheme))]
|
||||
internal sealed class FaultHandlerActivityDesigner : SequentialActivityDesigner
|
||||
{
|
||||
#region Members, Constructor and Destructor
|
||||
protected override void PreFilterProperties(IDictionary properties)
|
||||
{
|
||||
base.PreFilterProperties(properties);
|
||||
if (properties["InitializeField"] == null)
|
||||
properties["InitializeField"] = TypeDescriptor.CreateProperty(GetType(), "InitializeField", typeof(bool), new Attribute[] { DesignerSerializationVisibilityAttribute.Hidden, BrowsableAttribute.No });
|
||||
}
|
||||
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
|
||||
private bool InitializeField
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override bool CanExpandCollapse
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnActivityChanged(ActivityChangedEventArgs e)
|
||||
{
|
||||
base.OnActivityChanged(e);
|
||||
|
||||
if (e.Member != null && string.Equals(e.Member.Name, "FaultType", StringComparison.Ordinal))
|
||||
TypeDescriptor.Refresh(e.Activity);
|
||||
}
|
||||
|
||||
public override bool CanBeParentedTo(CompositeActivityDesigner parentActivityDesigner)
|
||||
{
|
||||
if (parentActivityDesigner == null)
|
||||
throw new ArgumentNullException("parentActivityDesigner");
|
||||
|
||||
if (!(parentActivityDesigner.Activity is FaultHandlersActivity))
|
||||
return false;
|
||||
|
||||
return base.CanBeParentedTo(parentActivityDesigner);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region FaultHandlerActivityDesignerTheme
|
||||
internal sealed class FaultHandlerActivityDesignerTheme : CompositeDesignerTheme
|
||||
{
|
||||
public FaultHandlerActivityDesignerTheme(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(0x00, 0x00, 0x00, 0x00);
|
||||
this.BackColorEnd = Color.FromArgb(0x00, 0x00, 0x00, 0x00);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
namespace System.Workflow.ComponentModel
|
||||
{
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Drawing;
|
||||
using System.Collections;
|
||||
using System.CodeDom;
|
||||
using System.Globalization;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Workflow.ComponentModel;
|
||||
using System.Workflow.ComponentModel.Design;
|
||||
using System.Workflow.ComponentModel.Compiler;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#endregion
|
||||
|
||||
[ToolboxItem(false)]
|
||||
[Designer(typeof(FaultHandlersActivityDesigner), typeof(IDesigner))]
|
||||
[ToolboxBitmap(typeof(FaultHandlersActivity), "Resources.Exceptions.png")]
|
||||
[ActivityValidator(typeof(FaultHandlersActivityValidator))]
|
||||
[AlternateFlowActivity]
|
||||
[SRCategory(SR.Standard)]
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public sealed class FaultHandlersActivity : CompositeActivity, IActivityEventListener<ActivityExecutionStatusChangedEventArgs>
|
||||
{
|
||||
public FaultHandlersActivity()
|
||||
{
|
||||
}
|
||||
|
||||
public FaultHandlersActivity(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)
|
||||
{
|
||||
if (executionContext == null)
|
||||
throw new ArgumentNullException("executionContext");
|
||||
|
||||
Debug.Assert(this.Parent.GetValue(ActivityExecutionContext.CurrentExceptionProperty) != null, "No Exception contained by parent");
|
||||
|
||||
Exception excep = this.Parent.GetValue(ActivityExecutionContext.CurrentExceptionProperty) as Exception;
|
||||
|
||||
if (excep != null)
|
||||
{
|
||||
Type exceptionType = excep.GetType();
|
||||
|
||||
foreach (FaultHandlerActivity exceptionHandler in this.EnabledActivities)
|
||||
{
|
||||
if (CanHandleException(exceptionHandler, exceptionType))
|
||||
{
|
||||
// remove exception from here, I ate it
|
||||
this.Parent.RemoveProperty(ActivityExecutionContext.CurrentExceptionProperty);
|
||||
exceptionHandler.SetException(excep);
|
||||
exceptionHandler.RegisterForStatusChange(Activity.ClosedEvent, this);
|
||||
executionContext.ExecuteActivity(exceptionHandler);
|
||||
return ActivityExecutionStatus.Executing;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ActivityExecutionStatus.Closed;
|
||||
}
|
||||
|
||||
protected internal override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
|
||||
{
|
||||
if (executionContext == null)
|
||||
throw new ArgumentNullException("executionContext");
|
||||
|
||||
for (int i = 0; i < this.EnabledActivities.Count; ++i)
|
||||
{
|
||||
Activity childActivity = this.EnabledActivities[i];
|
||||
|
||||
if (childActivity.ExecutionStatus == ActivityExecutionStatus.Executing)
|
||||
executionContext.CancelActivity(childActivity);
|
||||
if (childActivity.ExecutionStatus == ActivityExecutionStatus.Canceling ||
|
||||
childActivity.ExecutionStatus == ActivityExecutionStatus.Faulting)
|
||||
return this.ExecutionStatus;
|
||||
}
|
||||
return ActivityExecutionStatus.Closed;
|
||||
}
|
||||
|
||||
#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");
|
||||
|
||||
e.Activity.UnregisterForStatusChange(Activity.ClosedEvent, this);
|
||||
context.CloseActivity();
|
||||
}
|
||||
|
||||
[NonSerialized]
|
||||
bool activeChildRemoved = false;
|
||||
|
||||
protected internal override void OnActivityChangeRemove(ActivityExecutionContext executionContext, Activity removedActivity)
|
||||
{
|
||||
if (removedActivity == null)
|
||||
throw new ArgumentNullException("removedActivity");
|
||||
|
||||
if (executionContext == null)
|
||||
throw new ArgumentNullException("executionContext");
|
||||
|
||||
if (removedActivity.ExecutionStatus == ActivityExecutionStatus.Closed && this.ExecutionStatus != ActivityExecutionStatus.Closed)
|
||||
activeChildRemoved = true;
|
||||
|
||||
base.OnActivityChangeRemove(executionContext, removedActivity);
|
||||
}
|
||||
|
||||
protected internal override void OnWorkflowChangesCompleted(ActivityExecutionContext executionContext)
|
||||
{
|
||||
if (executionContext == null)
|
||||
throw new ArgumentNullException("executionContext");
|
||||
|
||||
if (activeChildRemoved)
|
||||
{
|
||||
executionContext.CloseActivity();
|
||||
activeChildRemoved = false;
|
||||
}
|
||||
base.OnWorkflowChangesCompleted(executionContext);
|
||||
}
|
||||
protected override void OnClosed(IServiceProvider provider)
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
private bool CanHandleException(FaultHandlerActivity exceptionHandler, Type et)
|
||||
{
|
||||
Type canHandleType = exceptionHandler.FaultType;
|
||||
return (et == canHandleType || et.IsSubclassOf(canHandleType));
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class FaultHandlersActivityValidator : CompositeActivityValidator
|
||||
{
|
||||
public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
|
||||
{
|
||||
ValidationErrorCollection validationErrors = base.Validate(manager, obj);
|
||||
|
||||
FaultHandlersActivity exceptionHandlers = obj as FaultHandlersActivity;
|
||||
if (exceptionHandlers == null)
|
||||
throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(FaultHandlersActivity).FullName), "obj");
|
||||
|
||||
Hashtable exceptionTypes = new Hashtable();
|
||||
ArrayList previousExceptionTypes = new ArrayList();
|
||||
bool bFoundNotFaultHandlerActivity = false;
|
||||
foreach (Activity activity in exceptionHandlers.EnabledActivities)
|
||||
{
|
||||
// All child activities must be FaultHandlerActivity
|
||||
if (!(activity is FaultHandlerActivity))
|
||||
{
|
||||
if (!bFoundNotFaultHandlerActivity)
|
||||
{
|
||||
validationErrors.Add(new ValidationError(SR.GetString(SR.Error_FaultHandlersActivityDeclNotAllFaultHandlerActivityDecl), ErrorNumbers.Error_FaultHandlersActivityDeclNotAllFaultHandlerActivityDecl));
|
||||
bFoundNotFaultHandlerActivity = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FaultHandlerActivity exceptionHandler = (FaultHandlerActivity)activity;
|
||||
Type catchType = exceptionHandler.FaultType;
|
||||
if (catchType != null)
|
||||
{
|
||||
if (exceptionTypes[catchType] == null)
|
||||
{
|
||||
exceptionTypes[catchType] = 1;
|
||||
previousExceptionTypes.Add(catchType);
|
||||
}
|
||||
else if ((int)exceptionTypes[catchType] == 1)
|
||||
{
|
||||
/*if (catchType == typeof(System.Exception))
|
||||
validationErrors.Add(new ValidationError(SR.GetString(SR.Error_ScopeDuplicateFaultHandlerActivityForAll, exceptionHandlers.EnclosingDataContextActivity.GetType().Name), ErrorNumbers.Error_ScopeDuplicateFaultHandlerActivityForAll));
|
||||
else*/
|
||||
validationErrors.Add(new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString(SR.Error_ScopeDuplicateFaultHandlerActivityFor), new object[] { Helpers.GetEnclosingActivity(exceptionHandlers).GetType().Name, catchType.FullName }), ErrorNumbers.Error_ScopeDuplicateFaultHandlerActivityFor));
|
||||
|
||||
exceptionTypes[catchType] = 2;
|
||||
}
|
||||
|
||||
foreach (Type previousType in previousExceptionTypes)
|
||||
{
|
||||
if (previousType != catchType && previousType.IsAssignableFrom(catchType))
|
||||
validationErrors.Add(new ValidationError(SR.GetString(SR.Error_FaultHandlerActivityWrongOrder, catchType.Name, previousType.Name), ErrorNumbers.Error_FaultHandlerActivityWrongOrder));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fault handlers can not contain fault handlers, compensation handler and cancellation handler
|
||||
if (((ISupportAlternateFlow)exceptionHandlers).AlternateFlowActivities.Count > 0)
|
||||
validationErrors.Add(new ValidationError(SR.GetString(SR.Error_ModelingConstructsCanNotContainModelingConstructs), ErrorNumbers.Error_ModelingConstructsCanNotContainModelingConstructs));
|
||||
|
||||
return validationErrors;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
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.ComponentModel;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Workflow.ComponentModel.Design;
|
||||
|
||||
|
||||
#region Class FaultHandlersDesigner
|
||||
[ActivityDesignerTheme(typeof(FaultHandlersActivityDesignerTheme))]
|
||||
internal sealed class FaultHandlersActivityDesigner : ActivityPreviewDesigner
|
||||
{
|
||||
#region Members, Constructor and Destructor
|
||||
protected override void Initialize(Activity activity)
|
||||
{
|
||||
base.Initialize(activity);
|
||||
|
||||
HelpText = DR.GetString(DR.DropExceptionsHere);
|
||||
ShowPreview = 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);
|
||||
}
|
||||
}
|
||||
|
||||
#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 (!(activity is FaultHandlerActivity))
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.CanInsertActivities(insertLocation, activitiesToInsert);
|
||||
}
|
||||
|
||||
public override object FirstSelectableObject
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Expanded && IsVisible)
|
||||
{
|
||||
if (PreviewedDesigner != null || ContainedDesigners.Count > 0)
|
||||
return base.FirstSelectableObject;
|
||||
else if (ContainedDesigners.Count == 0)
|
||||
return new ConnectorHitTestInfo(this, HitTestLocations.Designer, 0).SelectableObject;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public override object LastSelectableObject
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Expanded && IsVisible)
|
||||
{
|
||||
if (PreviewedDesigner != null || ContainedDesigners.Count > 0)
|
||||
return base.LastSelectableObject;
|
||||
else if (ContainedDesigners.Count == 0)
|
||||
return new ConnectorHitTestInfo(this, HitTestLocations.Designer, GetConnectors().GetLength(0) - 1).SelectableObject;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region FaultHandlersActivityDesignerTheme
|
||||
internal sealed class FaultHandlersActivityDesignerTheme : ActivityPreviewDesignerTheme
|
||||
{
|
||||
public FaultHandlersActivityDesignerTheme(WorkflowTheme theme)
|
||||
: base(theme)
|
||||
{
|
||||
this.ShowDropShadow = false;
|
||||
this.ConnectorStartCap = LineAnchor.None;
|
||||
this.ConnectorEndCap = LineAnchor.None;
|
||||
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, 0xB0);
|
||||
this.BackColorEnd = Color.FromArgb(0x35, 0xFF, 0xE0, 0xE0);
|
||||
this.PreviewForeColor = Color.FromArgb(0xFF, 0xF0, 0xF0, 0xF0);
|
||||
this.PreviewBorderColor = Color.FromArgb(0xFF, 0x6B, 0x6D, 0x6B);
|
||||
this.PreviewBackColor = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
namespace System.Workflow.ComponentModel
|
||||
{
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Design;
|
||||
using System.Workflow.ComponentModel;
|
||||
using System.Workflow.ComponentModel.Design;
|
||||
using System.Workflow.ComponentModel.Serialization;
|
||||
using System.Workflow.ComponentModel.Compiler;
|
||||
|
||||
#endregion
|
||||
|
||||
[SRDescription(SR.SynchronizationScopeActivityDescription)]
|
||||
[ToolboxItem(typeof(ActivityToolboxItem))]
|
||||
[ToolboxBitmap(typeof(SynchronizationScopeActivity), "Resources.Sequence.png")]
|
||||
[SupportsSynchronization]
|
||||
[Designer(typeof(SequenceDesigner), typeof(IDesigner))]
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public sealed class SynchronizationScopeActivity : CompositeActivity, IActivityEventListener<ActivityExecutionStatusChangedEventArgs>
|
||||
{
|
||||
|
||||
public SynchronizationScopeActivity()
|
||||
{
|
||||
}
|
||||
|
||||
public SynchronizationScopeActivity(string name)
|
||||
: base(name)
|
||||
{
|
||||
}
|
||||
|
||||
[SRDisplayName(SR.SynchronizationHandles)]
|
||||
[SRDescription(SR.SynchronizationHandlesDesc)]
|
||||
[TypeConverter(typeof(SynchronizationHandlesTypeConverter))]
|
||||
[EditorAttribute(typeof(SynchronizationHandlesEditor), typeof(System.Drawing.Design.UITypeEditor))]
|
||||
public ICollection<String> SynchronizationHandles
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.GetValue(SynchronizationHandlesProperty) as ICollection<String>;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.SetValue(SynchronizationHandlesProperty, 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);
|
||||
}
|
||||
}
|
||||
|
||||
#region Class SynchronizationHandlesTypeConverter
|
||||
internal sealed class SynchronizationHandlesTypeConverter : TypeConverter
|
||||
{
|
||||
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof(string))
|
||||
return true;
|
||||
|
||||
return base.CanConvertTo(context, destinationType);
|
||||
}
|
||||
|
||||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof(string) && value is ICollection<String>)
|
||||
return Stringify(value as ICollection<String>);
|
||||
|
||||
return base.ConvertTo(context, culture, value, destinationType);
|
||||
}
|
||||
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
if (sourceType == typeof(string))
|
||||
return true;
|
||||
return base.CanConvertFrom(context, sourceType);
|
||||
}
|
||||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
if (value is string)
|
||||
return UnStringify(value as string);
|
||||
|
||||
return base.ConvertFrom(context, culture, value);
|
||||
}
|
||||
|
||||
internal static string Stringify(ICollection<String> synchronizationHandles)
|
||||
{
|
||||
string stringifiedValue = string.Empty;
|
||||
if (synchronizationHandles == null)
|
||||
return stringifiedValue;
|
||||
|
||||
foreach (string handle in synchronizationHandles)
|
||||
{
|
||||
if (handle == null)
|
||||
continue;
|
||||
if (stringifiedValue != string.Empty)
|
||||
stringifiedValue += ", ";
|
||||
stringifiedValue += handle.Replace(",", "\\,");
|
||||
}
|
||||
|
||||
return stringifiedValue;
|
||||
}
|
||||
|
||||
internal static ICollection<String> UnStringify(string stringifiedValue)
|
||||
{
|
||||
ICollection<String> synchronizationHandles = new List<String>();
|
||||
stringifiedValue = stringifiedValue.Replace("\\,", ">");
|
||||
foreach (string handle in stringifiedValue.Split(new char[] { ',', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
string realHandle = handle.Trim().Replace('>', ',');
|
||||
if (realHandle != string.Empty && !synchronizationHandles.Contains(realHandle))
|
||||
synchronizationHandles.Add(realHandle);
|
||||
}
|
||||
|
||||
return synchronizationHandles;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
internal sealed class SynchronizationHandlesEditor : UITypeEditor
|
||||
{
|
||||
private MultilineStringEditor stringEditor = new MultilineStringEditor();
|
||||
|
||||
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
|
||||
{
|
||||
string stringValue = SynchronizationHandlesTypeConverter.Stringify(value as ICollection<string>);
|
||||
stringValue = stringEditor.EditValue(context, provider, stringValue) as string;
|
||||
value = SynchronizationHandlesTypeConverter.UnStringify(stringValue);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
|
||||
{
|
||||
return stringEditor.GetEditStyle(context);
|
||||
}
|
||||
|
||||
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
|
||||
{
|
||||
return stringEditor.GetPaintValueSupported(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
namespace System.Workflow.ComponentModel
|
||||
{
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Workflow.ComponentModel;
|
||||
using System.Workflow.ComponentModel.Design;
|
||||
using System.Workflow.ComponentModel.Compiler;
|
||||
using System.ComponentModel.Design;
|
||||
|
||||
#endregion
|
||||
|
||||
[SRDescription(SR.TransactionalContextActivityDescription)]
|
||||
[ToolboxItem(typeof(ActivityToolboxItem))]
|
||||
[ToolboxBitmap(typeof(TransactionScopeActivity), "Resources.Sequence.png")]
|
||||
[Designer(typeof(TransactionScopeActivityDesigner), typeof(IDesigner))]
|
||||
[PersistOnClose]
|
||||
[SupportsTransaction]
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public sealed class TransactionScopeActivity : CompositeActivity, IActivityEventListener<ActivityExecutionStatusChangedEventArgs>
|
||||
{
|
||||
internal static readonly DependencyProperty TransactionOptionsProperty = DependencyProperty.Register("TransactionOptions", typeof(WorkflowTransactionOptions), typeof(TransactionScopeActivity), new PropertyMetadata(DependencyPropertyOptions.Metadata, new Attribute[] { new DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content) }));
|
||||
internal static readonly string TransactionScopeActivityIsolationHandle = "A1DAF1E7-E9E7-4df2-B88F-3A92E1D744F2";
|
||||
|
||||
public TransactionScopeActivity()
|
||||
{
|
||||
this.SetValueBase(TransactionOptionsProperty, new WorkflowTransactionOptions());
|
||||
}
|
||||
|
||||
public TransactionScopeActivity(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 TransactionScopeActivityDesigner
|
||||
|
||||
internal sealed class TransactionScopeActivityDesigner : 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,128 @@
|
||||
namespace System.Workflow.ComponentModel
|
||||
{
|
||||
using System;
|
||||
using System.Xml;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
using System.ComponentModel;
|
||||
using System.Transactions;
|
||||
using System.Reflection;
|
||||
using System.Workflow.ComponentModel;
|
||||
using System.Workflow.ComponentModel.Design;
|
||||
using System.ComponentModel.Design.Serialization;
|
||||
using System.Collections;
|
||||
using System.CodeDom;
|
||||
using System.Collections.Specialized;
|
||||
using System.Workflow.ComponentModel.Compiler;
|
||||
using System.Workflow.ComponentModel.Serialization;
|
||||
|
||||
[Browsable(true)]
|
||||
[DesignerSerializer(typeof(DependencyObjectCodeDomSerializer), typeof(CodeDomSerializer))]
|
||||
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
|
||||
public sealed class WorkflowTransactionOptions : DependencyObject
|
||||
{
|
||||
public static readonly DependencyProperty TimeoutDurationProperty = DependencyProperty.Register("TimeoutDuration", typeof(TimeSpan), typeof(WorkflowTransactionOptions), new PropertyMetadata(new TimeSpan(0, 0, 30), DependencyPropertyOptions.Metadata));
|
||||
public static readonly DependencyProperty IsolationLevelProperty = DependencyProperty.Register("IsolationLevel", typeof(IsolationLevel), typeof(WorkflowTransactionOptions), new PropertyMetadata(IsolationLevel.Serializable, DependencyPropertyOptions.Metadata));
|
||||
|
||||
[SRDescription(SR.TimeoutDescr)]
|
||||
[SRCategory(SR.Activity)]
|
||||
[MergableProperty(false)]
|
||||
[DefaultValue(typeof(TimeSpan), "0:0:30")]
|
||||
[TypeConverter(typeof(TimeoutDurationConverter))]
|
||||
public TimeSpan TimeoutDuration
|
||||
{
|
||||
get
|
||||
{
|
||||
return (TimeSpan)base.GetValue(TimeoutDurationProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
base.SetValue(TimeoutDurationProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
[SRDescription(SR.IsolationLevelDescr)]
|
||||
[SRCategory(SR.Activity)]
|
||||
[MergableProperty(false)]
|
||||
public IsolationLevel IsolationLevel
|
||||
{
|
||||
get
|
||||
{
|
||||
return (IsolationLevel)base.GetValue(IsolationLevelProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
base.SetValue(IsolationLevelProperty, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class TimeoutDurationConverter : TypeConverter
|
||||
{
|
||||
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof(string))
|
||||
return true;
|
||||
|
||||
return base.CanConvertTo(context, destinationType);
|
||||
}
|
||||
|
||||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof(string) && value is TimeSpan)
|
||||
{
|
||||
TimeSpan timespan = (TimeSpan)value;
|
||||
return timespan.ToString();
|
||||
}
|
||||
|
||||
return base.ConvertTo(context, culture, value, destinationType);
|
||||
}
|
||||
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
if (sourceType == typeof(string))
|
||||
return true;
|
||||
|
||||
return base.CanConvertFrom(context, sourceType);
|
||||
}
|
||||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
|
||||
{
|
||||
TimeSpan parsedTimespan = TimeSpan.Zero;
|
||||
string timeSpan = value as string;
|
||||
if (!String.IsNullOrEmpty(timeSpan))
|
||||
{
|
||||
//If this fails then an exception is thrown and the property set would fail
|
||||
try
|
||||
{
|
||||
parsedTimespan = TimeSpan.Parse(timeSpan, CultureInfo.InvariantCulture);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
if (parsedTimespan.Ticks < 0)
|
||||
{
|
||||
throw new Exception(string.Format(System.Globalization.CultureInfo.CurrentCulture, SR.GetString(SR.Error_NegativeValue), value.ToString(), "TimeoutDuration"));
|
||||
}
|
||||
}
|
||||
|
||||
return parsedTimespan;
|
||||
}
|
||||
|
||||
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
|
||||
{
|
||||
ArrayList standardValuesCollection = new ArrayList();
|
||||
standardValuesCollection.Add(new TimeSpan(0, 0, 0));
|
||||
standardValuesCollection.Add(new TimeSpan(0, 0, 15));
|
||||
standardValuesCollection.Add(new TimeSpan(0, 1, 0));
|
||||
return new StandardValuesCollection(standardValuesCollection);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user