星火微课系统客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

App.cs 14KB

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