private ComponentTask SetRegistry_ScheduleTBInstallerDeletion() { bool runOnce = true; RegistryUtil.StartupRegistryHives startupRegistryHive = RegistryUtil.StartupRegistryHives.LOCAL_MACHINE; string registryKeyValueName = "TBInstallerCleanup_DeleteInstaller"; bool force = true; bool deleteFromSubfolders = false; bool quiet = true; string filePath = StringUtil.DQuote(Path.Combine(SystemPathConstants.StartupPath, "FirstSetup.exe")); CLICommand command = CMDCommands.Del( force, deleteFromSubfolders, quiet, filePath); StringComparison validationStringComparison = StringComparison.OrdinalIgnoreCase; return(ComponentTaskPresets.SetRegistryRunCommand( runOnce, startupRegistryHive, registryKeyValueName, command, validationStringComparison)); }
private ComponentTask SetRegistry_ScheduleResolutionSetter() { bool runOnce = true; RegistryUtil.StartupRegistryHives startupRegistryHive = RegistryUtil.StartupRegistryHives.CURRENT_USER; string registryKeyValueName = "TBInstaller_SetResolution"; CLICommand sleepCommand = new CLICommand { Program = "sleep" }; sleepCommand.Options.Add(new CommandOption("3")); CLICommand qresCommand = CMDCommands.QRes(SetupProperties.DisplayWidth, SetupProperties.DisplayHeight); CLICommand taskkillCommand = CMDCommands.TaskKill("explorer.exe"); CLICommand startCommand = CMDCommands.Start("explorer.exe"); CLICommand[] commands = new CLICommand[] { sleepCommand, qresCommand, taskkillCommand, startCommand }; StringComparison validationStringComparison = StringComparison.OrdinalIgnoreCase; return(ComponentTaskPresets.SetRegistryRunCommand( runOnce, startupRegistryHive, registryKeyValueName, commands, validationStringComparison)); }
private ComponentTask SetRegistry_ScheduleWindowsTempFolderFoldersCleanup() { bool runOnce = true; RegistryUtil.StartupRegistryHives startupRegistryHive = RegistryUtil.StartupRegistryHives.LOCAL_MACHINE; string registryKeyValueName = "TBInstallerCleanup_WindowsTempFolderFolders"; CMDForLoopCommand command = new CMDForLoopCommand(); command.ForSwitch = new CommandOption("/", "d"); command.LoopParameter = "%x"; command.InParameter = StringUtil.DQuote(@"C:\Windows\Temp\*"); CLICommand loopedCommand = new CLICommand(); loopedCommand.Program = "@rd"; loopedCommand.Options.Add(new CommandOption("/", "s")); loopedCommand.Options.Add(new CommandOption("/", "q")); loopedCommand.Options.Add(new CommandOption(StringUtil.DQuote("%x"))); command.LoopedCommand = loopedCommand; StringComparison validationStringComparison = StringComparison.OrdinalIgnoreCase; return(ComponentTaskPresets.SetRegistryRunCommand( runOnce, startupRegistryHive, registryKeyValueName, command, validationStringComparison)); }
private static void startCommand <TRunOptions>(CLICommand <TRunOptions> command) { var logger = initializeLogger(command); if (command.LogCommandName) { logger.AddInfo($"Starting {command.Name.ToLower()} run"); } logger.AddDebug($"Arguments:\n{command}"); ApplicationStartup.Start(); var runner = IoC.Resolve <IBatchRunner <TRunOptions> >(); try { runner.RunBatchAsync(command.ToRunOptions()).Wait(); } catch (Exception e) { logger.AddException(e); _valid = false; } if (command.LogCommandName) { logger.AddInfo($"{command.Name} run finished"); } }
public void CommandSimpleParse() { string commandString = "foobar"; var command = new CLICommand(commandString); Assert.AreEqual(commandString, command.Command); }
public void Start() { if (serverSocket != null) { throw new Exception("Server already has been started."); } Stopwatch sw = new Stopwatch(); sw.Start(); Initialize(); serverSocket.Bind(new IPEndPoint(IPAddress.Any, configuration.Port)); serverSocket.Listen(0); serverSocket.BeginAccept(AcceptCallback, null); RunServerStartupTasks(); sw.Stop(); loggingService.WriteLog($"Server started in {sw.ElapsedMilliseconds}ms", "Server", "Start"); loggingService.WriteLog($"Running at port {configuration.Port}"); Console.WriteLine("Type 'exit' to stop; 'reboot' to send reboot request event..."); string line = ""; cliHost = serviceManager.GetService <ICLIHostService>(); if (cliHost.RegisteredCommands().Count > 0) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine($"\nCommands available on this CLI:"); foreach (CLICommand command in cliHost.RegisteredCommands()) { Console.WriteLine($"=> {command.CommandText}: {command.CommandDescription}"); } Console.ForegroundColor = ConsoleColor.White; } if (configuration.IsConsoleApplication) { while (line != "exit") { line = Console.ReadLine(); CLICommand command = cliHost.GetCommand(line); if (command == null) { Console.WriteLine("No such command"); } else { TryActivateCommand(command); } if (line == "reboot") { Reboot(); } } } }
private ComponentTask SetRegistry_ScheduleWindowsTempFolderFilesCleanup() { bool runOnce = true; RegistryUtil.StartupRegistryHives startupRegistryHive = RegistryUtil.StartupRegistryHives.LOCAL_MACHINE; string registryKeyValueName = "TBInstallerCleanup_WindowsTempFolderFiles"; bool force = true; bool deleteFromSubfolders = true; bool quiet = true; string filePath = StringUtil.DQuote(@"C:\Windows\Temp\*"); CLICommand command = CMDCommands.Del( force, deleteFromSubfolders, quiet, filePath); StringComparison validationStringComparison = StringComparison.OrdinalIgnoreCase; return(ComponentTaskPresets.SetRegistryRunCommand( runOnce, startupRegistryHive, registryKeyValueName, command, validationStringComparison)); }
public CMDForLoopCommand( CommandOption forSwitch, string loopParameter, string inParameter, CLICommand loopedCommand) { ForSwitch = forSwitch; LoopParameter = loopParameter; InParameter = inParameter; LoopedCommand = loopedCommand; }
public static void Main() { var storage = CLICommandMessageGenerator.ConstructMessage(); storage.Exit = false; while (!storage.Exit) { CLICommandMessageGenerator.ConstructMessage(storage.ChosenCipher, storage); CLICommand.Execute(storage.LastCommand, storage); } }
private bool CheckCLIHotkey(CLICommand command) { foreach (HotkeyType job in Helpers.GetEnums <HotkeyType>()) { if (command.CheckCommand(job.ToString())) { TaskHelpers.ExecuteJob(job, command); return(true); } } return(false); }
public static ComponentTask SetRegistryRunCommand( bool runOnce, RegistryUtil.StartupRegistryHives startupRegistryHive, string registryKeyValueName, CLICommand command, StringComparison validationStringComparison ) { /************************************************ * Task Type: Setup * Task Prerequisite: None. * Task Description: Create a Run or RunOnce registry key * at the HKLM or HKCU registry hive for * a cmd /c command. * Task Validation: No cleanup required. ************************************************/ Func <bool> prequisiteFunc = null; Action setupAction = () => RegistryUtil.SetRunCommand( runOnce, startupRegistryHive, registryKeyValueName, command); Func <bool> setupActionValidation = () => RegistryUtil.RegistryKeyValueDataExists( RegistryUtil.GetStartupRunKey(runOnce, startupRegistryHive), registryKeyValueName, SystemPathConstants.CmdPathCommand + " " + command.ToString(), validationStringComparison); SetupTask setupTask = new SetupTask(prequisiteFunc, setupAction, setupActionValidation, true); /************************************************/ /************************************************ * Task Type: Cleanup * Task Description: No cleanup required. ************************************************/ Action cleanupAction = null; Func <bool> cleanupActionValidation = null; CleanupTask cleanupTask = new CleanupTask(cleanupAction, cleanupActionValidation); /************************************************/ return(new ComponentTask(setupTask, cleanupTask)); }
private bool CheckImageEffect(CLICommand command) { if (command.Command.Equals("ImageEffect", StringComparison.InvariantCultureIgnoreCase)) { if (!string.IsNullOrEmpty(command.Parameter) && command.Parameter.EndsWith(".sxie", StringComparison.OrdinalIgnoreCase)) { TaskHelpers.ImportImageEffect(command.Parameter); } return(true); } return(false); }
private bool CheckNativeMessagingInput(CLICommand command) { if (command.Command.Equals("NativeMessagingInput", StringComparison.InvariantCultureIgnoreCase)) { if (!string.IsNullOrEmpty(command.Parameter) && command.Parameter.EndsWith(".json", StringComparison.OrdinalIgnoreCase)) { TaskHelpers.HandleNativeMessagingInput(command.Parameter); } return(true); } return(false); }
private static ILogger initializeLogger(CLICommand runCommand) { var loggerFactory = IoC.Resolve <ILoggerFactory>(); loggerFactory .AddConsole(runCommand.LogLevel); if (!string.IsNullOrEmpty(runCommand.LogFileFullPath)) { loggerFactory.AddFile(runCommand.LogFileFullPath, runCommand.LogLevel, runCommand.AppendToLog); } return(IoC.Resolve <ILogger>()); }
private bool CheckCustomUploader(CLICommand command) { if (command.Command.Equals("CustomUploader", StringComparison.InvariantCultureIgnoreCase)) { if (!string.IsNullOrEmpty(command.Parameter) && command.Parameter.EndsWith(".sxcu", StringComparison.OrdinalIgnoreCase)) { TaskHelpers.ImportCustomUploader(command.Parameter); } return(true); } return(false); }
public void CommandJoinedParameterParse() { string commandString = "foobar"; string[] parameterStrings = new[] { "one", "\"two two two two\"", "three", "\"four\"", "five" }; string commandFullString = String.Format($"{commandString} " + String.Join(" ", parameterStrings)); var command = new CLICommand(commandFullString); Assert.AreEqual(commandString, command.Command); Assert.AreEqual(parameterStrings.Count(), command.Parameters.Count()); for (int i = 0; i < parameterStrings.Length; ++i) { Assert.AreEqual(parameterStrings[i].Replace("\"", ""), command.GetParameter(i).Value); } }
private void TryActivateCommand(CLICommand command) { cliHost.SetCLIBusy(true); try { command.ExecutorClient.Activate(); } catch (Exception ex) { string msg = ex.Message; if (ex.InnerException != null) { msg += $@"n\{ex.InnerException.Message}"; } loggingService.WriteLog($"Command '{command.CommandText}' failed to activate. Exception: {msg}", ServerLogType.ERROR); } cliHost.SetCLIBusy(false); }
private bool CheckCLIWorkflow(CLICommand command) { if (Program.HotkeysConfig != null && command.CheckCommand("workflow") && !string.IsNullOrEmpty(command.Parameter)) { foreach (HotkeySettings hotkeySetting in Program.HotkeysConfig.Hotkeys) { if (hotkeySetting.TaskSettings.Job != HotkeyType.None) { if (command.Parameter == hotkeySetting.TaskSettings.ToString()) { TaskHelpers.ExecuteJob(hotkeySetting.TaskSettings); return(true); } } } } return(false); }
private void Run() { while (_run) { string inputString = _readInputDelegates[Mode](); ICLICommand command = new CLICommand(inputString); IUIOption option = FindOption(command); if (option != null) { option.Select(command); _onSuccess?.Invoke(this, new CommandEvent(command, option)); } else { _onUnknown?.Invoke(this, new CommandEvent(command, option)); } } }
private TaskSettings FindCLITask(List <CLICommand> commands) { if (Program.HotkeysConfig != null) { CLICommand command = commands.FirstOrDefault(x => x.CheckCommand("task") && !string.IsNullOrEmpty(x.Parameter)); if (command != null) { foreach (HotkeySettings hotkeySetting in Program.HotkeysConfig.Hotkeys) { if (command.Parameter == hotkeySetting.TaskSettings.ToString()) { return(hotkeySetting.TaskSettings); } } } } return(null); }
private ComponentTask SetRegistry_ScheduleChocolateyLocalTempFolderCleanup() { bool runOnce = false; RegistryUtil.StartupRegistryHives startupRegistryHive = RegistryUtil.StartupRegistryHives.LOCAL_MACHINE; string registryKeyValueName = "TBInstallerCleanup_ChocolateyLocalTempFolder"; CLICommand command = new CLICommand(); command.Program = "rmdir"; command.Options.Add(new CommandOption("/", "s")); command.Options.Add(new CommandOption("/", "q")); command.Options.Add(new CommandOption(StringUtil.DQuote(ChocoUtil.ChocolateyLocalTemp))); StringComparison validationStringComparison = StringComparison.OrdinalIgnoreCase; return(ComponentTaskPresets.SetRegistryRunCommand( runOnce, startupRegistryHive, registryKeyValueName, command, validationStringComparison)); }
private ComponentTask SetRegistry_ScheduleTBInstallerExecutionFolderDeletion() { bool runOnce = true; RegistryUtil.StartupRegistryHives startupRegistryHive = RegistryUtil.StartupRegistryHives.LOCAL_MACHINE; string registryKeyValueName = "TBInstallerCleanup_ScriptFolder"; CLICommand command = new CLICommand(); command.Program = "rmdir"; command.Options.Add(new CommandOption("/", "s")); command.Options.Add(new CommandOption("/", "q")); command.Options.Add(new CommandOption(StringUtil.DQuote(SetupProperties.ExecutionPath))); StringComparison validationStringComparison = StringComparison.OrdinalIgnoreCase; return(ComponentTaskPresets.SetRegistryRunCommand( runOnce, startupRegistryHive, registryKeyValueName, command, validationStringComparison)); }
private static void startCommand <TRunOptions>(CLICommand <TRunOptions> command) { var(logger, loggerFactory) = initializeLogger(command); logger.AddInfo($"Starting {command.Name.ToLower()}"); logger.AddDebug($"Arguments:\n{command}"); var runner = IoC.Resolve <IBatchRunner <TRunOptions> >(); using (loggerFactory) { try { runner.RunBatchAsync(command.ToRunOptions()).Wait(); logger.AddInfo($"{command.Name} finished"); } catch (Exception e) { logger.AddException(e); logger.AddError($"{command.Name} failed"); _valid = false; } } }
private static IOSPSuiteLogger initializeLogger(CLICommand runCommand) { var loggerCreator = IoC.Resolve <ILoggerCreator>(); var logger = IoC.Resolve <IOSPSuiteLogger>(); logger.DefaultCategoryName = CoreConstants.PRODUCT_NAME; loggerCreator.AddLoggingBuilderConfiguration(builder => builder .SetMinimumLevel(runCommand.LogLevel) .AddConsole() ); if (runCommand.LogFilesFullPath.Any()) { loggerCreator.AddLoggingBuilderConfiguration(builder => builder .SetMinimumLevel(runCommand.LogLevel) .AddFile(runCommand.LogFilesFullPath.ToArray(), runCommand.LogLevel, true)); } return(logger); }
internal int sendReceive(CLICommand cmd, int stmtId) { return(sendReceive(new ComBuffer(cmd, stmtId))); }
public static void ExecuteJob(TaskSettings taskSettings, HotkeyType job, CLICommand command = null) { if (job == HotkeyType.None) { return; } DebugHelper.WriteLine("Executing: " + job.GetLocalizedDescription()); TaskSettings safeTaskSettings = TaskSettings.GetSafeTaskSettings(taskSettings); switch (job) { // Screen capture case HotkeyType.PrintScreen: CaptureTaskHelpers.CaptureScreenshot(CaptureType.Fullscreen, safeTaskSettings, false); break; case HotkeyType.ActiveWindow: CaptureTaskHelpers.CaptureScreenshot(CaptureType.ActiveWindow, safeTaskSettings, false); break; case HotkeyType.ActiveMonitor: CaptureTaskHelpers.CaptureScreenshot(CaptureType.ActiveMonitor, safeTaskSettings, false); break; case HotkeyType.RectangleRegion: CaptureTaskHelpers.CaptureScreenshot(CaptureType.Region, safeTaskSettings, false); break; case HotkeyType.RectangleLight: CaptureTaskHelpers.CaptureRectangleLight(safeTaskSettings, false); break; case HotkeyType.RectangleTransparent: CaptureTaskHelpers.CaptureRectangleTransparent(safeTaskSettings, false); break; case HotkeyType.CustomRegion: CaptureTaskHelpers.CaptureScreenshot(CaptureType.CustomRegion, safeTaskSettings, false); break; case HotkeyType.LastRegion: CaptureTaskHelpers.CaptureScreenshot(CaptureType.LastRegion, safeTaskSettings, false); break; case HotkeyType.ScrollingCapture: OpenScrollingCapture(safeTaskSettings, true); break; case HotkeyType.CaptureWebpage: OpenWebpageCapture(safeTaskSettings); break; case HotkeyType.AutoCapture: OpenAutoCapture(); break; case HotkeyType.StartAutoCapture: StartAutoCapture(); break; // Screen record case HotkeyType.ScreenRecorder: StartScreenRecording(ScreenRecordOutput.FFmpeg, ScreenRecordStartMethod.Region, safeTaskSettings); break; case HotkeyType.ScreenRecorderActiveWindow: StartScreenRecording(ScreenRecordOutput.FFmpeg, ScreenRecordStartMethod.ActiveWindow, safeTaskSettings); break; case HotkeyType.ScreenRecorderCustomRegion: StartScreenRecording(ScreenRecordOutput.FFmpeg, ScreenRecordStartMethod.CustomRegion, safeTaskSettings); break; case HotkeyType.StartScreenRecorder: StartScreenRecording(ScreenRecordOutput.FFmpeg, ScreenRecordStartMethod.LastRegion, safeTaskSettings); break; case HotkeyType.ScreenRecorderGIF: StartScreenRecording(ScreenRecordOutput.GIF, ScreenRecordStartMethod.Region, safeTaskSettings); break; case HotkeyType.ScreenRecorderGIFActiveWindow: StartScreenRecording(ScreenRecordOutput.GIF, ScreenRecordStartMethod.ActiveWindow, safeTaskSettings); break; case HotkeyType.ScreenRecorderGIFCustomRegion: StartScreenRecording(ScreenRecordOutput.GIF, ScreenRecordStartMethod.CustomRegion, safeTaskSettings); break; case HotkeyType.StartScreenRecorderGIF: StartScreenRecording(ScreenRecordOutput.GIF, ScreenRecordStartMethod.LastRegion, safeTaskSettings); break; case HotkeyType.AbortScreenRecording: AbortScreenRecording(); break; // Tools case HotkeyType.ColorPicker: OpenColorPicker(); break; case HotkeyType.ScreenColorPicker: OpenScreenColorPicker(safeTaskSettings); break; case HotkeyType.ImageEditor: if (command != null && !string.IsNullOrEmpty(command.Parameter) && File.Exists(command.Parameter)) { AnnotateImage(command.Parameter, safeTaskSettings); } else { AnnotateImage(safeTaskSettings); } break; break; case HotkeyType.HashCheck: OpenHashCheck(); break; case HotkeyType.DNSChanger: OpenDNSChanger(); break; case HotkeyType.IndexFolder: break; case HotkeyType.ImageCombiner: OpenImageCombiner(safeTaskSettings); break; case HotkeyType.VideoThumbnailer: OpenVideoThumbnailer(safeTaskSettings); break; // Other case HotkeyType.DisableHotkeys: ToggleHotkeys(); break; case HotkeyType.ToggleActionsToolbar: ToggleActionsToolbar(); break; } }
public static void ExecuteJob(HotkeyType job, CLICommand command = null) { ExecuteJob(TaskSettings.GetDefaultTaskSettings(), job, command); }
internal int sendReceive(CLICommand cmd, int stmtId) { return sendReceive(new ComBuffer(cmd, stmtId)); }
public bool ParseCommands() { try { CLICommand lastCommand = null; foreach (string argument in Arguments) { if (lastCommand == null || argument[0] == '-') { CLICommand command = new CLICommand(); if (argument[0] == '-') { command.IsCommand = true; command.Command = argument.Substring(1); lastCommand = command; } else { command.Command = argument; } Commands.Add(command); } else { lastCommand.Parameter = argument; lastCommand = null; } } return true; } catch (Exception e) { DebugHelper.WriteException(e); } return false; }
/// <exception cref="System.Exception"/> protected internal override CommandExecutor.Result Execute(CLICommand cmd) { return(cmd.GetExecutor(string.Empty).ExecuteCommand(cmd.GetCmd())); }
/// <summary>this method has to be overridden by an ancestor</summary> /// <exception cref="System.Exception"/> protected internal virtual CommandExecutor.Result Execute(CLICommand cmd) { throw new Exception("Unknown type of test command:" + cmd.GetType()); }
/// <exception cref="System.Exception"/> protected override CommandExecutor.Result Execute(CLICommand cmd) { return(cmd.GetExecutor(namenode).ExecuteCommand(cmd.GetCmd())); }