public CLIContext(string indexDirectory, CLISettings settings) { Paths = new PathHelper(this); Paths.Initialize(indexDirectory); Settings = settings; }
public void SaveSettings(CLISettings settings) { Console.WriteLine("Saving settings..."); var json = JsonConvert.SerializeObject(settings, Formatting.Indented); var settingsFile = GetSettingsFilePath(); Console.WriteLine(" Path: " + settingsFile); File.WriteAllText(settingsFile, json); SaveSettingsToLegacyFiles(settings); }
public void SaveSettingsToLegacyFiles(CLISettings settings) { // TODO: Phase this out once scripts no longer rely on it. var basePath = WorkingDirectory; File.WriteAllText(basePath + "/mqtt-host.security", settings.MqttHost); File.WriteAllText(basePath + "/mqtt-username.security", settings.MqttUsername); File.WriteAllText(basePath + "/mqtt-password.security", settings.MqttPassword); File.WriteAllText(basePath + "/mqtt-port.security", settings.MqttPort.ToString()); File.WriteAllText(basePath + "/wifi-name.security", settings.WiFiName); File.WriteAllText(basePath + "/wifi-password.security", settings.WiFiPassword); File.WriteAllText(basePath + "/smtp-server.security", settings.SmtpServer); File.WriteAllText(basePath + "/smpt-username.security", settings.SmtpUsername); File.WriteAllText(basePath + "/smtp-password.security", settings.SmtpPassword); File.WriteAllText(basePath + "/smtp-port.security", settings.SmtpPort.ToString()); File.WriteAllText(basePath + "/admin-email.security", settings.Email); }
public bool LoadSettingsFromArguments(Arguments arguments, CLISettings settings) { if (arguments.Contains("branch")) { SettingsChanged = true; settings.Branch = arguments["branch"]; Console.WriteLine(" Setting branch: " + settings.Branch); } if (arguments.Contains("version")) { SettingsChanged = true; settings.Version = arguments["version"]; Console.WriteLine(" Setting version: " + settings.Version); } if (arguments.Contains("username")) { LoginSettingsChanged = true; SettingsChanged = true; settings.Username = arguments["username"]; Console.WriteLine(" Setting login username: "******"password")) { LoginSettingsChanged = true; SettingsChanged = true; settings.Password = arguments["password"]; Console.WriteLine(" Setting login password: hidden (length " + settings.MqttPassword.Length + ")"); } if (arguments.Contains("wifi-name")) { WifiSettingsChanged = true; SettingsChanged = true; settings.WiFiName = arguments["wifi-name"]; Console.WriteLine(" Setting WiFi name: " + settings.WiFiName); } if (arguments.Contains("wifi-password")) { WifiSettingsChanged = true; SettingsChanged = true; settings.WiFiPassword = arguments["wifi-password"]; Console.WriteLine(" Setting WiFi password: "******"mqtt-host")) { MqttSettingsChanged = true; SettingsChanged = true; settings.MqttHost = arguments["mqtt-host"]; Console.WriteLine(" Setting MQTT host: " + settings.MqttHost); } if (arguments.Contains("mqtt-username")) { MqttSettingsChanged = true; SettingsChanged = true; settings.MqttUsername = arguments["mqtt-username"]; Console.WriteLine(" Setting MQTT username: "******"mqtt-password")) { MqttSettingsChanged = true; SettingsChanged = true; settings.MqttPassword = arguments["mqtt-password"]; Console.WriteLine(" Setting MQTT password: hidden (length " + settings.MqttPassword.Length + ")"); } if (arguments.Contains("mqtt-port")) { MqttSettingsChanged = true; SettingsChanged = true; settings.MqttPort = Convert.ToInt32(arguments["mqtt-port"]); Console.WriteLine(" Setting MQTT port: " + settings.MqttPort); } if (arguments.Contains("smtp-server")) { EmailSettingsChanged = true; SettingsChanged = true; settings.SmtpServer = arguments["smtp-server"]; Console.WriteLine(" Setting SMTP server: " + settings.SmtpServer); } if (arguments.Contains("smtp-username")) { EmailSettingsChanged = true; SettingsChanged = true; settings.SmtpUsername = arguments["smtp-username"]; Console.WriteLine(" Setting version: " + settings.SmtpUsername); } if (arguments.Contains("smtp-password")) { EmailSettingsChanged = true; SettingsChanged = true; settings.SmtpPassword = arguments["smtp-password"]; Console.WriteLine(" Setting SMTP password: hidden (length: " + settings.SmtpPassword.Length + ")"); } if (arguments.Contains("smtp-port")) { EmailSettingsChanged = true; SettingsChanged = true; settings.SmtpPort = Convert.ToInt32(arguments["smtp-port"]); Console.WriteLine(" Setting SMTP password: "******"email")) { EmailSettingsChanged = true; SettingsChanged = true; settings.Email = arguments["email"]; Console.WriteLine(" Setting email address: " + settings.Email); } if (arguments.Contains("mock-systemctl")) { settings.IsMockSystemCtl = Convert.ToBoolean(arguments["mock-systemctl"]); if (settings.IsMockSystemCtl) { Console.WriteLine(" Is mock systemctl: " + settings.IsMockSystemCtl); } } if (arguments.Contains("mock-docker")) { settings.IsMockDocker = Convert.ToBoolean(arguments["mock-docker"]); if (settings.IsMockDocker) { Console.WriteLine(" Is mock docker: " + settings.IsMockDocker); } } // TODO: Clean up //if (SettingsChanged) // SaveSettings(settings); return(SettingsChanged); }
public CLISettings LoadSettings()//CLIContext context) { Console.WriteLine("Loading settings..."); var settingsFile = GetSettingsFilePath(); Console.WriteLine(" Path: " + settingsFile); if (File.Exists(settingsFile)) { Console.WriteLine(" Settings file exists."); var settingsJson = File.ReadAllText(settingsFile); var settings = JsonConvert.DeserializeObject <CLISettings>(settingsJson); var starter = new ProcessStarter(WorkingDirectory); starter.StartBash("hostname"); settings.HostName = starter.Output.Trim(); return(settings); } else { Console.WriteLine(" Settings file doesn't exist. Loading from legacy settings files..."); var settings = new CLISettings(); // Load settings from legacy files if they exist if (File.Exists(WorkingDirectory + "/mqtt-host.security")) { settings.MqttHost = File.ReadAllText(WorkingDirectory + "/mqtt-host.security").Trim(); } if (File.Exists(WorkingDirectory + "/mqtt-username.security")) { settings.MqttUsername = File.ReadAllText(WorkingDirectory + "/mqtt-username.security").Trim(); } if (File.Exists(WorkingDirectory + "/mqtt-password.security")) { settings.MqttPassword = File.ReadAllText(WorkingDirectory + "/mqtt-password.security").Trim(); } if (File.Exists(WorkingDirectory + "/mqtt-port.security")) { settings.MqttPort = Convert.ToInt32(File.ReadAllText(WorkingDirectory + "/mqtt-port.security").Trim()); } if (File.Exists(WorkingDirectory + "/wifi-name.security")) { settings.WiFiName = File.ReadAllText(WorkingDirectory + "/wifi-name.security").Trim(); } if (File.Exists(WorkingDirectory + "/wifi-password.security")) { settings.WiFiPassword = File.ReadAllText(WorkingDirectory + "/wifi-password.security").Trim(); } if (File.Exists(WorkingDirectory + "/smtp-server.security")) { settings.SmtpServer = File.ReadAllText(WorkingDirectory + "/smtp-server.security").Trim(); } if (File.Exists(WorkingDirectory + "/smtp-username.security")) { settings.SmtpUsername = File.ReadAllText(WorkingDirectory + "/smtp-username.security").Trim(); } if (File.Exists(WorkingDirectory + "/smtp-password.security")) { settings.SmtpPassword = File.ReadAllText(WorkingDirectory + "/smtp-password.security").Trim(); } if (File.Exists(WorkingDirectory + "/smtp-port.security")) { settings.SmtpPort = Convert.ToInt32(File.ReadAllText(WorkingDirectory + "/smtp-port.security").Trim()); } if (File.Exists(WorkingDirectory + "/admin-email.security")) { settings.Email = File.ReadAllText(WorkingDirectory + "/admin-email.security").Trim(); } return(settings); } }