internal ServiceVertexTypePredefinition(VertexTypePredefinition myVertexTypePredefinition)
        {
            this.VertexTypeName      = myVertexTypePredefinition.TypeName;
            this.SuperVertexTypeName = myVertexTypePredefinition.SuperTypeName;
            this.IsSealed            = myVertexTypePredefinition.IsSealed;
            this.IsAbstract          = myVertexTypePredefinition.IsAbstract;
            this.Comment             = myVertexTypePredefinition.Comment;

            this.Uniques = (myVertexTypePredefinition.Uniques == null)
                ? null : myVertexTypePredefinition.Uniques.Select(x => new ServiceUniquePredefinition(x)).ToArray();

            this.Indices = (myVertexTypePredefinition.Indices == null)
                ? null : myVertexTypePredefinition.Indices.Select(x => new ServiceIndexPredefinition(x)).ToArray();

            this.Properties = (myVertexTypePredefinition.Properties == null)
                ? null : myVertexTypePredefinition.Properties.Select(x => new ServicePropertyPredefinition(x)).ToArray();

            this.BinaryProperties = (myVertexTypePredefinition.BinaryProperties == null)
                ? null : myVertexTypePredefinition.BinaryProperties.Select(x => new ServiceBinaryPropertyPredefinition(x)).ToArray();

            this.OutgoingEdges = (myVertexTypePredefinition.OutgoingEdges == null)
                ? null : myVertexTypePredefinition.OutgoingEdges.Select(x => new ServiceOutgoingEdgePredefinition(x)).ToArray();

            this.IncomingEdges = (myVertexTypePredefinition.IncomingEdges == null)
                ? null : myVertexTypePredefinition.IncomingEdges.Select(x => new ServiceIncomingEdgePredefinition(x)).ToArray();
        }
 /// <summary>
 /// Creates a new instance of TargetVertexTypeNotFoundException.
 /// </summary>
 /// <param name="myPredefinition">
 /// The Predefinition that contains the edges.
 /// </param>
 /// <param name="myTargetVertexTypeName">
 /// The vertex type name, that was not found.
 /// </param>
 /// <param name="myEdges">
 /// The list of edges that causes the exception.
 /// </param>
 /// <param name="innerException">The exception that is the cause of the current exception, this parameter can be NULL.</param>
 public TargetVertexTypeNotFoundException(VertexTypePredefinition myPredefinition, string myTargetVertexTypeName, IEnumerable <String> myEdges,
                                          Exception innerException = null) : base(innerException)
 {
     this.Predefinition        = myPredefinition;
     this.TargetVertexTypeName = myTargetVertexTypeName;
     this.Edges = myEdges;
     _msg       = string.Format("The outgoing edges ({0}) on vertex type {1} does point to a not existing target type {2}.", String.Join(",", myEdges), myPredefinition.TypeName, myTargetVertexTypeName);
 }
Пример #3
0
 /// <summary>
 /// Checks the uniqueness of property names on a vertex type predefinition without asking the FS.
 /// </summary>
 /// <param name="myVertexTypeDefinition">The vertex type predefinition to be checked.</param>
 /// <param name="myUniqueNameSet">A set of attribute names defined on this vertex type predefinition.</param>
 private static void CheckBinaryPropertiesUniqueName(VertexTypePredefinition myVertexTypeDefinition,
                                                     ISet <string> myUniqueNameSet)
 {
     if (myVertexTypeDefinition.BinaryProperties != null)
     {
         foreach (var prop in myVertexTypeDefinition.BinaryProperties)
         {
             prop.CheckNull("Binary Property in vertex type predefinition " + myVertexTypeDefinition.TypeName);
             if (!myUniqueNameSet.Add(prop.AttributeName))
             {
                 throw new DuplicatedAttributeNameException(myVertexTypeDefinition, prop.AttributeName);
             }
         }
     }
 }
Пример #4
0
 /// <summary>
 /// Checks the uniqueness of incoming edge names on a vertex type predefinition without asking the FS.
 /// </summary>
 /// <param name="myVertexTypeDefinition">The vertex type predefinition to be checked.</param>
 /// <param name="myUniqueNameSet">A set of attribute names defined on this vertex type predefinition.</param>
 protected static void CheckIncomingEdgesUniqueName(VertexTypePredefinition myVertexTypeDefinition,
                                                    ISet <String> myUniqueNameSet)
 {
     if (myVertexTypeDefinition.IncomingEdges != null)
     {
         foreach (var edge in myVertexTypeDefinition.IncomingEdges)
         {
             edge.CheckNull("Incoming myEdge in vertex type predefinition " + myVertexTypeDefinition.TypeName);
             if (!myUniqueNameSet.Add(edge.AttributeName))
             {
                 throw new DuplicatedAttributeNameException(myVertexTypeDefinition, edge.AttributeName);
             }
         }
     }
 }
Пример #5
0
        /// <summary>
        /// Creates the vertexType based on the VertexTypeName.
        ///
        /// The vertexType contains one Outgoing Edge Defintion, the edge
        /// is weighted and can't contain any other attributes.
        /// </summary>
        private void CreateVertexType()
        {
            #region create vertex type

            var vertexTypePreDef = new VertexTypePredefinition(_VertexTypeName);
            var outEdgePreDef    = new OutgoingEdgePredefinition(_EdgeTypeName, vertexTypePreDef);

            #region create edge definition

            // weighted multi-edge
            outEdgePreDef.SetEdgeTypeAsWeighted();
            // set inner edge type to weighted
            outEdgePreDef.SetMultiplicityAsMultiEdge("Weighted");

            vertexTypePreDef.AddOutgoingEdge(outEdgePreDef);

            #endregion

            #region create id definition

            var idPreDefinition = new PropertyPredefinition(GraphMLTokens.VERTEX_ID_NAME, GraphMLTokens.VERTEX_ID_TYPE);

            idPreDefinition.SetDefaultValue(GraphMLTokens.VERTEX_ID_DEF_VAL);

            vertexTypePreDef.AddProperty(idPreDefinition);

            #endregion

            #region create vertex type

            var requestCreateVertexType = new RequestCreateVertexType(vertexTypePreDef);

            _GraphDB.CreateVertexType(_SecurityToken,
                                      _TransactionToken,
                                      requestCreateVertexType,
                                      (stats, vType) => vType);

            #endregion

            #endregion
        }
