Esempio n. 1
0
        /// <summary>
        /// Adds a new edge to the vertex defintion
        /// </summary>
        /// <param name="myEdgeDefinition">The definition of the edge</param>
        /// <returns>The reference of the current object. (fluent interface).</returns>
        public RequestUpdate UpdateEdge(EdgePredefinition myEdgeDefinition)
        {
            UpdateOutgoingEdges = UpdateOutgoingEdges ?? new List <EdgePredefinition>();
            UpdateOutgoingEdges.Add(myEdgeDefinition);

            return(this);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a new edge to the vertex defintion
        /// </summary>
        /// <param name="myEdgeName">The name of the edge to be inserted</param>
        /// <param name="myEdgeDefinition">The definition of the edge</param>
        /// <returns>The reference of the current object. (fluent interface).</returns>
        public RequestInsertVertex AddEdge(EdgePredefinition myEdgeDefinition)
        {
            _edges = _edges ?? new HashSet <EdgePredefinition>();
            _edges.Add(myEdgeDefinition);

            return(this);
        }
Esempio n. 3
0
        /// <summary>
        /// Adds elements To a collection
        /// </summary>
        /// <param name="myAttributeName">The attribute that is going to be updated</param>
        /// <param name="myToBeAddedElements">The elements that should be added</param>
        /// <returns>The request itself</returns>
        public RequestUpdate AddElementsToCollection(String myAttributeName, EdgePredefinition myToBeAddedElements)
        {
            AddedElementsToCollectionEdges = AddedElementsToCollectionEdges ?? new Dictionary <String, EdgePredefinition>();
            AddedElementsToCollectionEdges[myAttributeName] = myToBeAddedElements;

            return(this);
        }
Esempio n. 4
0
        /// <summary>
        /// Removes elements from a collection
        /// </summary>
        /// <param name="myAttributeName">The attribute that is going to be updated</param>
        /// <param name="myToBeRemovedElements">The elements that should be removed</param>
        /// <returns>The request itself</returns>
        public RequestUpdate RemoveElementsFromCollection(String myAttributeName, EdgePredefinition myToBeRemovedElements)
        {
            RemovedElementsFromCollectionEdges = RemovedElementsFromCollectionEdges ?? new Dictionary <String, EdgePredefinition>();
            RemovedElementsFromCollectionEdges[myAttributeName] = myToBeRemovedElements;

            return(this);
        }
Esempio n. 5
0
        /// <summary>
        /// Reads an edge information from the GraphML File and inserts
        /// the edge in the GraphDB by altering the existing source vertex.
        ///
        /// Currently only the "weight" attribute will be considered and
        /// has to be annotated correctly (see class documentation).
        /// </summary>
        /// <param name='myReader'>
        /// XmlReader
        /// </param>
        private void ReadEdge(XmlReader myReader)
        {
            #region read edge data

            var sourceID = ReadVertexID(myReader, GraphMLTokens.SOURCE);
            var targetID = ReadVertexID(myReader, GraphMLTokens.TARGET);

            if (!_VertexIDMapper.ContainsKey(sourceID) || !_VertexIDMapper.ContainsKey(targetID))
            {
                throw new InvalidDataException(String.Format(
                                                   "Source or Target vertexID for edge ({0},{1}) doesn't exist",
                                                   sourceID,
                                                   targetID));
            }

            // get the weight
            var edgeWeight = ReadEdgeWeight(myReader);

            #endregion

            #region create edge (update vertex)

            var hyperEdge = new EdgePredefinition(_EdgeTypeName);
            hyperEdge.AddEdge(new EdgePredefinition()
                              .AddVertexID(_VertexTypeName, _VertexIDMapper[targetID])
                              .AddUnknownProperty(
                                  GraphMLTokens.EDGE_WEIGHT,
                                  Convert.ChangeType(edgeWeight, typeof(String), CultureInfo.GetCultureInfo("en-us"))
                                  ));


            var requestUpdate = new RequestUpdate(new RequestGetVertices(_VertexTypeName, new List <long>()
            {
                _VertexIDMapper[sourceID]
            }));
            requestUpdate.AddElementsToCollection(_EdgeTypeName, hyperEdge);

            // process the update
            _GraphDB.Update <IEnumerable <IVertex> >(
                _SecurityToken,
                _TransactionToken,
                requestUpdate,
                (stats, v) => v
                );

            _EdgeCount++;

            #endregion
        }
Esempio n. 6
0
        private void CheckSingleEdge(EdgePredefinition edge, IBaseType myTargetType)
        {
            if (edge.ContainedEdges != null)
            {
                //TODO better exception here.
                throw new Exception("A single edge can not contain other edges.");
            }

            if (edge.VertexIDsByVertexTypeID == null && edge.VertexIDsByVertexTypeName == null)
            {
                //TODO: better exception here
                throw new Exception("A single edge needs at least one target.");
            }

            ConvertUnknownProperties(edge, myTargetType);
        }
        public EdgePredefinition ToEdgePredefinition()
        {
            EdgePredefinition EdgePredef = new EdgePredefinition(this.EdgeName);

            if (!String.IsNullOrEmpty(Comment))
            {
                EdgePredef.Comment = this.Comment;
            }

            if (ContainedEdges != null)
            {
                foreach (var Edge in this.ContainedEdges)
                {
                    EdgePredef.AddEdge(Edge.ToEdgePredefinition());
                }
            }

            if (StructuredProperties != null)
            {
                foreach (var Property in this.StructuredProperties)
                {
                    EdgePredef.AddStructuredProperty(Property.PropertyName, Property.PropertyValue as IComparable);
                }
            }

            if (UnstructuredProperties != null)
            {
                foreach (var Property in this.UnstructuredProperties)
                {
                    EdgePredef.AddUnstructuredProperty(Property.PropertyName, Property.PropertyValue);
                }
            }

            if (VertexIDsByID != null)
            {
                foreach (var VertexTypeSet in this.VertexIDsByID)
                {
                    foreach (var Vertex in VertexTypeSet.Item2)
                    {
                        EdgePredef.AddVertexID(VertexTypeSet.Item1, Vertex);
                    }
                }
            }

            return(EdgePredef);
        }
Esempio n. 8
0
        internal ServiceEdgePredefinition(EdgePredefinition myEdgePredefinition)
        {
            this.EdgeName = myEdgePredefinition.EdgeName;
            this.Comment  = myEdgePredefinition.Comment;

            this.ContainedEdges = (myEdgePredefinition.ContainedEdges == null)
                ? null : myEdgePredefinition.ContainedEdges.Select(x => new ServiceEdgePredefinition(x)).ToList();

            this.VertexIDsByID = (myEdgePredefinition.VertexIDsByVertexTypeID == null)
                ? null : myEdgePredefinition.VertexIDsByVertexTypeID.Select(x => new Tuple <Int64, List <Int64> >(x.Key, x.Value.ToList())).ToList();

            this.StructuredProperties = (myEdgePredefinition.StructuredProperties == null)
                ? null : myEdgePredefinition.StructuredProperties.Select(x => new StructuredProperty(x.Key, x.Value)).ToList();

            this.UnstructuredProperties = (myEdgePredefinition.UnstructuredProperties == null)
                ? null : myEdgePredefinition.UnstructuredProperties.Select(x => new UnstructuredProperty(x.Key, x.Value)).ToList();
        }
Esempio n. 9
0
        internal ServiceEdgePredefinition(EdgePredefinition myEdgePredefinition)
        {
            this.EdgeName = myEdgePredefinition.EdgeName;
            this.Comment  = myEdgePredefinition.Comment;

            this.ContainedEdges = (myEdgePredefinition.ContainedEdges == null)
                ? null : myEdgePredefinition.ContainedEdges.Select(x => new ServiceEdgePredefinition(x)).ToArray();

            this.VertexIDsByID = (myEdgePredefinition.VertexIDsByVertexTypeID == null)
                ? null : myEdgePredefinition.VertexIDsByVertexTypeID.ToDictionary(_ => _.Key, _ => _.Value.ToArray());

            this.StructuredProperties = (myEdgePredefinition.StructuredProperties == null)
                ? null : myEdgePredefinition.StructuredProperties.Select(x => new StructuredProperty(x.Key, x.Value)).ToArray();

            this.UnstructuredProperties = (myEdgePredefinition.UnstructuredProperties == null)
                ? null : myEdgePredefinition.UnstructuredProperties.Select(x => new UnstructuredProperty(x.Key, x.Value)).ToArray();
        }
Esempio n. 10
0
        private void AddDefaultValues(ref EdgePredefinition edgeDef, IEdgeType myEdgeType)
        {
            var mandatoryProps = myEdgeType.GetPropertyDefinitions(true).Where(_ => _.IsMandatory);

            foreach (var propertyDefinition in mandatoryProps)
            {
                if (edgeDef.StructuredProperties == null || 
                    !edgeDef.StructuredProperties.ContainsKey(propertyDefinition.Name))
                    edgeDef.AddStructuredProperty(propertyDefinition.Name, propertyDefinition.DefaultValue);
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Adds edge default properties like CreationDate, ModifactionDate sao. to the predefinition if not already existing
 /// </summary>
 /// <param name="myPredef">The to be chaged Predefinition</param>
 /// <param name="myAttrDef">The outgoing edge definition</param>
 /// <param name="myDate">actual date long</param>
 private void AddDefaultPropertiesToEdgePredefinition(ref EdgePredefinition myPredef, 
                                                         IOutgoingEdgeDefinition myAttrDef, 
                                                         long myDate)
 {
     foreach (var item in new Dictionary<String, IComparable>
                                 { { "CreationDate", myDate },
                                   { "ModificationDate", myDate },
                                   { "EdgeTypeName", (myAttrDef.InnerEdgeType == null) 
                                                     ? myAttrDef.EdgeType.Name 
                                                     : myAttrDef.InnerEdgeType.Name },
                                   { "EdgeTypeID", (myAttrDef.InnerEdgeType == null) 
                                                     ? myAttrDef.EdgeType.ID 
                                                     : myAttrDef.InnerEdgeType.ID } })
     {
         if (myPredef.StructuredProperties == null || 
             !myPredef.StructuredProperties.ContainsKey(item.Key))
             myPredef.AddStructuredProperty(item.Key, item.Value );
     }
 }
Esempio n. 12
0
        private HyperEdgeAddDefinition? CreateMultiEdgeAddDefinition(
            Int64 myTransaction,
            SecurityToken mySecurity,
            VertexInformation source,
            long date,
            EdgePredefinition edgeDef,
            IOutgoingEdgeDefinition attrDef)
        {
            var vertexIDs = GetResultingVertexIDs(myTransaction, mySecurity, edgeDef, attrDef.TargetVertexType);

            var contained = CreateContainedEdges(myTransaction, mySecurity, date, vertexIDs, edgeDef, attrDef, source);
            if (contained == null)
                return null;

            return new HyperEdgeAddDefinition(attrDef.ID,
                                                attrDef.EdgeType.ID,
                                                source,
                                                contained,
                                                edgeDef.Comment,
                                                date,
                                                date,
                                                ConvertStructuredProperties(edgeDef, attrDef.InnerEdgeType), 
                                                edgeDef.UnstructuredProperties);
        }
Esempio n. 13
0
        private IEnumerable<SingleEdgeDeleteDefinition> CreateSingleEdgeDeleteDefinitions(VertexInformation mySource, Int64 myTransaction, SecurityToken mySecurity, EdgePredefinition myEdge, IOutgoingEdgeDefinition edgeDef)
        {
            List<SingleEdgeDeleteDefinition> result = new List<SingleEdgeDeleteDefinition>();

            switch (edgeDef.Multiplicity)
            {
                case EdgeMultiplicity.HyperEdge:
                    break;
                case EdgeMultiplicity.MultiEdge:
                    var targets = GetResultingVertexIDs(myTransaction, mySecurity, myEdge, edgeDef.TargetVertexType);
                    if (targets != null)
                        foreach (var target in targets)
                        {
                            result.Add(new SingleEdgeDeleteDefinition(mySource, target));
                        }

                    foreach (var innerEdge in myEdge.ContainedEdges)
                    {
                        targets = GetResultingVertexIDs(myTransaction, mySecurity, innerEdge, edgeDef.TargetVertexType);

                        if (targets != null)
                            foreach (var target in targets)
                            {
                                result.Add(new SingleEdgeDeleteDefinition(mySource, target));
                            }
                    }
                    break;
                default: throw new Exception("The EdgeMultiplicity enumeration was changed, but not this switch statement.");
            }

            return result;
        }
Esempio n. 14
0
        private SingleEdgeAddDefinition? CreateSingleEdgeAddDefinition(
            TransactionToken myTransaction,
            SecurityToken mySecurity,
            long date,
            long myAttributeID,
            EdgePredefinition edgeDef,
            IEdgeType myEdgeType,
            VertexInformation source,
            IVertexType myTargetType = null)
        {
            var vertexIDs = GetResultingVertexIDs(myTransaction, mySecurity, edgeDef, myTargetType);
            if (vertexIDs == null)
                return null;

            CheckMandatoryConstraint(edgeDef, myEdgeType);
            CheckTargetVertices(myTargetType, vertexIDs);
            AddDefaultValues(edgeDef, myEdgeType);
            return new SingleEdgeAddDefinition(myAttributeID, myEdgeType.ID, source, vertexIDs.First(), edgeDef.Comment, date, date, ConvertStructuredProperties(edgeDef, myEdgeType), edgeDef.UnstructuredProperties);
        }
Esempio n. 15
0
        private void ProcessAttributeRemoveList(IVertexType vertexType, GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, TransactionToken myTransactionToken, AttributeRemoveList attributeRemoveList, ref RequestUpdate result)
        {
            if (attributeRemoveList.TupleDefinition is VertexTypeVertexIDCollectionNode)
            {
                #region setofUUIDs

                var edgedef = new EdgePredefinition(attributeRemoveList.AttributeName);

                List<EdgePredefinition> toBeRemovedEdges = new List<EdgePredefinition>();

                foreach (var aTupleElement in ((VertexTypeVertexIDCollectionNode)attributeRemoveList.TupleDefinition).Elements)
                {
                    foreach (var aVertexIDTuple in aTupleElement.VertexIDs)
                    {
                        var innerEdge = new EdgePredefinition();

                        innerEdge.AddVertexID(aTupleElement.ReferencedVertexTypeName, aVertexIDTuple.Item1);

                        edgedef.AddEdge(innerEdge);
                    }
                }

                result.RemoveElementsFromCollection(attributeRemoveList.AttributeName, edgedef);

                #endregion
            }
            else if (attributeRemoveList.TupleDefinition is TupleDefinition)
            {
                if (((TupleDefinition)attributeRemoveList.TupleDefinition).All(_ => _.Value is ValueDefinition))
                {
                    #region base-set

                    //has to be list of comparables
                    ListCollectionWrapper listWrapper = new ListCollectionWrapper();
                    Type myRequestedType;
                    if (vertexType.HasProperty(attributeRemoveList.AttributeIDChain.ContentString))
                    {
                        myRequestedType = ((IPropertyDefinition)vertexType.GetAttributeDefinition(attributeRemoveList.AttributeIDChain.ContentString)).BaseType;
                    }
                    else
                    {
                        myRequestedType = typeof(String);
                    }

                    foreach (var aTupleElement in (TupleDefinition)attributeRemoveList.TupleDefinition)
                    {
                        listWrapper.Add(((ValueDefinition)aTupleElement.Value).Value.ConvertToIComparable(myRequestedType));
                    }

                    result.RemoveElementsFromCollection(attributeRemoveList.AttributeIDChain.ContentString, listWrapper);

                    #endregion
                }
                else
                {
                    #region binaryExpression

                    Dictionary<String, EdgePredefinition> toBeRemovedEdges = new Dictionary<String, EdgePredefinition>();

                    foreach (var aTupleElement in ((TupleDefinition)attributeRemoveList.TupleDefinition))
                    {
                        if (aTupleElement.Value is BinaryExpressionDefinition)
                        {
                            #region BinaryExpressionDefinition

                            if (!vertexType.HasAttribute(attributeRemoveList.AttributeName))
                            {
                                throw new InvalidVertexAttributeException(String.Format("The vertex type {0} has no attribute named {1}.", vertexType.Name, attributeRemoveList.AttributeName));
                            }

                            IAttributeDefinition attribute = vertexType.GetAttributeDefinition(attributeRemoveList.AttributeName);

                            var targetVertexType = ((IOutgoingEdgeDefinition)attribute).TargetVertexType;

                            var vertexIDs = ProcessBinaryExpression(
                                (BinaryExpressionDefinition)aTupleElement.Value,
                                myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, targetVertexType).ToList();

                            if (vertexIDs.Count > 1)
                            {
                                throw new ReferenceAssignmentExpectedException(String.Format("It is not possible to create a single edge pointing to {0} vertices", vertexIDs.Count));
                            }

                            EdgePredefinition outValue = null;

                            if (toBeRemovedEdges.TryGetValue(attributeRemoveList.AttributeName, out outValue))
                            {
                                foreach (var aVertex in vertexIDs)
                                {
                                    outValue.AddEdge(new EdgePredefinition().AddVertexID(aVertex.VertexTypeID, aVertex.VertexID));
                                }
                            }
                            else
                            {
                                EdgePredefinition edge = new EdgePredefinition(attributeRemoveList.AttributeName);

                                foreach (var aVertex in vertexIDs)
                                {
                                    edge.AddEdge(new EdgePredefinition().AddVertexID(aVertex.VertexTypeID, aVertex.VertexID));
                                }

                                toBeRemovedEdges.Add(attributeRemoveList.AttributeName, edge);
                            }

                            #endregion
                        }
                        else
                        {
                            throw new NotImplementedQLException("");
                        }
                    }

                    foreach (var item in toBeRemovedEdges)
                    {
                        result.RemoveElementsFromCollection(item.Key, item.Value);
                    }

                    #endregion
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 16
0
        private void ProcessAttributeAssignOrUpdateList(IVertexType vertexType, GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, TransactionToken myTransactionToken, AttributeAssignOrUpdateList attributeAssignOrUpdateList, ref RequestUpdate result)
        {
            Type myRequestedType;

            switch (attributeAssignOrUpdateList.CollectionDefinition.CollectionType)
            {
                case CollectionType.Set:

                    #region set

                    if (((TupleDefinition)attributeAssignOrUpdateList.CollectionDefinition.TupleDefinition).All(_ => _.Value is ValueDefinition))
                    {
                        #region base-set

                        //has to be list of comparables
                        SetCollectionWrapper setWrapper = new SetCollectionWrapper();

                        if (vertexType.HasProperty(attributeAssignOrUpdateList.AttributeIDChain.ContentString))
                        {
                            myRequestedType = ((IPropertyDefinition)vertexType.GetAttributeDefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString)).BaseType;
                        }
                        else
                        {
                            myRequestedType = typeof(String);
                        }

                        foreach (var aTupleElement in (TupleDefinition)attributeAssignOrUpdateList.CollectionDefinition.TupleDefinition)
                        {
                            setWrapper.Add(((ValueDefinition)aTupleElement.Value).Value.ConvertToIComparable(myRequestedType));
                        }

                        result.AddElementsToCollection(attributeAssignOrUpdateList.AttributeIDChain.ContentString, setWrapper);

                        #endregion
                    }
                    else
                    {
                        #region edge-set

                        EdgePredefinition edgeDefinition = new EdgePredefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString);

                        if (!vertexType.HasAttribute(attributeAssignOrUpdateList.AttributeIDChain.ContentString))
                        {
                            throw new InvalidVertexAttributeException(String.Format("The vertex type {0} has no attribute named {1}.", vertexType.Name, attributeAssignOrUpdateList.AttributeIDChain.ContentString));
                        }

                        IAttributeDefinition attribute =  vertexType.GetAttributeDefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString);
                        foreach (var aTupleElement in (TupleDefinition)attributeAssignOrUpdateList.CollectionDefinition.TupleDefinition)
                        {

                            if (aTupleElement.Value is BinaryExpressionDefinition)
                            {
                                #region BinaryExpressionDefinition

                                var targetVertexType = ((IOutgoingEdgeDefinition)attribute).TargetVertexType;

                                foreach (var aVertex in ProcessBinaryExpression(
                                    (BinaryExpressionDefinition)aTupleElement.Value,
                                    myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, targetVertexType))
                                {
                                    var inneredge = new EdgePredefinition().AddVertexID(aVertex.VertexTypeID, aVertex.VertexID);

                                    foreach (var aStructuredProperty in aTupleElement.Parameters)
                                    {
                                        inneredge.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value);
                                    }

                                    edgeDefinition.AddEdge(inneredge);
                                }

                                #endregion
                            }
                            else
                            {
                                throw new NotImplementedQLException("TODO");
                            }
                        }

                        if (attributeAssignOrUpdateList.Assign)
                        {
                            result.UpdateEdge(edgeDefinition);
                        }
                        else
                        {
                            result.AddElementsToCollection(attributeAssignOrUpdateList.AttributeIDChain.ContentString, edgeDefinition);
                        }

                        #endregion
                    }
                    #endregion

                    return;
                case CollectionType.List:

                    #region list

                    //has to be list of comparables
                    ListCollectionWrapper listWrapper = new ListCollectionWrapper();

                    if (vertexType.HasProperty(attributeAssignOrUpdateList.AttributeIDChain.ContentString))
                    {
                        myRequestedType = ((IPropertyDefinition)vertexType.GetAttributeDefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString)).BaseType;
                    }
                    else
                    {
                        myRequestedType = typeof(String);
                    }

                    foreach (var aTupleElement in (TupleDefinition)attributeAssignOrUpdateList.CollectionDefinition.TupleDefinition)
                    {
                        listWrapper.Add(((ValueDefinition)aTupleElement.Value).Value.ConvertToIComparable(myRequestedType));
                    }

                    result.AddElementsToCollection(attributeAssignOrUpdateList.AttributeIDChain.ContentString, listWrapper);

                    #endregion

                    return;
                case CollectionType.SetOfUUIDs:

                    #region SetOfUUIDs

                    EdgePredefinition anotheredgeDefinition = new EdgePredefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString);

                    foreach (var aTupleElement in ((VertexTypeVertexIDCollectionNode)attributeAssignOrUpdateList.CollectionDefinition.TupleDefinition).Elements)
                    {
                        foreach (var aVertexIDTuple in aTupleElement.VertexIDs)
                        {
                            var innerEdge = new EdgePredefinition();

                            foreach (var aStructuredProperty in aVertexIDTuple.Item2)
                            {
                                innerEdge.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value);
                            }

                            innerEdge.AddVertexID(aTupleElement.ReferencedVertexTypeName, aVertexIDTuple.Item1);

                            anotheredgeDefinition.AddEdge(innerEdge);
                        }
                    }

                    result.AddElementsToCollection(attributeAssignOrUpdateList.AttributeIDChain.ContentString, anotheredgeDefinition);

                    #endregion

                    return;
                default:
                    return;
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Adds an edge to this edge.
        /// </summary>
        /// <param name="myContainedEdge">The edges that will be contained by this hyper edge.</param>
        /// <returns>The reference of the current object. (fluent interface).</returns>
        public EdgePredefinition AddEdge(EdgePredefinition myContainedEdge)
        {
            _edges = _edges ?? new List<EdgePredefinition>();
            _edges.Add(myContainedEdge);

            return this;

        }
Esempio n. 18
0
        private static void ProcessStructuredProperty(GQLPluginManager myPluginManager,
                                                      IGraphDB myGraphDB,
                                                      SecurityToken mySecurityToken,
                                                      Int64 myTransactionToken,
                                                      IVertexType vertexType,
                                                      AAttributeAssignOrUpdate aAttributeDefinition,
                                                      ref RequestInsertVertex result)
        {
            #region AttributeAssignOrUpdateValue

            if (aAttributeDefinition is AttributeAssignOrUpdateValue)
            {
                var value = aAttributeDefinition as AttributeAssignOrUpdateValue;

                result.AddUnknownProperty(value.AttributeIDChain.ContentString, value.Value);

                return;
            }

            #endregion

            #region AttributeAssignOrUpdateList

            if (aAttributeDefinition is AttributeAssignOrUpdateList)
            {
                var value = aAttributeDefinition as AttributeAssignOrUpdateList;

                switch (value.CollectionDefinition.CollectionType)
                {
                case CollectionType.Set:

                    #region set

                    if (!vertexType.HasAttribute(aAttributeDefinition.AttributeIDChain.ContentString))
                    {
                        throw new InvalidVertexAttributeException(String.Format("The vertex type {0} has no attribute named {1}.",
                                                                                vertexType.Name,
                                                                                aAttributeDefinition.AttributeIDChain.ContentString));
                    }

                    IAttributeDefinition attribute = vertexType.GetAttributeDefinition(aAttributeDefinition
                                                                                       .AttributeIDChain
                                                                                       .ContentString);

                    EdgePredefinition edgeDefinition = new EdgePredefinition(value.AttributeIDChain.ContentString);

                    foreach (var aTupleElement in (TupleDefinition)value.CollectionDefinition.TupleDefinition)
                    {
                        if (aTupleElement.Value is BinaryExpressionDefinition)
                        {
                            #region BinaryExpressionDefinition

                            var targetVertexType = ((IOutgoingEdgeDefinition)attribute).TargetVertexType;

                            foreach (var aVertex in ProcessBinaryExpression(
                                         (BinaryExpressionDefinition)aTupleElement.Value,
                                         myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, targetVertexType))
                            {
                                var inneredge = new EdgePredefinition().AddVertexID(aVertex.VertexTypeID, aVertex.VertexID);

                                foreach (var aStructuredProperty in aTupleElement.Parameters)
                                {
                                    inneredge.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value);
                                }

                                edgeDefinition.AddEdge(inneredge);
                            }

                            #endregion
                        }
                        else
                        {
                            throw new NotImplementedQLException("TODO");
                        }
                    }

                    result.AddEdge(edgeDefinition);

                    #endregion )

                    return;

                case CollectionType.List:

                    #region list

                    //has to be list of comparables
                    ListCollectionWrapper listWrapper = new ListCollectionWrapper();

                    Type myRequestedType;
                    if (vertexType.HasProperty(aAttributeDefinition.AttributeIDChain.ContentString))
                    {
                        myRequestedType = ((IPropertyDefinition)vertexType
                                           .GetAttributeDefinition(aAttributeDefinition.AttributeIDChain.ContentString)).BaseType;
                    }
                    else
                    {
                        myRequestedType = typeof(String);
                    }

                    foreach (var aTupleElement in (TupleDefinition)value.CollectionDefinition.TupleDefinition)
                    {
                        listWrapper.Add(((ValueDefinition)aTupleElement.Value).Value.ConvertToIComparable(myRequestedType));
                    }

                    result.AddStructuredProperty(aAttributeDefinition.AttributeIDChain.ContentString, listWrapper);

                    #endregion )

                    return;

                case CollectionType.SetOfUUIDs:

                    #region SetOfUUIDs

                    EdgePredefinition anotheredgeDefinition = new EdgePredefinition(value.AttributeIDChain.ContentString);

                    foreach (var aTupleElement in ((VertexTypeVertexIDCollectionNode)value.CollectionDefinition.TupleDefinition).Elements)
                    {
                        foreach (var aVertexIDTuple in aTupleElement.VertexIDs)
                        {
                            var innerEdge = new EdgePredefinition();

                            foreach (var aStructuredProperty in aVertexIDTuple.Item2)
                            {
                                innerEdge.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value);
                            }

                            innerEdge.AddVertexID(aTupleElement.ReferencedVertexTypeName, aVertexIDTuple.Item1);

                            anotheredgeDefinition.AddEdge(innerEdge);
                        }
                    }

                    result.AddEdge(anotheredgeDefinition);

                    #endregion

                    return;

                default:
                    return;
                }
            }

            #endregion

            #region SetRefNode

            if (aAttributeDefinition is AttributeAssignOrUpdateSetRef)
            {
                var value = aAttributeDefinition as AttributeAssignOrUpdateSetRef;

                var edgeDefinition = new EdgePredefinition(value.AttributeIDChain.ContentString);

                if (value.SetRefDefinition.IsREFUUID)
                {
                    #region direct vertex ids

                    foreach (var aTupleElement in value.SetRefDefinition.TupleDefinition)
                    {
                        if (aTupleElement.Value is ValueDefinition)
                        {
                            #region ValueDefinition

                            foreach (var aProperty in aTupleElement.Parameters)
                            {
                                edgeDefinition.AddUnknownProperty(aProperty.Key, aProperty.Value);
                            }

                            edgeDefinition.AddVertexID(value.SetRefDefinition.ReferencedVertexType,
                                                       Convert.ToInt64(((ValueDefinition)aTupleElement.Value).Value));

                            #endregion
                        }
                        else
                        {
                            throw new NotImplementedQLException("TODO");
                        }
                    }

                    #endregion
                }
                else
                {
                    #region expression

                    if (!vertexType.HasAttribute(aAttributeDefinition.AttributeIDChain.ContentString))
                    {
                        throw new InvalidVertexAttributeException(String.Format("The vertex type {0} has no attribute named {1}.",
                                                                                vertexType.Name,
                                                                                aAttributeDefinition.AttributeIDChain.ContentString));
                    }
                    IAttributeDefinition attribute = vertexType.GetAttributeDefinition(aAttributeDefinition.AttributeIDChain.ContentString);

                    foreach (var aTupleElement in value.SetRefDefinition.TupleDefinition)
                    {
                        if (aTupleElement.Value is BinaryExpressionDefinition)
                        {
                            #region BinaryExpressionDefinition

                            var targetVertexType = ((IOutgoingEdgeDefinition)attribute).TargetVertexType;

                            var vertexIDs = ProcessBinaryExpression(
                                (BinaryExpressionDefinition)aTupleElement.Value,
                                myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, targetVertexType).ToList();

                            if (vertexIDs.Count > 1)
                            {
                                throw new ReferenceAssignmentExpectedException(String.Format("It is not possible to create a single edge pointing to {0} vertices",
                                                                                             vertexIDs.Count));
                            }

                            var inneredge = new EdgePredefinition();

                            foreach (var aStructuredProperty in aTupleElement.Parameters)
                            {
                                edgeDefinition.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value);
                            }

                            edgeDefinition.AddVertexID(vertexIDs.FirstOrDefault().VertexTypeID, vertexIDs.FirstOrDefault().VertexID);

                            #endregion
                        }
                        else
                        {
                            throw new NotImplementedQLException("");
                        }
                    }

                    #endregion
                }

                result.AddEdge(edgeDefinition);

                return;
            }

            #endregion
        }
