Exemplo n.º 1
0
        public async Task Should_Create_New_Actor_From_Entity_Parameter()
        {
            var person = new Person
            {
                born = 1962,
                name = "Tom Cruise"
            };

            var parameters = new Neo4jParameters().WithEntity("actor", person);

            try
            {
                await Session.RunAsync(@"CREATE (:Actor $actor)", parameters);

                var cursor = await Session.RunAsync(@"
                    MATCH (actor:Actor)
                    RETURN actor");

                var tomCruise = await cursor.MapSingleAsync <Person>();

                Assert.AreEqual(1962, tomCruise.born);
                Assert.AreEqual("Tom Cruise", tomCruise.name);
            }
            catch (Exception exception)
            {
                Assert.Fail(exception.Message);
            }
            finally
            {
                await Session.RunAsync(@"
                    MATCH (a:Actor)
                    DELETE a");
            }
        }
Exemplo n.º 2
0
        public async Task InserirNoAsync(string nome, string anilha, string sexo, string nomePopular, string nascimento)
        {
            session = _driver.AsyncSession(o => o.WithDatabase("neo4j"));//Nome da database está nas propriedades como padrão

            string query = String.Empty;

            if (sexo != string.Empty)
            {
                query += ",Sexo:" + "$sexo";
            }
            if (nomePopular != string.Empty)
            {
                query += ",NomePopular:" + "$nomePopular";
            }
            if (nascimento != string.Empty)
            {
                query += ",Nascimento:" + "$nascimento";
            }

            try {
                if (anilha == string.Empty)
                {
                    cursor = await session.RunAsync("CREATE (p:Passaro{nome:$nome" + query + "})", new { nome, sexo, nomePopular, nascimento });//MERGE Impede cadastro de mesmo nome
                }
                else
                {
                    cursor = await session.RunAsync("CREATE (p:Passaro{nome:$nome, anilha:$anilha" + query + "})", new { nome, anilha, sexo, nomePopular, nascimento });
                }

                await cursor.ConsumeAsync();
            }
            finally {
                await session.CloseAsync();
            }
        }
        public async void Dispose()
        {
            await _session.RunAsync("MATCH (u:TestUser) DETACH DELETE u");

            await _session.RunAsync("MATCH (r:TestRole) DETACH DELETE r");

            await _session.CloseAsync();

            _driver.Dispose();
        }
Exemplo n.º 4
0
        public async Task ShouldShowMessage(string message)
        {
            var query = await session.RunAsync(
                "CREATE (a:Greeting {message: $message}) " +
                "RETURN a.message + ', from node ' + id(a)",
                new { message });

            var result = await query.SingleAsync();

            result[0].As <string>().ShouldStartWith(message);
        }
Exemplo n.º 5
0
        public async Task Setup()
        {
            driver  = GraphDatabase.Driver("bolt://localhost:7687");
            session = driver.AsyncSession();

            await session.RunAsync("MATCH (m:Movie) DETACH DELETE m ");

            await session.RunAsync("MATCH (p:Person) DETACH DELETE p ");

            await session.RunAsync("MATCH (a:Greeting) DELETE a ");
        }
    // ############
    // RETURN TWO LIST<STRING>
    // ############

    async void MultipleReturnsTest()
    {
        // Each IDriver instance maintains a pool of connections inside, as a result, it is recommended to only use one driver per application.
        // The driver is thread-safe, while the session or the transaction is not thread-safe.
        IDriver       driver  = GraphDatabase.Driver("neo4j://localhost:7687", AuthTokens.Basic("neo4j", "123456"));
        IAsyncSession session = driver.AsyncSession(o => o.WithDatabase("neo4j"));

        try
        {
            IResultCursor cursor = await session.RunAsync("MATCH (a:Person) RETURN a.name, a.born");

            // A record is accessible once it is received by the client. It is not needed for the whole result set to be received before it can be visited.
            // Each record can only be visited (a.k.a.consumed) once!
            // The recommended way to access these result records is to make use of methods provided by ResultCursorExtensions such as SingleAsync,
            // ToListAsync, and ForEachAsync.
            List <DataHolder> people = await cursor.ToListAsync(record => new DataHolder(record["a.name"].As <string>(), record["a.born"].As <string>()));

            await cursor.ConsumeAsync();

            foreach (var item in people)
            {
                Debug.Log(item.ToString());
            }
        }
        finally
        {
            await session.CloseAsync();
        }
        await driver.CloseAsync();
    }
    // ############
    // RETURN SINGLE NODE
    // ############

    async void SingleNodeLabelsTest()
    {
        // Each IDriver instance maintains a pool of connections inside, as a result, it is recommended to only use one driver per application.
        // The driver is thread-safe, while the session or the transaction is not thread-safe.
        IDriver       driver  = GraphDatabase.Driver("neo4j://localhost:7687", AuthTokens.Basic("neo4j", "123456"));
        IAsyncSession session = driver.AsyncSession(o => o.WithDatabase("neo4j"));

        try
        {
            IResultCursor cursor = await session.RunAsync("MATCH (a {name: 'Joel Silver'}) RETURN a");

            // The recommended way to access these result records is to make use of methods provided by ResultCursorExtensions such as SingleAsync,
            // ToListAsync, and ForEachAsync.
            INode person = await cursor.SingleAsync(record => record["a"].As <INode>());

            await cursor.ConsumeAsync();

            foreach (var item in person.Labels)
            {
                Debug.Log(item);
            }
        }
        finally
        {
            await session.CloseAsync();
        }
        await driver.CloseAsync();
    }
    // ############
    // RETURN SINGLE LIST<STRING>
    // ############

    async void SingleReturnTest()
    {
        // Each IDriver instance maintains a pool of connections inside, as a result, it is recommended to only use one driver per application.
        // The driver is thread-safe, while the session or the transaction is not thread-safe.
        IDriver       driver  = GraphDatabase.Driver("neo4j://localhost:7687", AuthTokens.Basic("neo4j", "123456"));
        IAsyncSession session = driver.AsyncSession(o => o.WithDatabase("neo4j"));

        try
        {
            IResultCursor cursor = await session.RunAsync("MATCH (a:Person) RETURN a.name as name");

            // The recommended way to access these result records is to make use of methods provided by ResultCursorExtensions such as SingleAsync,
            // ToListAsync, and ForEachAsync.
            List <string> people = await cursor.ToListAsync(record => record["name"].As <string>());

            await cursor.ConsumeAsync();

            Debug.Log(people.Count + " single returns");
        }
        finally
        {
            await session.CloseAsync();
        }
        await driver.CloseAsync();
    }
Exemplo n.º 9
0
        private async Task mnu_ClickAsync(object sender, RoutedEventArgs e)
        {
            IDriver       driver  = GraphDatabase.Driver("neo4j://localhost:7687", AuthTokens.Basic("neo4j", "neo4j"));
            IAsyncSession session = driver.AsyncSession(o => o.WithDatabase("neo4j"));

            try
            {
                IResultCursor cursor = await session.RunAsync("CREATE (n) RETURN n");

                await cursor.ConsumeAsync();
            }
            finally
            {
                await session.CloseAsync();
            }

            await driver.CloseAsync();

            ///https://stackoverflow.com/questions/59581789/why-does-idriver-not-contain-a-definition-for-session-when-using-neo4j-in-c
            ///test

            /*[TestClass]
             * {
             *  [TestMethod]
             *  {
             *      System.Console.WriteLine();
             *  }
             * }*/
        }
Exemplo n.º 10
0
        public async void CreateActor()
        {
            // arrange
            IAsyncSession session = _neo4JResource.GetAsyncSession();

            try
            {
                // act
                var actor = new Actor("Keanu Reaves", 56);

                IDictionary <string, object> parameters =
                    new Neo4jParameters().WithEntity("newActor", actor);

                IResultCursor cursor = await session.RunAsync(
                    @"CREATE (actor:Actor $newActor) RETURN actor",
                    parameters);

                Actor createdActor = await cursor.MapSingleAsync <Actor>();

                await cursor.ConsumeAsync();

                // assert
                createdActor.MatchSnapshot();
            }
            finally
            {
                await session.CloseAsync();
            }
        }
Exemplo n.º 11
0
        public async Task ExecuteNonQuery(string cypherQuery, object queryParams = null)
        {
            IAsyncSession session = _driver.AsyncSession(o => o.WithDatabase(this._database));

            if (queryParams == null)
            {
                queryParams = new {};
            }

            try
            {
                _logger.LogDebug($"Executing query: {cypherQuery}");

                IResultCursor cursor = await session.RunAsync(cypherQuery, queryParams);

                IResultSummary result = await cursor.ConsumeAsync();

                _logger.LogTrace($"Query executed successfully.");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error executing query. {ex.Message}");
                throw;
            }
            finally
            {
                await session.CloseAsync();
            }
        }
Exemplo n.º 12
0
        public async Task <List <Room> > GetRooms()
        {
            _logger.LogInformation("starting query");
            var rooms = new List <Room>();

            var cursor = await _graphClient.RunAsync("MATCH (a:Room) RETURN a");

            var records = await cursor.ToListAsync();

            foreach (var record in records)
            {
                var nodeProps = JsonSerializer.Serialize(record[0].As <INode>().Properties);
                rooms.Add(JsonSerializer.Deserialize <Room>(nodeProps));
            }
            return(rooms);
        }
Exemplo n.º 13
0
        // Get all records as a List
        public async Task <List <T> > FetchRecords <T>(
            Func <IRecord, T> recordProcessor,
            string cypherQuery,
            object queryParams = null)
        {
            List <T>      result  = null;
            IAsyncSession session = _driver.AsyncSession(o => o.WithDatabase(this._database));

            _logger.LogDebug($"Executing query: {cypherQuery}");

            if (queryParams == null)
            {
                queryParams = new {};
            }

            try
            {
                IResultCursor resultCursor = await session.RunAsync(cypherQuery, queryParams);

                result = await resultCursor.ToListAsync(record => recordProcessor(record));

                _logger.LogDebug("Query executed successfully");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Error executing query. {ex.Message}");
                throw;
            }
            finally
            {
                await session.CloseAsync();
            }

            return(result);
        }
        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();
            }
        }
