Program.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using FISLib;
  2. using System.Diagnostics;
  3. using Vinno.vCloud.FIS.CrossPlatform.Linux;
  4. using Vinno.vCloud.FIS.CrossPlatform.Linux.Hardware;
  5. namespace FIS.Linux
  6. {
  7. internal class Program
  8. {
  9. private static readonly ManualResetEvent _manualResetEvent = new ManualResetEvent(false);
  10. private static void Main(string[] args)
  11. {
  12. try
  13. {
  14. Console.WriteLine($"FIS.Linux Init Begin");
  15. string logPath = string.Empty;
  16. if (args.Length == 1)
  17. {
  18. logPath = args[0];
  19. }
  20. FISIMPL.FISIMPL.InitFISLogPath(logPath);
  21. AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
  22. _manualResetEvent.Reset();
  23. FISIMPL.FISIMPL.CloseFISExeEvent += OnCloseFISExe;
  24. FISLinux.Initialize(FISIMPL.FISIMPL.FISLogBasePath);
  25. var machineId = CpuInfo.MachineId;
  26. FISIMPL.FISIMPL.Start(machineId, FISPlatform.Linux);
  27. Console.WriteLine($"FIS.Linux Init Finished");
  28. while (true)
  29. {
  30. Thread.Sleep(1000);
  31. }
  32. }
  33. catch (Exception ex)
  34. {
  35. var errorMsg = $"FIS.Linux Main Error:{ex}";
  36. FISIMPL.FISIMPL.WriteErrorLog(errorMsg);
  37. Console.WriteLine(errorMsg);
  38. Process.GetCurrentProcess().Kill();
  39. }
  40. }
  41. private static void OnCloseFISExe(object? sender, EventArgs e)
  42. {
  43. try
  44. {
  45. var msg = $"FIS.Linux OnCloseFISExe Invoke!!!";
  46. FISIMPL.FISIMPL.WriteInfoLog(msg);
  47. Console.WriteLine(msg);
  48. FISIMPL.FISIMPL.CloseFISExeEvent -= OnCloseFISExe;
  49. Task.Run(() => KillSelf());
  50. FISIMPL.FISIMPL.Stop();
  51. _manualResetEvent.Set();
  52. }
  53. catch (Exception ex)
  54. {
  55. var errorMsg = $"FIS.Linux OnCloseFISExe Error:{ex}";
  56. FISIMPL.FISIMPL.WriteErrorLog(errorMsg);
  57. Console.WriteLine(errorMsg);
  58. Process.GetCurrentProcess().Kill();
  59. }
  60. }
  61. private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
  62. {
  63. var msg = $"FIS.Linux OnUnhandledException Invoke:{e.ExceptionObject}";
  64. FISIMPL.FISIMPL.WriteInfoLog(msg);
  65. Console.WriteLine(msg);
  66. }
  67. private static void KillSelf()
  68. {
  69. _manualResetEvent.WaitOne(5000);
  70. Process.GetCurrentProcess().Kill();
  71. }
  72. }
  73. }