Esempio n. 19
0
        EdgePredefinition CreateEdge(List<long> recentVertexIDs, Random myPRNG, long vertexTypeID)
        {
            var result = new EdgePredefinition("Friends");

            if (_maxCountOfEdges > recentVertexIDs.Count)
            {
                AddSingleEdges(result, recentVertexIDs, vertexTypeID);
            }
            else
            {
                HashSet<long> destinationVertexIDs = new HashSet<long>();
                var countEdges = myPRNG.Next(_minCountOfEdges, _maxCountOfEdges);

                do
                {
                    destinationVertexIDs.Add(recentVertexIDs[myPRNG.Next(0, recentVertexIDs.Count)]);
                } while (destinationVertexIDs.Count < countEdges);

                AddSingleEdges(result, destinationVertexIDs, vertexTypeID);
            }

            return result;
        }
Esempio n. 20
0
 void AddSingleEdges(EdgePredefinition result, IEnumerable<long> destinationVertexIDs, long vertexTypeID)
 {
     foreach (var aDestinationID in destinationVertexIDs)
     {
         result.AddEdge(new EdgePredefinition().AddVertexID(vertexTypeID, aDestinationID));
     }
 }
Esempio n. 21
0
        /// <summary>
        /// Adds a new edge to the vertex defintion
        /// </summary>
        /// <param name="myEdgeName">The name of the edge to be inserted</param>
        /// <param name="myEdgeDefinition">The definition of the edge</param>
        /// <returns>The reference of the current object. (fluent interface).</returns>
        public RequestInsertVertex AddEdge(EdgePredefinition myEdgeDefinition)
        {
            _edges = _edges ?? new HashSet<EdgePredefinition>();
            _edges.Add(myEdgeDefinition);

            return this;
        }
Esempio n. 22
0
        private void Run()
        {
            /*var UserVertexPredifinition = new VertexTypePredefinition("User")
                     .AddProperty(new PropertyPredefinition("Name", "String"))
                     .AddOutgoingEdge(new OutgoingEdgePredefinition("friends", "User").SetMultiplicityAsMultiEdge());*/

            EdgeTypePredefinition EdgeDate_TypePredefinition = new EdgeTypePredefinition("EdgeDate").
                AddProperty(new PropertyPredefinition("Time", "Int32"));
            var UserVertexPredifinition = new VertexTypePredefinition("User")
                     .AddProperty(new PropertyPredefinition("Name", "String"))
                     .AddOutgoingEdge(new OutgoingEdgePredefinition("friends", "User").SetMultiplicityAsMultiEdge("EdgeDate"));


            var UserEdge = GraphDSServer.CreateEdgeType<IEdgeType>(
               SecToken,
               TransactionID,
               new RequestCreateEdgeType(EdgeDate_TypePredefinition),
               (Statistics, EdgeType) => EdgeType);

            var UserVertex = GraphDSServer.CreateVertexType<IVertexType>(
               SecToken,
               TransactionID,
               new RequestCreateVertexType(UserVertexPredifinition),
               (Statistics, VertexTypes) => VertexTypes);

            DateTime dt = DateTime.Now;
            DateTime full_time = DateTime.Now;

            ReadFile();

            Console.WriteLine("Time of reading: {0}", DateTime.Now - dt);
            dt = DateTime.Now;

            for (int i = 0; i < vertices; ++i)
            {
                EdgePredefinition temp_edge = new EdgePredefinition("friends");
                for (int j = 0; j < edge_list[i].Count; ++j)
                    temp_edge.AddEdge(new EdgePredefinition()
                                        .AddStructuredProperty("Time", edge_list[i][j].Value)
                                        .AddVertexID("User", edge_list[i][j].Key));

                var ins = GraphDSServer.Insert<IVertex>(
                         SecToken,
                         TransactionID,
                         new RequestInsertVertex("User")
                             .AddStructuredProperty("Name", "User" + i.ToString())
                             .AddUnknownProperty("VertexID", i)
                             .AddEdge(temp_edge),
                         (Statistics, Result) => Result);
            }

            Console.WriteLine("Time of inserting: {0}", DateTime.Now - dt);
            dt = DateTime.Now;

            edge_list.Clear();
            
            //PrintAllVerticesInBase(UserVertex);

            //Console.WriteLine("Time of selecting: {0}", DateTime.Now - dt);
            //Console.WriteLine("Full time: {0}", DateTime.Now - full_time);

            //var qres_dij = GraphDSServer.Query(SecToken, TransactionID,
            //                    "FROM User U SELECT U.Name, U.friends.Dijkstra(U.Name = 'User4', 5, 'EdgeDate') AS 'path' WHERE U.Name = 'User0'",
            //                    SonesGQLConstants.GQL);

            //var qres = GraphDSServer.Query(SecToken, TransactionID,
            //                                "FROM User U SELECT U.Name, U.friends.PATH(U.Name = 'User4', 5, 5, true, false) AS 'path' WHERE U.Name = 'User0' OR U.Name = 'User1'",
            //                                SonesGQLConstants.GQL);

            //Console.WriteLine("Time of BFS: {0}", DateTime.Now - dt);
            //dt = DateTime.Now;

            //CheckResult(qres);

            //var first_vert = qres.Vertices.FirstOrDefault();

            //foreach (var vert in qres.Vertices)
            //    PrintWays(vert);

            //Console.WriteLine("Time of printing: {0}", DateTime.Now - dt);
            //Console.WriteLine("Full time: {0}", DateTime.Now - full_time);
        }
