Exemple #1
0
        public override string RunTemplate()
        {
            var meta         = GetMetadata();
            var fullFileName = Path.Combine(meta.GetFullLocationPath(), meta.FileNameWithExtension());

            var jsonObject = new AppSettingsEditor(LoadOrCreate(fullFileName));

            foreach (var appSetting in _appSettings)
            {
                jsonObject.AddPropertyIfNotExists(appSetting.Key, appSetting.Value);
            }

            foreach (var connectionString in _connectionStrings)
            {
                jsonObject.AddPropertyIfNotExists("ConnectionStrings", new object());
                var configConnectionStrings = jsonObject.GetProperty("ConnectionStrings");
                if (configConnectionStrings[connectionString.Name] == null)
                {
                    configConnectionStrings[connectionString.Name] = connectionString.ConnectionString;
                }
                jsonObject.SetProperty("ConnectionStrings", configConnectionStrings);
            }

            foreach (var decorator in GetDecorators())
            {
                decorator.UpdateSettings(jsonObject);
            }

            return(JsonConvert.SerializeObject(jsonObject.Value, new JsonSerializerSettings()
            {
                Formatting = Formatting.Indented
            }));
        }
 public abstract void UpdateSettings(AppSettingsEditor appSettings);