Пример #6
0
        /// <summary>
        /// Checks the uniqueness of property names on a vertex type predefinition without asking the FS.
        /// </summary>
        /// <param name="myVertexTypeDefinition">The vertex type predefinition to be checked.</param>
        /// <param name="myUniqueNameSet">A set of attribute names defined on this vertex type predefinition.</param>
        protected static void CheckPropertiesUniqueName(VertexTypePredefinition myVertexTypeDefinition, ISet<string> myUniqueNameSet)
        {
            if (myVertexTypeDefinition.Properties != null)
                foreach (var prop in myVertexTypeDefinition.Properties)
                {
                    prop.CheckNull("Property in vertex type predefinition " + myVertexTypeDefinition.VertexTypeName);
                    if (!myUniqueNameSet.Add(prop.AttributeName))
                        throw new DuplicatedAttributeNameException(myVertexTypeDefinition, prop.AttributeName);

                    CheckPropertyType(myVertexTypeDefinition, prop);
                }
        }
Пример #7
0
        /// <summary>
        /// Checks the uniqueness of property names on a vertex type predefinition without asking the FS.
        /// </summary>
        /// <param name="myVertexTypeDefinition">The vertex type predefinition to be checked.</param>
        /// <param name="myUniqueNameSet">A set of attribute names defined on this vertex type predefinition.</param>
        protected static void CheckOutgoingEdgesUniqueName(VertexTypePredefinition myVertexTypeDefinition, ISet<string> myUniqueNameSet)
        {
            if (myVertexTypeDefinition.OutgoingEdges != null)
                foreach (var edge in myVertexTypeDefinition.OutgoingEdges)
                {
                    edge.CheckNull("Outgoing myEdge in vertex type predefinition " + myVertexTypeDefinition.VertexTypeName);
                    if (!myUniqueNameSet.Add(edge.AttributeName))
                        throw new DuplicatedAttributeNameException(myVertexTypeDefinition, edge.AttributeName);

                    CheckEdgeType(myVertexTypeDefinition, edge);
                }
        }
Пример #8
0
 private static void CheckIndices(VertexTypePredefinition vertexTypeDefinition)
 {
     //TODO
 }
        public VertexTypePredefinition ToVertexTypePredefinition()
        {
            VertexTypePredefinition VertexTypePreDef = new VertexTypePredefinition(this.VertexTypeName);

            if (this.IsAbstract)
                VertexTypePreDef.MarkAsAbstract();
            if (this.IsSealed)
                VertexTypePreDef.MarkAsSealed();

            VertexTypePreDef.SetComment(this.Comment);
            VertexTypePreDef.SetSuperTypeName(this.SuperVertexTypeName);

            if (this.Properties != null)
            {
                foreach (var Property in this.Properties)
                {
                    VertexTypePreDef.AddProperty(Property.ToPropertyPredefinition());
                }
            }

            if (this.BinaryProperties != null)
            {
                foreach (var BinaryProperty in this.BinaryProperties)
                {
                    VertexTypePreDef.AddBinaryProperty(BinaryProperty.ToBinaryPropertyPredefinition());
                }
            }

            if (this.Uniques != null)
            {
                foreach (var Unique in this.Uniques)
                {
                    VertexTypePreDef.AddUnique(Unique.ToUniquePredefinition());
                }
            }

            if (this.IncomingEdges != null)
            {
                foreach (var IncomingEdge in this.IncomingEdges)
                {
                    VertexTypePreDef.AddIncomingEdge(IncomingEdge.ToIncomingEdgePredefinition());
                }
            }

            if (this.OutgoingEdges != null)
            {
                foreach (var OutgoingEdge in this.OutgoingEdges)
                {
                    VertexTypePreDef.AddOutgoingEdge(OutgoingEdge.ToOutgoingEdgePredefinition());
                }
            }

            if (this.Indices != null)
            {
                foreach (var Index in this.Indices)
                {
                    VertexTypePreDef.AddIndex(Index.ToIndexPredefinition());
                }
            }
            return VertexTypePreDef;
        }
Пример #10
0
        /// <summary>
        /// Checks if outgoing edges have a valid target.
        /// </summary>
        /// <param name="myVertexTypePredefinition">The vertex type definition of that the outgoing edges will be checked,</param>
        /// <param name="myDefsByName">The vertex type predefinitions indexed by their name that are alse defined in this CanAdd operation.<remarks><c>NULL</c> is not allowed, but not checked.</remarks></param>
        /// <param name="myTransaction">A transaction token for this operation.</param>
        /// <param name="mySecurity">A security token for this operation.</param>
        private void CanAddCheckOutgoingEdgeTargets(VertexTypePredefinition myVertexTypePredefinition, IDictionary<string, VertexTypePredefinition> myDefsByName, TransactionToken myTransaction, SecurityToken mySecurity)
        {
            if (myVertexTypePredefinition.OutgoingEdges == null)
                return;

            var grouped = myVertexTypePredefinition.OutgoingEdges.GroupBy(x => x.AttributeType);
            foreach (var group in grouped)
            {
                if (myDefsByName.ContainsKey(group.Key))
                    continue;

                var vertex = Get(group.Key, myTransaction, mySecurity);
                if (vertex == null)
                    throw new TargetVertexTypeNotFoundException(myVertexTypePredefinition, group.Key,
                                                                group.Select(x => x.AttributeName));
            }
        }
Пример #11
0
        /// <summary>
        /// Checks the uniqueness of attribute names on a vertex type predefinition without asking the FS.
        /// </summary>
        /// <param name="myVertexTypeDefinition">The vertex type predefinition to be checked.</param>
        private static void CheckAttributes(VertexTypePredefinition vertexTypeDefinition)
        {
            var uniqueNameSet = new HashSet<string>();

            CheckIncomingEdgesUniqueName(vertexTypeDefinition, uniqueNameSet);
            CheckOutgoingEdgesUniqueName(vertexTypeDefinition, uniqueNameSet);
            CheckPropertiesUniqueName(vertexTypeDefinition, uniqueNameSet);
            CheckBinaryPropertiesUniqueName(vertexTypeDefinition, uniqueNameSet);
        }
Пример #12
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);
        }
Пример #13
0
 /// <summary>
 /// Creates a new request that creates a new vertex type inside the Graphdb
 /// </summary>
 /// <param name="myVertexTypeDefinition">Describes the vertex that is going to be created</param>
 public RequestCreateVertexType(VertexTypePredefinition myVertexTypeDefinition)
 {
     VertexTypeDefinition = myVertexTypeDefinition;
 }
Пример #14
0
        private static void ConvertUnknownAttributes(VertexTypePredefinition myVertexTypeDefinition)
        {
            if (myVertexTypeDefinition.UnknownAttributes == null)
                return;

            var toBeConverted = myVertexTypeDefinition.UnknownAttributes.ToArray();
            foreach (var unknown in toBeConverted)
            {
                if (BinaryPropertyPredefinition.TypeName.Equals(unknown.AttributeType))
                {
                    var prop = ConvertUnknownToBinaryProperty(unknown);

                    myVertexTypeDefinition.AddBinaryProperty(prop);
                }
                else if (IsBaseType(unknown.AttributeType))
                {
                    var prop = ConvertUnknownToProperty(unknown);

                    myVertexTypeDefinition.AddProperty(prop);
                }
                else if (unknown.AttributeType.Contains(IncomingEdgePredefinition.TypeSeparator))
                {
                    var prop = ConvertUnknownToIncomingEdge(unknown);
                    myVertexTypeDefinition.AddIncomingEdge(prop);
                }
                else
                {
                    var prop = ConvertUnknownToOutgoingEdge(unknown);
                    myVertexTypeDefinition.AddOutgoingEdge(prop);
                }
            }
            myVertexTypeDefinition.ResetUnknown();
        }
Пример #15
0
 private static void ConvertPropertyUniques(VertexTypePredefinition vertexTypeDefinition)
 {
     if (vertexTypeDefinition.Properties != null)
         foreach (var uniqueProp in vertexTypeDefinition.Properties.Where(_ => _.IsUnique))
         {
             vertexTypeDefinition.AddUnique(new UniquePredefinition(uniqueProp.AttributeName));
         }
 }
Пример #16
0
 /// <summary>
 /// Checks whether the vertex type property on an vertex type definition contains anything.
 /// </summary>
 /// <param name="myVertexTypeDefinition">The vertex type predefinition to be checked.</param>
 private static void CheckVertexTypeName(VertexTypePredefinition myVertexTypeDefinition)
 {
     if (string.IsNullOrWhiteSpace(myVertexTypeDefinition.VertexTypeName))
     {
         throw new EmptyVertexTypeNameException();
     }
 }
Пример #17
0
 private static void CheckUniques(VertexTypePredefinition vertexTypeDefinition)
 {
 }
Пример #18
0
 /// <summary>
 /// Checks whether a vertex type predefinition is not sealed and abstract.
 /// </summary>
 /// <param name="myVertexTypePredefinition">The vertex type predefinition to be checked.</param>
 private static void CheckSealedAndAbstract(VertexTypePredefinition myVertexTypePredefinition)
 {
     if (myVertexTypePredefinition.IsSealed && myVertexTypePredefinition.IsAbstract)
     {
         throw new UselessVertexTypeException(myVertexTypePredefinition);
     }
 }
Пример #19
0
 /// <summary>
 /// Checks whether a vertex type predefinition is not derived from a base vertex type.
 /// </summary>
 /// <param name="myVertexTypeDefinition"></param>
 private static void CheckParentTypeAreNoBaseTypes(VertexTypePredefinition myVertexTypeDefinition)
 {
     if (!CanBeParentType(myVertexTypeDefinition.SuperVertexTypeName))
     {
         throw new InvalidBaseVertexTypeException(myVertexTypeDefinition.VertexTypeName);
     }
 }
Пример #20
0
        /// <summary>
        /// Checks if a given property definition has a valid type.
        /// </summary>
        /// <param name="myVertexTypeDefinition">The vertex type predefinition that defines the property.</param>
        /// <param name="myProperty">The property to be checked.</param>
        protected static void CheckPropertyType(VertexTypePredefinition myVertexTypeDefinition, PropertyPredefinition myProperty)
        {
            if (String.IsNullOrWhiteSpace(myProperty.AttributeType))
            {
                throw new EmptyPropertyTypeException(myVertexTypeDefinition, myProperty.AttributeName);
            }

            if (!IsBaseType(myProperty.AttributeType))
            {
                //it is not one of the base types
                //TODO: check if it is a user defined data type
                throw new UnknownPropertyTypeException(myVertexTypeDefinition, myProperty.AttributeType);
            }
        }
Пример #21
0
 /// <summary>
 /// Creates a new request that creates a new vertex type inside the Graphdb
 /// </summary>
 /// <param name="myVertexTypeDefinition">Describes the vertex that is going to be created</param>
 public RequestCreateVertexType(VertexTypePredefinition myVertexTypeDefinition)
 {
     VertexTypeDefinition = myVertexTypeDefinition;
 }
Пример #22
0
        /// <summary>
        /// Sets the type of this outgoing edge with a VertexTypePredefinition.
        /// </summary>
        /// <param name="myTargetVertexType">The target vertex type predefinition</param>
        /// <returns>The reference of the current object. (fluent interface).</returns>
        public OutgoingEdgePredefinition SetAttributeType(VertexTypePredefinition myTargetVertexType)
        {
            if (myTargetVertexType != null)
                AttributeType = myTargetVertexType.VertexTypeName;

            return this;
        }
Пример #23
0
 /// <summary>
 /// Creates an instance of OutgoingEdgeNotFoundException.
 /// </summary>
 /// <param name="myPredefinition">
 /// The predefinition, that contains the incoming edge.
 /// </param>
 /// <param name="myIncomingEdge">
 /// The incoming edge that causes the exception.
 /// </param>
 public OutgoingEdgeNotFoundException(VertexTypePredefinition myPredefinition, IncomingEdgePredefinition myIncomingEdge, Exception innerException = null) : base(innerException)
 {
     Predefinition = myPredefinition;
     IncomingEdge  = myIncomingEdge;
     _msg          = string.Format("Vertextype {0} defines an incoming edge on a nonexisting outgoing edge ({1}).", myPredefinition.TypeName, myIncomingEdge.AttributeType);
 }
Пример #24
0
        /// <summary>
        /// Generates a single vertex type predefinition
        /// </summary>
        /// <param name="aDefinition">The definition that has been created by the gql</param>
        /// <returns>The corresponding vertex type predefinition</returns>
        private VertexTypePredefinition GenerateAVertexTypePredefinition(GraphDBTypeDefinition aDefinition)
        {
            var result = new VertexTypePredefinition(aDefinition.Name);

            #region extends

            if (aDefinition.ParentType != null && aDefinition.ParentType.Length > 0)
            {
                result.SetSuperTypeName(aDefinition.ParentType);
            }

            #endregion

            #region abstract

            if (aDefinition.IsAbstract)
            {
                result.MarkAsAbstract();
            }

            #endregion

            #region comment

            if (aDefinition.Comment != null && aDefinition.Comment.Length > 0)
            {
                result.SetComment(aDefinition.Comment);
            }

            #endregion

            #region attributes

            if (aDefinition.Attributes != null)
            {
                foreach (var aAttribute in aDefinition.Attributes)
                {
                    result.AddUnknownAttribute(GenerateUnknownAttribute(aAttribute));
                }
            }

            #endregion

            #region incoming edges

            if (aDefinition.BackwardEdgeNodes != null)
            {
                foreach (var aIncomingEdge in aDefinition.BackwardEdgeNodes)
                {
                    result.AddIncomingEdge(GenerateAIncomingEdge(aIncomingEdge));
                }
            }

            #endregion

            #region indices

            if (aDefinition.Indices != null)
            {
                foreach (var aIndex in aDefinition.Indices)
                {
                    result.AddIndex(GenerateIndex(aIndex, aDefinition.Name));
                }
            }

            #endregion

            return result;
        }
Пример #25
0
        /// <summary>
        /// Checks if an incoming myEdge has a coresponding outgoing myEdge.
        /// </summary>
        /// <param name="myVertexTypePredefinition">The vertex type definition of that the incoming edges will be checked,</param>
        /// <param name="myDefsByName">The vertex type predefinitions indexed by their name that are alse defined in this CanAdd operation.<remarks><c>NULL</c> is not allowed, but not checked.</remarks></param>
        /// <param name="myTransaction">A transaction token for this operation.</param>
        /// <param name="mySecurity">A security token for this operation.</param>
        private void CanAddCheckIncomingEdgeSources(VertexTypePredefinition myVertexTypePredefinition, IDictionary<string, VertexTypePredefinition> myDefsByName, TransactionToken myTransaction, SecurityToken mySecurity)
        {
            if (myVertexTypePredefinition.IncomingEdges == null)
                return;

            var grouped = myVertexTypePredefinition.IncomingEdges.GroupBy(x => GetTargetVertexTypeFromAttributeType(x.AttributeType));
            foreach (var group in grouped)
            {
                if (!myDefsByName.ContainsKey(group.Key))
                {
                    var vertex = Get(group.Key, myTransaction, mySecurity);
                    if (vertex == null)
                        throw new TargetVertexTypeNotFoundException(myVertexTypePredefinition, group.Key, group.Select(x => x.AttributeName));

                    var attributes = vertex.GetIncomingVertices((long)BaseTypes.OutgoingEdge, (long)AttributeDefinitions.AttributeDotDefiningType);
                    foreach (var edge in group)
                    {
                        if (!attributes.Any(outgoing => GetTargetVertexTypeFromAttributeType(edge.AttributeName).Equals(outgoing.GetPropertyAsString((long)AttributeDefinitions.AttributeDotName))))
                            throw new OutgoingEdgeNotFoundException(myVertexTypePredefinition, edge);
                    }
                }
                else
                {
                    var target = myDefsByName[group.Key];

                    foreach (var edge in group)
                    {
                        if (!target.OutgoingEdges.Any(outgoing => GetTargetEdgeNameFromAttributeType(edge.AttributeType).Equals(outgoing.AttributeName)))
                            throw new OutgoingEdgeNotFoundException(myVertexTypePredefinition, edge);
                    }

                }
            }
        }
Пример #26
0
        public void SocialNetwork(IGraphDS myGraphDS)
        {
            var transactionID = myGraphDS.BeginTransaction(null);

            #region ontology [API]

            var entityTypeDefinition = new VertexTypePredefinition(_vtEntity)
                        .AddProperty(new PropertyPredefinition(_pName, typeof(String).Name));

            var userTypeDefinition =
                new VertexTypePredefinition(_vtUser)
                        .SetSuperTypeName(_vtEntity)
                        .AddOutgoingEdge(new OutgoingEdgePredefinition(_pHasVisited, _vtCity).SetMultiplicityAsMultiEdge());

            var placeTypeDefinition =
                new VertexTypePredefinition(_vtPlace)
                        .SetSuperTypeName(_vtEntity);

            var countryTypeDefinition =
                new VertexTypePredefinition(_vtCountry)
                        .SetSuperTypeName(_vtPlace)
                        .AddIncomingEdge(new IncomingEdgePredefinition(_pCities, _vtCity, _pInCountry));

            var cityTypeDefinition =
                new VertexTypePredefinition(_vtCity)
                        .SetSuperTypeName(_vtPlace)
                        .AddOutgoingEdge(new OutgoingEdgePredefinition(_pInCountry, _vtCountry));

            Dictionary<String, IVertexType> vertexTypes = myGraphDS.CreateVertexTypes(null, transactionID,
                new RequestCreateVertexTypes(new List<VertexTypePredefinition>
                    { 	entityTypeDefinition,
                        userTypeDefinition,
                        placeTypeDefinition,
                        countryTypeDefinition,
                        cityTypeDefinition
                    }),
                (stats, types) => types.ToDictionary(vType => vType.Name, vType => vType));

            #endregion

            #region country [GQL]
            ExecuteQuery("insert into " + _vtCountry + " values ( " + _pName + " = 'UK' )", myGraphDS, transactionID);

            #endregion

            #region cities [GQL]

            var cityVertexIDs = new List<long>();
            foreach (var aCity in new List<String> { "London", "Manchester", "Edinburgh", "Cambridge", "Oxford" })
            {
                cityVertexIDs.Add(ExecuteQuery("insert into " + _vtCity + " values ( " + _pName + " = '" + aCity + "', " + _pInCountry + " = REF(" + _pName + " = 'UK'))", myGraphDS, transactionID).First().GetProperty<long>("VertexID"));
            }

            #endregion

            #region user [API]

            var userType = vertexTypes[_vtUser];
            var cityType = vertexTypes[_vtCity];

            Parallel.ForEach(
                Partitioner.Create(0, _countOfUsers, _countOfUsers / Environment.ProcessorCount),
                range =>
                {
                    for (long i = range.Item1; i < range.Item2; i++)
                    {
                        CreateANewUser(userType, i, myGraphDS, cityVertexIDs, cityType, transactionID);
                    }
                });

            #endregion

            myGraphDS.CommitTransaction(null, transactionID);
        }
Пример #27
0
 /// <summary>
 /// Checks if the name of the given vertex type predefinition is not used in FS before.
 /// </summary>
 /// <param name="myVertexTypePredefinition">The name of this vertex type definition will be checked.</param>
 /// <param name="myTransaction">A transaction token for this operation.</param>
 /// <param name="mySecurity">A security token for this operation.</param>
 private void CanAddCheckVertexNameUniqueWithFS(VertexTypePredefinition myVertexTypePredefinition, TransactionToken myTransaction, SecurityToken mySecurity)
 {
     if (Get(myVertexTypePredefinition.VertexTypeName, myTransaction, mySecurity) != null)
         throw new DuplicatedVertexTypeNameException(myVertexTypePredefinition.VertexTypeName);
 }
        public VertexTypePredefinition ToVertexTypePredefinition()
        {
            VertexTypePredefinition VertexTypePreDef = new VertexTypePredefinition(this.VertexTypeName);

            if (this.IsAbstract)
            {
                VertexTypePreDef.MarkAsAbstract();
            }
            if (this.IsSealed)
            {
                VertexTypePreDef.MarkAsSealed();
            }

            VertexTypePreDef.SetComment(this.Comment);
            VertexTypePreDef.SetSuperTypeName(this.SuperVertexTypeName);

            if (this.Properties != null)
            {
                foreach (var Property in this.Properties)
                {
                    VertexTypePreDef.AddProperty(Property.ToPropertyPredefinition());
                }
            }

            if (this.BinaryProperties != null)
            {
                foreach (var BinaryProperty in this.BinaryProperties)
                {
                    VertexTypePreDef.AddBinaryProperty(BinaryProperty.ToBinaryPropertyPredefinition());
                }
            }

            if (this.Uniques != null)
            {
                foreach (var Unique in this.Uniques)
                {
                    VertexTypePreDef.AddUnique(Unique.ToUniquePredefinition());
                }
            }

            if (this.IncomingEdges != null)
            {
                foreach (var IncomingEdge in this.IncomingEdges)
                {
                    VertexTypePreDef.AddIncomingEdge(IncomingEdge.ToIncomingEdgePredefinition());
                }
            }

            if (this.OutgoingEdges != null)
            {
                foreach (var OutgoingEdge in this.OutgoingEdges)
                {
                    VertexTypePreDef.AddOutgoingEdge(OutgoingEdge.ToOutgoingEdgePredefinition());
                }
            }

            if (this.Indices != null)
            {
                foreach (var Index in this.Indices)
                {
                    VertexTypePreDef.AddIndex(Index.ToIndexPredefinition());
                }
            }
            return(VertexTypePreDef);
        }
