/// <summary> /// Submits a request message that consists of a script with bindings as an asynchronous operation. /// </summary> /// <typeparam name="T">The type of the expected results.</typeparam> /// <param name="gremlinClient">The <see cref="IGremlinClient" /> that submits the request.</param> /// <param name="requestScript">The Gremlin request script to send.</param> /// <param name="bindings">Bindings for parameters used in the requestScript.</param> /// <returns>A collection of the data returned from the server.</returns> /// <exception cref="Exceptions.ResponseException"> /// Thrown when a response is received from Gremlin Server that indicates /// that an error occurred. /// </exception> public static async Task <GremlinResponse <T> > SubmitAsync <T>(this IGremlinClient gremlinClient, string requestScript, Dictionary <string, object> bindings = null) { var msgBuilder = RequestMessage.Build(Tokens.OpsEval).AddArgument(Tokens.ArgsGremlin, requestScript); if (bindings != null) { msgBuilder.AddArgument(Tokens.ArgsBindings, bindings); } var msg = msgBuilder.Create(); return(await gremlinClient.SubmitAsync <T>(msg).ConfigureAwait(false)); }
private async Task UpsertRelationship <A, B>(string relationShipName, IField left, IField right, IGremlinClient graphClient) { string vertexALabel = GetVertexLabel <A>(); string vertexBLabel = GetVertexLabel <B>(); string edgeLabel = GetEdgeLabel(relationShipName); string query = $"g.{VertexTraversal(vertexALabel, left)}.as('A')" + $".{VertexTraversal(vertexBLabel, right)}" + $".coalesce(__.inE('{edgeLabel}').where(outV().as('A'))," + $"addE('{edgeLabel}').from('A'))"; await ExecuteQuery(query, graphClient); }
private static async Task RunAirportQuery(IGremlinClient client, string gremlinCode) { IReadOnlyCollection <dynamic> results = await client.SubmitAsync <dynamic>(gremlinCode); int count = 0; foreach (dynamic result in results) { count++; dynamic jResult = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(result)); JArray steps = (JArray)jResult["objects"]; int userStep = 0; int totalDistanceInMinutes = 0; int i = 0; Console.WriteLine(); Console.WriteLine($"Choice # {count}"); foreach (JToken step in steps) { i++; if (step["type"].Value <string>() == "vertex") { userStep++; string userStepCaption = (userStep == 1 ? "Start at" : (i == steps.Count ? "Arrive at" : "Go to")); string vertexInfo = $"{userStep}. {userStepCaption} {step["label"]} = {step["id"]}"; if (step["label"].Value <string>() == "restaurant") { vertexInfo += $", rating = {step["properties"]["rating"][0]["value"]}"; vertexInfo += $", avg price = {step["properties"]["averagePrice"][0]["value"]}"; } vertexInfo += $" ({totalDistanceInMinutes} min)"; Console.WriteLine(vertexInfo); } else { int distanceInMinutes = step["properties"]["distanceInMinutes"].Value <int>(); totalDistanceInMinutes += distanceInMinutes; string edgeInfo = $" ({step["label"]} = {distanceInMinutes} min)"; Console.WriteLine(edgeInfo); } } } }
private async Task <IEnumerable <Dictionary <string, object> > > ExecuteQuery(string query, IGremlinClient client = null) { try { if (client == null) { using IGremlinClient graphclient = GremlinClient(); return(await graphclient.SubmitAsync <Dictionary <string, object> >(query)); } return(await client.SubmitAsync <Dictionary <string, object> >(query)); } catch (ResponseException e) { throw new GraphRepositoryException(e.Message, e); } }
/// <summary> /// Initializes a new <see cref="IRemoteConnection" />. /// </summary> /// <param name="client">The <see cref="IGremlinClient" /> that will be used for the connection.</param> /// <param name="traversalSource">The name of the traversal source on the server to bind to.</param> /// <exception cref="ArgumentNullException">Thrown when client is null.</exception> public DriverRemoteConnection(IGremlinClient client, string traversalSource) { _client = client ?? throw new ArgumentNullException(nameof(client)); _traversalSource = traversalSource ?? throw new ArgumentNullException(nameof(traversalSource)); }
private DriverRemoteConnection(IGremlinClient client, string traversalSource, Guid sessionId) : this(client, traversalSource) { _sessionId = sessionId.ToString(); }
/// <summary> /// Initializes a new instance of the <see cref="GraphClient"/> class. /// </summary> /// <param name="gremlinClient">The gremlin client.</param> /// <exception cref="ArgumentNullException">gremlinClient</exception> public GraphClient(IGremlinClient gremlinClient) { _gremlinClient = gremlinClient ?? throw new ArgumentNullException(nameof(gremlinClient)); }
/// <summary> /// Initializes a new instance of the <see cref="GraphClient"/> class. /// </summary> /// <param name="gremlinHostname">The hostname.</param> /// <param name="databaseName">Name of the database (case-sensitive).</param> /// <param name="graphName">Name of the graph.</param> /// <param name="accessKey">The access key.</param> public GraphClient(string gremlinHostname, string databaseName, string graphName, string accessKey) { var server = new GremlinServer(gremlinHostname, 443, true, $"/dbs/{databaseName}/colls/{graphName}", accessKey); _gremlinClient = new GremlinClient(server, new GraphSONJTokenReader(), mimeType: GremlinClient.GraphSON2MimeType); }
public GremlinClientNativeGremlinQueryProvider(IGremlinClient gremlinClient, string traversalSourceName, ILogger logger) { this._logger = logger; this._gremlinClient = gremlinClient; this.TraversalSource = GremlinQuery.Create(traversalSourceName); }
public DriverRemoteTraversalSideEffects(IGremlinClient gremlinClient, Guid serverSideEffectId) { _gremlinClient = gremlinClient; _serverSideEffectId = serverSideEffectId; }
public BaseGremlinService(CosmosClient cosmosClient, IGremlinClient gremlinClient) { CosmosContainer = cosmosClient.GetDatabase("example-db").GetContainer("main"); GremlinClient = gremlinClient; }
/// <summary> /// Initializes a new <see cref="IRemoteConnection" />. /// </summary> /// <param name="client">The <see cref="IGremlinClient" /> that will be used for the connection.</param> /// <exception cref="ArgumentNullException">Thrown when client is null.</exception> public DriverRemoteConnection(IGremlinClient client) { _client = client ?? throw new ArgumentNullException(nameof(client)); }
public DriverRemoteTraversal(IGremlinClient gremlinClient, Guid requestId, IEnumerable <Traverser> traversers) { Traversers = traversers; }
public DriverRemoteTraversal(IGremlinClient gremlinClient, Guid requestId, IEnumerable <Traverser> traversers) { Traversers = traversers; SideEffects = new DriverRemoteTraversalSideEffects(gremlinClient, requestId); }
public static IGremlinClient TransformRequest(this IGremlinClient client, Func <RequestMessage, Task <RequestMessage> > transformation) => new RequestInterceptingGremlinClient(client, transformation);
public static INativeGremlinQueryProvider <JToken> ToNativeGremlinQueryProvider(this IGremlinClient client, string traversalSourceName, ILogger logger) { return(new GremlinClientNativeGremlinQueryProvider(client, traversalSourceName, logger)); }
public static IGremlinClient ObserveResultStatusAttributes(this IGremlinClient client, Action <RequestMessage, IReadOnlyDictionary <string, object> > observer) => new ObserveResultStatusAttributesGremlinClient(client, observer);
public GetUser(IHttpClientFactory httpClientFactory, IGremlinClient gremlinClient, IB2CGraphClient b2cGraphClient, TelemetryConfiguration telemetryConfiguration) : base(httpClientFactory, gremlinClient, b2cGraphClient, telemetryConfiguration) { // Calls base }
public async Task DeleteRelationships <A, B>(params AmendRelationshipRequest[] amendRelationshipRequests) { using IGremlinClient gremlinClient = GremlinClient(); await RunForAllItems(amendRelationshipRequests, relationship => DeleteRelationship <A, B>(relationship.Type, relationship.A, relationship.B, gremlinClient)); }
public WebSocketGremlinQueryExecutor(IGremlinClient client, IGraphsonSerializerFactory graphSonSerializerFactory, ILogger logger = null) : base(client, graphSonSerializerFactory, logger) { }
private async Task <IEnumerable <Entity <TNode> > > GetAllEntities <TNode>(IField field, IEnumerable <string> relationships, IGremlinClient gremlinClient = null) where TNode : class { string vertexLabel = GetVertexLabel <TNode>(); string query = $"g.{VertexTraversal(vertexLabel, field)}" + $".coalesce({BothEdgeTraversal(relationships.ToArray())}.otherV().path(), path())"; IEnumerable <Dictionary <string, object> > results = await ExecuteQuery(query, gremlinClient); return(_pathResultsTransform.TransformMatches <TNode>(results, vertexLabel, field)); }
/// <summary> /// Submits a request message that consists of a script with bindings as an asynchronous operation without returning the result received from the Gremlin Server. /// </summary> /// <param name="gremlinClient">The <see cref="IGremlinClient"/> that submits the request.</param> /// <param name="requestScript">The Gremlin request script to send.</param> /// <param name="bindings">Bindings for parameters used in the requestScript.</param> /// <returns>The task object representing the asynchronous operation.</returns> /// <exception cref="Exceptions.ResponseException">Thrown when a response is received from Gremlin Server that indicates that an error occurred.</exception> public static async Task SubmitAsync(this IGremlinClient gremlinClient, string requestScript, Dictionary <string, object> bindings = null) { await gremlinClient.SubmitAsync <object>(requestScript, bindings).ConfigureAwait(false); }
private async Task <IEnumerable <Entity <TNode> > > GetCircularDependencies <TNode>(string relationship, IField field, IGremlinClient client) where TNode : class { string vertexLabel = GetVertexLabel <TNode>(); string query = $"g.{VertexTraversal(vertexLabel, field)}.as('A')" + $".repeat({OutEdgeTraversal(relationship)}.inV().simplePath()).times(31).emit(loops().is(gte(1)))" + $".{OutEdgeTraversal(relationship)}.inV().where(eq('A')).path()" + ".dedup().by(unfold().order().by(id).dedup().fold())"; IEnumerable <Dictionary <string, object> > results = await ExecuteQuery(query, client); return(_pathResultsTransform.TransformAll <TNode>(results, vertexLabel, field)); }
/// <summary> /// Submits a request message as an asynchronous operation without returning the result received from the Gremlin Server. /// </summary> /// <param name="gremlinClient">The <see cref="IGremlinClient"/> that submits the request.</param> /// <param name="requestMessage">The <see cref="ScriptRequestMessage"/> to send.</param> /// <returns>The task object representing the asynchronous operation.</returns> /// <exception cref="Exceptions.ResponseException">Thrown when a response is received from Gremlin Server that indicates that an error occurred.</exception> public static async Task SubmitAsync(this IGremlinClient gremlinClient, ScriptRequestMessage requestMessage) { await gremlinClient.SubmitAsync <object>(requestMessage).ConfigureAwait(false); }
/// <summary> /// Initializes a new <see cref="IRemoteConnection" /> using "g" as the default remote TraversalSource name. /// </summary> /// <param name="client">The <see cref="IGremlinClient" /> that will be used for the connection.</param> /// <exception cref="ArgumentNullException">Thrown when client is null.</exception> public DriverRemoteConnection(IGremlinClient client) : this(client, "g") { }
public RequestInterceptingGremlinClient(IGremlinClient baseClient, Func <RequestMessage, Task <RequestMessage> > transformation) { _baseClient = baseClient; _transformation = transformation; }
/// <summary> /// Add GremlinClient to Graph /// </summary> public IGraph AddClient(IGremlinClient client) { this.GremlinClient = client; return(this); }
public ObserveResultStatusAttributesGremlinClient(IGremlinClient baseClient, Action <RequestMessage, IReadOnlyDictionary <string, object> > observer) { _observer = observer; _baseClient = baseClient; }
/// <summary> /// Initializes a new instance of OrientGraph with given client /// </summary> /// <param name="client">Client that is in use</param> public OrientGraph(IGremlinClient client) { Gremlin = client; type = GraphType.Orient; localId = 1; }
/// <summary> /// Submits a request message as an asynchronous operation without returning the result received from the Gremlin /// Server. /// </summary> /// <param name="gremlinClient">The <see cref="IGremlinClient" /> that submits the request.</param> /// <param name="requestMessage">The <see cref="RequestMessage" /> to send.</param> /// <returns>The task object representing the asynchronous operation.</returns> /// <exception cref="Exceptions.ResponseException"> /// Thrown when a response is received from Gremlin Server that indicates /// that an error occurred. /// </exception> public static async Task <GremlinResponse> SubmitAsync(this IGremlinClient gremlinClient, RequestMessage requestMessage) { return(await gremlinClient.SubmitAsync <object>(requestMessage).ConfigureAwait(false)); }