Exemplo n.º 15
0
        private static async Task <Response> RunQueryAsync(IAsyncSession session, PlanType planType, Dictionary <string, object> parameters)
        {
            var query  = GetQuery(planType);
            var result = await(await session.RunAsync(query, parameters)).ToListAsync();
            var plan   = result
                         .Select(r =>
                                 r["nodes"]
                                 .As <List <INode> >()
                                 .Select(n => FormatNode(n))
                                 .ToList())
                         .FirstOrDefault();

            var markers = result
                          .Select(r =>
                                  r["nodes"]
                                  .As <List <INode> >()
                                  .Where(n => n.Labels.Contains("Stop"))
                                  .Select(n => n["location"].As <Point>())
                                  .Select(p => new LatLng(p.Y, p.X))
                                  .ToArray())
                          .FirstOrDefault();

            if (plan == null)
            {
                return(null);
            }

            FormatPlan(plan, planType);

            return(new Response(plan.ToArray(), markers));
        }
Exemplo n.º 16
0
        public async Task <T> ExecuteScalar <T>(string cypherQuery, object queryParams = null)
        {
            T             result  = default(T);
            IAsyncSession session = _driver.AsyncSession(o => o.WithDatabase(this._database));

            _logger.LogDebug($"Executing query: {cypherQuery}");

            if (queryParams == null)
            {
                queryParams = new {};
            }

            try
            {
                IResultCursor resultCursor = await session.RunAsync(cypherQuery, queryParams);

                IRecord record = await resultCursor.SingleAsync();

                result = record[0].As <T>();

                _logger.LogDebug("Query executed successfully");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Error executing query. {ex.Message}");
                throw;
            }
            finally
            {
                await session.CloseAsync();
            }

            return(result);
        }
