Program.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using CommandLine;
  5. using NLog;
  6. namespace ET
  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. ProtobufHelper.Init();
  24. MongoHelper.Register(Game.EventSystem.GetTypes());
  25. // 命令行参数
  26. Options options = null;
  27. Parser.Default.ParseArguments<Options>(args)
  28. .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
  29. .WithParsed(o => { options = o; });
  30. Options.Instance = options;
  31. Game.ILog = new NLogger(Game.Options.AppType.ToString());
  32. LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Options.Process:000000}";
  33. Log.Info($"server start........................ {Game.Scene.Id}");
  34. switch (Game.Options.AppType)
  35. {
  36. case AppType.ExcelExporter:
  37. {
  38. Game.Options.Console = 1;
  39. ExcelExporter.Export();
  40. return 0;
  41. }
  42. case AppType.Proto2CS:
  43. {
  44. Game.Options.Console = 1;
  45. Proto2CS.Export();
  46. return 0;
  47. }
  48. }
  49. }
  50. catch (Exception e)
  51. {
  52. Log.Console(e.ToString());
  53. }
  54. return 1;
  55. }
  56. }
  57. }