Init.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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>().Log = new NLogger(Options.Instance.AppType.ToString(), Options.Instance.Process, 0);
  23. World.Instance.AddSingleton<CodeTypes, Assembly[]>(new[] { typeof (Init).Assembly });
  24. World.Instance.AddSingleton<EventSystem>();
  25. // 强制调用一下mongo,避免mongo库被裁剪
  26. MongoHelper.ToJson(1);
  27. ETTask.ExceptionHandler += Log.Error;
  28. Log.Info($"server start........................ ");
  29. switch (Options.Instance.AppType)
  30. {
  31. case AppType.ExcelExporter:
  32. {
  33. Options.Instance.Console = 1;
  34. ExcelExporter.Export();
  35. return 0;
  36. }
  37. case AppType.Proto2CS:
  38. {
  39. Options.Instance.Console = 1;
  40. Proto2CS.Export();
  41. return 0;
  42. }
  43. }
  44. }
  45. catch (Exception e)
  46. {
  47. Log.Console(e.ToString());
  48. }
  49. return 1;
  50. }
  51. }
  52. }