Esempio n. 23
0
        private void ProcessAttributeAssignOrUpdateList(IVertexType vertexType,
                                                        GQLPluginManager myPluginManager,
                                                        IGraphDB myGraphDB,
                                                        SecurityToken mySecurityToken,
                                                        Int64 myTransactionToken,
                                                        AttributeAssignOrUpdateList attributeAssignOrUpdateList,
                                                        ref RequestUpdate result)
        {
            Type myRequestedType;

            switch (attributeAssignOrUpdateList.CollectionDefinition.CollectionType)
            {
            case CollectionType.Set:

                #region set

                if (((TupleDefinition)attributeAssignOrUpdateList.CollectionDefinition.TupleDefinition).All(_ => _.Value is ValueDefinition))
                {
                    #region base-set

                    //has to be list of comparables
                    SetCollectionWrapper setWrapper = new SetCollectionWrapper();

                    if (vertexType.HasProperty(attributeAssignOrUpdateList.AttributeIDChain.ContentString))
                    {
                        myRequestedType = ((IPropertyDefinition)vertexType.GetAttributeDefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString)).BaseType;
                    }
                    else
                    {
                        myRequestedType = typeof(String);
                    }

                    foreach (var aTupleElement in (TupleDefinition)attributeAssignOrUpdateList.CollectionDefinition.TupleDefinition)
                    {
                        setWrapper.Add(((ValueDefinition)aTupleElement.Value).Value.ConvertToIComparable(myRequestedType));
                    }

                    result.AddElementsToCollection(attributeAssignOrUpdateList.AttributeIDChain.ContentString, setWrapper);

                    #endregion
                }
                else
                {
                    #region edge-set

                    EdgePredefinition edgeDefinition = new EdgePredefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString);

                    if (!vertexType.HasAttribute(attributeAssignOrUpdateList.AttributeIDChain.ContentString))
                    {
                        throw new InvalidVertexAttributeException(String.Format("The vertex type {0} has no attribute named {1}.", vertexType.Name, attributeAssignOrUpdateList.AttributeIDChain.ContentString));
                    }

                    IAttributeDefinition attribute = vertexType.GetAttributeDefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString);
                    foreach (var aTupleElement in (TupleDefinition)attributeAssignOrUpdateList.CollectionDefinition.TupleDefinition)
                    {
                        if (aTupleElement.Value is BinaryExpressionDefinition)
                        {
                            #region BinaryExpressionDefinition

                            var targetVertexType = ((IOutgoingEdgeDefinition)attribute).TargetVertexType;

                            foreach (var aVertex in ProcessBinaryExpression(
                                         (BinaryExpressionDefinition)aTupleElement.Value,
                                         myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, targetVertexType))
                            {
                                var inneredge = new EdgePredefinition().AddVertexID(aVertex.VertexTypeID, aVertex.VertexID);

                                foreach (var aStructuredProperty in aTupleElement.Parameters)
                                {
                                    inneredge.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value);
                                }

                                edgeDefinition.AddEdge(inneredge);
                            }

                            #endregion
                        }
                        else
                        {
                            throw new NotImplementedQLException("TODO");
                        }
                    }

                    if (attributeAssignOrUpdateList.Assign)
                    {
                        result.UpdateEdge(edgeDefinition);
                    }
                    else
                    {
                        result.AddElementsToCollection(attributeAssignOrUpdateList.AttributeIDChain.ContentString, edgeDefinition);
                    }

                    #endregion
                }
                #endregion

                return;

            case CollectionType.List:

                #region list

                //has to be list of comparables
                ListCollectionWrapper listWrapper = new ListCollectionWrapper();

                if (vertexType.HasProperty(attributeAssignOrUpdateList.AttributeIDChain.ContentString))
                {
                    myRequestedType = ((IPropertyDefinition)vertexType.GetAttributeDefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString)).BaseType;
                }
                else
                {
                    myRequestedType = typeof(String);
                }

                foreach (var aTupleElement in (TupleDefinition)attributeAssignOrUpdateList.CollectionDefinition.TupleDefinition)
                {
                    listWrapper.Add(((ValueDefinition)aTupleElement.Value).Value.ConvertToIComparable(myRequestedType));
                }

                result.AddElementsToCollection(attributeAssignOrUpdateList.AttributeIDChain.ContentString, listWrapper);

                #endregion

                return;

            case CollectionType.SetOfUUIDs:

                #region SetOfUUIDs

                EdgePredefinition anotheredgeDefinition = new EdgePredefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString);

                foreach (var aTupleElement in ((VertexTypeVertexIDCollectionNode)attributeAssignOrUpdateList.CollectionDefinition.TupleDefinition).Elements)
                {
                    foreach (var aVertexIDTuple in aTupleElement.VertexIDs)
                    {
                        var innerEdge = new EdgePredefinition();

                        foreach (var aStructuredProperty in aVertexIDTuple.Item2)
                        {
                            innerEdge.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value);
                        }

                        innerEdge.AddVertexID(aTupleElement.ReferencedVertexTypeName, aVertexIDTuple.Item1);

                        anotheredgeDefinition.AddEdge(innerEdge);
                    }
                }

                result.AddElementsToCollection(attributeAssignOrUpdateList.AttributeIDChain.ContentString, anotheredgeDefinition);

                #endregion

                return;

            default:
                return;
            }
        }
