Exemple #1
0
        /// <summary>
        /// Add depth values to the graph fragment
        /// </summary>
        private void UpdateFragmentAddDepth(CdmRequest r, CdmGraph gFragmentFromPool)
        {
            // a) node process: if request.node == node being inspected, and depth = -1, make depth 0. If depth = anything else, leave it alone.
            // b) edge process: look at the nodes on either end of the edge (call them n1 and n2) and examine their depth values:
            //      n1  n2
            //      -1  -1  both unknown, should not happen, leave alone
            //       0  -1  make the -1 = 1 (same case as below, order doesnt matter)
            //      -1   X  make the -1 = X + 1 (same case as above, order doesnt matter)
            //       X   Y  both known, leave alone

            // a) Node process
            List <CdmNode> nodes = gFragmentFromPool.GetAllNodes();

            foreach (CdmNode n in nodes)
            {
                if (r.NodeId == n.NodeId)
                {
                    if (n.Depth == -1)
                    {
                        // the node we're looking at is the node that was asked for in the request. Now, if previously
                        // we didn't know it's depth we know now that it must be the first requested node for this graph.
                        n.Depth = 0;
                    }
                    break;
                }
            }

            // b) Edge process
            List <CdmEdge> edges = gFragmentFromPool.GetAllEdges();

            foreach (CdmEdge e in edges)
            {
                CdmNode n1 = null;
                CdmNode n2 = null;
                gFragmentFromPool.GetNodesAtEitherEndofEdge(e.EdgeId, out n1, out n2);
                if (n1.Depth == -1 && n2.Depth == -1)
                {
                    // both unknown, shouldn't happen, just leave alone
                    Msg.LogWarning("CdmCore.UpdateFragmentAddDepth() has both nodes unknown depth for edge: " + e.EdgeId);
                }
                else if (n1.Depth != -1 || n2.Depth != -1)
                {
                    // precisely one unknown, so now we know the other
                    if (n1.Depth == -1)
                    {
                        n1.Depth = n2.Depth + 1;
                    }
                    else
                    {
                        n2.Depth = n1.Depth + 1;
                    }
                }
                else
                {
                    // both known, this is fine where we're just refreshing known values, so leave alone
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Pushes a Cdm Graph fragment g into the cdmpool, fulfilling request r
        /// It is fine to provide more nodes and edges in the graph fragment g, anything extra (over and above what fulfills
        /// the request r) is stored in the pool anyway (the pool acts as a cache), just won't be send to UI listeners.
        /// It is also fine to pass in a null request, this means data will be added to the Cdm cache, but no events will
        /// be raised for UI listeners
        /// </summary>
        /// <param name="r">Request that has been fulfilled either in this call or prior, null if data to be added to cache only</param>
        /// <param name="g">Graph fragment</param>
        public void IngestCdmGraphFragment(CdmRequest r, CdmGraph g)
        {
            // Add the new fragment to the pool
            // Remember Btc etc specific functionality is supported in Cdm* derived classes
            CdmPool.AddNodeRange(g.GetAllNodes());
            CdmPool.AddEdgeRange(g.GetAllEdges());

            // Add depth information and tell listeners, but only for edges that were requested in request r
            if (r != null && !r.IsCacheFillOnly)
            {
                CdmGraph gFragmentFromPool = CanCdmPoolFulfillRequest(r, false);
                UpdateFragmentAddDepth(r, gFragmentFromPool);
                RaiseOnCdmPoolRequestFulfilled(r, gFragmentFromPool);
            }
            else
            {
                Msg.Log("CdmCore.IngestCdmGraphFragment received a cache-fill call (data added to pool, not passed to frontends)");
            }
        }