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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. using ComeCapture;
  2. using Common.system;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Reflection;
  7. using System.Security.Principal;
  8. using System.Security.RightsManagement;
  9. using System.Threading;
  10. using System.Windows;
  11. using System.Windows.Documents;
  12. using System.Windows.Threading;
  13. using TStudyDigitalPen.HID;
  14. using XHWK.Model;
  15. namespace XHWK.WKTool
  16. {
  17. public partial class APP : Application
  18. {
  19. #region 全局变量
  20. /// <summary>
  21. /// 用户信息
  22. /// </summary>
  23. public static Model_UserInfo UserInfo=null;
  24. /// <summary>
  25. /// 接口返回消息
  26. /// </summary>
  27. public static string ServerMsg=string.Empty;
  28. /// <summary>
  29. /// 用户微课列表模型
  30. /// </summary>
  31. public static List<Model_WKData> WKDataList = null;
  32. /// <summary>
  33. /// 微课模型
  34. /// </summary>
  35. public static Model_WKData WKData = null;
  36. /// <summary>
  37. /// 微课视频列表
  38. /// </summary>
  39. public static List<Model_Video> VideoList = null;
  40. /// <summary>
  41. /// 画板模型
  42. /// </summary>
  43. public static List<Model_DrawData> PageDrawList = null;
  44. /// <summary>
  45. /// 录屏工具
  46. /// </summary>
  47. public static FFMpeg FFmpeg = new FFMpeg();
  48. /// <summary>
  49. /// 登陆状态 false 未登录 true已登陆
  50. /// </summary>
  51. public static bool IsLoginType = false;
  52. public static readonly Model_Page pageData = new Model.Model_Page();
  53. /// <summary>
  54. /// 防止图片地址重复
  55. /// </summary>
  56. public static long num = 9999;
  57. /// <summary>
  58. /// 导入图片路径
  59. /// </summary>
  60. public static string[] Paths = new string[] { };
  61. /// <summary>
  62. /// 截图图片路径
  63. /// </summary>
  64. public static string[] JPaths = new string[999];
  65. public static string ImgPath = string.Empty;
  66. /// <summary>
  67. /// 页码IP
  68. /// </summary>
  69. public static string[] OutPut = new string[] { };
  70. public static string CameraPosition = string.Empty;
  71. /// <summary>
  72. /// 数据存放目录
  73. /// </summary>
  74. public static string DataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\XHMicroLesson\\";
  75. #region 点阵笔
  76. /// <summary>
  77. /// 点阵笔
  78. /// </summary>
  79. public static DigitalPenHID digitalPen;
  80. /// <summary>
  81. /// 笔序号
  82. /// </summary>
  83. public static string PenSerial;
  84. /// <summary>
  85. /// 笔状态,是否已连接
  86. /// </summary>
  87. public static bool PenStatus;
  88. #endregion
  89. #region 页面
  90. /// <summary>
  91. /// 主页面
  92. /// </summary>
  93. public static XHMicroLessonSystemWindow W_XHMicroLessonSystemWindow = null;
  94. /// <summary>
  95. /// 创建微课页面
  96. /// </summary>
  97. public static CreateAMicroLessonWindow W_CreateAMicroLessonWindow = null;
  98. /// <summary>
  99. /// 开始录像
  100. /// </summary>
  101. public static CountdownWindow W_CountdownWindow = null;
  102. /// <summary>
  103. /// 录像工具栏
  104. /// </summary>
  105. public static ScreenRecordingToolbarWindow W_ScreenRecordingToolbarWindow = null;
  106. /// <summary>
  107. /// 登陆
  108. /// </summary>
  109. public static LoginWindow W_LoginWindow = null;
  110. /// <summary>
  111. /// 截图
  112. /// </summary>
  113. public static JieTuWindow W_JieTuWindow = null;
  114. /// <summary>
  115. /// 批注
  116. /// </summary>
  117. public static PracticeWindow W_PracticeWindow = null;
  118. /// <summary>
  119. /// 我的视频
  120. /// </summary>
  121. public static FileDirectoryWindow fileDirectoryWindow = null;
  122. /// <summary>
  123. /// 打印
  124. /// </summary>
  125. public static PrintWindow W_PrintWindow = null;
  126. /// <summary>
  127. /// 提示窗口
  128. /// </summary>
  129. public static PromptWindow W_PromptWindow = null;
  130. #endregion
  131. #endregion
  132. [STAThread]
  133. private static void Main()
  134. {
  135. try
  136. {
  137. UserInfo = new Model_UserInfo();
  138. WKDataList = new List<Model_WKData>();
  139. WKData = new Model_WKData();
  140. VideoList = new List<Model_Video>();
  141. #region 强制以管理员方式运行 修改人:赵耀 修改时间:2020年9月7日
  142. WindowsIdentity identity = WindowsIdentity.GetCurrent();
  143. WindowsPrincipal principal = new WindowsPrincipal(identity);
  144. //判断当前登录用户是否为管理员
  145. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  146. {
  147. //如果是管理员,则直接运行
  148. W_CreateAMicroLessonWindow = new CreateAMicroLessonWindow();
  149. // 定义Application对象作为整个应用程序入口
  150. Application app = new Application();
  151. app.Run(W_CreateAMicroLessonWindow);
  152. //Application.Run(W_CreateAMicroLessonWindow);
  153. }
  154. else
  155. {
  156. //创建启动对象
  157. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
  158. startInfo.UseShellExecute = true;
  159. startInfo.WorkingDirectory = Environment.CurrentDirectory;
  160. startInfo.FileName = Assembly.GetExecutingAssembly().Location;
  161. //设置启动动作,确保以管理员身份运行
  162. startInfo.Verb = "runas";
  163. try
  164. {
  165. System.Diagnostics.Process.Start(startInfo);
  166. }
  167. catch
  168. {
  169. return;
  170. }
  171. //退出
  172. //Current.Shutdown();
  173. Environment.Exit(0);
  174. }
  175. #endregion
  176. }
  177. catch (Exception ex)
  178. {
  179. string ErrMessage = "【进程】(Main):进程意外关闭。 " + ex.Message;
  180. LogHelper.WriteErrLog(ErrMessage, ex);
  181. }
  182. StopSameProcess();
  183. Killffmpeg();
  184. LatticeFileHelper.RunPrintConfig();
  185. }
  186. #region 杀死已存在的进程
  187. /// <summary>
  188. /// 结束已运行的程序
  189. /// </summary>
  190. private static void StopSameProcess()
  191. {
  192. Process current = Process.GetCurrentProcess();
  193. Process[] processList = Process.GetProcesses();
  194. foreach (Process process in processList)
  195. {
  196. if (process.ProcessName.ToUpper() == "XHSCHOOL")
  197. {
  198. if (process.Id != current.Id) //忽略当前进程
  199. {
  200. try
  201. {
  202. process.Kill(); //结束进程
  203. }
  204. catch (Exception)
  205. {
  206. }
  207. }
  208. }
  209. }
  210. }
  211. /// <summary>
  212. /// 杀死正在运行的ffmpeg
  213. /// </summary>
  214. public static void Killffmpeg()
  215. {
  216. Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
  217. foreach (var KillProcess in KillProcessArray)
  218. {
  219. KillProcess.Kill();
  220. }
  221. }
  222. #endregion
  223. /// <summary>
  224. /// 错误处理
  225. /// </summary>
  226. /// <param name="sender"></param>
  227. /// <param name="e"></param>
  228. private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  229. {
  230. LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
  231. MessageBox.Show("程序异常." + Environment.NewLine + e.Exception.Message);
  232. e.Handled = true;
  233. }
  234. #region 数据保存和读取
  235. /// <summary>
  236. /// 保存微课信息
  237. /// </summary>
  238. public static void SaveWkData()
  239. {
  240. try
  241. {
  242. if (UserInfo == null)
  243. {
  244. return;
  245. }
  246. if (!string.IsNullOrWhiteSpace(APP.UserInfo.Username))
  247. {
  248. WKData.VideoList = VideoList;
  249. if (WKDataList != null)
  250. {
  251. WKDataList.RemoveAll(x => x.WkName == WKData.WkName);
  252. }
  253. else
  254. {
  255. WKDataList = new List<Model_WKData>();
  256. }
  257. WKDataList.Add(WKData);
  258. //string WkDateXmlStr = XmlUtilHelper.Serializer(typeof(Model_WKData), WKData);
  259. string WkDateXmlStr = XmlUtilHelper.XmlSerialize(WKDataList);
  260. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/");
  261. FileToolsCommon.CreateDirectory(SavePath);
  262. string SaveName = SavePath + "UserWkDate.d";
  263. FileToolsCommon.DeleteFile(SaveName);
  264. FileToolsCommon.WriteText(SaveName, WkDateXmlStr);
  265. }
  266. }
  267. catch (Exception ex)
  268. {
  269. LogHelper.WriteErrLog("【微课数据保存】(SaveWkData)保存失败:" + ex.Message, ex);
  270. }
  271. }
  272. /// <summary>
  273. /// 读取微课信息
  274. /// </summary>
  275. public static void ReadWkData()
  276. {
  277. try
  278. {
  279. if (UserInfo == null)
  280. {
  281. return;
  282. }
  283. if (!string.IsNullOrWhiteSpace(APP.UserInfo.Username))
  284. {
  285. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/");
  286. FileToolsCommon.CreateDirectory(SavePath);
  287. string SaveName = SavePath + "UserWkDate.d";
  288. //文件若存在则读取
  289. if (FileToolsCommon.IsExistFile(SaveName))
  290. {
  291. string WkDateXmlStr = FileToolsCommon.FileToString(SaveName);
  292. WKDataList = XmlUtilHelper.DESerializer<List<Model_WKData>>(WkDateXmlStr);
  293. }
  294. }
  295. }
  296. catch (Exception ex)
  297. {
  298. LogHelper.WriteErrLog("【微课数据读取】(ReadWkData)读取失败:" + ex.Message, ex);
  299. }
  300. }
  301. /// <summary>
  302. /// 保存画板数据
  303. /// </summary>
  304. public static void SaveDraw()
  305. {
  306. try
  307. {
  308. if (PageDrawList == null)
  309. {
  310. return;
  311. }
  312. if (PageDrawList.Count < 1)
  313. {
  314. return;
  315. }
  316. FileToolsCommon.CreateDirectory(WKData.WkPath);
  317. string SavePath = WKData.WkPath + "PageData.d";
  318. FileToolsCommon.DeleteFile(SavePath);
  319. string PageDataXmlStr = XmlUtilHelper.XmlSerialize(PageDrawList);
  320. FileToolsCommon.WriteText(SavePath, PageDataXmlStr);
  321. }
  322. catch (Exception ex)
  323. {
  324. LogHelper.WriteErrLog("【画板数据保存】(SaveDraw)保存失败:" + ex.Message, ex);
  325. }
  326. }
  327. /// <summary>
  328. /// 读取文件
  329. /// </summary>
  330. public static void ReadDrawData()
  331. {
  332. try
  333. {
  334. PageDrawList = new List<Model_DrawData>();
  335. FileToolsCommon.CreateDirectory(WKData.WkPath);
  336. string SavePath = WKData.WkPath + "PageData.d";
  337. if (FileToolsCommon.IsExistFile(SavePath))
  338. {
  339. string PageDataXmlStr = FileToolsCommon.FileToString(SavePath);
  340. PageDrawList = XmlUtilHelper.DESerializer<List<Model_DrawData>>(PageDataXmlStr);
  341. }
  342. }
  343. catch (Exception ex)
  344. {
  345. LogHelper.WriteErrLog("【画板数据读取】(ReadDraw)读取失败:" + ex.Message, ex);
  346. }
  347. }
  348. #endregion
  349. #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  350. /// <summary>
  351. /// 内存释放压缩
  352. /// </summary>
  353. /// <param name="e"></param>
  354. protected override void OnStartup(StartupEventArgs e)
  355. {
  356. //private LierdaCracker cracker = new LierdaCracker();
  357. //cracker.Cracker(5000);//间隔时间
  358. //base.OnStartup(e);
  359. new Thread(o =>
  360. {
  361. while (true)
  362. {
  363. try
  364. {
  365. //FreeMemoryHelper.SetDate();
  366. FreeMemoryHelper.ReallocateMemory();
  367. Thread.Sleep(20000);//暂定每20秒释放一次
  368. }
  369. catch (Exception ex)
  370. {
  371. LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
  372. }
  373. }
  374. }).Start();
  375. }
  376. #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  377. }
  378. }