protected override object CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type)
        {
            if (serializationManager == null)
            {
                throw new ArgumentNullException("serializationManager");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            Connector                connector = null;
            IReferenceService        service   = serializationManager.GetService(typeof(IReferenceService)) as IReferenceService;
            FreeformActivityDesigner designer  = serializationManager.Context[typeof(FreeformActivityDesigner)] as FreeformActivityDesigner;

            if ((designer != null) && (service != null))
            {
                ConnectionPoint source = null;
                ConnectionPoint target = null;
                try
                {
                    Dictionary <string, string> connectorConstructionArguments = this.GetConnectorConstructionArguments(serializationManager, type);
                    if ((connectorConstructionArguments.ContainsKey("SourceActivity") && connectorConstructionArguments.ContainsKey("SourceConnectionIndex")) && connectorConstructionArguments.ContainsKey("SourceConnectionEdge"))
                    {
                        ActivityDesigner associatedDesigner = ActivityDesigner.GetDesigner(service.GetReference(connectorConstructionArguments["SourceActivity"]) as Activity);
                        DesignerEdges    designerEdge       = (DesignerEdges)Enum.Parse(typeof(DesignerEdges), connectorConstructionArguments["SourceConnectionEdge"]);
                        int connectionIndex = Convert.ToInt32(connectorConstructionArguments["SourceConnectionIndex"], CultureInfo.InvariantCulture);
                        if (((associatedDesigner != null) && (designerEdge != DesignerEdges.None)) && (connectionIndex >= 0))
                        {
                            source = new ConnectionPoint(associatedDesigner, designerEdge, connectionIndex);
                        }
                    }
                    if ((connectorConstructionArguments.ContainsKey("TargetActivity") && connectorConstructionArguments.ContainsKey("TargetConnectionIndex")) && connectorConstructionArguments.ContainsKey("TargetConnectionEdge"))
                    {
                        ActivityDesigner designer3 = ActivityDesigner.GetDesigner(service.GetReference(connectorConstructionArguments["TargetActivity"]) as Activity);
                        DesignerEdges    edges2    = (DesignerEdges)Enum.Parse(typeof(DesignerEdges), connectorConstructionArguments["TargetConnectionEdge"]);
                        int num2 = Convert.ToInt32(connectorConstructionArguments["TargetConnectionIndex"], CultureInfo.InvariantCulture);
                        if (((designer3 != null) && (edges2 != DesignerEdges.None)) && (num2 >= 0))
                        {
                            target = new ConnectionPoint(designer3, edges2, num2);
                        }
                    }
                }
                catch
                {
                }
                if ((source != null) && (target != null))
                {
                    connector = designer.AddConnector(source, target);
                }
            }
            return(connector);
        }
        protected override object CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type)
        {
            if (serializationManager == null)
            {
                throw new ArgumentNullException("serializationManager");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            object designer = null;

            IDesignerHost host   = serializationManager.GetService(typeof(IDesignerHost)) as IDesignerHost;
            XmlReader     reader = serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader;

            if (host != null && reader != null)
            {
                //Find the associated activity
                string associatedActivityName = String.Empty;
                while (reader.MoveToNextAttribute() && !reader.LocalName.Equals("Name", StringComparison.Ordinal))
                {
                    ;
                }
                if (reader.LocalName.Equals("Name", StringComparison.Ordinal) && reader.ReadAttributeValue())
                {
                    associatedActivityName = reader.Value;
                }
                reader.MoveToElement();

                if (!String.IsNullOrEmpty(associatedActivityName))
                {
                    CompositeActivityDesigner parentDesigner = serializationManager.Context[typeof(CompositeActivityDesigner)] as CompositeActivityDesigner;
                    if (parentDesigner == null)
                    {
                        Activity activity = host.RootComponent as Activity;
                        if (activity != null && !associatedActivityName.Equals(activity.Name, StringComparison.Ordinal))
                        {
                            foreach (IComponent component in host.Container.Components)
                            {
                                activity = component as Activity;
                                if (activity != null && associatedActivityName.Equals(activity.Name, StringComparison.Ordinal))
                                {
                                    break;
                                }
                            }
                        }

                        if (activity != null)
                        {
                            designer = host.GetDesigner(activity);
                        }
                    }
                    else
                    {
                        CompositeActivity compositeActivity = parentDesigner.Activity as CompositeActivity;
                        if (compositeActivity != null)
                        {
                            Activity matchingActivity = null;
                            foreach (Activity activity in compositeActivity.Activities)
                            {
                                if (associatedActivityName.Equals(activity.Name, StringComparison.Ordinal))
                                {
                                    matchingActivity = activity;
                                    break;
                                }
                            }

                            if (matchingActivity != null)
                            {
                                designer = host.GetDesigner(matchingActivity);
                            }
                        }
                    }

                    if (designer == null)
                    {
                        serializationManager.ReportError(SR.GetString(SR.Error_LayoutSerializationActivityNotFound, reader.LocalName, associatedActivityName, "Name"));
                    }
                }
                else
                {
                    serializationManager.ReportError(SR.GetString(SR.Error_LayoutSerializationAssociatedActivityNotFound, reader.LocalName, "Name"));
                }
            }

            return(designer);
        }
        protected override object CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type)
        {
            if (serializationManager == null)
            {
                throw new ArgumentNullException("serializationManager");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            Connector connector = null;

            IReferenceService        referenceService = serializationManager.GetService(typeof(IReferenceService)) as IReferenceService;
            FreeformActivityDesigner freeformDesigner = serializationManager.Context[typeof(FreeformActivityDesigner)] as FreeformActivityDesigner;

            if (freeformDesigner != null && referenceService != null)
            {
                ConnectionPoint sourceConnection = null;
                ConnectionPoint targetConnection = null;

                try
                {
                    Dictionary <string, string> constructionArguments = GetConnectorConstructionArguments(serializationManager, type);

                    if (constructionArguments.ContainsKey("SourceActivity") &&
                        constructionArguments.ContainsKey("SourceConnectionIndex") &&
                        constructionArguments.ContainsKey("SourceConnectionEdge"))
                    {
                        ActivityDesigner sourceDesigner = ActivityDesigner.GetDesigner(referenceService.GetReference(constructionArguments["SourceActivity"] as string) as Activity);
                        DesignerEdges    sourceEdge     = (DesignerEdges)Enum.Parse(typeof(DesignerEdges), constructionArguments["SourceConnectionEdge"] as string);
                        int sourceIndex = Convert.ToInt32(constructionArguments["SourceConnectionIndex"] as string, System.Globalization.CultureInfo.InvariantCulture);
                        if (sourceDesigner != null && sourceEdge != DesignerEdges.None && sourceIndex >= 0)
                        {
                            sourceConnection = new ConnectionPoint(sourceDesigner, sourceEdge, sourceIndex);
                        }
                    }

                    if (constructionArguments.ContainsKey("TargetActivity") &&
                        constructionArguments.ContainsKey("TargetConnectionIndex") &&
                        constructionArguments.ContainsKey("TargetConnectionEdge"))
                    {
                        ActivityDesigner targetDesigner = ActivityDesigner.GetDesigner(referenceService.GetReference(constructionArguments["TargetActivity"] as string) as Activity);
                        DesignerEdges    targetEdge     = (DesignerEdges)Enum.Parse(typeof(DesignerEdges), constructionArguments["TargetConnectionEdge"] as string);
                        int targetIndex = Convert.ToInt32(constructionArguments["TargetConnectionIndex"] as string, System.Globalization.CultureInfo.InvariantCulture);
                        if (targetDesigner != null && targetEdge != DesignerEdges.None && targetIndex >= 0)
                        {
                            targetConnection = new ConnectionPoint(targetDesigner, targetEdge, targetIndex);
                        }
                    }
                }
                catch
                {
                }

                if (sourceConnection != null && targetConnection != null)
                {
                    connector = freeformDesigner.AddConnector(sourceConnection, targetConnection);
                }
            }

            return(connector);
        }
Exemple #4
0
        protected override object CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type)
        {
            Activity activity3;

            if (serializationManager == null)
            {
                throw new ArgumentNullException("serializationManager");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            object        obj2    = null;
            IDesignerHost service = serializationManager.GetService(typeof(IDesignerHost)) as IDesignerHost;
            XmlReader     reader  = serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader;

            if ((service == null) || (reader == null))
            {
                return(obj2);
            }
            string str = string.Empty;

            while (reader.MoveToNextAttribute() && !reader.LocalName.Equals("Name", StringComparison.Ordinal))
            {
            }
            if (reader.LocalName.Equals("Name", StringComparison.Ordinal) && reader.ReadAttributeValue())
            {
                str = reader.Value;
            }
            reader.MoveToElement();
            if (string.IsNullOrEmpty(str))
            {
                serializationManager.ReportError(SR.GetString("Error_LayoutSerializationAssociatedActivityNotFound", new object[] { reader.LocalName, "Name" }));
                return(obj2);
            }
            CompositeActivityDesigner designer = serializationManager.Context[typeof(CompositeActivityDesigner)] as CompositeActivityDesigner;

            if (designer != null)
            {
                CompositeActivity activity2 = designer.Activity as CompositeActivity;
                if (activity2 == null)
                {
                    goto Label_01D0;
                }
                activity3 = null;
                foreach (Activity activity4 in activity2.Activities)
                {
                    if (str.Equals(activity4.Name, StringComparison.Ordinal))
                    {
                        activity3 = activity4;
                        break;
                    }
                }
            }
            else
            {
                Activity rootComponent = service.RootComponent as Activity;
                if ((rootComponent != null) && !str.Equals(rootComponent.Name, StringComparison.Ordinal))
                {
                    foreach (IComponent component in service.Container.Components)
                    {
                        rootComponent = component as Activity;
                        if ((rootComponent != null) && str.Equals(rootComponent.Name, StringComparison.Ordinal))
                        {
                            break;
                        }
                    }
                }
                if (rootComponent != null)
                {
                    obj2 = service.GetDesigner(rootComponent);
                }
                goto Label_01D0;
            }
            if (activity3 != null)
            {
                obj2 = service.GetDesigner(activity3);
            }
Label_01D0:
            if (obj2 == null)
            {
                serializationManager.ReportError(SR.GetString("Error_LayoutSerializationActivityNotFound", new object[] { reader.LocalName, str, "Name" }));
            }
            return(obj2);
        }
        protected override object CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type)
        {
            if (serializationManager == null)
            {
                throw new ArgumentNullException("serializationManager");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            StateDesignerConnector connector = null;

            IReferenceService        referenceService = serializationManager.GetService(typeof(IReferenceService)) as IReferenceService;
            FreeformActivityDesigner freeformDesigner = serializationManager.Context[typeof(FreeformActivityDesigner)] as FreeformActivityDesigner;

            if (freeformDesigner != null && referenceService != null)
            {
                StateDesigner.DesignerLayoutConnectionPoint sourceConnection = null;
                ConnectionPoint targetConnection            = null;
                StateDesigner.TransitionInfo transitionInfo = null;
                StateDesigner rootStateDesigner             = null;

                try
                {
                    Dictionary <string, string> constructionArguments = GetConnectorConstructionArguments(serializationManager, type);

                    if (constructionArguments.ContainsKey("EventHandlerName") &&
                        constructionArguments.ContainsKey("SetStateName") &&
                        constructionArguments.ContainsKey("TargetStateName"))
                    {
                        CompositeActivity eventHandler = (CompositeActivity)referenceService.GetReference(constructionArguments["EventHandlerName"] as string);
                        SetStateActivity  setState     = (SetStateActivity)referenceService.GetReference(constructionArguments["SetStateName"] as string);
                        StateActivity     targetState  = (StateActivity)referenceService.GetReference(constructionArguments["TargetStateName"] as string);
                        transitionInfo             = new StateDesigner.TransitionInfo(setState, eventHandler);
                        transitionInfo.TargetState = targetState;
                    }

                    if (constructionArguments.ContainsKey("SourceActivity") &&
                        constructionArguments.ContainsKey("SourceConnectionIndex") &&
                        constructionArguments.ContainsKey("SourceConnectionEdge") &&
                        constructionArguments.ContainsKey("EventHandlerName"))
                    {
                        StateDesigner     sourceDesigner = (StateDesigner)StateDesigner.GetDesigner(referenceService.GetReference(constructionArguments["SourceActivity"] as string) as Activity);
                        CompositeActivity eventHandler   = (CompositeActivity)referenceService.GetReference(constructionArguments["EventHandlerName"] as string);
                        rootStateDesigner = sourceDesigner.RootStateDesigner;
                        DesignerEdges sourceEdge  = (DesignerEdges)Enum.Parse(typeof(DesignerEdges), constructionArguments["SourceConnectionEdge"] as string);
                        int           sourceIndex = Convert.ToInt32(constructionArguments["SourceConnectionIndex"] as string, System.Globalization.CultureInfo.InvariantCulture);
                        if (sourceDesigner != null && eventHandler != null && sourceEdge != DesignerEdges.None && sourceIndex >= 0)
                        {
                            sourceConnection = new StateDesigner.DesignerLayoutConnectionPoint(sourceDesigner, sourceIndex, eventHandler, sourceEdge);
                        }
                    }

                    if (constructionArguments.ContainsKey("TargetActivity") &&
                        constructionArguments.ContainsKey("TargetConnectionIndex") &&
                        constructionArguments.ContainsKey("TargetConnectionEdge"))
                    {
                        ActivityDesigner targetDesigner = StateDesigner.GetDesigner(referenceService.GetReference(constructionArguments["TargetActivity"] as string) as Activity);
                        DesignerEdges    targetEdge     = (DesignerEdges)Enum.Parse(typeof(DesignerEdges), constructionArguments["TargetConnectionEdge"] as string);
                        int targetIndex = Convert.ToInt32(constructionArguments["TargetConnectionIndex"] as string, System.Globalization.CultureInfo.InvariantCulture);
                        if (targetDesigner != null && targetEdge != DesignerEdges.None && targetIndex >= 0)
                        {
                            targetConnection = new ConnectionPoint(targetDesigner, targetEdge, targetIndex);
                        }
                    }
                }
                catch
                {
                }

                if (transitionInfo != null && sourceConnection != null && targetConnection != null)
                {
                    connector = rootStateDesigner.FindConnector(transitionInfo);
                    if (connector == null)
                    {
                        rootStateDesigner.AddingSetState = false;
                        try
                        {
                            connector = freeformDesigner.AddConnector(sourceConnection, targetConnection) as StateDesignerConnector;
                        }
                        finally
                        {
                            rootStateDesigner.AddingSetState = true;
                        }
                    }
                    else
                    {
                        connector.Source = sourceConnection;
                        connector.Target = targetConnection;
                        connector.ClearConnectorSegments();
                    }
                }
            }

            return(connector);
        }
        protected override object CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type)
        {
            if (serializationManager == null)
            {
                throw new ArgumentNullException("serializationManager");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            StateDesignerConnector   connector = null;
            IReferenceService        service   = serializationManager.GetService(typeof(IReferenceService)) as IReferenceService;
            FreeformActivityDesigner designer  = serializationManager.Context[typeof(FreeformActivityDesigner)] as FreeformActivityDesigner;

            if ((designer != null) && (service != null))
            {
                StateDesigner.DesignerLayoutConnectionPoint source = null;
                ConnectionPoint target = null;
                StateDesigner.TransitionInfo transitionInfo = null;
                StateDesigner rootStateDesigner             = null;
                try
                {
                    Dictionary <string, string> connectorConstructionArguments = base.GetConnectorConstructionArguments(serializationManager, type);
                    if ((connectorConstructionArguments.ContainsKey("EventHandlerName") && connectorConstructionArguments.ContainsKey("SetStateName")) && connectorConstructionArguments.ContainsKey("TargetStateName"))
                    {
                        CompositeActivity reference = (CompositeActivity)service.GetReference(connectorConstructionArguments["EventHandlerName"]);
                        SetStateActivity  setState  = (SetStateActivity)service.GetReference(connectorConstructionArguments["SetStateName"]);
                        StateActivity     activity3 = (StateActivity)service.GetReference(connectorConstructionArguments["TargetStateName"]);
                        transitionInfo = new StateDesigner.TransitionInfo(setState, reference)
                        {
                            TargetState = activity3
                        };
                    }
                    if ((connectorConstructionArguments.ContainsKey("SourceActivity") && connectorConstructionArguments.ContainsKey("SourceConnectionIndex")) && (connectorConstructionArguments.ContainsKey("SourceConnectionEdge") && connectorConstructionArguments.ContainsKey("EventHandlerName")))
                    {
                        StateDesigner     associatedDesigner = (StateDesigner)StateDesigner.GetDesigner(service.GetReference(connectorConstructionArguments["SourceActivity"]) as Activity);
                        CompositeActivity eventHandler       = (CompositeActivity)service.GetReference(connectorConstructionArguments["EventHandlerName"]);
                        rootStateDesigner = associatedDesigner.RootStateDesigner;
                        DesignerEdges designerEdges   = (DesignerEdges)Enum.Parse(typeof(DesignerEdges), connectorConstructionArguments["SourceConnectionEdge"]);
                        int           connectionIndex = Convert.ToInt32(connectorConstructionArguments["SourceConnectionIndex"], CultureInfo.InvariantCulture);
                        if (((associatedDesigner != null) && (eventHandler != null)) && ((designerEdges != DesignerEdges.None) && (connectionIndex >= 0)))
                        {
                            source = new StateDesigner.DesignerLayoutConnectionPoint(associatedDesigner, connectionIndex, eventHandler, designerEdges);
                        }
                    }
                    if ((connectorConstructionArguments.ContainsKey("TargetActivity") && connectorConstructionArguments.ContainsKey("TargetConnectionIndex")) && connectorConstructionArguments.ContainsKey("TargetConnectionEdge"))
                    {
                        ActivityDesigner designer4    = StateDesigner.GetDesigner(service.GetReference(connectorConstructionArguments["TargetActivity"]) as Activity);
                        DesignerEdges    designerEdge = (DesignerEdges)Enum.Parse(typeof(DesignerEdges), connectorConstructionArguments["TargetConnectionEdge"]);
                        int num2 = Convert.ToInt32(connectorConstructionArguments["TargetConnectionIndex"], CultureInfo.InvariantCulture);
                        if (((designer4 != null) && (designerEdge != DesignerEdges.None)) && (num2 >= 0))
                        {
                            target = new ConnectionPoint(designer4, designerEdge, num2);
                        }
                    }
                }
                catch
                {
                }
                if (((transitionInfo == null) || (source == null)) || (target == null))
                {
                    return(connector);
                }
                connector = rootStateDesigner.FindConnector(transitionInfo);
                if (connector == null)
                {
                    rootStateDesigner.AddingSetState = false;
                    try
                    {
                        return(designer.AddConnector(source, target) as StateDesignerConnector);
                    }
                    finally
                    {
                        rootStateDesigner.AddingSetState = true;
                    }
                }
                connector.Source = source;
                connector.Target = target;
                connector.ClearConnectorSegments();
            }
            return(connector);
        }