DesignerInterfaces.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 / Design / DesignerInterfaces.cs / 1305376 / DesignerInterfaces.cs

                            namespace System.Workflow.ComponentModel.Design 
{
 	using System;
	using System.Drawing;
	using System.Collections; 
	using System.Collections.ObjectModel;
 	using System.Collections.Generic; 
	using System.Collections.Specialized; 
 	using System.Windows.Forms;
 	using System.Windows.Forms.Design; 
	using System.ComponentModel;
 	using System.ComponentModel.Design;
	using System.CodeDom;
	using System.IO; 
	using System.Reflection;
    using System.Drawing.Printing; 
    using System.Drawing.Drawing2D; 
    using System.Runtime.InteropServices;
 	using System.Workflow.ComponentModel; 
	using System.Workflow.ComponentModel.Compiler;
 	using System.Security.Permissions;
 	
	#region Workflow Interfaces 

 	#region Interface IIdentifierCreationService 
	 
	public interface IIdentifierCreationService
	{ 
 		void EnsureUniqueIdentifiers(CompositeActivity parentActivity, ICollection childActivities);
		void ValidateIdentifier(Activity activity, string identifier);
 	}
 
 	#endregion
 
	#region Interface IMemberCreationService 

 	//Revisit the functions in this interface for consistency and performance 
	public interface IMemberCreationService
	{
		void CreateField(string className, string fieldName, Type fieldType, Type[] genericParameterTypes, MemberAttributes attributes, CodeSnippetExpression initializationExpression, bool overwriteExisting);
 		void CreateProperty(string className, string propertyName, Type propertyType, AttributeInfo[] attributes, bool emitDependencyProperty, bool isMetaProperty, bool isAttached, Type ownerType, bool isReadOnly); 
        void CreateEvent(string className, string eventName, Type eventType, AttributeInfo[] attributes, bool emitDependencyProperty);
		void UpdateTypeName(string oldClassName, string newClassName); 
 		void UpdateBaseType(string className, Type baseType); 
        void UpdateProperty(string className, string oldPropertyName, Type oldPropertyType, string newPropertyName, Type newPropertyType, AttributeInfo[] attributes, bool emitDependencyProperty, bool isMetaProperty);
        void UpdateEvent(string className, string oldEventName, Type oldEventType, string newEventName, Type newEventType, AttributeInfo[] attributes, bool emitDependencyProperty, bool isMetaProperty); 
 		void RemoveProperty(string className, string propertyName, Type propertyType);
        void RemoveEvent(string className, string eventName, Type eventType);

		void ShowCode(Activity activity, string methodName, Type delegateType); 
 	    void ShowCode();
	} 
 
	#endregion
 
	#region Interface IExtendedUIService
 	public interface IExtendedUIService
	{
 		DialogResult AddWebReference(out Uri url, out Type proxyClass); 
        Uri GetUrlForProxyClass(Type proxyClass);
        Type GetProxyClassForUrl(Uri url); 
 
        //Task provider related functionality
 		void AddDesignerActions(DesignerAction[] actions); 
		void RemoveDesignerActions();
 		
		//Property Grid related functionality
		bool NavigateToProperty(string propName); 

        //Get the selected property context from property grid 
        ITypeDescriptorContext GetSelectedPropertyContext(); 

		//Show the ToolsOptions 
 		void ShowToolsOptions();

		//Retrieve Xsd project Item information
 		Dictionary GetXsdProjectItemsInfo(); 

 		//Add assembly reference (including dynamic assembly resolution) 
		void AddAssemblyReference(AssemblyName assemblyName); 

 
 	}

    public interface IExtendedUIService2
    { 
        //Get current project's target version
        long GetTargetFrameworkVersion(); 
 
        //Get if the given type is supported in the current target framework
        bool IsSupportedType(Type type); 

        //Get the assembly loaded in reflection context for the current target framework.
        Assembly GetReflectionAssembly(AssemblyName assemblyName);
 
        //Get the current runtime type for the passed in reflection type. Reflection type is target framework type.
        Type GetRuntimeType(Type reflectionType); 
    } 
	#endregion
 
	#endregion

	#region Design Surface related classes and Interfaces
 
 	#region Interface IWorkflowDesignerMessageSink
	internal interface IWorkflowDesignerMessageSink 
 	{ 
 		bool OnMouseDown(MouseEventArgs e);
		bool OnMouseMove(MouseEventArgs e); 
 		bool OnMouseUp(MouseEventArgs e);
		bool OnMouseDoubleClick(MouseEventArgs e);
		bool OnMouseEnter(MouseEventArgs e);
		bool OnMouseHover(MouseEventArgs e); 
 		bool OnMouseLeave();
		bool OnMouseWheel(MouseEventArgs e); 
 		bool OnMouseCaptureChanged(); 
 		bool OnMouseDragBegin(Point initialPoint, MouseEventArgs e);
		bool OnMouseDragMove(MouseEventArgs e); 
 		bool OnMouseDragEnd();

		bool OnDragEnter(DragEventArgs e);
		bool OnDragOver(DragEventArgs e); 
		bool OnDragLeave();
 		bool OnDragDrop(DragEventArgs e); 
		bool OnGiveFeedback(GiveFeedbackEventArgs e); 
 		bool OnQueryContinueDrag(QueryContinueDragEventArgs e);
 
 		bool OnKeyDown(KeyEventArgs e);
		bool OnKeyUp(KeyEventArgs e);

        bool OnScroll(ScrollBar sender, int value); 
 		bool OnShowContextMenu(Point screenMenuPoint);
		bool ProcessMessage(Message message); 
 
		void OnLayout(LayoutEventArgs layoutEventArgs);
		void OnLayoutPosition(Graphics graphics); 
 		void OnLayoutSize(Graphics graphics);
		void OnThemeChange();

        void OnBeginResizing(DesignerEdges sizingEdge); 
        void OnResizing(DesignerEdges sizingEdge, Rectangle bounds);
        void OnEndResizing(); 
 
 		bool OnPaint(PaintEventArgs e, Rectangle viewPort);
 		bool OnPaintWorkflowAdornments(PaintEventArgs e, Rectangle viewPort); 
    }
	#endregion

 	#region Class ViewPortData 
	//
 
	internal sealed class ViewPortData 
    {
        public Rectangle LogicalViewPort; 
        public Bitmap MemoryBitmap;
        public SizeF Scaling = new SizeF(1.0f, 1.0f);
        public Point Translation = Point.Empty;
        public Size	ShadowDepth = Size.Empty; 
        public Color TransparentColor = Color.White;
        public Size ViewPortSize = Size.Empty; 
 	} 
	#endregion
 
 	#region Class ActivityDragEventArgs
    /// 
    /// EventArgs passed to the ActivityDesigners when drag drop operation is in progress on workflow.
    /// ActivityDesigners can access the information contained to influence the drag drop behavior. 
    /// 
 	public class ActivityDragEventArgs: DragEventArgs 
	{ 
 		private Point snapPoint = Point.Empty;
        private Point dragInitiationPoint = Point.Empty; 
        private List draggedActivities;

        internal ActivityDragEventArgs(DragEventArgs dragEventArgs, Point dragInitiationPoint, Point point, List draggedActivities)
            : base(dragEventArgs.Data, dragEventArgs.KeyState, point.X, point.Y, dragEventArgs.AllowedEffect, dragEventArgs.Effect) 
        {
            this.dragInitiationPoint = dragInitiationPoint; 
 
            if (draggedActivities == null)
                this.draggedActivities = new List(); 
            else
				this.draggedActivities = new List(draggedActivities);
        }
 
        /// 
        /// Returns Activities being dragged drop 
        ///  
        public ReadOnlyCollection Activities
        { 
            get
            {
                return this.draggedActivities.AsReadOnly();
            } 
        }
 
