星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

App.cs 8.1KB

4 lat temu
4 lat temu
4 lat temu
4 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. using ComeCapture;
  2. using Common.system;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Security.RightsManagement;
  7. using System.Threading;
  8. using System.Windows;
  9. using System.Windows.Threading;
  10. using TStudyDigitalPen.HID;
  11. using XHWK.Model;
  12. namespace XHWK.WKTool
  13. {
  14. public partial class APP : Application
  15. {
  16. #region 全局变量
  17. /// <summary>
  18. /// 用户信息
  19. /// </summary>
  20. public static Model_UserInfo UserInfo=null;
  21. /// <summary>
  22. /// 接口返回消息
  23. /// </summary>
  24. public static string ServerMsg=string.Empty;
  25. /// <summary>
  26. /// 用户微课列表模型
  27. /// </summary>
  28. public static List<Model_WKData> WKDataList = null;
  29. /// <summary>
  30. /// 微课模型
  31. /// </summary>
  32. public static Model_WKData WKData = null;
  33. /// <summary>
  34. /// 微课视频列表
  35. /// </summary>
  36. public static List<Model_Video> VideoList = null;
  37. /// <summary>
  38. /// 主页面
  39. /// </summary>
  40. public static XHMicroLessonSystemWindow W_XHMicroLessonSystemWindow = null;
  41. /// <summary>
  42. /// 录屏工具
  43. /// </summary>
  44. public static FFMpeg FFmpeg = new FFMpeg();
  45. /// <summary>
  46. /// 开始录像
  47. /// </summary>
  48. public static CountdownWindow W_CountdownWindow = null;
  49. /// <summary>
  50. /// 录像工具栏
  51. /// </summary>
  52. public static ScreenRecordingToolbarWindow W_ScreenRecordingToolbarWindow = null;
  53. /// <summary>
  54. /// 登陆
  55. /// </summary>
  56. public static LoginWindow W_LoginWindow = null;
  57. /// <summary>
  58. /// 截图
  59. /// </summary>
  60. public static JieTuWindow W_JieTuWindow = null;
  61. /// <summary>
  62. /// 批注
  63. /// </summary>
  64. public static PracticeWindow W_PracticeWindow = null;
  65. /// <summary>
  66. /// 登陆状态 false 未登录 true已登陆
  67. /// </summary>
  68. public static bool IsLoginType = false;
  69. public static readonly Model_Page pageData = new Model.Model_Page();
  70. /// <summary>
  71. /// 防止图片地址重复
  72. /// </summary>
  73. public static long num = 9999;
  74. /// <summary>
  75. /// 导入图片路径
  76. /// </summary>
  77. public static string[] Paths = new string[] { };
  78. /// <summary>
  79. /// 截图图片路径
  80. /// </summary>
  81. public static string[] JPaths = new string[999];
  82. public static string ImgPath = string.Empty;
  83. /// <summary>
  84. /// 点阵笔
  85. /// </summary>
  86. public static DigitalPenHID digitalPen;
  87. /// <summary>
  88. /// 笔序号
  89. /// </summary>
  90. public static string PenSerial;
  91. /// <summary>
  92. /// 笔状态,是否已连接
  93. /// </summary>
  94. public static bool PenStatus;
  95. //labPenStatus
  96. #endregion
  97. [STAThread]
  98. private static void Main()
  99. {
  100. // 定义Application对象作为整个应用程序入口
  101. Application app = new Application();
  102. UserInfo = new Model_UserInfo();
  103. WKDataList = new List<Model_WKData>();
  104. WKData = new Model_WKData();
  105. VideoList = new List<Model_Video>();
  106. //app.DispatcherUnhandledException += MyApp_DispatcherUnhandledException;
  107. CreateAMicroLessonWindow win = new CreateAMicroLessonWindow();
  108. app.Run(win);
  109. //LogHelper.WriteInfoLog("启动项目");
  110. StopSameProcess();
  111. LatticeFileHelper.RunPrintConfig();
  112. }
  113. /// <summary>
  114. /// 结束已运行的程序
  115. /// </summary>
  116. private static void StopSameProcess()
  117. {
  118. Process current = Process.GetCurrentProcess();
  119. Process[] processList = Process.GetProcesses();
  120. foreach (Process process in processList)
  121. {
  122. if (process.ProcessName.ToUpper() == "XHSCHOOL")
  123. {
  124. if (process.Id != current.Id) //忽略当前进程
  125. {
  126. try
  127. {
  128. process.Kill(); //结束进程
  129. }
  130. catch (Exception)
  131. {
  132. }
  133. }
  134. }
  135. }
  136. }
  137. /// <summary>
  138. /// 错误处理
  139. /// </summary>
  140. /// <param name="sender"></param>
  141. /// <param name="e"></param>
  142. private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  143. {
  144. LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
  145. MessageBox.Show("程序异常." + Environment.NewLine + e.Exception.Message);
  146. e.Handled = true;
  147. }
  148. /// <summary>
  149. /// 保存微课信息
  150. /// </summary>
  151. public static void SaveWkData()
  152. {
  153. if(UserInfo == null)
  154. {
  155. return;
  156. }
  157. if (!string.IsNullOrWhiteSpace(APP.UserInfo.Username))
  158. {
  159. WKData.VideoList = VideoList;
  160. if (WKDataList != null)
  161. {
  162. WKDataList.RemoveAll(x => x.WkName == WKData.WkName);
  163. }
  164. else
  165. {
  166. WKDataList = new List<Model_WKData>();
  167. }
  168. WKDataList.Add(WKData);
  169. //string WkDateXmlStr = XmlUtilHelper.Serializer(typeof(Model_WKData), WKData);
  170. string WkDateXmlStr = XmlUtilHelper.XmlSerialize(WKDataList);
  171. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/");
  172. FileToolsCommon.CreateDirectory(SavePath);
  173. string SaveName = SavePath + "UserWkDate.d";
  174. FileToolsCommon.DeleteFile(SaveName);
  175. FileToolsCommon.WriteText(SaveName, WkDateXmlStr);
  176. }
  177. }
  178. /// <summary>
  179. /// 读取微课信息
  180. /// </summary>
  181. public static void ReadWkData()
  182. {
  183. if (UserInfo == null)
  184. {
  185. return;
  186. }
  187. if (!string.IsNullOrWhiteSpace(APP.UserInfo.Username))
  188. {
  189. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/");
  190. FileToolsCommon.CreateDirectory(SavePath);
  191. string SaveName = SavePath + "UserWkDate.d";
  192. if (FileToolsCommon.IsExistFile(SaveName))
  193. {
  194. string WkDateXmlStr=FileToolsCommon.FileToString(SaveName);
  195. WKDataList = XmlUtilHelper.DESerializer<List<Model_WKData>>(WkDateXmlStr);
  196. if (WKDataList != null)
  197. {
  198. WKDataList.RemoveAll(x => x.WkName == WKData.WkName);
  199. }
  200. }
  201. }
  202. }
  203. #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  204. /// <summary>
  205. /// 内存释放压缩
  206. /// </summary>
  207. /// <param name="e"></param>
  208. protected override void OnStartup(StartupEventArgs e)
  209. {
  210. //private LierdaCracker cracker = new LierdaCracker();
  211. //cracker.Cracker(5000);//间隔时间
  212. //base.OnStartup(e);
  213. new Thread(o =>
  214. {
  215. while (true)
  216. {
  217. try
  218. {
  219. //FreeMemoryHelper.SetDate();
  220. FreeMemoryHelper.ReallocateMemory();
  221. Thread.Sleep(20000);//暂定每20秒释放一次
  222. }
  223. catch (Exception ex)
  224. {
  225. LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
  226. }
  227. }
  228. }).Start();
  229. }
  230. #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  231. }
  232. }