public override void LoadModelParameters(string parameters)
		{
			var urlParser = new UrlParser(parameters);
			if (urlParser.GetQueryParam("mode") == "new")
			{
				IsNewTransformer = true;
				Header = "New Transformer";

				UpdateFromTransformer(new TransformerDefinition());

				return;
			}

			var name = urlParser.Path;
			if (string.IsNullOrWhiteSpace(name))
				HandleTransformerNotFound(null);

			Header = name;
			OriginalName = name;
			IsNewTransformer = false;

			DatabaseCommands.GetTransformerAsync(name)
				.ContinueOnUIThread(task =>
				{
					if (task.IsFaulted || task.Result == null)
					{
						HandleTransformerNotFound(name);
						return;
					}

					UpdateFromTransformer(task.Result);
				}).Catch();
		}
Esempio n. 2
0
		public override void Execute(object parameter)
		{
			bool shouldRedirect = true;

			var urlParser = new UrlParser(UrlUtil.Url);
			if (urlParser.GetQueryParam("database") == databaseName)
				shouldRedirect = false;

			urlParser.SetQueryParam("database", databaseName);

			var server = ApplicationModel.Current.Server.Value;
			server.SetCurrentDatabase(urlParser);
			server.SelectedDatabase.Value.AsyncDatabaseCommands
				.EnsureSilverlightStartUpAsync()
				.Catch();

			var updateAllFromServer = View.UpdateAllFromServer();
			refreshStaticModels
				.Except(updateAllFromServer.Select(x=>x.GetType()))
				.Select(model => (Model) Activator.CreateInstance(model))
				.ForEach(model => model.ForceTimerTicked());
			
			
			if (shouldRedirect)
			{
				UrlUtil.Navigate(urlParser.BuildUrl());
			}
		}
Esempio n. 3
0
		public static void Navigate(string url)
		{
			if (url == null)
				return;

			url = new UrlParser(url).BuildUrl();
			Navigate((new Uri(url, UriKind.Relative)));
		}
Esempio n. 4
0
		public override void LoadModelParameters(string parameters)
		{
			IndexName = new UrlParser(parameters).Path.Trim('/');

			var allErrors = Database.Value.Statistics.Value.Errors;
			if (IsShowingErrorForASpecificIndex)
				allErrors = allErrors.Where(e => e.Index == IndexName).ToArray();
			Errors = allErrors;
		}
Esempio n. 5
0
		public override void LoadModelParameters(string parameters)
		{
			var url = new UrlParser(UrlUtil.Url);

			if (url.GetQueryParam("mode") == "new")
			{
				Mode = DocumentMode.New;
				return;
			}

			var docId = url.GetQueryParam("id");
			var neighbors = url.GetQueryParam("neighbors");
			if (neighbors != null)
				NeighborIds = neighbors.Split(',').ToList();
			if (string.IsNullOrWhiteSpace(docId) == false)
			{
				Mode = DocumentMode.DocumentWithId;
				LocalId = docId;
				SetCurrentDocumentKey(docId);
				DatabaseCommands.GetAsync(docId)
					.ContinueOnSuccessInTheUIThread(newdoc =>
														{
															if (newdoc == null)
															{
																HandleDocumentNotFound();
																return;
															}
															document.Value = newdoc;
															isLoaded = true;
														})
					.Catch();
				return;
			}

			projectionId = url.GetQueryParam("projection");
			if (string.IsNullOrWhiteSpace(projectionId) == false)
			{
				Mode = DocumentMode.Projection;
				try
				{
					ViewableDocument viewableDocument;
					ProjectionData.Projections.TryGetValue(projectionId, out viewableDocument);

					var ravenJObject = RavenJObject.Parse(viewableDocument.InnerDocument.ToJson().ToString(Formatting.None));
					var newdoc = ravenJObject.ToJsonDocument();
					document.Value = newdoc;
					LocalId = projectionId;
				}
				catch
				{
					HandleDocumentNotFound();
					throw; // Display why we couldn't parse the projection from the URL correctly
				}
			}
		}
