Beispiel #1
0
        private static Task GetFetchDocumentsMethod(DocumentsModel documentsModel)
        {
            string name;

            if (SelectedCollection.Value == null || string.IsNullOrWhiteSpace(name = SelectedCollection.Value.Name))
            {
                return(Execute.EmptyResult <string>());
            }

            return(ApplicationModel.DatabaseCommands
                   .QueryAsync("Raven/DocumentsByEntityName", new IndexQuery {
                Start = documentsModel.Pager.Skip, PageSize = documentsModel.Pager.PageSize, Query = "Tag:" + name
            }, new string[] {})
                   .ContinueOnSuccess(queryResult =>
            {
                var documents = SerializationHelper.RavenJObjectsToJsonDocuments(queryResult.Results)
                                .Select(x => new ViewableDocument(x))
                                .ToArray();
                documentsModel.Documents.Match(documents);
                if (DocumentsForSelectedCollection.Value.Pager.TotalResults.Value.HasValue == false || DocumentsForSelectedCollection.Value.Pager.TotalResults.Value.Value != queryResult.TotalResults)
                {
                    DocumentsForSelectedCollection.Value.Pager.TotalResults.Value = queryResult.TotalResults;
                }
            })
                   .CatchIgnore <InvalidOperationException>(() => ApplicationModel.Current.AddNotification(new Notification("Unable to retrieve collections from server.", NotificationLevel.Error))));
        }
Beispiel #2
0
 private Task GetFetchDocumentsMethod(DocumentsModel documentsModel)
 {
     return databaseCommands
         .QueryAsync("Raven/DocumentsByEntityName", new IndexQuery { Start = documentsModel.Pager.Skip, PageSize = documentsModel.Pager.PageSize, Query = "Tag:" + Name }, new string[] { })
         .ContinueOnSuccess(queryResult =>
         {
             var documents = SerializationHelper.RavenJObjectsToJsonDocuments(queryResult.Results);
             documentsModel.Documents.Match(documents.Select(x => new ViewableDocument(x)).ToArray());
             Documents.Value.Pager.TotalResults.Value = queryResult.TotalResults;
         });
 }
Beispiel #3
0
        private static DocumentsModel CreateDocumentsModel()
        {
            var documentsModel = new DocumentsModel(new DocumentsCollectionSource())
            {
                DocumentNavigatorFactory = (id, index) => DocumentNavigator.Create(id, index),
                Context = "AllDocuments",
            };

            documentsModel.SetChangesObservable(d => d.DocumentChanges.Select(s => Unit.Default));

            return(documentsModel);
        }
Beispiel #4
0
		private static DocumentsModel CreateDocumentsModel()
		{
			var documentsModel = new DocumentsModel(new DocumentsCollectionSource())
									 {
										 DocumentNavigatorFactory = (id, index) => DocumentNavigator.Create(id, index),
										 Context = "AllDocuments",
									 };

			documentsModel.SetChangesObservable(d => d.DocumentChanges.Select(s => Unit.Default));

			return documentsModel;
		}
Beispiel #5
0
        private void Initialize()
        {
            if (Database.Value == null)
            {
                Database.RegisterOnce(Initialize);
                return;
            }

            var documents = new DocumentsModel(GetFetchDocumentsMethod);
            documents.Pager.PageSize = 15;
            documents.Pager.SetTotalResults(new Observable<long>(Database.Value.Statistics, v => ((DatabaseStatistics)v).CountOfDocuments));
            RecentDocuments.Value = documents;
        }
