private ApplicationConfig GetApplicationForProtocol(ScalusConfig config, string protocol) { var application = config.Protocols.FirstOrDefault(x => x.Protocol == protocol); if (application == null) { return(null); } return(config.Applications.FirstOrDefault(x => x.Id == application.AppId)); }
private void Save(ScalusConfig configuration) { var serializerSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver(), Formatting = Formatting.Indented }; var json = JsonConvert.SerializeObject(configuration, serializerSettings); File.WriteAllText(_configFile, json); }
public ScalusConfig SaveConfiguration(ScalusConfig configuration) { // TODO: Save the file and keep the comments and formatting // I think this can be done by switching the config file to // json5 and adding a parser for that where we would read the // config as json5 replace the values from the incoming config // object and then write it out again Save(configuration); Load(); return(Config); }
private void Save(ScalusConfig configuration) { var configFile = Path.Combine(Constants.GetBinaryDir(), "scalus.json"); var serializerSettings = new JsonSerializerSettings(); serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); serializerSettings.Formatting = Formatting.Indented; var json = JsonConvert.SerializeObject(configuration, serializerSettings); File.WriteAllText(configFile, json); }
protected void Load() { var configFile = Path.Combine(Constants.GetBinaryDir(), "scalus.json"); if (!File.Exists(configFile)) { Serilog.Log.Warning($"config file not found at: {configFile}"); return; } var configJson = File.ReadAllText(configFile); var serializerSettings = new JsonSerializerSettings(); serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); var json = JsonConvert.SerializeObject(configJson, serializerSettings); Config = JsonConvert.DeserializeObject <ScalusConfig>(configJson); }
public void Post([FromBody] ScalusConfig value) { Configuration.SaveConfiguration(value); }
private void ShowDto() { var example = new ScalusConfig() { Protocols = new List <ProtocolMapping> { { new ProtocolMapping() { Protocol = "myprotocol", AppId = "applicationId" } } }, Applications = new List <ApplicationConfig>() { new ApplicationConfig() { Id = "applicationId", Name = "applicationName", Description = "optional desc", Protocol = "myprotocol", Platforms = new List <Dto.Platform> { Dto.Platform.Windows, Dto.Platform.Linux, Dto.Platform.Mac }, Parser = new ParserConfig() { ParserId = "url", UseDefaultTemplate = false, UseTemplateFile = "/path/tofile", Options = new List <string> { "waitforexit" }, PostProcessingExec = "path/toplugin", PostProcessingArgs = new List <string> { "arg1", "arg2" }, }, Exec = "/path/tocommand", Args = new List <string> { "arg1", "arg2 " } } } }; Console.WriteLine(@" * Example SCALUS configuration: ---------------------------- "); Console.WriteLine(JsonConvert.SerializeObject(example, Formatting.Indented)); Console.WriteLine(@" * DTO Properties : -------------- "); foreach (var one in ScalusConfig.DtoPropertyDescription) { Console.WriteLine($" - {one.Key} : {one.Value}"); } }
public int Run() { var example = new ScalusConfig() { Protocols = new List <ProtocolMapping> { { new ProtocolMapping() { Protocol = "myprotocol", AppId = "applicationId" } } }, Applications = new List <ApplicationConfig>() { new ApplicationConfig() { Id = "applicationId", Name = "applicationName", Description = "optional desc", Protocol = "myprotocol", Platforms = new List <Dto.Platform> { Dto.Platform.Windows, Dto.Platform.Linux, Dto.Platform.Mac }, Parser = new ParserConfig() { ParserId = "url", UseDefaultTemplate = false, UseTemplateFile = "/path/tofile", Options = new List <string> { "waitforexit" }, PostProcessingExec = "path/toplugin", PostProcessingArgs = new List <string> { "arg1", "arg2" }, }, Exec = "/path/tocommand", Args = new List <string> { "arg1", "arg2 " } } } }; if (Options.Dto) { ShowDto(); return(0); } if (Options.Tokens) { ShowTokens(); return(0); } ShowConfig(); return(0); }