Esempio n. 6
0
		public override void LoadModelParameters(string parameters)
		{
			var urlParser = new UrlParser(parameters);
			var name = urlParser.GetQueryParam("name");
			if (SelectedCollection.Value != null && SelectedCollection.Value.Documents.Value != null)
			{
				SelectedCollection.Value.Documents.Value.Pager.SetSkip(urlParser);
				ForceTimerTicked();
			}
			initialSelectedDatabaseName = name;
		}
Esempio n. 7
0
		protected override void OnViewLoaded()
		{
			var indexToShow = new UrlParser(UrlUtil.Url).GetQueryParam("index");
            if (indexToShow != null)
            {
                SelectedViewOption.Value = indexToShow;
                Breadcrumb = "Indexes";
                OnPropertyChanged(() => Breadcrumb);
            }

		    base.OnViewLoaded();
		}
Esempio n. 8
0
		protected override Task TimerTickedAsync()
		{
			return DatabaseCommands.GetTermsCount("Raven/DocumentsByEntityName", "Tag", "", 100)
				.ContinueOnSuccess(Update)
				.CatchIgnore<WebException>(() =>
				       	{
							var urlParser = new UrlParser(UrlUtil.Url);
				       		if (urlParser.RemoveQueryParam("name"))
				       			UrlUtil.Navigate(urlParser.BuildUrl());
				       		ApplicationModel.Current.AddNotification(new Notification("Unable to retrieve collections from server.", NotificationLevel.Error));
				       	});
		}
        public static DocumentNavigator FromUrl(UrlParser parser)
        {
            var mode = parser.GetQueryParam("navigationMode");

            if (mode == "allDocs")
                return AllDocumentsNavigator.AllDocumentsFromUrl(parser);
            
            if (mode == "index")
                return IndexDocumentsNavigator.IndexNavigatorFromUrl(parser);

            return new SingleDocumentNavigator(parser.GetQueryParam("id"));
        }
Esempio n. 10
0
		private void PutCollectionNameInTheUrl()
		{
			var urlParser = new UrlParser(UrlUtil.Url);
			var collection = SelectedCollection.Value;
			if (collection == null)
				return;
			var name = collection.Name;
			initialSelectedDatabaseName = name;
			if (urlParser.GetQueryParam("name") != name)
			{
				urlParser.SetQueryParam("name", name);
				UrlUtil.Navigate(urlParser.BuildUrl());
			}
		}
		public override void Execute(object parameter)
		{
			var urlParser = new UrlParser("/edit");
			var friendly = (parameter as FriendlyDocument);
			if (friendly != null)
			{
				urlParser.SetQueryParam(friendly.IsProjection ? "projection" : "id", friendly.Id);
				
				if (friendly.NeighborsIds != null)
					urlParser.SetQueryParam("neighbors", string.Join(",", friendly.NeighborsIds));
			}

			UrlUtil.Navigate(urlParser.BuildUrl());
		}
Esempio n. 12
0
		public override void Execute(object parameter)
		{
			var urlParser = new UrlParser(UrlUtil.Url);
			if (urlParser.GetQueryParam("database") == databaseName)
			{
			    return;
			}
			if (navigateAfter) 
				urlParser = new UrlParser("/documents");

			urlParser.SetQueryParam("database", databaseName);
			// MainPage.ContentFrame_Navigated takes care of actually responding to the db name change
			UrlUtil.Navigate(urlParser.BuildUrl());
		}
Esempio n. 13
0
        // EnsureDatabaseParameterIncluded
        private void ContentFrame_Navigating(object sender, NavigatingCancelEventArgs e)
        {
            if (navigationMode != NavigationMode.New) return;

            var urlParser = new UrlParser(e.Uri.ToString());
            if (urlParser.GetQueryParam("database") != null)
                return;

            e.Cancel = true;
            navigationMode = NavigationMode.Refresh;
            urlParser.SetQueryParam("database", ApplicationModel.Current.Server.Value.SelectedDatabase.Value.Name);
            urlParser.NavigateTo();
            navigationMode = NavigationMode.New;
        }