Beispiel #6
0
		private Task GetFetchDocumentsMethod(DocumentsModel documentsModel)
		{
			if (string.IsNullOrWhiteSpace(Name)) return null;

			return DatabaseCommands
				.QueryAsync("Raven/DocumentsByEntityName", new IndexQuery { Start = documentsModel.Pager.Skip, PageSize = documentsModel.Pager.PageSize, Query = "Tag:" + Name }, new string[] { })
				.ContinueOnSuccess(queryResult =>
					{
						var documents = SerializationHelper.RavenJObjectsToJsonDocuments(queryResult.Results);
						documentsModel.Documents.Match(documents.Select(x => new ViewableDocument(x)).ToArray());
						Documents.Value.Pager.TotalResults.Value = queryResult.TotalResults;
					})
				.CatchIgnore<InvalidOperationException>(() => ApplicationModel.Current.AddNotification(new Notification("Unable to retrieve collections from server.", NotificationLevel.Error)));
		}
		private Task GetFetchDocumentsMethod(DocumentsModel documentsModel)
		{
			var q = new IndexQuery
			{
				Start = model.DocumentsResult.Value.Pager.Skip,
				PageSize = model.DocumentsResult.Value.Pager.PageSize,
				Query = query,
			};

			if (model.SortBy != null && model.SortBy.Count > 0)
			{
				var sortedFields = new List<SortedField>();
				foreach (var sortByRef in model.SortBy)
				{
					var sortBy = sortByRef.Value;
					if (sortBy.EndsWith(QueryModel.SortByDescSuffix))
					{
						var field = sortBy.Remove(sortBy.Length - QueryModel.SortByDescSuffix.Length);
						sortedFields.Add(new SortedField(field) {Descending = true});
					}
					else
						sortedFields.Add(new SortedField(sortBy));
				}
				q.SortedFields = sortedFields.ToArray();
			}

			if (model.IsSpatialQuerySupported)
			{
				q = new SpatialIndexQuery(q)
					{
						Latitude = model.Latitude.HasValue ? model.Latitude.Value : 0,
						Longitude = model.Longitude.HasValue ? model.Longitude.Value : 0,
						Radius = model.Radius.HasValue ? model.Radius.Value : 0,
					};
			}

			return DatabaseCommands.QueryAsync(model.IndexName, q, null)
				.ContinueOnSuccessInTheUIThread(qr =>
				{
					var viewableDocuments = qr.Results.Select(obj => new ViewableDocument(obj.ToJsonDocument())).ToArray();
					documentsModel.Documents.Match(viewableDocuments);
					documentsModel.Pager.TotalResults.Value = qr.TotalResults;

					if (qr.TotalResults == 0)
						SuggestResults();
				})
				.CatchIgnore<WebException>(ex => model.Error = ex.SimplifyError());
		}
Beispiel #8
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"
            };
        }
Beispiel #9
0
		private void Initialize()
		{
			if (Database.Value == null)
			{
				Database.RegisterOnce(Initialize);
				return;
			}

			var documents = new DocumentsModel(GetFetchDocumentsMethod)
			{
				ViewTitle = "Recent Documents", 
				Pager = {PageSize = 15}
			};
			documents.Pager.SetTotalResults(new Observable<long>(Database.Value.Statistics, v => ((DatabaseStatistics)v).CountOfDocuments));
			RecentDocuments.Value = documents;
			documents.Pager.TotalResults.PropertyChanged += (sender, args) => ShowCreateSampleData = documents.Pager.TotalResults.Value == 0;
		}
Beispiel #10
0
        private Task GetFetchDocumentsMethod(DocumentsModel documentsModel)
        {
            if (string.IsNullOrWhiteSpace(Name))
            {
                return(null);
            }

            return(DatabaseCommands
                   .QueryAsync("Raven/DocumentsByEntityName", new IndexQuery {
                Start = documentsModel.Pager.Skip, PageSize = documentsModel.Pager.PageSize, Query = "Tag:" + Name
            }, new string[] { })
                   .ContinueOnSuccess(queryResult =>
            {
                var documents = SerializationHelper.RavenJObjectsToJsonDocuments(queryResult.Results);
                documentsModel.Documents.Match(documents.Select(x => new ViewableDocument(x)).ToArray());
                Documents.Value.Pager.TotalResults.Value = queryResult.TotalResults;
            })
                   .CatchIgnore <InvalidOperationException>(() => ApplicationModel.Current.AddNotification(new Notification("Unable to retrieve collections from server.", NotificationLevel.Error))));
        }
Beispiel #11
0
		private static Task GetFetchDocumentsMethod(DocumentsModel documentsModel)
		{
			string name;
			if (SelectedCollection.Value == null || string.IsNullOrWhiteSpace(name = SelectedCollection.Value.Name))
				return Execute.EmptyResult<string>();

			return ApplicationModel.DatabaseCommands
				.QueryAsync("Raven/DocumentsByEntityName", new IndexQuery {Start = documentsModel.Pager.Skip, PageSize = documentsModel.Pager.PageSize, Query = "Tag:" + name}, new string[] {})
				.ContinueOnSuccess(queryResult =>
				                   	{
				                   		var documents = SerializationHelper.RavenJObjectsToJsonDocuments(queryResult.Results)
				                   			.Select(x => new ViewableDocument(x))
				                   			.ToArray();
				                   		documentsModel.Documents.Match(documents);
										if (DocumentsForSelectedCollection.Value.Pager.TotalResults.Value.HasValue == false || DocumentsForSelectedCollection.Value.Pager.TotalResults.Value.Value != queryResult.TotalResults)
										{
											DocumentsForSelectedCollection.Value.Pager.TotalResults.Value = queryResult.TotalResults;
										}
				                   	})
				.CatchIgnore<InvalidOperationException>(() => ApplicationModel.Current.AddNotification(new Notification("Unable to retrieve collections from server.", NotificationLevel.Error)));
		}
Beispiel #12
0
 private Task GetFetchDocumentsMethod(DocumentsModel documentsModel)
 {
     ApplicationModel.Current.AddNotification(new Notification("Executing query..."));
     var q = new IndexQuery
     {
         Start = (model.Pager.CurrentPage - 1) * model.Pager.PageSize,
         PageSize = model.Pager.PageSize, Query = model.Query.Value
     };
     return asyncDatabaseCommands.QueryAsync(model.IndexName, q, null)
         .ContinueWith(task =>
         {
             if (task.Exception != null)
             {
                 model.Error = task.Exception.ExtractSingleInnerException().SimplifyError();
                 return;
             }
             var qr = task.Result;
             var viewableDocuments = qr.Results.Select(obj => new ViewableDocument(obj.ToJsonDocument())).ToArray();
             documentsModel.Documents.Match(viewableDocuments);
             documentsModel.Pager.TotalResults.Value = qr.TotalResults;
         })
         .ContinueOnSuccess(() => ApplicationModel.Current.AddNotification(new Notification("Query executed.")))
         .Catch();
 }
Beispiel #13
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};
		}
		private Task GetFetchDocumentsMethod(DocumentsModel documentsModel)
		{
			var q = new IndexQuery
			{
				Start = model.DocumentsResult.Value.Pager.Skip,
				PageSize = model.DocumentsResult.Value.Pager.PageSize,
				Query = query,
			};

			if (model.SortBy != null && model.SortBy.Count > 0)
			{
				var sortedFields = new List<SortedField>();
				foreach (var sortByRef in model.SortBy)
				{
					var sortBy = sortByRef.Value;
					if (sortBy.EndsWith(QueryModel.SortByDescSuffix))
					{
						var field = sortBy.Remove(sortBy.Length - QueryModel.SortByDescSuffix.Length);
						sortedFields.Add(new SortedField(field) {Descending = true});
					}
					else
						sortedFields.Add(new SortedField(sortBy));
				}
				q.SortedFields = sortedFields.ToArray();
			}

			if (model.IsSpatialQuerySupported)
			{
				q = new SpatialIndexQuery(q)
					{
						Latitude = model.Latitude.HasValue ? model.Latitude.Value : 0,
						Longitude = model.Longitude.HasValue ? model.Longitude.Value : 0,
						Radius = model.Radius.HasValue ? model.Radius.Value : 0,
					};
			}

			var queryStartTime = DateTime.Now.Ticks;
			var queryEndtime = DateTime.MinValue.Ticks;
			return DatabaseCommands.QueryAsync(model.IndexName, q, null)
				.ContinueWith(task =>
				{
					queryEndtime = DateTime.Now.Ticks;
					return task;
				})
				.Unwrap()
				.ContinueOnSuccessInTheUIThread(qr =>
				{
					model.QueryTime = new TimeSpan(queryEndtime - queryStartTime);
					model.Results = new RavenQueryStatistics
					{
						IndexEtag = qr.IndexEtag,
						IndexName = qr.IndexName,
						IndexTimestamp = qr.IndexTimestamp,
						IsStale = qr.IsStale,
						SkippedResults = qr.SkippedResults,
						Timestamp = DateTime.Now,
						TotalResults = qr.TotalResults
					};
					var viewableDocuments = qr.Results.Select(obj => new ViewableDocument(obj.ToJsonDocument())).ToArray();
					
					var documetsIds = new List<string>();
					ProjectionData.Projections.Clear();
					foreach (var viewableDocument in viewableDocuments)
					{
						var id = string.IsNullOrEmpty(viewableDocument.Id) == false ? viewableDocument.Id : Guid.NewGuid().ToString();

						if (string.IsNullOrEmpty(viewableDocument.Id))
							ProjectionData.Projections.Add(id, viewableDocument);

						documetsIds.Add(id);

						viewableDocument.NeighborsIds = documetsIds;
					}
					
					documentsModel.Documents.Match(viewableDocuments);
					documentsModel.Pager.TotalResults.Value = qr.TotalResults;

					if (qr.TotalResults == 0)
						SuggestResults();
				})
				.CatchIgnore<WebException>(ex => model.Error = ex.SimplifyError());
		}
