コード例 #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
 public SelectionElementAggregate(IGQLAggregate myBaseAggregate, string myAlias, EdgeList myEdgeList, LevelKey myLevelKey, IDChainDefinition myRelatedIDChainDefinition, AggregateDefinition myAggregateDefinition)
 {
     Alias                    = myAlias;
     EdgeList                 = myEdgeList;
     LevelKey                 = myLevelKey;
     Aggregate                = myBaseAggregate;
     AggregateDefinition      = myAggregateDefinition;
     RelatedIDChainDefinition = myRelatedIDChainDefinition;
 }
コード例 #3
0
        /// <summary>
        /// Creates an validated asterisk chain for the given type.
        /// </summary>
        /// <param name="myIDChainPart">The type chain part.</param>
        public IDChainDefinition(ChainPartTypeOrAttributeDefinition myIDChainPart, TypesOfSelect mySelType, String myTypeName = null)
        {
            RootPart = myIDChainPart;

            IsValidated = true;
            SelectType  = mySelType;

            _Edges   = new List <EdgeKey>();
            LevelKey = new LevelKey();
        }
コード例 #4
0
        public override bool Equals(object obj)
        {
            LevelKey otherKey = obj as LevelKey;

            if (otherKey != null)
            {
                return(otherKey.packName == packName && otherKey.levelNumber == levelNumber);
            }
            return(false);
        }
コード例 #5
0
    static LevelKey convertToLevelKey(string entry)
    {
        //parse string on space
        char[]   delimchars = { ';' };
        string[] words      = entry.Split(delimchars);
        //print (words[0]);
        //print (words[1]);
        int      x   = Int32.Parse(words[1]);
        LevelKey key = new LevelKey(words[0], x);

        return(key);
    }
コード例 #6
0
    public static void deserializeDic(TextReader reader, IDictionary dictionary)
    {
        dictionary.Clear();
        XmlSerializer serializer = new XmlSerializer(typeof(List <Entry>));
        List <Entry>  list       = (List <Entry>)serializer.Deserialize(reader);

        foreach (Entry entry in list)
        {
            LevelKey key = convertToLevelKey(entry.Key);
            dictionary.Add(key, entry.Value);
        }
    }
コード例 #7
0
        public void addLevel(string pack, int level, int status)
        {
            LevelKey key = new LevelKey(pack, level);

            if (completedLevels.ContainsKey(key))
            {
                completedLevels[key] = status;
            }
            else
            {
                completedLevels.Add(key, status);
            }
        }
コード例 #8
0
        public int getLevelStatus(string pack, int level)
        {
            LevelKey key = new LevelKey(pack, level);

            if (completedLevels.ContainsKey(key))
            {
                return(completedLevels[key]);
            }
            else
            {
                //TODO change this to a better value
                return(0);
            }
        }
コード例 #9
0
        private static void MatchData(DataContainer data,
                                      IExpressionGraph resultGraph,
                                      IGraphDB myGraphDB,
                                      SecurityToken mySecurityToken,
                                      Int64 myTransactionToken,
                                      TypesOfOperators myTypeOfOperator,
                                      BinaryOperator myOperator,
                                      String myExpressionIndex)
        {
            #region data

            LevelKey myLevelKey = CreateLevelKey(data.IDChainDefinitions.Item1, myGraphDB, mySecurityToken, myTransactionToken);

            #endregion

            var vertices = myGraphDB.GetVertices <List <IVertex> >(
                mySecurityToken,
                myTransactionToken,
                new GraphDB.Request.RequestGetVertices(
                    new BinaryExpression(
                        new PropertyExpression(data.IDChainDefinitions.Item1.LastType.Name, data.IDChainDefinitions.Item1.LastAttribute.Name),
                        myOperator,
                        GenerateLiteral(data.Operands.Item1, ((IPropertyDefinition)data.IDChainDefinitions.Item1.LastAttribute).BaseType),
                        myExpressionIndex)),
                (stats, vertexEnumerable) => vertexEnumerable.ToList());

            foreach (var aVertex in vertices)
            {
                IntegrateInGraph(aVertex, resultGraph, myLevelKey, myTypeOfOperator);
            }

            if (resultGraph.ContainsLevelKey(myLevelKey))
            {
                #region clean lower levels

                if (myTypeOfOperator == TypesOfOperators.AffectsLowerLevels)
                {
                    CleanLowerLevel(myLevelKey, resultGraph, myGraphDB, mySecurityToken, myTransactionToken);
                }

                #endregion
            }
            else
            {
                resultGraph.AddEmptyLevel(myLevelKey);
            }
        }
