Suspend.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Common / AuthoringOM / Suspend.cs / 1305376 / Suspend.cs

                            namespace System.Workflow.ComponentModel 
{
    #region Imports

    using System; 
    using System.Text;
    using System.Reflection; 
    using System.Collections; 
    using System.CodeDom;
    using System.ComponentModel; 
    using System.ComponentModel.Design;
    using System.Drawing;
    using System.Workflow.ComponentModel;
    using System.Workflow.ComponentModel.Design; 
    using System.Collections.Generic;
    using System.Drawing.Design; 
    using System.Workflow.ComponentModel.Compiler; 
    using System.Workflow.Runtime;
    #endregion 

    [SRDescription(SR.SuspendActivityDescription)]
    [ToolboxItem(typeof(ActivityToolboxItem))]
    [Designer(typeof(SuspendDesigner), typeof(IDesigner))] 
    [ToolboxBitmap(typeof(SuspendActivity), "Resources.Suspend.png")]
    [ActivityValidator(typeof(SuspendValidator))] 
    [SRCategory(SR.Standard)] 
    public sealed class SuspendActivity : Activity
    { 
        public static readonly DependencyProperty ErrorProperty = DependencyProperty.Register("Error", typeof(string), typeof(SuspendActivity));

        #region Constructors
 
        public SuspendActivity()
        { 
        } 

        public SuspendActivity(string name) 
            : base(name)
        {
        }
 
        #endregion
 
        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 sealed ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) 
		{ 
			executionContext.CloseActivity();
 
            string suspendReason = this.Error;
            executionContext.SuspendWorkflowInstance(suspendReason);
            return ActivityExecutionStatus.Closed;
        } 

        [Browsable(true)] 
        [SRCategory(SR.Activity)] 
        [SRDescription(SR.SuspendErrorMessageDescr)]
        [MergableProperty(false)] 
        [DefaultValue((string)null)]
        public string Error
        {
            get 
            {
                return base.GetValue(ErrorProperty) as string; 
            } 
            set
            { 
                base.SetValue(ErrorProperty, value);
            }
        }
    } 

    internal sealed class SuspendValidator : ActivityValidator 
    { 
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        { 
            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

            SuspendActivity suspend = obj as SuspendActivity;
            if (suspend == null) 
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(SuspendActivity).FullName), "obj");
 
            CompositeActivity parent = suspend.Parent; 
            while (parent != null)
            { 
                if (parent.SupportsTransaction)
                {
                    validationErrors.Add(new ValidationError(SR.GetString(SR.Error_SuspendInAtomicScope), ErrorNumbers.Error_SuspendInAtomicScope));
                    break; 
                }
                parent = parent.Parent; 
            } 
            return validationErrors;
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
namespace System.Workflow.ComponentModel 
{
    #region Imports

    using System; 
    using System.Text;
    using System.Reflection; 
    using System.Collections; 
    using System.CodeDom;
    using System.ComponentModel; 
    using System.ComponentModel.Design;
    using System.Drawing;
    using System.Workflow.ComponentModel;
    using System.Workflow.ComponentModel.Design; 
    using System.Collections.Generic;
    using System.Drawing.Design; 
    using System.Workflow.ComponentModel.Compiler; 
    using System.Workflow.Runtime;
    #endregion 

    [SRDescription(SR.SuspendActivityDescription)]
    [ToolboxItem(typeof(ActivityToolboxItem))]
    [Designer(typeof(SuspendDesigner), typeof(IDesigner))] 
    [ToolboxBitmap(typeof(SuspendActivity), "Resources.Suspend.png")]
    [ActivityValidator(typeof(SuspendValidator))] 
    [SRCategory(SR.Standard)] 
    public sealed class SuspendActivity : Activity
    { 
        public static readonly DependencyProperty ErrorProperty = DependencyProperty.Register("Error", typeof(string), typeof(SuspendActivity));

        #region Constructors
 
        public SuspendActivity()
        { 
        } 

        public SuspendActivity(string name) 
            : base(name)
        {
        }
 
        #endregion
 
        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 sealed ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) 
		{ 
			executionContext.CloseActivity();
 
            string suspendReason = this.Error;
            executionContext.SuspendWorkflowInstance(suspendReason);
            return ActivityExecutionStatus.Closed;
        } 

        [Browsable(true)] 
        [SRCategory(SR.Activity)] 
        [SRDescription(SR.SuspendErrorMessageDescr)]
        [MergableProperty(false)] 
        [DefaultValue((string)null)]
        public string Error
        {
            get 
            {
                return base.GetValue(ErrorProperty) as string; 
            } 
            set
            { 
                base.SetValue(ErrorProperty, value);
            }
        }
    } 

    internal sealed class SuspendValidator : ActivityValidator 
    { 
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        { 
            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

            SuspendActivity suspend = obj as SuspendActivity;
            if (suspend == null) 
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(SuspendActivity).FullName), "obj");
 
            CompositeActivity parent = suspend.Parent; 
            while (parent != null)
            { 
                if (parent.SupportsTransaction)
                {
                    validationErrors.Add(new ValidationError(SR.GetString(SR.Error_SuspendInAtomicScope), ErrorNumbers.Error_SuspendInAtomicScope));
                    break; 
                }
                parent = parent.Parent; 
            } 
            return validationErrors;
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK