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

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