        ///  
        /// WorkflowView creates drag image for the activities being dragged.
        /// ActivityDesigners can choose to snap this image to a drop target to indicate that activities can be dropped at a particular location 
        /// 
        public Point DragImageSnapPoint
		{
			get 
 			{
                return this.snapPoint; 
            } 

			set 
 			{
                this.snapPoint = value;
            }
 		} 

        ///  
        /// Returns point at which the drag drop operation was initiated in logical coordinates 
        /// 
        public Point DragInitiationPoint 
        {
            get
            {
                return this.dragInitiationPoint; 
            }
        } 
	} 
 	#endregion
 
	#endregion

	#region Classes, Interfaces and enums used by Designers
 
	#region Class ActivityChangeEventArgs
 	///  
	/// Contains information about the changes made to the activity associated with the designer 
 	/// 
 	public class ActivityChangedEventArgs : EventArgs 
	{
 		private Activity activity;
		private MemberDescriptor member;
		private object oldValue; 
		private object newValue;
 
 		public ActivityChangedEventArgs(Activity activity, MemberDescriptor member, object oldValue, object newValue) 
		{
 			this.activity = activity; 
 			this.member = member;
			this.oldValue = oldValue;
 			this.newValue = newValue;
		} 

		///  
		/// Activity being changed 
 		/// 
		public Activity Activity 
 		{
 			get
			{
 				return this.activity; 
			}
		} 
 
		/// 
 		/// Member of the activity being changed 
		/// 
 		public MemberDescriptor Member
 		{
			get 
 			{
				return this.member; 
			} 
		}
 
 		/// 
		/// OldValue of the member before the change
 		/// 
 		public object OldValue 
		{
 			get 
			{ 
				return this.oldValue;
			} 
 		}

		/// 
 		/// New value of the member after the change 
 		/// 
		public object NewValue 
 		{ 
			get
			{ 
				return this.newValue;
 			}
		}
 	} 
 	#endregion
 
	#region Class ActivityDesignerLayoutEventArgs 
 	/// 
	/// Contains arguments passed to layout functions of ActivityDesigner 
	/// 
	public class ActivityDesignerLayoutEventArgs : EventArgs
 	{
		private Graphics graphics; 
 		private ActivityDesignerTheme designerTheme;
 
 		public ActivityDesignerLayoutEventArgs(Graphics graphics, ActivityDesignerTheme designerTheme) 
		{
 			this.graphics = graphics; 
			this.designerTheme = designerTheme;
		}

		///  
 		/// Gets the ambient theme associated with workflow
		///  
 		public AmbientTheme AmbientTheme 
 		{
			get 
 			{
				return WorkflowTheme.CurrentTheme.AmbientTheme;
			}
		} 

 		///  
		/// Gets the designet theme associated with activity designer 
 		/// 
 		public ActivityDesignerTheme DesignerTheme 
		{
 			get
			{
				return this.designerTheme; 
			}
 		} 
 
		/// 
 		/// Gets the graphics object on which the activity designer will be drawn 
 		/// 
		public Graphics Graphics
 		{
			get 
			{
				return this.graphics; 
 			} 
		}
 	} 
 	#endregion

	#region Class ActivityDesignerPaintEventArgs
 	///  
	/// Contains arguments passed to draw function of ActivityDesigner
	///  
	public class ActivityDesignerPaintEventArgs : EventArgs 
 	{
		private Graphics graphics; 
 		private Rectangle clipRectangle;
 		private Rectangle viewPort;
		private ActivityDesignerTheme designerTheme;
 
 		public ActivityDesignerPaintEventArgs(Graphics graphics, Rectangle clipRectangle, Rectangle viewPort, ActivityDesignerTheme designerTheme)
		{ 
			this.graphics = graphics; 
			this.clipRectangle = Rectangle.Inflate(clipRectangle, 1, 1);
 			this.viewPort = viewPort; 
			this.designerTheme = designerTheme;
 		}

 		///  
		/// Graphics object associated with design surface on which the activity needs to draw
 		///  
		public Graphics Graphics 
		{
			get 
 			{
				return this.graphics;
 			}
 		} 

		///  
 		/// Bounding rectangle outside which the activity can not draw 
		/// 
		public Rectangle ClipRectangle 
		{
 			get
			{
 				return this.clipRectangle; 
 			}
		} 
 
 		/// 
		/// Gets the ambient theme associated with Workflow 
		/// 
		public AmbientTheme AmbientTheme
 		{
			get 
 			{
 				return WorkflowTheme.CurrentTheme.AmbientTheme; 
			} 
 		}
 
		/// 
		/// Gets the theme associated with designer
		/// 
 		public ActivityDesignerTheme DesignerTheme 
		{
 			get 
 			{ 
				return this.designerTheme;
 			} 
		}

		internal Rectangle ViewPort
		{ 
 			get
			{ 
 				return this.viewPort; 
 			}
		} 
 	}
	#endregion

    #region Class ActivityDesignerResizeEventArgs 
    public class ActivityDesignerResizeEventArgs : EventArgs
    { 
        private DesignerEdges sizingEdge; 
        private Rectangle newBounds;
 
        public ActivityDesignerResizeEventArgs(DesignerEdges sizingEdge, Rectangle newBounds)
        {
            this.sizingEdge = sizingEdge;
            this.newBounds = newBounds; 
        }
 
        public DesignerEdges SizingEdge 
        {
            get 
            {
                return this.sizingEdge;
            }
        } 

        public Rectangle Bounds 
        { 
            get
            { 
                return this.newBounds;
            }
        }
    } 
    #endregion
 
    #region Enum DesignerEdges 
    [Flags]
    public enum DesignerEdges 
    {
        None = 0,
        Left = 1,
        Top = 2, 
        Right = 4,
        Bottom = 8, 
        All = 15 
    }
    #endregion 

    #region Interface IDesignerGlyphProvider
    /// 
    /// Allows the user to add custom glyph providers. 
    /// Custom glyph providers are called to render the glyphs on designer.
    ///  
	public interface IDesignerGlyphProviderService 
	{
 		void AddGlyphProvider(IDesignerGlyphProvider glyphProvider); 
		void RemoveGlyphProvider(IDesignerGlyphProvider glyphProvider);
        ReadOnlyCollection GlyphProviders { get;}
    }
 
 	public interface IDesignerGlyphProvider
 	{ 
        ActivityDesignerGlyphCollection GetGlyphs(ActivityDesigner activityDesigner); 
	}
 	#endregion 

    #region Interface IDesignerVerbProvider
    /// 
    /// Allows the user to add custom verb providers. 
    /// Custom verb providers are called in order to return the set of verbs associated with the designer.
    ///  
    public interface IDesignerVerbProviderService 
    {
        void AddVerbProvider(IDesignerVerbProvider verbProvider); 
        void RemoveVerbProvider(IDesignerVerbProvider verbProvider);
        ReadOnlyCollection VerbProviders { get;}
    }
 
    public interface IDesignerVerbProvider
    { 
        ActivityDesignerVerbCollection GetVerbs(ActivityDesigner activityDesigner); 
    }
    #endregion 

    #region Interface IPersistUIState
    public interface IPersistUIState
    { 
        void SaveViewState(BinaryWriter writer);
        void LoadViewState(BinaryReader reader); 
    } 
    #endregion
 
    #region Interface IWorkflowRootDesigner
    public interface IWorkflowRootDesigner : IRootDesigner
    {
        CompositeActivityDesigner InvokingDesigner { get;set;} 
        ReadOnlyCollection MessageFilters {get;}
        bool IsSupportedActivityType(Type activityType); 
        bool SupportsLayoutPersistence { get;} 
    }
    #endregion 

    #region Used for keyboard navigation
    public enum DesignerNavigationDirection
	{ 
		Down = 0,//Next
		Up = 1,//Previous 
 		Left = 2, 
		Right = 3
 	} 
 	#endregion

