示例#1
0
 public EdgeDefinition(object edge, GraphItemBase sourceVetex, GraphItemBase targetVertex, bool single = false)
 {
     EdgeEntity   = edge;
     SourceVertex = sourceVetex;
     TargetVertex = targetVertex;
     Single       = single;
 }
示例#2
0
 internal GraphItemChangedEventArgs(GraphItemBase gi, string text, bool add, bool inter)
 {
     this.gi    = gi;
     this.add   = add;
     this.inter = inter;
     this.txt   = text;
 }
示例#3
0
 internal void SilentRemove(GraphItemBase item, bool inter)
 {
     base.Remove(item);
     if (this.ItemsChanged != null)
     {
         this.ItemsChanged(this, new GraphItemChangedEventArgs(item, "", false, inter));
     }
 }
        private void AssertGraphEdgeValues(IDictionary <string, object> edge, GraphItemBase source, GraphItemBase dest)
        {
            Assert.AreEqual(source.PartitionKey, edge[PartitionKeyPropertyName], "partitionKey not matching");

            Assert.AreEqual(source.Id, edge["_vertexId"], "source vertex id not matching");
            Assert.AreEqual(source.Label, edge["_vertexLabel"], "source vertex label not matching");

            Assert.AreEqual(dest.Id, edge["_sink"], "destination vertex id not matching");
            Assert.AreEqual(dest.Label, edge["_sinkLabel"], "destination vertex label not matching");
            Assert.AreEqual(dest.PartitionKey, edge["_sinkPartition"], "destination vertex partitionKey not matching");
        }
示例#5
0
 /// <summary>
 /// insert a new Element
 /// </summary>
 /// <param name="index">The Index where the Element should be stored</param>
 /// <param name="item">The object that should be inserted</param>
 public void Insert(int index, GraphItemBase item)
 {
     if (this.Contains(item))
     {
         return;
     }
     base.Insert(index, item);
     if (this.ItemsChanged != null)
     {
         this.ItemsChanged(this, new GraphItemChangedEventArgs(item, "", true, false));
     }
 }
示例#6
0
        internal int SilentAdd(GraphItemBase item, string text, bool inter)
        {
            if (this.Contains(item))
            {
                return(-1);
            }
            int res = base.Add(item);

            if (this.ItemsChanged != null)
            {
                this.ItemsChanged(this, new GraphItemChangedEventArgs(item, text, true, inter));
            }
            return(res);
        }
        public void GenerateGraphEdgeWithGraphItemBase()
        {
            //Initialize Objects
            var movieTitle         = "The Network";
            var movieGraphItemBase = new GraphItemBase {
                Id = "movieId", Label = "Movie", PartitionKey = movieTitle
            };
            var ratingItemBase = new GraphItemBase {
                Id = "ratingId", Label = "Rating", PartitionKey = movieTitle
            };
            var movieRating = new MovieRatingEdge {
                SiteName = "SiteName"
            };

            //Generate a single edge
            var movieRatingEdgeSingle  = CosmosEntitySerializer.Default.ToGraphEdge(movieRating, movieGraphItemBase, ratingItemBase, single: true) as IDictionary <string, object>;
            var movieRatingEdgeSingle2 = CosmosEntitySerializer.Default.ToGraphEdge(movieRating, movieGraphItemBase, ratingItemBase, single: true) as IDictionary <string, object>;

            Assert.IsNotNull(movieRatingEdgeSingle, "Failed to convert movie to Graph Vertex");
            Assert.IsNotNull(movieRatingEdgeSingle2, "Failed to convert movie to Graph Vertex");

            //Ensure all properties are present in the result
            AssertGraphEdgeHasBaseProperties(movieRatingEdgeSingle);
            //Ensure all property values match the inputs
            AssertGraphEdgeValues(movieRatingEdgeSingle, movieGraphItemBase, ratingItemBase);
            Assert.AreEqual($"{movieGraphItemBase.Id}-{ratingItemBase.Id}", movieRatingEdgeSingle["id"], "id not matching");
            Assert.AreEqual(movieRating.GetType().Name, movieRatingEdgeSingle["label"], "label not matching");
            Assert.IsTrue(movieRatingEdgeSingle.ContainsKey("SiteName"), "Edge missing SiteName Property");
            Assert.AreEqual(movieRating.SiteName, movieRatingEdgeSingle["SiteName"], "SiteName not matching");
            //Ensure that 2 single edges have the same Ids
            Assert.AreEqual(movieRatingEdgeSingle["id"], movieRatingEdgeSingle2["id"], "Ids for 2 single edges should match");


            //Generate a multi edge
            var movieRatingEdgeMulti1 = CosmosEntitySerializer.Default.ToGraphEdge(movieRating, movieGraphItemBase, ratingItemBase, false) as IDictionary <string, object>;
            var movieRatingEdgeMulti2 = CosmosEntitySerializer.Default.ToGraphEdge(movieRating, movieGraphItemBase, ratingItemBase, false) as IDictionary <string, object>;

            Assert.IsNotNull(movieRatingEdgeMulti1, "Failed to convert movie to Graph Vertex");
            Assert.IsNotNull(movieRatingEdgeMulti2, "Failed to convert movie to Graph Vertex");
            //Ensure all properties are present in the result
            AssertGraphEdgeHasBaseProperties(movieRatingEdgeMulti1);
            //Ensure all property values match the inputs
            AssertGraphEdgeValues(movieRatingEdgeMulti1, movieGraphItemBase, ratingItemBase);
            Assert.AreEqual(movieRating.GetType().Name, movieRatingEdgeMulti1["label"], "label not matching");
            Assert.IsTrue(movieRatingEdgeSingle.ContainsKey("SiteName"), "Edge missing SiteName Property");
            Assert.AreEqual(movieRating.SiteName, movieRatingEdgeSingle["SiteName"], "SiteName not matching");
            //Ensure that 2 multi edges have the different Ids
            Assert.AreNotEqual(movieRatingEdgeMulti1["id"], movieRatingEdgeMulti2["id"], "id should be dynamic");
        }
