static void Main(string[] args) { var builder = new ContainerBuilder(); builder.RegisterModule(new SrirachaAutofacorator(EnumDIMode.Service)); var container = builder.Build(); _logger = container.Resolve<ILog>(); _diFactory = container.Resolve<IDIFactory>(); var session = _diFactory.CreateInjectedObject<IDocumentSession>(); if(args != null && args.Contains("--dropAllIndexes", StringComparer.CurrentCultureIgnoreCase)) { DropAllIndexes(session.Advanced.DocumentStore); } if(args != null && args.Contains("--purgeSystemLog")) { PurgeSystemLog(session); } if(args == null || args.Length == 0) { var x = session.Query<DeployCredentials>().FirstOrDefault(i=>i.UserName == "mmoone00c"); if(x != null) { session.Delete(x); session.SaveChanges(); } bool done = false; int processedRecords = 0; while(!done) { RavenQueryStatistics stats; var list = session.Query<DeployBuild>() .Statistics(out stats) .OrderBy(i=>i.CreatedDateTimeUtc) .Skip(processedRecords) .ToList(); foreach(var build in list) { string oldVersion = build.Version; build.Version = "test"; build.Version = oldVersion; session.SaveEvict(build); } processedRecords += list.Count; if (processedRecords >= stats.TotalResults) { done = true; } } done = false; while(!done) { var processedRecordList = new List<string>(); RavenQueryStatistics stats; var list = session.Query<DeployState>() .Statistics(out stats) .OrderBy(i => i.CreatedDateTimeUtc) .Take(int.MaxValue) .Skip(processedRecordList.Count) .ToList(); foreach (var state in list) { if(processedRecordList.Contains(state.Id)) { throw new Exception("Duplicatge: " + state.Id); } if(state.Build != null) { string oldVersion = state.Build.Version; state.Build.Version = "test"; state.Build.Version = oldVersion; //session.SaveEvict(state); } processedRecordList.Add(state.Id); } session.SaveChanges(); if (processedRecordList.Count >= stats.TotalResults) { done = true; } } } }
static void Main(string[] args) { switch(AppConfigOptions.DIContainer) { case DIContainer.Ninject: { throw new NotSupportedException("Ninject is no longer supported"); //var kernel = new StandardKernel(new NinjectModules.SrirachaNinjectorator()); //_logger = kernel.Get<NLog.Logger>(); //_diFactory = kernel.Get<IDIFactory>(); } //break; case DIContainer.Autofac: { try { var builder = new ContainerBuilder(); builder.RegisterModule(new SrirachaAutofacorator(EnumDIMode.Service)); builder.RegisterType<WinService>().AsSelf(); var container = builder.Build(); _logger = container.Resolve<NLog.Logger>(); _diFactory = container.Resolve<IDIFactory>(); } catch(ReflectionTypeLoadException err) { foreach(var loaderError in err.LoaderExceptions) { Console.WriteLine("LOADER EXCEPTION: " + loaderError.ToString()); } throw; } } break; default: throw new UnknownEnumValueException(AppConfigOptions.DIContainer); } SetupColorConsoleLogging(); var options = new CommandLineOptions(); if(!Parser.Default.ParseArguments(args, options)) { throw new Exception(options.GetUsage()); } if(!string.IsNullOrWhiteSpace(options.WorkingDirectory)) { var settings = _diFactory.CreateInjectedObject<ISystemSettings>(); settings.DeployWorkingDirectory = options.WorkingDirectory; } if(!string.IsNullOrEmpty(options.RunDeploymentId)) { var deploymentBatchRunner = _diFactory.CreateInjectedObject<IDeployBatchRunner>(); deploymentBatchRunner.ForceRunDeployment(options.RunDeploymentId); } else if (options.CleanupFolders) { var job = _diFactory.CreateInjectedObject<IFolderCleanupJob>(); job.ForceRun(); } else if (options.CreateOfflineDeployment) { var job = _diFactory.CreateInjectedObject<IOfflineDeploymentPackageJob>(); job.RunNow(); } else if (options.Debug) { Console.WriteLine("\t-Starting in debug mode..."); try { var service = _diFactory.CreateInjectedObject<WinService>(); service.DebugStart(options.ThrashMode); } catch(Exception err) { _logger.ErrorException("Debug mode failed: " + err.ToString(), err); } finally { Console.WriteLine("Press any key to exit"); Console.ReadKey(); } } else { var service = _diFactory.CreateInjectedObject<WinService>(); ServiceBase.Run(service); } }
public bool MatchesRule(DeployBuild build, IDIFactory diFactory) { var deployStateRepository = diFactory.CreateInjectedObject<IDeployStateRepository>(); var projectRepository = diFactory.CreateInjectedObject<IProjectRepository>(); if (this.EnvironmentIdList != null) { foreach(var environmentId in this.EnvironmentIdList) { var list = deployStateRepository.FindDeployStateListForEnvironment(build.Id, environmentId); if (list != null && list.Count > 0) { return true; } } } var project = projectRepository.GetProject(build.ProjectId); if (this.EnvironmentNameList != null) { foreach(var environmentName in this.EnvironmentNameList) { var environmentList = project.EnvironmentList.Where(i=>i.EnvironmentName == environmentName); if(environmentList != null) { foreach(var environment in environmentList) { var list = deployStateRepository.FindDeployStateListForEnvironment(build.Id, environment.Id); if(list != null && list.Count > 0) { return true; } } } } } if(this.MachineIdList != null) { foreach(var machineId in this.MachineIdList) { var machine = project.GetMachine(machineId); var list = deployStateRepository.FindDeployStateListForMachine(build.Id, machine.EnvironmentId, machine.Id); if(list != null) { foreach(var item in list) { if(item.MachineList.Any(i=>i.Id == machine.Id)) { return true; } } } } } if(this.MachineNameList != null) { foreach(var machineName in this.MachineNameList) { var machineList = project.GetMachineListForName(machineName); if(machineList != null) { foreach(var machine in machineList) { var list = deployStateRepository.FindDeployStateListForMachine(build.Id, machine.EnvironmentId, machine.Id); if(list != null) { foreach(var item in list) { if(item.MachineList.Any(i=>i.Id == machine.Id)) { return true; } } } } } } } return false; }
static int Main(string[] args) { switch(AppConfigOptions.DIContainer) { case DIContainer.Ninject: { throw new NotSupportedException("Ninject is no longer supported"); //var kernel = new StandardKernel(new NinjectModules.SrirachaNinjectorator()); //_diFactory = kernel.Get<IDIFactory>(); } //break; case DIContainer.Autofac: { var builder = new ContainerBuilder(); builder.RegisterModule(new SrirachaAutofacorator(EnumDIMode.CommandLine)); var container = builder.Build(); _logger = container.Resolve<NLog.Logger>(); _diFactory = container.Resolve<IDIFactory>(); } break; default: throw new UnknownEnumValueException(AppConfigOptions.DIContainer); } SetupColorConsoleLogging(); bool pause = false; Program._logger = _diFactory.CreateInjectedObject<NLog.Logger>(); try { var options = new CommandLineOptions(); if(!CommandLineParser.Parser.Default.ParseArguments(args, options) || options.Action == ActionType.Unknown) { throw new Exception(options.GetUsage()); } pause = options.Pause; switch(options.Action) { case ActionType.Deploy: if(string.IsNullOrWhiteSpace(options.EnvironmentId)) { throw new Exception("EnvironmentID (--environment|-e) required for Deploy"); } if(string.IsNullOrWhiteSpace(options.BuildId)) { throw new Exception("BuildID (--build|-b) required for Deploy"); } if(string.IsNullOrWhiteSpace(options.MachineId)) { throw new Exception("MachineID (--machine|-m) required for Deploy"); } Deploy(options.EnvironmentId, options.BuildId, options.MachineId); break; //case ActionType.Configure: // if(!string.IsNullOrWhiteSpace(options.EnvironmentId) && !string.IsNullOrWhiteSpace(options.MachineId)) // { // throw new Exception("EnvironmentID (--environment|-e) and Machine ID (--machine|-m) cannot be used at the same time for Configure"); // } // if(string.IsNullOrWhiteSpace(options.ConfigName)) // { // throw new Exception("ConfigName (--configName) required for Configure"); // } // if(!string.IsNullOrWhiteSpace(options.EnvironmentId) && !string.IsNullOrWhiteSpace(options.ComponentId)) // { // ConfigureEnvironment(options.EnvironmentId, options.ComponentId, options.ConfigName, options.ConfigValue); // } // else if (!string.IsNullOrWhiteSpace(options.MachineId)) // { // ConfigureMachine(options.MachineId, options.ConfigName, options.ConfigValue); // } // else // { // throw new Exception("EnvironmentID (--environment|-e) or combination of Machine ID (--machine|-m) and Component ID (--component|-c) required for Configure"); // } // break; case ActionType.Publish: VerifyParameter(options.ApiUrl,"Publish", "ApiUrl", "apiurl", 'a'); VerifyParameter(options.ProjectId,"Publish", "ProjectId", "project", 'p'); //VerifyParameter(options.BranchId,"Publish", "BranchId", "branch"); VerifyParameter(options.ComponentId,"Publish", "ComponentId", "component", 'c'); VerifyParameter(options.Version,"Publish", "Version", "version", 'v'); if((!string.IsNullOrEmpty(options.UserName) && string.IsNullOrEmpty(options.Password)) || (string.IsNullOrEmpty(options.UserName) && !string.IsNullOrEmpty(options.Password))) { throw new Exception("UserName (--userName) and Password (--password) must be used together for Publish"); } if(!string.IsNullOrWhiteSpace(options.File)) { if (!string.IsNullOrWhiteSpace(options.Directory)) { throw new Exception("File (--file|-f) and Directory (--directory|-f) cannot be both be used together for Publish"); } if(!string.IsNullOrWhiteSpace(options.FilePattern)) { throw new Exception("File (--file|-f) and FilePattern (--filePattern) cannot be both be used together for Publish"); } PublishFile(options.File, options.ApiUrl, options.ProjectId, options.ComponentId, options.BranchId, options.Version, options.NewFileName, options.UserName, options.Password, options.DeployNow); } else if (!string.IsNullOrWhiteSpace(options.Directory)) { if (!string.IsNullOrWhiteSpace(options.FilePattern)) { throw new Exception("Directory (--directory|-d) and FilePattern (--filePattern) cannot be both be used together for Publish"); } PublishDirectory(options.Directory, options.ApiUrl, options.ProjectId, options.ComponentId, options.BranchId, options.Version, options.UserName, options.Password, options.DeployNow); } else if (!string.IsNullOrWhiteSpace(options.FilePattern)) { PublishFilePattern(options.FilePattern, options.ApiUrl, options.ProjectId, options.ComponentId, options.BranchId, options.Version, options.NewFileName, options.UserName, options.Password, options.DeployNow); } else { throw new Exception("Either File (--file|-f), Directory (--directory|-f), or FilePattern (--filePattern) required for Publish"); } break; default: throw new UnknownEnumValueException(options.Action); } if(args == null || args.Length == 0 || string.IsNullOrWhiteSpace(args[0])) { throw new Exception("All your sriracha are belong to us"); } return 0; } catch(Exception err) { Program._logger.ErrorException("Error: " + err.ToString(), err); return 2; } finally { if(pause) { Console.WriteLine("Please any key to continue"); Console.ReadKey(); } } }