示例#1
0
        public QueryViewModel(IApplicationInteraction applicationInteraction, IQueryHistoryProvider queryHistoryProvider)
        {
            _applicationInteraction = applicationInteraction;
            _queryHistoryProvider   = queryHistoryProvider;

            DisplayName = "Query";

            IconContent = new PackIcon {
                Kind = PackIconKind.CodeGreaterThan
            };

            PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == nameof(CurrentDatabase))
                {
                    SetDisplay(CurrentDatabase);
                }
            };

            RunQueryCommand = new RelayCommand(_ => RunAllRawQuery(), _ => CanRunQuery);

            RunSelectedQueryCommand = new RelayCommand(_ => RunSelectedQuery(), _ => CanRunSelectedQuery);

            OpenHelpCommand = new RelayCommand(_ => OpenHelp(), _ => true);

            QueryHistoryView = IoC.Get <QueryHistoryViewModel>();

            QueryHistoryView.Parent = this;

            QueryHistoryView.FilterActiveDatabase = true;
        }
示例#2
0
        public QueryViewModel(
            IApplicationInteraction applicationInteraction,
            IQueryViewsProvider queryViewsProvider,
            IQueryHistoryProvider queryHistoryProvider)
        {
            _applicationInteraction = applicationInteraction;
            _queryViewsProvider     = queryViewsProvider;
            _queryHistoryProvider   = queryHistoryProvider;

            DisplayName = "Query";

            RunQueryCommand = new AsyncCommand(RunAllRawQuery, () => CanRunQuery);

            RunSelectedQueryCommand = new AsyncCommand(RunSelectedQuery, () => CanRunSelectedQuery);

            OpenHelpCommand = new AsyncCommand(OpenHelp);

            QueryHistoryView = IoC.Get <QueryHistoryViewModel>();

            QueryHistoryView.Parent = this;

            QueryHistoryView.FilterActiveDatabase = true;

            QueryHandlersMetadata = _queryViewsProvider.ListMetadata();

            CurrentQueryHandlerName = QueryHandlersMetadata.Select(p => p.Name).FirstOrDefault();
        }
        public QueryHistoryViewModel(IQueryHistoryProvider queryHistoryProvider, IApplicationInteraction applicationInteraction)
        {
            _queryHistoryProvider   = queryHistoryProvider;
            _applicationInteraction = applicationInteraction;

            DisplayName = "Query History";

            QueryHistoriesView = new CollectionViewSource
            {
                Source = _queryHistoryProvider.QueryHistories
            };

            QueryHistoriesView.Filter += (sender, args) =>
            {
                if (_activeDatabase != null && FilterActiveDatabase && args.Item is RawQueryHistory rawQueryHistory)
                {
                    args.Accepted = rawQueryHistory.DatabaseLocation.Equals(_activeDatabase.Location,
                                                                            StringComparison.OrdinalIgnoreCase);
                }
                else
                {
                    args.Accepted = true;
                }
            };
        }
示例#4
0
        public Task <IList <IScreen> > RunQuery(DatabaseReference databaseReference, IQueryHistoryProvider queryHistoryProvider, string query)
        {
            var result = new List <IScreen>();

            if (string.IsNullOrWhiteSpace(query))
            {
                return(Task.FromResult <IList <IScreen> >(result));
            }

            var rawQueries = RemoveQueryComments(query)
                             .Split(new[] { "db.", "DB." }, StringSplitOptions.RemoveEmptyEntries)
                             .Select(q => $"db.{q.Trim()}")
                             .ToList();

            var resultCount = 0;

            foreach (var rawQuery in rawQueries)
            {
                resultCount++;

                try
                {
                    var resultViewModel = IoC.Get <QueryResultViewModel>();

                    IList <BsonValue> results;
                    using (resultViewModel.StartTime())
                    {
                        results = databaseReference.RunCommand(rawQuery);
                    }
                    resultViewModel.SetResult(
                        $"Result {resultCount}",
                        rawQuery,
                        new QueryResult(results, UserDefinedCultureFormat.Default));

                    result.Add(resultViewModel);
                }
                catch (Exception e)
                {
                    var title           = $"Query {resultCount} Error";
                    var exceptionScreen = new ExceptionScreenViewModel(title, $"Error on Query {resultCount}:\n'{rawQuery}'", e);
                    result.Add(exceptionScreen);
                }
            }

            var queryHistory = new RawQueryHistory
            {
                QueryHandlerName = Name,
                RawQuery         = query.Trim(),
                DatabaseLocation = databaseReference.Location,
                DatabaseVersion  = databaseReference.DatabaseVersion,
                CreatedAt        = DateTime.UtcNow,
                LastRunAt        = DateTime.UtcNow,
            };

            queryHistoryProvider.Upsert(queryHistory);

            return(Task.FromResult <IList <IScreen> >(result));
        }
示例#5
0
        public QueryViewModel(
            IApplicationInteraction applicationInteraction,
            IQueryViewsProvider queryViewsProvider,
            IQueryHistoryProvider queryHistoryProvider)
        {
            _applicationInteraction = applicationInteraction;
            _queryViewsProvider     = queryViewsProvider;
            _queryHistoryProvider   = queryHistoryProvider;

            DisplayName = "Query";

            IconContent = new PackIcon {
                Kind = PackIconKind.CodeGreaterThan
            };

            PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == nameof(CurrentDatabase))
                {
                    SetDisplay(CurrentDatabase);
                }
            };

            RunQueryCommand = new AsyncCommand(RunAllRawQuery, () => CanRunQuery);

            RunSelectedQueryCommand = new AsyncCommand(RunSelectedQuery, () => CanRunSelectedQuery);

            OpenHelpCommand = new AsyncCommand(OpenHelp);

            QueryHistoryView = IoC.Get <QueryHistoryViewModel>();

            QueryHistoryView.Parent = this;

            QueryHistoryView.FilterActiveDatabase = true;

            QueryHandlersMetadata = _queryViewsProvider.ListMetadata();

            CurrentQueryHandlerName = QueryHandlersMetadata.Select(p => p.Name).FirstOrDefault();
        }