public virtual async Task <KongvergeConfiguration> ReadConfiguration(string folderPath) { Log.Information("Reading files from {folderPath}", folderPath); var filePaths = Directory.EnumerateFiles(folderPath, $"*{Settings.FileExtension}", SearchOption.AllDirectories); var services = new List <KongService>(); ExtendibleKongObject globalConfig = null; foreach (var configFilePath in filePaths) { if (configFilePath.EndsWith(Settings.GlobalConfigFileName)) { if (globalConfig != null) { throw new InvalidConfigurationFileException(configFilePath, $"Cannot have more than one {Settings.GlobalConfigFileName} file."); } globalConfig = await ParseFile <ExtendibleKongObject>(configFilePath); } else { services.Add(await ParseFile <KongService>(configFilePath)); } } return(new KongvergeConfiguration { Services = services.AsReadOnly(), GlobalConfig = globalConfig ?? new ExtendibleKongObject() }); }
protected override string SerializingToConfigJson() => Serialized = new ExtendibleKongObject { Plugins = new [] { Instance } } .ToConfigJson();
private static async Task WriteConfigObject(ExtendibleKongObject configObject, string folderPath, string fileName) { var json = configObject.ToConfigJson(); var path = $"{folderPath}\\{fileName}"; Log.Information("Writing {path}", path); using (var stream = File.OpenWrite(path)) using (var writer = new StreamWriter(stream)) { await writer.WriteAsync(json); } }
private Task ConvergeChildrenPlugins(ExtendibleKongObject existing, ExtendibleKongObject target) { Task UpsertPlugin(KongPlugin plugin, ExtendibleKongObject parent) { parent.AssignParentId(plugin); return(_kongWriter.UpsertPlugin(plugin)); } return(ConvergeObjects( existing?.Plugins, target.Plugins, x => _kongWriter.DeletePlugin(x.Id), x => UpsertPlugin(x, target), x => UpsertPlugin(x, target))); }