Inheritance: Raven.Studio.Models.SettingsSectionModel, IAutoCompleteSuggestionProvider
Beispiel #1
0
        protected override void OnViewLoaded()
        {
            var databaseName = ApplicationModel.Current.Server.Value.SelectedDatabase.Value.Name;

			if(databaseName == Constants.SystemDatabase)
			{
				var apiKeys = new ApiKeysSectionModel();
				Settings.Sections.Add(apiKeys);
				Settings.SelectedSection.Value = apiKeys;
				Settings.Sections.Add(new PeriodicBackupSettingsSectionModel());
				Settings.Sections.Add(new WindowsAuthSettingsSectionModel());

				return; 
			}

	        ApplicationModel.Current.Server.Value.DocumentStore
		        .AsyncDatabaseCommands
		        .ForDefaultDatabase()
		        .CreateRequest("/admin/databases/" + databaseName, "GET")
		        .ReadResponseJsonAsync()
		        .ContinueOnSuccessInTheUIThread(doc =>
		        {
			        if (doc == null)
				        return;

			        var databaseDocument = ApplicationModel.Current.Server.Value.DocumentStore.Conventions.CreateSerializer()
						.Deserialize<DatabaseDocument>(new RavenJTokenReader(doc));
			        Settings.DatabaseDocument = databaseDocument;

			        var databaseSettingsSectionViewModel = new DatabaseSettingsSectionViewModel();
			        Settings.Sections.Add(databaseSettingsSectionViewModel);
			        Settings.SelectedSection.Value = databaseSettingsSectionViewModel;

					Settings.Sections.Add(new PeriodicBackupSettingsSectionModel());

			        string activeBundles;
			        databaseDocument.Settings.TryGetValue("Raven/ActiveBundles", out activeBundles);

			        if (activeBundles != null)
			        {
				        if (activeBundles.Contains("Quotas"))
					        Settings.Sections.Add(new QuotaSettingsSectionModel());

				        if (activeBundles.Contains("Replication"))
					        Settings.Sections.Add(new ReplicationSettingsSectionModel());

				        if (activeBundles.Contains("Versioning"))
					        Settings.Sections.Add(new VersioningSettingsSectionModel());

				        if (activeBundles.Contains("Authorization"))
					        Settings.Sections.Add(new AuthorizationSettingsSectionModel());
			        }

			        foreach (var settingsSectionModel in Settings.Sections)
			        {
				        settingsSectionModel.LoadFor(databaseDocument);
			        }
		        });
        }
