Beispiel #1
0
        /// <summary>
        /// Insert a workflow along side this node in a workflow
        /// (same successors and predecessors) and optionally delete this node
        /// </summary>
        /// <param name="w">Workflow to insert</param>
        /// <param name="replaceMode">True if this node is to be deleted after insert</param>
        public void InsertWorkflow(GuidanceWorkflow w, bool replaceMode)
        {
            Node startOfWorkflow;
            Node endOfWorkflow;

            if (this.predecessors.Count != 1 ||
                this.predecessors.Count != 1)
            {
                throw new Exception(Resources.Node_ErrorOnlySinglePredecessor);
            }


            if (w != null)
            {
                startOfWorkflow = w.InitialNode as Node;
                startOfWorkflow = startOfWorkflow.successors[0];

                endOfWorkflow = w.Successors.Traverse<INode>(s => s.Successors).OfType<IFinal>().FirstOrDefault() as Node;
                endOfWorkflow = endOfWorkflow.predecessors[0];

                startOfWorkflow.predecessors.Clear();
                endOfWorkflow.successors.Clear();
            }
            else
            {
                //
                // If the incoming "workflow" is null, then we simply want to delete this node.
                //
                // One of the assumptions made for "include://" nodes is that they have one and only one
                // successor and predecessor
                //
                startOfWorkflow = this.successors.ToArray()[0];
                endOfWorkflow = this.predecessors.ToArray()[0];
            }

            //
            // Make all of my predecessors point at the new start
            //
            foreach (Node pred in predecessors)
            {
                foreach (Node predRef in pred.successors.ToArray())
                {
                    if (predRef == this)
                    {
                        if (replaceMode)
                            pred.successors.Remove(this);
                        break;
                    }
                }
                pred.successors.Add(startOfWorkflow);
                startOfWorkflow.predecessors.Add(pred);
            }

            //
            // Make all of my successors point at my new end
            //
            foreach (Node succ in successors)
            {
                foreach (Node succRef in succ.predecessors.ToArray())
                {
                    if (succRef == this)
                    {
                        if (replaceMode)
                            succ.predecessors.Remove(this);
                        break;
                    }
                }
                succ.predecessors.Add(endOfWorkflow);
                endOfWorkflow.successors.Add(succ);
            }

        }
Beispiel #2
0
        /// <summary>
        /// Insert a workflow along side this node in a workflow
        /// (same successors and predecessors) and optionally delete this node
        /// </summary>
        /// <param name="w">Workflow to insert</param>
        /// <param name="replaceMode">True if this node is to be deleted after insert</param>
        public void InsertWorkflow(GuidanceWorkflow w, bool replaceMode)
        {
            Node startOfWorkflow;
            Node endOfWorkflow;

            if (this.predecessors.Count != 1 ||
                this.predecessors.Count != 1)
            {
                throw new Exception(Resources.Node_ErrorOnlySinglePredecessor);
            }


            if (w != null)
            {
                startOfWorkflow = w.InitialNode as Node;
                startOfWorkflow = startOfWorkflow.successors[0];

                endOfWorkflow = w.Successors.Traverse <INode>(s => s.Successors).OfType <IFinal>().FirstOrDefault() as Node;
                endOfWorkflow = endOfWorkflow.predecessors[0];

                startOfWorkflow.predecessors.Clear();
                endOfWorkflow.successors.Clear();
            }
            else
            {
                //
                // If the incoming "workflow" is null, then we simply want to delete this node.
                //
                // One of the assumptions made for "include://" nodes is that they have one and only one
                // successor and predecessor
                //
                startOfWorkflow = this.successors.ToArray()[0];
                endOfWorkflow   = this.predecessors.ToArray()[0];
            }

            //
            // Make all of my predecessors point at the new start
            //
            foreach (Node pred in predecessors)
            {
                foreach (Node predRef in pred.successors.ToArray())
                {
                    if (predRef == this)
                    {
                        if (replaceMode)
                        {
                            pred.successors.Remove(this);
                        }
                        break;
                    }
                }
                pred.successors.Add(startOfWorkflow);
                startOfWorkflow.predecessors.Add(pred);
            }

            //
            // Make all of my successors point at my new end
            //
            foreach (Node succ in successors)
            {
                foreach (Node succRef in succ.predecessors.ToArray())
                {
                    if (succRef == this)
                    {
                        if (replaceMode)
                        {
                            succ.predecessors.Remove(this);
                        }
                        break;
                    }
                }
                succ.predecessors.Add(endOfWorkflow);
                endOfWorkflow.successors.Add(succ);
            }
        }