Пример #1
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Length == 0 || args[0] == "help")
                {
                    Console.WriteLine("Expecting command");
                    Console.WriteLine("Available commands:");
                    Console.WriteLine(" * run <instanceName> <arguments>");
                    Console.WriteLine("   --discord-token - discord auth token string [MANDATORY]");
                    Console.WriteLine("   --tracker-url - tracker service url [default=none]");
                    Console.WriteLine("   --tracker-token - tracker service auth token [default=none]");
                    Console.WriteLine("   --data-directory - db storage location [default=./]");
                    Console.WriteLine(" * stop <instanceName>");
                    return;
                }

                BotProperties botProperties = BotProperties.Parse(args);
                _instanceName = botProperties.InstanceName;

                NLog.LayoutRenderers.LayoutRenderer.Register("instance", (logevent) => botProperties.InstanceName);
                NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration("logger.config");
                _logger = NLog.LogManager.GetCurrentClassLogger();

                if (string.IsNullOrEmpty(_instanceName))
                {
                    throw new ArgumentException("Instance name is not set");
                }

                if (botProperties.Command == "run")
                {
                    Run(botProperties);
                }
                else if (botProperties.Command == "stop")
                {
                    Stop();
                }
                else
                {
                    throw new ArgumentException("Unknown command '" + botProperties.Command + "'");
                }
            }
            catch (Exception ex)
            {
                LogError(ex.ToString());
            }
            finally
            {
                NLog.LogManager.Shutdown();
            }
        }