Esempio n. 1
0
        public ServiceIndexDefinition CreateIndex(SecurityToken mySecurityToken, Int64 myTransactionToken, ServiceIndexPredefinition myVertexTypePreDef)
        {
            var Request  = ServiceRequestFactory.MakeRequestCreateIndex(myVertexTypePreDef);
            var Response = this.GraphDS.CreateIndex <IIndexDefinition>(mySecurityToken, myTransactionToken, Request,
                                                                       ServiceReturnConverter.ConverteOnlyIndexDefinition);

            return(new ServiceIndexDefinition(Response));
        }
Esempio n. 2
0
 public static RequestCreateIndex MakeRequestCreateIndex(ServiceIndexPredefinition myIndexPreDef)
 {
     return(new RequestCreateIndex(myIndexPreDef.ToIndexPredefinition()));
 }
        private void GenerateDBContent()
        {
            #region define type "Tag"

            //create a VertexTypePredefinition
            var Tag_VertexTypePredefinition = new ServiceVertexTypePredefinition();
            Tag_VertexTypePredefinition.VertexTypeName = "Tag";
            Tag_VertexTypePredefinition.Properties = new List<ServicePropertyPredefinition>();
            Tag_VertexTypePredefinition.OutgoingEdges = new List<ServiceOutgoingEdgePredefinition>();

            //create property
            var PropertyName = new ServicePropertyPredefinition();
            PropertyName.AttributeName = "Name";
            PropertyName.AttributeType = "String";
            PropertyName.Comment = "This is a property on type 'Tag' named 'Name' and is of type 'String'";

            //add property
            Tag_VertexTypePredefinition.Properties.Add(PropertyName);

            //create outgoing edge to "Website"
            var OutgoingEdgesTaggedWebsites = new ServiceOutgoingEdgePredefinition();
            OutgoingEdgesTaggedWebsites.AttributeName = "TaggedWebsites";
            OutgoingEdgesTaggedWebsites.AttributeType = "Website";
            OutgoingEdgesTaggedWebsites.Multiplicity = ServiceEdgeMultiplicity.MultiEdge;
            OutgoingEdgesTaggedWebsites.Comment = @"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.OutgoingEdges.Add(OutgoingEdgesTaggedWebsites);

            #endregion

            #region define type "Website"

            //create a VertexTypePredefinition
            var Website_VertexTypePredefinition = new ServiceVertexTypePredefinition();
            Website_VertexTypePredefinition.VertexTypeName = "Website";
            Website_VertexTypePredefinition.Properties = new List<ServicePropertyPredefinition>();
            Website_VertexTypePredefinition.Indices = new List<ServiceIndexPredefinition>();
            Website_VertexTypePredefinition.IncomingEdges = new List<ServiceIncomingEdgePredefinition>();

            //create properties
            PropertyName = new ServicePropertyPredefinition();
            PropertyName.AttributeName = "Name";
            PropertyName.AttributeType = "String";
            PropertyName.Comment = "This is a property on type 'Website' named 'Name' and is of type 'String'";

            var PropertyUrl = new ServicePropertyPredefinition();
            PropertyUrl.AttributeName = "URL";
            PropertyUrl.AttributeType = "String";

            //add properties
            Website_VertexTypePredefinition.Properties.Add(PropertyName);
            Website_VertexTypePredefinition.Properties.Add(PropertyUrl);

            #region create an index on type "Website" on property "Name"

            var MyIndex = new ServiceIndexPredefinition();
            MyIndex.Name = "MyIndex";
            MyIndex.IndexType = "SonesIndex";
            MyIndex.Properties = new List<string>();
            MyIndex.Properties.Add("Name");
            MyIndex.VertexTypeName = "Website";

            //add index
            Website_VertexTypePredefinition.Indices.Add(MyIndex);

            #endregion

            //add IncomingEdge "Tags", the related OutgoingEdge is "TaggedWebsites" on type "Tag"
            ServiceIncomingEdgePredefinition Incoming = new ServiceIncomingEdgePredefinition();
            Incoming.AttributeName = "Tags";
            Incoming.AttributeType = "Tag";
            Incoming.OutgoingEdgeName = "TaggedWebsites";

            Website_VertexTypePredefinition.IncomingEdges.Add(Incoming);
            #endregion

            #region create types by sending requests

            //create the types "Tag" and "Website"

            var DBTypes = _GraphDS_Service.CreateVertexTypes(SecToken, TransToken, new List<ServiceVertexTypePredefinition>(){Tag_VertexTypePredefinition,
                    Website_VertexTypePredefinition});
            Console.WriteLine("CreateVertexTypes ('Websites', 'Tag') successful executed!");

            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

            ServiceInsertPayload Insert = new ServiceInsertPayload();
            Insert.StructuredProperties = new List<StructuredProperty>();
            Insert.UnstructuredProperties = new List<UnstructuredProperty>();

            StructuredProperty Property = new StructuredProperty();
            Property.PropertyName = "Name";
            Property.PropertyValue = "CNN";
            Insert.StructuredProperties.Add(Property);
            Property = new StructuredProperty();
            Property.PropertyName = "URL";
            Property.PropertyValue = "http://cnn.com/";
            Insert.StructuredProperties.Add(Property);

            var cnn = _GraphDS_Service.Insert(SecToken, TransToken, "Website", Insert);
            Console.WriteLine("Insert into 'Websites' successful executed!");

            Insert = new ServiceInsertPayload();
            Insert.StructuredProperties = new List<StructuredProperty>();
            Insert.UnstructuredProperties = new List<UnstructuredProperty>();
            Property = new StructuredProperty();
            Property.PropertyName = "Name";
            Property.PropertyValue = "xkcd";
            Insert.StructuredProperties.Add(Property);
            Property = new StructuredProperty();
            Property.PropertyName = "URL";
            Property.PropertyValue = "http://xkcd.com/";
            Insert.StructuredProperties.Add(Property);

            var xkcd = _GraphDS_Service.Insert(SecToken, TransToken, "Website", Insert);
            Console.WriteLine("Insert into 'Websites' successful executed!");

            Insert = new ServiceInsertPayload();
            Insert.StructuredProperties = new List<StructuredProperty>();
            Insert.UnstructuredProperties = new List<UnstructuredProperty>();
            Property = new StructuredProperty();
            Property.PropertyName = "Name";
            Property.PropertyValue = "onion";
            Insert.StructuredProperties.Add(Property);
            Property = new StructuredProperty();
            Property.PropertyName = "URL";
            Property.PropertyValue = "http://theonion.com/";
            Insert.StructuredProperties.Add(Property);

            var onion = _GraphDS_Service.Insert(SecToken, TransToken, "Website", Insert);
            Console.WriteLine("Insert into 'Websites' successful executed!");

            Insert = new ServiceInsertPayload();
            Insert.StructuredProperties = new List<StructuredProperty>();
            Insert.UnstructuredProperties = new List<UnstructuredProperty>();
            Property = new StructuredProperty();
            Property.PropertyName = "Name";
            Property.PropertyValue = "Test";
            Insert.StructuredProperties.Add(Property);
            Property = new StructuredProperty();
            Property.PropertyName = "URL";
            Property.PropertyValue = "";
            Insert.StructuredProperties.Add(Property);
            UnstructuredProperty UnsProp = new UnstructuredProperty();
            UnsProp.PropertyName = "IsValide";
            UnsProp.PropertyValue = false;
            Insert.UnstructuredProperties.Add(UnsProp);

            //adding an unstructured property means the property isn't defined before
            var test = _GraphDS_Service.Insert(SecToken, TransToken, "Website", Insert);
            Console.WriteLine("Insert into 'Websites' successful executed!");

            #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

            Insert = new ServiceInsertPayload();
            Insert.StructuredProperties = new List<StructuredProperty>();
            Insert.Edges = new List<ServiceEdgePredefinition>();
            Insert.UnstructuredProperties = new List<UnstructuredProperty>();

            Property = new StructuredProperty();
            Property.PropertyName = "Name";
            Property.PropertyValue = "good";
            Insert.StructuredProperties.Add(Property);

            ServiceEdgePredefinition Edge = new ServiceEdgePredefinition();
            Edge.EdgeName = "TaggedWebsites";
            Edge.ContainedEdges = new List<ServiceEdgePredefinition>();

            ServiceEdgePredefinition InnerEdge = new ServiceEdgePredefinition();
            InnerEdge.VertexIDsByID = new List<Tuple<long, List<long>>>();
            var VertexIDs = new List<long>();
            VertexIDs.Add(cnn.VertexID);
            VertexIDs.Add(xkcd.VertexID);

            InnerEdge.VertexIDsByID.Add(new Tuple<long, List<long>>(Website.ID, VertexIDs));
            Edge.ContainedEdges.Add(InnerEdge);

            Insert.Edges.Add(Edge);

            var good = _GraphDS_Service.Insert(SecToken, TransToken, "Tag", Insert);
            Console.WriteLine("Insert into 'Tag' successful executed!");

            Insert = new ServiceInsertPayload();
            Insert.StructuredProperties = new List<StructuredProperty>();
            Insert.Edges = new List<ServiceEdgePredefinition>();
            Insert.UnstructuredProperties = new List<UnstructuredProperty>();

            Property = new StructuredProperty();
            Property.PropertyName = "Name";
            Property.PropertyValue = "funny";
            Insert.StructuredProperties.Add(Property);

            Edge = new ServiceEdgePredefinition();
            Edge.EdgeName = "TaggedWebsites";
            Edge.ContainedEdges = new List<ServiceEdgePredefinition>();

            InnerEdge = new ServiceEdgePredefinition();
            InnerEdge.VertexIDsByID = new List<Tuple<long, List<long>>>();
            VertexIDs = new List<long>();
            VertexIDs.Add(xkcd.VertexID);
            VertexIDs.Add(onion.VertexID);

            InnerEdge.VertexIDsByID.Add(new Tuple<long, List<long>>(Website.ID, VertexIDs));

            Edge.ContainedEdges.Add(InnerEdge);

            Insert.Edges.Add(Edge);

            var funny = _GraphDS_Service.Insert(SecToken, TransToken, "Tag", Insert);
            Console.WriteLine("Insert into 'Tag' successful executed!");

            #endregion
        }