	#region enum HitTestLocations
 	///  
    /// Enumeration returning area of the designer which was under the point passed to hit test.
    ///  
    [FlagsAttribute] 
    public enum HitTestLocations
    { 
        None = 0,
        Designer = 1,
        ActionArea = 2,
        Left = 4, 
        Top = 8,
        Right = 16, 
        Bottom = 32, 
        Connector = 64
    } 
    #endregion

    #region Class HitTestInfo
    ///  
    /// Identifies the part of the designer at the specified location.
    /// Used by various operation including drag-drop, cut-paste etc 
    ///  
    public class HitTestInfo
    { 
        private static HitTestInfo nowhere;
        private ActivityDesigner activityDesigner = null;
		private HitTestLocations location = HitTestLocations.None;
        private IDictionary userData; 

        ///  
        /// Returns Empty HitTestInfo 
        /// 
        public static HitTestInfo Nowhere 
        {
            get
            {
                if (HitTestInfo.nowhere == null) 
                    HitTestInfo.nowhere = new HitTestInfo();
                return HitTestInfo.nowhere; 
            } 
        }
 
        internal HitTestInfo()
        {
        }
 
        /// 
        /// Constructs HitTestInfo with specified parameters 
        ///  
        /// ActivityDesigner associated with HitTestInfo
		/// HitTestLocations indicating where the hit happened 
		public HitTestInfo(ActivityDesigner designer, HitTestLocations location)
        {
            if (designer == null)
                throw new ArgumentNullException("designer"); 

            this.activityDesigner = designer; 
            this.location = location; 
        }
 
        /// 
        /// Returns designer associated
        /// 
        [Browsable(false)] 
        public ActivityDesigner AssociatedDesigner
        { 
            get 
            {
                return this.activityDesigner; 
            }
        }

        ///  
        /// Returns flags indicating where hit happened
        ///  
        [Browsable(false)] 
        public HitTestLocations HitLocation
        { 
            get
            {
                return this.location;
            } 
        }
 
        ///  
        /// Returns enclosing bounds for the hit area
        ///  
        [Browsable(false)]
        public virtual Rectangle Bounds
        {
            get 
            {
                if (this.activityDesigner != null) 
                    return this.activityDesigner.Bounds; 
                else
                    return Rectangle.Empty; 
            }
        }

        ///  
        /// Returns selectable object associated with Hit Area
        ///  
        [Browsable(false)] 
        public virtual object SelectableObject
        { 
            get
            {
                if (this.activityDesigner != null)
                    return this.activityDesigner.Activity; 
                else
                    return null; 
            } 
        }
 
        /// 
 		/// Returns UserData to associated with HitLocation
        /// 
        [Browsable(false)] 
        public IDictionary UserData
        { 
            get 
            {
                if (this.userData == null) 
                    this.userData = new HybridDictionary();
                return this.userData;
            }
        } 

        ///  
        /// Maps Hit area to index using which designers are to be inserted. 
        /// 
        ///  
        public virtual int MapToIndex()
        {
            CompositeActivity compositeActivity = this.activityDesigner.Activity as CompositeActivity;
            if (compositeActivity != null) 
                return compositeActivity.Activities.Count;
            else 
                return 0; 
        }
    } 
    #endregion

	#region Class ConnectorHitTestInfo
 	///  
 	/// Represents the hittest information for connectors within the designer, structured designers are expected to have connectors within them
	///  
 	public class ConnectorHitTestInfo : HitTestInfo 
	{
		private int connector = 0; 

		/// 
 		/// Constructor for ConnectorHitTestInfo
		///  
 		/// Designer associated with the HitTestInfo
 		/// Flags where HitTest occured 
		/// Index of the connector which was hit 
 		public ConnectorHitTestInfo(CompositeActivityDesigner compositeActivityDesigner, HitTestLocations flags, int connector)
			: base(compositeActivityDesigner, flags) 
		{
			if (this.connector < 0)
 				throw new ArgumentException(SR.GetString(SR.Error_InvalidConnectorValue), "connector");
 
			this.connector = connector;
 		} 
 
 		public override Rectangle Bounds
		{ 
 			get
			{
				//
				SequentialActivityDesigner sequentialActivityDesigner = AssociatedDesigner as SequentialActivityDesigner; 
 				if (sequentialActivityDesigner != null && sequentialActivityDesigner.Expanded)
                { 
                    Rectangle[] connectors = sequentialActivityDesigner.GetConnectors(); 
                    if(connectors.Length > 0)
                        return connectors[this.connector]; 
                }

                return Rectangle.Empty;
			} 
 		}
 
 		public override object SelectableObject 
		{
 			get 
			{
				return this;
			}
 		} 

		public override int MapToIndex() 
 		{ 
 			return this.connector;
		} 

 		public override bool Equals(object obj)
		{
			ConnectorHitTestInfo destinationConnector = obj as ConnectorHitTestInfo; 
			if (destinationConnector != null)
 			{ 
				if (destinationConnector.AssociatedDesigner == AssociatedDesigner && 
 					destinationConnector.HitLocation == HitLocation &&
 					destinationConnector.MapToIndex() == MapToIndex()) 
					return true;
 			}

			return false; 
		}
 
		public override int GetHashCode() 
 		{
			return base.GetHashCode() ^ ((AssociatedDesigner != null) ? AssociatedDesigner.GetHashCode() : 0) ^ MapToIndex().GetHashCode(); 
 		}
 	}
	#endregion
 
    #region Class DesignerAction
    //Public class as ActivityDesigners can provide their own DesignerActions 
    public sealed class DesignerAction 
    {
        private ActivityDesigner activityDesigner; 
 		private int actionId;
        private string text;
        private Image image;
        private IDictionary  userData; 
		private string propertyName = null;
 
        public DesignerAction(ActivityDesigner activityDesigner, int actionId, string text) 
        {
            if (activityDesigner == null) 
                throw new ArgumentNullException("activityDesigner");

            if (text == null || text.Length == 0)
                throw new ArgumentException(SR.GetString(SR.Error_NullOrEmptyValue), "text"); 

            this.activityDesigner = activityDesigner; 
			this.actionId = actionId; 
            this.text = text;
        } 

		public DesignerAction(ActivityDesigner activityDesigner, int actionId, string text, Image image)
 			: this(activityDesigner, actionId, text)
        { 
            this.image = image;
        } 
 
		public string PropertyName
 		{ 
 			get
			{
 				return this.propertyName;
			} 
			set
			{ 
 				this.propertyName = value; 
			}
 		} 

        public int ActionId
        {
            get 
            {
 				return this.actionId; 
            } 
        }
 
        public string Text
        {
            get
            { 
                return this.text;
            } 
        } 

        public Image Image 
        {
            get
            {
                return this.image; 
            }
        } 
 
		public IDictionary UserData
        { 
            get
            {
 				if (this.userData == null)
					this.userData = new HybridDictionary(); 
				return this.userData;
            } 
        } 

        public void Invoke() 
        {
            this.activityDesigner.OnExecuteDesignerAction(this);
        }
    } 
    #endregion
 
    #region Enum DesignerVerbGroup 
    /// 
    /// Provides categories for grouping of similar verbs 
    /// 
    public enum DesignerVerbGroup
    {
        General = 0, 
        View = 1,
        Edit = 2, 
        Options = 3, 
        Actions = 4,
        Misc = 5 
    }
    #endregion

    #region Class ActivityDesignerVerb 
    /// 
    /// DesignerVerb class specific to ActivityDesigners. 
    /// Allows user to group similar types of DesignerVerbs togather. 
    /// Provides user the ability to update the status of the verb.
    ///  
    public class ActivityDesignerVerb : DesignerVerb
    {
        private ActivityDesigner activityDesigner = null;
        private EventHandler invokeHandler = null; 
        private EventHandler statusHandler = null;
        private DesignerVerbGroup verbGroup; 
        private int id = 0; 