Esempio n. 24
0
        private void CheckSingleEdge(EdgePredefinition edge, IBaseType myTargetType)
        {
            if (edge.ContainedEdges != null)
            {
                //TODO better exception here.
                throw new Exception("A single edge can not contain other edges.");
            }

            if (edge.VertexIDsByVertexTypeID == null && edge.VertexIDsByVertexTypeName == null)
                //TODO: better exception here
                throw new Exception("A single edge needs at least one target.");

            ConvertUnknownProperties(edge, myTargetType);
        }
Esempio n. 25
0
        private void ProcessAttributeAssignOrUpdateSetRef(IVertexType vertexType, GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, TransactionToken myTransactionToken, AttributeAssignOrUpdateSetRef attributeAssignOrUpdateSetRef, ref RequestUpdate result)
        {
            #region SetRefNode

            var edgeDefinition = new EdgePredefinition(attributeAssignOrUpdateSetRef.AttributeIDChain.ContentString);

            if (attributeAssignOrUpdateSetRef.SetRefDefinition.IsREFUUID)
            {
                #region direct vertex ids

                foreach (var aTupleElement in attributeAssignOrUpdateSetRef.SetRefDefinition.TupleDefinition)
                {
                    if (aTupleElement.Value is ValueDefinition)
                    {
                        #region ValueDefinition

                        foreach (var aProperty in aTupleElement.Parameters)
                        {
                            edgeDefinition.AddUnknownProperty(aProperty.Key, aProperty.Value);
                        }

                        edgeDefinition.AddVertexID(
                            attributeAssignOrUpdateSetRef.SetRefDefinition.ReferencedVertexType,
                            Convert.ToInt64(((ValueDefinition)aTupleElement.Value).Value));

                        #endregion
                    }
                    else
                    {
                        throw new NotImplementedQLException("TODO");
                    }
                }

                result.UpdateEdge(edgeDefinition);

                #endregion
            }
            else
            {
                #region expression

                if (!vertexType.HasAttribute(attributeAssignOrUpdateSetRef.AttributeIDChain.ContentString))
                {
                    throw new InvalidVertexAttributeException(String.Format("The vertex type {0} has no attribute named {1}.", vertexType.Name, attributeAssignOrUpdateSetRef.AttributeIDChain.ContentString));
                }
                IAttributeDefinition attribute = vertexType.GetAttributeDefinition(attributeAssignOrUpdateSetRef.AttributeIDChain.ContentString);

                foreach (var aTupleElement in attributeAssignOrUpdateSetRef.SetRefDefinition.TupleDefinition)
                {
                    if (aTupleElement.Value is BinaryExpressionDefinition)
                    {
                        #region BinaryExpressionDefinition

                        var targetVertexType = ((IOutgoingEdgeDefinition)attribute).TargetVertexType;

                        var vertexIDs = ProcessBinaryExpression(
                            (BinaryExpressionDefinition)aTupleElement.Value,
                            myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, targetVertexType).ToList();

                        if (vertexIDs.Count > 1)
                        {
                            throw new ReferenceAssignmentExpectedException(String.Format("It is not possible to create a single edge pointing to {0} vertices", vertexIDs.Count));
                        }

                        var inneredge = new EdgePredefinition();

                        foreach (var aStructuredProperty in aTupleElement.Parameters)
                        {
                            edgeDefinition.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value);
                        }

                        edgeDefinition.AddVertexID(vertexIDs.FirstOrDefault().VertexTypeID, vertexIDs.FirstOrDefault().VertexID);

                        #endregion
                    }
                    else
                    {
                        throw new NotImplementedQLException("");
                    }
                }

                #endregion

                result.UpdateEdge(edgeDefinition);

                return;
            }

            #endregion
        }
Esempio n. 26
0
        /// <summary>
        /// Removes elements from a collection
        /// </summary>
        /// <param name="myAttributeName">The attribute that is going to be updated</param>
        /// <param name="myToBeRemovedElements">The elements that should be removed</param>
        /// <returns>The request itself</returns>
        public RequestUpdate RemoveElementsFromCollection(String myAttributeName, EdgePredefinition myToBeRemovedElements)
        {
            RemovedElementsFromCollectionEdges = RemovedElementsFromCollectionEdges ?? new Dictionary<String, EdgePredefinition>();
            RemovedElementsFromCollectionEdges[myAttributeName] = myToBeRemovedElements;

            return this;
        }
Esempio n. 27
0
        private IEnumerable<SingleEdgeAddDefinition> CreateContainedEdges(
            TransactionToken myTransaction,
            SecurityToken mySecurity,
            long myDate,
            IEnumerable<VertexInformation> vertexIDs,
            EdgePredefinition edgeDef,
            IOutgoingEdgeDefinition attrDef,
            VertexInformation mySource)
        {
            if ((vertexIDs == null || vertexIDs.Count() == 0) && (edgeDef.ContainedEdges == null || edgeDef.ContainedEdges.Count() == 0))
                return null;

            List<SingleEdgeAddDefinition> result = new List<SingleEdgeAddDefinition>();
            if (vertexIDs != null)
            {
                foreach (var vertex in vertexIDs)
                {
                    //single edges from VertexIDs or expression does not have user properties
                    //TODO they can have default values
                    CheckMandatoryConstraint(null, attrDef.InnerEdgeType);
                    result.Add(new SingleEdgeAddDefinition(Int64.MinValue, attrDef.InnerEdgeType.ID, mySource, vertex, null, myDate, myDate, null, null));
                }
            }

            if (edgeDef.ContainedEdges != null)
            {
                foreach (var edge in edgeDef.ContainedEdges)
                {
                    if (edge.ContainedEdges != null)
                        //TODO a better exception here
                        throw new Exception("An edge within a multi edge cannot have contained edges.");

                    var toAdd = CreateSingleEdgeAddDefinition(myTransaction, mySecurity, myDate, Int64.MinValue, edge, attrDef.InnerEdgeType, mySource, attrDef.TargetVertexType);

                    if (toAdd.HasValue)
                        result.Add(toAdd.Value);
                }
            }
            return result;
        }
