internal static ReadOnlyCollection<DesignerView> GetViews(StructuredCompositeActivityDesigner designer)
        {
            Debug.Assert(designer.Activity != null);
            if (designer.Activity == null)
                throw new ArgumentException("Component can not be null!");

            bool locked = !designer.IsEditable;

            //Get all the possible view types
            List<object[]> viewTypes = new List<object[]>();

            string displayName = ActivityToolboxItem.GetToolboxDisplayName(designer.Activity.GetType());
            viewTypes.Add(new object[] { designer.Activity.GetType(), DR.GetString(DR.ViewActivity, displayName) });

            //Only show the views in workflow designer or for nested activities
            if (designer.Activity.Site != null)
            {
                WorkflowDesignerLoader loader = designer.Activity.Site.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                Type activityType = designer.Activity.GetType();

                if (loader == null ||
                    (typeof(CompositeActivity).IsAssignableFrom(activityType) &&
                    (!locked || FindActivity(designer, typeof(CancellationHandlerActivity)) != null)))
                    viewTypes.Add(new object[] { typeof(CancellationHandlerActivity), DR.GetString(DR.ViewCancelHandler) });

                if (loader == null ||
                    (typeof(CompositeActivity).IsAssignableFrom(activityType) &&
                    (!locked || FindActivity(designer, typeof(FaultHandlersActivity)) != null)))
                    viewTypes.Add(new object[] { typeof(FaultHandlersActivity), DR.GetString(DR.ViewExceptions) });

                if (loader == null ||
                    (designer.Activity is ICompensatableActivity && typeof(CompositeActivity).IsAssignableFrom(activityType) &&
                    (!locked || FindActivity(designer, typeof(CompensationHandlerActivity)) != null)))
                    viewTypes.Add(new object[] { typeof(CompensationHandlerActivity), DR.GetString(DR.ViewCompensation) });

                if (loader == null ||
                    (Type.GetType(EventHandlingScopeRef).IsAssignableFrom(activityType) &&
                    (!locked || FindActivity(designer, Type.GetType(EventHandlersRef)) != null)))
                    viewTypes.Add(new object[] { Type.GetType(EventHandlersRef), DR.GetString(DR.ViewEvents) });
            }

            //Now go through the view types and create views
            List<DesignerView> views = new List<DesignerView>();
            for (int i = 0; i < viewTypes.Count; i++)
            {
                Type viewType = viewTypes[i][0] as Type;
                DesignerView view = new SecondaryView(designer, i + 1, viewTypes[i][1] as string, viewType);
                views.Add(view);
            }

            return views.AsReadOnly();
        }
        internal static void OnViewRemoved(StructuredCompositeActivityDesigner designer, Type viewTypeRemoved)
        {
            ReadOnlyCollection <DesignerView> views = designer.Views;

            for (int i = 1; i < views.Count; i++)
            {
                Type type = views[i].UserData[SecondaryView.UserDataKey_ActivityType] as Type;
                if (viewTypeRemoved == type)
                {
                    views[i].UserData[SecondaryView.UserDataKey_Designer] = null;
                }
            }
        }
        internal static Activity FindActivity(StructuredCompositeActivityDesigner designer, Type activityType)
        {
            CompositeActivity activity = designer.Activity as CompositeActivity;

            if ((activityType != null) && (activity != null))
            {
                foreach (Activity activity2 in activity.Activities)
                {
                    if (activityType.IsAssignableFrom(activity2.GetType()))
                    {
                        return(activity2);
                    }
                }
            }
            return(null);
        }
        internal static ReadOnlyCollection <DesignerView> GetViews(StructuredCompositeActivityDesigner designer)
        {
            if (designer.Activity == null)
            {
                throw new ArgumentException("Component can not be null!");
            }
            bool            flag = !designer.IsEditable;
            List <object[]> list = new List <object[]>();
            string          toolboxDisplayName = ActivityToolboxItem.GetToolboxDisplayName(designer.Activity.GetType());

            list.Add(new object[] { designer.Activity.GetType(), DR.GetString("ViewActivity", new object[] { toolboxDisplayName }) });
            if (designer.Activity.Site != null)
            {
                WorkflowDesignerLoader service = designer.Activity.Site.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                Type c = designer.Activity.GetType();
                if ((service == null) || (typeof(CompositeActivity).IsAssignableFrom(c) && (!flag || (FindActivity(designer, typeof(CancellationHandlerActivity)) != null))))
                {
                    list.Add(new object[] { typeof(CancellationHandlerActivity), DR.GetString("ViewCancelHandler", new object[0]) });
                }
                if ((service == null) || (typeof(CompositeActivity).IsAssignableFrom(c) && (!flag || (FindActivity(designer, typeof(FaultHandlersActivity)) != null))))
                {
                    list.Add(new object[] { typeof(FaultHandlersActivity), DR.GetString("ViewExceptions", new object[0]) });
                }
                if ((service == null) || (((designer.Activity is ICompensatableActivity) && typeof(CompositeActivity).IsAssignableFrom(c)) && (!flag || (FindActivity(designer, typeof(CompensationHandlerActivity)) != null))))
                {
                    list.Add(new object[] { typeof(CompensationHandlerActivity), DR.GetString("ViewCompensation", new object[0]) });
                }
                if ((service == null) || (Type.GetType("System.Workflow.Activities.EventHandlingScopeActivity, System.Workflow.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35").IsAssignableFrom(c) && (!flag || (FindActivity(designer, Type.GetType("System.Workflow.Activities.EventHandlersActivity, System.Workflow.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")) != null))))
                {
                    list.Add(new object[] { Type.GetType("System.Workflow.Activities.EventHandlersActivity, System.Workflow.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"), DR.GetString("ViewEvents", new object[0]) });
                }
            }
            List <DesignerView> list2 = new List <DesignerView>();

            for (int i = 0; i < list.Count; i++)
            {
                Type         activityType = list[i][0] as Type;
                DesignerView item         = new SecondaryView(designer, i + 1, list[i][1] as string, activityType);
                list2.Add(item);
            }
            return(list2.AsReadOnly());
        }
        internal static Activity FindActivity(StructuredCompositeActivityDesigner designer, Type activityType)
        {
            Debug.Assert(activityType != null);
            CompositeActivity compositeActivity = designer.Activity as CompositeActivity;

            if (activityType == null || compositeActivity == null)
            {
                return(null);
            }

            foreach (Activity activity in compositeActivity.Activities)
            {
                if (activityType.IsAssignableFrom(activity.GetType()))
                {
                    return(activity);
                }
            }

            return(null);
        }
 internal static IList<Type> GetActivityTypes(StructuredCompositeActivityDesigner designer)
 {
     List<Type> activityTypes = new List<Type>();
     ReadOnlyCollection<DesignerView> views = designer.Views;
     for (int i = 1; i < views.Count; i++)
     {
         Type activityType = views[i].UserData[SecondaryView.UserDataKey_ActivityType] as Type;
         activityTypes.Add(activityType);
     }
     return activityTypes.AsReadOnly();
 }
 internal SecondaryView(StructuredCompositeActivityDesigner parentDesigner, int id, string text, Type activityType)
     : base(id, text, ActivityToolboxItem.GetToolboxImage(activityType))
 {
     this.parentDesigner = parentDesigner;
     UserData[UserDataKey_ActivityType] = activityType;
     if (this.parentDesigner.Activity.GetType() == activityType)
         UserData[UserDataKey_Designer] = this.parentDesigner;
 }
        internal static Activity FindActivity(StructuredCompositeActivityDesigner designer, Type activityType)
        {
            Debug.Assert(activityType != null);
            CompositeActivity compositeActivity = designer.Activity as CompositeActivity;
            if (activityType == null || compositeActivity == null)
                return null;

            foreach (Activity activity in compositeActivity.Activities)
            {
                if (activityType.IsAssignableFrom(activity.GetType()))
                    return activity;
            }

            return null;
        }
 internal static void OnViewRemoved(StructuredCompositeActivityDesigner designer, Type viewTypeRemoved)
 {
     ReadOnlyCollection<DesignerView> views = designer.Views;
     for (int i = 1; i < views.Count; i++)
     {
         Type activityType = views[i].UserData[SecondaryView.UserDataKey_ActivityType] as Type;
         if (viewTypeRemoved == activityType)
             views[i].UserData[SecondaryView.UserDataKey_Designer] = null;
     }
 }
        internal static ReadOnlyCollection <DesignerView> GetViews(StructuredCompositeActivityDesigner designer)
        {
            Debug.Assert(designer.Activity != null);
            if (designer.Activity == null)
            {
                throw new ArgumentException("Component can not be null!");
            }

            bool locked = !designer.IsEditable;

            //Get all the possible view types
            List <object[]> viewTypes = new List <object[]>();

            string displayName = ActivityToolboxItem.GetToolboxDisplayName(designer.Activity.GetType());

            viewTypes.Add(new object[] { designer.Activity.GetType(), DR.GetString(DR.ViewActivity, displayName) });

            //Only show the views in workflow designer or for nested activities
            if (designer.Activity.Site != null)
            {
                WorkflowDesignerLoader loader = designer.Activity.Site.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                Type activityType             = designer.Activity.GetType();

                if (loader == null ||
                    (typeof(CompositeActivity).IsAssignableFrom(activityType) &&
                     (!locked || FindActivity(designer, typeof(CancellationHandlerActivity)) != null)))
                {
                    viewTypes.Add(new object[] { typeof(CancellationHandlerActivity), DR.GetString(DR.ViewCancelHandler) });
                }

                if (loader == null ||
                    (typeof(CompositeActivity).IsAssignableFrom(activityType) &&
                     (!locked || FindActivity(designer, typeof(FaultHandlersActivity)) != null)))
                {
                    viewTypes.Add(new object[] { typeof(FaultHandlersActivity), DR.GetString(DR.ViewExceptions) });
                }

                if (loader == null ||
                    (designer.Activity is ICompensatableActivity && typeof(CompositeActivity).IsAssignableFrom(activityType) &&
                     (!locked || FindActivity(designer, typeof(CompensationHandlerActivity)) != null)))
                {
                    viewTypes.Add(new object[] { typeof(CompensationHandlerActivity), DR.GetString(DR.ViewCompensation) });
                }

                if (loader == null ||
                    (Type.GetType(EventHandlingScopeRef).IsAssignableFrom(activityType) &&
                     (!locked || FindActivity(designer, Type.GetType(EventHandlersRef)) != null)))
                {
                    viewTypes.Add(new object[] { Type.GetType(EventHandlersRef), DR.GetString(DR.ViewEvents) });
                }
            }

            //Now go through the view types and create views
            List <DesignerView> views = new List <DesignerView>();

            for (int i = 0; i < viewTypes.Count; i++)
            {
                Type         viewType = viewTypes[i][0] as Type;
                DesignerView view     = new SecondaryView(designer, i + 1, viewTypes[i][1] as string, viewType);
                views.Add(view);
            }

            return(views.AsReadOnly());
        }