Esempio n. 14
0
		private void Initialize()
		{
            if (DesignerProperties.IsInDesignTool)
            {
                return;
            }

			documentStore = new DocumentStore
			{
				Url = Url
			};

			var urlParser = new UrlParser(UrlUtil.Url);
			var apiKey = urlParser.GetQueryParam("api-key");
			if (string.IsNullOrEmpty(apiKey) == false)
				documentStore.ApiKey = apiKey;

			documentStore.Initialize();

			// We explicitly enable this for the Studio, we rely on SL to actually get us the credentials, and that 
			// already gives the user a clear warning about the dangers of sending passwords in the clear. I think that 
			// this is sufficient warning and we don't require an additional step, so we can disable this check safely.
			documentStore.JsonRequestFactory.
				EnableBasicAuthenticationOverUnsecureHttpEvenThoughPasswordsWouldBeSentOverTheWireInClearTextToBeStolenByHackers =
				true;
			
			documentStore.JsonRequestFactory.ConfigureRequest += (o, eventArgs) =>
			{
				if (onWebRequest != null)
					onWebRequest(eventArgs.Request);
			};

			defaultDatabase = new[] { new DatabaseModel(DatabaseModel.DefaultDatabaseName, documentStore) };
			Databases.Set(defaultDatabase);
			SetCurrentDatabase(new UrlParser(UrlUtil.Url));

			DisplayBuildNumber();
			DisplyaLicenseStatus();

			var changeDatabaseCommand = new ChangeDatabaseCommand();
			SelectedDatabase.PropertyChanged += (sender, args) =>
			{
				if (SelectedDatabase.Value == null)
					return;
				var databaseName = SelectedDatabase.Value.Name;
				Command.ExecuteCommand(changeDatabaseCommand, databaseName);
			};
		}
Esempio n. 15
0
		public override void LoadModelParameters(string parameters)
		{
			var urlParser = new UrlParser(parameters);

			IndexName = urlParser.Path.Trim('/');

			DatabaseCommands.GetIndexAsync(IndexName)
				.ContinueOnSuccessInTheUIThread(definition =>
				{
					if (definition == null)
					{
						IndexDefinitionModel.HandleIndexNotFound(IndexName);
						return;
					}
				}).Catch();
		}
Esempio n. 16
0
		public override void Execute(object parameter)
		{
			var urlParser = new UrlParser("/edit");

			if (string.IsNullOrEmpty(viewableDocument.Id))
			{
				var projection = viewableDocument.InnerDocument.ToJson().ToString(Formatting.None);
				urlParser.SetQueryParam("projection", projection);
			}
			else
			{
				urlParser.SetQueryParam("id", viewableDocument.Id);
			}

			UrlUtil.Navigate(urlParser.BuildUrl());
		}
Esempio n. 17
0
		public override void Execute(object parameter)
		{
			var urlParser = new UrlParser("/edit");

			if (string.IsNullOrEmpty(viewableDocument.Id))
			{
				var key = ProjectionData.Projections.First(x => x.Value == viewableDocument).Key;
				urlParser.SetQueryParam("projection", key);
			}
			else
			{
				urlParser.SetQueryParam("id", viewableDocument.Id);
			}

			UrlUtil.Navigate(urlParser.BuildUrl());
		}
Esempio n. 18
0
		public override void LoadModelParameters(string parameters)
		{
			var url = new UrlParser(UrlUtil.Url);

			if (url.GetQueryParam("mode") == "new")
			{
				Mode = DocumentMode.New;
				return;
			}

			var docId = url.GetQueryParam("id");
			if (string.IsNullOrWhiteSpace(docId) == false)
			{
				Mode = DocumentMode.DocumentWithId;
				SetCurrentDocumentKey(docId);
				DatabaseCommands.GetAsync(docId)
					.ContinueOnSuccessInTheUIThread(newdoc =>
									   {
										   if (newdoc == null)
										   {
											   HandleDocumentNotFound();
											   return;
										   }
										   document.Value = newdoc;
										   isLoaded = true;
									   	originalId = docId;
									   })
					.Catch();
				return;
			}

			var projection = url.GetQueryParam("projection");
			if (string.IsNullOrWhiteSpace(projection) == false)
			{
				Mode = DocumentMode.Projection;
				try
				{
					var newdoc = RavenJObject.Parse(projection).ToJsonDocument();
					document.Value = newdoc;
				}
				catch
				{
					HandleDocumentNotFound();
					throw; // Display why we couldn't parse the projection from the URL correctly
				}
			}
		}
