Exemplo n.º 1
0
        static void AddEnvironment()
        {
            EnvironmentConfig env = new EnvironmentConfig();

            ModifyEnvironment(env);

            configFile.Environments.Add(env);
            SaveConfig();
        }
Exemplo n.º 2
0
        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!");
        }
Exemplo n.º 3
0
        static void ProcessConfigQuestions()
        {
            /* Check for environments, if none we need to add one before moving on to profiles */
            if (configFile.Environments.Count == 0)
            {
                Console.WriteLine("There are currently no environments defined. Making a new one.");
                AddEnvironment();
            }

            var modifyEnv = "n";

            do
            {
                PromptWithDefault("Would you like to modify an existing environment? (y/n)", ref modifyEnv);

                if (modifyEnv == "y")
                {
                    EnvironmentConfig toModify = PromptWithList("Select the environment you wish to modify", configFile.Environments);
                    ModifyEnvironment(toModify);
                }
            } while (modifyEnv == "y");

            var addEnv = "n";

            do
            {
                PromptWithDefault("Would you like to create a new environment? (y/n)", ref addEnv);

                if (addEnv == "y")
                {
                    AddEnvironment();
                }
            } while (addEnv == "y");


            /* Check for profiles, if none we need to add one */
            if (configFile.Profiles.Count == 0)
            {
                Console.WriteLine("There are currently no profiles defined. Making a new one.");
                AddProfile();
            }

            var modifyProfile = "n";

            do
            {
                PromptWithDefault("Would you like to modify an existing profile? (y/n)", ref modifyProfile);

                if (modifyProfile == "y")
                {
                    ProfileConfig toModify = PromptWithList("Select the profile you wish to modify", configFile.Profiles);
                    ModifyProfile(toModify);
                }
            } while (modifyEnv == "y");


            var addProfile = "n";

            do
            {
                PromptWithDefault("Would you like to create a new profile? (y/n)", ref addProfile);

                if (addProfile == "y")
                {
                    AddProfile();
                }
            } while (addProfile == "y");
        }
Exemplo n.º 4
0
      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!");
      }