Esempio n. 28
0
        /// <summary>
        /// Adds elements To a collection
        /// </summary>
        /// <param name="myAttributeName">The attribute that is going to be updated</param>
        /// <param name="myToBeAddedElements">The elements that should be added</param>
        /// <returns>The request itself</returns>
        public RequestUpdate AddElementsToCollection(String myAttributeName, EdgePredefinition myToBeAddedElements)
        {
            AddedElementsToCollectionEdges = AddedElementsToCollectionEdges ?? new Dictionary<String, EdgePredefinition>();
            AddedElementsToCollectionEdges[myAttributeName] = myToBeAddedElements;

            return this;
        }
Esempio n. 29
0
        /// <summary>
        /// This method checks if a element inside the to be updated edge already exist,
        /// if it exist an exception is thrown.
        /// </summary>
        /// <param name="myVertex">the to be updated vertex.</param>
        /// <param name="myEdgeDef">The edge definition.</param>
        /// <param name="myEdgePredef">The update edge predefinition.</param>
        /// <param name="myTransaction">TransactionID</param>
        /// <param name="mySecurityToken">SecurityToken</param>
        private void CheckIfToBeAddedElementAlreadyExist(IVertex myVertex,
                                                            IOutgoingEdgeDefinition myEdgeDef,
                                                            EdgePredefinition myEdgePredef,
                                                            Int64 myTransaction,
                                                            SecurityToken mySecurityToken)
        {
            switch (myEdgeDef.Multiplicity)
            {
                case EdgeMultiplicity.HyperEdge:
                    break;
                case EdgeMultiplicity.MultiEdge:
                    var newTargets = GetResultingVertexIDs(myTransaction, mySecurityToken, myEdgePredef, myEdgeDef.TargetVertexType);
                    var existTargets = myVertex.GetOutgoingHyperEdge(myEdgeDef.ID) == null
                                        ? new List<IVertex>()
                                        : myVertex.GetOutgoingHyperEdge(myEdgeDef.ID).GetTargetVertices();

                    if (newTargets == null)
                    {
                        if (myEdgePredef.ContainedEdges != null)
                        {
                            foreach (var innerEdge in myEdgePredef.ContainedEdges)
                            {
                                newTargets = GetResultingVertexIDs(myTransaction, mySecurityToken, innerEdge, myEdgeDef.TargetVertexType);
                                
                                foreach (var target in newTargets)
                                    if (existTargets.Any(item => item.VertexID.Equals(target.VertexID) && 
                                            item.VertexTypeID.Equals(target.VertexTypeID)))
                                        throw new VertexAlreadyExistException(target.VertexTypeID, target.VertexID);
                            }
                        }
                    }
                    else
                        foreach (var target in newTargets)
                            if (existTargets.Any(item => item.VertexID.Equals(target.VertexID) &&
                                        item.VertexTypeID.Equals(target.VertexTypeID)))
                                throw new VertexAlreadyExistException(target.VertexTypeID, target.VertexID);

                    break;
                default: throw new Exception("The EdgeMultiplicity enumeration was changed, but not this switch statement.");
            }
        }
Esempio n. 30
0
        /// <summary>
        /// Adds a new edge to the vertex defintion
        /// </summary>
        /// <param name="myEdgeDefinition">The definition of the edge</param>
        /// <returns>The reference of the current object. (fluent interface).</returns>
        public RequestUpdate UpdateEdge(EdgePredefinition myEdgeDefinition)
        {
            UpdateOutgoingEdges = UpdateOutgoingEdges ?? new List<EdgePredefinition>();
            UpdateOutgoingEdges.Add(myEdgeDefinition);

            return this;
        }
Esempio n. 31
0
        private void CreateSingleEdgeUpdateDefinitions(VertexInformation mySource, Int64 myTransaction, SecurityToken mySecurity, EdgePredefinition myEdge, IOutgoingEdgeDefinition edgeDef, out StructuredPropertiesUpdate outStructuredUpdate, out UnstructuredPropertiesUpdate outUnstructuredUpdate, out IEnumerable<SingleEdgeUpdateDefinition> outSingleUpdate)
        {
            #region predefine
            List<SingleEdgeUpdateDefinition> singleUpdate = new List<SingleEdgeUpdateDefinition>();
            #endregion

            outStructuredUpdate = null;
            outUnstructuredUpdate = null;

            switch (edgeDef.Multiplicity)
            {
                case EdgeMultiplicity.HyperEdge:
                    break;
                case EdgeMultiplicity.MultiEdge:
                    var targets = GetResultingVertexIDs(myTransaction, mySecurity, myEdge, edgeDef.TargetVertexType);
                    if (targets != null)
                        foreach (var target in targets)
                        {
                            singleUpdate.Add(new SingleEdgeUpdateDefinition(mySource, target, Int64.MinValue));
                        }

                    if (myEdge.ContainedEdges != null)
                    {

                        foreach (var innerEdge in myEdge.ContainedEdges)
                        {
                            targets = GetResultingVertexIDs(myTransaction, mySecurity, innerEdge, edgeDef.TargetVertexType);
                            ConvertUnknownProperties(innerEdge, edgeDef.InnerEdgeType);

                            var innerStructuredUpdate = CreateStructuredUpdate(innerEdge.StructuredProperties, edgeDef.InnerEdgeType);
                            var innerUnstructuredUpdate = CreateUnstructuredUpdate(innerEdge.UnstructuredProperties);
                            if (targets != null)
                                foreach (var target in targets)
                                {
                                    singleUpdate.Add(new SingleEdgeUpdateDefinition(mySource, target, Int64.MinValue, null, innerStructuredUpdate, innerUnstructuredUpdate));
                                }
                        }
                    }

                    outStructuredUpdate = CreateStructuredUpdate(myEdge.StructuredProperties, edgeDef.InnerEdgeType);
                    outUnstructuredUpdate = CreateUnstructuredUpdate(myEdge.UnstructuredProperties);

                    break;
                default: throw new Exception("The EdgeMultiplicity enumeration was changed, but not this switch statement.");
            }

            #region return

            outSingleUpdate = singleUpdate;

            #endregion
        }
