Beispiel #1
0
        private void ExecuteCypher(object sender, ExecuteQueryArgs e)
        {
            try
            {
                if (_connected == false)
                {
                    var control = _customTaskPane.Control as ExecuteQuery;
                    ConnectDatabase(this, new ConnectDatabaseArgs {
                        ConnectionString = control.ConnectionString()
                    });
                }

                var worksheet = ((Worksheet)Application.ActiveSheet);

                using (var session = _driver.Session())
                {
                    var  result     = session.Run(e.Cypher);
                    bool isFirstRow = true;
                    int  row        = 2;
                    foreach (var record in result)
                    {
                        for (int i = 0; i < record.Keys.Count; i++)
                        {
                            var colName = GetColNameFromIndex(i + 1);
                            var key     = record.Keys[i];
                            if (isFirstRow)
                            {
                                worksheet.Range[$"{colName}1"].Value2 = key;
                            }
                            worksheet.Range[$"{colName}{row}"].Value2 = record.Values[key].As <string>();
                        }
                        row++;
                        isFirstRow = false;
                    }
                }
            }
            catch (Neo4jException ex)
            {
                CurrentControl.SetMessage(ex.Message);
            }
        }
Beispiel #2
0
        private async void ExecuteCypher(object sender, ExecuteQueryArgs e)
        {
            var session = _driver.AsyncSession();

            try
            {
                if (_connected == false)
                {
                    var control = _customTaskPane.Control as ExecuteQuery;
                    ConnectDatabase(this, new ConnectDatabaseArgs {
                        ConnectionString = control.ConnectionString()
                    });
                }

                var worksheet = ((Worksheet)Application.ActiveSheet);

                try
                {
                    IResultCursor cursor = await session.RunAsync(e.Cypher);

                    var records = await cursor.ToListAsync();

                    var summary = await cursor.ConsumeAsync();

                    string message = summary.ToString();
                    CurrentControl.SetMessage(message);
                }
                finally
                {
                    await session.CloseAsync();
                }
            }
            catch (Neo4jException ex)
            {
                CurrentControl.SetMessage(ex.Message);
            }
            finally
            {
                await session.CloseAsync();
            }
        }
Beispiel #3
0
 private async void ExecuteCypher(object sender, ExecuteQueryArgs e)
 {
     await ExecuteCypher(e.Cypher);
 }