示例#1
0
        public QueryModel()
        {
            ModelUrl = "/query";
            ApplicationModel.Current.Server.Value.RawUrl = null;

            queryDocument = new EditorDocument()
            {
                Language = SyntaxEditorHelper.LoadLanguageDefinitionFromResourceStream("RavenQuery.langdef")
            };

            ExceptionLine   = -1;
            ExceptionColumn = -1;

            CollectionSource = new QueryDocumentsCollectionSource();
            Observable.FromEventPattern <QueryStatisticsUpdatedEventArgs>(h => CollectionSource.QueryStatisticsUpdated += h,
                                                                          h => CollectionSource.QueryStatisticsUpdated -= h)
            .SampleResponsive(TimeSpan.FromSeconds(0.5))
            .TakeUntil(Unloaded)
            .ObserveOnDispatcher()
            .Subscribe(e =>
            {
                QueryTime = e.EventArgs.QueryTime;
                Results   = e.EventArgs.Statistics;
            });
            Observable.FromEventPattern <QueryErrorEventArgs>(h => CollectionSource.QueryError += h,
                                                              h => CollectionSource.QueryError -= h)
            .ObserveOnDispatcher()
            .Subscribe(e => HandleQueryError(e.EventArgs.Exception));

            DocumentsResult = new DocumentsModel(CollectionSource)
            {
                Header = "Results",
                DocumentNavigatorFactory = (id, index) => DocumentNavigator.Create(id, index, IndexName, CollectionSource.TemplateQuery),
            };

            QueryErrorMessage = new Observable <string>();
            IsErrorVisible    = new Observable <bool>();

            SortBy = new BindableCollection <StringRef>(x => x.Value);
            SortBy.CollectionChanged += HandleSortByChanged;
            SortByOptions             = new BindableCollection <string>(x => x);
            Suggestions    = new BindableCollection <FieldAndTerm>(x => x.Field);
            DynamicOptions = new BindableCollection <string>(x => x)
            {
                "AllDocs"
            };
        }
示例#2
0
        public PatchModel()
        {
            Values    = new ObservableCollection <PatchValue>();
            InProcess = new Observable <bool>();

            OriginalDoc = new EditorDocument
            {
                Language   = JsonLanguage,
                IsReadOnly = true,
            };

            NewDoc = new EditorDocument
            {
                Language   = JsonLanguage,
                IsReadOnly = true,
            };

            Script = new EditorDocument
            {
                Language = JScriptLanguage
            };

            Script.Language.RegisterService(new PatchScriptIntelliPromptProvider(Values, recentDocuments));
            Script.Language.RegisterService <IEditorDocumentTextChangeEventSink>(new AutoCompletionTrigger());

            QueryDoc = new EditorDocument
            {
                Language = QueryLanguage
            };

            ShowBeforeAndAfterPrompt = true;
            ShowAfterPrompt          = true;
            AvailableObjects         = new ObservableCollection <string>();

            queryCollectionSource = new QueryDocumentsCollectionSource();
            QueryResults          = new DocumentsModel(queryCollectionSource)
            {
                Header = "Matching Documents", MinimalHeader = true, HideItemContextMenu = true
            };
            QueryResults.ItemSelection.SelectionChanged += (sender, args) =>
            {
                var firstOrDefault = QueryResults.ItemSelection.GetSelectedItems().FirstOrDefault();
                if (firstOrDefault != null)
                {
                    UpdateBeforeDocument(firstOrDefault.Item.Document);
                    HasSelection = true;
                }
                else
                {
                    HasSelection = false;
                    ClearBeforeAndAfter();
                }
            };

            QueryResults.RecentDocumentsChanged += delegate
            {
                recentDocuments.Clear();
                recentDocuments.AddRange(QueryResults.GetMostRecentDocuments().Where(d => d.Document != null).Take(5).Select(d => d.Document));
            };

            PatchScriptErrorMessage = new Observable <string>();
            IsErrorVisible          = new Observable <bool>();
        }
