protected override bool CanConnect(ConnectionPoint source, ConnectionPoint target)
 {
     DesignerLayoutConnectionPoint point = source as DesignerLayoutConnectionPoint;
     DesignerLayoutConnectionPoint point2 = target as DesignerLayoutConnectionPoint;
     if (point == null)
     {
         if (!this.IsValidTargetConnectionPoint(source))
         {
             return false;
         }
     }
     else if (point.DesignerLayout.ActivityDesigner is StateFinalizationDesigner)
     {
         return false;
     }
     if (point2 == null)
     {
         if (!this.IsValidTargetConnectionPoint(target))
         {
             return false;
         }
     }
     else if (point2.DesignerLayout.ActivityDesigner is StateFinalizationDesigner)
     {
         return false;
     }
     return (((point == null) && (point2 != null)) || ((point != null) && (point2 == null)));
 }
 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;
 }
 public Connector(ConnectionPoint source, ConnectionPoint target)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     if (target == null)
     {
         throw new ArgumentNullException("target");
     }
     if (ConnectionManager.GetConnectorContainer(source.AssociatedDesigner) != ConnectionManager.GetConnectorContainer(target.AssociatedDesigner))
     {
         throw new ArgumentException(DR.GetString("Error_Connector1", new object[0]));
     }
     this.source = source;
     this.target = target;
 }
 public Connector(ConnectionPoint source, ConnectionPoint target)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     if (target == null)
     {
         throw new ArgumentNullException("target");
     }
     if (ConnectionManager.GetConnectorContainer(source.AssociatedDesigner) != ConnectionManager.GetConnectorContainer(target.AssociatedDesigner))
     {
         throw new ArgumentException(DR.GetString("Error_Connector1", new object[0]));
     }
     this.source = source;
     this.target = target;
 }
Exemplo n.º 5
0
 private void ContinueEditing(Point editPoint)
 {
     if (this.EditingInProgress)
     {
         ConnectionPoint[] pointArray = null;
         if (this.connectorEditor.EditedConectionPoint != null)
         {
             ConnectionPoint sourceConnectionPoint = (this.connectorEditor.EditedConnector.Source == this.connectorEditor.EditedConectionPoint) ? this.connectorEditor.EditedConnector.Target : this.connectorEditor.EditedConnector.Source;
             pointArray = GetSnappableConnectionPoints(editPoint, sourceConnectionPoint, this.connectorEditor.EditedConectionPoint, base.MessageHitTestContext.AssociatedDesigner, out this.snappedConnectionPoint);
         }
         this.ConnectablePoints = pointArray;
         if (this.SnappedConnectionPoint != null)
         {
             editPoint = this.SnappedConnectionPoint.Location;
         }
         this.connectorEditor.OnContinueEditing(editPoint);
     }
 }
        public Connector AddConnector(ConnectionPoint source, ConnectionPoint target)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (source.AssociatedDesigner == null)
            {
                throw new ArgumentException("source", SR.GetString("Error_AssociatedDesignerMissing"));
            }
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            if (target.AssociatedDesigner == null)
            {
                throw new ArgumentException("target", SR.GetString("Error_AssociatedDesignerMissing"));
            }
            FreeformActivityDesigner connectorContainer = ConnectionManager.GetConnectorContainer(source.AssociatedDesigner);

            if (this != connectorContainer)
            {
                throw new InvalidOperationException(DR.GetString("Error_AddConnector1", new object[0]));
            }
            if (((base.Activity != source.AssociatedDesigner.Activity) && !Helpers.IsChildActivity(base.Activity as CompositeActivity, source.AssociatedDesigner.Activity)) || ((base.Activity != target.AssociatedDesigner.Activity) && !Helpers.IsChildActivity(base.Activity as CompositeActivity, target.AssociatedDesigner.Activity)))
            {
                throw new ArgumentException(DR.GetString("Error_AddConnector2", new object[0]));
            }
            Connector item = this.CreateConnector(source, target);

            if (item != null)
            {
                if (this.connectors.Contains(item))
                {
                    throw new InvalidOperationException(DR.GetString("Error_AddConnector3", new object[0]));
                }
                this.connectors.Add(item);
                item.SetParent(this);
                this.OnConnectorAdded(new ConnectorEventArgs(item));
            }
            base.PerformLayout();
            return(item);
        }
 public Connector AddConnector(ConnectionPoint source, ConnectionPoint target)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     if (source.AssociatedDesigner == null)
     {
         throw new ArgumentException("source", SR.GetString("Error_AssociatedDesignerMissing"));
     }
     if (target == null)
     {
         throw new ArgumentNullException("target");
     }
     if (target.AssociatedDesigner == null)
     {
         throw new ArgumentException("target", SR.GetString("Error_AssociatedDesignerMissing"));
     }
     FreeformActivityDesigner connectorContainer = ConnectionManager.GetConnectorContainer(source.AssociatedDesigner);
     if (this != connectorContainer)
     {
         throw new InvalidOperationException(DR.GetString("Error_AddConnector1", new object[0]));
     }
     if (((base.Activity != source.AssociatedDesigner.Activity) && !Helpers.IsChildActivity(base.Activity as CompositeActivity, source.AssociatedDesigner.Activity)) || ((base.Activity != target.AssociatedDesigner.Activity) && !Helpers.IsChildActivity(base.Activity as CompositeActivity, target.AssociatedDesigner.Activity)))
     {
         throw new ArgumentException(DR.GetString("Error_AddConnector2", new object[0]));
     }
     Connector item = this.CreateConnector(source, target);
     if (item != null)
     {
         if (this.connectors.Contains(item))
         {
             throw new InvalidOperationException(DR.GetString("Error_AddConnector3", new object[0]));
         }
         this.connectors.Add(item);
         item.SetParent(this);
         this.OnConnectorAdded(new ConnectorEventArgs(item));
     }
     base.PerformLayout();
     return item;
 }
