static void Main(string[] args) { /* Add main Pivet assembly */ LoadedAssemblies.Add(Assembly.GetExecutingAssembly()); /* Load any plugin DLLs */ if (Directory.Exists("plugins")) { DirectoryInfo dir = new DirectoryInfo("plugins"); foreach (FileInfo file in dir.GetFiles("*.dll")) { Logger.Write("Loaded plugin: " + file.Name); Assembly assembly = Assembly.LoadFrom(file.FullName); if (assembly.GetTypes().Where(p => (typeof(IDataProcessor).IsAssignableFrom(p) && !p.IsInterface && !p.IsAbstract)).Count() > 0) { LoadedAssemblies.Add(assembly); } } } var configFile = "config.json"; var profileToRun = ""; var wantsBuilder = false; ShowProgress = false; if (args.Length > 1) { for (var x = 0; x < args.Length - 1; x++) { if (args[x].ToLower().Equals("-c")) { configFile = args[x + 1]; } if (args[x].ToLower().Equals("-p")) { profileToRun = args[x + 1]; } if (args[x].ToLower().Equals("-b")) { wantsBuilder = true; } if (args[x].ToLower().Equals("-p")) { ShowProgress = true; } } } else if (args.Length == 1) { if (args[0].ToLower().Equals("-b")) { wantsBuilder = true; } if (args[0].ToLower().Equals("-p")) { ShowProgress = true; } } if (File.Exists(configFile) == false) { if (wantsBuilder) { configFile = ConfigBuilder.RunBuilder(); } if (configFile == "") { Logger.Error("Pivet cannot run without a configuration file."); return; } } else { if (wantsBuilder) { Console.Write("Found an existing config file, would you like to modify it? (y/n)"); if (Console.ReadLine() == "y") { configFile = ConfigBuilder.RunBuilder(configFile); } } } string j = File.ReadAllText(configFile); try { GlobalConfig = JsonConvert.DeserializeObject <Config>(j); } catch (Exception ex) { Logger.Error("Failed to parse config.json, please validate all required fields are present."); Logger.Error(ex.ToString()); Console.ReadKey(); return; } Logger.Write($"Config loaded. {GlobalConfig.Environments.Count} Environment(s) found, {GlobalConfig.Profiles.Count} Profile(s) found."); foreach (var profile in GlobalConfig.Profiles) { if (profileToRun.Length > 0) { if (profile.Name.Equals(profileToRun)) { EnvironmentConfig environment = GlobalConfig.Environments.Where(e => e.Name.Equals(profile.EnvironmentName)).FirstOrDefault(); if (environment == null) { Logger.Error($"Could not run profile '{profileToRun}', unable to find environment named '{profile.EnvironmentName}'"); return; } else { ProfileRunner.Run(profile, environment); } } } else { EnvironmentConfig environment = GlobalConfig.Environments.Where(e => e.Name.Equals(profile.EnvironmentName)).FirstOrDefault(); if (environment == null) { Logger.Error($"Could not run profile '{profileToRun}', unable to find environment named '{profile.EnvironmentName}'"); } else { ProfileRunner.Run(profile, environment); } } } Logger.Write("All done!"); }
static void Main(string[] args) { /* Add main Pivet assembly */ LoadedAssemblies.Add(Assembly.GetExecutingAssembly()); /* Load any plugin DLLs */ if (Directory.Exists("plugins")) { DirectoryInfo dir = new DirectoryInfo("plugins"); foreach (FileInfo file in dir.GetFiles("*.dll")) { Logger.Write("Loaded plugin: " + file.Name); Assembly assembly = Assembly.LoadFrom(file.FullName); if (assembly.GetTypes().Where(p => (typeof(IDataProcessor).IsAssignableFrom(p) && !p.IsInterface && !p.IsAbstract)).Count() > 0) { LoadedAssemblies.Add(assembly); } } } /* by default no custom commit message */ CustomCommitMessage = ""; var configFile = "config.json"; var jobToRun = ""; var wantsBuilder = false; var passwordEncryptMode = false; ShowProgress = false; if (args.Contains("-e")) { passwordEncryptMode = true; } if (args.Length > 1) { for (var x = 0; x < args.Length - 1; x++) { if (args[x].ToLower().Equals("-c")) { configFile = args[x + 1]; x++; } if (args[x].ToLower().Equals("-j")) { jobToRun = args[x + 1]; x++; } if (args[x].ToLower().Equals("-b")) { wantsBuilder = true; } if (args[x].ToLower().Equals("-v")) { ShowProgress = true; } if (args[x].ToLower().Equals("-m")) { CustomCommitMessage = args[x + 1]; x++; } } } else if (args.Length == 1) { if (args[0].ToLower().Equals("-b")) { wantsBuilder = true; } if (args[0].ToLower().Equals("-v")) { ShowProgress = true; } } if (passwordEncryptMode) { bool passwordMatch = false; string pass = ""; while (passwordMatch == false) { Console.Write("Enter the password you want to encrypt: "); pass = ReadPassword('*'); Console.Write("Please confirm the password: "******"Passwords did not match. Please try again."); } } Console.WriteLine("Encrypted: " + PasswordCrypto.EncryptPassword(pass)); return; } if (File.Exists(configFile) == false) { if (wantsBuilder) { configFile = ConfigBuilder.RunBuilder(); } if (configFile == "") { Logger.Error("Pivet cannot run without a configuration file."); return; } } else { if (wantsBuilder) { Console.Write("Found an existing config file, would you like to modify it? (y/n)"); if (Console.ReadLine() == "y") { configFile = ConfigBuilder.RunBuilder(configFile); } } } string j = File.ReadAllText(configFile); try { GlobalConfig = JsonConvert.DeserializeObject <Config>(j); } catch (Exception ex) { Logger.Error("Failed to parse config.json, please validate all required fields are present."); Logger.Error(ex.ToString()); Console.ReadKey(); return; } Logger.Write($"Config loaded. {GlobalConfig.Environments.Count} Environment(s) found, {GlobalConfig.Profiles.Count} Profile(s) found."); foreach (var job in GlobalConfig.Jobs) { if (jobToRun.Length > 0) { if (job.Name.Equals(jobToRun)) { EnvironmentConfig environment = GlobalConfig.Environments.Where(e => e.Name.Equals(job.EnvironmentName)).FirstOrDefault(); if (environment == null) { Logger.Error($"Could not run profile '{jobToRun}', unable to find environment named '{job.EnvironmentName}'"); return; } else { JobRunner.Run(GlobalConfig, job); } } } else { EnvironmentConfig environment = GlobalConfig.Environments.Where(e => e.Name.Equals(job.EnvironmentName)).FirstOrDefault(); if (environment == null) { Logger.Error($"Could not run profile '{jobToRun}', unable to find environment named '{job.EnvironmentName}'"); } else { JobRunner.Run(GlobalConfig, job); } } } Logger.Write("All done!"); }