Esempio n. 19
0
		public static void Navigate(string url, bool dontOpenNewTab = false)
		{
			if (url == null)
				return;

			url = new UrlParser(url).BuildUrl();

			Execute.OnTheUI(() =>
			                	{
									if (Keyboard.Modifiers == ModifierKeys.Control && dontOpenNewTab == false)
			                		{
			                			OpenUrlOnANewTab(url);
										return;
			                		}

			                		Navigate((new Uri(url, UriKind.Relative)));
			                	});
		}
Esempio n. 20
0
        public static void Navigate(string url)
        {
            if (url == null)
            {
                return;
            }

            url = new UrlParser(url).BuildUrl();

            Execute.OnTheUI(() =>
            {
                if (Keyboard.Modifiers == ModifierKeys.Control)
                {
                    OpenUrlOnANewTab(url);
                    return;
                }

                Navigate((new Uri(url, UriKind.Relative)));
            });
        }
Esempio n. 21
0
		public override void Execute(object parameter)
		{
			bool shouldRedirect = true;

			var urlParser = new UrlParser(UrlUtil.Url);
			if (urlParser.GetQueryParam("database") == databaseName)
				shouldRedirect = false;

			urlParser.SetQueryParam("database", databaseName);

			var server = ApplicationModel.Current.Server.Value;
			server.SetCurrentDatabase(urlParser);
			server.SelectedDatabase.Value.AsyncDatabaseCommands
				.EnsureSilverlightStartUpAsync()
				.Catch();

			if (shouldRedirect)
			{
				UrlUtil.Navigate(urlParser.BuildUrl());
			}
		}
Esempio n. 22
0
		private void Initialize()
		{
			if (DesignerProperties.IsInDesignTool)
				return;

			documentStore = new DocumentStore
			{
				Url = Url
			};

			var urlParser = new UrlParser(UrlUtil.Url);
			var apiKey = urlParser.GetQueryParam("api-key");
			if (string.IsNullOrEmpty(apiKey) == false)
				documentStore.ApiKey = apiKey;

			documentStore.Initialize();

			// We explicitly enable this for the Studio, we rely on SL to actually get us the credentials, and that 
			// already gives the user a clear warning about the dangers of sending passwords in the clear. I think that 
			// this is sufficient warning and we don't require an additional step, so we can disable this check safely.
			documentStore.JsonRequestFactory.
			              EnableBasicAuthenticationOverUnsecuredHttpEvenThoughPasswordsWouldBeSentOverTheWireInClearTextToBeStolenByHackers
				=
				true;

			documentStore.JsonRequestFactory.ConfigureRequest += (o, eventArgs) =>
			{
				if (onWebRequest != null)
					onWebRequest(eventArgs.Request);
			};

			defaultDatabase = new[] {Constants.SystemDatabase};
			Databases.Set(defaultDatabase);
			SetCurrentDatabase(new UrlParser(UrlUtil.Url));

			//DisplayRawUrl();
			DisplayBuildNumber();
			DisplayLicenseStatus();
			TimerTickedAsync();
		}
Esempio n. 23
0
		public static void Navigate(string url)
		{
			if (url == null)
				return;

			if (Keyboard.Modifiers == ModifierKeys.Control)
			{
				var hostUrl = HtmlPage.Document.DocumentUri.OriginalString;
				var fregmentIndex = hostUrl.IndexOf('#');
				string host = fregmentIndex != -1 ? hostUrl.Substring(0, fregmentIndex + 1) : hostUrl;

				//Fix for issue with FireFox
				if (host[host.Length - 1] != '#')
					host += "#";

				HtmlPage.Window.Navigate(new Uri(host + url, UriKind.Absolute), "_blank");
				return;
			}

			url = new UrlParser(url).BuildUrl();
			Navigate((new Uri(url, UriKind.Relative)));
		}