Exemplo n.º 8
0
        private void EndEditing(Nullable <Point> editPoint)
        {
            WorkflowView workflowView = ParentView;

            if (workflowView == null)
            {
                return;
            }

            if (EditingInProgress)
            {
                if (editPoint != null)
                {
                    ConnectionPoint[] snapableConnectionPoints = null;
                    if (this.connectorEditor.EditedConectionPoint != null)
                    {
                        ConnectionPoint sourceConnectionPoint = this.connectorEditor.EditedConnector.Source == this.connectorEditor.EditedConectionPoint ?
                                                                this.connectorEditor.EditedConnector.Target :
                                                                this.connectorEditor.EditedConnector.Source;
                        snapableConnectionPoints = GetSnappableConnectionPoints(editPoint.Value, sourceConnectionPoint, this.connectorEditor.EditedConectionPoint, MessageHitTestContext.AssociatedDesigner, out this.snappedConnectionPoint);
                    }

                    if (SnappedConnectionPoint != null)
                    {
                        editPoint = SnappedConnectionPoint.Location;
                    }
                }

                this.connectorEditor.OnEndEditing((editPoint != null) ? editPoint.Value : Point.Empty, (editPoint != null));
            }

            this.initialDragPoint       = null;
            this.dragPointHitInfo       = null;
            this.snappedConnectionPoint = null;
            ConnectablePoints           = null;
            workflowView.Capture        = false;
            this.connectorEditor        = null;
        }
