예제 #1
0
        public async Task <IActionResult> UpdateAppSettings(AppSettingsTransferObject appSettingTransferObject)
        {
            if (!string.IsNullOrEmpty(appSettingTransferObject.StorageFolder))
            {
                if (!_appSettings.StorageFolderAllowEdit)
                {
                    Response.StatusCode = 403;
                    return(Content("There is an Environment variable set so you can't update it here"));
                }
                if (!_hostStorage.ExistFolder(appSettingTransferObject.StorageFolder))
                {
                    return(NotFound("Location on disk not found"));
                }
            }

            // To update current session
            AppSettingsCompareHelper.Compare(_appSettings, appSettingTransferObject);

            // should not forget app: prefix
            var jsonOutput = JsonSerializer.Serialize(new { app = appSettingTransferObject }, new JsonSerializerOptions
            {
                WriteIndented = true,
                Converters    =
                {
                    new JsonBoolQuotedConverter(),
                },
                DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
            });

            await _hostStorage.WriteStreamAsync(
                new PlainTextFileHelper().StringToStream(jsonOutput),
                _appSettings.AppSettingsPath);

            return(Env());
        }
예제 #2
0
        public void NewObject()
        {
            var input = new AppSettings();

            AppSettingsCompareHelper.Compare(input, null);

            Assert.AreEqual(input.Structure, new AppSettings().Structure);
        }
예제 #3
0
        public void NullableBoolCompare()
        {
            var source = new AppSettings
            {
                Verbose = true
            };

            var to = new AppSettingsTransferObject()
            {
                Verbose = false                 // or null
            };

            AppSettingsCompareHelper.Compare(source, to);
            Assert.AreEqual(source.Verbose, to.Verbose);
        }
예제 #4
0
        public void DatabaseTypeListCompare()
        {
            var source = new AppSettings
            {
                DatabaseType = AppSettings.DatabaseTypeList.Sqlite
            };

            var to = new AppSettings
            {
                DatabaseType = AppSettings.DatabaseTypeList.InMemoryDatabase
            };

            AppSettingsCompareHelper.Compare(source, to);
            Assert.AreEqual(source.DatabaseType, to.DatabaseType);
        }
예제 #5
0
        public void StringCompare()
        {
            var source = new AppSettings
            {
                DatabaseType       = AppSettings.DatabaseTypeList.Sqlite,
                DatabaseConnection = "Data Source=source"
            };

            var to = new AppSettings
            {
                DatabaseType       = AppSettings.DatabaseTypeList.Sqlite,
                DatabaseConnection = "Data Source=to"
            };

            AppSettingsCompareHelper.Compare(source, to);
            Assert.AreEqual(source.DatabaseConnection, to.DatabaseConnection);
        }
예제 #6
0
        public void ListStringCompare_Same()
        {
            var source = new AppSettings
            {
                ReadOnlyFolders = new List <string> {
                    "/same"
                }
            };

            var to = new AppSettings
            {
                ReadOnlyFolders = new List <string> {
                    "/same"
                }
            };

            AppSettingsCompareHelper.Compare(source, source);
            Assert.AreEqual(source.ReadOnlyFolders.FirstOrDefault(), to.ReadOnlyFolders.FirstOrDefault());
        }
예제 #7
0
        public void ListAppSettingsPublishProfilesCompare()
        {
            var source = new AppSettings
            {
                PublishProfiles = new Dictionary <string, List <AppSettingsPublishProfiles> >
                {
                    { "zz__example", new List <AppSettingsPublishProfiles>
                      {
                          new AppSettingsPublishProfiles
                          {
                              ContentType     = TemplateContentType.Jpeg,
                              SourceMaxWidth  = 1000,
                              OverlayMaxWidth = 380,
                              Path            = "{AssemblyDirectory}/EmbeddedViews/qdrawlarge.png",
                              Folder          = "1000",
                              Append          = "_kl1k"
                          }
                      } }
                }
            };

            var to = new AppSettings
            {
                PublishProfiles = new Dictionary <string, List <AppSettingsPublishProfiles> >
                {
                    { "zz__example2", new List <AppSettingsPublishProfiles>
                      {
                          new AppSettingsPublishProfiles
                          {
                              ContentType     = TemplateContentType.Jpeg,
                              SourceMaxWidth  = 300,
                              OverlayMaxWidth = 380,
                              Folder          = "1000",
                              Append          = "_kl1k"
                          }
                      } }
                }
            };

            AppSettingsCompareHelper.Compare(source, to);

            Assert.AreEqual(source.PublishProfiles.Keys.FirstOrDefault(), to.PublishProfiles.Keys.FirstOrDefault());
        }
예제 #8
0
        public void ListAppSettingsPublishProfilesCompare_Same()
        {
            var source = new AppSettings
            {
                PublishProfiles = new Dictionary <string, List <AppSettingsPublishProfiles> >
                {
                    { "same", new List <AppSettingsPublishProfiles>
                      {
                          new AppSettingsPublishProfiles
                          {
                              ContentType     = TemplateContentType.Jpeg,
                              SourceMaxWidth  = 300,
                              OverlayMaxWidth = 380,
                              Folder          = "1000",
                              Append          = "_kl1k"
                          }
                      } }
                }
            };

            var to = new AppSettings
            {
                PublishProfiles = new Dictionary <string, List <AppSettingsPublishProfiles> >
                {
                    { "same", new List <AppSettingsPublishProfiles>
                      {
                          new AppSettingsPublishProfiles
                          {
                              ContentType     = TemplateContentType.Jpeg,
                              SourceMaxWidth  = 300,
                              OverlayMaxWidth = 380,
                              Folder          = "1000",
                              Append          = "_kl1k"
                          }
                      } }
                }
            };

            AppSettingsCompareHelper.Compare(source, to);
            Assert.AreEqual(source.PublishProfiles.Keys.FirstOrDefault(), to.PublishProfiles.Keys.FirstOrDefault());
        }