        public ActivityDesignerVerb(ActivityDesigner activityDesigner, DesignerVerbGroup verbGroup, string text, EventHandler invokeHandler) 
            : base(text, new EventHandler(OnExecuteDesignerVerb), new CommandID(WorkflowMenuCommands.MenuGuid, 0))
        {
            if (text == null || text.Length == 0)
                throw new ArgumentNullException("text"); 

            if (invokeHandler == null) 
                throw new ArgumentNullException("invokeHandler"); 

            this.verbGroup = verbGroup; 
            this.invokeHandler = invokeHandler;
            this.activityDesigner = activityDesigner;
        }
 
        public ActivityDesignerVerb(ActivityDesigner activityDesigner, DesignerVerbGroup verbGroup, string text, EventHandler invokeHandler, EventHandler statusHandler)
            : this(activityDesigner, verbGroup, text, invokeHandler) 
        { 
            this.statusHandler = statusHandler;
        } 

        public override int OleStatus
        {
            get 
            {
                if (statusHandler != null) 
                { 
                    try
                    { 
                        statusHandler(this, EventArgs.Empty);
                    }
                    catch
                    { 
                    }
                } 
 
                return base.OleStatus;
            } 
        }

        public override CommandID CommandID
        { 
            get
            { 
                return new CommandID(WorkflowMenuCommands.MenuGuid, this.id); 
            }
        } 

        public DesignerVerbGroup Group
        {
            get 
            {
                return this.verbGroup; 
            } 
        }
 
        internal int Id
        {
            get
            { 
                return this.id;
            } 
 
            set
            { 
                this.id = value;
            }
        }
 
        internal ActivityDesigner ActivityDesigner
        { 
            get 
            {
                return this.activityDesigner; 
            }
        }

        private static void OnExecuteDesignerVerb(object sender, EventArgs e) 
        {
            ActivityDesignerVerb activityDesignerVerb = sender as ActivityDesignerVerb; 
            if (activityDesignerVerb != null) 
            {
                if (activityDesignerVerb.invokeHandler != null) 
                    activityDesignerVerb.invokeHandler(sender, e);

                int status = activityDesignerVerb.OleStatus;
                status = 0; 

                if (activityDesignerVerb.activityDesigner != null) 
                { 
                    foreach (DesignerVerb verb in ((IDesigner)activityDesignerVerb.activityDesigner).Verbs)
                    { 
                        if (verb is ActivityDesignerVerb)
                        {
                            //Update the status of the
                            status = verb.OleStatus; 
                            status = 0;
                        } 
                    } 
                }
            } 
        }
    }
    #endregion
 
    #region Class ActivityDesignerVerbCollection
    ///  
    /// Maintains collection of ActivityDesignerVerbs. 
    /// Groups verbs belonging to the same veb groups and ensures that their identifiers are consecutive.
    ///  
	[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
 	[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
    public sealed class ActivityDesignerVerbCollection : DesignerVerbCollection
    { 
        public ActivityDesignerVerbCollection()
        { 
        } 

        public ActivityDesignerVerbCollection(IEnumerable verbs) 
        {
			if (verbs == null)
 				throw new ArgumentNullException("verbs");
 
            foreach(ActivityDesignerVerb verb in verbs)
 			    Add(verb); 
        } 

        protected override void OnValidate(object value) 
        {
            if (!(value is ActivityDesignerVerb))
                throw new InvalidOperationException(SR.GetString(SR.Error_InvalidDesignerVerbValue));
        } 

        ///  
        /// Returns a collection that is consumable by MenuCommandService. Verbs in the 
        /// safe collection have Ids in the range of VerbFirst.ID to VerbLast.ID. Also,
        /// the items are sorted, and the first item ID == VerbFirst.ID 
        /// 
        internal ActivityDesignerVerbCollection SafeCollection
        {
            get 
            {
                if (this.Count == 0) 
                    return this; 

                Dictionary> activityDesignerVerbs = new Dictionary>(); 
                ArrayList safeCollection = new ArrayList(this);

                // set Ids
                foreach (ActivityDesignerVerb verb in safeCollection) 
                {
                    List verbList = null; 
                    if (!activityDesignerVerbs.ContainsKey(verb.Group)) 
                    {
                        verbList = new List(); 
                        activityDesignerVerbs.Add(verb.Group, verbList);
                    }
                    else
                    { 
                        verbList = activityDesignerVerbs[verb.Group];
                    } 
 
                    if (!verbList.Contains(verb))
                    { 
                        verb.Id = ConvertGroupToId(verb.Group) + verbList.Count;
                        verbList.Add(verb);
                    }
                } 

                //items should be sorted by verb id 
                safeCollection.Sort(new ActivityDesignerVerbComparer()); 

                // add first dummy verb if needed 
                if (((ActivityDesignerVerb)safeCollection[0]).Id != MenuCommands.VerbFirst.ID)
                {
                    safeCollection.Insert(0, new ActivityDesignerVerb(null, DesignerVerbGroup.General, "Dummy", new EventHandler(OnDummyVerb)));
                    ((ActivityDesignerVerb)safeCollection[0]).Visible = false; 
                }
 
                ActivityDesignerVerbCollection verbs = new ActivityDesignerVerbCollection(); 
                foreach (ActivityDesignerVerb verb in safeCollection)
                    verbs.Add(verb); 

                return verbs;
            }
        } 

        private void OnDummyVerb(object sender, EventArgs e) 
        { 
            // Should never be called
        } 

        private int ConvertGroupToId(DesignerVerbGroup group)
        {
            if (group == DesignerVerbGroup.General) 
                return WorkflowMenuCommands.VerbGroupGeneral;
            else if (group == DesignerVerbGroup.View) 
                return WorkflowMenuCommands.VerbGroupView; 
            else if (group == DesignerVerbGroup.Edit)
                return WorkflowMenuCommands.VerbGroupEdit; 
            else if (group == DesignerVerbGroup.Options)
                return WorkflowMenuCommands.VerbGroupOptions;
            else if (group == DesignerVerbGroup.Actions)
                return WorkflowMenuCommands.VerbGroupActions; 
            else
                return WorkflowMenuCommands.VerbGroupMisc; 
        } 
        #region class ActivityDesignerVerbComparer
 
        private class ActivityDesignerVerbComparer : IComparer
        {
            #region IComparer Members
 
            public int Compare(object x, object y)
            { 
                ActivityDesignerVerb verb1 = x as ActivityDesignerVerb; 
                ActivityDesignerVerb verb2 = y as ActivityDesignerVerb;
 
                if (verb1.Id == verb2.Id)
                    return 0;
                else if (verb1.Id > verb2.Id)
                    return 1; 
                else
                    return -1; 
            } 
            #endregion
        } 

        #endregion

    } 
    #endregion
 
	#endregion 

 	#region ITypeFilterProvider Interface 
	public interface ITypeFilterProvider
	{
		bool CanFilterType(Type type, bool throwOnError);
 		string FilterDescription { get; } 
	}
 	#endregion 
 
 	#region TypeFilterProviderAttribute
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = false)] 
 	public sealed class TypeFilterProviderAttribute : Attribute
	{
		private string typeName = null;
 
		public TypeFilterProviderAttribute(Type type)
 		{ 
			if (type == null) 
 				throw new ArgumentNullException("type");
 
 			this.typeName = type.AssemblyQualifiedName;
		}

 		public TypeFilterProviderAttribute(string typeName) 
		{
			this.typeName = typeName; 
		} 

 		public string TypeFilterProviderTypeName 
		{
 			get
 			{
				return this.typeName; 
 			}
		} 
	} 
	#endregion
 
