星火微课系统客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

App.cs 11KB

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