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

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