Exemplo n.º 9
0
        private static ConnectionPoint[] GetSnappableConnectionPoints(Point currentPoint, ConnectionPoint sourceConnectionPoint, ConnectionPoint activeConnectionPoint, ActivityDesigner activityDesigner, out ConnectionPoint snappedConnectionPoint)
        {
            snappedConnectionPoint = null;
            List <ConnectionPoint>   list = new List <ConnectionPoint>();
            FreeformActivityDesigner connectorContainer = GetConnectorContainer(activeConnectionPoint.AssociatedDesigner);

            if (connectorContainer != null)
            {
                FreeformActivityDesigner designer2 = activityDesigner as FreeformActivityDesigner;
                List <ActivityDesigner>  list2     = new List <ActivityDesigner> {
                    activityDesigner
                };
                if (designer2 != null)
                {
                    list2.AddRange(designer2.ContainedDesigners);
                }
                double num = 20.0;
                foreach (ActivityDesigner designer3 in list2)
                {
                    if (GetConnectorContainer(designer3) == connectorContainer)
                    {
                        bool flag = false;
                        List <ConnectionPoint> collection = new List <ConnectionPoint>();
                        foreach (ConnectionPoint point in designer3.GetConnectionPoints(DesignerEdges.All))
                        {
                            if (!point.Equals(activeConnectionPoint) && connectorContainer.CanConnectContainedDesigners(sourceConnectionPoint, point))
                            {
                                collection.Add(point);
                                double num2 = DesignerGeometryHelper.DistanceFromPointToRectangle(currentPoint, point.Bounds);
                                if (num2 <= 20.0)
                                {
                                    flag = true;
                                    if (num2 < num)
                                    {
                                        snappedConnectionPoint = point;
                                        num = num2;
                                    }
                                }
                            }
                        }
                        if (flag)
                        {
                            list.AddRange(collection);
                        }
                    }
                }
                if (snappedConnectionPoint != null)
                {
                    foreach (ConnectionPoint point2 in snappedConnectionPoint.AssociatedDesigner.GetConnectionPoints(DesignerEdges.All))
                    {
                        if (!list.Contains(point2))
                        {
                            list.Add(point2);
                        }
                    }
                }
            }
            return(list.ToArray());
        }
 public EditPoint(ConnectorEditor owner, ConnectionPoint connectionPoint)
 {
     this.owner = owner;
     this.editPointType = EditPointTypes.ConnectionEditPoint;
     this.connectionPoint = connectionPoint;
     this.point = connectionPoint.Location;
 }
 /// <summary>
 /// Called to check if connection can be established between source and target designer
 /// </summary>
 /// <param name="source">Source connection point</param>
 /// <param name="target">Target connection point</param>
 /// <returns>True if connection can be established, false otherwise</returns>
 protected virtual bool CanConnect(ConnectionPoint source, ConnectionPoint target)
 {
     return true;
 }
 bool IConnectableDesigner.CanConnect(ConnectionPoint source, ConnectionPoint target)
 {
     return CanConnect(source, target);
 }
 protected internal virtual void OnContainedDesignersConnected(ConnectionPoint source, ConnectionPoint target)
 {
     ((IConnectableDesigner) source.AssociatedDesigner).OnConnected(source, target);
     ((IConnectableDesigner) target.AssociatedDesigner).OnConnected(source, target);
 }
 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();
     }
 }