コード例 #10
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);
 }
コード例 #11
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);
     }
 }
コード例 #12
0
 public override int GetHashCode()
 {
     return(Alias.GetHashCode() ^ EdgeList.GetHashCode() ^ Element.GetHashCode() ^ Selection.GetHashCode() ^ IsGroupedOrAggregated.GetHashCode() ^ LevelKey.GetHashCode() ^ Function.FuncName.GetHashCode());
 }
コード例 #13
0
        /// <summary>
        /// Validates the id chain if it is not already validated and returns all errors and warnings.
        /// </summary>
        public void Validate(GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken, Dictionary <String, IVertexType> myListOfReferences, Boolean allowUndefinedAttributes = false)
        {
            IsValidated = true;

            int    _HashCode       = 0;
            Object funcWorkingBase = null;
            var    curPart         = RootPart;

            if (curPart == null)
            {
                if (myListOfReferences.Count != 1)
                {
                    throw new DuplicateReferenceOccurrenceException("");
                }

                _Reference = new Tuple <string, IVertexType>(myListOfReferences.First().Key, myListOfReferences.First().Value);
                _LastType  = _Reference.Item2;
                _Edges     = new List <EdgeKey>();
                _Edges.Add(new EdgeKey(_LastType.ID));
                SelectType = TypesOfSelect.Asterisk;
                LevelKey   = new LevelKey(_Edges, myGraphDB, mySecurityToken, myTransactionToken);
            }

            while (curPart != null)
            {
                #region Go through each part and try to fill lastType, lastAttribute etc...

                if (curPart is ChainPartFuncDefinition)
                {
                    #region ChainPartFuncDefinition

                    var funcPart = (curPart as ChainPartFuncDefinition);
                    funcPart.Validate(myPluginManager, myGraphDB, mySecurityToken, myTransactionToken);

                    if (!funcPart.Function.ValidateWorkingBase(funcWorkingBase, myGraphDB, mySecurityToken, myTransactionToken))
                    {
                        throw new InvalidFunctionBaseException(_LastAttribute.Name, funcPart.FuncName);
                    }

                    var returnType = funcPart.Function.GetReturnType();
                    if (returnType != null)
                    {
                        if (returnType is IAttributeDefinition)
                        {
                            //_LastAttribute = (returnType as DBTypeAttribute).GetValue();
                            //_LastType = GetDBTypeByAttribute(myDBContext, _LastAttribute);
                        }
                        else if (returnType is Object)
                        {
                            //_LastAttribute = null;
                            //_LastType = (returnType as DBType).GetValue();
                        }
                        else if (returnType is Type)
                        {
                            //_LastAttribute = null;
                            //_LastType = myDBContext.DBTypeManager.GetTypeByName((returnType as ADBBaseObject).ObjectName);
                        }
                        else
                        {
                            throw new InvalidFunctionReturnTypeException(funcPart.FuncName, returnType.GetType(), typeof(IAttributeDefinition), typeof(IVertexType), typeof(Object));
                        }
                        funcWorkingBase = returnType;
                    }

                    #endregion
                }
                else if (curPart is ChainPartTypeOrAttributeDefinition)
                {
                    var typeOrAttr = curPart as ChainPartTypeOrAttributeDefinition;

                    #region Check whether it is a reference

                    if (_LastAttribute != null)
                    {
                        #region Any attribute on an undefined attributes or not user defined (reference) type is not allowed

                        if (_LastAttribute is UnstructuredProperty || _LastAttribute.Kind == AttributeType.Property)
                        {
                            throw new VertexAttributeIsNotDefinedException(typeOrAttr.TypeOrAttributeName);
                        }

                        #endregion

                        #region The previous attribute seems to be an reference attribute

                        _LastType = GetTargetVertexTypeByAttribute(_LastAttribute);

                        typeOrAttr.DBType        = _LastType;
                        typeOrAttr.TypeAttribute = typeOrAttr.DBType.GetAttributeDefinition(typeOrAttr.TypeOrAttributeName);
                        _LastAttribute           = typeOrAttr.TypeAttribute;

                        if (_LastAttribute == null)
                        {
                            #region Undefined attribute

                            if (allowUndefinedAttributes)
                            {
                                UndefinedAttribute       = typeOrAttr.TypeOrAttributeName;
                                _LastAttribute           = new UnstructuredProperty(UndefinedAttribute);
                                typeOrAttr.TypeAttribute = _LastAttribute;
                                AddNewEdgeKey(_LastType, _LastAttribute.ID);
                            }
                            else
                            {
                                throw new VertexAttributeIsNotDefinedException(typeOrAttr.TypeOrAttributeName);
                            }

                            #endregion
                        }
                        else
                        {
                            AddNewEdgeKey(_LastType, _LastAttribute.ID);
                        }

                        #endregion
                    }
                    else if (_LastType == null)
                    {
                        #region We did not resolve any type - so we should have a reference (U.Friends) or an undefined attribute

                        if (myListOfReferences.ContainsKey(typeOrAttr.TypeOrAttributeName))
                        {
                            #region The current TypeOrAttributeName is either an reference U

                            typeOrAttr.DBType = myListOfReferences[typeOrAttr.TypeOrAttributeName];

                            //Case 1: sth like "U" (where U stands for User)
                            #region Case 1

                            _LastType  = typeOrAttr.DBType;
                            _Reference = new Tuple <string, IVertexType>(typeOrAttr.TypeOrAttributeName, typeOrAttr.DBType);

                            if (curPart.Next == null) // we just have an type definition
                            {
                                SelectType = TypesOfSelect.Asterisk;
                                _Edges.Add(new EdgeKey(_LastType.ID));
                            }

                            #endregion

                            //Case 2: an attribute like "Car" (of "User") is used and in parallel a similar written Type exists. In this case
                            // it is necessary to throw an error.
                            #region Case 2

                            var typesWithAttibute = (from aContextType in myListOfReferences
                                                     where (aContextType.Key != typeOrAttr.TypeOrAttributeName) && aContextType.Value.GetAttributeDefinition(typeOrAttr.TypeOrAttributeName) != null
                                                     select aContextType.Key).FirstOrDefault();

                            if (typesWithAttibute != null)
                            {
                                throw new DuplicateReferenceOccurrenceException(typeOrAttr.TypeOrAttributeName);
                            }

                            #endregion

                            #region Skip this part - this is a reference

                            RootPart = curPart.Next;

                            #endregion

                            #endregion
                        }
                        else
                        {
                            //Case 3:
                            //  (3.1)In this case it must be an attribute. If it is used in an ambigous way, an exception would be thrown.
                            //  (3.2)In this case it can be an undefined attribute or if it was used like an edge it is treated like does not exist (U.NotExists.Name)

                            #region case 3

                            #region sth like Name --> we have to find out the corresponding type

                            Boolean foundSth  = false;
                            String  reference = null;
                            foreach (var contextElement in myListOfReferences)
                            {
                                var tempAttr = contextElement.Value.GetAttributeDefinition(typeOrAttr.TypeOrAttributeName);


                                //tempTypeAttribute = (from aAttribute in tempType.AttributeLookupTable where aAttribute.Value.Name == tempTypeOrAttributeName select aAttribute.Value).FirstOrDefault();

                                if (tempAttr != null)
                                {
                                    typeOrAttr.DBType = contextElement.Value;
                                    reference         = contextElement.Key;

                                    if (foundSth == true)
                                    {
                                        throw new AmbiguousVertexAttributeException("The attribute or type \"" + typeOrAttr.TypeOrAttributeName + "\" has been used ambigous.");
                                    }
                                    else
                                    {
                                        typeOrAttr.TypeAttribute = tempAttr;
                                        foundSth = true;
                                    }
                                }
                            }

                            #endregion

                            if (foundSth)
                            {
                                #region 3.1

                                //_Edges.Add(new EdgeKey(typeOrAttr.DBType.VertexID, typeOrAttr.TypeAttribute.VertexID));
                                _LastAttribute = typeOrAttr.TypeAttribute;
                                _LastType      = typeOrAttr.DBType;
                                _Reference     = new Tuple <string, IVertexType>(reference, typeOrAttr.DBType); //T1 -->key in context dictionary

                                _Edges.ForEach(item => _HashCode = _HashCode ^ item.GetHashCode());
                                AddNewEdgeKey(_LastType, _LastAttribute.ID);

                                #endregion
                            }
                            else
                            {
                                #region 3.2 - Undefined attribute or attribute does not exist

                                if (curPart.Next != null || !allowUndefinedAttributes)
                                {
                                    #region Calling an attribute on an undefined attribute is not allowed

                                    throw new VertexAttributeIsNotDefinedException(typeOrAttr.TypeOrAttributeName);

                                    #endregion
                                }
                                else
                                {
                                    #region This is the last unknown attribute and with this, it is an undefined attribute

                                    UndefinedAttribute = typeOrAttr.TypeOrAttributeName;

                                    if (myListOfReferences.Count != 1)
                                    {
                                        throw new AmbiguousVertexAttributeException("The attribute or type \"" + typeOrAttr.TypeOrAttributeName + "\" has been used ambigous.");
                                    }
                                    else
                                    {
                                        var theRef = myListOfReferences.First();
                                        _Reference     = new Tuple <string, IVertexType>(theRef.Key, theRef.Value); //T1 -->key in context dictionary
                                        _LastType      = _Reference.Item2;
                                        _LastAttribute = new UnstructuredProperty(UndefinedAttribute);

                                        typeOrAttr.TypeAttribute = _LastAttribute;
                                        typeOrAttr.DBType        = _LastType;

                                        AddNewEdgeKey(_LastType, _LastAttribute.ID);
                                    }

                                    #endregion
                                }

                                //_isValidated = false;

                                //_invalidNodeParts.AddRange(parseNode.ChildNodes);

                                #endregion
                            }

                            #endregion
                        }

                        #endregion
                    }
                    else
                    {
                        #region This is a regular attribute after a reference (U.Name)

                        typeOrAttr.DBType        = _LastType;
                        typeOrAttr.TypeAttribute = typeOrAttr.DBType.GetAttributeDefinition(typeOrAttr.TypeOrAttributeName);
                        _LastAttribute           = typeOrAttr.TypeAttribute;

                        if (_LastAttribute == null)
                        {
                            if (curPart.Next != null || !allowUndefinedAttributes)
                            {
                                #region Calling an attribute on an undefined attribute is not allowed - so we assume a typo

                                throw new VertexAttributeIsNotDefinedException(typeOrAttr.TypeOrAttributeName);
                                //continue;

                                #endregion
                            }
                            else
                            {
                                UndefinedAttribute       = typeOrAttr.TypeOrAttributeName;
                                _LastAttribute           = new UnstructuredProperty(UndefinedAttribute);
                                typeOrAttr.TypeAttribute = _LastAttribute;
                                AddNewEdgeKey(_LastType, _LastAttribute.ID);
                            }
                        }
                        else
                        {
                            AddNewEdgeKey(_LastType, _LastAttribute.ID);
                        }

                        #endregion
                    }

                    #endregion

                    funcWorkingBase = _LastAttribute;
                }

                curPart = curPart.Next;

                #endregion
            }

            LevelKey = new LevelKey(Edges, myGraphDB, mySecurityToken, myTransactionToken);
        }