Beispiel #2
0
        protected override void OnViewLoaded()
        {
            var databaseName = ApplicationModel.Current.Server.Value.SelectedDatabase.Value.Name;

            if (databaseName == Constants.SystemDatabase)
            {
                var apiKeys = new ApiKeysSectionModel();
                Settings.Sections.Add(apiKeys);
                Settings.SelectedSection.Value = apiKeys;
                Settings.Sections.Add(new WindowsAuthSettingsSectionModel());

                return;
            }

            ApplicationModel.Current.Server.Value.DocumentStore
            .AsyncDatabaseCommands
            .ForSystemDatabase()
            .CreateRequest("/admin/databases/" + databaseName, "GET")
            .ReadResponseJsonAsync()
            .ContinueOnSuccessInTheUIThread(doc =>
            {
                if (doc == null)
                {
                    return;
                }

                var databaseDocument = ApplicationModel.Current.Server.Value.DocumentStore.Conventions.CreateSerializer()
                                       .Deserialize <DatabaseDocument>(new RavenJTokenReader(doc));
                Settings.DatabaseDocument = databaseDocument;

                var databaseSettingsSectionViewModel = new DatabaseSettingsSectionViewModel();
                Settings.Sections.Add(databaseSettingsSectionViewModel);
                Settings.SelectedSection.Value = databaseSettingsSectionViewModel;

                Settings.Sections.Add(new PeriodicBackupSettingsSectionModel());

                string activeBundles;
                databaseDocument.Settings.TryGetValue("Raven/ActiveBundles", out activeBundles);

                if (activeBundles != null)
                {
                    var bundles = activeBundles.Split(';').ToList();

                    if (bundles.Contains("Quotas"))
                    {
                        Settings.Sections.Add(new QuotaSettingsSectionModel());
                    }

                    if (bundles.Contains("Replication"))
                    {
                        Settings.Sections.Add(new ReplicationSettingsSectionModel());
                    }

                    if (bundles.Contains("SqlReplication"))
                    {
                        Settings.Sections.Add(new SqlReplicationSettingsSectionModel());
                    }

                    if (bundles.Contains("Versioning"))
                    {
                        Settings.Sections.Add(new VersioningSettingsSectionModel());
                    }

                    if (bundles.Contains("Authorization"))
                    {
                        Settings.Sections.Add(new AuthorizationSettingsSectionModel());
                    }
                }

                foreach (var settingsSectionModel in Settings.Sections)
                {
                    settingsSectionModel.LoadFor(databaseDocument);
                }

                var req = ApplicationModel.DatabaseCommands.ForSystemDatabase().CreateRequest("/plugins/status".NoCache(), "GET");

                req.ReadResponseJsonAsync().ContinueOnSuccessInTheUIThread(item =>
                {
                    var plugins = ((RavenJObject)item).Deserialize <PluginsStatus>(new DocumentConvention());

                    if (plugins == null || plugins.Plugins.Contains("Raven.Bundles.Authorization", StringComparer.InvariantCultureIgnoreCase) == false)
                    {
                        return;
                    }

                    var authSection = new AuthorizationSettingsSectionModel();
                    Settings.Sections.Add(authSection);
                    authSection.LoadFor(databaseDocument);
                });
            });
        }
Beispiel #3
0
        protected override async void OnViewLoaded()
        {
            if (firstLoad)
            {
                RegisterToDatabaseChange();
            }

            firstLoad = false;

            var databaseName = ApplicationModel.Current.Server.Value.SelectedDatabase.Value.Name;

            Settings.Sections.Clear();
            OnPropertyChanged(() => CurrentDatabase);
            if (databaseName == Constants.SystemDatabase)
            {
                var apiKeys = new ApiKeysSectionModel();
                Settings.Sections.Add(apiKeys);
                Settings.SelectedSection.Value = apiKeys;
                Settings.Sections.Add(new WindowsAuthSettingsSectionModel());

                return;
            }

            var debug = await ApplicationModel.DatabaseCommands.CreateRequest("/debug/config".NoCache(), "GET").ReadResponseJsonAsync();

            var bundles = ApplicationModel.CreateSerializer()
                          .Deserialize <List <string> >(
                new RavenJTokenReader(debug.SelectToken("ActiveBundles")));
            var addedVersioning = false;

            if (ApplicationModel.Current.Server.Value.UserInfo.IsAdminGlobal)
            {
                var doc = await ApplicationModel.Current.Server.Value.DocumentStore
                          .AsyncDatabaseCommands
                          .ForSystemDatabase()
                          .CreateRequest("/admin/databases/" + databaseName, "GET")
                          .ReadResponseJsonAsync();

                if (doc != null)
                {
                    var databaseDocument =
                        ApplicationModel.CreateSerializer().Deserialize <DatabaseDocument>(new RavenJTokenReader(doc));
                    Settings.DatabaseDocument = databaseDocument;

                    var databaseSettingsSectionViewModel = new DatabaseSettingsSectionViewModel();
                    Settings.Sections.Add(databaseSettingsSectionViewModel);
                    Settings.SelectedSection.Value = databaseSettingsSectionViewModel;
                    Settings.Sections.Add(new PeriodicBackupSettingsSectionModel());

                    //Bundles that need the database document
                    if (bundles.Contains("Quotas"))
                    {
                        Settings.Sections.Add(new QuotaSettingsSectionModel());
                    }

                    if (bundles.Contains("Versioning"))
                    {
                        AddModel(new VersioningSettingsSectionModel());
                        addedVersioning = true;
                    }

                    foreach (var settingsSectionModel in Settings.Sections)
                    {
                        settingsSectionModel.LoadFor(databaseDocument);
                    }
                }
            }

            //Bundles that don't need the database document
            if (bundles.Contains("Replication"))
            {
                AddModel(new ReplicationSettingsSectionModel());
            }

            if (bundles.Contains("Versioning") && addedVersioning == false)
            {
                AddModel(new VersioningSettingsSectionModel());
            }

            if (bundles.Contains("SqlReplication"))
            {
                AddModel(new SqlReplicationSettingsSectionModel());
            }

            if (bundles.Contains("ScriptedIndexResults"))
            {
                AddModel(new ScriptedIndexSettingsSectionModel());
            }

            if (bundles.Contains("Authorization"))
            {
                var triggers = ApplicationModel.Current.Server.Value.SelectedDatabase.Value.Statistics.Value.Triggers;
                if (triggers.Any(info => info.Name.Contains("Authorization")))
                {
                    var authModel = new AuthorizationSettingsSectionModel();
                    Settings.Sections.Add(authModel);
                    authModel.LoadFor(null);
                }
            }

            if (Settings.Sections.Count == 0)
            {
                Settings.Sections.Add(new NoSettingsSectionModel());
            }

            var url = new UrlParser(UrlUtil.Url);

            var id = url.GetQueryParam("id");

            if (string.IsNullOrWhiteSpace(id) == false)
            {
                switch (id)
                {
                case "scripted":
                    if (Settings.Sections.Any(model => model is ScriptedIndexSettingsSectionModel))
                    {
                        Settings.SelectedSection.Value = Settings.Sections.FirstOrDefault(model => model is ScriptedIndexSettingsSectionModel);
                    }
                    break;
                }
            }
            else
            {
                Settings.SelectedSection.Value = Settings.Sections[0];
            }
        }