Esempio n. 32
0
        private static void ProcessStructuredProperty(GQLPluginManager myPluginManager, 
            IGraphDB myGraphDB,
            SecurityToken mySecurityToken,
            Int64 myTransactionToken,
            IVertexType vertexType,
            AAttributeAssignOrUpdate aAttributeDefinition,
            ref RequestInsertVertex result)
        {
            #region AttributeAssignOrUpdateValue

            if (aAttributeDefinition is AttributeAssignOrUpdateValue)
            {
                var value = aAttributeDefinition as AttributeAssignOrUpdateValue;

                result.AddUnknownProperty(value.AttributeIDChain.ContentString, value.Value);

                return;
            }

            #endregion

            #region AttributeAssignOrUpdateList

            if (aAttributeDefinition is AttributeAssignOrUpdateList)
            {
                var value = aAttributeDefinition as AttributeAssignOrUpdateList;

                switch (value.CollectionDefinition.CollectionType)
                {
                    case CollectionType.Set:

                        #region set

                        if (!vertexType.HasAttribute(aAttributeDefinition.AttributeIDChain.ContentString))
                        {
                            throw new InvalidVertexAttributeException(String.Format("The vertex type {0} has no attribute named {1}.",
                                                                        vertexType.Name,
                                                                        aAttributeDefinition.AttributeIDChain.ContentString));
                        }

                        IAttributeDefinition attribute = vertexType.GetAttributeDefinition(aAttributeDefinition
                                                                                            .AttributeIDChain
                                                                                            .ContentString);

                        EdgePredefinition edgeDefinition = new EdgePredefinition(value.AttributeIDChain.ContentString);

                        foreach (var aTupleElement in (TupleDefinition)value.CollectionDefinition.TupleDefinition)
                        {

                            if (aTupleElement.Value is BinaryExpressionDefinition)
                            {
                                #region BinaryExpressionDefinition

                                var targetVertexType = ((IOutgoingEdgeDefinition)attribute).TargetVertexType;

                                foreach (var aVertex in ProcessBinaryExpression(
                                    (BinaryExpressionDefinition)aTupleElement.Value,
                                    myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, targetVertexType))
                                {
                                    var inneredge = new EdgePredefinition().AddVertexID(aVertex.VertexTypeID, aVertex.VertexID);

                                    foreach (var aStructuredProperty in aTupleElement.Parameters)
                                    {
                                        inneredge.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value);
                                    }

                                    edgeDefinition.AddEdge(inneredge);
                                }

                                #endregion
                            }
                            else
                            {
                                throw new NotImplementedQLException("TODO");
                            }
                        }

                        result.AddEdge(edgeDefinition);

                        #endregion)

                        return;
                    case CollectionType.List:

                        #region list

                        //has to be list of comparables
                        ListCollectionWrapper listWrapper = new ListCollectionWrapper();

                        Type myRequestedType;
                        if (vertexType.HasProperty(aAttributeDefinition.AttributeIDChain.ContentString))
                        {
                            myRequestedType = ((IPropertyDefinition)vertexType
                                                .GetAttributeDefinition(aAttributeDefinition.AttributeIDChain.ContentString)).BaseType;
                        }
                        else
                        {
                            myRequestedType = typeof(String);
                        }

                        foreach (var aTupleElement in (TupleDefinition)value.CollectionDefinition.TupleDefinition)
                        {
                            listWrapper.Add(((ValueDefinition)aTupleElement.Value).Value.ConvertToIComparable(myRequestedType));
                        }

                        result.AddStructuredProperty(aAttributeDefinition.AttributeIDChain.ContentString, listWrapper);

                        #endregion)

                        return;
                    case CollectionType.SetOfUUIDs:

                        #region SetOfUUIDs

                        EdgePredefinition anotheredgeDefinition = new EdgePredefinition(value.AttributeIDChain.ContentString);

                        foreach (var aTupleElement in ((VertexTypeVertexIDCollectionNode)value.CollectionDefinition.TupleDefinition).Elements)
                        {
                            foreach (var aVertexIDTuple in aTupleElement.VertexIDs)
                            {
                                var innerEdge = new EdgePredefinition();

                                foreach (var aStructuredProperty in aVertexIDTuple.Item2)
                                {
                                    innerEdge.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value);
                                }

                                innerEdge.AddVertexID(aTupleElement.ReferencedVertexTypeName, aVertexIDTuple.Item1);

                                anotheredgeDefinition.AddEdge(innerEdge);
                            }
                        }

                        result.AddEdge(anotheredgeDefinition);

                        #endregion

                        return;
                    default:
                        return;
                }

            }

            #endregion

            #region SetRefNode

            if (aAttributeDefinition is AttributeAssignOrUpdateSetRef)
            {
                var value = aAttributeDefinition as AttributeAssignOrUpdateSetRef;

                var edgeDefinition = new EdgePredefinition(value.AttributeIDChain.ContentString);

                if (value.SetRefDefinition.IsREFUUID)
                {
                    #region direct vertex ids

                    foreach (var aTupleElement in value.SetRefDefinition.TupleDefinition)
                    {
                        if (aTupleElement.Value is ValueDefinition)
                        {
                            #region ValueDefinition

                            foreach (var aProperty in aTupleElement.Parameters)
                            {
                                edgeDefinition.AddUnknownProperty(aProperty.Key, aProperty.Value);
                            }

                            edgeDefinition.AddVertexID(value.SetRefDefinition.ReferencedVertexType,
                                                        Convert.ToInt64(((ValueDefinition) aTupleElement.Value).Value));

                            #endregion
                        }
                        else
                        {
                            throw new NotImplementedQLException("TODO");
                        }
                    }

                    #endregion
                }
                else
                {
                    #region expression

                    if (!vertexType.HasAttribute(aAttributeDefinition.AttributeIDChain.ContentString))
                    {
                        throw new InvalidVertexAttributeException(String.Format("The vertex type {0} has no attribute named {1}.",
                                                                    vertexType.Name,
                                                                    aAttributeDefinition.AttributeIDChain.ContentString));
                    }
                    IAttributeDefinition attribute = vertexType.GetAttributeDefinition(aAttributeDefinition.AttributeIDChain.ContentString);

                    foreach (var aTupleElement in value.SetRefDefinition.TupleDefinition)
                    {
                        if (aTupleElement.Value is BinaryExpressionDefinition)
                        {
                            #region BinaryExpressionDefinition

                            var targetVertexType = ((IOutgoingEdgeDefinition)attribute).TargetVertexType;

                            var vertexIDs = ProcessBinaryExpression(
                                (BinaryExpressionDefinition)aTupleElement.Value,
                                myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, targetVertexType).ToList();

                            if (vertexIDs.Count > 1)
                            {
                                throw new ReferenceAssignmentExpectedException(String.Format("It is not possible to create a single edge pointing to {0} vertices",
                                                                                vertexIDs.Count));
                            }

                            var inneredge = new EdgePredefinition();

                            foreach (var aStructuredProperty in aTupleElement.Parameters)
                            {
                                edgeDefinition.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value);
                            }

                            edgeDefinition.AddVertexID(vertexIDs.FirstOrDefault().VertexTypeID, vertexIDs.FirstOrDefault().VertexID);

                            #endregion
                        }
                        else
                        {
                            throw new NotImplementedQLException("");
                        }
                    }

                    #endregion
                }

                result.AddEdge(edgeDefinition);

                return;
            }

            #endregion
        }
Esempio n. 33
0
        /// <summary>
        /// Creates SingleEdgeAddDefintions to create single edges.
        /// </summary>
        /// <param name="myTransaction">TransactionID</param>
        /// <param name="mySecurity">SecurityToken</param>
        /// <param name="myDate">Actual DateTime in long.</param>
        /// <param name="vertexIDs"></param>
        /// <param name="edgeDef">The EdgePredefnintion.</param>
        /// <param name="attrDef">The attribute defintion of the outgoing egde.</param>
        /// <param name="mySource">The source of the edge.</param>
        /// <returns></returns>
        private IEnumerable<SingleEdgeAddDefinition> CreateContainedEdges(
            Int64 myTransaction,
            SecurityToken mySecurity,
            long myDate,
            IEnumerable<VertexInformation> vertexIDs,
            EdgePredefinition edgeDef,
            IOutgoingEdgeDefinition attrDef,
            VertexInformation mySource)
        {
            if ((vertexIDs == null || vertexIDs.Count() == 0) && 
                (edgeDef.ContainedEdges == null || edgeDef.ContainedEdges.Count() == 0))
                return null;

            List<SingleEdgeAddDefinition> result = new List<SingleEdgeAddDefinition>();

            if (vertexIDs != null)
            {
                foreach (var vertex in vertexIDs)
                {
                    var toAdd = CreateSingleEdgeAddDefinition(myTransaction, 
                                                                mySecurity, 
                                                                myDate, 
                                                                Int64.MinValue,
                                                                edgeDef, 
                                                                attrDef.InnerEdgeType, 
                                                                mySource, 
                                                                attrDef);

                    if (toAdd.HasValue)
                        result.Add(toAdd.Value);
                }
            }

            if (edgeDef.ContainedEdges != null)
            {
                foreach (var edge in edgeDef.ContainedEdges)
                {
                    if (edge.ContainedEdges != null)
                        //TODO a better exception here
                        throw new Exception("An edge within a multi edge cannot have contained edges.");

                    var toAdd = CreateSingleEdgeAddDefinition(myTransaction, 
                                                                mySecurity, 
                                                                myDate, 
                                                                Int64.MinValue, 
                                                                edge, 
                                                                attrDef.InnerEdgeType, 
                                                                mySource, 
                                                                attrDef);

                    if (toAdd.HasValue)
                        result.Add(toAdd.Value);
                }
            }
            return result;
        }