コード例 #14
0
 /// <summary>
 /// Initializes a new instance of the InvalidLevelKeyOperationException using a level key.
 /// </summary>
 /// <param name="myLevelKeyA"></param>
 /// <param name="myLevelKeyB"></param>
 /// <param name="myOperation"></param>
 /// <param name="innerException">The exception that is the cause of the current exception, this parameter can be NULL.</param>
 public InvalidLevelKeyOperationException(LevelKey myLevelKeyA, LevelKey myLevelKeyB, String myOperation, Exception innerException = null) : base(innerException)
 {
     LevelKeyA = myLevelKeyA;
     LevelKeyB = myLevelKeyB;
     Operation = myOperation;
 }
コード例 #15
0
 /// <summary>
 /// Initializes a new instance of the InvalidLevelKeyOperationException using an edge key.
 /// </summary>
 /// <param name="myLevelKey"></param>
 /// <param name="myEdgeKey"></param>
 /// <param name="myOperation"></param>
 /// <param name="innerException">The exception that is the cause of the current exception, this parameter can be NULL.</param>
 public InvalidLevelKeyOperationException(LevelKey myLevelKey, EdgeKey myEdgeKey, String myOperation, Exception innerException = null) : base(innerException)
 {
     LevelKeyA = myLevelKey;
     EdgeKeyA  = myEdgeKey;
     Operation = myOperation;
 }