Exemplo n.º 17
0
        public async Task DefinirPaisAsync(string filho, string aniFilho, string pai, string aniPai, string mae, string aniMae, bool[] comAnilha)
        {
            session = _driver.AsyncSession(o => o.WithDatabase("neo4j"));//Nome da database está nas propriedades como padrão

            try {
                if (!comAnilha.All(anilhas => anilhas == true))  //Expressão Lambda (entrada) => (corpo/condição)
                {
                    string matchf = " MATCH(f: Passaro { nome: $filho, anilha:$aniFilho})";
                    string matchp = " MATCH(p: Passaro { nome: $pai, anilha:$aniPai})";
                    string matchm = " MATCH(m:Passaro  { nome: $mae, anilha:$aniMae})";
                    string where = " WHERE NOT (:Passaro)-[:PAI]->(f)<-[:MAE]-(:Passaro)";
                    string merge = " MERGE (p)-[:PAI]->(f)<-[:MAE]-(m)";

                    if (!comAnilha[0])
                    {
                        matchf = "MATCH (f:Passaro {nome: $filho})";
                        where += " and ID(f) = toInteger($aniFilho)";
                    }
                    if (!comAnilha[1])
                    {
                        matchp = "MATCH (p:Passaro {nome: $pai})";
                        where += " and ID(p) = toInteger($aniPai)";
                    }
                    if (!comAnilha[2])
                    {
                        matchm = "MATCH (m:Passaro {nome: $mae})";
                        where += " and ID(m) = toInteger($aniMae)";
                    }
                    cursor = await session.RunAsync(matchf + matchp + matchm + where + merge, new { filho, aniFilho, pai, aniPai, mae, aniMae });
                }
                else
                {
                    cursor = await session.RunAsync("MATCH (f:Passaro {nome: $filho, anilha:$aniFilho})" +
                                                    "MATCH (p:Passaro {nome: $pai, anilha:$aniPai})" +
                                                    "MATCH (m:Passaro {nome: $mae, anilha:$aniMae})" +
                                                    "WHERE NOT (:Passaro)-[:PAI]->(f)<-[:MAE]-(:Passaro)" +
                                                    "MERGE (p)-[:PAI]->(f)<-[:MAE]-(m)", new { filho, aniFilho, pai, aniPai, mae, aniMae });
                }
                resultado = await cursor.ConsumeAsync();
            }
            finally {
                await session.CloseAsync();
            }
        }