Beispiel #15
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>();
        }
Beispiel #16
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;
                        }
                    });
                }
            };
        }
Beispiel #17
0
 private Task GetFetchDocumentsMethod(DocumentsModel documentsModel)
 {
     return DatabaseCommands.GetDocumentsAsync(documentsModel.Pager.Skip, documentsModel.Pager.PageSize)
         .ContinueOnSuccess(docs => documentsModel.Documents.Match(docs.Select(x => new ViewableDocument(x)).ToArray()));
 }
Beispiel #18
0
        public DocumentsPageModel()
		{
			ModelUrl = "/documents";
		
			ApplicationModel.Current.Server.Value.RawUrl = null;
            SelectedCollectionSortingMode = new Observable<string> { Value = Settings.Instance.CollectionSortingMode };

            collectionSource = new CollectionDocumentsCollectionSource();
            collectionDocumentsModel = new DocumentsModel(collectionSource)
            {
                DocumentNavigatorFactory = (id, index) =>
                                           DocumentNavigator.Create(id, index, CollectionsIndex,
                                                                    new IndexQuery
                                                                    {
                                                                        Query = "Tag:" + GetSelectedCollectionName()
                                                                    })
            };
            collectionDocumentsModel.SetChangesObservable(d => d.IndexChanges
                     .Where(n => n.Name.Equals(CollectionsIndex, StringComparison.InvariantCulture))
                     .Select(m => Unit.Default));

            allDocumentsDocumentsModel = new DocumentsModel(new DocumentsCollectionSource())
            {
                DocumentNavigatorFactory = (id, index) => DocumentNavigator.Create(id, index),
                Context = "AllDocuments",
            };

            allDocumentsDocumentsModel.SetChangesObservable(d => d.DocumentChanges.Select(s => Unit.Default));

			ravenDocumentsDocumentsModel = new DocumentsModel(new CollectionDocumentsCollectionSource());

			ravenDocumentsDocumentsModel.SetChangesObservable(d => d.DocumentChanges.Select(s => Unit.Default));

            Collections = new BindableCollection<CollectionModel>(model => model.Name)
            {
                new AllDocumentsCollectionModel(),
				new RavenDocumentsCollectionModel()
            };

            SelectedCollection = new Observable<CollectionModel>();
            SelectedCollection.PropertyChanged += (sender, args) =>
            {
                PutCollectionNameInTheUrl();

                var selectedCollectionName = GetSelectedCollectionName();
                if (selectedCollectionName == "")
                {
                    DocumentsModel = allDocumentsDocumentsModel;
                }
				else if (selectedCollectionName == "Raven Documents")
				{
					DocumentsModel = ravenDocumentsDocumentsModel;
				}
                else
                {
                    collectionSource.CollectionName = selectedCollectionName;
                    collectionDocumentsModel.Context = "Collection/" + GetSelectedCollectionName();
                    DocumentsModel = collectionDocumentsModel;
                }
            };

		    SortedCollectionsList = new CollectionViewSource
		    {
		        Source = Collections,
		        SortDescriptions =
		        {
					GetSortDescription()
		        }
		    };

            SelectedCollectionSortingMode.PropertyChanged += (sender, args) =>
			{
			    using (SortedCollectionsList.DeferRefresh())
			    {
			        SortedCollectionsList.SortDescriptions.Clear();
			        SortedCollectionsList.SortDescriptions.Add(GetSortDescription());
			    }

				Settings.Instance.CollectionSortingMode = SelectedCollectionSortingMode.Value;
			};

            CollectionsListWidth = DefaultCollectionsListWidth;
		}
