Пример #1
0
        public void AddNodeAndBackwardEdge(LevelKey myPath, IVertex aVertex, EdgeKey backwardDirection, VertexInformation backwardDestination, IComparable EdgeWeight, IComparable NodeWeight)
        {
            lock (_Content)
            {
                var node = GenerateVertexInfoFromLevelKeyAndVertexID(aVertex.VertexTypeID, aVertex.VertexID);

                if (_Content.ContainsKey(myPath))
                {
                    //the level exists
                    if (_Content[myPath].Nodes.ContainsKey(node))
                    {
                        //Node exists
                        _Content[myPath].Nodes[node].AddBackwardEdge(backwardDirection, backwardDestination, EdgeWeight);
                    }
                    else
                    {
                        //Node does not exist
                        _Content[myPath].Nodes.Add(node, new ExpressionNode(aVertex, NodeWeight, node));
                        _Content[myPath].Nodes[node].AddBackwardEdge(backwardDirection, backwardDestination, EdgeWeight);
                    }
                }
                else
                {
                    HashSet <IExpressionEdge> backwardEdges = new HashSet <IExpressionEdge>()
                    {
                        new ExpressionEdge(backwardDestination, EdgeWeight, backwardDirection)
                    };

                    _Content.Add(myPath, new ExpressionLevelEntry(myPath));
                    _Content[myPath].Nodes.Add(node, new ExpressionNode(aVertex, NodeWeight, node));
                    _Content[myPath].Nodes[node].AddBackwardEdge(backwardDirection, backwardDestination, EdgeWeight);
                }
            }
        }
Пример #2
0
 public void AddBackwardEdgesToNode(LevelKey myPath, VertexInformation myVertexInformation, EdgeKey backwardDestination, Dictionary <VertexInformation, IComparable> validUUIDs)
 {
     lock (_Content)
     {
         if (_Content.ContainsKey(myPath))
         {
             //the level exists
             if (_Content[myPath].Nodes.ContainsKey(myVertexInformation))
             {
                 //Node exists
                 _Content[myPath].Nodes[myVertexInformation].AddBackwardEdges(backwardDestination, validUUIDs);
             }
             else
             {
                 //Node does not exist
                 throw new ExpressionGraphInternalException("The node does not exist in this LevelKey.");
             }
         }
         else
         {
             //LevelKey does not exist
             throw new ExpressionGraphInternalException("The LevelKey does not exist in this ExpressionLevel.");
         }
     }
 }
Пример #3
0
 public void AddForwardEdgeToNode(LevelKey levelKey, VertexInformation myVertexInformation, EdgeKey forwardDirection, VertexInformation destination, IComparable edgeWeight)
 {
     lock (_Content)
     {
         if (_Content.ContainsKey(levelKey))
         {
             //the level exists
             if (_Content[levelKey].Nodes.ContainsKey(myVertexInformation))
             {
                 //Node exists
                 _Content[levelKey].Nodes[myVertexInformation].AddForwardEdge(forwardDirection, destination, edgeWeight);
             }
             else
             {
                 //Node does not exist
                 throw new ExpressionGraphInternalException("The node does not exist in this LevelKey.");
             }
         }
         else
         {
             //LevelKey does not exist
             throw new ExpressionGraphInternalException("The LevelKey does not exist in this ExpressionLevel.");
         }
     }
 }
Пример #4
0
        public LevelKey AddLevelKey(LevelKey myLevelKey2, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken)
        {
            if ((this.Edges == null || this.Edges.Count == 0) && (myLevelKey2.Edges == null || myLevelKey2.Edges.Count == 0))
            {
                return(new LevelKey());
            }
            else if (this.Edges == null || this.Edges.Count == 0)
            {
                return(new LevelKey(myLevelKey2.Edges, myGraphDB, mySecurityToken, myTransactionToken));
            }
            else if (myLevelKey2.Edges == null || myLevelKey2.Edges.Count == 0)
            {
                return(new LevelKey(this.Edges, myGraphDB, mySecurityToken, myTransactionToken));
            }

            if (this.Level == 0 && myLevelKey2.Level == 0)
            {
                #region both are level 0 (User/null)
                if (this.Edges[0].VertexTypeID != myLevelKey2.Edges[0].VertexTypeID) // if the types are different then something is really wrong
                {
                    throw new InvalidLevelKeyOperationException(this, myLevelKey2, "+");
                }
                else
                {
                    return(new LevelKey(this.Edges, myGraphDB, mySecurityToken, myTransactionToken));
                }
                #endregion
            }
            else if (this.Level == 0)
            {
                #region one of them is level 0 - so we can just skip this level: User/null + User/Friends == User/Friends
                if (this.Edges[0].VertexTypeID != myLevelKey2.Edges[0].VertexTypeID) // if the types are different then something is really wrong
                {
                    throw new InvalidLevelKeyOperationException(this, myLevelKey2, "+");
                }
                else
                {
                    return(new LevelKey(myLevelKey2.Edges, myGraphDB, mySecurityToken, myTransactionToken)); // just return the other level
                }
                #endregion
            }
            else if (myLevelKey2.Level == 0)
            {
                #region one of them is level 0 - so we can just skip this level: User/null + User/Friends == User/Friends
                if (this.Edges[0].VertexTypeID != myLevelKey2.Edges[0].VertexTypeID) // if the types are different then something is really wrong
                {
                    throw new InvalidLevelKeyOperationException(this, myLevelKey2, "+");
                }
                else
                {
                    return(new LevelKey(this.Edges, myGraphDB, mySecurityToken, myTransactionToken)); // just return the other level
                }
                #endregion
            }

            var edges = new List <EdgeKey>(this.Edges);
            edges.AddRange(myLevelKey2.Edges);

            return(new LevelKey(edges, myGraphDB, mySecurityToken, myTransactionToken));
        }
