Пример #1
0
 public static void CallNextItem(this IWorkFlowItem item, object input)
 {
     item.Connectors.Where(z => z.Type == ConnectorType.Out).ToList().ForEach(connector => {
         Parallel.ForEach(connector.Lines, line => {
             if (line.End.WorkFlowItem is IExecutableNode)
             {
                 ((IExecutableNode)line.End.WorkFlowItem).Run(input);
             }
         });
     });
 }
Пример #2
0
 public static void MoveItem(this IWorkFlowItem item, WorkFlowPoint point, double width, double height, Func <IConnector, WorkFlowPoint> getPosition)
 {
     foreach (var connector in item.Connectors.Where(z => z.Lines.Any()))
     {
         foreach (var line in connector.Lines)
         {
             point.X += width / 2;
             point.Y += height / 2;
             if (connector.Type == ConnectorType.In)
             {
                 line.End.Point = getPosition(connector);
                 line.DrawPath(line.Start.Point, line.End.Point);
             }
             else
             {
                 line.Start.Point = getPosition(connector);
                 line.DrawPath(line.Start.Point, line.End.Point);
             }
         }
     }
 }
Пример #3
0
 public static IConnector AddWorkFlowConnector(this IWorkFlowItem item, IConnector connector)
 {
     item.Connectors.Add(connector);
     item.ItemContent.AddConnector(connector);
     return(connector);
 }
        private IWorkFlowItem CreateNewNode(Type type, string title, string description)
        {
            IWorkFlowItem item = (IWorkFlowItem)Activator.CreateInstance(type, editorCanvas);


            item.ItemContent.ItemContentContext.Title       = title;
            item.ItemContent.ItemContentContext.Description = description;

            item.UIElement.GetUiElement <FrameworkElement>().Width  = 200;
            item.UIElement.GetUiElement <FrameworkElement>().Height = 100;
            foreach (var connector in item.Connectors)
            {
                connector.UIElement.GetUiElement <FrameworkElement>().MouseEnter += (s, e) =>
                {
                    connector.MouseIn();
                };
                item.UIElement.GetUiElement <FrameworkElement>().MouseLeave += (s, e) =>
                {
                    connector.MouseOut();
                };

                if (connector.Type == ConnectorType.Out)
                {
                    connector.UIElement.GetUiElement <FrameworkElement>().MouseLeftButtonDown += (s, e) =>
                    {
                        e.Handled       = true;
                        connector.Point = e.GetPosition(editorCanvas).ToWorkFlowPoint();

                        MovingLine = CreateLine(connector, null);
                        connector.Lines.Add(MovingLine);
                        editorCanvas.Children.Add(MovingLine.UIElement.GetUiElement <FrameworkElement>());
                        SetResetConnectorCanConnect(MovingLine, WorkFlowItems);
                    };

                    connector.UIElement.GetUiElement <FrameworkElement>().MouseLeftButtonUp += (s, e) =>
                    {
                        ConnectionCreateCleanup();
                    };
                }
                else
                {
                    connector.UIElement.GetUiElement <FrameworkElement>().MouseLeftButtonUp += (s, e) =>
                    {
                        if (MovingLine != null)
                        {
                            e.Handled = true;

                            if (!connector.CanConnect(MovingLine))
                            {
                                ConnectionCreateCleanup();
                                return;
                            }

                            if (IsLoop(MovingLine.Start, connector))
                            {
                                OnLoopDetected(new WorkFlowLoopEventModel(MovingLine.Start, connector));

                                if (!AllowLoops)
                                {
                                    ConnectionCreateCleanup();
                                    return;
                                }
                            }

                            connector.Point = e.GetPosition(editorCanvas).ToWorkFlowPoint();
                            MovingLine.End  = connector;
                            MovingLine.DrawPath(MovingLine.Start.Point, MovingLine.End.Point);
                            connector.Lines.Add(MovingLine);

                            MovingLine = new LineItem();
                            MovingLine = null;
                            SetResetConnectorCanConnect(null, WorkFlowItems);
                        }
                    };
                }
            }


            item.UIElement.GetUiElement <FrameworkElement>().MouseLeftButtonDown += (s, e) =>
            {
                e.Handled = true;
                var sender = s as FrameworkElement;
                sender.CaptureMouse();
            };

            item.UIElement.GetUiElement <FrameworkElement>().MouseLeftButtonUp += (s, e) =>
            {
                e.Handled = true;
                var sender = s as FrameworkElement;
                sender.ReleaseMouseCapture();
                ConnectionCreateCleanup();
            };

            item.UIElement.GetUiElement <FrameworkElement>().MouseMove += (s, e) =>
            {
                editorCanvas.Width  = editorCanvas.ActualWidth;
                editorCanvas.Height = editorCanvas.ActualHeight;


                e.Handled = true;
                var sender = s as FrameworkElement;
                if (sender.IsMouseCaptured)
                {
                    var point = e.GetPosition(editorCanvas);

                    if (point.X >= editorCanvas.Width - ItemWidth + 10)
                    {
                        editorCanvas.Width += 5;
                        zoomAndPanControl.ContentOffsetX += 5;
                    }
                    if (point.Y >= editorCanvas.Height - ItemWidth + 10)
                    {
                        editorCanvas.Height += 5;
                        zoomAndPanControl.ContentOffsetY += 5;
                    }

                    if (point.X <= 100)
                    {
                        return;
                    }
                    if (point.Y <= 50)
                    {
                        return;
                    }


                    item.Move(point.ToWorkFlowPoint());

                    MakeCanvasFit((int)this.ActualWidth, (int)this.ActualHeight);
                }
            };
            return(item);
        }