Init.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. //Process process = Game.Instance.Create();
  24. // 异步方法全部会回掉到主线程
  25. //process.AddSingleton<MainThreadSynchronizationContext>();
  26. //process.AddSingleton<TimeInfo>();
  27. //process.AddSingleton<ObjectPool>();
  28. //process.AddSingleton<IdGenerater>();
  29. World.Instance.AddSingleton<CodeTypes, Assembly[]>(new[] { typeof (Init).Assembly });
  30. World.Instance.AddSingleton<EventSystem>();
  31. MongoHelper.Register();
  32. ETTask.ExceptionHandler += Log.Error;
  33. //
  34. //process.AddSingleton<EntitySystemSingleton>();
  35. //
  36. //process.AddSingleton<Root>();
  37. //MongoHelper.Register();
  38. Log.Info($"server start........................ ");
  39. switch (Options.Instance.AppType)
  40. {
  41. case AppType.ExcelExporter:
  42. {
  43. Options.Instance.Console = 1;
  44. ExcelExporter.Export();
  45. return 0;
  46. }
  47. case AppType.Proto2CS:
  48. {
  49. Options.Instance.Console = 1;
  50. Proto2CS.Export();
  51. return 0;
  52. }
  53. }
  54. }
  55. catch (Exception e)
  56. {
  57. Log.Console(e.ToString());
  58. }
  59. return 1;
  60. }
  61. }
  62. }