Program.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows.Forms;
  4. using System.Threading;
  5. using Common.Logging;
  6. using ILog = Common.Logging.ILog;
  7. using Tofly.Core.Exceptions;
  8. using Tofly.Core.Context;
  9. using Tofly.Core.Context.Support;
  10. using Tofly.CoreUI.Message;
  11. using Tofly.CoreUI.Control;
  12. using Tofly.CoreUI.Plot.Win.Config;
  13. using Tofly.GISUI.Plugin;
  14. namespace Main.Win.Config
  15. {
  16. static class Program
  17. {
  18. /// <summary>
  19. /// 应用程序的主入口点。
  20. /// </summary>
  21. [STAThread]
  22. static void Main()
  23. {
  24. try
  25. {
  26. Application.ThreadException += Application_ThreadException;
  27. Application.EnableVisualStyles();
  28. AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
  29. Application.SetCompatibleTextRenderingDefault(false);
  30. try
  31. {
  32. IApplicationContext pContext = ContextRegistry.GetContext();
  33. IInitGISLicense license = pContext.GetObject("IInitGISLicense") as IInitGISLicense;
  34. license.InitializeLicense();
  35. }
  36. catch (Exception e)
  37. {
  38. if (e is Tofly.Core.SysRegist.SysRegistException)
  39. {
  40. //Tofly.SysReg.SysRegistForm from = new Tofly.SysReg.SysRegistForm();
  41. //from.ShowDialog();
  42. //MessageBox.Show("系统未注册,请使用正版软件!");
  43. Application.Exit();
  44. }
  45. try
  46. {
  47. ILog adviceLogger = LogManager.GetLogger(AppDomain.CurrentDomain.Id.ToString());
  48. adviceLogger.Error(e.Message, e);
  49. }
  50. catch { }
  51. }
  52. FormConfigureClass form = new FormConfigureClass();
  53. Application.Run(form);
  54. }
  55. catch (Exception e)
  56. {
  57. if (e is Tofly.Core.SysRegist.SysRegistException)
  58. {
  59. //Tofly.SysReg.SysRegistForm from = new Tofly.SysReg.SysRegistForm();
  60. //from.ShowDialog();
  61. Application.Exit();
  62. }
  63. try
  64. {
  65. ILog adviceLogger = LogManager.GetLogger(AppDomain.CurrentDomain.Id.ToString());
  66. adviceLogger.Error(e.Message, e);
  67. MessageManager.Show(MessageType.Error, e.Message);
  68. }
  69. catch { }
  70. }
  71. }
  72. /// <summary>
  73. /// 捕捉系统异常
  74. /// </summary>
  75. /// <param name="sender"></param>
  76. /// <param name="e"></param>
  77. static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  78. {
  79. UnhandleException(e.ExceptionObject as Exception);
  80. }
  81. /// <summary>
  82. /// 捕捉系统异常
  83. /// </summary>
  84. /// <param name="sender"></param>
  85. /// <param name="e"></param>
  86. private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
  87. {
  88. UnhandleException(e.Exception);
  89. }
  90. private static void UnhandleException(Exception e)
  91. {
  92. // 记录日志
  93. IException innerException = e as IException;
  94. ILog adviceLogger = LogManager.GetLogger(AppDomain.CurrentDomain.Id.ToString());
  95. try
  96. {
  97. if (innerException != null)
  98. {
  99. if (innerException is Tofly.Core.SysRegist.SysRegistException)
  100. {
  101. //Tofly.SysReg.SysRegistForm from = new Tofly.SysReg.SysRegistForm();
  102. //from.ShowDialog();
  103. //MessageBox.Show("系统未注册,请使用正版软件!");
  104. Application.Exit();
  105. }
  106. else
  107. {
  108. if (!innerException.IsLog)
  109. {
  110. adviceLogger.Error(e.Message, e);
  111. innerException.IsLog = true;
  112. }
  113. if (!innerException.IsShow)
  114. {
  115. innerException.IsShow = true;
  116. MessageManager.Show(Tofly.CoreUI.Message.MessageType.Error, e.Message);
  117. }
  118. }
  119. }
  120. else
  121. {
  122. adviceLogger.Error(e.Message, e);
  123. MessageManager.Show(Tofly.CoreUI.Message.MessageType.Error, e.Message);
  124. }
  125. }
  126. catch (Exception ex)
  127. {
  128. adviceLogger.Error(ex.Message, ex);
  129. }
  130. }
  131. }
  132. }