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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. /// <summary>
  108. /// 我的视频
  109. /// </summary>
  110. public static FileDirectoryWindow fileDirectoryWindow = null;
  111. #endregion
  112. #endregion
  113. [STAThread]
  114. private static void Main()
  115. {
  116. // 定义Application对象作为整个应用程序入口
  117. Application app = new Application();
  118. UserInfo = new Model_UserInfo();
  119. WKDataList = new List<Model_WKData>();
  120. WKData = new Model_WKData();
  121. VideoList = new List<Model_Video>();
  122. //app.DispatcherUnhandledException += MyApp_DispatcherUnhandledException;
  123. W_CreateAMicroLessonWindow = new CreateAMicroLessonWindow();
  124. app.Run(W_CreateAMicroLessonWindow);
  125. //LogHelper.WriteInfoLog("启动项目");
  126. StopSameProcess();
  127. Killffmpeg();
  128. LatticeFileHelper.RunPrintConfig();
  129. }
  130. /// <summary>
  131. /// 结束已运行的程序
  132. /// </summary>
  133. private static void StopSameProcess()
  134. {
  135. Process current = Process.GetCurrentProcess();
  136. Process[] processList = Process.GetProcesses();
  137. foreach (Process process in processList)
  138. {
  139. if (process.ProcessName.ToUpper() == "XHSCHOOL")
  140. {
  141. if (process.Id != current.Id) //忽略当前进程
  142. {
  143. try
  144. {
  145. process.Kill(); //结束进程
  146. }
  147. catch (Exception)
  148. {
  149. }
  150. }
  151. }
  152. }
  153. }
  154. /// <summary>
  155. /// 错误处理
  156. /// </summary>
  157. /// <param name="sender"></param>
  158. /// <param name="e"></param>
  159. private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  160. {
  161. LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
  162. MessageBox.Show("程序异常." + Environment.NewLine + e.Exception.Message);
  163. e.Handled = true;
  164. }
  165. #region 数据保存和读取
  166. /// <summary>
  167. /// 保存微课信息
  168. /// </summary>
  169. public static void SaveWkData()
  170. {
  171. try
  172. {
  173. if (UserInfo == null)
  174. {
  175. return;
  176. }
  177. if (!string.IsNullOrWhiteSpace(APP.UserInfo.Username))
  178. {
  179. WKData.VideoList = VideoList;
  180. if (WKDataList != null)
  181. {
  182. WKDataList.RemoveAll(x => x.WkName == WKData.WkName);
  183. }
  184. else
  185. {
  186. WKDataList = new List<Model_WKData>();
  187. }
  188. WKDataList.Add(WKData);
  189. //string WkDateXmlStr = XmlUtilHelper.Serializer(typeof(Model_WKData), WKData);
  190. string WkDateXmlStr = XmlUtilHelper.XmlSerialize(WKDataList);
  191. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/");
  192. FileToolsCommon.CreateDirectory(SavePath);
  193. string SaveName = SavePath + "UserWkDate.d";
  194. FileToolsCommon.DeleteFile(SaveName);
  195. FileToolsCommon.WriteText(SaveName, WkDateXmlStr);
  196. }
  197. }
  198. catch (Exception ex)
  199. {
  200. LogHelper.WriteErrLog("【微课数据保存】(SaveWkData)保存失败:" + ex.Message, ex);
  201. }
  202. }
  203. /// <summary>
  204. /// 读取微课信息
  205. /// </summary>
  206. public static void ReadWkData()
  207. {
  208. try
  209. {
  210. if (UserInfo == null)
  211. {
  212. return;
  213. }
  214. if (!string.IsNullOrWhiteSpace(APP.UserInfo.Username))
  215. {
  216. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/");
  217. FileToolsCommon.CreateDirectory(SavePath);
  218. string SaveName = SavePath + "UserWkDate.d";
  219. //文件若存在则读取
  220. if (FileToolsCommon.IsExistFile(SaveName))
  221. {
  222. string WkDateXmlStr = FileToolsCommon.FileToString(SaveName);
  223. WKDataList = XmlUtilHelper.DESerializer<List<Model_WKData>>(WkDateXmlStr);
  224. }
  225. }
  226. }
  227. catch (Exception ex)
  228. {
  229. LogHelper.WriteErrLog("【微课数据读取】(ReadWkData)读取失败:" + ex.Message, ex);
  230. }
  231. }
  232. /// <summary>
  233. /// 保存画板数据
  234. /// </summary>
  235. public static void SaveDraw()
  236. {
  237. try
  238. {
  239. if (PageDrawList == null)
  240. {
  241. return;
  242. }
  243. if (PageDrawList.Count < 1)
  244. {
  245. return;
  246. }
  247. FileToolsCommon.CreateDirectory(WKData.WkPath);
  248. string SavePath = WKData.WkPath + "PageData.d";
  249. FileToolsCommon.DeleteFile(SavePath);
  250. string PageDataXmlStr = XmlUtilHelper.XmlSerialize(PageDrawList);
  251. FileToolsCommon.WriteText(SavePath, PageDataXmlStr);
  252. }
  253. catch (Exception ex)
  254. {
  255. LogHelper.WriteErrLog("【画板数据保存】(SaveDraw)保存失败:" + ex.Message, ex);
  256. }
  257. }
  258. /// <summary>
  259. /// 读取文件
  260. /// </summary>
  261. public static void ReadDrawData()
  262. {
  263. try
  264. {
  265. PageDrawList = new List<Model_DrawData>();
  266. FileToolsCommon.CreateDirectory(WKData.WkPath);
  267. string SavePath = WKData.WkPath + "PageData.d";
  268. if (FileToolsCommon.IsExistFile(SavePath))
  269. {
  270. string PageDataXmlStr = FileToolsCommon.FileToString(SavePath);
  271. PageDrawList = XmlUtilHelper.DESerializer<List<Model_DrawData>>(PageDataXmlStr);
  272. }
  273. }
  274. catch (Exception ex)
  275. {
  276. LogHelper.WriteErrLog("【画板数据读取】(ReadDraw)读取失败:" + ex.Message, ex);
  277. }
  278. }
  279. #endregion
  280. /// <summary>
  281. /// 杀死正在运行的ffmpeg
  282. /// </summary>
  283. public static void Killffmpeg()
  284. {
  285. Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
  286. foreach (var KillProcess in KillProcessArray)
  287. {
  288. KillProcess.Kill();
  289. }
  290. }
  291. #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  292. /// <summary>
  293. /// 内存释放压缩
  294. /// </summary>
  295. /// <param name="e"></param>
  296. protected override void OnStartup(StartupEventArgs e)
  297. {
  298. //private LierdaCracker cracker = new LierdaCracker();
  299. //cracker.Cracker(5000);//间隔时间
  300. //base.OnStartup(e);
  301. new Thread(o =>
  302. {
  303. while (true)
  304. {
  305. try
  306. {
  307. //FreeMemoryHelper.SetDate();
  308. FreeMemoryHelper.ReallocateMemory();
  309. Thread.Sleep(20000);//暂定每20秒释放一次
  310. }
  311. catch (Exception ex)
  312. {
  313. LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
  314. }
  315. }
  316. }).Start();
  317. }
  318. #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  319. }
  320. }