public static void Shutdown(ShutdownAction action) { if (!shutdownAlreadyInitiated) { shutdownAlreadyInitiated = true; ShutdownRequested = true; Task.WaitAll( //Task.Run(delegate { SaveLoad.SaveAll(); }) ); Log.WriteLogMessage("Shutdown complete", LogOutputLevel.Info); Thread.Sleep(1000); switch (action) { case ShutdownAction.Shutdown: Environment.Exit(69); break; case ShutdownAction.Restart: Environment.Exit(0); break; case ShutdownAction.Update: Environment.Exit(70); break; } Environment.Exit(69); } }
public static void ShutdownWMI(ShutdownAction action) { if (action == ShutdownAction.None) { return; } ManagementBaseObject mboShutdown = null; ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem"); mcWin32.Get(); // You can't shutdown without security privileges mcWin32.Scope.Options.EnablePrivileges = true; ManagementBaseObject mboShutdownParams = mcWin32.GetMethodParameters("Win32Shutdown"); // Flag 1 means we want to shut down the system. Use "2" to reboot. switch (action) { case ShutdownAction.Logoff: mboShutdownParams["Flags"] = "0"; break; case ShutdownAction.Reboot: mboShutdownParams["Flags"] = "2"; break; case ShutdownAction.Shutdown: mboShutdownParams["Flags"] = "1"; break; default: mboShutdownParams["Flags"] = "0"; break; } mboShutdownParams["Reserved"] = "0"; foreach (ManagementObject manObj in mcWin32.GetInstances()) { mboShutdown = manObj.InvokeMethod("Win32Shutdown", mboShutdownParams, null); } }
public void ValidateDataTest() { ShutdownAction target = new ShutdownAction(); target.ValidateData(); Assert.AreEqual(target.ConfigurationState, GenericAction.ConfigurationStates.Configured); }
public void ShutdownActionConstructorTest() { ShutdownAction target = new ShutdownAction(); Assert.AreEqual(55, target.Height, "The property 'Height' is not properly initialized"); Assert.IsTrue(target.IsTemplate, "The property 'IsTemplate' is not properly initialized"); Assert.IsFalse(target.IsSelected, "The property 'IsSelected' is not properly initialized"); }
private static System.Action GetAction(int taskID, ActionModel action) { IAction actionInstance = null; switch (action.Action) { case ActionType.WriteFile: actionInstance = new WriteFileAction(); break; case ActionType.IF: actionInstance = new IFAction(); break; case ActionType.HttpRequest: actionInstance = new HttpRequestAction(); break; case ActionType.Shutdown: actionInstance = new ShutdownAction(); break; case ActionType.StartProcess: actionInstance = new StartProcessAction(); break; case ActionType.OpenURL: actionInstance = new OpenURLAction(); break; case ActionType.Snipping: actionInstance = new SnippingAction(); break; case ActionType.DeleteFile: actionInstance = new DeleteFileAction(); break; case ActionType.SoundPlay: actionInstance = new SoundPlayAction(); break; case ActionType.GetIPAddress: actionInstance = new GetIPAddressAction(); break; case ActionType.Keyboard: actionInstance = new KeyboardAction(); break; } if (actionInstance != null) { return(actionInstance.GenerateAction(taskID, action)); } return(null); }
public void GetXMLActionTest() { ShutdownAction target = new ShutdownAction(); string expected = "<Action>\r\n<ElementType>CustomActions.ShutdownAction</ElementType>\r\n</Action>"; string actual; actual = target.GetXMLAction(); Assert.AreEqual(expected, actual, "The 'GetXMLAction' method doesn't return the good string"); }
public static void Shutdown(ShutdownAction action) { String param_string = ""; switch (action) { case ShutdownAction.Logoff: param_string = "-l"; break; case ShutdownAction.Reboot: param_string = "-r"; break; case ShutdownAction.Shutdown: param_string = "-s"; break; default: return; } System.Diagnostics.Process.Start("shutdown", param_string + " -f -t 0"); }
/* ***************************************************** */ /* Protected Methods */ /* ***************************************************** */ protected void SelectLoop() { Thread.CurrentThread.Name = "tcp_select_thread"; //No one can see this except this thread, so there is no //need for thread synchronization SocketState ss = new SocketState(this); ss.TAA = _ta_auth; if (ProtocolLog.Monitor.Enabled) { // log every 5 seconds. ActionQueue.Enqueue(new LogAction(new TimeSpan(0, 0, 0, 0, 5000), ActionQueue)); } //Start the select action: ActionQueue.Enqueue(new SelectAction(this)); bool got_action = false; while (ss.Run) { SocketStateAction a = ActionQueue.TryDequeue(out got_action); if (got_action) { a.Start(ss); } } ShutdownAction sda = new ShutdownAction(this); sda.Start(ss); //Empty the queue to remove references to old objects do { ActionQueue.TryDequeue(out got_action); } while(got_action); }
/// <summary> /// Shutdown the system. /// </summary> public static void ShutDown(ShutdownAction action, ShutdownForceMode forceMode) { ApiHelper.FailIfZero(ExitWindowsEx((uint)action | (uint)forceMode, SHTDN_REASON_FLAG_PLANNED)); }
/* ***************************************************** */ /* Protected Methods */ /* ***************************************************** */ protected void SelectLoop() { Thread.CurrentThread.Name = "tcp_select_thread"; //No one can see this except this thread, so there is no //need for thread synchronization SocketState ss = new SocketState(this); ss.TAA = _ta_auth; if( ProtocolLog.Monitor.Enabled ) { // log every 5 seconds. ActionQueue.Enqueue(new LogAction(new TimeSpan(0,0,0,0,5000), ActionQueue)); } //Start the select action: ActionQueue.Enqueue(new SelectAction(this)); bool got_action = false; while(ss.Run) { SocketStateAction a = ActionQueue.TryDequeue(out got_action); if( got_action ) { a.Start(ss); } } ShutdownAction sda = new ShutdownAction(this); sda.Start(ss); //Empty the queue to remove references to old objects do { ActionQueue.TryDequeue(out got_action); } while(got_action); }
public static void ShutDown(ShutdownAction action, ShutdownForceMode forceMode) { ApiHelper.FailIfZero(ExitWindowsEx((uint)action | (uint)forceMode, SHTDN_REASON_FLAG_PLANNED)); }
public static void ShutDown(ShutdownAction action) { ShutDown(action, ShutdownForceMode.NoForce); }
public void Start(string[] args) { Singleton = this; Console.Title = BaseWindowTitle; if (_restartsLimit > -1) { if (_restartsTimeWindow > 0) { if (!RestartsStopwatch.IsRunning) { RestartsStopwatch.Start(); } else if (RestartsStopwatch.Elapsed.TotalSeconds > _restartsTimeWindow) { RestartsStopwatch.Restart(); _restarts = 0; } } if (!_ignoreNextRestart) { _restarts++; } else { _ignoreNextRestart = false; } if (_restarts > _restartsLimit) { ConsoleUtil.WriteLine("Restarts limit exceeded.", ConsoleColor.Red); ExitAction = ShutdownAction.SilentShutdown; Exit(1); } } try { var reconfigure = false; var useDefault = false; if (_firstRun) { if (args.Length == 0 || !ushort.TryParse(args[0], out GamePort)) { ConsoleUtil.WriteLine("You can pass port number as first startup argument.", ConsoleColor.Green); Console.WriteLine(string.Empty); ConsoleUtil.Write("Port number (default: 7777): ", ConsoleColor.Green); ReadInput((input) => { if (!string.IsNullOrEmpty(input)) { return(ushort.TryParse(input, out GamePort)); } GamePort = 7777; return(true); }, () => { }, () => { ConsoleUtil.WriteLine("Port number must be a unsigned short integer.", ConsoleColor.Red); }); } var capture = CaptureArgs.None; foreach (var arg in args) { switch (capture) { case CaptureArgs.None: if (arg.StartsWith("-", StringComparison.Ordinal) && !arg.StartsWith("--", StringComparison.Ordinal) && arg.Length > 1) { for (var i = 1; i < arg.Length; i++) { switch (arg[i]) { case 'c': NoSetCursor = true; break; case 'p': PrintControlMessages = true; break; case 'n': AutoFlush = false; break; case 'l': EnableLogging = false; break; case 'r': reconfigure = true; break; case 's': _stdPrint = true; break; case 'd': useDefault = true; break; } } } else { switch (arg) { case "--noSetCursor": NoSetCursor = true; break; case "--printControl": PrintControlMessages = true; break; case "--noAutoFlush": AutoFlush = false; break; case "--noLogs": EnableLogging = false; break; case "--reconfigure": reconfigure = true; break; case "--printStd": _stdPrint = true; break; case "--useDefault": useDefault = true; break; case "--config": capture = CaptureArgs.ConfigPath; break; case "--logs": capture = CaptureArgs.LaLogsPath; break; case "--gameLogs": capture = CaptureArgs.GameLogsPath; break; case "--restartsLimit": capture = CaptureArgs.RestartsLimit; break; case "--restartsTimeWindow": capture = CaptureArgs.RestartsTimeWindow; break; case "--logLengthLimit": capture = CaptureArgs.LogLengthLimit; break; case "--logEntriesLimit": capture = CaptureArgs.LogEntriesLimit; break; case "--": capture = CaptureArgs.ArgsPassthrough; break; } } break; case CaptureArgs.ArgsPassthrough: _gameArguments += $"\"{arg}\" "; break; case CaptureArgs.ConfigPath: ConfigPath = arg; capture = CaptureArgs.None; break; case CaptureArgs.LaLogsPath: LaLogsPath = arg + Path.DirectorySeparatorChar; capture = CaptureArgs.None; break; case CaptureArgs.GameLogsPath: GameLogsPath = arg + Path.DirectorySeparatorChar; capture = CaptureArgs.None; break; case CaptureArgs.RestartsLimit: if (!int.TryParse(arg, out _restartsLimit) || _restartsLimit < -1) { _restartsLimit = 4; ConsoleUtil.WriteLine("restartsLimit argument value must be an integer greater or equal to -1.", ConsoleColor.Red); } capture = CaptureArgs.None; break; case CaptureArgs.RestartsTimeWindow: if (!int.TryParse(arg, out _restartsTimeWindow) || _restartsLimit < 0) { _restartsTimeWindow = 480; ConsoleUtil.WriteLine("restartsTimeWindow argument value must be an integer greater or equal to 0.", ConsoleColor.Red); } capture = CaptureArgs.None; break; case CaptureArgs.LogLengthLimit: { string a = arg.Replace("k", "000", StringComparison.Ordinal) .Replace("M", "000000", StringComparison.Ordinal) .Replace("G", "000000000", StringComparison.Ordinal) .Replace("T", "000000000000", StringComparison.Ordinal); if (!ulong.TryParse(a, out LogLengthLimit)) { ConsoleUtil.WriteLine( "logLengthLimit argument value must be an integer greater or equal to 0.", ConsoleColor.Red); LogLengthLimit = 25000000000; } capture = CaptureArgs.None; } break; case CaptureArgs.LogEntriesLimit: { string a = arg.Replace("k", "000", StringComparison.Ordinal) .Replace("M", "000000", StringComparison.Ordinal) .Replace("G", "000000000", StringComparison.Ordinal) .Replace("T", "000000000000", StringComparison.Ordinal); if (!ulong.TryParse(a, out LogEntriesLimit)) { ConsoleUtil.WriteLine( "logEntriesLimit argument value must be an integer greater or equal to 0.", ConsoleColor.Red); LogEntriesLimit = 10000000000; } capture = CaptureArgs.None; } break; default: throw new ArgumentOutOfRangeException(); } } } if (ConfigPath != null) { if (File.Exists(ConfigPath)) { Configuration = Config.DeserializeConfig(File.ReadAllLines(ConfigPath, Encoding.UTF8)); } else { reconfigure = true; } } else { var cfgPath = $"{GameUserDataRoot}config{Path.DirectorySeparatorChar}{GamePort}{Path.DirectorySeparatorChar}config_localadmin.txt"; if (File.Exists(cfgPath)) { Configuration = Config.DeserializeConfig(File.ReadAllLines(cfgPath, Encoding.UTF8)); } else { cfgPath = $"{GameUserDataRoot}config{Path.DirectorySeparatorChar}config_localadmin_global.txt"; if (File.Exists(cfgPath)) { Configuration = Config.DeserializeConfig(File.ReadAllLines(cfgPath, Encoding.UTF8)); } else { reconfigure = true; } } } if (reconfigure) { ConfigWizard.RunConfigWizard(useDefault); } NoSetCursor |= Configuration !.LaNoSetCursor; AutoFlush &= Configuration !.LaLogAutoFlush; EnableLogging &= Configuration !.EnableLaLogs; InputQueue.Clear(); if (_firstRun) { try { SetupExitHandlers(); } catch (Exception ex) { ConsoleUtil.WriteLine( $"Starting exit handlers threw {ex}. Game process will NOT be closed on console closing!", ConsoleColor.Yellow); } } if (_firstRun || _exit) { _exit = false; _firstRun = false; SetupKeyboardInput(); } RegisterCommands(); SetupReader(); StartSession(); _readerTask !.Start(); if (!EnableLogging) { ConsoleUtil.WriteLine("Logging has been disabled.", ConsoleColor.Red); } else if (!AutoFlush) { ConsoleUtil.WriteLine("Logs auto flush has been disabled.", ConsoleColor.Yellow); } if (PrintControlMessages) { ConsoleUtil.WriteLine("Printing control messages been enabled using startup argument.", ConsoleColor.Gray); } if (NoSetCursor) { ConsoleUtil.WriteLine("Cursor management been disabled.", ConsoleColor.Gray); } if (Configuration.LaDeleteOldLogs || Configuration.DeleteOldRoundLogs || Configuration.CompressOldRoundLogs) { LogCleaner.Initialize(); } while (!_exit) { Thread.Sleep(250); } // If the game was terminated intentionally, then wait, otherwise no Exit(0, true); // After the readerTask is completed this will happen } catch (Exception ex) { File.WriteAllText($"LocalAdmin Crash {DateTime.UtcNow:yyyy-MM-ddTHH-mm-ssZ}.txt", ex.ToString()); Logger.Log("|===| Exception |===|"); Logger.Log(ex); Logger.Log("|===================|"); Logger.Log(""); } }
private GenericAction GetElementFromXML(XmlReader reader) { GenericAction element = null; string elementType = reader.ReadElementContentAsString(); switch (elementType) { case "CustomActions.AddRegKeyAction": element = new AddRegKeyAction(); break; case "CustomActions.AddRegValueAction": element = new AddRegValueAction(); break; case "CustomActions.ChangeRegDataAction": element = new ChangeRegDataAction(); break; case "CustomActions.ChangeServiceAction": element = new ChangeServiceAction(); break; case "CustomActions.CopyFileAction": element = new CopyFileAction(); break; case "CustomActions.CreateFolderAction": element = new CreateFolderAction(); break; case "CustomActions.CreateShortcutAction": element = new CreateShortcutAction(); break; case "CustomActions.CreateTextFileAction": element = new CreateTextFileAction(); break; case "CustomActions.DeleteFileAction": element = new DeleteFileAction(); break; case "CustomActions.DeleteFolderAction": element = new DeleteFolderAction(); break; case "CustomActions.DeleteRegKeyAction": element = new DeleteRegKeyAction(); break; case "CustomActions.DeleteRegValueAction": element = new DeleteRegValueAction(); break; case "CustomActions.DeleteTaskAction": element = new DeleteTaskAction(); break; case "CustomActions.ExecutableAction": element = new ExecutableAction(); break; case "CustomActions.ImportRegFileAction": element = new ImportRegFileAction(); break; case "CustomActions.KillProcessAction": element = new KillProcessAction(); break; case "CustomActions.RebootAction": element = new RebootAction(); break; case "CustomActions.RegisterDLLAction": element = new RegisterDLLAction(); break; case "CustomActions.RenameFileAction": element = new RenameFileAction(); break; case "CustomActions.RenameFolderAction": element = new RenameFolderAction(); break; case "CustomActions.RenameRegKeyAction": element = new RenameRegKeyAction(); break; case "CustomActions.RenameRegValueAction": element = new RenameRegValueAction(); break; case "CustomActions.RunPowershellScriptAction": element = new RunPowershellScriptAction(); break; case "CustomActions.RunVbScriptAction": element = new RunVbScriptAction(); break; case "CustomActions.ShutdownAction": element = new ShutdownAction(); break; case "CustomActions.StartServiceAction": element = new StartServiceAction(); break; case "CustomActions.StopServiceAction": element = new StopServiceAction(); break; case "CustomActions.UninstallMsiProductByGuidAction": element = new UninstallMsiProductByGuidAction(); break; case "CustomActions.UninstallMsiProductByNameAction": element = new UninstallMsiProductByNameAction(); break; case "CustomActions.UnregisterDLLAction": element = new UnregisterDLLAction(); break; case "CustomActions.UnregisterServiceAction": element = new UnregisterServiceAction(); break; case "CustomActions.WaitAction": element = new WaitAction(); break; case "CustomActions.InstallMsiAction": element = new InstallMsiAction(); break; case "CustomActions.ReturnCode": try { this.SetReturnCodeFromXml(reader); } catch (Exception ex) { if (this.IsUIEnable) { System.Windows.Forms.MessageBox.Show(Localizator.Getinstance().GetLocalizedString("UnableToSetReturnCodeFromXmlFile") + "\r\n" + ex.Message); } else { throw new Exception(Localizator.Getinstance().GetLocalizedString("UnableToSetReturnCodeFromXmlFile") + "\r\n" + ex.Message); } } break; default: if (this.IsUIEnable) { System.Windows.Forms.MessageBox.Show(Localizator.Getinstance().GetLocalizedString("ThisActionHasNotBeenRecognized") + elementType); } else { throw new Exception(Localizator.Getinstance().GetLocalizedString("ThisActionHasNotBeenRecognized") + elementType); } break; } return(element); }
public DoShutdownAction(ShutdownAction action) { this.Action = action; }
/// <summary> /// Initializes a new instance of the <see cref="MessageDispatcher" /> class. /// </summary> /// <param name="configurator">TBD</param> protected MessageDispatcher(MessageDispatcherConfigurator configurator) { Configurator = configurator; Throughput = DefaultThroughput; _shutdownAction = new ShutdownAction(this); }
/// <summary> /// Initializes a new instance of the <see cref="MessageDispatcher" /> class. /// </summary> protected MessageDispatcher(MessageDispatcherConfigurator configurator) { Configurator = configurator; Throughput = DefaultThroughput; _shutdownAction = new ShutdownAction(this); }
/// <summary> /// Shutdown the system. /// </summary> public static void ShutDown(ShutdownAction action) { ShutDown(action, ShutdownForceMode.NoForce); }
private static IAction GetAction(ActionModel action) { IAction actionInstance = null; switch (action.Action) { case ActionType.WriteFile: actionInstance = new WriteFileAction(); break; case ActionType.IF: actionInstance = new IFAction(); break; case ActionType.HttpRequest: actionInstance = new HttpRequestAction(); break; case ActionType.Shutdown: actionInstance = new ShutdownAction(); break; case ActionType.StartProcess: actionInstance = new StartProcessAction(); break; case ActionType.OpenURL: actionInstance = new OpenURLAction(); break; case ActionType.Snipping: actionInstance = new SnippingAction(); break; case ActionType.DeleteFile: actionInstance = new DeleteFileAction(); break; case ActionType.SoundPlay: actionInstance = new SoundPlayAction(); break; case ActionType.GetIPAddress: actionInstance = new GetIPAddressAction(); break; case ActionType.Keyboard: actionInstance = new KeyboardAction(); break; case ActionType.SystemNotification: actionInstance = new SystemNotificationAction(); break; case ActionType.DownloadFile: actionInstance = new DownloadFileAction(); break; case ActionType.Dialog: actionInstance = new DialogAction(); break; case ActionType.Delay: actionInstance = new DelayAction(); break; case ActionType.Loops: actionInstance = new LoopsAction(); break; case ActionType.KillProcess: actionInstance = new KillProcessAction(); break; case ActionType.SetDeviceVolume: actionInstance = new SetDeviceVolumeAction(); break; case ActionType.Regex: actionInstance = new RegexAction(); break; case ActionType.ReadFile: actionInstance = new ReadFileAction(); break; case ActionType.JsonDeserialize: actionInstance = new JsonDeserializeAction(); break; } if (actionInstance != null) { return(actionInstance); } return(null); }
private ActionUnit(int priority, string name, ShutdownAction action) : base(name, priority) { Action = action; }