Exemplo n.º 18
0
        public async Task <List <IRecord> > ProcurarPais(string nome, string anilha, bool comAnilha)
        {
            session = _driver.AsyncSession(o => o.WithDatabase("neo4j"));//Nome da database está nas propriedades como padrão

            try {
                if (!comAnilha)
                {
                    if (anilha != String.Empty)
                    {
                        cursor = await session.RunAsync("MATCH (f:Passaro{nome:$nome})" +
                                                        "WHERE ID(f) = toInteger($anilha) " +
                                                        "OPTIONAL MATCH (m1:Passaro)-[:MAE]->(f)" +
                                                        "OPTIONAL MATCH (f)<-[:PAI]-(p1:Passaro)" +
                                                        "RETURN f,[f.nome] AS Nomes,[m1.nome] AS Maes,[p1.nome] AS Pais, [ID(f)] AS Ids", new { nome, anilha });
                    }
                    else
                    {
                        cursor = await session.RunAsync("MATCH (f:Passaro{nome:$nome})" +
                                                        "OPTIONAL MATCH (m1:Passaro)-[:MAE]->(f)" +
                                                        "OPTIONAL MATCH (f)<-[:PAI]-(p1:Passaro)" +
                                                        "RETURN f,[f.nome] AS Nomes,[m1.nome] AS Maes,[p1.nome] AS Pais, [ID(f)] AS Ids", new { nome });
                    }
                }
                else
                {
                    cursor = await session.RunAsync("MATCH (f:Passaro {nome: $nome, anilha:$anilha})" +
                                                    "OPTIONAL MATCH (m1:Passaro)-[:MAE]->(f)" +
                                                    "OPTIONAL MATCH (f)<-[:PAI]-(p1:Passaro)" +
                                                    "RETURN f,[f.nome] AS Nomes,[m1.nome] AS Maes,[p1.nome] AS Pais, [ID(f)] AS Ids", new { nome, anilha });
                }

                var lista = await cursor.ToListAsync();

                resultado = await cursor.ConsumeAsync();

                return(lista);
            }
            finally {
                await session.CloseAsync();
            }
        }
