public override void Build(IRootCommandMultiple root) { root.NewSubCommand("update", "Checks for updates and if there is a new version performs the actual update") .Build((cmd, arg, opt) => { var configuration = BuildConfigurationOption(opt); var local = BuildLocalOption(opt); var force = BuildForceOption(opt); var ping = BuildDryRunOption(opt); cmd.OnExecute(() => _controller.Execute(configuration.Value, local.HasValue, force.HasValue, ping.HasValue).ToInteger()); }); }
/// <summary> /// - gets a new version of patches and questions /// - tries to compile patches and questions if update was successfull /// otherwise the latest compiled dll is used "Patches.dll" /// - creates patches instances and builds problem tree. /// </summary> private TroubleShooter() { //load run data if process started using Kros.TroubleShooterInputs method RunData = Runner.GetData(); //init web api client Client = new TroubleShooterClient(); //create update dir if (!Directory.Exists(SOURCES_LOCATION)) { Directory.CreateDirectory(SOURCES_LOCATION); } //get latest source files if server is online... check if its a new version UpdateController updater = new UpdateController(SOURCES_LOCATION, Client); ServerOnline = Client.TryConnection(); IsNewVersion = ServerOnline && updater.Execute(); //recompile if its a new version if (IsNewVersion) { Compiler.Compile(SOURCES_LOCATION); } //load last time compiled assembly sourcesAssembly = Compiler.LoadPatchAssembly(); //init triubleshooter Patches = new List <Patch>(); if (sourcesAssembly != null) { #if DEBUG //patche sa podarilo skompilovat ale ak ich chcem debugovat pozijeme tie v tejto assembly //tiez by bolo fajn mat v priecinku s troubleshooterom aj runData subor pre debugovanie... sourcesAssembly = this.GetType().Assembly; #endif //register all patches, create its instances var compiledPatches = (from type in sourcesAssembly.GetTypes() where type.IsSubclassOf(typeof(Patch)) select(Patch) Activator.CreateInstance(type)).ToList(); foreach (Patch patch in compiledPatches) { Patches.Add(patch); } //initialise a root question - decorated by RootQuestionAttribute RootQuestion = (from type in sourcesAssembly.GetTypes() where type.IsSubclassOf(typeof(Question)) where type.GetCustomAttributes(typeof(RootQuestionAttribute)).Count() != 0 select(Question) Activator.CreateInstance(type)).FirstOrDefault(); } }