/// <summary> /// Saves the given configuration in the default location /// </summary> /// <param name="bpc"></param> static public void SaveConfiguration(BatchProcessorConfig bpc) { string p = ConfigFilePath; string text = bpc.Serialize(); File.WriteAllText(p, text); }
/// <summary> /// Writes the configuration file according to the current status of <see cref="ExecutionQueues"/>. /// </summary> public static void SaveExecutionQueues() { var conf = new BatchProcessorConfig() { AllQueues = ExecutionQueues.ToArray() }; //for(int i = 0; i < ExecutionQueues.Count; i++) { // conf.AllQueus[i] = ExecutionQueues[i].GetConfig(); //} BatchProcessorConfig.SaveConfiguration(conf); }
/// <summary> /// Reload from configuration file /// </summary> public static void ReloadExecutionQueues() { executionQueues = new List <BatchProcessorClient>(); BatchProcessorConfig bpc; try { bpc = BatchProcessorConfig.LoadOrDefault(); } catch (Exception e) { Console.Error.WriteLine($"{e.GetType().Name} caught while loading batch processor configuration file - using a default configuration. Message: {e.Message}"); executionQueues.Add(new MiniBatchProcessorClient()); return; } executionQueues.AddRange(bpc.AllQueues); }
/// <summary> /// Used for control objects in work-flow management, de-serializing from a string. /// </summary> public static BatchProcessorConfig Deserialize(string Str) { JsonSerializer formatter = new JsonSerializer() { NullValueHandling = NullValueHandling.Ignore, TypeNameHandling = TypeNameHandling.Auto, ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor, ReferenceLoopHandling = ReferenceLoopHandling.Error }; using (var tr = new StringReader(Str)) { //string typeName = tr.ReadLine(); Type ControlObjectType = typeof(BatchProcessorConfig); //Type.GetType(typeName); using (JsonReader reader = new JsonTextReader(tr)) { var obj = formatter.Deserialize(reader, ControlObjectType); BatchProcessorConfig ctrl = (BatchProcessorConfig)obj; return(ctrl); } } }
/// <summary> /// Loading of a configuration file from settings directory; if file does not exist, a default /// configuration is returned and the file is created. /// </summary> static public BatchProcessorConfig LoadOrDefault() { string p = ConfigFilePath; if (File.Exists(p)) { string text = File.ReadAllText(p); var bpc = Deserialize(text); return(bpc); } else { var r = new BatchProcessorConfig() { AllQueues = new BatchProcessorClient[] { new MiniBatchProcessorClient() } }; SaveConfiguration(r); return(r); } }