Exemplo n.º 19
0
        public async Task ProcurarFamilia(string filho, string aniFilho, bool comAnilha) //Testar essa função
        {
            session = _driver.AsyncSession(o => o.WithDatabase("neo4j"));                //Nome da database está nas propriedades como padrão
            try {
                string optMatch;
                string matchf;
                if (comAnilha)
                {
                    matchf = "MATCH (f:Passaro{nome:$filho, anilha:$aniFilho})" +
                             "OPTIONAL MATCH (f)<-[:PAI]-(p1:Passaro)" +
                             "OPTIONAL MATCH (m1:Passaro)-[:MAE]->(f)";
                }
                else
                {
                    matchf = "MATCH (f:Passaro{nome:$filho})" +
                             "WHERE ID(f) = toInteger($aniFilho)" +
                             "OPTIONAL MATCH (f)<-[:PAI]-(p1:Passaro)" +
                             "OPTIONAL MATCH (m1:Passaro)-[:MAE]->(f)";
                }
                optMatch =
                    "optional match(m2:Passaro)-[:MAE]->(p1) < -[:PAI] - (p2: Passaro)" +
                    "optional match(m3:Passaro)-[:MAE]->(m1) < -[:PAI] - (p3: Passaro)" +
                    "optional match(m4:Passaro)-[:MAE]->(p2) < -[:PAI] - (p4: Passaro)" +
                    "optional match(m5:Passaro)-[:MAE]->(m2) < -[:PAI] - (p5: Passaro)" +
                    "optional match(m6:Passaro)-[:MAE]->(p3) < -[:PAI] - (p6: Passaro)" +
                    "optional match(m7:Passaro)-[:MAE]->(m3) < -[:PAI] - (p7: Passaro)" +
                    "OPTIONAL MATCH(m8:Passaro)-[:MAE]->(p4) < -[:PAI] - (p8: Passaro)" +
                    "OPTIONAL MATCH(m9:Passaro)-[:MAE]->(m4) < -[:PAI] - (p9: Passaro)" +
                    "OPTIONAL MATCH(m10:Passaro)-[:MAE]->(p5) < -[:PAI] - (p10: Passaro)" +
                    "OPTIONAL MATCH(m11:Passaro)-[:MAE]->(m5) < -[:PAI] - (p11: Passaro)" +
                    "OPTIONAL MATCH(m12:Passaro)-[:MAE]->(p6) < -[:PAI] - (p12: Passaro)" +
                    "OPTIONAL MATCH(m13:Passaro)-[:MAE]->(m6) < -[:PAI] - (p13: Passaro)" +
                    "OPTIONAL MATCH(m14:Passaro)-[:MAE]->(p7) < -[:PAI] - (p14: Passaro)" +
                    "OPTIONAL MATCH(m15:Passaro)-[:MAE]->(m7) < -[:PAI] - (p15: Passaro)" +
                    "return [f.nome, p1.nome, m1.nome, p2.nome, m2.nome, p3.nome, m3.nome, " +
                    "p4.nome, m4.nome, p5.nome, m5.nome, p6.nome, m6.nome, p7.nome, m7.nome," +
                    "p8.nome, m8.nome, p9.nome, m9.nome, p10.nome, m10.nome, p11.nome, m11.nome," +
                    "p12.nome, m12.nome, p13.nome, m13.nome, p14.nome, m14.nome, p15.nome, m15.nome] AS familia";

                cursor = await session.RunAsync(matchf + optMatch, new { filho, aniFilho });

                records = await cursor.ToListAsync();

                familia = new List <string>();
                //familia.Add(aniFilho);
                //familia.Add(filho);
                familia   = Records();
                resultado = await cursor.ConsumeAsync();
            }
            finally {
                await session.CloseAsync();
            }
        }
        public static async Task <TEntity> GetNodeAsync <TEntity>(
            this IAsyncSession asyncSession,
            long nodeId) where TEntity : class
        {
            var parameters = new Neo4jParameters()
                             .WithValue("p1", nodeId);

            var resultCursor = await asyncSession.RunAsync(Constants.Statement.GetNode, parameters)
                               .ConfigureAwait(false);

            return(await resultCursor.MapSingleAsync <TEntity>().ConfigureAwait(false));
        }
 private static Task <IResultCursor> ExecuteQuery(IAsyncSession session, string cypher)
 {
     try
     {
         return(session.RunAsync(cypher));
     }
     catch (Neo4jException ex)
     {
         Console.WriteLine("\tError!");
         Console.WriteLine($"\t{ex}");
         throw;
     }
 }