Beispiel #19
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>();
        }
Beispiel #20
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
            };
        }
Beispiel #21
0
        public DocumentsPageModel()
        {
            ModelUrl = "/documents";

            ApplicationModel.Current.Server.Value.RawUrl = null;
            SelectedCollectionSortingMode = new Observable <string> {
                Value = Settings.Instance.CollectionSortingMode
            };

            collectionSource         = new CollectionDocumentsCollectionSource();
            collectionDocumentsModel = new DocumentsModel(collectionSource)
            {
                DocumentNavigatorFactory = (id, index) =>
                                           DocumentNavigator.Create(id, index, CollectionsIndex,
                                                                    new IndexQuery
                {
                    Query = "Tag:" + GetSelectedCollectionName()
                })
            };
            collectionDocumentsModel.SetChangesObservable(d => d.IndexChanges
                                                          .Where(n => n.Name.Equals(CollectionsIndex, StringComparison.InvariantCulture))
                                                          .Select(m => Unit.Default));

            allDocumentsDocumentsModel = new DocumentsModel(new DocumentsCollectionSource())
            {
                DocumentNavigatorFactory = (id, index) => DocumentNavigator.Create(id, index),
                Context = "AllDocuments",
            };

            allDocumentsDocumentsModel.SetChangesObservable(d => d.DocumentChanges.Select(s => Unit.Default));

            ravenDocumentsDocumentsModel = new DocumentsModel(new CollectionDocumentsCollectionSource());

            ravenDocumentsDocumentsModel.SetChangesObservable(d => d.DocumentChanges.Select(s => Unit.Default));

            Collections = new BindableCollection <CollectionModel>(model => model.Name)
            {
                new AllDocumentsCollectionModel(),
                new RavenDocumentsCollectionModel()
            };

            SelectedCollection = new Observable <CollectionModel>();
            SelectedCollection.PropertyChanged += (sender, args) =>
            {
                PutCollectionNameInTheUrl();

                var selectedCollectionName = GetSelectedCollectionName();
                if (selectedCollectionName == "")
                {
                    DocumentsModel = allDocumentsDocumentsModel;
                }
                else if (selectedCollectionName == "Raven Documents")
                {
                    DocumentsModel = ravenDocumentsDocumentsModel;
                }
                else
                {
                    collectionSource.CollectionName  = selectedCollectionName;
                    collectionDocumentsModel.Context = "Collection/" + GetSelectedCollectionName();
                    DocumentsModel = collectionDocumentsModel;
                }
            };

            SortedCollectionsList = new CollectionViewSource
            {
                Source           = Collections,
                SortDescriptions =
                {
                    GetSortDescription()
                }
            };

            SelectedCollectionSortingMode.PropertyChanged += (sender, args) =>
            {
                using (SortedCollectionsList.DeferRefresh())
                {
                    SortedCollectionsList.SortDescriptions.Clear();
                    SortedCollectionsList.SortDescriptions.Add(GetSortDescription());
                }

                Settings.Instance.CollectionSortingMode = SelectedCollectionSortingMode.Value;
            };

            CollectionsListWidth = DefaultCollectionsListWidth;
        }
Beispiel #22
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"};

		}
Beispiel #23
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;
							}
						});
	        };
        }
 public ExportDocumentDetailsCommand(DocumentsModel model)
 {
     this.model = model;
 }