Init.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using System.Threading;
  5. using CommandLine;
  6. namespace ET.Server
  7. {
  8. internal static class Init
  9. {
  10. private static int Main(string[] args)
  11. {
  12. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  13. {
  14. Log.Error(e.ExceptionObject.ToString());
  15. };
  16. try
  17. {
  18. // 命令行参数
  19. Parser.Default.ParseArguments<Options>(args)
  20. .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
  21. .WithParsed((o)=>World.Instance.AddSingleton(o));
  22. World.Instance.AddSingleton<Logger>().ILog = new NLogger(Options.Instance.AppType.ToString(), Options.Instance.Process, "../Config/NLog/NLog.config");
  23. World.Instance.AddSingleton<CodeTypes, Assembly[]>(new[] { typeof (Init).Assembly });
  24. World.Instance.AddSingleton<EventSystem>();
  25. MongoHelper.Register();
  26. ETTask.ExceptionHandler += Log.Error;
  27. Log.Info($"server start........................ ");
  28. switch (Options.Instance.AppType)
  29. {
  30. case AppType.ExcelExporter:
  31. {
  32. Options.Instance.Console = 1;
  33. ExcelExporter.Export();
  34. return 0;
  35. }
  36. case AppType.Proto2CS:
  37. {
  38. Options.Instance.Console = 1;
  39. Proto2CS.Export();
  40. return 0;
  41. }
  42. }
  43. }
  44. catch (Exception e)
  45. {
  46. Log.Console(e.ToString());
  47. }
  48. return 1;
  49. }
  50. }
  51. }