Пример #5
0
        public LevelKey RemoveLevelKey(LevelKey myOtherLevelKey, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken)
        {
            if (this.Level < myOtherLevelKey.Level)
            {
                throw new ArgumentException("level of left (" + this.Level + ") operand is lower than right (" + myOtherLevelKey.Level + ") operand:", "myOtherLevelKey");
            }

            if (!this.StartsWith(myOtherLevelKey, true))
            {
                throw new ArgumentException("left operand level does not starts with right operand level");
            }

            if (myOtherLevelKey.Level == 0)
            {
                return(this);
            }

            if (this.Level == myOtherLevelKey.Level)
            {
                return(new LevelKey(this.Edges[0].VertexTypeID, myGraphDB, mySecurityToken, myTransactionToken));
            }

            var edgeList = new List <EdgeKey>(this.Edges);

            return(new LevelKey(this.Edges.Skip(myOtherLevelKey.Edges.Count), myGraphDB, mySecurityToken, myTransactionToken));
        }
Пример #6
0
        protected EdgeKey GetBackwardEdgeKey(LevelKey myPath, int desiredBELevel, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken)
        {
            #region data

            IVertexType          tempType;
            IAttributeDefinition tempAttr;

            #endregion

            tempType = myGraphDB.GetVertexType <IVertexType>(
                mySecurityToken,
                myTransactionToken,
                new RequestGetVertexType(myPath.Edges[desiredBELevel].VertexTypeID),
                (stats, vertexType) => vertexType);

            tempAttr = tempType.GetAttributeDefinition(myPath.Edges[desiredBELevel].AttributeID);

            if (tempAttr.Kind != AttributeType.IncomingEdge)
            {
                return(new EdgeKey(tempType.ID, tempAttr.ID));
            }
            else
            {
                IIncomingEdgeDefinition incomingEdgeDefinition = tempAttr as IIncomingEdgeDefinition;

                return(new EdgeKey(incomingEdgeDefinition.RelatedEdgeDefinition.SourceVertexType.ID, incomingEdgeDefinition.RelatedEdgeDefinition.ID));
            }
        }
Пример #7
0
 public Boolean HasLevelKey(LevelKey myLevelKey)
 {
     lock (_Content)
     {
         return(_Content.ContainsKey(myLevelKey));
     }
 }
Пример #8
0
 public void AddEmptyLevelKey(LevelKey levelKey)
 {
     lock (_Content)
     {
         if (!_Content.ContainsKey(levelKey))
         {
             _Content.Add(levelKey, new ExpressionLevelEntry(levelKey));
         }
     }
 }
Пример #9
0
 public void RemoveComplexConnection(LevelKey myLevelKey, VertexInformation myUUID)
 {
     lock (_lockObj)
     {
         if (_ComplexConnection.ContainsKey(myLevelKey))
         {
             _ComplexConnection[myLevelKey].Remove(myUUID);
         }
     }
 }
Пример #10
0
 public void RemoveNode(LevelKey myLevelKey, VertexInformation myToBeRemovedVertex)
 {
     lock (_Content)
     {
         if (_Content.ContainsKey(myLevelKey))
         {
             _Content[myLevelKey].Nodes.Remove(myToBeRemovedVertex);
         }
     }
 }
Пример #11
0
        public Dictionary <VertexInformation, IExpressionNode> GetNode(LevelKey myLevelKey)
        {
            lock (_Content)
            {
                if (_Content.ContainsKey(myLevelKey))
                {
                    return(_Content[myLevelKey].Nodes);
                }

                return(null);
            }
        }
Пример #12
0
        public IEnumerable <IExpressionNode> GetNodes(LevelKey myLevelKey)
        {
            lock (_Content)
            {
                if (_Content.ContainsKey(myLevelKey))
                {
                    return(_Content[myLevelKey].Nodes.Values);
                }

                return(null);
            }
        }