 	#region ITypeProviderCreator Interface
	[Guid("0E6DF9D7-B4B5-4af7-9647-FC335CCE393F")]
 	[ComVisible(true)]
 	public interface ITypeProviderCreator 
	{
 		ITypeProvider			GetTypeProvider(object obj); 
		Assembly				GetLocalAssembly(object obj); 
		Assembly				GetTransientAssembly(AssemblyName assemblyName);
		ITypeResolutionService	GetTypeResolutionService(object obj); 
 	}
	#endregion
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
namespace System.Workflow.ComponentModel.Design 
{
 	using System;
	using System.Drawing;
	using System.Collections; 
	using System.Collections.ObjectModel;
 	using System.Collections.Generic; 
	using System.Collections.Specialized; 
 	using System.Windows.Forms;
 	using System.Windows.Forms.Design; 
	using System.ComponentModel;
 	using System.ComponentModel.Design;
	using System.CodeDom;
	using System.IO; 
	using System.Reflection;
    using System.Drawing.Printing; 
    using System.Drawing.Drawing2D; 
    using System.Runtime.InteropServices;
 	using System.Workflow.ComponentModel; 
	using System.Workflow.ComponentModel.Compiler;
 	using System.Security.Permissions;
 	
	#region Workflow Interfaces 

 	#region Interface IIdentifierCreationService 
	 
	public interface IIdentifierCreationService
	{ 
 		void EnsureUniqueIdentifiers(CompositeActivity parentActivity, ICollection childActivities);
		void ValidateIdentifier(Activity activity, string identifier);
 	}
 
 	#endregion
 
	#region Interface IMemberCreationService 

 	//Revisit the functions in this interface for consistency and performance 
	public interface IMemberCreationService
	{
		void CreateField(string className, string fieldName, Type fieldType, Type[] genericParameterTypes, MemberAttributes attributes, CodeSnippetExpression initializationExpression, bool overwriteExisting);
 		void CreateProperty(string className, string propertyName, Type propertyType, AttributeInfo[] attributes, bool emitDependencyProperty, bool isMetaProperty, bool isAttached, Type ownerType, bool isReadOnly); 
        void CreateEvent(string className, string eventName, Type eventType, AttributeInfo[] attributes, bool emitDependencyProperty);
		void UpdateTypeName(string oldClassName, string newClassName); 
 		void UpdateBaseType(string className, Type baseType); 
        void UpdateProperty(string className, string oldPropertyName, Type oldPropertyType, string newPropertyName, Type newPropertyType, AttributeInfo[] attributes, bool emitDependencyProperty, bool isMetaProperty);
        void UpdateEvent(string className, string oldEventName, Type oldEventType, string newEventName, Type newEventType, AttributeInfo[] attributes, bool emitDependencyProperty, bool isMetaProperty); 
 		void RemoveProperty(string className, string propertyName, Type propertyType);
        void RemoveEvent(string className, string eventName, Type eventType);

		void ShowCode(Activity activity, string methodName, Type delegateType); 
 	    void ShowCode();
	} 
 
	#endregion
 
	#region Interface IExtendedUIService
 	public interface IExtendedUIService
	{
 		DialogResult AddWebReference(out Uri url, out Type proxyClass); 
        Uri GetUrlForProxyClass(Type proxyClass);
        Type GetProxyClassForUrl(Uri url); 
 
        //Task provider related functionality
 		void AddDesignerActions(DesignerAction[] actions); 
		void RemoveDesignerActions();
 		
		//Property Grid related functionality
		bool NavigateToProperty(string propName); 

        //Get the selected property context from property grid 
        ITypeDescriptorContext GetSelectedPropertyContext(); 

		//Show the ToolsOptions 
 		void ShowToolsOptions();

		//Retrieve Xsd project Item information
 		Dictionary GetXsdProjectItemsInfo(); 

 		//Add assembly reference (including dynamic assembly resolution) 
		void AddAssemblyReference(AssemblyName assemblyName); 

 
 	}

    public interface IExtendedUIService2
    { 
        //Get current project's target version
        long GetTargetFrameworkVersion(); 
 
        //Get if the given type is supported in the current target framework
        bool IsSupportedType(Type type); 

        //Get the assembly loaded in reflection context for the current target framework.
        Assembly GetReflectionAssembly(AssemblyName assemblyName);
 
        //Get the current runtime type for the passed in reflection type. Reflection type is target framework type.
        Type GetRuntimeType(Type reflectionType); 
    } 
	#endregion
 
	#endregion

	#region Design Surface related classes and Interfaces
 
 	#region Interface IWorkflowDesignerMessageSink
	internal interface IWorkflowDesignerMessageSink 
 	{ 
 		bool OnMouseDown(MouseEventArgs e);
		bool OnMouseMove(MouseEventArgs e); 
 		bool OnMouseUp(MouseEventArgs e);
		bool OnMouseDoubleClick(MouseEventArgs e);
		bool OnMouseEnter(MouseEventArgs e);
		bool OnMouseHover(MouseEventArgs e); 
 		bool OnMouseLeave();
		bool OnMouseWheel(MouseEventArgs e); 
 		bool OnMouseCaptureChanged(); 
 		bool OnMouseDragBegin(Point initialPoint, MouseEventArgs e);
		bool OnMouseDragMove(MouseEventArgs e); 
 		bool OnMouseDragEnd();

		bool OnDragEnter(DragEventArgs e);
		bool OnDragOver(DragEventArgs e); 
		bool OnDragLeave();
 		bool OnDragDrop(DragEventArgs e); 
		bool OnGiveFeedback(GiveFeedbackEventArgs e); 
 		bool OnQueryContinueDrag(QueryContinueDragEventArgs e);
 
 		bool OnKeyDown(KeyEventArgs e);
		bool OnKeyUp(KeyEventArgs e);

        bool OnScroll(ScrollBar sender, int value); 
 		bool OnShowContextMenu(Point screenMenuPoint);
		bool ProcessMessage(Message message); 
 
		void OnLayout(LayoutEventArgs layoutEventArgs);
		void OnLayoutPosition(Graphics graphics); 
 		void OnLayoutSize(Graphics graphics);
		void OnThemeChange();

        void OnBeginResizing(DesignerEdges sizingEdge); 
        void OnResizing(DesignerEdges sizingEdge, Rectangle bounds);
        void OnEndResizing(); 
 
 		bool OnPaint(PaintEventArgs e, Rectangle viewPort);
 		bool OnPaintWorkflowAdornments(PaintEventArgs e, Rectangle viewPort); 
    }
	#endregion

 	#region Class ViewPortData 
	//
 
	internal sealed class ViewPortData 
    {
        public Rectangle LogicalViewPort; 
        public Bitmap MemoryBitmap;
        public SizeF Scaling = new SizeF(1.0f, 1.0f);
        public Point Translation = Point.Empty;
        public Size	ShadowDepth = Size.Empty; 
        public Color TransparentColor = Color.White;
        public Size ViewPortSize = Size.Empty; 
 	} 
	#endregion
 
 	#region Class ActivityDragEventArgs
    /// 
    /// EventArgs passed to the ActivityDesigners when drag drop operation is in progress on workflow.
    /// ActivityDesigners can access the information contained to influence the drag drop behavior. 
    /// 
 	public class ActivityDragEventArgs: DragEventArgs 
	{ 
 		private Point snapPoint = Point.Empty;
        private Point dragInitiationPoint = Point.Empty; 
        private List draggedActivities;

        internal ActivityDragEventArgs(DragEventArgs dragEventArgs, Point dragInitiationPoint, Point point, List draggedActivities)
            : base(dragEventArgs.Data, dragEventArgs.KeyState, point.X, point.Y, dragEventArgs.AllowedEffect, dragEventArgs.Effect) 
        {
            this.dragInitiationPoint = dragInitiationPoint; 
 
            if (draggedActivities == null)
                this.draggedActivities = new List(); 
            else
				this.draggedActivities = new List(draggedActivities);
        }
 
        /// 
        /// Returns Activities being dragged drop 
        ///  
        public ReadOnlyCollection Activities
        { 
            get
            {
                return this.draggedActivities.AsReadOnly();
            } 
        }
 