Exemplo n.º 15
0
 protected override Connector CreateConnector(ConnectionPoint source, ConnectionPoint target)
 {
     return new StateDesignerConnector(source, target);
 }
 protected internal virtual Connector CreateConnector(ConnectionPoint source, ConnectionPoint target)
 {
     return new Connector(source, target);
 }
        /// <summary>
        /// Adds connector to the designer
        /// </summary>
        /// <param name="connector">Connector to add</param>
        public Connector AddConnector(ConnectionPoint source, ConnectionPoint target)
        {
            if (source == null)
                throw new ArgumentNullException("source");

            if (source.AssociatedDesigner == null)
                throw new ArgumentException("source", SR.GetString(SR.Error_AssociatedDesignerMissing));

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

            if (target.AssociatedDesigner == null)
                throw new ArgumentException("target", SR.GetString(SR.Error_AssociatedDesignerMissing));

            //This check can be eliminated if it slows down connections, this is just to ensure we are adding connectors
            //to correct activity designer
            FreeformActivityDesigner connectorContainer = ConnectionManager.GetConnectorContainer(source.AssociatedDesigner);
            if (this != connectorContainer)
                throw new InvalidOperationException(DR.GetString(DR.Error_AddConnector1));

            if ((Activity != source.AssociatedDesigner.Activity && !Helpers.IsChildActivity(Activity as CompositeActivity, source.AssociatedDesigner.Activity)) ||
                (Activity != target.AssociatedDesigner.Activity && !Helpers.IsChildActivity(Activity as CompositeActivity, target.AssociatedDesigner.Activity)))
                throw new ArgumentException(DR.GetString(DR.Error_AddConnector2));

            Connector connector = CreateConnector(source, target);
            if (connector != null)
            {
                if (this.connectors.Contains(connector))
                    throw new InvalidOperationException(DR.GetString(DR.Error_AddConnector3));

                this.connectors.Add(connector);
                connector.SetParent(this);
                OnConnectorAdded(new ConnectorEventArgs(connector));
            }

            PerformLayout();

            return connector;
        }
        public static void GetRoutingObstacles(IServiceProvider serviceProvider, object source, object target, out List <Rectangle> rectanglesToExclude, out List <Point> linesToExclude, out List <Point> pointsToExclude)
        {
            AmbientTheme     ambientTheme                 = WorkflowTheme.CurrentTheme.AmbientTheme;
            ActivityDesigner safeRootDesigner             = ActivityDesigner.GetSafeRootDesigner(serviceProvider);
            ConnectionPoint  point                        = source as ConnectionPoint;
            Point            point2                       = (point != null) ? point.Location : ((Point)source);
            ActivityDesigner designer                     = (point != null) ? point.AssociatedDesigner : safeRootDesigner.HitTest(point2).AssociatedDesigner;
            ConnectionPoint  point3                       = target as ConnectionPoint;
            Point            point4                       = (point3 != null) ? point3.Location : ((Point)target);
            ActivityDesigner designer3                    = (point3 != null) ? point3.AssociatedDesigner : safeRootDesigner.HitTest(point4).AssociatedDesigner;
            Dictionary <int, ActivityDesigner> dictionary = new Dictionary <int, ActivityDesigner>();

            if (designer != null)
            {
                for (CompositeActivityDesigner designer4 = designer.ParentDesigner; designer4 != null; designer4 = designer4.ParentDesigner)
                {
                    if (dictionary.ContainsKey(designer4.GetHashCode()))
                    {
                        break;
                    }
                    dictionary.Add(designer4.GetHashCode(), designer4);
                }
            }
            if (designer3 != null)
            {
                for (CompositeActivityDesigner designer5 = designer3.ParentDesigner; designer5 != null; designer5 = designer5.ParentDesigner)
                {
                    if (dictionary.ContainsKey(designer5.GetHashCode()))
                    {
                        break;
                    }
                    dictionary.Add(designer5.GetHashCode(), designer5);
                }
            }
            rectanglesToExclude = new List <Rectangle>();
            pointsToExclude     = new List <Point>();
            foreach (CompositeActivityDesigner designer6 in dictionary.Values)
            {
                ReadOnlyCollection <ActivityDesigner> containedDesigners = designer6.ContainedDesigners;
                for (int i = 0; i < containedDesigners.Count; i++)
                {
                    ActivityDesigner designer7 = containedDesigners[i];
                    if ((designer7.IsVisible && !dictionary.ContainsKey(designer7.GetHashCode())) && ((designer7 != designer) && (designer7 != designer3)))
                    {
                        Rectangle bounds = designer7.Bounds;
                        bounds.Inflate(ambientTheme.Margin);
                        rectanglesToExclude.Add(bounds);
                    }
                }
            }
            linesToExclude = new List <Point>();
            if (((designer != null) && (designer == designer3)) && !designer.IsRootDesigner)
            {
                linesToExclude.AddRange(GetDesignerEscapeCover(designer, new object[] { source, target }));
            }
            else
            {
                if ((designer != null) && !designer.IsRootDesigner)
                {
                    linesToExclude.AddRange(GetDesignerEscapeCover(designer, new object[] { source }));
                }
                if ((designer3 != null) && !designer3.IsRootDesigner)
                {
                    bool flag = true;
                    for (CompositeActivityDesigner designer8 = (designer != null) ? designer.ParentDesigner : null; designer8 != null; designer8 = (designer != null) ? designer8.ParentDesigner : null)
                    {
                        if (designer3 == designer8)
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (flag)
                    {
                        linesToExclude.AddRange(GetDesignerEscapeCover(designer3, new object[] { target }));
                    }
                }
            }
        }
 private static ConnectionPoint[] GetSnappableConnectionPoints(Point currentPoint, ConnectionPoint sourceConnectionPoint, ConnectionPoint activeConnectionPoint, ActivityDesigner activityDesigner, out ConnectionPoint snappedConnectionPoint)
 {
     snappedConnectionPoint = null;
     List<ConnectionPoint> list = new List<ConnectionPoint>();
     FreeformActivityDesigner connectorContainer = GetConnectorContainer(activeConnectionPoint.AssociatedDesigner);
     if (connectorContainer != null)
     {
         FreeformActivityDesigner designer2 = activityDesigner as FreeformActivityDesigner;
         List<ActivityDesigner> list2 = new List<ActivityDesigner> {
             activityDesigner
         };
         if (designer2 != null)
         {
             list2.AddRange(designer2.ContainedDesigners);
         }
         double num = 20.0;
         foreach (ActivityDesigner designer3 in list2)
         {
             if (GetConnectorContainer(designer3) == connectorContainer)
             {
                 bool flag = false;
                 List<ConnectionPoint> collection = new List<ConnectionPoint>();
                 foreach (ConnectionPoint point in designer3.GetConnectionPoints(DesignerEdges.All))
                 {
                     if (!point.Equals(activeConnectionPoint) && connectorContainer.CanConnectContainedDesigners(sourceConnectionPoint, point))
                     {
                         collection.Add(point);
                         double num2 = DesignerGeometryHelper.DistanceFromPointToRectangle(currentPoint, point.Bounds);
                         if (num2 <= 20.0)
                         {
                             flag = true;
                             if (num2 < num)
                             {
                                 snappedConnectionPoint = point;
                                 num = num2;
                             }
                         }
                     }
                 }
                 if (flag)
                 {
                     list.AddRange(collection);
                 }
             }
         }
         if (snappedConnectionPoint != null)
         {
             foreach (ConnectionPoint point2 in snappedConnectionPoint.AssociatedDesigner.GetConnectionPoints(DesignerEdges.All))
             {
                 if (!list.Contains(point2))
                 {
                     list.Add(point2);
                 }
             }
         }
     }
     return list.ToArray();
 }
 private void EndEditing(Point? editPoint)
 {
     WorkflowView parentView = base.ParentView;
     if (parentView != null)
     {
         if (this.EditingInProgress)
         {
             if (editPoint.HasValue)
             {
                 if (this.connectorEditor.EditedConectionPoint != null)
                 {
                     ConnectionPoint sourceConnectionPoint = (this.connectorEditor.EditedConnector.Source == this.connectorEditor.EditedConectionPoint) ? this.connectorEditor.EditedConnector.Target : this.connectorEditor.EditedConnector.Source;
                     GetSnappableConnectionPoints(editPoint.Value, sourceConnectionPoint, this.connectorEditor.EditedConectionPoint, base.MessageHitTestContext.AssociatedDesigner, out this.snappedConnectionPoint);
                 }
                 if (this.SnappedConnectionPoint != null)
                 {
                     editPoint = new Point?(this.SnappedConnectionPoint.Location);
                 }
             }
             this.connectorEditor.OnEndEditing(editPoint.HasValue ? editPoint.Value : Point.Empty, editPoint.HasValue);
         }
         this.initialDragPoint = null;
         this.dragPointHitInfo = null;
         this.snappedConnectionPoint = null;
         this.ConnectablePoints = null;
         parentView.Capture = false;
         this.connectorEditor = null;
     }
 }
Exemplo n.º 21
0
 internal ConnectionPointGlyph(ConnectionPoint connectionPoint)
 {
     this.connectionPoint = connectionPoint;
 }
 protected internal virtual void OnContainedDesignersConnected(ConnectionPoint source, ConnectionPoint target)
 {
     ((IConnectableDesigner)source.AssociatedDesigner).OnConnected(source, target);
     ((IConnectableDesigner)target.AssociatedDesigner).OnConnected(source, target);
 }
Exemplo n.º 23
0
        protected override bool CanConnect(ConnectionPoint source, ConnectionPoint target)
        {
            DesignerLayoutConnectionPoint sourceDesignerLayoutConnectionPoint = source as DesignerLayoutConnectionPoint;
            DesignerLayoutConnectionPoint targetDesignerLayoutConnectionPoint = target as DesignerLayoutConnectionPoint;

            if (sourceDesignerLayoutConnectionPoint == null)
            {
                if (!IsValidTargetConnectionPoint(source))
                    return false;
            }
            else
            {
                if (sourceDesignerLayoutConnectionPoint.DesignerLayout.ActivityDesigner is StateFinalizationDesigner)
                    return false;
            }

            if (targetDesignerLayoutConnectionPoint == null)
            {
                if (!IsValidTargetConnectionPoint(target))
                    return false;
            }
            else
            {
                if (targetDesignerLayoutConnectionPoint.DesignerLayout.ActivityDesigner is StateFinalizationDesigner)
                    return false;
            }

            bool canConnect =
                (sourceDesignerLayoutConnectionPoint == null && targetDesignerLayoutConnectionPoint != null) ||
                (sourceDesignerLayoutConnectionPoint != null && targetDesignerLayoutConnectionPoint == null);

            return canConnect;
        }
 protected internal virtual bool CanConnectContainedDesigners(ConnectionPoint source, ConnectionPoint target)
 {
     return(((IConnectableDesigner)source.AssociatedDesigner).CanConnect(source, target) && ((IConnectableDesigner)target.AssociatedDesigner).CanConnect(source, target));
 }
Exemplo n.º 25
0
 private bool IsValidTargetConnectionPoint(ConnectionPoint target)
 {
     StateDesigner stateDesigner = target.AssociatedDesigner as StateDesigner;
     if (stateDesigner == null)
         return false;
     StateActivity state = (StateActivity)stateDesigner.Activity;
     return StateMachineHelpers.IsLeafState(state);
 }
        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;
        }
