Beispiel #1
0
        /// <summary>
        /// Attempts to add a copy of a DependancyGraphNode to the internal dictionary.
        /// </summary>
        /// <param name="objDependancyGraphNode"></param>
        /// <returns></returns>
        public DependancyGraphNode <T> TryAddCopyToDictionary(DependancyGraphNode <T> objDependancyGraphNode)
        {
            T objLoopKey = objDependancyGraphNode.MyObject;

            if (!NodeDictionary.TryGetValue(objLoopKey, out DependancyGraphNode <T> objExistingValue))
            {
                objExistingValue = new DependancyGraphNode <T>(objLoopKey, this);
                // This is the first time the DependancyGraphNode object was attempted to be added to the dictionary, so don't do anything extra
                _dicNodeDictionary.Add(objLoopKey, objExistingValue);
            }

            // Attempt to add all descendants of the current DependancyGraphNode to the SearchDictionary
            foreach (DependancyGraphNodeWithCondition <T> objDownStreamNode in objDependancyGraphNode.DownStreamNodes)
            {
                if (!NodeDictionary.TryGetValue(objDownStreamNode.Node.MyObject, out DependancyGraphNode <T> objLoopValue) || !objLoopValue.Initializing)
                {
                    bool blnTempLoopValueInitializing = objLoopValue?.Initializing == false;
                    if (blnTempLoopValueInitializing)
                    {
                        objLoopValue.Initializing = true;
                    }
                    DependancyGraphNode <T> objDownStreamNodeCopy = TryAddCopyToDictionary(objDownStreamNode.Node);
                    objExistingValue.DownStreamNodes.Add(new DependancyGraphNodeWithCondition <T>(objDownStreamNodeCopy, objDownStreamNode.DependancyCondition));
                    objDownStreamNodeCopy.UpStreamNodes.Add(new DependancyGraphNodeWithCondition <T>(objExistingValue, objDownStreamNode.DependancyCondition));
                    if (blnTempLoopValueInitializing)
                    {
                        objLoopValue.Initializing = false;
                    }
                }
            }

            // Attempt to add all dependants of the current DependancyGraphNode to the SearchDictionary
            foreach (DependancyGraphNodeWithCondition <T> objUpStreamNode in objDependancyGraphNode.UpStreamNodes)
            {
                if (!NodeDictionary.TryGetValue(objUpStreamNode.Node.MyObject, out DependancyGraphNode <T> objLoopValue) || !objLoopValue.Initializing)
                {
                    bool blnTempLoopValueInitializing = objLoopValue?.Initializing == false;
                    if (blnTempLoopValueInitializing)
                    {
                        objLoopValue.Initializing = true;
                    }
                    DependancyGraphNode <T> objUpStreamNodeCopy = TryAddCopyToDictionary(objUpStreamNode.Node);
                    objExistingValue.UpStreamNodes.Add(new DependancyGraphNodeWithCondition <T>(objUpStreamNodeCopy, objUpStreamNode.DependancyCondition));
                    objUpStreamNodeCopy.DownStreamNodes.Add(new DependancyGraphNodeWithCondition <T>(objExistingValue, objUpStreamNode.DependancyCondition));
                    if (blnTempLoopValueInitializing)
                    {
                        objLoopValue.Initializing = false;
                    }
                }
            }

            objExistingValue.Initializing = false;
            return(objExistingValue);
        }
 public DependancyGraphNodeWithCondition(DependancyGraphNode <T> objNode, Func <bool> funcDependancyCondition)
 {
     Node = objNode;
     DependancyCondition = funcDependancyCondition;
 }