        ///  
        /// WorkflowView creates drag image for the activities being dragged.
        /// ActivityDesigners can choose to snap this image to a drop target to indicate that activities can be dropped at a particular location 
        /// 
        public Point DragImageSnapPoint
		{
			get 
 			{
                return this.snapPoint; 
            } 

			set 
 			{
                this.snapPoint = value;
            }
 		} 

        ///  
        /// Returns point at which the drag drop operation was initiated in logical coordinates 
        /// 
        public Point DragInitiationPoint 
        {
            get
            {
                return this.dragInitiationPoint; 
            }
        } 
	} 
 	#endregion
 
	#endregion

	#region Classes, Interfaces and enums used by Designers
 
	#region Class ActivityChangeEventArgs
 	///  
	/// Contains information about the changes made to the activity associated with the designer 
 	/// 
 	public class ActivityChangedEventArgs : EventArgs 
	{
 		private Activity activity;
		private MemberDescriptor member;
		private object oldValue; 
		private object newValue;
 
 		public ActivityChangedEventArgs(Activity activity, MemberDescriptor member, object oldValue, object newValue) 
		{
 			this.activity = activity; 
 			this.member = member;
			this.oldValue = oldValue;
 			this.newValue = newValue;
		} 

		///  
		/// Activity being changed 
 		/// 
		public Activity Activity 
 		{
 			get
			{
 				return this.activity; 
			}
		} 
 
		/// 
 		/// Member of the activity being changed 
		/// 
 		public MemberDescriptor Member
 		{
			get 
 			{
				return this.member; 
			} 
		}
 
 		/// 
		/// OldValue of the member before the change
 		/// 
 		public object OldValue 
		{
 			get 
			{ 
				return this.oldValue;
			} 
 		}

		/// 
 		/// New value of the member after the change 
 		/// 
		public object NewValue 
 		{ 
			get
			{ 
				return this.newValue;
 			}
		}
 	} 
 	#endregion
 
	#region Class ActivityDesignerLayoutEventArgs 
 	/// 
	/// Contains arguments passed to layout functions of ActivityDesigner 
	/// 
	public class ActivityDesignerLayoutEventArgs : EventArgs
 	{
		private Graphics graphics; 
 		private ActivityDesignerTheme designerTheme;
 
 		public ActivityDesignerLayoutEventArgs(Graphics graphics, ActivityDesignerTheme designerTheme) 
		{
 			this.graphics = graphics; 
			this.designerTheme = designerTheme;
		}

		///  
 		/// Gets the ambient theme associated with workflow
		///  
 		public AmbientTheme AmbientTheme 
 		{
			get 
 			{
				return WorkflowTheme.CurrentTheme.AmbientTheme;
			}
		} 

 		///  
		/// Gets the designet theme associated with activity designer 
 		/// 
 		public ActivityDesignerTheme DesignerTheme 
		{
 			get
			{
				return this.designerTheme; 
			}
 		} 
 
		/// 
 		/// Gets the graphics object on which the activity designer will be drawn 
 		/// 
		public Graphics Graphics
 		{
			get 
			{
				return this.graphics; 
 			} 
		}
 	} 
 	#endregion

	#region Class ActivityDesignerPaintEventArgs
 	///  
	/// Contains arguments passed to draw function of ActivityDesigner
	///  
	public class ActivityDesignerPaintEventArgs : EventArgs 
 	{
		private Graphics graphics; 
 		private Rectangle clipRectangle;
 		private Rectangle viewPort;
		private ActivityDesignerTheme designerTheme;
 
 		public ActivityDesignerPaintEventArgs(Graphics graphics, Rectangle clipRectangle, Rectangle viewPort, ActivityDesignerTheme designerTheme)
		{ 
			this.graphics = graphics; 
			this.clipRectangle = Rectangle.Inflate(clipRectangle, 1, 1);
 			this.viewPort = viewPort; 
			this.designerTheme = designerTheme;
 		}

 		///  
		/// Graphics object associated with design surface on which the activity needs to draw
 		///  
		public Graphics Graphics 
		{
			get 
 			{
				return this.graphics;
 			}
 		} 

		///  
 		/// Bounding rectangle outside which the activity can not draw 
		/// 
		public Rectangle ClipRectangle 
		{
 			get
			{
 				return this.clipRectangle; 
 			}
		} 
 
 		/// 
		/// Gets the ambient theme associated with Workflow 
		/// 
		public AmbientTheme AmbientTheme
 		{
			get 
 			{
 				return WorkflowTheme.CurrentTheme.AmbientTheme; 
			} 
 		}
 
		/// 
		/// Gets the theme associated with designer
		/// 
 		public ActivityDesignerTheme DesignerTheme 
		{
 			get 
 			{ 
				return this.designerTheme;
 			} 
		}

		internal Rectangle ViewPort
		{ 
 			get
			{ 
 				return this.viewPort; 
 			}
		} 
 	}
	#endregion

    #region Class ActivityDesignerResizeEventArgs 
    public class ActivityDesignerResizeEventArgs : EventArgs
    { 
        private DesignerEdges sizingEdge; 
        private Rectangle newBounds;
 
        public ActivityDesignerResizeEventArgs(DesignerEdges sizingEdge, Rectangle newBounds)
        {
            this.sizingEdge = sizingEdge;
            this.newBounds = newBounds; 
        }
 
        public DesignerEdges SizingEdge 
        {
            get 
            {
                return this.sizingEdge;
            }
        } 

        public Rectangle Bounds 
        { 
            get
            { 
                return this.newBounds;
            }
        }
    } 
    #endregion
 
    #region Enum DesignerEdges 
    [Flags]
    public enum DesignerEdges 
    {
        None = 0,
        Left = 1,
        Top = 2, 
        Right = 4,
        Bottom = 8, 
        All = 15 
    }
    #endregion 

    #region Interface IDesignerGlyphProvider
    /// 
    /// Allows the user to add custom glyph providers. 
    /// Custom glyph providers are called to render the glyphs on designer.
    ///  
	public interface IDesignerGlyphProviderService 
	{
 		void AddGlyphProvider(IDesignerGlyphProvider glyphProvider); 
		void RemoveGlyphProvider(IDesignerGlyphProvider glyphProvider);
        ReadOnlyCollection GlyphProviders { get;}
    }
 
 	public interface IDesignerGlyphProvider
 	{ 
        ActivityDesignerGlyphCollection GetGlyphs(ActivityDesigner activityDesigner); 
	}
 	#endregion 

    #region Interface IDesignerVerbProvider
    /// 
    /// Allows the user to add custom verb providers. 
    /// Custom verb providers are called in order to return the set of verbs associated with the designer.
    ///  
    public interface IDesignerVerbProviderService 
    {
        void AddVerbProvider(IDesignerVerbProvider verbProvider); 
        void RemoveVerbProvider(IDesignerVerbProvider verbProvider);
        ReadOnlyCollection VerbProviders { get;}
    }
 
    public interface IDesignerVerbProvider
    { 
        ActivityDesignerVerbCollection GetVerbs(ActivityDesigner activityDesigner); 
    }
    #endregion 

    #region Interface IPersistUIState
    public interface IPersistUIState
    { 
        void SaveViewState(BinaryWriter writer);
        void LoadViewState(BinaryReader reader); 
    } 
    #endregion
 
    #region Interface IWorkflowRootDesigner
    public interface IWorkflowRootDesigner : IRootDesigner
    {
        CompositeActivityDesigner InvokingDesigner { get;set;} 
        ReadOnlyCollection MessageFilters {get;}
        bool IsSupportedActivityType(Type activityType); 
        bool SupportsLayoutPersistence { get;} 
    }
    #endregion 

    #region Used for keyboard navigation
    public enum DesignerNavigationDirection
	{ 
		Down = 0,//Next
		Up = 1,//Previous 
 		Left = 2, 
		Right = 3
 	} 
 	#endregion

	#region enum HitTestLocations
 	///  
    /// Enumeration returning area of the designer which was under the point passed to hit test.
    ///  
    [FlagsAttribute] 
    public enum HitTestLocations
    { 
        None = 0,
        Designer = 1,
        ActionArea = 2,
        Left = 4, 
        Top = 8,
        Right = 16, 
        Bottom = 32, 
        Connector = 64
    } 
    #endregion