Пример #29
0
        /// <summary>
        /// Describes how to define a type with user defined properties and indices and create some instances by using GraphDB requests.
        /// </summary>
        private void GraphDBRequests()
        {
            #region define type "Tag"

            //create a VertexTypePredefinition
            var Tag_VertexTypePredefinition = new VertexTypePredefinition("Tag");

            //create property
            var PropertyName = new PropertyPredefinition("Name", "String")
                               .SetComment("This is a property on type 'Tag' named 'Name' and is of type 'String'");

            //add property
            Tag_VertexTypePredefinition.AddProperty(PropertyName);

            //create outgoing edge to "Website"
            var OutgoingEdgesTaggedWebsites = new OutgoingEdgePredefinition("TaggedWebsites", "Website")
                                              .SetMultiplicityAsMultiEdge()
                                              .SetComment(@"This is an outgoing edge on type 'Tag' wich points to the type 'Website' (the AttributeType) 
                                                                            and is defined as 'MultiEdge', which means that this edge can contain multiple single edges");

            //add outgoing edge
            Tag_VertexTypePredefinition.AddOutgoingEdge(OutgoingEdgesTaggedWebsites);

            #endregion

            #region define type "Website"

            //create a VertexTypePredefinition
            var Website_VertexTypePredefinition = new VertexTypePredefinition("Website");

            //create properties
            PropertyName = new PropertyPredefinition("Name", "String")
                           .SetComment("This is a property on type 'Website' named 'Name' and is of type 'String'");

            var PropertyUrl = new PropertyPredefinition("URL", "String")
                              .SetAsMandatory();

            //add properties
            Website_VertexTypePredefinition.AddProperty(PropertyName);
            Website_VertexTypePredefinition.AddProperty(PropertyUrl);

            #region create an index on type "Website" on property "Name"
            //there are three ways to set an index on property "Name"
            //Beware: Use just one of them!

            //1. create an index definition and specifie the property- and type name
            var MyIndex = new IndexPredefinition("MyIndex").SetIndexType("SonesIndex").AddProperty("Name").SetVertexType("Website");
            //add index
            Website_VertexTypePredefinition.AddIndex((IndexPredefinition)MyIndex);

            //2. on creating the property definition of property "Name" call the SetAsIndexed() method, the GraphDB will create the index
            //PropertyName = new PropertyPredefinition("Name")
            //                           .SetAttributeType("String")
            //                           .SetComment("This is a property on type 'Website' with name 'Name' and is of type 'String'")
            //                           .SetAsIndexed();

            //3. make a create index request, like creating a type
            //BEWARE: This statement must be execute AFTER the type "Website" is created.
            //var MyIndex = GraphDSServer.CreateIndex<IIndexDefinition>(SecToken,
            //                                                          TransToken,
            //                                                          new RequestCreateIndex(
            //                                                          new IndexPredefinition("MyIndex")
            //                                                                   .SetIndexType("SonesIndex")
            //                                                                   .AddProperty("Name")
            //                                                                   .SetVertexType("Website")), (Statistics, Index) => Index);

            #endregion

            //add IncomingEdge "Tags", the related OutgoingEdge is "TaggedWebsites" on type "Tag"
            Website_VertexTypePredefinition.AddIncomingEdge(new IncomingEdgePredefinition("Tags",
                                                                                          "Tag",
                                                                                          "TaggedWebsites"));

            #endregion


            #region create types by sending requests

            //create the types "Tag" and "Website"
            var DBTypes = GraphDSServer.CreateVertexTypes <IEnumerable <IVertexType> >(SecToken,
                                                                                       TransationID,
                                                                                       new RequestCreateVertexTypes(
                                                                                           new List <VertexTypePredefinition> {
                Tag_VertexTypePredefinition,
                Website_VertexTypePredefinition
            }),
                                                                                       (Statistics, VertexTypes) => VertexTypes);

            /*
             * BEWARE: The following two operations won't work because the two types "Tag" and "Website" depending on each other,
             *          because one type has an incoming edge to the other and the other one has an incoming edge,
             *          so they cannot be created separate (by using create type),
             *          they have to be created at the same time (by using create types)
             *
             * //create the type "Website"
             * var Website = GraphDSServer.CreateVertexType<IVertexType>(SecToken,
             *                                                           TransToken,
             *                                                           new RequestCreateVertexType(Website_VertexTypePredefinition),
             *                                                           (Statistics, VertexType) => VertexType);
             *
             * //create the type "Tag"
             * var Tag = GraphDSServer.CreateVertexType<IVertexType>(SecToken,
             *                                                       TransToken,
             *                                                       new RequestCreateVertexType(Tag_VertexTypePredefinition),
             *                                                       (Statistics, VertexType) => VertexType);
             */

            var Tag = DBTypes.Where(type => type.Name == "Tag").FirstOrDefault();

            var Website = DBTypes.Where(type => type.Name == "Website").FirstOrDefault();

            #endregion

            #region insert some Websites by sending requests

            var cnn = GraphDSServer.Insert <IVertex>(SecToken, TransationID, new RequestInsertVertex("Website")
                                                     .AddStructuredProperty("Name", "CNN")
                                                     .AddStructuredProperty("URL", "http://cnn.com/"),
                                                     (Statistics, Result) => Result);

            var xkcd = GraphDSServer.Insert <IVertex>(SecToken, TransationID, new RequestInsertVertex("Website")
                                                      .AddStructuredProperty("Name", "xkcd")
                                                      .AddStructuredProperty("URL", "http://xkcd.com/"),
                                                      (Statistics, Result) => Result);

            var onion = GraphDSServer.Insert <IVertex>(SecToken, TransationID, new RequestInsertVertex("Website")
                                                       .AddStructuredProperty("Name", "onion")
                                                       .AddStructuredProperty("URL", "http://theonion.com/"),
                                                       (Statistics, Result) => Result);

            //adding an unknown property means the property isn't defined before
            var test = GraphDSServer.Insert <IVertex>(SecToken, TransationID, new RequestInsertVertex("Website")
                                                      .AddStructuredProperty("Name", "Test")
                                                      .AddStructuredProperty("URL", "")
                                                      .AddUnknownProperty("Unknown", "unknown property"),
                                                      (Statistics, Result) => Result);

            #endregion

            #region insert some Tags by sending requests

            //insert a "Tag" with an OutgoingEdge to a "Website" include that the GraphDB creates an IncomingEdge on the given Website instances
            //(because we created an IncomingEdge on type "Website") --> as a consequence we never have to set any IncomingEdge
            var good = GraphDSServer.Insert <IVertex>(SecToken, TransationID, new RequestInsertVertex("Tag")
                                                      .AddStructuredProperty("Name", "good")
                                                      .AddEdge(new EdgePredefinition("TaggedWebsites")
                                                               .AddVertexID(Website.ID, cnn.VertexID)
                                                               .AddVertexID(Website.ID, xkcd.VertexID)),
                                                      (Statistics, Result) => Result);

            var funny = GraphDSServer.Insert <IVertex>(SecToken, TransationID, new RequestInsertVertex("Tag")
                                                       .AddStructuredProperty("Name", "funny")
                                                       .AddEdge(new EdgePredefinition("TaggedWebsites")
                                                                .AddVertexID(Website.ID, xkcd.VertexID)
                                                                .AddVertexID(Website.ID, onion.VertexID)),
                                                       (Statistics, Result) => Result);

            #endregion

            #region how to get a type from the DB, properties of the type, instances of a specific type and read out property values

            //how to get a type from the DB
            var TagDBType = GraphDSServer.GetVertexType <IVertexType>(SecToken, TransationID, new RequestGetVertexType(Tag.ID), (Statistics, Type) => Type);

            //read informations from type
            var typeName = TagDBType.Name;
            //are there other types wich extend the type "Tag"
            var hasChildTypes = TagDBType.HasChildTypes;
            //get the definition of the property "Name"
            var propName = TagDBType.GetPropertyDefinition("Name");

            //how to get all instances of a type from the DB
            var TagInstances = GraphDSServer.GetVertices(SecToken, TransationID, new RequestGetVertices(TagDBType.ID), (Statistics, Vertices) => Vertices);

            foreach (var item in TagInstances)
            {
                //to get the value of a property of an instance, you need the property ID
                //(that's why we fetched the type from DB an read out the property definition of property "Name")
                var name = item.GetPropertyAsString(propName.ID);
            }

            #endregion
        }
Пример #30
0
 /// <summary>
 /// Check for the correct default value.
 /// </summary>
 /// <param name="vertexTypeDefinition">The vertex type predefinition to be checked.</param>
 private static void CheckDefaultValue(VertexTypePredefinition vertexTypeDefinition)
 {
     if (vertexTypeDefinition.Properties != null)
     {
         foreach (var item in vertexTypeDefinition.Properties.Where(_ => _.DefaultValue != null))
         {
             try
             {
                 var baseType = BaseGraphStorageManager.GetBaseType(item.AttributeType);
                 item.DefaultValue.ConvertToIComparable(baseType);
             }
             catch (Exception e)
             {
                 throw new InvalidTypeException(item.DefaultValue.GetType().Name, item.AttributeType);
             }
         }
     }
 }
Пример #31
0
        /// <summary>
        /// Creates the vertexType based on the VertexTypeName.
        /// 
        /// The vertexType contains one Outgoing Edge Defintion, the edge
        /// is weighted and can't contain any other attributes.
        /// </summary>
        private void CreateVertexType()
        {
            #region create vertex type

            var vertexTypePreDef 	= new VertexTypePredefinition(_VertexTypeName);
            var outEdgePreDef 		= new OutgoingEdgePredefinition(_EdgeTypeName, vertexTypePreDef);

            #region create edge definition

            // weighted multi-edge
            outEdgePreDef.SetEdgeTypeAsWeighted();
            // set inner edge type to weighted
            outEdgePreDef.SetMultiplicityAsMultiEdge("Weighted");

            vertexTypePreDef.AddOutgoingEdge(outEdgePreDef);

            #endregion

            #region create id definition

            var idPreDefinition = new PropertyPredefinition(GraphMLTokens.VERTEX_ID_NAME , GraphMLTokens.VERTEX_ID_TYPE);

            idPreDefinition.SetDefaultValue(GraphMLTokens.VERTEX_ID_DEF_VAL);

            vertexTypePreDef.AddProperty(idPreDefinition);

            #endregion

            #region create vertex type

            var requestCreateVertexType = new RequestCreateVertexType(vertexTypePreDef);

            _GraphDB.CreateVertexType(_SecurityToken,
                                     _TransactionToken,
                                     requestCreateVertexType,
                                     (stats, vType) => vType);

            #endregion

            #endregion
        }
Пример #32
0
 /// <summary>
 /// Checks whether the edge type property on an outgoing edge definition contains anything.
 /// </summary>
 /// <param name="myVertexTypeDefinition">The vertex type predefinition that defines the outgoing edge.</param>
 /// <param name="myEdge">The outgoing edge to be checked.</param>
 protected static void CheckEdgeType(VertexTypePredefinition myVertexTypeDefinition, OutgoingEdgePredefinition myEdge)
 {
     if (string.IsNullOrWhiteSpace(myEdge.EdgeType))
     {
         throw new EmptyEdgeTypeException(myVertexTypeDefinition, myEdge.AttributeName);
     }
 }
Пример #33
0
        private void GraphDBRequests()
        {
            Console.WriteLine("performing DB requests...");
            #region define type "Tag"

            //create a VertexTypePredefinition
            var Tag_VertexTypePredefinition = new VertexTypePredefinition("Tag");

            //create property
            var PropertyName = new PropertyPredefinition("Name", "String")
                                           .SetComment("This is a property on type 'Tag' named 'Name' and is of type 'String'");

            //add property
            Tag_VertexTypePredefinition.AddProperty(PropertyName);

            //create outgoing edge to "Website"
            var OutgoingEdgesTaggedWebsites = new OutgoingEdgePredefinition("TaggedWebsites", "Website")
                                                          .SetMultiplicityAsMultiEdge()
                                                          .SetComment(@"This is an outgoing edge on type 'Tag' wich points to the type 'Website' (the AttributeType) 
                                                                            and is defined as 'MultiEdge', which means that this edge can contain multiple single edges");

            //add outgoing edge
            Tag_VertexTypePredefinition.AddOutgoingEdge(OutgoingEdgesTaggedWebsites);

            #endregion

            #region define type "Website"

            //create a VertexTypePredefinition
            var Website_VertexTypePredefinition = new VertexTypePredefinition("Website");

            //create properties
            PropertyName = new PropertyPredefinition("Name", "String")
                                       .SetComment("This is a property on type 'Website' named 'Name' and is of type 'String'");

            var PropertyUrl = new PropertyPredefinition("URL", "String")
                                         .SetAsMandatory();

            //add properties
            Website_VertexTypePredefinition.AddProperty(PropertyName);
            Website_VertexTypePredefinition.AddProperty(PropertyUrl);

            #region create an index on type "Website" on property "Name"
            //there are three ways to set an index on property "Name" 
            //Beware: Use just one of them!

            //1. create an index definition and specifie the property- and type name
            var MyIndex = new IndexPredefinition("MyIndex").SetIndexType("SonesIndex").AddProperty("Name").SetVertexType("Website");
            //add index
            Website_VertexTypePredefinition.AddIndex((IndexPredefinition)MyIndex);

            //2. on creating the property definition of property "Name" call the SetAsIndexed() method, the GraphDB will create the index
            //PropertyName = new PropertyPredefinition("Name")
            //                           .SetAttributeType("String")
            //                           .SetComment("This is a property on type 'Website' with name 'Name' and is of type 'String'")
            //                           .SetAsIndexed();

            //3. make a create index request, like creating a type
            //BEWARE: This statement must be execute AFTER the type "Website" is created.
            //var MyIndex = GraphDSServer.CreateIndex<IIndexDefinition>(SecToken,
            //                                                          TransToken,
            //                                                          new RequestCreateIndex(
            //                                                          new IndexPredefinition("MyIndex")
            //                                                                   .SetIndexType("SonesIndex")
            //                                                                   .AddProperty("Name")
            //                                                                   .SetVertexType("Website")), (Statistics, Index) => Index);

            #endregion

            //add IncomingEdge "Tags", the related OutgoingEdge is "TaggedWebsites" on type "Tag"
            Website_VertexTypePredefinition.AddIncomingEdge(new IncomingEdgePredefinition("Tags",
                                                                                            "Tag",
                                                                                            "TaggedWebsites"));

            #endregion


            #region create types by sending requests

            //create the types "Tag" and "Website"
            var DBTypes = GraphDSClient.CreateVertexTypes<IEnumerable<IVertexType>>(SecToken,
                                                                                    TransToken,
                                                                                    new RequestCreateVertexTypes(
                                                                                        new List<VertexTypePredefinition> { Tag_VertexTypePredefinition, 
                                                                                                                            Website_VertexTypePredefinition }),
                                                                                    (Statistics, VertexTypes) => VertexTypes);

            /* 
             * BEWARE: The following two operations won't work because the two types "Tag" and "Website" depending on each other,
             *          because one type has an incoming edge to the other and the other one has an incoming edge, 
             *          so they cannot be created separate (by using create type),
             *          they have to be created at the same time (by using create types)
             *          
             * //create the type "Website"
             * var Website = GraphDSServer.CreateVertexType<IVertexType>(SecToken, 
             *                                                           TransToken, 
             *                                                           new RequestCreateVertexType(Website_VertexTypePredefinition), 
             *                                                           (Statistics, VertexType) => VertexType);
             * 
             * //create the type "Tag"
             * var Tag = GraphDSServer.CreateVertexType<IVertexType>(SecToken, 
             *                                                       TransToken, 
             *                                                       new RequestCreateVertexType(Tag_VertexTypePredefinition), 
             *                                                       (Statistics, VertexType) => VertexType);
             */

            var Tag = DBTypes.Where(type => type.Name == "Tag").FirstOrDefault();
            if (Tag != null)
                Console.WriteLine("Vertex Type 'Tag' created");
            var Website = DBTypes.Where(type => type.Name == "Website").FirstOrDefault();
            if(Website != null)
                Console.WriteLine("Vertex Type 'Website' created");

            #endregion

            #region insert some Websites by sending requests

            var sones = GraphDSClient.Insert<IVertex>(SecToken, TransToken, new RequestInsertVertex("Website")
                                                                                    .AddStructuredProperty("Name", "Sones")
                                                                                    .AddStructuredProperty("URL", "http://sones.com/"),
                                                                                    (Statistics, Result) => Result);

            var cnn = GraphDSClient.Insert<IVertex>(SecToken, TransToken, new RequestInsertVertex("Website")
                                                                                    .AddStructuredProperty("Name", "CNN")
                                                                                    .AddStructuredProperty("URL", "http://cnn.com/"),
                                                                                    (Statistics, Result) => Result);

            var xkcd = GraphDSClient.Insert<IVertex>(SecToken, TransToken, new RequestInsertVertex("Website")
                                                                                    .AddStructuredProperty("Name", "xkcd")
                                                                                    .AddStructuredProperty("URL", "http://xkcd.com/"),
                                                                                    (Statistics, Result) => Result);

            var onion = GraphDSClient.Insert<IVertex>(SecToken, TransToken, new RequestInsertVertex("Website")
                                                                                    .AddStructuredProperty("Name", "onion")
                                                                                    .AddStructuredProperty("URL", "http://theonion.com/"),
                                                                                    (Statistics, Result) => Result);

            //adding an unknown property means the property isn't defined before
            var test = GraphDSClient.Insert<IVertex>(SecToken, TransToken, new RequestInsertVertex("Website")
                                                                                    .AddStructuredProperty("Name", "Test")
                                                                                    .AddStructuredProperty("URL", "")
                                                                                    .AddUnknownProperty("Unknown", "unknown property"),
                                                                                    (Statistics, Result) => Result);

            if (sones != null)
                Console.WriteLine("Website 'sones' successfully inserted");

            if (cnn != null)
                Console.WriteLine("Website 'cnn' successfully inserted");

            if (xkcd != null)
                Console.WriteLine("Website 'xkcd' successfully inserted");

            if (onion != null)
                Console.WriteLine("Website 'onion' successfully inserted");

            if (test != null)
                Console.WriteLine("Website 'test' successfully inserted");

            #endregion

            #region insert some Tags by sending requests

            //insert a "Tag" with an OutgoingEdge to a "Website" include that the GraphDB creates an IncomingEdge on the given Website instances
            //(because we created an IncomingEdge on type "Website") --> as a consequence we never have to set any IncomingEdge
            var good = GraphDSClient.Insert<IVertex>(SecToken, TransToken, new RequestInsertVertex("Tag")
                                                                                    .AddStructuredProperty("Name", "good")
                                                                                    .AddEdge(new EdgePredefinition("TaggedWebsites")
                                                                                        .AddVertexID(Website.ID, cnn.VertexID)
                                                                                        .AddVertexID(Website.ID, xkcd.VertexID)),
                                                                                    (Statistics, Result) => Result);

            var funny = GraphDSClient.Insert<IVertex>(SecToken, TransToken, new RequestInsertVertex("Tag")
                                                                                    .AddStructuredProperty("Name", "funny")
                                                                                    .AddEdge(new EdgePredefinition("TaggedWebsites")
                                                                                        .AddVertexID(Website.ID, xkcd.VertexID)
                                                                                        .AddVertexID(Website.ID, onion.VertexID)),
                                                                                    (Statistics, Result) => Result);

            if (good != null)
                Console.WriteLine("Tag 'good' successfully inserted");

            if (funny != null)
                Console.WriteLine("Tag 'funny' successfully inserted");

            #endregion

            #region how to get a type from the DB, properties of the type, instances of a specific type and read out property values

            //how to get a type from the DB
            var TagDBType = GraphDSClient.GetVertexType<IVertexType>(SecToken, TransToken, new RequestGetVertexType(Tag.Name), (Statistics, Type) => Type);

            //how to get a type from the DB
            var WebsiteDBType = GraphDSClient.GetVertexType<IVertexType>(SecToken, TransToken, new RequestGetVertexType(Website.Name), (Statistics, Type) => Type);

            //read informations from type
            var typeName = TagDBType.Name;
            //are there other types wich extend the type "Tag"
            var hasChildTypes = TagDBType.HasChildTypes;

            var hasPropName = TagDBType.HasProperty("Name");

            //get the definition of the property "Name"
            var propName = TagDBType.GetPropertyDefinition("Name");

            //how to get all instances of a type from the DB
            var TagInstances = GraphDSClient.GetVertices(SecToken, TransToken, new RequestGetVertices(TagDBType.Name), (Statistics, Vertices) => Vertices);

            foreach (var item in TagInstances)
            {
                //to get the value of a property of an instance, you need the property ID 
                //(that's why we fetched the type from DB an read out the property definition of property "Name")
                var name = item.GetPropertyAsString(propName.ID);
            }

            Console.WriteLine("API operations finished...");

            #endregion
        }
Пример #34
0
        /// <summary>
        /// Generates a single vertex type predefinition
        /// </summary>
        /// <param name="aDefinition">The definition that has been created by the gql</param>
        /// <returns>The corresponding vertex type predefinition</returns>
        private VertexTypePredefinition GenerateAVertexTypePredefinition(GraphDBTypeDefinition aDefinition)
        {
            var result = new VertexTypePredefinition(aDefinition.Name);

            #region extends

            if (aDefinition.ParentType != null && aDefinition.ParentType.Length > 0)
            {
                result.SetSuperTypeName(aDefinition.ParentType);
            }

            #endregion

            #region abstract

            if (aDefinition.IsAbstract)
            {
                result.MarkAsAbstract();
            }

            #endregion

            #region comment

            if (aDefinition.Comment != null && aDefinition.Comment.Length > 0)
            {
                result.SetComment(aDefinition.Comment);
            }

            #endregion

            #region attributes

            if (aDefinition.Attributes != null)
            {
                foreach (var aAttribute in aDefinition.Attributes)
                {
                    result.AddUnknownAttribute(GenerateUnknownAttribute(aAttribute));
                }
            }

            #endregion

            #region incoming edges

            if (aDefinition.BackwardEdgeNodes != null)
            {
                foreach (var aIncomingEdge in aDefinition.BackwardEdgeNodes)
                {
                    result.AddIncomingEdge(GenerateAIncomingEdge(aIncomingEdge));
                }
            }

            #endregion

            #region indices

            if (aDefinition.Indices != null)
            {
                foreach (var aIndex in aDefinition.Indices)
                {
                    result.AddIndex(GenerateIndex(aIndex, aDefinition.Name));
                }
            }

            #endregion

            return(result);
        }