Пример #1
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);
                }
            }
        }
Пример #2
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);
                        }
                    }
                }
            }
        }
Пример #3
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;
        }
Пример #4
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;
        }
Пример #5
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.");
                    }
                }
            }
        }
Пример #6
0
        private IEnumerable<LevelKey> GenerateAllLowerLevelKeys(LevelKey myLevelKey)
        {
            LevelKey myLevelKeyPred;

            if (myLevelKey.Level > 0)
            {
                do
                {
                    myLevelKeyPred = myLevelKey.GetPredecessorLevel(_iGraphDB, _securityToken, _transactionToken);

                    yield return myLevelKeyPred;

                } while (myLevelKeyPred.Level != 0);
            }

            yield break;
        }