コード例 #1
0
        /// <summary>
        /// Remove extension branch indexed by given key
        /// </summary>
        /// <param name="key">Key which extension branch will be removed</param>
        internal void Remove(object key)
        {
            if (!IsConnected)
            {
                //nothing to remove
                return;
            }

            ExtensionPoint extension;

            if (!_extensions.TryGetValue(key, out extension))
            {
                //there is nothing with given key - don't need to remove branch
                return;
            }

            _extensions.Remove(key);
            Owner.RemoveFlowChild(extension);
            extension.Graph.End.RemoveFlowChild(Sink);

            if (_extensions.Count == 0)
            {
                disconnect();
            }
        }
コード例 #2
0
        /// <summary>
        /// Set throw branches from current point into specified program points. These branches contain
        /// catch point and handles given ThrowInfo values.
        /// </summary>
        /// <param name="branches">ThrowInfo values specifiing udpates/creations/deletions of throw branches</param>
        /// <param name="removeFlowChildren">If true flow children will be removed, otherwise no other than catch point children are affected</param>
        public void SetThrowBranching(IEnumerable <ThrowInfo> branches, bool removeFlowChildren = false)
        {
            //create indexed structure for branches
            var indexed = new Dictionary <CatchBlockDescription, ThrowInfo>();

            foreach (var branch in branches)
            {
                indexed.Add(branch.Catch, branch);
            }

            //update already existing branches
            var childrenCopy = CurrentProgramPoint.FlowChildren.ToArray();

            foreach (var child in childrenCopy)
            {
                var catchChild = child as CatchPoint;
                if (catchChild == null)
                {
                    if (removeFlowChildren)
                    {
                        CurrentProgramPoint.RemoveFlowChild(child);
                    }

                    continue;
                }

                ThrowInfo info;
                if (indexed.TryGetValue(catchChild.CatchDescription, out info))
                {
                    catchChild.ReThrow(info);

                    //remove branch from index because it is already complete
                    indexed.Remove(catchChild.CatchDescription);
                }
                else
                {
                    //no more it contains branch for this catch child
                    //disconnect it from graph
                    CurrentProgramPoint.RemoveFlowChild(catchChild);
                    catchChild.RemoveFlowChild(catchChild.TargetPoint);
                }
            }

            //add new branches
            foreach (var throwInfo in indexed.Values)
            {
                //create catch point according to specified throw info
                var catchPoint = new CatchPoint(CurrentProgramPoint, throwInfo.Catch);
                InitializeNewPoint(catchPoint, catchPoint.TargetPoint.OwningPPGraph);

                catchPoint.ReThrow(throwInfo);

                //connect branch into graph
                CurrentProgramPoint.AddFlowChild(catchPoint);
                catchPoint.AddFlowChild(catchPoint.TargetPoint);
            }
        }