    #region Class HitTestInfo
    ///  
    /// Identifies the part of the designer at the specified location.
    /// Used by various operation including drag-drop, cut-paste etc 
    ///  
    public class HitTestInfo
    { 
        private static HitTestInfo nowhere;
        private ActivityDesigner activityDesigner = null;
		private HitTestLocations location = HitTestLocations.None;
        private IDictionary userData; 

        ///  
        /// Returns Empty HitTestInfo 
        /// 
        public static HitTestInfo Nowhere 
        {
            get
            {
                if (HitTestInfo.nowhere == null) 
                    HitTestInfo.nowhere = new HitTestInfo();
                return HitTestInfo.nowhere; 
            } 
        }
 
        internal HitTestInfo()
        {
        }
 
        /// 
        /// Constructs HitTestInfo with specified parameters 
        ///  
        /// ActivityDesigner associated with HitTestInfo
		/// HitTestLocations indicating where the hit happened 
		public HitTestInfo(ActivityDesigner designer, HitTestLocations location)
        {
            if (designer == null)
                throw new ArgumentNullException("designer"); 

            this.activityDesigner = designer; 
            this.location = location; 
        }
 
        /// 
        /// Returns designer associated
        /// 
        [Browsable(false)] 
        public ActivityDesigner AssociatedDesigner
        { 
            get 
            {
                return this.activityDesigner; 
            }
        }

        ///  
        /// Returns flags indicating where hit happened
        ///  
        [Browsable(false)] 
        public HitTestLocations HitLocation
        { 
            get
            {
                return this.location;
            } 
        }
 
        ///  
        /// Returns enclosing bounds for the hit area
        ///  
        [Browsable(false)]
        public virtual Rectangle Bounds
        {
            get 
            {
                if (this.activityDesigner != null) 
                    return this.activityDesigner.Bounds; 
                else
                    return Rectangle.Empty; 
            }
        }

        ///  
        /// Returns selectable object associated with Hit Area
        ///  
        [Browsable(false)] 
        public virtual object SelectableObject
        { 
            get
            {
                if (this.activityDesigner != null)
                    return this.activityDesigner.Activity; 
                else
                    return null; 
            } 
        }
 
        /// 
 		/// Returns UserData to associated with HitLocation
        /// 
        [Browsable(false)] 
        public IDictionary UserData
        { 
            get 
            {
                if (this.userData == null) 
                    this.userData = new HybridDictionary();
                return this.userData;
            }
        } 

        ///  
        /// Maps Hit area to index using which designers are to be inserted. 
        /// 
        ///  
        public virtual int MapToIndex()
        {
            CompositeActivity compositeActivity = this.activityDesigner.Activity as CompositeActivity;
            if (compositeActivity != null) 
                return compositeActivity.Activities.Count;
            else 
                return 0; 
        }
    } 
    #endregion

	#region Class ConnectorHitTestInfo
 	///  
 	/// Represents the hittest information for connectors within the designer, structured designers are expected to have connectors within them
	///  
 	public class ConnectorHitTestInfo : HitTestInfo 
	{
		private int connector = 0; 

		/// 
 		/// Constructor for ConnectorHitTestInfo
		///  
 		/// Designer associated with the HitTestInfo
 		/// Flags where HitTest occured 
		/// Index of the connector which was hit 
 		public ConnectorHitTestInfo(CompositeActivityDesigner compositeActivityDesigner, HitTestLocations flags, int connector)
			: base(compositeActivityDesigner, flags) 
		{
			if (this.connector < 0)
 				throw new ArgumentException(SR.GetString(SR.Error_InvalidConnectorValue), "connector");
 
			this.connector = connector;
 		} 
 
 		public override Rectangle Bounds
		{ 
 			get
			{
				//
				SequentialActivityDesigner sequentialActivityDesigner = AssociatedDesigner as SequentialActivityDesigner; 
 				if (sequentialActivityDesigner != null && sequentialActivityDesigner.Expanded)
                { 
                    Rectangle[] connectors = sequentialActivityDesigner.GetConnectors(); 
                    if(connectors.Length > 0)
                        return connectors[this.connector]; 
                }

                return Rectangle.Empty;
			} 
 		}
 
 		public override object SelectableObject 
		{
 			get 
			{
				return this;
			}
 		} 

		public override int MapToIndex() 
 		{ 
 			return this.connector;
		} 

 		public override bool Equals(object obj)
		{
			ConnectorHitTestInfo destinationConnector = obj as ConnectorHitTestInfo; 
			if (destinationConnector != null)
 			{ 
				if (destinationConnector.AssociatedDesigner == AssociatedDesigner && 
 					destinationConnector.HitLocation == HitLocation &&
 					destinationConnector.MapToIndex() == MapToIndex()) 
					return true;
 			}

			return false; 
		}
 
		public override int GetHashCode() 
 		{
			return base.GetHashCode() ^ ((AssociatedDesigner != null) ? AssociatedDesigner.GetHashCode() : 0) ^ MapToIndex().GetHashCode(); 
 		}
 	}
	#endregion
 
    #region Class DesignerAction
    //Public class as ActivityDesigners can provide their own DesignerActions 
    public sealed class DesignerAction 
    {
        private ActivityDesigner activityDesigner; 
 		private int actionId;
        private string text;
        private Image image;
        private IDictionary  userData; 
		private string propertyName = null;
 
        public DesignerAction(ActivityDesigner activityDesigner, int actionId, string text) 
        {
            if (activityDesigner == null) 
                throw new ArgumentNullException("activityDesigner");

            if (text == null || text.Length == 0)
                throw new ArgumentException(SR.GetString(SR.Error_NullOrEmptyValue), "text"); 

            this.activityDesigner = activityDesigner; 
			this.actionId = actionId; 
            this.text = text;
        } 

		public DesignerAction(ActivityDesigner activityDesigner, int actionId, string text, Image image)
 			: this(activityDesigner, actionId, text)
        { 
            this.image = image;
        } 
 
		public string PropertyName
 		{ 
 			get
			{
 				return this.propertyName;
			} 
			set
			{ 
 				this.propertyName = value; 
			}
 		} 

        public int ActionId
        {
            get 
            {
 				return this.actionId; 
            } 
        }
 
        public string Text
        {
            get
            { 
                return this.text;
            } 
        } 

        public Image Image 
        {
            get
            {
                return this.image; 
            }
        } 
 
		public IDictionary UserData
        { 
            get
            {
 				if (this.userData == null)
					this.userData = new HybridDictionary(); 
				return this.userData;
            } 
        } 

        public void Invoke() 
        {
            this.activityDesigner.OnExecuteDesignerAction(this);
        }
    } 
    #endregion
 
    #region Enum DesignerVerbGroup 
    /// 
    /// Provides categories for grouping of similar verbs 
    /// 
    public enum DesignerVerbGroup
    {
        General = 0, 
        View = 1,
        Edit = 2, 
        Options = 3, 
        Actions = 4,
        Misc = 5 
    }
    #endregion

    #region Class ActivityDesignerVerb 
    /// 
    /// DesignerVerb class specific to ActivityDesigners. 
    /// Allows user to group similar types of DesignerVerbs togather. 
    /// Provides user the ability to update the status of the verb.
    ///  
    public class ActivityDesignerVerb : DesignerVerb
    {
        private ActivityDesigner activityDesigner = null;
        private EventHandler invokeHandler = null; 
        private EventHandler statusHandler = null;
        private DesignerVerbGroup verbGroup; 
        private int id = 0; 

