Пример #1
0
        private Node AddNode(string activityId, int x, int y)
        {
            if (this.State == PageState.Running)
            {
                MessageBox.Show("The robot is currently running.");
                return(null);
            }

            Node node;
            var  activity = Activity.CreateInstance(activityId);

            if (activity is StartNodeActivity)
            {
                node = new StartNode(activity)
                {
                    Name = "Start"
                };
            }
            else if (activity is EndNodeActivity)
            {
                node = new EndNode(activity)
                {
                    Name = "End"
                };
            }
            else if (activity is ProcessNodeActivity)
            {
                node = new ProcessNode(activity);
            }
            else if (activity is DecisionNodeActivity)
            {
                node = new DecisionNode(activity);
            }
            else if (activity is LoopStartNodeActivity)
            {
                node = new LoopStartNode(activity)
                {
                    Name = "Start Loop"
                };
                var loopStartNode = node as LoopStartNode;
                var loopEndNode   = this.AddNode(typeof(LoopEndNodeActivity).FullName, x, y + PageRenderOptions.GridSize * 10) as LoopEndNode;
                loopStartNode.LoopEndNodeId = loopEndNode.Id;
                loopEndNode.LoopStartNodeId = loopStartNode.Id;
            }
            else if (activity is LoopEndNodeActivity)
            {
                node = new LoopEndNode(activity)
                {
                    Name = "End Loop"
                };
            }
            else if (activity is VariableNodeActivity)
            {
                var variableIndex = 1;
                while (this.GetNodes <VariableNode>().Count(v => v.Name == "Variable " + variableIndex) > 0)
                {
                    variableIndex++;
                }
                node = new VariableNode(activity)
                {
                    Name = "Variable " + variableIndex
                };
            }
            else
            {
                throw new NotSupportedException();
            }
            var bounds = node.Bounds;

            bounds.X = x - bounds.Width / 2;
            bounds.Y = y - bounds.Height / 2;
            node.SetBounds(bounds);
            this.Nodes.Add(node);
            return(node);
        }
Пример #2
0
        public Node AddNode(string activityFullName, int x, int y)
        {
            Node node;
            var  activity = Activity.CreateInstance(activityFullName);

            if (activity is StartNodeActivity)
            {
                node = new StartNode(this.StartNodeActivity)
                {
                    Name = "Start"
                };
            }
            else if (activity is EndNodeActivity)
            {
                node = new EndNode(this.EndNodeActivity)
                {
                    Name = "End"
                };
            }
            else if (activity is ProcessNodeActivity)
            {
                node = new ProcessNode(activity)
                {
                    Name = activityFullName.Split('.').Last().Humanize()
                };
            }
            else if (activity is DecisionNodeActivity)
            {
                node = new DecisionNode(activity)
                {
                    Name = activityFullName.Split('.').Last().Humanize()
                };
            }
            else if (activity is PreparationNodeActivity)
            {
                node = new PreparationNode(activity)
                {
                    Name = "Preparation"
                };
            }
            else if (activity is LoopStartNodeActivity)
            {
                node = new LoopStartNode(activity)
                {
                    Name = "Start Loop"
                };
                var loopStartNode = node as LoopStartNode;
                var loopEndNode   = this.AddNode(typeof(LoopEndNodeActivity).FullName, x, y + PageRenderOptions.GridSize * 10) as LoopEndNode;
                loopStartNode.LoopEndNodeId = loopEndNode.Id;
                loopEndNode.LoopStartNodeId = loopStartNode.Id;
            }
            else if (activity is LoopEndNodeActivity)
            {
                node = new LoopEndNode(activity)
                {
                    Name = "End Loop"
                };
            }
            else
            {
                throw new NotSupportedException();
            }
            var bounds = node.Bounds;

            bounds.Location = new Point(x, y);
            bounds.Offset(-bounds.Width / 2, -bounds.Height / 2);
            node.SetBounds(bounds);
            this.Nodes.Add(node);
            return(node);
        }