Init.cs 2.4 KB

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