Exemplo n.º 27
0
        private static ConnectionPoint[] GetSnappableConnectionPoints(Point currentPoint, ConnectionPoint sourceConnectionPoint, ConnectionPoint activeConnectionPoint, ActivityDesigner activityDesigner, out ConnectionPoint snappedConnectionPoint)
        {
            //If the activity designer is composite activity designer then we will go through its children else we will go through its connection points
            snappedConnectionPoint = null;

            List <ConnectionPoint> snappableConnectionPoints = new List <ConnectionPoint>();

            FreeformActivityDesigner connectorContainer = ConnectionManager.GetConnectorContainer(activeConnectionPoint.AssociatedDesigner);

            if (connectorContainer != null)
            {
                FreeformActivityDesigner freeFormDesigner = activityDesigner as FreeformActivityDesigner;
                List <ActivityDesigner>  designersToCheck = new List <ActivityDesigner>();
                designersToCheck.Add(activityDesigner);
                if (freeFormDesigner != null)
                {
                    designersToCheck.AddRange(freeFormDesigner.ContainedDesigners);
                }

                double minimumDistance = ConnectionManager.SnapHighlightDistance;
                foreach (ActivityDesigner designer in designersToCheck)
                {
                    if (ConnectionManager.GetConnectorContainer(designer) == connectorContainer)
                    {
                        bool addValidSnapPoints = false;
                        List <ConnectionPoint> validSnapPoints = new List <ConnectionPoint>();

                        ReadOnlyCollection <ConnectionPoint> snapPoints = designer.GetConnectionPoints(DesignerEdges.All);
                        foreach (ConnectionPoint snapPoint in snapPoints)
                        {
                            if (!snapPoint.Equals(activeConnectionPoint) &&
                                connectorContainer.CanConnectContainedDesigners(sourceConnectionPoint, snapPoint))
                            {
                                validSnapPoints.Add(snapPoint);

                                double distanceToDesigner = DesignerGeometryHelper.DistanceFromPointToRectangle(currentPoint, snapPoint.Bounds);
                                if (distanceToDesigner <= ConnectionManager.SnapHighlightDistance)
                                {
                                    addValidSnapPoints = true;
                                    if (distanceToDesigner < minimumDistance)
                                    {
                                        snappedConnectionPoint = snapPoint;
                                        minimumDistance        = distanceToDesigner;
                                    }
                                }
                            }
                        }

                        if (addValidSnapPoints)
                        {
                            snappableConnectionPoints.AddRange(validSnapPoints);
                        }
                    }
                }

                if (snappedConnectionPoint != null)
                {
                    foreach (ConnectionPoint connectionPoint in snappedConnectionPoint.AssociatedDesigner.GetConnectionPoints(DesignerEdges.All))
                    {
                        if (!snappableConnectionPoints.Contains(connectionPoint))
                        {
                            snappableConnectionPoints.Add(connectionPoint);
                        }
                    }
                }
            }

            return(snappableConnectionPoints.ToArray());
        }
 protected internal virtual bool CanConnectContainedDesigners(ConnectionPoint source, ConnectionPoint target)
 {
     return (((IConnectableDesigner) source.AssociatedDesigner).CanConnect(source, target) && ((IConnectableDesigner) target.AssociatedDesigner).CanConnect(source, target));
 }
        private static ConnectionPoint[] GetSnappableConnectionPoints(Point currentPoint, ConnectionPoint sourceConnectionPoint, ConnectionPoint activeConnectionPoint, ActivityDesigner activityDesigner, out ConnectionPoint snappedConnectionPoint)
        {
            //If the activity designer is composite activity designer then we will go through its children else we will go through its connection points
            snappedConnectionPoint = null;

            List<ConnectionPoint> snappableConnectionPoints = new List<ConnectionPoint>();

            FreeformActivityDesigner connectorContainer = ConnectionManager.GetConnectorContainer(activeConnectionPoint.AssociatedDesigner);
            if (connectorContainer != null)
            {
                FreeformActivityDesigner freeFormDesigner = activityDesigner as FreeformActivityDesigner;
                List<ActivityDesigner> designersToCheck = new List<ActivityDesigner>();
                designersToCheck.Add(activityDesigner);
                if (freeFormDesigner != null)
                    designersToCheck.AddRange(freeFormDesigner.ContainedDesigners);

                double minimumDistance = ConnectionManager.SnapHighlightDistance;
                foreach (ActivityDesigner designer in designersToCheck)
                {
                    if (ConnectionManager.GetConnectorContainer(designer) == connectorContainer)
                    {
                        bool addValidSnapPoints = false;
                        List<ConnectionPoint> validSnapPoints = new List<ConnectionPoint>();

                        ReadOnlyCollection<ConnectionPoint> snapPoints = designer.GetConnectionPoints(DesignerEdges.All);
                        foreach (ConnectionPoint snapPoint in snapPoints)
                        {
                            if (!snapPoint.Equals(activeConnectionPoint) &&
                                connectorContainer.CanConnectContainedDesigners(sourceConnectionPoint, snapPoint))
                            {
                                validSnapPoints.Add(snapPoint);

                                double distanceToDesigner = DesignerGeometryHelper.DistanceFromPointToRectangle(currentPoint, snapPoint.Bounds);
                                if (distanceToDesigner <= ConnectionManager.SnapHighlightDistance)
                                {
                                    addValidSnapPoints = true;
                                    if (distanceToDesigner < minimumDistance)
                                    {
                                        snappedConnectionPoint = snapPoint;
                                        minimumDistance = distanceToDesigner;
                                    }
                                }
                            }
                        }

                        if (addValidSnapPoints)
                            snappableConnectionPoints.AddRange(validSnapPoints);
                    }
                }

                if (snappedConnectionPoint != null)
                {
                    foreach (ConnectionPoint connectionPoint in snappedConnectionPoint.AssociatedDesigner.GetConnectionPoints(DesignerEdges.All))
                    {
                        if (!snappableConnectionPoints.Contains(connectionPoint))
                            snappableConnectionPoints.Add(connectionPoint);
                    }
                }
            }

            return snappableConnectionPoints.ToArray();
        }
        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);
        }
 internal ConnectionPointGlyph(ConnectionPoint connectionPoint)
 {
     this.connectionPoint = connectionPoint;
 }
 /// <summary>
 /// Called when connection is established between two connection points
 /// </summary>
 /// <param name="source">Source connection point</param>
 /// <param name="target">Target connection point</param>
 protected virtual void OnConnected(ConnectionPoint source, ConnectionPoint target)
 {
 }
 protected internal virtual Connector CreateConnector(ConnectionPoint source, ConnectionPoint target)
 {
     return(new Connector(source, target));
 }
 void IConnectableDesigner.OnConnected(ConnectionPoint source, ConnectionPoint target)
 {
     OnConnected(source, target);
 }
 internal StateDesignerConnector(ConnectionPoint source, ConnectionPoint target)
     : base(source, target)
 {
 }
        private void EndEditing(Nullable<Point> editPoint)
        {
            WorkflowView workflowView = ParentView;
            if (workflowView == null)
                return;

            if (EditingInProgress)
            {
                if (editPoint != null)
                {
                    ConnectionPoint[] snapableConnectionPoints = null;
                    if (this.connectorEditor.EditedConectionPoint != null)
                    {
                        ConnectionPoint sourceConnectionPoint = this.connectorEditor.EditedConnector.Source == this.connectorEditor.EditedConectionPoint ?
                            this.connectorEditor.EditedConnector.Target :
                            this.connectorEditor.EditedConnector.Source;
                        snapableConnectionPoints = GetSnappableConnectionPoints(editPoint.Value, sourceConnectionPoint, this.connectorEditor.EditedConectionPoint, MessageHitTestContext.AssociatedDesigner, out this.snappedConnectionPoint);
                    }

                    if (SnappedConnectionPoint != null)
                        editPoint = SnappedConnectionPoint.Location;
                }

                this.connectorEditor.OnEndEditing((editPoint != null) ? editPoint.Value : Point.Empty, (editPoint != null));
            }

            this.initialDragPoint = null;
            this.dragPointHitInfo = null;
            this.snappedConnectionPoint = null;
            ConnectablePoints = null;
            workflowView.Capture = false;
            this.connectorEditor = null;
        }
        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;
        }