示例#1
0
        public void AddNode(LevelKey levelKey, IExpressionNode expressionNode)
        {
            lock (_Content)
            {
                if (_Content.ContainsKey(levelKey))
                {
                    var tempInt64 = expressionNode.GetIVertex().VertexID;

                    var node = expressionNode.VertexInformation;

                    if (_Content[levelKey].Nodes.ContainsKey(node))
                    {
                        //the node already exist, so update its edges
                        foreach (var aBackwardEdge in expressionNode.BackwardEdges)
                        {
                            _Content[levelKey].Nodes[node].AddBackwardEdges(aBackwardEdge.Value);
                        }

                        foreach (var aForwardsEdge in expressionNode.ForwardEdges)
                        {
                            _Content[levelKey].Nodes[node].AddForwardEdges(aForwardsEdge.Value);
                        }
                    }
                    else
                    {
                        _Content[levelKey].Nodes.Add(node, expressionNode);
                    }
                }
                else
                {
                    _Content.Add(levelKey, new ExpressionLevelEntry(levelKey));

                    _Content[levelKey].Nodes.Add(expressionNode.VertexInformation, expressionNode);
                }
            }
        }
示例#2
0
        private void UpdateLowerLevels(IExpressionNode myNode, LevelKey myCurrentLevelKey, IEnumerable<LevelKey> myLowerLevelKeys, IExpressionGraph myGraph)
        {
            if (myCurrentLevelKey.Level > 0)
            {
                lock (myGraph)
                {
                    //iterate the next lower LevelKeys
                    foreach (var aLowerLevelKey in myLowerLevelKeys)
                    {
                        #region data

                        //get next lower attribute (might be more than one step away)
                        int levelDistance = myCurrentLevelKey.Level - aLowerLevelKey.Level;
                        //VertexType currentType = null;
                        EdgeKey myCurrentBackwardEdgekey = null;
                        IAttributeDefinition currentAttribute = null;

                        #endregion

                        if (levelDistance >= 1)
                        {
                            if (myCurrentLevelKey.Level > 1)
                            {
                                myCurrentBackwardEdgekey = myCurrentLevelKey.Edges[myCurrentLevelKey.Level - 1];
                            }
                            else
                            {
                                myCurrentBackwardEdgekey = myCurrentLevelKey.Edges[0];
                            }
                        }
                        else
                        {
                            throw new ExpressionGraphInternalException("Distances below 1 are not valid.");
                        }

                        IEnumerable<IVertex> referencedUUIDs = null;

                        IVertexType tempVertexType = _iGraphDB.GetVertexType<IVertexType>(
                            _securityToken,
                            _transactionToken,
                            new RequestGetVertexType(myCurrentBackwardEdgekey.VertexTypeID),
                            (stats, vertexType) => vertexType);

                        currentAttribute = tempVertexType.GetAttributeDefinition(myCurrentBackwardEdgekey.AttributeID);

                        if (currentAttribute.Kind == AttributeType.IncomingEdge)
                        {
                            var incomingAttribite = (IIncomingEdgeDefinition)currentAttribute;

                            var IVertex = myNode.GetIVertex();

                            if (IVertex.HasOutgoingEdge(incomingAttribite.RelatedEdgeDefinition.ID))
                            {
                                referencedUUIDs = IVertex.GetOutgoingEdge(incomingAttribite.RelatedEdgeDefinition.ID).GetTargetVertices();
                            }
                        }
                        else
                        {
                            var outgoingAttribute = (IOutgoingEdgeDefinition)currentAttribute;

                            if (myNode.BackwardEdges.ContainsKey(aLowerLevelKey.LastEdge))
                            {
                                //take the edges that are already available
                                List<IVertex> tempVertices = new List<IVertex>();
                                foreach (var aVertexInformation in myNode.BackwardEdges[aLowerLevelKey.LastEdge].Select(item => item.Destination))
                                {
                                    tempVertices.Add(_iGraphDB.GetVertex<IVertex>(
                                    _securityToken,
                                    _transactionToken,
                                    new RequestGetVertex(aVertexInformation.VertexTypeID, aVertexInformation.VertexID),
                                    (stats, vertices) => vertices));
                                }

                                referencedUUIDs = tempVertices;
                            }
                            else
                            {
                                var aVertex = myNode.GetIVertex();

                                if (aVertex.HasIncomingVertices(myCurrentBackwardEdgekey.VertexTypeID, myCurrentBackwardEdgekey.AttributeID))
                                {
                                    referencedUUIDs = aVertex.GetIncomingVertices(myCurrentBackwardEdgekey.VertexTypeID, myCurrentBackwardEdgekey.AttributeID);
                                }

                            }
                        }

                        if (referencedUUIDs != null)
                        {
                            var lowerLevelKeys = ExtractLowerLevelKeys(GetPreviousLevel(aLowerLevelKey.Level, myGraph.Levels), aLowerLevelKey, myGraph);

                            EdgeKey edgeKeyForBackwardEdge = null;
                            //get edgeKey for backwardEdge
                            if (myCurrentLevelKey.Level == 1)
                            {
                                edgeKeyForBackwardEdge = aLowerLevelKey.LastEdge;
                            }
                            else
                            {
                                edgeKeyForBackwardEdge = aLowerLevelKey.Edges[aLowerLevelKey.Level - 1];
                            }

                            foreach (var aVertex in referencedUUIDs)
                            {
                                AddNodeRecursiveBackward(aVertex, myNode.VertexInformation, myCurrentLevelKey, aLowerLevelKey, lowerLevelKeys, myGraph);
                                myNode.AddBackwardEdge(edgeKeyForBackwardEdge, GenerateVertexInfoFromLevelKeyAndVertexID(aVertex.VertexTypeID, aVertex.VertexID), null);
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        public void AddNode(LevelKey levelKey, IExpressionNode expressionNode)
        {
            lock (_Content)
            {
                if (_Content.ContainsKey(levelKey))
                {
                    var tempInt64 = expressionNode.GetIVertex().VertexID;

                    var node = expressionNode.VertexInformation;

                    if (_Content[levelKey].Nodes.ContainsKey(node))
                    {
                        //the node already exist, so update its edges
                        foreach (var aBackwardEdge in expressionNode.BackwardEdges)
                        {
                            _Content[levelKey].Nodes[node].AddBackwardEdges(aBackwardEdge.Value);
                        }

                        foreach (var aForwardsEdge in expressionNode.ForwardEdges)
                        {
                            _Content[levelKey].Nodes[node].AddForwardEdges(aForwardsEdge.Value);
                        }
                    }
                    else
                    {
                        _Content[levelKey].Nodes.Add(node, expressionNode);
                    }
                }
                else
                {
                    _Content.Add(levelKey, new ExpressionLevelEntry(levelKey));

                    _Content[levelKey].Nodes.Add(expressionNode.VertexInformation, expressionNode);
                }
            }
        }