Beispiel #4
0
        protected override void OnViewLoaded()
        {
            var databaseName = ApplicationModel.Current.Server.Value.SelectedDatabase.Value.Name;

            if (databaseName == Constants.SystemDatabase)
            {
                var apiKeys = new ApiKeysSectionModel();
                Settings.Sections.Add(apiKeys);
                Settings.SelectedSection.Value = apiKeys;
                Settings.Sections.Add(new PeriodicBackupSettingsSectionModel());
                Settings.Sections.Add(new WindowsAuthSettingsSectionModel());

                return;
            }

            ApplicationModel.Current.Server.Value.DocumentStore
            .AsyncDatabaseCommands
            .ForDefaultDatabase()
            .CreateRequest("/admin/databases/" + databaseName, "GET")
            .ReadResponseJsonAsync()
            .ContinueOnSuccessInTheUIThread(doc =>
            {
                if (doc == null)
                {
                    return;
                }

                var databaseDocument = ApplicationModel.Current.Server.Value.DocumentStore.Conventions.CreateSerializer()
                                       .Deserialize <DatabaseDocument>(new RavenJTokenReader(doc));
                Settings.DatabaseDocument = databaseDocument;

                var databaseSettingsSectionViewModel = new DatabaseSettingsSectionViewModel();
                Settings.Sections.Add(databaseSettingsSectionViewModel);
                Settings.SelectedSection.Value = databaseSettingsSectionViewModel;

                Settings.Sections.Add(new PeriodicBackupSettingsSectionModel());

                string activeBundles;
                databaseDocument.Settings.TryGetValue("Raven/ActiveBundles", out activeBundles);

                if (activeBundles != null)
                {
                    if (activeBundles.Contains("Quotas"))
                    {
                        Settings.Sections.Add(new QuotaSettingsSectionModel());
                    }

                    if (activeBundles.Contains("Replication"))
                    {
                        Settings.Sections.Add(new ReplicationSettingsSectionModel());
                    }

                    if (activeBundles.Contains("Versioning"))
                    {
                        Settings.Sections.Add(new VersioningSettingsSectionModel());
                    }

                    if (activeBundles.Contains("Authorization"))
                    {
                        Settings.Sections.Add(new AuthorizationSettingsSectionModel());
                    }
                }

                foreach (var settingsSectionModel in Settings.Sections)
                {
                    settingsSectionModel.LoadFor(databaseDocument);
                }
            });
        }