Exemplo n.º 22
0
        public async Task CriarUniqueAsync()
        {
            session = _driver.AsyncSession(o => o.WithDatabase("neo4j"));//Nome da database está nas propriedades como padrão

            try {
                cursor = await session.RunAsync("CREATE CONSTRAINT anilhaC ON (p:Passaro) ASSERT p.anilha IS UNIQUE");

                await cursor.ConsumeAsync();
            }
            finally {
                await session.CloseAsync();
            }
        }
Exemplo n.º 23
0
        public async Task <IRequestExecutor> CreateSchema()
        {
            IAsyncSession session = GetAsyncSession();
            IResultCursor cursor  = await session.RunAsync(seedCypher);

            await cursor.ConsumeAsync();

            return(await new ServiceCollection()
                   .AddSingleton(Driver)
                   .AddGraphQL()
                   .AddQueryType()
                   .AddMovieTypes()
                   .Services
                   .BuildServiceProvider()
                   .GetRequiredService <IRequestExecutorResolver>()
                   .GetRequestExecutorAsync());
        }
Exemplo n.º 24
0
        // Get records as a stream of buffered List
        public async IAsyncEnumerable <List <T> > FetchRecordsAsStream <T>(
            Func <IRecord, T> recordProcessor,
            string cypherQuery, object queryParams = null,
            long bufferSize = 100)
        {
            long recordsProcessed = 0;

            List <T>      resultBuffer = new List <T>();
            IAsyncSession session      = _driver.AsyncSession(o => o.WithDatabase(this._database));

            _logger.LogDebug($"Executing query: {cypherQuery}");

            if (queryParams == null)
            {
                queryParams = new {};
            }

            try
            {
                IResultCursor resultCursor = await session.RunAsync(cypherQuery, queryParams);

                _logger.LogDebug("Reading cursor");

                while (await resultCursor.FetchAsync())
                {
                    recordsProcessed += 1;

                    resultBuffer.Add(recordProcessor(resultCursor.Current));

                    if (resultBuffer.Count >= bufferSize)
                    {
                        _logger.LogDebug($"Records processed: {recordsProcessed} ...");
                        yield return(resultBuffer);

                        resultBuffer.Clear();
                    }
                }

                _logger.LogDebug($"* Total records processed: {recordsProcessed} *");
                yield return(resultBuffer);
            }
            finally
            {
                await session.CloseAsync();
            }
        }
        public static async Task <IResultCursor> SetNodeAsync <TEntity>(
            this IAsyncSession asyncSession,
            TEntity entity) where TEntity : class
        {
            var nodeId = EntityAccessor.GetNodeId(entity);

            if (nodeId == null)
            {
                throw new InvalidOperationException(Constants.NodeIdUnspecifiedMessage);
            }

            var parameters = new Neo4jParameters()
                             .WithValue("p1", nodeId)
                             .WithEntity("p2", entity);

            return(await asyncSession.RunAsync(Constants.Statement.SetNode, parameters)
                   .ConfigureAwait(false));
        }