示例#8
0
 /// <summary>
 /// add a new Element
 /// </summary>
 /// <param name="item">The object you want to add</param>
 /// <returns>The index it was added on</returns>
 public int Add(GraphItemBase item, string text)
 {
     return(SilentAdd(item, text, false));
 }
示例#9
0
 /// <summary>
 /// Checks wether or not the object is already stored in the List
 /// </summary>
 /// <param name="item">The Object you are looking for</param>
 /// <returns>true, if it was found</returns>
 public bool Contains(GraphItemBase item)
 {
     return(base.Contains(item));
 }
示例#10
0
 /// <summary>
 /// remove an Element
 /// </summary>
 /// <param name="item">The object that should be removed</param>
 public void Remove(GraphItemBase item)
 {
     this.SilentRemove(item, false);
 }
示例#11
0
 /// <summary>
 /// add a new Element
 /// </summary>
 /// <param name="item">The object you want to add</param>
 /// <returns>The index it was added on</returns>
 public int Add(GraphItemBase item)
 {
     return(SilentAdd(item, "", false));
 }
示例#12
0
 /// <summary>
 /// Upsert an edge into the database by referencing the source and target vertices just by their base properties (id, partitionKey, label).
 /// This call uses the SQL API to upsert the edge as a document.
 /// </summary>
 /// <param name="edge">Edge entity to upsert</param>
 /// <param name="source">Source vertex of the edge</param>
 /// <param name="target">Target vertex of the edge</param>
 /// <param name="single">
 /// [Optional] Indicates if there can only be one edge of this kind between the 2 vertices. Defaults to false.
 /// i.e an edge defining a 'isFriend' relationship between 2 people needs to be singe:true because only one friend edge makes sense.
 /// i.e an edge defining a 'visited' relationship between a person and a restaurant needs to be single:false because a person can visit the restaurant multiple times
 /// </param>
 /// <exception cref="InvalidOperationException">Throws invalid operation exception if the GraphClient was initialized without a CosmosSQLClient</exception>
 /// <returns><see cref="CosmosResponse"/> that tracks success status along with various performance parameters</returns>
 public Task <CosmosResponse> UpsertEdge <T>(T edge, GraphItemBase source, GraphItemBase target, bool single = false)
 {
     EnsureCosmosSqlClient();
     return(CosmosSqlClient.UpsertDocumentInternal(CosmosSerializer.ToGraphEdge(edge, source, target, single)));
 }