示例#3
0
        public PatchModel()
        {
            selectedItem = new Observable <string>();
            OriginalDoc  = new EditorDocument()
            {
                Language   = JsonLanguage,
                IsReadOnly = true,
            };

            NewDoc = new EditorDocument()
            {
                Language   = JsonLanguage,
                IsReadOnly = true,
            };

            Script = new EditorDocument()
            {
                Language = JScriptLanguage
            };

            QueryDoc = new EditorDocument()
            {
                Language = QueryLanguage
            };

            ShowBeforeAndAfterPrompt = true;
            ShowAfterPrompt          = true;
            AvailableObjects         = new ObservableCollection <string>();

            Values = new ObservableCollection <PatchValue>();

            queryCollectionSource = new QueryDocumentsCollectionSource();
            QueryResults          = new DocumentsModel(queryCollectionSource)
            {
                Header = "Matching Documents", MinimalHeader = true, HideItemContextMenu = true
            };
            QueryResults.ItemSelection.SelectionChanged += (sender, args) =>
            {
                var firstOrDefault = QueryResults.ItemSelection.GetSelectedItems().FirstOrDefault();
                if (firstOrDefault != null)
                {
                    OriginalDoc.SetText(firstOrDefault.Item.Document.ToJson().ToString());
                    ShowBeforeAndAfterPrompt = false;
                    HasSelection             = true;
                    OnPropertyChanged(() => HasSelection);
                }
                else
                {
                    HasSelection = false;
                    OnPropertyChanged(() => HasSelection);
                    ClearBeforeAndAfter();
                }
            };

            selectedItem.PropertyChanged += (sender, args) =>
            {
                if (PatchOn == PatchOnOptions.Document && string.IsNullOrWhiteSpace(SelectedItem) == false)
                {
                    ApplicationModel.Database.Value.AsyncDatabaseCommands.GetAsync(SelectedItem).
                    ContinueOnSuccessInTheUIThread(doc =>
                    {
                        if (doc == null)
                        {
                            ClearBeforeAndAfter();
                        }
                        else
                        {
                            OriginalDoc.SetText(doc.ToJson().ToString());
                            ShowBeforeAndAfterPrompt = false;
                        }
                    });
                }
            };
        }
示例#4
0
        public QueryModel()
        {
            ModelUrl = "/query";
            ApplicationModel.Current.Server.Value.RawUrl = null;
            SelectedTransformer = new Observable <string> {
                Value = "None"
            };
            SelectedTransformer.PropertyChanged += (sender, args) => Requery();

            ApplicationModel.DatabaseCommands.GetTransformersAsync(0, 256).ContinueOnSuccessInTheUIThread(transformers =>
            {
                Transformers = new List <string> {
                    "None"
                };
                Transformers.AddRange(transformers.Select(definition => definition.Name));

                OnPropertyChanged(() => Transformers);
            });

            queryDocument = new EditorDocument
            {
                Language = SyntaxEditorHelper.LoadLanguageDefinitionFromResourceStream("RavenQuery.langdef")
            };

            ExceptionLine   = -1;
            ExceptionColumn = -1;

            CollectionSource = new QueryDocumentsCollectionSource();
            Observable.FromEventPattern <QueryStatisticsUpdatedEventArgs>(h => CollectionSource.QueryStatisticsUpdated += h,
                                                                          h => CollectionSource.QueryStatisticsUpdated -= h)
            .SampleResponsive(TimeSpan.FromSeconds(0.5))
            .TakeUntil(Unloaded)
            .ObserveOnDispatcher()
            .Subscribe(e =>
            {
                QueryTime = e.EventArgs.QueryTime;
                Results   = e.EventArgs.Statistics;
            });
            Observable.FromEventPattern <QueryErrorEventArgs>(h => CollectionSource.QueryError += h,
                                                              h => CollectionSource.QueryError -= h)
            .ObserveOnDispatcher()
            .Subscribe(e => HandleQueryError(e.EventArgs.Exception));

            DocumentsResult = new DocumentsModel(CollectionSource)
            {
                Header = "Results",
                DocumentNavigatorFactory = (id, index) => DocumentNavigator.Create(id, index, IndexName, CollectionSource.TemplateQuery),
            };

            QueryErrorMessage = new Observable <string>();
            IsErrorVisible    = new Observable <bool>();

            SortBy = new BindableCollection <StringRef>(x => x.Value);
            SortBy.CollectionChanged += HandleSortByChanged;
            SortByOptions             = new BindableCollection <string>(x => x);
            Suggestions    = new BindableCollection <FieldAndTerm>(x => x.Field);
            DynamicOptions = new BindableCollection <string>(x => x)
            {
                "AllDocs"
            };
            AvailableIndexes = new BindableCollection <string>(x => x);

            SpatialQuery = new SpatialQueryModel {
                IndexName = indexName
            };
        }