Esempio n. 24
0
	    protected override async void OnViewLoaded()
	    {
			if (firstLoad)
				RegisterToDatabaseChange();

			firstLoad = false;

			Status.Sections.Clear();
			OnPropertyChanged(() => CurrentDatabase);
		    await DatabaseCommands.GetStatisticsAsync();

		    Status.Sections.Add(new StatisticsStatusSectionModel());
			Status.Sections.Add(new LogsStatusSectionModel());
			Status.Sections.Add(new AlertsStatusSectionModel());
			Status.Sections.Add(new IndexesErrorsStatusSectionModel());
			Status.Sections.Add(new ReplicationStatisticsStatusSectionModel());
			Status.Sections.Add(new UserInfoStatusSectionModel());

			var url = new UrlParser(UrlUtil.Url);

			var id = url.GetQueryParam("id");
			if (string.IsNullOrWhiteSpace(id) == false)
			{
				switch (id)
				{
					case "indexes-errors":
						Status.SelectedSection.Value = Status.Sections[3];
						break;
					case "replication":
						Status.SelectedSection.Value = Status.Sections[4];
						break;
					default:
						Status.SelectedSection.Value = Status.Sections[0];
						break;
				}
			}
			else
				Status.SelectedSection.Value = Status.Sections[0];
	    }
Esempio n. 25
0
	    private void PutCollectionNameInTheUrl()
		{
			var urlParser = new UrlParser(UrlUtil.Url);
			var collection = SelectedCollection.Value;
			if (collection == null)
				return;
			var name = collection.Name;
			initialSelectedCollectionName = name;
			if (urlParser.GetQueryParam("collection") != name)
			{
			    if (name != "")
			    {
			        urlParser.SetQueryParam("collection", name);
			    }
			    else
			    {
			        urlParser.RemoveQueryParam("collection");
			    }

			    UrlUtil.Navigate(urlParser.BuildUrl());
			}
		}
Esempio n. 26
0
		public override void LoadModelParameters(string parameters)
		{
			var urlParser = new UrlParser(parameters);

			IndexName = urlParser.Path.Trim('/');

			DatabaseCommands.GetIndexAsync(IndexName)
				.ContinueOnSuccessInTheUIThread(definition =>
				{
					if (definition == null)
					{
						IndexDefinitionModel.HandleIndexNotFound(IndexName);
						return;
					}
					fields.Match(definition.Fields);

					foreach (var field in fields)
					{
						var localterms = fieldsTermsDictionary[field] = new List<string>();
						GetTermsForField(field, localterms);
					}
				}).Catch();
		}
Esempio n. 27
0
		public void RestoreHistory()
		{
		    var url = new UrlParser(UrlUtil.Url);
		    var recentQueryHashCode = url.GetQueryParam("recentQuery");

            if (PerDatabaseState.QueryHistoryManager.IsHistoryLoaded)
            {
                ApplyQueryState(recentQueryHashCode);
            }
            else
            {
                PerDatabaseState.QueryHistoryManager.WaitForHistoryAsync()
                    .ContinueOnUIThread(_ => ApplyQueryState(recentQueryHashCode));
            }	    
		}
