예제 #1
0
        private static async Task <bool> InitShutdownSequence()
        {
            if (ShutdownSequenceInitialized)
            {
                return(false);
            }

            ShutdownSequenceInitialized = true;

            // Sockets created by HttpListener might still be running for a short while after complete app shutdown
            // Ensure that IPC is stopped before we finalize shutdown sequence
            if (IPC.IsRunning)
            {
                IPC.Stop();

                for (byte i = 0; (i < WebBrowser.MaxTries) && IPC.IsRunning; i++)
                {
                    await Task.Delay(1000).ConfigureAwait(false);
                }
            }

            if (Bot.Bots.Count > 0)
            {
                IEnumerable <Task> tasks = Bot.Bots.Values.Select(bot => Task.Run(() => bot.Stop(true)));

                switch (GlobalConfig.OptimizationMode)
                {
                case GlobalConfig.EOptimizationMode.MinMemoryUsage:
                    foreach (Task task in tasks)
                    {
                        await Task.WhenAny(task, Task.Delay(WebBrowser.MaxTries * 1000)).ConfigureAwait(false);
                    }

                    break;

                default:
                    await Task.WhenAny(Task.WhenAll(tasks), Task.Delay(Bot.Bots.Count *WebBrowser.MaxTries * 1000)).ConfigureAwait(false);

                    break;
                }

                // Extra second for Steam requests to go through
                await Task.Delay(1000).ConfigureAwait(false);
            }

            LogManager.Flush();
            return(true);
        }
예제 #2
0
        private static void OnConfigurationChanged(object sender, LoggingConfigurationChangedEventArgs e)
        {
            if ((sender == null) || (e == null))
            {
                ASF.ArchiLogger.LogNullError(nameof(sender) + " || " + nameof(e));
                return;
            }

            InitConsoleLoggers();

            if (IsWaitingForUserInput)
            {
                OnUserInputStart();
            }

            HistoryTarget historyTarget = LogManager.Configuration.AllTargets.OfType <HistoryTarget>().FirstOrDefault();

            IPC.OnNewHistoryTarget(historyTarget);
        }
예제 #3
0
        internal static void InitHistoryLogger()
        {
            if (IsUsingCustomConfiguration || (LogManager.Configuration == null))
            {
                return;
            }

            // TODO: We could use some nice HTML layout for this
            HistoryTarget historyTarget = new HistoryTarget("History")
            {
                Layout   = GeneralLayout,
                MaxCount = 20
            };

            LogManager.Configuration.AddTarget(historyTarget);
            LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, historyTarget));

            LogManager.ReconfigExistingLoggers();
            IPC.OnNewHistoryTarget(historyTarget);
        }
예제 #4
0
        private static void ParsePostInitArgs(IEnumerable <string> args)
        {
            if (args == null)
            {
                ASF.ArchiLogger.LogNullError(nameof(args));
                return;
            }

            foreach (string arg in args)
            {
                switch (arg)
                {
                case "":
                    break;

                case "--server":
                    IPC.Start();
                    break;

                case "--service":
                    ServiceMode = true;
                    break;

                default:
                    if (arg.StartsWith("--", StringComparison.Ordinal))
                    {
                        if (arg.StartsWith("--cryptkey=", StringComparison.Ordinal) && (arg.Length > 11))
                        {
                            CryptoHelper.SetEncryptionKey(arg.Substring(11));
                        }
                    }

                    break;
                }
            }
        }
예제 #5
0
 private static void OnProcessExit(object sender, EventArgs e) => IPC.Stop();
예제 #6
0
        private static void ParsePostInitArgs(IReadOnlyCollection <string> args)
        {
            if (args == null)
            {
                ASF.ArchiLogger.LogNullError(nameof(args));
                return;
            }

            bool cryptKeyNext = false;

            foreach (string arg in args)
            {
                switch (arg)
                {
                case "":
                    break;

                case "--path":
                    if (cryptKeyNext)
                    {
                        goto default;
                    }

                    // Not handled in PostInit
                    break;

                case "--cryptkey":
                    if (cryptKeyNext)
                    {
                        goto default;
                    }

                    cryptKeyNext = true;
                    break;

                case "--server":
                    if (cryptKeyNext)
                    {
                        goto default;
                    }

                    IPC.Start(GlobalConfig.IPCHost, GlobalConfig.IPCPort);
                    break;

                case "--service":
                    if (cryptKeyNext)
                    {
                        goto default;
                    }

                    ServiceMode = true;
                    break;

                default:
                    if (cryptKeyNext)
                    {
                        cryptKeyNext = false;
                        HandleCryptKeyArgument(arg);
                    }
                    else if (arg.StartsWith("--", StringComparison.Ordinal))
                    {
                        if (arg.StartsWith("--cryptkey=", StringComparison.Ordinal) && (arg.Length > 11))
                        {
                            HandleCryptKeyArgument(arg.Substring(11));
                        }
                    }

                    break;
                }
            }
        }
예제 #7
0
        private static void ParsePostInitArgs(IReadOnlyCollection <string> args)
        {
            if (args == null)
            {
                ASF.ArchiLogger.LogNullError(nameof(args));
                return;
            }

            bool cryptKeyNext = false;

            foreach (string arg in args)
            {
                switch (arg)
                {
                case "--cryptkey" when !cryptKeyNext:
                    cryptKeyNext = true;
                    break;

                case "--no-restart" when !cryptKeyNext:
                    RestartAllowed = false;
                    break;

                case "--process-required" when !cryptKeyNext:
                    ProcessRequired = true;
                    break;

                case "--server" when !cryptKeyNext:
                    // TODO: Deprecate further in the next version
                    ASF.ArchiLogger.LogGenericWarning(string.Format(Strings.WarningDeprecated, "--server", "GlobalConfig.IPC"));

                    ProcessRequired = true;

                    if (GlobalConfig.IPCPrefixes.Count > 0)
                    {
                        IPC.Start(GlobalConfig.IPCPrefixes);
                    }

                    break;

                case "--service" when !cryptKeyNext:
                    // TODO: Deprecate further in the next version
                    ASF.ArchiLogger.LogGenericWarning(string.Format(Strings.WarningDeprecated, "--service", "--no-restart --process-required --system-required"));
                    RestartAllowed  = false;
                    ProcessRequired = true;
                    SystemRequired  = true;
                    break;

                case "--system-required" when !cryptKeyNext:
                    SystemRequired = true;
                    break;

                default:
                    if (cryptKeyNext)
                    {
                        cryptKeyNext = false;
                        HandleCryptKeyArgument(arg);
                    }
                    else if ((arg.Length > 11) && arg.StartsWith("--cryptkey=", StringComparison.Ordinal))
                    {
                        HandleCryptKeyArgument(arg.Substring(11));
                    }

                    break;
                }
            }
        }