Esempio n. 34
0
        private void ProcessAttributeRemoveList(IVertexType vertexType,
                                                GQLPluginManager myPluginManager,
                                                IGraphDB myGraphDB,
                                                SecurityToken mySecurityToken,
                                                Int64 myTransactionToken,
                                                AttributeRemoveList attributeRemoveList,
                                                ref RequestUpdate result)
        {
            if (attributeRemoveList.TupleDefinition is VertexTypeVertexIDCollectionNode)
            {
                #region setofUUIDs

                var edgedef = new EdgePredefinition(attributeRemoveList.AttributeName);

                List <EdgePredefinition> toBeRemovedEdges = new List <EdgePredefinition>();

                foreach (var aTupleElement in ((VertexTypeVertexIDCollectionNode)attributeRemoveList.TupleDefinition).Elements)
                {
                    foreach (var aVertexIDTuple in aTupleElement.VertexIDs)
                    {
                        var innerEdge = new EdgePredefinition();

                        innerEdge.AddVertexID(aTupleElement.ReferencedVertexTypeName, aVertexIDTuple.Item1);

                        edgedef.AddEdge(innerEdge);
                    }
                }

                result.RemoveElementsFromCollection(attributeRemoveList.AttributeName, edgedef);

                #endregion
            }
            else if (attributeRemoveList.TupleDefinition is TupleDefinition)
            {
                if (((TupleDefinition)attributeRemoveList.TupleDefinition).All(_ => _.Value is ValueDefinition))
                {
                    #region base-set

                    //has to be list of comparables
                    ListCollectionWrapper listWrapper = new ListCollectionWrapper();
                    Type myRequestedType;
                    if (vertexType.HasProperty(attributeRemoveList.AttributeIDChain.ContentString))
                    {
                        myRequestedType = ((IPropertyDefinition)vertexType.GetAttributeDefinition(attributeRemoveList.AttributeIDChain.ContentString)).BaseType;
                    }
                    else
                    {
                        myRequestedType = typeof(String);
                    }

                    foreach (var aTupleElement in (TupleDefinition)attributeRemoveList.TupleDefinition)
                    {
                        listWrapper.Add(((ValueDefinition)aTupleElement.Value).Value.ConvertToIComparable(myRequestedType));
                    }

                    result.RemoveElementsFromCollection(attributeRemoveList.AttributeIDChain.ContentString, listWrapper);

                    #endregion
                }
                else
                {
                    #region binaryExpression

                    Dictionary <String, EdgePredefinition> toBeRemovedEdges = new Dictionary <String, EdgePredefinition>();

                    foreach (var aTupleElement in ((TupleDefinition)attributeRemoveList.TupleDefinition))
                    {
                        if (aTupleElement.Value is BinaryExpressionDefinition)
                        {
                            #region BinaryExpressionDefinition

                            if (!vertexType.HasAttribute(attributeRemoveList.AttributeName))
                            {
                                throw new InvalidVertexAttributeException(String.Format("The vertex type {0} has no attribute named {1}.", vertexType.Name, attributeRemoveList.AttributeName));
                            }

                            IAttributeDefinition attribute = vertexType.GetAttributeDefinition(attributeRemoveList.AttributeName);

                            var targetVertexType = ((IOutgoingEdgeDefinition)attribute).TargetVertexType;

                            var vertexIDs = ProcessBinaryExpression(
                                (BinaryExpressionDefinition)aTupleElement.Value,
                                myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, targetVertexType).ToList();

                            if (vertexIDs.Count > 1)
                            {
                                throw new ReferenceAssignmentExpectedException(String.Format("It is not possible to create a single edge pointing to {0} vertices", vertexIDs.Count));
                            }

                            EdgePredefinition outValue = null;

                            if (toBeRemovedEdges.TryGetValue(attributeRemoveList.AttributeName, out outValue))
                            {
                                foreach (var aVertex in vertexIDs)
                                {
                                    outValue.AddEdge(new EdgePredefinition().AddVertexID(aVertex.VertexTypeID, aVertex.VertexID));
                                }
                            }
                            else
                            {
                                EdgePredefinition edge = new EdgePredefinition(attributeRemoveList.AttributeName);

                                foreach (var aVertex in vertexIDs)
                                {
                                    edge.AddEdge(new EdgePredefinition().AddVertexID(aVertex.VertexTypeID, aVertex.VertexID));
                                }

                                toBeRemovedEdges.Add(attributeRemoveList.AttributeName, edge);
                            }

                            #endregion
                        }
                        else
                        {
                            throw new NotImplementedQLException("");
                        }
                    }

                    foreach (var item in toBeRemovedEdges)
                    {
                        result.RemoveElementsFromCollection(item.Key, item.Value);
                    }

                    #endregion
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 35
0
        private SingleEdgeAddDefinition? CreateSingleEdgeAddDefinition(
            Int64 myTransaction,
            SecurityToken mySecurity,
            long date,
            long myAttributeID,
            EdgePredefinition edgeDef,
            IEdgeType myEdgeType,
            VertexInformation source,
            IOutgoingEdgeDefinition attrDef)
        {
            AddDefaultPropertiesToEdgePredefinition(ref edgeDef, attrDef, date);

            var vertexIDs = GetResultingVertexIDs(myTransaction,
                                                    mySecurity,
                                                    edgeDef,
                                                    attrDef.TargetVertexType);

            if (vertexIDs == null)
                return null;

            CheckTargetVertices(attrDef.TargetVertexType, vertexIDs);

            //adds the basic attributes like CreationDate, ModificationDate ... to the structured properties
            AddDefaultValues(ref edgeDef, myEdgeType);

            return new SingleEdgeAddDefinition(myAttributeID,
                                                myEdgeType.ID,
                                                source,
                                                vertexIDs.First(),
                                                edgeDef.Comment,
                                                date,
                                                date,
                                                ConvertStructuredProperties(edgeDef, myEdgeType),
                                                edgeDef.UnstructuredProperties);
        }
Esempio n. 36
0
        private void ProcessAttributeAssignOrUpdateSetRef(IVertexType vertexType,
                                                          GQLPluginManager myPluginManager,
                                                          IGraphDB myGraphDB,
                                                          SecurityToken mySecurityToken,
                                                          Int64 myTransactionToken,
                                                          AttributeAssignOrUpdateSetRef attributeAssignOrUpdateSetRef,
                                                          ref RequestUpdate result)
        {
            #region SetRefNode

            var edgeDefinition = new EdgePredefinition(attributeAssignOrUpdateSetRef.AttributeIDChain.ContentString);

            if (attributeAssignOrUpdateSetRef.SetRefDefinition.IsREFUUID)
            {
                #region direct vertex ids

                foreach (var aTupleElement in attributeAssignOrUpdateSetRef.SetRefDefinition.TupleDefinition)
                {
                    if (aTupleElement.Value is ValueDefinition)
                    {
                        #region ValueDefinition

                        foreach (var aProperty in aTupleElement.Parameters)
                        {
                            edgeDefinition.AddUnknownProperty(aProperty.Key, aProperty.Value);
                        }

                        edgeDefinition.AddVertexID(
                            attributeAssignOrUpdateSetRef.SetRefDefinition.ReferencedVertexType,
                            Convert.ToInt64(((ValueDefinition)aTupleElement.Value).Value));

                        #endregion
                    }
                    else
                    {
                        throw new NotImplementedQLException("TODO");
                    }
                }

                result.UpdateEdge(edgeDefinition);

                #endregion
            }
            else
            {
                #region expression

                if (!vertexType.HasAttribute(attributeAssignOrUpdateSetRef.AttributeIDChain.ContentString))
                {
                    throw new InvalidVertexAttributeException(String.Format("The vertex type {0} has no attribute named {1}.", vertexType.Name, attributeAssignOrUpdateSetRef.AttributeIDChain.ContentString));
                }
                IAttributeDefinition attribute = vertexType.GetAttributeDefinition(attributeAssignOrUpdateSetRef.AttributeIDChain.ContentString);

                foreach (var aTupleElement in attributeAssignOrUpdateSetRef.SetRefDefinition.TupleDefinition)
                {
                    if (aTupleElement.Value is BinaryExpressionDefinition)
                    {
                        #region BinaryExpressionDefinition

                        var targetVertexType = ((IOutgoingEdgeDefinition)attribute).TargetVertexType;

                        var vertexIDs = ProcessBinaryExpression(
                            (BinaryExpressionDefinition)aTupleElement.Value,
                            myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, targetVertexType).ToList();

                        if (vertexIDs.Count > 1)
                        {
                            throw new ReferenceAssignmentExpectedException(String.Format("It is not possible to create a single edge pointing to {0} vertices", vertexIDs.Count));
                        }

                        var inneredge = new EdgePredefinition();

                        foreach (var aStructuredProperty in aTupleElement.Parameters)
                        {
                            edgeDefinition.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value);
                        }

                        edgeDefinition.AddVertexID(vertexIDs.FirstOrDefault().VertexTypeID, vertexIDs.FirstOrDefault().VertexID);

                        #endregion
                    }
                    else
                    {
                        throw new NotImplementedQLException("");
                    }
                }

                #endregion

                result.UpdateEdge(edgeDefinition);

                return;
            }

            #endregion
        }
Esempio n. 37
0
        private IEnumerable<VertexInformation> GetResultingVertexIDs(Int64 myTransaction, SecurityToken mySecurity, EdgePredefinition myEdgeDef, IVertexType myTargetType = null)
        {
            if (myEdgeDef.VertexIDsByVertexTypeID != null || myEdgeDef.VertexIDsByVertexTypeName != null)
            {
                HashSet<VertexInformation> result = new HashSet<VertexInformation>();
                if (myEdgeDef.VertexIDsByVertexTypeID != null)
                {
                    foreach (var kvP in myEdgeDef.VertexIDsByVertexTypeID)
                    {
                        foreach (var vertex in kvP.Value)
                        {
                            result.Add(new VertexInformation(kvP.Key, vertex));
                        }

                    }
                }
                if (myEdgeDef.VertexIDsByVertexTypeName != null)
                {
                    foreach (var kvP in myEdgeDef.VertexIDsByVertexTypeName)
                    {
                        var vertexType = _vertexTypeManager.ExecuteManager.GetType(kvP.Key, myTransaction, mySecurity);
                        foreach (var vertex in kvP.Value)
                        {
                            result.Add(new VertexInformation(vertexType.ID, vertex));
                        }

                    }
                }
                return result;
            }
            return null;
        }
Esempio n. 38
0
        /// <summary>
        /// Reads an edge information from the GraphML File and inserts
        /// the edge in the GraphDB by altering the existing source vertex.
        /// 
        /// Currently only the "weight" attribute will be considered and
        /// has to be annotated correctly (see class documentation).
        /// </summary>
        /// <param name='myReader'>
        /// XmlReader
        /// </param>
        private void ReadEdge(XmlReader myReader)
        {
            #region read edge data

            var sourceID = ReadVertexID(myReader, GraphMLTokens.SOURCE);
            var targetID = ReadVertexID(myReader, GraphMLTokens.TARGET);

            if(!_VertexIDMapper.ContainsKey(sourceID) || !_VertexIDMapper.ContainsKey(targetID))
            {
                throw new InvalidDataException(String.Format(
                    "Source or Target vertexID for edge ({0},{1}) doesn't exist",
                    sourceID,
                    targetID));
            }

            // get the weight
            var edgeWeight = ReadEdgeWeight(myReader);

            #endregion

            #region create edge (update vertex)

            var hyperEdge = new EdgePredefinition(_EdgeTypeName);
            hyperEdge.AddEdge(new EdgePredefinition()
                .AddVertexID(_VertexTypeName, _VertexIDMapper[targetID])
                .AddUnknownProperty(
                    GraphMLTokens.EDGE_WEIGHT,
                    Convert.ChangeType(edgeWeight, typeof(String), CultureInfo.GetCultureInfo("en-us"))
                ));

            var requestUpdate = new RequestUpdate(new RequestGetVertices(_VertexTypeName, new List<long>() { _VertexIDMapper[sourceID] }));
            requestUpdate.AddElementsToCollection(_EdgeTypeName, hyperEdge);

            // process the update
            _GraphDB.Update<IEnumerable<IVertex>>(
                _SecurityToken,
                _TransactionToken,
                requestUpdate,
                (stats, v) => v
                );

            _EdgeCount++;

            #endregion
        }