Program.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using CommandLine;
  5. using NLog;
  6. namespace ET.Server
  7. {
  8. internal static class Program
  9. {
  10. private static int Main(string[] args)
  11. {
  12. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  13. {
  14. Log.Error(e.ExceptionObject.ToString());
  15. };
  16. ETTask.ExceptionHandler += Log.Error;
  17. // 异步方法全部会回掉到主线程
  18. SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
  19. try
  20. {
  21. Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(typeof (Game).Assembly);
  22. Game.EventSystem.Add(types);
  23. MongoHelper.Register(Game.EventSystem.GetTypes());
  24. // 命令行参数
  25. Options options = null;
  26. Parser.Default.ParseArguments<Options>(args)
  27. .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
  28. .WithParsed(o => { options = o; });
  29. Options.Instance = options;
  30. Game.ILog = new NLogger(Game.Options.AppType.ToString());
  31. LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Options.Process:000000}";
  32. Log.Info($"server start........................ {Game.Scene.Id}");
  33. switch (Game.Options.AppType)
  34. {
  35. case AppType.ExcelExporter:
  36. {
  37. Game.Options.Console = 1;
  38. ExcelExporter.Export();
  39. return 0;
  40. }
  41. case AppType.Proto2CS:
  42. {
  43. Game.Options.Console = 1;
  44. Proto2CS.Export();
  45. return 0;
  46. }
  47. }
  48. }
  49. catch (Exception e)
  50. {
  51. Log.Console(e.ToString());
  52. }
  53. return 1;
  54. }
  55. }
  56. }