星火微课系统客户端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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