Esempio n. 28
0
        public override void LoadModelParameters(string parameters)
        {
            var urlParser = new UrlParser(parameters);

            UpdateAvailableIndexes();
            ClearCurrentQuery();

            if (urlParser.GetQueryParam("mode") == "dynamic")
            {
                var collection = urlParser.GetQueryParam("collection");

                IsDynamicQuery = true;
                DatabaseCommands.GetTermsAsync("Raven/DocumentsByEntityName", "Tag", "", 100)
                    .ContinueOnSuccessInTheUIThread(collections =>
                    {
                        DynamicOptions.Match(new[] { "AllDocs" }.Concat(collections).ToArray());

                        string selectedOption = null;
                        if (!string.IsNullOrEmpty(collection))
                            selectedOption = DynamicOptions.FirstOrDefault(s => s.Equals(collection));

                        if (selectedOption == null)
                            selectedOption = DynamicOptions[0];

                        DynamicSelectedOption = selectedOption;
                        DocumentsResult.SetChangesObservable(null);
                    });

                return;
            }

            IsDynamicQuery = false;
            var newIndexName = urlParser.Path.Trim('/');

            if (string.IsNullOrEmpty(newIndexName))
            {
                if (AvailableIndexes.Any())
                {
                    NavigateToIndexQuery(AvailableIndexes.FirstOrDefault());
                    return;
                }
            }

            IndexName = newIndexName;

	        if (Database.Value.Statistics.Value.Errors.Any(error => error.Index == IndexName))
	        {
		        QueryErrorMessage.Value = "The index " + IndexName + " has errors";
		        IsErrorVisible.Value = true;
	        }

	        DatabaseCommands.GetIndexAsync(IndexName)
                .ContinueOnUIThread(task =>
                {
                    if (task.IsFaulted || task.Result == null)
                    {
                        if (AvailableIndexes.Any())
                        {

                            NavigateToIndexQuery(AvailableIndexes.FirstOrDefault());
                        }
                        else
                        {
                            NavigateToIndexesList();
                        }
                        return;
                    }

                    var fields = task.Result.Fields;
                    QueryIndexAutoComplete = new QueryIndexAutoComplete(fields, IndexName, QueryDocument);

	                var regex1 = new Regex(@"(?:SpatialIndex\.Generate|SpatialGenerate)");
	                var regex2 = new Regex(@"(?:SpatialIndex\.Generate|SpatialGenerate)\(@?\""([^\""]+)\""");

	                var strs = task.Result.Maps.ToList();
					if (task.Result.Reduce != null)
						strs.Add(task.Result.Reduce);
					
					var legacyFields = new HashSet<string>();
					foreach (var map in task.Result.Maps)
					{
						var count = regex1.Matches(map).Count;
						var matches = regex2.Matches(map).Cast<Match>().Select(x => x.Groups[1].Value).ToList();
						if (matches.Count < count)
							legacyFields.Add(Constants.DefaultSpatialFieldName);

						matches.ForEach(x => legacyFields.Add(x));
					}

					var spatialFields = task.Result.SpatialIndexes
						.Select(x => new SpatialQueryField
						{
							Name = x.Key,
							IsGeographical = x.Value.Type == SpatialFieldType.Geography,
							Units = x.Value.Units
						})
						.ToList();

					legacyFields.ForEach(x => spatialFields.Add(new SpatialQueryField
						{
							Name = x,
							IsGeographical = true,
							Units = SpatialUnits.Kilometers
						}));

					UpdateSpatialFields(spatialFields);

                    HasTransform = !string.IsNullOrEmpty(task.Result.TransformResults);

                    DocumentsResult.SetChangesObservable(
                        d => d.IndexChanges
                                 .Where(n =>n.Name.Equals(indexName,StringComparison.InvariantCulture))
                                 .Select(m => Unit.Default));
		
                    SetSortByOptions(fields);
                    RestoreHistory();
                }).Catch();


        }
Esempio n. 29
0
	    private bool HasIndexChanged(string newIndexName)
	    {
            if (newIndexName.StartsWith("dynamic", StringComparison.OrdinalIgnoreCase))
            {
                return false;
            }

	        var currentIndex = new UrlParser(UrlUtil.Url.Substring(ModelUrl.Length)).Path.Trim('/');
            return !newIndexName.Equals(currentIndex, StringComparison.OrdinalIgnoreCase);
	    }
Esempio n. 30
0
		public override void LoadModelParameters(string parameters)
		{
			ShowErrorsOnly = new UrlParser(parameters).Path.Trim('/') == "error";
		}
Esempio n. 31
0
 private void SelectDatabase(DatabaseModel database)
 {
     var urlParser = new UrlParser(UrlUtil.Url);
     urlParser.SetQueryParam("database", database.Name);
     urlParser.NavigateTo();
 }