Пример #13
0
        public bool StartsWith(LevelKey myLevel)
        {
            if (myLevel.Level > Level)
            {
                throw new ArgumentException(myLevel + " is greater than " + Level);
            }

            for (Int32 i = 0; i < myLevel.Level; i++)
            {
                if (myLevel.Edges[i].VertexTypeID != Edges[i].VertexTypeID)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #14
0
 public void AddComplexConnection(LevelKey myLevelKey, VertexInformation myUUID)
 {
     lock (_lockObj)
     {
         if (_ComplexConnection.ContainsKey(myLevelKey))
         {
             _ComplexConnection[myLevelKey].Add(myUUID);
         }
         else
         {
             _ComplexConnection.Add(myLevelKey, new HashSet <VertexInformation>()
             {
                 myUUID
             });
         }
     }
 }
Пример #15
0
 public bool ContainsLevelKey(LevelKey levelKey)
 {
     if (this.Levels.ContainsKey(levelKey.Level))
     {
         if (this.Levels[levelKey.Level].ExpressionLevels.ContainsKey(levelKey))
         {
             return true;
         }
         else
         {
             return false;
         }
     }
     else
     {
         return false;
     }
 }
Пример #16
0
 public bool ContainsLevelKey(LevelKey levelKey)
 {
     if (this.Levels.ContainsKey(levelKey.Level))
     {
         if (this.Levels[levelKey.Level].ExpressionLevels.ContainsKey(levelKey))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Пример #17
0
        public override Boolean Equals(System.Object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return(false);
            }

            // If parameter cannot be cast to Point return false.
            if (obj is LevelKey)
            {
                LevelKey p = (LevelKey)obj;
                return(Equals(p));
            }
            else
            {
                return(false);
            }
        }
Пример #18
0
        public bool StartsWith(LevelKey myLevel, Boolean IncludingAttrs)
        {
            if (!IncludingAttrs)
            {
                return(StartsWith(myLevel));
            }

            if (myLevel.Level > Level)
            {
                throw new ArgumentException(myLevel + " is greater than " + Level);
            }

            for (Int32 i = 0; i < myLevel.Level; i++)
            {
                if (myLevel.Edges[i].VertexTypeID != Edges[i].VertexTypeID || myLevel.Edges[i].AttributeID != Edges[i].AttributeID)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #19
0
        public void AddNodeAndBackwardEdge(LevelKey myPath, IVertex aVertex, EdgeKey backwardDirection, VertexInformation backwardDestination, IComparable EdgeWeight, IComparable NodeWeight)
        {
            lock (_Content)
            {
                var node = GenerateVertexInfoFromLevelKeyAndVertexID(aVertex.VertexTypeID, aVertex.VertexID);

                if (_Content.ContainsKey(myPath))
                {
                    //the level exists
                    if (_Content[myPath].Nodes.ContainsKey(node))
                    {


                        //Node exists
                        _Content[myPath].Nodes[node].AddBackwardEdge(backwardDirection, backwardDestination, EdgeWeight);


                    }
                    else
                    {

                        //Node does not exist
                        _Content[myPath].Nodes.Add(node, new ExpressionNode(aVertex, NodeWeight, node));
                        _Content[myPath].Nodes[node].AddBackwardEdge(backwardDirection, backwardDestination, EdgeWeight);

                    }
                }
                else
                {
                    HashSet<IExpressionEdge> backwardEdges = new HashSet<IExpressionEdge>() { new ExpressionEdge(backwardDestination, EdgeWeight, backwardDirection) };

                    _Content.Add(myPath, new ExpressionLevelEntry(myPath));
                    _Content[myPath].Nodes.Add(node, new ExpressionNode(aVertex, NodeWeight, node));
                    _Content[myPath].Nodes[node].AddBackwardEdge(backwardDirection, backwardDestination, EdgeWeight);

                }

            }
        }
Пример #20
0
        public Boolean Equals(LevelKey p)
        {
            // If parameter is null return false:
            if ((object)p == null)
            {
                return(false);
            }

            if (this.Level != p.Level)
            {
                return(false);
            }

            for (int i = 0; i < Edges.Count; i++)
            {
                if (this.Edges[i] != p.Edges[i])
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #21
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);
                }
            }
        }
Пример #22
0
 public abstract void AddNodes(IEnumerable<IExpressionNode> iEnumerable, LevelKey myPath);
Пример #23
0
 public abstract void AddNode(IVertex myVertex, LevelKey myIDNode);
Пример #24
0
 public abstract void GatherEdgeWeight(LevelKey StartLevel, LevelKey EndLevel);
Пример #25
0
 /// <summary>
 /// We need to add an empty level in case, the DBO should not be integerated. Otherwise the select does not know, either the level was never touched or 
 /// not added due to an expression
 /// </summary>
 /// <param name="myExpressionGraph"></param>
 /// <param name="myLevelKey"></param>
 private void ExcludeFromGraph(IExpressionGraph myExpressionGraph, LevelKey myLevelKey)
 {
     myExpressionGraph.AddEmptyLevel(myLevelKey);
 }
Пример #26
0
        private static void CleanLowerLevel(LevelKey myLevelKey, IExpressionGraph myGraph, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken)
        {
            if (myLevelKey.Level > 0)
            {
                var previousLevelKey = myLevelKey.GetPredecessorLevel(myGraphDB, mySecurityToken, myTransactionToken);
                HashSet<VertexInformation> toBeDeletedNodes = new HashSet<VertexInformation>();

                foreach (var aLowerDBO in myGraph.Select(previousLevelKey, null, false))
                {
                    if (aLowerDBO.HasOutgoingEdge(myLevelKey.LastEdge.AttributeID))
                    {
                        foreach (var aVertex in aLowerDBO.GetOutgoingEdge(myLevelKey.LastEdge.AttributeID).GetTargetVertices())
                        {
                            //took the vertextype id of the levelkey, because it is possible that the vertextypeid of the vertex is something inheritated
                            VertexInformation node = new VertexInformation(aVertex.VertexTypeID, aVertex.VertexID);

                            if (!myGraph.GetLevel(myLevelKey.Level).ExpressionLevels[myLevelKey].Nodes.ContainsKey(node))
                            {
                                //a reference occurred that is not in the higher level --> found a Zoidberg

                                toBeDeletedNodes.Add(node);
                                break;
                            }
                        }
                    }
                }

                foreach (var aToBeDeletedNode in toBeDeletedNodes)
                {
                    myGraph.GetLevel(previousLevelKey.Level).RemoveNode(previousLevelKey, aToBeDeletedNode);
                }
            }
        }
Пример #27
0
        public override Boolean IsGraphRelevant(LevelKey myLevelKey, IVertex mySourceDBObject)
        {
            lock (_Levels)
            {
                if (!this.ContainsLevelKey(myLevelKey))
                {
                    return false;
                }

                if (myLevelKey.Level == 0)
                {
                    return this._Levels[myLevelKey.Level].ExpressionLevels[myLevelKey].Nodes.ContainsKey(GenerateVertexInfoFromLevelKeyAndVertexID(mySourceDBObject.VertexTypeID, mySourceDBObject.VertexID));
                }
                else
                {
                    if (mySourceDBObject != null)
                    {

                        VertexInformation mySourceDBObjectNode = GenerateVertexInfoFromLevelKeyAndVertexID(mySourceDBObject.VertexTypeID, mySourceDBObject.VertexID);

                        var predecessorLevelKey = myLevelKey.GetPredecessorLevel(_iGraphDB, _securityToken, _transactionToken);

                        if (!this.ContainsLevelKey(predecessorLevelKey))
                        {
                            var interestingEdge = new ExpressionEdge(mySourceDBObjectNode, null, predecessorLevelKey.LastEdge);
                            //take the backwardEdges
                            return this._Levels[myLevelKey.Level].ExpressionLevels[myLevelKey].Nodes.Where(item => item.Value.BackwardEdges[predecessorLevelKey.LastEdge].Contains(interestingEdge)).Count() > 0;
                        }
                        else
                        {

                            if (this._Levels[predecessorLevelKey.Level].ExpressionLevels[predecessorLevelKey].Nodes[mySourceDBObjectNode].ForwardEdges.ContainsKey(myLevelKey.LastEdge))
                            {
                                if (this._Levels[predecessorLevelKey.Level].ExpressionLevels[predecessorLevelKey].Nodes[mySourceDBObjectNode].ForwardEdges[myLevelKey.LastEdge].Count > 0)
                                {
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                return false;
                            }
                        }
                    }
                    else
                    {
                        throw new ExpressionGraphInternalException("No IVertex givon for graph relevance test in a higher level.");
                    }
                }
            }
        }
Пример #28
0
 public override void GatherEdgeWeight(LevelKey StartLevel, LevelKey EndLevel)
 {
     throw new NotImplementedException();
 }
Пример #29
0
 public abstract void AddNode(IVertex myVertex, LevelKey myIDNode);
Пример #30
0
 public abstract void AddNodesWithComplexRelation(IVertex leftVertex, LevelKey leftLevelKey, IVertex rightVertex, LevelKey rightLevelKey, int backwardResolution);
Пример #31
0
 public abstract Boolean IsGraphRelevant(LevelKey myLevelKey, IVertex mySourceVertex);
Пример #32
0
 public abstract IEnumerable <VertexInformation> SelectVertexIDs(LevelKey myLevelKey, IVertex mySourceVertex = null, Boolean generateLevel = true);
Пример #33
0
 public abstract IEnumerable <IVertex> Select(LevelKey myLevelKey, IVertex mySourceVertex = null, Boolean generateLevel = true);
Пример #34
0
 public abstract IEnumerable<VertexInformation> SelectVertexIDs(LevelKey myLevelKey, IVertex mySourceVertex = null, Boolean generateLevel = true);
Пример #35
0
 public abstract void AddNodesWithComplexRelation(IVertex leftVertex, LevelKey leftLevelKey, IVertex rightVertex, LevelKey rightLevelKey, int backwardResolution);
Пример #36
0
        public override IEnumerable<IVertex> Select(LevelKey myLevelKey, IVertex mySourceDBObject = null, Boolean doLevelGeneration = true)
        {
            lock (_Levels)
            {
                if (doLevelGeneration)
                {
                    if (!this.ContainsLevelKey(myLevelKey))
                    {
                        //the graph does not contain the LevelKey, so create it
                        #region create LevelKey

                        GenerateLevel(myLevelKey);

                        #endregion
                    }
                }

                if (myLevelKey.Level == 0)
                {
                    if (this.ContainsLevelKey(myLevelKey))
                    {
                        //return all Objects of this levelKey
                        foreach (var aNode in this._Levels[myLevelKey.Level].ExpressionLevels[myLevelKey].Nodes)
                        {
                            yield return aNode.Value.GetIVertex();
                        }
                    }
                    else
                    {
                        yield break;
                    }
                }
                else
                {
                    if (mySourceDBObject != null)
                    {
                        var predecessorLevelKey = myLevelKey.GetPredecessorLevel(_iGraphDB, _securityToken, _transactionToken);

                        if (!this.ContainsLevelKey(predecessorLevelKey))
                        {
                            var sourceNode = GenerateVertexInfoFromLevelKeyAndVertexID(mySourceDBObject.VertexTypeID, mySourceDBObject.VertexID);

                            //take the backwardEdges
                            foreach (var aNode in this._Levels[myLevelKey.Level].ExpressionLevels[myLevelKey].Nodes.Where(item => item.Value.BackwardEdges[predecessorLevelKey.LastEdge].Where(aBackWardEdge => aBackWardEdge.Destination == sourceNode).Count() > 0))
                            {
                                yield return aNode.Value.GetIVertex();
                            }
                        }
                        else
                        {

                            //take the forwardEdges
                            var interestingVertexIDs = this._Levels[predecessorLevelKey.Level]
                                .ExpressionLevels[predecessorLevelKey]
                                .Nodes[GenerateVertexInfoFromLevelKeyAndVertexID(mySourceDBObject.VertexTypeID, mySourceDBObject.VertexID)]
                                .ForwardEdges[myLevelKey.LastEdge].Select(item => item.Destination);

                            foreach (var aInterestingID in interestingVertexIDs)
                            {
                                yield return this._Levels[myLevelKey.Level]
                                .ExpressionLevels[myLevelKey]
                                .Nodes[aInterestingID].GetIVertex();
                            }
                        }
                    }
                    else
                    {
                        //there is no sourceObject given, so return the complete level
                        foreach (var aNode in this._Levels[myLevelKey.Level].ExpressionLevels[myLevelKey].Nodes)
                        {
                            yield return aNode.Value.GetIVertex();
                        }
                    }
                }

            }
            //all done
            yield break;
        }
Пример #37
0
 public ExpressionLevelEntry(LevelKey myCorrespondingLevelKey)
     : this(myCorrespondingLevelKey, new Dictionary <VertexInformation, IExpressionNode>())
 {
 }
Пример #38
0
        public override IEnumerable<VertexInformation> SelectVertexIDs(LevelKey myLevelKey, IVertex mySourceDBObject = null, Boolean doLevelGeneration = true)
        {
            lock (_Levels)
            {
                if (doLevelGeneration)
                {
                    if (!this.ContainsLevelKey(myLevelKey))
                    {
                        //the graph does not contain the LevelKey, so create it
                        #region create LevelKey

                        GenerateLevel(myLevelKey);

                        #endregion
                    }
                }

                if (myLevelKey.Level == 0)
                {
                    if (this.ContainsLevelKey(myLevelKey))
                    {
                        //return all Objects of this levelKey
                        foreach (var aNode in this._Levels[myLevelKey.Level].ExpressionLevels[myLevelKey].Nodes)
                        {
                            yield return aNode.Value.VertexInformation;
                        }
                    }
                    else
                    {
                        yield break;
                    }
                }
                else
                {
                    if (mySourceDBObject != null)
                    {
                        var predecessorLevelKey = myLevelKey.GetPredecessorLevel(_iGraphDB, _securityToken, _transactionToken);

                        if (!this.ContainsLevelKey(predecessorLevelKey))
                        {
                            var node = GenerateVertexInfoFromLevelKeyAndVertexID(mySourceDBObject.VertexTypeID, mySourceDBObject.VertexID);

                            //take the backwardEdges
                            foreach (var aNode in this._Levels[myLevelKey.Level].ExpressionLevels[myLevelKey].Nodes.Where(item => item.Value.BackwardEdges[predecessorLevelKey.LastEdge].Where(aBackWardEdge => aBackWardEdge.Destination == node).Count() > 0))
                            {
                                yield return aNode.Value.VertexInformation;
                            }
                        }
                        else
                        {
                            //took the vertextypeid of the levelkey, because the vertextypeid of the sourceDBObject can be sth inheritated
                            VertexInformation source = GenerateVertexInfoFromLevelKeyAndVertexID(mySourceDBObject.VertexTypeID, mySourceDBObject.VertexID);

                            //take the forwardEdges
                            if (this._Levels[predecessorLevelKey.Level].ExpressionLevels[predecessorLevelKey].Nodes[source].ForwardEdges.ContainsKey(myLevelKey.LastEdge))
                            {
                                foreach (var aUUID in this._Levels[predecessorLevelKey.Level].ExpressionLevels[predecessorLevelKey].Nodes[source].ForwardEdges[myLevelKey.LastEdge].Select(item => item.Destination))
                                {
                                    yield return aUUID;
                                }
                            }
                            //else
                            //{
                            //    AddNode(mySourceDBObject, myLevelKey);
                            //    //var attrVal = mySourceDBObject.GetAttribute(myLevelKey.LastEdge.AttrUUID);
                            //}
                        }
                    }
                    else
                    {
                        //there is no sourceObject given, so return the complete level
                        foreach (var aNode in this._Levels[myLevelKey.Level].ExpressionLevels[myLevelKey].Nodes)
                        {
                            yield return aNode.Value.VertexInformation;
                        }
                    }
                }

            }
            //all done
            yield break;
        }
Пример #39
0
 public abstract void AddNodes(IEnumerable <IExpressionNode> iEnumerable, LevelKey myPath);
Пример #40
0
        /// <summary>
        /// This method adds a IVertex to a Level if it is valid for a LevelKey.
        /// </summary>
        /// <param name="aDBObject">The Object that is going to be added</param>
        /// <param name="myLevelKey">The LevelKey which is needed for validation.</param>
        /// <param name="currentBackwardResolution">The current backward resolution (initially 0)</param>
        /// <param name="source">The Int64 of the </param>
        /// <returns>True if it was valid or false otherwise.</returns>
        private bool AddNodeIfValid(IVertex aDBObject, LevelKey myLevelKey, int currentBackwardResolution, VertexInformation source, int backwardResolutiondepth)
        {
            #region data

            IAttributeDefinition tempTypeAttribute = null;

            IEnumerable<IVertex> referenceUUIDs = null;

            #endregion

            if ((myLevelKey.Level - currentBackwardResolution) > 0)
            {
                #region level > 0

                int desiredBackwardEdgeLevel = myLevelKey.Level - currentBackwardResolution - 1;

                var tempVertexType = _iGraphDB.GetVertexType(
                    _securityToken,
                    _transactionToken,
                    new RequestGetVertexType(myLevelKey.Edges[desiredBackwardEdgeLevel].VertexTypeID),
                    (stats, vertexType) => vertexType);

                tempTypeAttribute = tempVertexType.GetAttributeDefinition(myLevelKey.Edges[desiredBackwardEdgeLevel].AttributeID);

                #region get reference UUIDs

                if (tempTypeAttribute.Kind == AttributeType.IncomingEdge)
                {
                    #region backward edge handling

                    var incomingEdgeAttribute = tempTypeAttribute as IIncomingEdgeDefinition;

                    if (aDBObject.HasOutgoingEdge(incomingEdgeAttribute.RelatedEdgeDefinition.ID))
                    {
                        referenceUUIDs = aDBObject.GetOutgoingEdge(incomingEdgeAttribute.RelatedEdgeDefinition.ID).GetTargetVertices();
                        //GetUUIDsForAttribute(aDBObject, incomingEdgeAttribute.RelatedEdgeDefinition, tempTypeAttribute.BackwardEdgeDefinition.GetTypeAndAttributeInformation(_DBContext.DBTypeManager).Item2, _DBContext.DBTypeManager.GetTypeByUUID(aDBObject.TypeUUID));
                    }

                    #endregion
                }
                else
                {
                    #region forward edge handling

                    var tempEdgeKey = GetBackwardEdgeKey(myLevelKey, desiredBackwardEdgeLevel, _iGraphDB, _securityToken, _transactionToken);

                    if (!aDBObject.HasIncomingVertices(tempEdgeKey.VertexTypeID, tempEdgeKey.AttributeID))
                    {
                        return false;
                    }

                    referenceUUIDs = aDBObject.GetIncomingVertices(tempEdgeKey.VertexTypeID, tempEdgeKey.AttributeID);

                    #endregion
                }

                #endregion

                if (referenceUUIDs != null)
                {
                    #region references

                    Dictionary<VertexInformation, IComparable> validUUIDs = new Dictionary<VertexInformation, IComparable>();

                    #region process references recursivly

                    foreach (var aReferenceUUID in referenceUUIDs)
                    {
                        if (AddNodeIfValid(aReferenceUUID, myLevelKey, currentBackwardResolution + 1, GenerateVertexInfoFromLevelKeyAndVertexID(aDBObject.VertexTypeID, aDBObject.VertexID), backwardResolutiondepth))
                        {
                            validUUIDs.Add(GenerateVertexInfoFromLevelKeyAndVertexID(aReferenceUUID.VertexTypeID, aReferenceUUID.VertexID), null);
                        }
                    }

                    #endregion

                    if (validUUIDs.Count > 0)
                    {
                        //some valid uuids
                        if (currentBackwardResolution <= backwardResolutiondepth)
                        {
                            #region fill graph

                            FillGraph(aDBObject, myLevelKey, currentBackwardResolution, source, myLevelKey.Edges[desiredBackwardEdgeLevel], validUUIDs);

                            #endregion
                        }

                        return true;
                    }
                    else
                    {
                        //not valid
                        return false;
                    }

                    #endregion
                }
                else
                {
                    #region no references

                    return false;

                    #endregion
                }
                #endregion
            }
            else
            {
                #region Level 0

                if (currentBackwardResolution <= backwardResolutiondepth)
                {
                    #region fill graph

                    LevelKey newLevelKey = new LevelKey(myLevelKey.Edges.First().VertexTypeID, _iGraphDB, _securityToken, _transactionToken);

                    if (currentBackwardResolution > 0)
                    {
                        //we have to add forwardEdges and (if not already there) add nodes
                        AddEmptyLevel(newLevelKey);

                        var node = GenerateVertexInfoFromLevelKeyAndVertexID(aDBObject.VertexTypeID, aDBObject.VertexID);

                        Levels[0].AddNode(newLevelKey, new ExpressionNode(aDBObject, null, node));
                        Levels[0].AddForwardEdgeToNode(newLevelKey, node, new EdgeKey(myLevelKey.Edges[0].VertexTypeID, myLevelKey.Edges[0].AttributeID), source, null);

                    }
                    else
                    {
                        //we are in the lowest level and are the first time in this method... so there's no need for adding forward-edges to nodes
                        AddEmptyLevel(newLevelKey);
                        Levels[0].AddNode(newLevelKey, new ExpressionNode(aDBObject, null, GenerateVertexInfoFromLevelKeyAndVertexID(aDBObject.VertexTypeID, aDBObject.VertexID)));
                    }

                    #endregion
                }

                return true;

                #endregion
            }
        }
Пример #41
0
 private static void IntegrateInGraph(IVertex myDBObjectStream, IExpressionGraph myExpressionGraph, LevelKey myLevelKey, TypesOfOperators myTypesOfOperators)
 {
     if (myTypesOfOperators == TypesOfOperators.AffectsLowerLevels)
     {
         myExpressionGraph.AddNode(myDBObjectStream, myLevelKey, 1);
     }
     else
     {
         myExpressionGraph.AddNode(myDBObjectStream, myLevelKey, 0);
     }
 }
Пример #42
0
 public abstract void AddNode(IVertex myVertex, LevelKey myIDNode, int backwardResolution);
Пример #43
0
        protected EdgeKey GetBackwardEdgeKey(LevelKey myPath, int desiredBELevel, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken)
        {
            #region data

            IVertexType tempType;
            IAttributeDefinition tempAttr;

            #endregion

            tempType = myGraphDB.GetVertexType<IVertexType>(
                mySecurityToken, 
                myTransactionToken,
                new RequestGetVertexType(myPath.Edges[desiredBELevel].VertexTypeID), 
                (stats, vertexType) => vertexType);
            
            tempAttr = tempType.GetAttributeDefinition(myPath.Edges[desiredBELevel].AttributeID);

            if (tempAttr.Kind != AttributeType.IncomingEdge)
            {
                return new EdgeKey(tempType.ID, tempAttr.ID);
            }
            else
            {
                IIncomingEdgeDefinition incomingEdgeDefinition = tempAttr as IIncomingEdgeDefinition;

                return new EdgeKey(incomingEdgeDefinition.RelatedEdgeDefinition.SourceVertexType.ID, incomingEdgeDefinition.RelatedEdgeDefinition.ID);
            }
        }
Пример #44
0
        /// <summary>
        /// This method adds a Node to a Level.
        /// </summary>
        /// <param name="myNode">The Node that is going to be added</param>
        /// <param name="myPath">The place where the node is going to be added.</param>
        private void AddNodeToLevel(IExpressionNode myNode, LevelKey myPath)
        {
            lock (_Levels)
            {
                AddEmptyLevel(myPath);

                _Levels[myPath.Level].AddNode(myPath, myNode);
            }
        }
Пример #45
0
 public abstract void AddNode(IVertex myVertex, LevelKey myIDNode, int backwardResolution);
Пример #46
0
        private void DownfillLevelKey(IExpressionGraph aGraph, LevelKey aLevel)
        {
            lock (aGraph)
            {
                DownFillStructureOfGraph(aGraph, aLevel);

                #region get levelKeys that match

                var lowerLevelKeys = ExtractLowerLevelKeys(aLevel.Level - 1, aLevel, aGraph);

                #endregion

                if (lowerLevelKeys != null)
                {
                    foreach (var aNode in aGraph.Levels[aLevel.Level].ExpressionLevels[aLevel].Nodes)
                    {
                        #region update levels that are lower (e.g. 1(current)-->0)

                        if (lowerLevelKeys != null)
                        {
                            UpdateLowerLevels(aNode.Value, aLevel, lowerLevelKeys, aGraph);
                        }

                        #endregion

                    }
                }
            }
        }
Пример #47
0
 public abstract Boolean AddEmptyLevel(LevelKey myLevelKey);
Пример #48
0
        private void DownFillStructureOfGraph(IExpressionGraph anotherGraph, LevelKey levelKey)
        {
            lock (anotherGraph)
            {
                if (levelKey.Level > 0)
                {
                    var nextLowerLevel = levelKey.Level - 1;
                    var nextLowerLevelKey = levelKey.GetPredecessorLevel(_iGraphDB, _securityToken, _transactionToken);

                    if (anotherGraph.Levels.ContainsKey(nextLowerLevel))
                    {
                        if (!anotherGraph.Levels[nextLowerLevel].ExpressionLevels.ContainsKey(nextLowerLevelKey))
                        {
                            anotherGraph.Levels[nextLowerLevel].AddEmptyLevelKey(nextLowerLevelKey);

                            if (nextLowerLevel > 0)
                            {
                                DownFillStructureOfGraph(anotherGraph, nextLowerLevelKey.GetPredecessorLevel(_iGraphDB, _securityToken, _transactionToken));
                            }
                        }
                    }
                    else
                    {
                        anotherGraph.Levels.Add(nextLowerLevel, new ExpressionLevel());
                        anotherGraph.Levels[nextLowerLevel].AddEmptyLevelKey(nextLowerLevelKey);

                        if (nextLowerLevel > 0)
                        {
                            DownFillStructureOfGraph(anotherGraph, nextLowerLevelKey);
                        }
                    }
                }
            }
        }
Пример #49
0
 public abstract IEnumerable<IVertex> Select(LevelKey myLevelKey, IVertex mySourceVertex = null, Boolean generateLevel = true);
Пример #50
0
        private void ExtendGraphUp(LevelKey startLevelKey, LevelKey endLevelKey, IExpressionGraph aGraph)
        {
            if (startLevelKey != endLevelKey)
            {
                var nextHigherLevelKeys = (from aHigherExpressionLevel in aGraph.Levels[startLevelKey.Level + 1].ExpressionLevels
                                           where IsValidLevelKeyNeighbourship(startLevelKey, aHigherExpressionLevel.Key)
                                           select aHigherExpressionLevel.Key);
                var nextHigherLevelKey = (from aLowerExpressionLevel in nextHigherLevelKeys where IsValidLevelKeyNeighbourship(aLowerExpressionLevel, endLevelKey) select aLowerExpressionLevel).FirstOrDefault();

                IVertex currentDBObject = null;
                EdgeKey myCurrentForwardEdgekey = nextHigherLevelKey.Edges[startLevelKey.Level];

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

                IAttributeDefinition interestingAttribute = currentType.GetAttributeDefinition(myCurrentForwardEdgekey.AttributeID);

                //find out whats the real type of the referenced objects
                var typeOfReferencedObjects = GetTypeOfAttribute(currentType, interestingAttribute);

                //Extend graph
                foreach (var aNode in aGraph.Levels[startLevelKey.Level].ExpressionLevels[startLevelKey].Nodes)
                {
                    currentDBObject = aNode.Value.GetIVertex();

                    if (currentDBObject != null)
                    {
                        //there is no need to extend the graph if there is no IVertex available
                        switch (interestingAttribute.Kind)
                        {
                            case AttributeType.IncomingEdge:

                                var incomingAttribute = (IIncomingEdgeDefinition)interestingAttribute;

                                if (currentDBObject.HasIncomingVertices(incomingAttribute.RelatedEdgeDefinition.SourceVertexType.ID, incomingAttribute.RelatedEdgeDefinition.ID))
                                {
                                    foreach (var aIncomingVertex in currentDBObject.GetIncomingVertices(incomingAttribute.RelatedEdgeDefinition.SourceVertexType.ID, incomingAttribute.RelatedEdgeDefinition.ID))
                                    {
                                        //add backwardEdge to node (and itself)
                                        aGraph.Levels[nextHigherLevelKey.Level].AddNodeAndBackwardEdge(nextHigherLevelKey, aIncomingVertex, startLevelKey.LastEdge, aNode.Key, null, null);

                                        //recursion
                                        ExtendGraphUp(nextHigherLevelKey, endLevelKey, aGraph);
                                        aNode.Value.AddForwardEdge(myCurrentForwardEdgekey, GenerateVertexInfoFromLevelKeyAndVertexID(aIncomingVertex.VertexTypeID, aIncomingVertex.VertexID), null);
                                    }
                                }

                                break;
                            case AttributeType.OutgoingEdge:

                                var outgoingEdgeAttribute = (IOutgoingEdgeDefinition)interestingAttribute;

                                if (currentDBObject.HasOutgoingEdge(outgoingEdgeAttribute.ID))
                                {
                                    foreach (var aOutgoingVertex in currentDBObject.GetOutgoingEdge(outgoingEdgeAttribute.ID).GetTargetVertices())
                                    {
                                        //add backwardEdge to node (and itself)
                                        aGraph.Levels[nextHigherLevelKey.Level].AddNodeAndBackwardEdge(nextHigherLevelKey, aOutgoingVertex, startLevelKey.LastEdge, aNode.Key, null, null);

                                        //recursion
                                        ExtendGraphUp(nextHigherLevelKey, endLevelKey, aGraph);
                                        aNode.Value.AddForwardEdge(myCurrentForwardEdgekey, GenerateVertexInfoFromLevelKeyAndVertexID(aOutgoingVertex.VertexTypeID, aOutgoingVertex.VertexID), null);
                                    }
                                }

                                break;
                            case AttributeType.Property:
                            default:
                                break;
                        }
                    }
                }
            }
        }
Пример #51
0
 public abstract Boolean IsGraphRelevant(LevelKey myLevelKey, IVertex mySourceVertex);
Пример #52
0
        public LevelKey AddLevelKey(LevelKey myLevelKey2, IGraphDB myGraphDB, SecurityToken mySecurityToken, TransactionToken myTransactionToken)
        {
            if ((this.Edges == null || this.Edges.Count == 0) && (myLevelKey2.Edges == null || myLevelKey2.Edges.Count == 0))
                return new LevelKey();
            else if (this.Edges == null || this.Edges.Count == 0)
                return new LevelKey(myLevelKey2.Edges, myGraphDB, mySecurityToken, myTransactionToken);
            else if (myLevelKey2.Edges == null || myLevelKey2.Edges.Count == 0)
                return new LevelKey(this.Edges, myGraphDB, mySecurityToken, myTransactionToken);

            if (this.Level == 0 && myLevelKey2.Level == 0)
            {
                #region both are level 0 (User/null)
                if (this.Edges[0].VertexTypeID != myLevelKey2.Edges[0].VertexTypeID) // if the types are different then something is really wrong
                    throw new InvalidLevelKeyOperationException(this, myLevelKey2, "+");
                else
                    return new LevelKey(this.Edges, myGraphDB, mySecurityToken, myTransactionToken);
                #endregion
            }
            else if (this.Level == 0)
            {
                #region one of them is level 0 - so we can just skip this level: User/null + User/Friends == User/Friends
                if (this.Edges[0].VertexTypeID != myLevelKey2.Edges[0].VertexTypeID) // if the types are different then something is really wrong
                    throw new InvalidLevelKeyOperationException(this, myLevelKey2, "+");
                else
                    return new LevelKey(myLevelKey2.Edges, myGraphDB, mySecurityToken, myTransactionToken); // just return the other level
                #endregion
            }
            else if (myLevelKey2.Level == 0)
            {
                #region one of them is level 0 - so we can just skip this level: User/null + User/Friends == User/Friends
                if (this.Edges[0].VertexTypeID != myLevelKey2.Edges[0].VertexTypeID) // if the types are different then something is really wrong
                    throw new InvalidLevelKeyOperationException(this, myLevelKey2, "+");
                else
                    return new LevelKey(this.Edges, myGraphDB, mySecurityToken, myTransactionToken); // just return the other level
                #endregion
            }

            var edges = new List<EdgeKey>(this.Edges);
            edges.AddRange(myLevelKey2.Edges);

            return new LevelKey(edges, myGraphDB, mySecurityToken, myTransactionToken);
        }
Пример #53
0
 public abstract void GatherEdgeWeight(LevelKey StartLevel, LevelKey EndLevel);
Пример #54
0
        public Boolean Equals(LevelKey p)
        {
            // If parameter is null return false:
            if ((object)p == null)
            {
                return false;
            }

            if (this.Level != p.Level)
            {
                return false;
            }

            for (int i = 0; i < Edges.Count; i++)
            {
                if (this.Edges[i] != p.Edges[i])
                {
                    return false;
                }
            }

            return true;
        }
Пример #55
0
        public LevelKey RemoveLevelKey(LevelKey myOtherLevelKey, IGraphDB myGraphDB, SecurityToken mySecurityToken, TransactionToken myTransactionToken)
        {
            if (this.Level < myOtherLevelKey.Level)
                throw new ArgumentException("level of left (" + this.Level + ") operand is lower than right (" + myOtherLevelKey.Level + ") operand:", "myOtherLevelKey");

            if (!this.StartsWith(myOtherLevelKey, true))
                throw new ArgumentException("left operand level does not starts with right operand level");

            if (myOtherLevelKey.Level == 0)
                return this;

            if (this.Level == myOtherLevelKey.Level)
                return new LevelKey(this.Edges[0].VertexTypeID, myGraphDB, mySecurityToken, myTransactionToken);

            var edgeList = new List<EdgeKey>(this.Edges);

            return new LevelKey(this.Edges.Skip(myOtherLevelKey.Edges.Count), myGraphDB, mySecurityToken, myTransactionToken);
        }
Пример #56
0
        public bool StartsWith(LevelKey myLevel)
        {
            if (myLevel.Level > Level)
                throw new ArgumentException(myLevel + " is greater than " + Level);

            for (Int32 i = 0; i < myLevel.Level; i++)
            {
                if (myLevel.Edges[i].VertexTypeID != Edges[i].VertexTypeID)
                    return false;
            }
            return true;
        }
Пример #57
0
 public ExpressionLevelEntry(LevelKey myCorrespondingLevelKey, Dictionary <VertexInformation, IExpressionNode> myObjects)
 {
     _Objects = myObjects;
     _CorrespondingLevelKey = myCorrespondingLevelKey;
 }
Пример #58
0
        public bool StartsWith(LevelKey myLevel, Boolean IncludingAttrs)
        {
            if (!IncludingAttrs)
                return StartsWith(myLevel);

            if (myLevel.Level > Level)
                throw new ArgumentException(myLevel + " is greater than " + Level);

            for (Int32 i = 0; i < myLevel.Level; i++)
            {
                if (myLevel.Edges[i].VertexTypeID != Edges[i].VertexTypeID || myLevel.Edges[i].AttributeID != Edges[i].AttributeID)
                    return false;
            }
            return true;
        }
Пример #59
0
        private void AddNodeRecursiveBackward(IVertex myNewVertex, VertexInformation mySourceUUID, LevelKey mySourceLevelKey, LevelKey myNewNodeLevelKey, List<LevelKey> lowerLevelKeys, IExpressionGraph myGraph)
        {
            lock (myGraph)
            {
                //took the vertextype id of the levelkey, because it is possible that the vertextypeid of the vertex is something inheritated
                VertexInformation node = GenerateVertexInfoFromLevelKeyAndVertexID(myNewVertex.VertexTypeID, myNewVertex.VertexID);

                #region add node
                //add node and the node's backwardEdge

                //in this point we are shure that the level reall exists

                if (!myGraph.Levels[myNewNodeLevelKey.Level].ExpressionLevels[myNewNodeLevelKey].Nodes.ContainsKey(node))
                {
                    myGraph.Levels[myNewNodeLevelKey.Level].ExpressionLevels[myNewNodeLevelKey].Nodes.Add(node, new ExpressionNode(myNewVertex, null, node));
                }

                myGraph.Levels[myNewNodeLevelKey.Level].AddForwardEdgeToNode(myNewNodeLevelKey, node, mySourceLevelKey.LastEdge, mySourceUUID, null);

                #endregion

                #region recursion

                if (lowerLevelKeys != null)
                {
                    UpdateLowerLevels(myGraph.Levels[myNewNodeLevelKey.Level].ExpressionLevels[myNewNodeLevelKey].Nodes[node], myNewNodeLevelKey, lowerLevelKeys, myGraph);
                }

                #endregion
            }
        }
Пример #60
0
 public abstract Boolean AddEmptyLevel(LevelKey myLevelKey);