        public ActivityDesignerVerb(ActivityDesigner activityDesigner, DesignerVerbGroup verbGroup, string text, EventHandler invokeHandler) 
            : base(text, new EventHandler(OnExecuteDesignerVerb), new CommandID(WorkflowMenuCommands.MenuGuid, 0))
        {
            if (text == null || text.Length == 0)
                throw new ArgumentNullException("text"); 

            if (invokeHandler == null) 
                throw new ArgumentNullException("invokeHandler"); 

            this.verbGroup = verbGroup; 
            this.invokeHandler = invokeHandler;
            this.activityDesigner = activityDesigner;
        }
 
        public ActivityDesignerVerb(ActivityDesigner activityDesigner, DesignerVerbGroup verbGroup, string text, EventHandler invokeHandler, EventHandler statusHandler)
            : this(activityDesigner, verbGroup, text, invokeHandler) 
        { 
            this.statusHandler = statusHandler;
        } 

        public override int OleStatus
        {
            get 
            {
                if (statusHandler != null) 
                { 
                    try
                    { 
                        statusHandler(this, EventArgs.Empty);
                    }
                    catch
                    { 
                    }
                } 
 
                return base.OleStatus;
            } 
        }

        public override CommandID CommandID
        { 
            get
            { 
                return new CommandID(WorkflowMenuCommands.MenuGuid, this.id); 
            }
        } 

        public DesignerVerbGroup Group
        {
            get 
            {
                return this.verbGroup; 
            } 
        }
 
        internal int Id
        {
            get
            { 
                return this.id;
            } 
 
            set
            { 
                this.id = value;
            }
        }
 
        internal ActivityDesigner ActivityDesigner
        { 
            get 
            {
                return this.activityDesigner; 
            }
        }

        private static void OnExecuteDesignerVerb(object sender, EventArgs e) 
        {
            ActivityDesignerVerb activityDesignerVerb = sender as ActivityDesignerVerb; 
            if (activityDesignerVerb != null) 
            {
                if (activityDesignerVerb.invokeHandler != null) 
                    activityDesignerVerb.invokeHandler(sender, e);

                int status = activityDesignerVerb.OleStatus;
                status = 0; 

                if (activityDesignerVerb.activityDesigner != null) 
                { 
                    foreach (DesignerVerb verb in ((IDesigner)activityDesignerVerb.activityDesigner).Verbs)
                    { 
                        if (verb is ActivityDesignerVerb)
                        {
                            //Update the status of the
                            status = verb.OleStatus; 
                            status = 0;
                        } 
                    } 
                }
            } 
        }
    }
    #endregion
 
    #region Class ActivityDesignerVerbCollection
    ///  
    /// Maintains collection of ActivityDesignerVerbs. 
    /// Groups verbs belonging to the same veb groups and ensures that their identifiers are consecutive.
    ///  
	[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
 	[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
    public sealed class ActivityDesignerVerbCollection : DesignerVerbCollection
    { 
        public ActivityDesignerVerbCollection()
        { 
        } 

        public ActivityDesignerVerbCollection(IEnumerable verbs) 
        {
			if (verbs == null)
 				throw new ArgumentNullException("verbs");
 
            foreach(ActivityDesignerVerb verb in verbs)
 			    Add(verb); 
        } 

        protected override void OnValidate(object value) 
        {
            if (!(value is ActivityDesignerVerb))
                throw new InvalidOperationException(SR.GetString(SR.Error_InvalidDesignerVerbValue));
        } 

        ///  
        /// Returns a collection that is consumable by MenuCommandService. Verbs in the 
        /// safe collection have Ids in the range of VerbFirst.ID to VerbLast.ID. Also,
        /// the items are sorted, and the first item ID == VerbFirst.ID 
        /// 
        internal ActivityDesignerVerbCollection SafeCollection
        {
            get 
            {
                if (this.Count == 0) 
                    return this; 

                Dictionary> activityDesignerVerbs = new Dictionary>(); 
                ArrayList safeCollection = new ArrayList(this);

                // set Ids
                foreach (ActivityDesignerVerb verb in safeCollection) 
                {
                    List verbList = null; 
                    if (!activityDesignerVerbs.ContainsKey(verb.Group)) 
                    {
                        verbList = new List(); 
                        activityDesignerVerbs.Add(verb.Group, verbList);
                    }
                    else
                    { 
                        verbList = activityDesignerVerbs[verb.Group];
                    } 
 
                    if (!verbList.Contains(verb))
                    { 
                        verb.Id = ConvertGroupToId(verb.Group) + verbList.Count;
                        verbList.Add(verb);
                    }
                } 

                //items should be sorted by verb id 
                safeCollection.Sort(new ActivityDesignerVerbComparer()); 

                // add first dummy verb if needed 
                if (((ActivityDesignerVerb)safeCollection[0]).Id != MenuCommands.VerbFirst.ID)
                {
                    safeCollection.Insert(0, new ActivityDesignerVerb(null, DesignerVerbGroup.General, "Dummy", new EventHandler(OnDummyVerb)));
                    ((ActivityDesignerVerb)safeCollection[0]).Visible = false; 
                }
 
                ActivityDesignerVerbCollection verbs = new ActivityDesignerVerbCollection(); 
                foreach (ActivityDesignerVerb verb in safeCollection)
                    verbs.Add(verb); 

                return verbs;
            }
        } 

        private void OnDummyVerb(object sender, EventArgs e) 
        { 
            // Should never be called
        } 

        private int ConvertGroupToId(DesignerVerbGroup group)
        {
            if (group == DesignerVerbGroup.General) 
                return WorkflowMenuCommands.VerbGroupGeneral;
            else if (group == DesignerVerbGroup.View) 
                return WorkflowMenuCommands.VerbGroupView; 
            else if (group == DesignerVerbGroup.Edit)
                return WorkflowMenuCommands.VerbGroupEdit; 
            else if (group == DesignerVerbGroup.Options)
                return WorkflowMenuCommands.VerbGroupOptions;
            else if (group == DesignerVerbGroup.Actions)
                return WorkflowMenuCommands.VerbGroupActions; 
            else
                return WorkflowMenuCommands.VerbGroupMisc; 
        } 
        #region class ActivityDesignerVerbComparer
 
        private class ActivityDesignerVerbComparer : IComparer
        {
            #region IComparer Members
 
            public int Compare(object x, object y)
            { 
                ActivityDesignerVerb verb1 = x as ActivityDesignerVerb; 
                ActivityDesignerVerb verb2 = y as ActivityDesignerVerb;
 
                if (verb1.Id == verb2.Id)
                    return 0;
                else if (verb1.Id > verb2.Id)
                    return 1; 
                else
                    return -1; 
            } 
            #endregion
        } 

        #endregion

    } 
    #endregion
 
	#endregion 

 	#region ITypeFilterProvider Interface 
	public interface ITypeFilterProvider
	{
		bool CanFilterType(Type type, bool throwOnError);
 		string FilterDescription { get; } 
	}
 	#endregion 
 
 	#region TypeFilterProviderAttribute
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = false)] 
 	public sealed class TypeFilterProviderAttribute : Attribute
	{
		private string typeName = null;
 
		public TypeFilterProviderAttribute(Type type)
 		{ 
			if (type == null) 
 				throw new ArgumentNullException("type");
 
 			this.typeName = type.AssemblyQualifiedName;
		}

 		public TypeFilterProviderAttribute(string typeName) 
		{
			this.typeName = typeName; 
		} 

 		public string TypeFilterProviderTypeName 
		{
 			get
 			{
				return this.typeName; 
 			}
		} 
	} 
	#endregion
 
 	#region ITypeProviderCreator Interface
	[Guid("0E6DF9D7-B4B5-4af7-9647-FC335CCE393F")]
 	[ComVisible(true)]
 	public interface ITypeProviderCreator 
	{
 		ITypeProvider			GetTypeProvider(object obj); 
		Assembly				GetLocalAssembly(object obj); 
		Assembly				GetTransientAssembly(AssemblyName assemblyName);
		ITypeResolutionService	GetTypeResolutionService(object obj); 
 	}
	#endregion
}

// 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