Exemplo n.º 26
0
        public async Task <ActionResult> Get()
        {
            IResultCursor cursor;
            var           types   = new List <string>();
            IAsyncSession session = _driver.AsyncSession();

            try
            {
                cursor = await session.RunAsync(@"MATCH (t:Type) RETURN t.name AS name");

                types = await cursor.ToListAsync(record => record["name"].As <string>());
            }
            finally
            {
                await session.CloseAsync();
            }

            return(Ok(types));
        }
Exemplo n.º 27
0
        //TODO: Mudar cor das labels na frente do cartão pelo usuário
        //TODO: Menu para atualizar campos de passarinho
        //TODO: Pontos que precisam estão marcados com indicadores de bandeira branca
        //TODO: Clicar em pesquisar sem sair nomeFilhoF faz com que listnomesF == null
        //TODO: Criar menu para cadastrar em árvore
        //TODO: Atualizar buttonPesquisa para buttonImpressão
        public async Task <List <IRecord> > ProcurarFilhos(string nome)
        {
            session = _driver.AsyncSession(o => o.WithDatabase("neo4j"));//Nome da database está nas propriedades como padrão

            try {
                cursor = await session.RunAsync("MATCH (p:Passaro {nome: $nome})" +
                                                "OPTIONAL MATCH (p)-[:PAI|MAE]->(f:Passaro)" +
                                                "RETURN [p.nome] AS Nomes, [ID(p)] AS Ids,[f.nome] AS Filhos, " +
                                                "[p.anilha] AS Anilhas, [p.Sexo] AS Sexos, [p.NomePopular] AS NomesPopulares, " +
                                                "[p.Nascimento] AS Nascimentos ", new { nome });

                var lista = await cursor.ToListAsync();

                resultado = await cursor.ConsumeAsync();

                return(lista);
            }
            finally {
                await session.CloseAsync();
            }
        }
Exemplo n.º 28
0
        public async Task <IRequestExecutor> CreateSchema()
        {
            IAsyncSession session = GetAsyncSession();
            IResultCursor cursor  = await session.RunAsync(seedCypher);

            await cursor.ConsumeAsync();

            return(await new ServiceCollection()
                   .AddSingleton(Driver)
                   .AddGraphQL()
                   .AddQueryType(d => d.Name("Query"))
                   .AddType <Queries>()
                   .AddNeo4JProjections()
                   .AddNeo4JFiltering()
                   .AddNeo4JSorting()
                   .UseDefaultPipeline()
                   .Services
                   .BuildServiceProvider()
                   .GetRequiredService <IRequestExecutorResolver>()
                   .GetRequestExecutorAsync());
        }
Exemplo n.º 29
0
 public static Task<IResultCursor> Run(this IAsyncSession session, CypherQuery query, IGraphClient gc)
 {
     return session.RunAsync(query.QueryText, query.ToNeo4jDriverParameters(gc));
 }
Exemplo n.º 30
0
        /// <inheritdoc />
        public async ValueTask <IList> ToListAsync(CancellationToken cancellationToken)
        {
            IResultCursor cursor = await _session.RunAsync(Pipeline().Build());

            return(await cursor.MapAsync <T>().ConfigureAwait(false));
        }