private async Task <bool> pushQueue(Queue <PendingCypher> pendingCyphers, IAsyncSession session, string sessionId) { //var pushTasks = new List<Task>(); var wtxResult = await session.WriteTransactionAsync(async tx => { while (pendingCyphers.Count > 0) { var pendingQuery = pendingCyphers.Dequeue(); if (pendingQuery.Props != null && pendingQuery.Props.ContainsKey("SessionId")) { pendingQuery.Props["SessionId"] = sessionId; } var result = await(pendingQuery.Props != null && pendingQuery.Props.Count > 0 ? tx.RunAsync(pendingQuery.Query, pendingQuery.Props) : tx.RunAsync(pendingQuery.Query)); pendingQuery.Complete(result); //pushTasks.Add(result); // commitedList.Add(pendingQuery); } return(true); //return Task.WhenAll(pushTasks); }); return(wtxResult); }
public static async Task <List <IRecord> > Query(string query) { if (driver is null) { throw new ArgumentNullException("Connect to DB before you query"); } else { IAsyncSession session = driver.AsyncSession(); try { return(await session.WriteTransactionAsync(tx => RunCypherWithResults(tx, query))); } catch (Exception err) { // Error throw err; } finally { Console.WriteLine("Closed connection"); await session.CloseAsync(); } } }
public async Task UpsertNodes <T>(IEnumerable <T> nodes, IEnumerable <string> indices = null) { IAsyncSession session = AsyncSession(); string objectName = typeof(T).Name.ToLowerInvariant(); string key = null; try { if (!indices.IsNullOrEmpty()) { key = indices.Select(_ => $"{{{_}:{objectName}.{_}}}").FirstOrDefault(); foreach (var query in indices.Select(_ => $"INDEX ON :{objectName}({_})")) { ICypherBuilder cypherBuilder = _cypherBuilderFactory.NewCypherBuilder().AddCreate(query); await session.RunAsync(cypherBuilder.ToString()); } } string cypher = UpsertNodesCypher <T>(key); await session.WriteTransactionAsync(tx => RunCypher(tx, cypher, new Dictionary <string, object>() { { "nodes", nodes.ToDictionaries() } })); } finally { await session.CloseAsync(); } }
private static Task SaveBatch(string query, IList <Dictionary <string, object> > parameters, IAsyncSession session) { return(session.WriteTransactionAsync(async transaction => { await transaction.RunAsync(query, new Dictionary <string, object> { ["data"] = parameters }); })); }
private async Task ExecuteCypher(string cypher, Dictionary <string, object> parameters = null) { IAsyncSession session = AsyncSession(); try { await session.WriteTransactionAsync(tx => RunCypher(tx, cypher, parameters)); } catch (Neo4jException e) { throw new GraphRepositoryException(e.Message, e); } finally { await session.CloseAsync(); } }
public async Task Run(ICommand[] commands, string databaseName, bool defaultDatabase) { IAsyncSession session = GetAsyncSession(databaseName, defaultDatabase); try { // transaction functions auto-retry //todo: configure retry? timeout? etc. LogRun("command(s)", databaseName, defaultDatabase); await session.WriteTransactionAsync(async tx => { foreach (ICommand command in commands) { IResultCursor result = await tx.RunAsync(command.Query); var records = await result.ToListAsync(r => r); var resultSummary = await result.ConsumeAsync(); _logger.LogDebug("Query result available after: {ResultAvailableAfter}, consumed after: {ResultConsumedAfter}", resultSummary.ResultAvailableAfter, resultSummary.ResultConsumedAfter); if (resultSummary.Notifications.Any()) { _logger.LogWarning($"Query had notifications{Environment.NewLine}:{string.Join(Environment.NewLine, resultSummary.Notifications)}"); } command.ValidateResults(records, resultSummary); } }); } finally { await session.CloseAsync(); } }
public static async Task <long> NextUniqueIdAsync(this IAsyncSession session, string scope) { return(await session.WriteTransactionAsync( async transaction => await transaction.NextUniqueIdAsync(scope).ConfigureAwait(false)) .ConfigureAwait(false)); }
public static async Task UpdateUniqueIdAsync(this IAsyncSession session, string scope, long value) { await session.WriteTransactionAsync( async transaction => await transaction.UpdateUniqueIdAsync(scope, value).ConfigureAwait(false)) .ConfigureAwait(false); }
public static async Task InitialiseUniqueIdsAsync(this IAsyncSession session) { await session.WriteTransactionAsync( async transaction => await transaction.InitialiseAsync().ConfigureAwait(false)) .ConfigureAwait(false); }
public async Task <T> WriteTransactionAsync <T>(Func <IAsyncTransaction, Task <T> > work) { return(await _session.WriteTransactionAsync(work)); }