/// <summary> /// Creates a vertex with given label and properties /// </summary> /// <param name="label">Label of created vertex</param> /// <param name="properties">Properties of created vertex</param> /// <returns>Created IVertex</returns> public IVertex AddVertex(string label, IVertexProperties properties = null) { IVertex tmpVertex = new TitanVertex(); tmpVertex.Label = label; tmpVertex.ID = localId.ToString(); localId++; tmpVertex.Properties = properties; try { GremlinScript script = new GremlinScript(); script.Append_CreateVertexWithLabel(label, (Dictionary <string, List <IVertexValue> >)properties).Append(";"); IVertex createdVert = Gremlin.GetVertex(script); logger.Info("Vertex " + createdVert.ID + " has been created."); tmpVertex = createdVert; } catch (WebSocketException we) { logger.Error("Can not connect to Server. " + we); throw; } catch (JsonReaderException jre) { logger.Error("Can not read JSON. " + jre.Data + jre.StackTrace); throw; } catch (Exception e) { logger.Error(e); throw; } return(tmpVertex); }
/// <summary> /// Reads incoming Json and parses it to the right implementation /// </summary> /// <param name="reader">Reader that has json</param> /// <param name="objectType">objectType to which should be converted</param> /// <param name="existingValue">A potentially existing value</param> /// <param name="serializer">Serializer that is in use</param> /// <returns>parsed object</returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var jsonObject = JObject.Load(reader); var graphItemType = default(object); if (objectType == typeof(TitanVertexProperties) || objectType == typeof(OrientVertexProperties)) { if (objectType == typeof(OrientVertexProperties)) { graphItemType = new OrientVertexProperties(); } else if (objectType == typeof(TitanVertexProperties)) { graphItemType = new TitanVertexProperties(); } } else if (objectType == typeof(TitanEdgeProperties) || objectType == typeof(OrientEdgeProperties)) { if (objectType == typeof(OrientEdgeProperties)) { graphItemType = new OrientEdgeProperties(); } else if (objectType == typeof(TitanEdgeProperties)) { graphItemType = new TitanEdgeProperties(); } } else { JProperty jsonProp = jsonObject.Property("id"); JToken token = jsonProp.Value; //Titan if (token.Type == JTokenType.Integer || token.Type == JTokenType.String) { if (objectType == typeof(IVertex)) { graphItemType = new TitanVertex(); } else if (objectType == typeof(IEdge)) { graphItemType = new TitanEdge(); } else if (objectType == typeof(IVertexValue)) { graphItemType = new TitanVertexValue(); } } //Orient else if (token.Type == JTokenType.Object) { if (objectType == typeof(IVertex)) { graphItemType = new OrientVertex(); } else if (objectType == typeof(IEdge)) { graphItemType = new OrientEdge(); } else if (objectType == typeof(IVertexValue)) { graphItemType = new OrientVertexValue(); } } else { throw (new Exceptions.NotSupportedDatabaseException("Not supported GraphDatabase. Titan or OrientDB are supported.")); } } serializer.Populate(jsonObject.CreateReader(), graphItemType); return(graphItemType); }