/* TODO: Error Handling for write operation of config.json and user input */ private static void Write_Config() { int choice; string rate = String.Empty; Console.WriteLine("\n\n****************PROGRAM INITIALIZATION****************\n"); Console.WriteLine("ASCC: 1"); Console.WriteLine("UTEM: 2"); Console.WriteLine("UPSI: 3"); Console.WriteLine("UUM: 4"); Console.WriteLine("Others: 5"); Console.Write("Enter organization: "); choice = Convert.ToInt32(Console.ReadKey().Key.ToString().Substring(1)); Console.WriteLine(); Console.Write("Enter polling rate(ms)(recommended 250): "); rate = Console.ReadLine(); Console.WriteLine(); if (rate == "") { rate = "250"; } ProgramConfig config = new ProgramConfig { organizationChoice = choice, pollingRate = rate }; File.WriteAllText(@"config.json", JsonConvert.SerializeObject(config)); }
/* TODO: Error Handling for read operation of config.json */ private static Boolean Program_Initialize() { for (int fail = 0; fail < 3; fail++) { if (File.Exists("config.json")) { Console.WriteLine("Reading Config File..."); Program_Delay(); config = JsonConvert.DeserializeObject <ProgramConfig>(File.ReadAllText(@"config.json")); Console.WriteLine("Successful!"); break; } else // If file not found, assume as first initialization, create new config file { Console.WriteLine("config.json not found. Initiating config initialization..."); Program_Delay(); Write_Config(); Console.WriteLine("Writing config.json..."); Program_Delay(); Console.WriteLine("Successful!"); } if (fail == 2) { return(false); } } return(true); }