internal bool Matches(StateDesignerConnector stateDesignerConnector)
            {
                if (stateDesignerConnector == null)
                {
                    throw new ArgumentNullException("stateDesignerConnector");
                }

                if (this.Connector != null &&
                    this.Connector == stateDesignerConnector)
                {
                    return(true);
                }

                // this transitioninfo is incomplete,
                // therefore, it cannot match an existing connector
                if (this.SetState == null ||
                    this.SourceState == null ||
                    this.TargetState == null ||
                    this.EventHandler == null)
                {
                    return(false);
                }

                if (this.SetState.QualifiedName != stateDesignerConnector.SetStateName)
                {
                    return(false);
                }

                if (this.SourceState.QualifiedName != stateDesignerConnector.SourceStateName)
                {
                    return(false);
                }

                if (this.TargetState.QualifiedName != stateDesignerConnector.TargetStateName ||
                    stateDesignerConnector.Target.AssociatedDesigner.Activity.QualifiedName != stateDesignerConnector.TargetStateName)
                {
                    return(false);
                }

                if (this.EventHandler.QualifiedName != stateDesignerConnector.EventHandlerName)
                {
                    return(false);
                }

                return(true);
            }
            internal bool Matches(StateDesignerConnector stateDesignerConnector)
            {
                if (stateDesignerConnector == null)
                    throw new ArgumentNullException("stateDesignerConnector");

                if (this.Connector != null &&
                    this.Connector == stateDesignerConnector)
                    return true;

                // this transitioninfo is incomplete,
                // therefore, it cannot match an existing connector
                if (this.SetState == null ||
                    this.SourceState == null ||
                    this.TargetState == null ||
                    this.EventHandler == null)
                    return false;

                if (this.SetState.QualifiedName != stateDesignerConnector.SetStateName)
                    return false;

                if (this.SourceState.QualifiedName != stateDesignerConnector.SourceStateName)
                    return false;

                if (this.TargetState.QualifiedName != stateDesignerConnector.TargetStateName ||
                    stateDesignerConnector.Target.AssociatedDesigner.Activity.QualifiedName != stateDesignerConnector.TargetStateName)
                    return false;

                if (this.EventHandler.QualifiedName != stateDesignerConnector.EventHandlerName)
                    return false;

                return true;
            }
 internal bool Matches(StateDesignerConnector stateDesignerConnector)
 {
     if (stateDesignerConnector == null)
     {
         throw new ArgumentNullException("stateDesignerConnector");
     }
     if ((this.Connector == null) || (this.Connector != stateDesignerConnector))
     {
         if (((this.SetState == null) || (this.SourceState == null)) || ((this.TargetState == null) || (this.EventHandler == null)))
         {
             return false;
         }
         if (this.SetState.QualifiedName != stateDesignerConnector.SetStateName)
         {
             return false;
         }
         if (this.SourceState.QualifiedName != stateDesignerConnector.SourceStateName)
         {
             return false;
         }
         if ((this.TargetState.QualifiedName != stateDesignerConnector.TargetStateName) || (stateDesignerConnector.Target.AssociatedDesigner.Activity.QualifiedName != stateDesignerConnector.TargetStateName))
         {
             return false;
         }
         if (this.EventHandler.QualifiedName != stateDesignerConnector.EventHandlerName)
         {
             return false;
         }
     }
     return true;
 }
        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);
        }