public ConnectorAccessibleObject(Connector connector)
 {
     if (connector == null)
     {
         throw new ArgumentNullException("connector");
     }
     this.connector = connector;
 }
 public void RemoveConnector(Connector connector)
 {
     if (connector == null)
     {
         throw new ArgumentNullException("connector");
     }
     if (this.connectors.Contains(connector))
     {
         this.OnConnectorRemoved(new ConnectorEventArgs(connector));
         connector.SetParent(null);
         this.connectors.Remove(connector);
     }
 }
Exemplo n.º 3
0
        private void UpdateConnectors()
        {
            try
            {
                Debug.Assert(this.IsRootStateDesigner);
                Debug.Assert(this.ActiveDesigner == null);

                this.RootStateDesigner.RemovingSetState = false;

                StateActivity rootState = (StateActivity)this.Activity;
                ReadOnlyCollection<TransitionInfo> transitions = TransitionInfo.ParseStateMachine(rootState);
                Connector[] connectors = new Connector[this.Connectors.Count];
                this.Connectors.CopyTo(connectors, 0);
                foreach (Connector connector in connectors)
                {
                    StateDesignerConnector stateDesignerConnector = connector as StateDesignerConnector;
                    if (stateDesignerConnector == null)
                    {
                        RemoveConnector(connector);
                        continue;
                    }

                    bool foundMatchingTransition = false;
                    foreach (TransitionInfo transitionInfo in transitions)
                    {
                        if (transitionInfo.Matches(stateDesignerConnector))
                        {
                            transitionInfo.Connector = stateDesignerConnector;
                            foundMatchingTransition = true;
                            break;
                        }
                    }

                    if (!foundMatchingTransition)
                        RemoveConnector(connector);
                }

                foreach (TransitionInfo transitionInfo in transitions)
                {
                    if (transitionInfo.Connector == null && transitionInfo.TargetState != null)
                    {
                        DesignerLayoutConnectionPoint source = GetEventHandlerConnectionPoint(transitionInfo.EventHandler);
                        ConnectionPoint target = GetTargetStateConnectionPoint(transitionInfo.TargetState);

                        if (source != null && target != null)
                        {
                            this.RootStateDesigner.AddingSetState = false;
                            try
                            {
                                StateDesignerConnector stateDesignerConnector = (StateDesignerConnector)this.AddConnector(source, target);
                                stateDesignerConnector.SetStateName = transitionInfo.SetState.QualifiedName;
                                stateDesignerConnector.TargetStateName = transitionInfo.SetState.TargetStateName;
                                if (transitionInfo.EventHandler != null)
                                    stateDesignerConnector.EventHandlerName = transitionInfo.EventHandler.QualifiedName;
                            }
                            finally
                            {
                                this.RootStateDesigner.AddingSetState = true;
                            }
                        }
                    }
                }

            }
#if DEBUG
            catch (Exception exception)
            {
                Trace.WriteLine(String.Format(
                    System.Globalization.CultureInfo.InvariantCulture,
                    "Unhandled exception in {0}.UpdateConnectors: {1}",
                    typeof(StateDesigner), exception));
                throw;
            }
#endif
            finally
            {
                this.RemovingSetState = true;
            }
        }
 public void OnEndEditing(Point point, bool commitChanges)
 {
     if (this.activeEditPoint != null)
     {
         this.Invalidate();
         if (commitChanges)
         {
             this.UpdateEditPoints(point);
             EditPoint activeEditPoint = this.activeEditPoint;
             this.activeEditPoint = null;
             this.UpdateEditPoints(point);
             bool flag = false;
             if (activeEditPoint.Type == EditPoint.EditPointTypes.ConnectionEditPoint)
             {
                 ConnectionManager service = this.GetService(typeof(ConnectionManager)) as ConnectionManager;
                 FreeformActivityDesigner connectorContainer = ConnectionManager.GetConnectorContainer(activeEditPoint.EditedConnectionPoint.AssociatedDesigner);
                 if (((service != null) && (service.SnappedConnectionPoint != null)) && (connectorContainer != null))
                 {
                     ConnectionPoint source = this.editedConnector.Source;
                     ConnectionPoint target = this.editedConnector.Target;
                     if (target.Equals(activeEditPoint.EditedConnectionPoint))
                     {
                         target = service.SnappedConnectionPoint;
                     }
                     else if (source.Equals(activeEditPoint.EditedConnectionPoint))
                     {
                         source = service.SnappedConnectionPoint;
                     }
                     if ((connectorContainer == ConnectionManager.GetConnectorContainer(target.AssociatedDesigner)) && connectorContainer.CanConnectContainedDesigners(source, target))
                     {
                         this.editedConnector.Source = source;
                         this.editedConnector.Target = target;
                         if (this.editedConnector.ParentDesigner == null)
                         {
                             this.editedConnector = connectorContainer.AddConnector(source, target);
                             WorkflowDesignerLoader loader = this.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                             if (loader != null)
                             {
                                 loader.SetModified(true);
                             }
                         }
                         connectorContainer.OnContainedDesignersConnected(source, target);
                     }
                     flag = true;
                 }
             }
             else
             {
                 flag = true;
             }
             if (flag)
             {
                 this.editedConnector.SetConnectorSegments(this.GetPointsFromEditPoints(this.editPoints));
                 if (this.editedConnector.ParentDesigner != null)
                 {
                     this.editedConnector.ParentDesigner.OnConnectorChanged(new ConnectorEventArgs(this.editedConnector));
                     WorkflowDesignerLoader loader2 = this.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                     if (loader2 != null)
                     {
                         loader2.SetModified(true);
                     }
                 }
             }
             this.PerformLayout();
         }
         this.Invalidate();
     }
 }
 public ConnectorEditor(Connector connectorEdited)
 {
     this.editedConnector = connectorEdited;
     this.serviceProvider = this.editedConnector.Source.AssociatedDesigner.Activity.Site;
     this.CreateEditPoints();
 }
 private void UpdateConnectors()
 {
     try
     {
         this.RootStateDesigner.RemovingSetState = false;
         StateActivity rootState = (StateActivity) base.Activity;
         ReadOnlyCollection<TransitionInfo> onlys = TransitionInfo.ParseStateMachine(rootState);
         Connector[] array = new Connector[base.Connectors.Count];
         base.Connectors.CopyTo(array, 0);
         foreach (Connector connector in array)
         {
             StateDesignerConnector stateDesignerConnector = connector as StateDesignerConnector;
             if (stateDesignerConnector == null)
             {
                 base.RemoveConnector(connector);
                 continue;
             }
             bool flag = false;
             foreach (TransitionInfo info in onlys)
             {
                 if (info.Matches(stateDesignerConnector))
                 {
                     info.Connector = stateDesignerConnector;
                     flag = true;
                     break;
                 }
             }
             if (!flag)
             {
                 base.RemoveConnector(connector);
             }
         }
         foreach (TransitionInfo info2 in onlys)
         {
             if ((info2.Connector == null) && (info2.TargetState != null))
             {
                 DesignerLayoutConnectionPoint eventHandlerConnectionPoint = this.GetEventHandlerConnectionPoint(info2.EventHandler);
                 ConnectionPoint targetStateConnectionPoint = this.GetTargetStateConnectionPoint(info2.TargetState);
                 if ((eventHandlerConnectionPoint != null) && (targetStateConnectionPoint != null))
                 {
                     this.RootStateDesigner.AddingSetState = false;
                     try
                     {
                         StateDesignerConnector connector3 = (StateDesignerConnector) base.AddConnector(eventHandlerConnectionPoint, targetStateConnectionPoint);
                         connector3.SetStateName = info2.SetState.QualifiedName;
                         connector3.TargetStateName = info2.SetState.TargetStateName;
                         if (info2.EventHandler != null)
                         {
                             connector3.EventHandlerName = info2.EventHandler.QualifiedName;
                         }
                     }
                     finally
                     {
                         this.RootStateDesigner.AddingSetState = true;
                     }
                 }
             }
         }
     }
     finally
     {
         this.RemovingSetState = true;
     }
 }