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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. public static PrintWindow W_PrintWindow = null;
  123. #endregion
  124. #endregion
  125. [STAThread]
  126. private static void Main()
  127. {
  128. try
  129. {
  130. UserInfo = new Model_UserInfo();
  131. WKDataList = new List<Model_WKData>();
  132. WKData = new Model_WKData();
  133. VideoList = new List<Model_Video>();
  134. #region 强制以管理员方式运行 修改人:赵耀 修改时间:2020年9月7日
  135. WindowsIdentity identity = WindowsIdentity.GetCurrent();
  136. WindowsPrincipal principal = new WindowsPrincipal(identity);
  137. //判断当前登录用户是否为管理员
  138. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  139. {
  140. //如果是管理员,则直接运行
  141. W_CreateAMicroLessonWindow = new CreateAMicroLessonWindow();
  142. // 定义Application对象作为整个应用程序入口
  143. Application app = new Application();
  144. app.Run(W_CreateAMicroLessonWindow);
  145. //Application.Run(W_CreateAMicroLessonWindow);
  146. }
  147. else
  148. {
  149. //创建启动对象
  150. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
  151. startInfo.UseShellExecute = true;
  152. startInfo.WorkingDirectory = Environment.CurrentDirectory;
  153. startInfo.FileName = Assembly.GetExecutingAssembly().Location;
  154. //设置启动动作,确保以管理员身份运行
  155. startInfo.Verb = "runas";
  156. try
  157. {
  158. System.Diagnostics.Process.Start(startInfo);
  159. }
  160. catch
  161. {
  162. return;
  163. }
  164. //退出
  165. //Current.Shutdown();
  166. Environment.Exit(0);
  167. }
  168. #endregion
  169. }
  170. catch (Exception ex)
  171. {
  172. string ErrMessage = "【进程】(Main):进程意外关闭。 " + ex.Message;
  173. LogHelper.WriteErrLog(ErrMessage, ex);
  174. }
  175. StopSameProcess();
  176. Killffmpeg();
  177. LatticeFileHelper.RunPrintConfig();
  178. }
  179. #region 杀死已存在的进程
  180. /// <summary>
  181. /// 结束已运行的程序
  182. /// </summary>
  183. private static void StopSameProcess()
  184. {
  185. Process current = Process.GetCurrentProcess();
  186. Process[] processList = Process.GetProcesses();
  187. foreach (Process process in processList)
  188. {
  189. if (process.ProcessName.ToUpper() == "XHSCHOOL")
  190. {
  191. if (process.Id != current.Id) //忽略当前进程
  192. {
  193. try
  194. {
  195. process.Kill(); //结束进程
  196. }
  197. catch (Exception)
  198. {
  199. }
  200. }
  201. }
  202. }
  203. }
  204. /// <summary>
  205. /// 杀死正在运行的ffmpeg
  206. /// </summary>
  207. public static void Killffmpeg()
  208. {
  209. Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
  210. foreach (var KillProcess in KillProcessArray)
  211. {
  212. KillProcess.Kill();
  213. }
  214. }
  215. #endregion
  216. /// <summary>
  217. /// 错误处理
  218. /// </summary>
  219. /// <param name="sender"></param>
  220. /// <param name="e"></param>
  221. private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  222. {
  223. LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
  224. MessageBox.Show("程序异常." + Environment.NewLine + e.Exception.Message);
  225. e.Handled = true;
  226. }
  227. #region 数据保存和读取
  228. /// <summary>
  229. /// 保存微课信息
  230. /// </summary>
  231. public static void SaveWkData()
  232. {
  233. try
  234. {
  235. if (UserInfo == null)
  236. {
  237. return;
  238. }
  239. if (!string.IsNullOrWhiteSpace(APP.UserInfo.Username))
  240. {
  241. WKData.VideoList = VideoList;
  242. if (WKDataList != null)
  243. {
  244. WKDataList.RemoveAll(x => x.WkName == WKData.WkName);
  245. }
  246. else
  247. {
  248. WKDataList = new List<Model_WKData>();
  249. }
  250. WKDataList.Add(WKData);
  251. //string WkDateXmlStr = XmlUtilHelper.Serializer(typeof(Model_WKData), WKData);
  252. string WkDateXmlStr = XmlUtilHelper.XmlSerialize(WKDataList);
  253. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/");
  254. FileToolsCommon.CreateDirectory(SavePath);
  255. string SaveName = SavePath + "UserWkDate.d";
  256. FileToolsCommon.DeleteFile(SaveName);
  257. FileToolsCommon.WriteText(SaveName, WkDateXmlStr);
  258. }
  259. }
  260. catch (Exception ex)
  261. {
  262. LogHelper.WriteErrLog("【微课数据保存】(SaveWkData)保存失败:" + ex.Message, ex);
  263. }
  264. }
  265. /// <summary>
  266. /// 读取微课信息
  267. /// </summary>
  268. public static void ReadWkData()
  269. {
  270. try
  271. {
  272. if (UserInfo == null)
  273. {
  274. return;
  275. }
  276. if (!string.IsNullOrWhiteSpace(APP.UserInfo.Username))
  277. {
  278. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/");
  279. FileToolsCommon.CreateDirectory(SavePath);
  280. string SaveName = SavePath + "UserWkDate.d";
  281. //文件若存在则读取
  282. if (FileToolsCommon.IsExistFile(SaveName))
  283. {
  284. string WkDateXmlStr = FileToolsCommon.FileToString(SaveName);
  285. WKDataList = XmlUtilHelper.DESerializer<List<Model_WKData>>(WkDateXmlStr);
  286. }
  287. }
  288. }
  289. catch (Exception ex)
  290. {
  291. LogHelper.WriteErrLog("【微课数据读取】(ReadWkData)读取失败:" + ex.Message, ex);
  292. }
  293. }
  294. /// <summary>
  295. /// 保存画板数据
  296. /// </summary>
  297. public static void SaveDraw()
  298. {
  299. try
  300. {
  301. if (PageDrawList == null)
  302. {
  303. return;
  304. }
  305. if (PageDrawList.Count < 1)
  306. {
  307. return;
  308. }
  309. FileToolsCommon.CreateDirectory(WKData.WkPath);
  310. string SavePath = WKData.WkPath + "PageData.d";
  311. FileToolsCommon.DeleteFile(SavePath);
  312. string PageDataXmlStr = XmlUtilHelper.XmlSerialize(PageDrawList);
  313. FileToolsCommon.WriteText(SavePath, PageDataXmlStr);
  314. }
  315. catch (Exception ex)
  316. {
  317. LogHelper.WriteErrLog("【画板数据保存】(SaveDraw)保存失败:" + ex.Message, ex);
  318. }
  319. }
  320. /// <summary>
  321. /// 读取文件
  322. /// </summary>
  323. public static void ReadDrawData()
  324. {
  325. try
  326. {
  327. PageDrawList = new List<Model_DrawData>();
  328. FileToolsCommon.CreateDirectory(WKData.WkPath);
  329. string SavePath = WKData.WkPath + "PageData.d";
  330. if (FileToolsCommon.IsExistFile(SavePath))
  331. {
  332. string PageDataXmlStr = FileToolsCommon.FileToString(SavePath);
  333. PageDrawList = XmlUtilHelper.DESerializer<List<Model_DrawData>>(PageDataXmlStr);
  334. }
  335. }
  336. catch (Exception ex)
  337. {
  338. LogHelper.WriteErrLog("【画板数据读取】(ReadDraw)读取失败:" + ex.Message, ex);
  339. }
  340. }
  341. #endregion
  342. #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  343. /// <summary>
  344. /// 内存释放压缩
  345. /// </summary>
  346. /// <param name="e"></param>
  347. protected override void OnStartup(StartupEventArgs e)
  348. {
  349. //private LierdaCracker cracker = new LierdaCracker();
  350. //cracker.Cracker(5000);//间隔时间
  351. //base.OnStartup(e);
  352. new Thread(o =>
  353. {
  354. while (true)
  355. {
  356. try
  357. {
  358. //FreeMemoryHelper.SetDate();
  359. FreeMemoryHelper.ReallocateMemory();
  360. Thread.Sleep(20000);//暂定每20秒释放一次
  361. }
  362. catch (Exception ex)
  363. {
  364. LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
  365. }
  366. }
  367. }).Start();
  368. }
  369. #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  370. }
  371. }