星火微课系统客户端
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 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. public static List<Model_DrawData> PageDrawList = null;
  38. /// <summary>
  39. /// 录屏工具
  40. /// </summary>
  41. public static FFMpeg FFmpeg = new FFMpeg();
  42. /// <summary>
  43. /// 登陆状态 false 未登录 true已登陆
  44. /// </summary>
  45. public static bool IsLoginType = false;
  46. public static readonly Model_Page pageData = new Model.Model_Page();
  47. /// <summary>
  48. /// 防止图片地址重复
  49. /// </summary>
  50. public static long num = 9999;
  51. /// <summary>
  52. /// 导入图片路径
  53. /// </summary>
  54. public static string[] Paths = new string[] { };
  55. /// <summary>
  56. /// 截图图片路径
  57. /// </summary>
  58. public static string[] JPaths = new string[999];
  59. public static string ImgPath = string.Empty;
  60. /// <summary>
  61. /// 页码IP
  62. /// </summary>
  63. public static string[] OutPut = new string[] { };
  64. #region 点阵笔
  65. /// <summary>
  66. /// 点阵笔
  67. /// </summary>
  68. public static DigitalPenHID digitalPen;
  69. /// <summary>
  70. /// 笔序号
  71. /// </summary>
  72. public static string PenSerial;
  73. /// <summary>
  74. /// 笔状态,是否已连接
  75. /// </summary>
  76. public static bool PenStatus;
  77. #endregion
  78. #region 页面
  79. /// <summary>
  80. /// 主页面
  81. /// </summary>
  82. public static XHMicroLessonSystemWindow W_XHMicroLessonSystemWindow = null;
  83. /// <summary>
  84. /// 创建微课页面
  85. /// </summary>
  86. public static CreateAMicroLessonWindow W_CreateAMicroLessonWindow = null;
  87. /// <summary>
  88. /// 开始录像
  89. /// </summary>
  90. public static CountdownWindow W_CountdownWindow = null;
  91. /// <summary>
  92. /// 录像工具栏
  93. /// </summary>
  94. public static ScreenRecordingToolbarWindow W_ScreenRecordingToolbarWindow = null;
  95. /// <summary>
  96. /// 登陆
  97. /// </summary>
  98. public static LoginWindow W_LoginWindow = null;
  99. /// <summary>
  100. /// 截图
  101. /// </summary>
  102. public static JieTuWindow W_JieTuWindow = null;
  103. /// <summary>
  104. /// 批注
  105. /// </summary>
  106. public static PracticeWindow W_PracticeWindow = null;
  107. #endregion
  108. #endregion
  109. [STAThread]
  110. private static void Main()
  111. {
  112. // 定义Application对象作为整个应用程序入口
  113. Application app = new Application();
  114. UserInfo = new Model_UserInfo();
  115. WKDataList = new List<Model_WKData>();
  116. WKData = new Model_WKData();
  117. VideoList = new List<Model_Video>();
  118. //app.DispatcherUnhandledException += MyApp_DispatcherUnhandledException;
  119. W_CreateAMicroLessonWindow = new CreateAMicroLessonWindow();
  120. app.Run(W_CreateAMicroLessonWindow);
  121. //LogHelper.WriteInfoLog("启动项目");
  122. StopSameProcess();
  123. Killffmpeg();
  124. LatticeFileHelper.RunPrintConfig();
  125. }
  126. /// <summary>
  127. /// 结束已运行的程序
  128. /// </summary>
  129. private static void StopSameProcess()
  130. {
  131. Process current = Process.GetCurrentProcess();
  132. Process[] processList = Process.GetProcesses();
  133. foreach (Process process in processList)
  134. {
  135. if (process.ProcessName.ToUpper() == "XHSCHOOL")
  136. {
  137. if (process.Id != current.Id) //忽略当前进程
  138. {
  139. try
  140. {
  141. process.Kill(); //结束进程
  142. }
  143. catch (Exception)
  144. {
  145. }
  146. }
  147. }
  148. }
  149. }
  150. /// <summary>
  151. /// 错误处理
  152. /// </summary>
  153. /// <param name="sender"></param>
  154. /// <param name="e"></param>
  155. private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  156. {
  157. LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
  158. MessageBox.Show("程序异常." + Environment.NewLine + e.Exception.Message);
  159. e.Handled = true;
  160. }
  161. #region 数据保存和读取
  162. /// <summary>
  163. /// 保存微课信息
  164. /// </summary>
  165. public static void SaveWkData()
  166. {
  167. try
  168. {
  169. if (UserInfo == null)
  170. {
  171. return;
  172. }
  173. if (!string.IsNullOrWhiteSpace(APP.UserInfo.Username))
  174. {
  175. WKData.VideoList = VideoList;
  176. if (WKDataList != null)
  177. {
  178. WKDataList.RemoveAll(x => x.WkName == WKData.WkName);
  179. }
  180. else
  181. {
  182. WKDataList = new List<Model_WKData>();
  183. }
  184. WKDataList.Add(WKData);
  185. //string WkDateXmlStr = XmlUtilHelper.Serializer(typeof(Model_WKData), WKData);
  186. string WkDateXmlStr = XmlUtilHelper.XmlSerialize(WKDataList);
  187. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/");
  188. FileToolsCommon.CreateDirectory(SavePath);
  189. string SaveName = SavePath + "UserWkDate.d";
  190. FileToolsCommon.DeleteFile(SaveName);
  191. FileToolsCommon.WriteText(SaveName, WkDateXmlStr);
  192. }
  193. }
  194. catch (Exception ex)
  195. {
  196. LogHelper.WriteErrLog("【微课数据保存】(SaveWkData)保存失败:" + ex.Message, ex);
  197. }
  198. }
  199. /// <summary>
  200. /// 读取微课信息
  201. /// </summary>
  202. public static void ReadWkData()
  203. {
  204. try
  205. {
  206. if (UserInfo == null)
  207. {
  208. return;
  209. }
  210. if (!string.IsNullOrWhiteSpace(APP.UserInfo.Username))
  211. {
  212. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/");
  213. FileToolsCommon.CreateDirectory(SavePath);
  214. string SaveName = SavePath + "UserWkDate.d";
  215. //文件若存在则读取
  216. if (FileToolsCommon.IsExistFile(SaveName))
  217. {
  218. string WkDateXmlStr = FileToolsCommon.FileToString(SaveName);
  219. WKDataList = XmlUtilHelper.DESerializer<List<Model_WKData>>(WkDateXmlStr);
  220. }
  221. }
  222. }
  223. catch (Exception ex)
  224. {
  225. LogHelper.WriteErrLog("【微课数据读取】(ReadWkData)读取失败:" + ex.Message, ex);
  226. }
  227. }
  228. /// <summary>
  229. /// 保存画板数据
  230. /// </summary>
  231. public static void SaveDraw()
  232. {
  233. try
  234. {
  235. if (PageDrawList == null)
  236. {
  237. return;
  238. }
  239. if (PageDrawList.Count < 1)
  240. {
  241. return;
  242. }
  243. FileToolsCommon.CreateDirectory(WKData.WkPath);
  244. string SavePath = WKData.WkPath + "PageData.d";
  245. FileToolsCommon.DeleteFile(SavePath);
  246. string PageDataXmlStr = XmlUtilHelper.XmlSerialize(PageDrawList);
  247. FileToolsCommon.WriteText(SavePath, PageDataXmlStr);
  248. }
  249. catch (Exception ex)
  250. {
  251. LogHelper.WriteErrLog("【画板数据保存】(SaveDraw)保存失败:" + ex.Message, ex);
  252. }
  253. }
  254. /// <summary>
  255. /// 读取文件
  256. /// </summary>
  257. public static void ReadDrawData()
  258. {
  259. try
  260. {
  261. PageDrawList = new List<Model_DrawData>();
  262. FileToolsCommon.CreateDirectory(WKData.WkPath);
  263. string SavePath = WKData.WkPath + "PageData.d";
  264. if (FileToolsCommon.IsExistFile(SavePath))
  265. {
  266. string PageDataXmlStr = FileToolsCommon.FileToString(SavePath);
  267. PageDrawList = XmlUtilHelper.DESerializer<List<Model_DrawData>>(PageDataXmlStr);
  268. }
  269. }
  270. catch (Exception ex)
  271. {
  272. LogHelper.WriteErrLog("【画板数据读取】(ReadDraw)读取失败:" + ex.Message, ex);
  273. }
  274. }
  275. #endregion
  276. /// <summary>
  277. /// 杀死正在运行的ffmpeg
  278. /// </summary>
  279. public static void Killffmpeg()
  280. {
  281. Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
  282. foreach (var KillProcess in KillProcessArray)
  283. {
  284. KillProcess.Kill();
  285. }
  286. }
  287. #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  288. /// <summary>
  289. /// 内存释放压缩
  290. /// </summary>
  291. /// <param name="e"></param>
  292. protected override void OnStartup(StartupEventArgs e)
  293. {
  294. //private LierdaCracker cracker = new LierdaCracker();
  295. //cracker.Cracker(5000);//间隔时间
  296. //base.OnStartup(e);
  297. new Thread(o =>
  298. {
  299. while (true)
  300. {
  301. try
  302. {
  303. //FreeMemoryHelper.SetDate();
  304. FreeMemoryHelper.ReallocateMemory();
  305. Thread.Sleep(20000);//暂定每20秒释放一次
  306. }
  307. catch (Exception ex)
  308. {
  309. LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
  310. }
  311. }
  312. }).Start();
  313. }
  314. #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  315. }
  316. }