星火微课系统客户端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

App.xaml.cs 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. using ComeCapture;
  2. using Common.system;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Security.Principal;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using XHWK.Model;
  13. using XHWK.WKTool.Helpers;
  14. using XHWK.WKTool.Skin;
  15. namespace XHWK.WKTool
  16. {
  17. public partial class App
  18. {
  19. #region 全局变量
  20. #region 更新需改动
  21. /// <summary>
  22. /// 是否为测试版
  23. /// </summary>
  24. public static bool isDebug = FileToolsCommon.GetConfigValue("IsDebug") != "0";
  25. /// <summary>
  26. /// 参数是否加密
  27. /// </summary>
  28. public static bool IsParameterEncryption = FileToolsCommon.GetConfigValue("IsParameterEncryption") != "0";
  29. #endregion 更新需改动
  30. #region 接口地址
  31. /// <summary>
  32. /// 是否为校外接口
  33. /// </summary>
  34. public static bool IsOutsideSchool = FileToolsCommon.GetConfigValue("IsOutsideSchool") == "1";
  35. /// <summary>
  36. /// 服务地址
  37. /// </summary>
  38. public static Model_ServiceAddress ServiceAddress;
  39. /// <summary>
  40. /// 接口地址
  41. /// </summary>
  42. public static string apiUrl = isDebug ? "http://schoolapitest.xhkjedu.com" : FileToolsCommon.GetConfigValue("APIRequestAddress");
  43. /// <summary>
  44. /// 图片地址
  45. /// </summary>
  46. public static string uploadUrl = isDebug ? "http://schoolfiletest.xhkjedu.com/" : FileToolsCommon.GetConfigValue("FileRequestAddress");
  47. /// <summary>
  48. /// 展示文件
  49. /// </summary>
  50. public static string showImageUrl = isDebug ? "http://schoolstatictest.xhkjedu.com/static/" : FileToolsCommon.GetConfigValue("SchoolfileRequestAddress") + "/static/";
  51. /// <summary>
  52. /// 认证接口地址
  53. /// </summary>
  54. public static string certapiUrl = isDebug ? "http://scapitest.xhkjedu.com" : FileToolsCommon.GetConfigValue("CertapiRequestAddress");
  55. #endregion 接口地址
  56. #region 配置项
  57. /// <summary>
  58. /// 是否输出测试记录日志
  59. /// </summary>
  60. public static bool IsOutputInfoLog = FileToolsCommon.GetConfigValue("IsOutputInfoLog") != "0";
  61. /// <summary>
  62. /// 是否隐藏录屏工具栏
  63. /// </summary>
  64. public static bool IsHideSRTool = FileToolsCommon.GetConfigValue("IsHideSRTool") != "0";
  65. /// <summary>
  66. /// 皮肤样式 0白 1蓝 2黑色
  67. /// </summary>
  68. public static string SkinStyle = FileToolsCommon.GetConfigValue("SkinStyle");
  69. /// <summary>
  70. /// 数据存放目录
  71. /// </summary>
  72. public static string DataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\XHMicroLesson\\";
  73. /// <summary>
  74. /// 摄像头位置
  75. /// </summary>
  76. public static string CameraPosition = string.Empty;
  77. /// <summary>
  78. /// 摄像头名
  79. /// </summary>
  80. public static string CameraName = "";
  81. /// <summary>
  82. /// 麦克风名
  83. /// </summary>
  84. public static string MicrophoneName = "";
  85. #endregion 配置项
  86. #region 记录数据
  87. /// <summary>
  88. /// 全局页面数据变量
  89. /// </summary>
  90. public static readonly Model_Page PageContextData = new Model.Model_Page();
  91. /// <summary>
  92. /// 录屏工具
  93. /// </summary>
  94. public static FFMpeg FFmpeg = new FFMpeg();
  95. /// <summary>
  96. /// 后台线程帮助类
  97. /// </summary>
  98. public static BackgroundWorkerHelper BackgroundWorkerHelper => BackgroundWorkerHelper.GetInstance();
  99. /// <summary>
  100. /// 签名
  101. /// </summary>
  102. public static string Signature = "";
  103. public static string secretKey = "nanhuakaizhangjianwangni";
  104. /// <summary>
  105. /// 用户信息
  106. /// </summary>
  107. public static Model_UserInfo UserInfo;
  108. /// <summary>
  109. /// 接口返回消息
  110. /// </summary>
  111. public static string ServerMsg = string.Empty;
  112. /// <summary>
  113. /// 登录状态 false 未登录 true已登录
  114. /// </summary>
  115. public static bool IsLoginType = false;
  116. /// <summary>
  117. /// 截图地址
  118. /// </summary>
  119. public static string ImgPath = string.Empty;
  120. /// <summary>
  121. /// 教材列表
  122. /// </summary>
  123. public static List<Model_TsubjectbookList> TsubjectbookList = null;
  124. /// <summary>
  125. /// 章节列表
  126. /// </summary>
  127. public static List<Model_DirectorList> DirectorList = null;
  128. /// <summary>
  129. /// 上传个人空间 入参
  130. /// </summary>
  131. public static Model_ResourceAddTwo ResourceAddTwo = null;
  132. /// <summary>
  133. /// 是否正在上传
  134. /// </summary>
  135. public static bool IsUpLoad = false;
  136. #endregion 记录数据
  137. #region 微课数据记录
  138. /// <summary>
  139. /// 用户微课列表模型
  140. /// </summary>
  141. public static List<Model_WKData> WKDataList;
  142. /// <summary>
  143. /// 微课模型
  144. /// </summary>
  145. public static Model_WKData WKData;
  146. /// <summary>
  147. /// 微课视频列表
  148. /// </summary>
  149. public static List<Model_Video> VideoList;
  150. /// <summary>
  151. /// 画板模型
  152. /// </summary>
  153. public static List<Model_DrawData> PageDrawList = new List<Model_DrawData>();
  154. #endregion 微课数据记录
  155. #region 点阵笔
  156. /// <summary>
  157. /// 笔序号
  158. /// </summary>
  159. public static string PenSerial;
  160. /// <summary>
  161. /// 笔状态,是否已连接
  162. /// </summary>
  163. public static bool PenStatus = false;
  164. /// <summary>
  165. /// 手写板状态,是否已连接
  166. /// </summary>
  167. public static bool BoardStatus = false;
  168. #endregion 点阵笔
  169. #region 腾千里手写笔
  170. ///// <summary>
  171. ///// 铺码服务请求
  172. ///// </summary>
  173. //public static DAL_TmatrixCode dAL_TmatrixCode;
  174. /// <summary>
  175. /// 腾千里手写笔事件
  176. /// </summary>
  177. public static PenEvents TQLPenevents;
  178. /// <summary>
  179. /// 腾千里手写笔是否已连接
  180. /// </summary>
  181. public static bool TQLPenStatus = false;
  182. #region 打印
  183. public static bool gbGenerateBGWithVImage = false;
  184. public static bool gbGenerateVImage = false;
  185. public static bool gbGenerateBGWithoutVImage = false;
  186. public static bool gbGenerateBGWithImage = false;
  187. public static bool gbGenPageSet = false;
  188. public static int[] gPointType = new int[5];
  189. public static int[] gPointDPI = new int[5];
  190. public static string gTMXElementFileName;
  191. public static string gNewProjectDirectory;
  192. public static bool gbElementFileExist { get; set; }
  193. #endregion 打印
  194. #endregion 腾千里手写笔
  195. #region 页面
  196. /// <summary>
  197. /// 主页面
  198. /// </summary>
  199. public static MainWindow W_XHMicroLessonSystemWindow = null;
  200. /// <summary>
  201. /// 倒计时窗口
  202. /// </summary>
  203. public static CountdownWindow W_CountdownWindow = null;
  204. /// <summary>
  205. /// 录像工具栏
  206. /// </summary>
  207. public static ScreenRecordingToolbarWindow W_ScreenRecordingToolbarWindow = null;
  208. /// <summary>
  209. /// 登录
  210. /// </summary>
  211. public static LoginWindow W_LoginWindow = null;
  212. /// <summary>
  213. /// 截图
  214. /// </summary>
  215. public static JieTuWindow W_JieTuWindow = null;
  216. /// <summary>
  217. /// 批注
  218. /// </summary>
  219. public static PracticeWindow W_PracticeWindow = null;
  220. /// <summary>
  221. /// 提示窗口
  222. /// </summary>
  223. public static PromptWindow W_PromptWindow = null;
  224. /// <summary>
  225. /// loding页面
  226. /// </summary>
  227. public static LoadDialog myloading;
  228. /// <summary>
  229. /// 上传页面
  230. /// </summary>
  231. public static UploadWindow W_UploadWindow = null;
  232. /// <summary>
  233. /// 最小化工具栏
  234. /// </summary>
  235. public static MinToolbar W_MinToolbar = null;
  236. /// <summary>
  237. /// 视频剪辑
  238. /// </summary>
  239. public static VideoClipWindow W_VideoClipWindow = null;
  240. #endregion 页面
  241. #endregion 全局变量
  242. public App()
  243. {
  244. Console.WriteLine(@"初始化APP");
  245. LogHelper.InitLog4Net();
  246. myloading = new LoadDialog();
  247. StopSameProcess();
  248. Killffmpeg();
  249. try
  250. {
  251. UserInfo = new Model_UserInfo();
  252. WKDataList = new List<Model_WKData>();
  253. VideoList = new List<Model_Video>();
  254. #region 强制以管理员方式运行 修改人:赵耀 修改时间:2020年9月7日
  255. WindowsIdentity identity = WindowsIdentity.GetCurrent();
  256. WindowsPrincipal principal = new WindowsPrincipal(identity);
  257. #endregion 强制以管理员方式运行 修改人:赵耀 修改时间:2020年9月7日
  258. try
  259. {
  260. if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "Temp")) //清除临时文件
  261. {
  262. Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "Temp", true);
  263. }
  264. }
  265. catch (Exception)
  266. {
  267. // ignored
  268. }
  269. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  270. {
  271. SkinConfig.InitSkin();
  272. }
  273. else
  274. {
  275. //创建启动对象
  276. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  277. {
  278. UseShellExecute = true,
  279. WorkingDirectory = Environment.CurrentDirectory,
  280. FileName = Assembly.GetExecutingAssembly().Location,
  281. //设置启动动作,确保以管理员身份运行
  282. Verb = "runas"
  283. };
  284. try
  285. {
  286. System.Diagnostics.Process.Start(startInfo);
  287. }
  288. catch
  289. {
  290. return;
  291. }
  292. //退出
  293. //Current.Shutdown();
  294. Environment.Exit(0);
  295. }
  296. }
  297. catch (Exception ex)
  298. {
  299. string errMessage = "【进程】(Main):进程意外关闭。 " + ex.Message;
  300. LogHelper.WriteErrLog(errMessage, ex);
  301. }
  302. }
  303. #region 杀死已存在的进程
  304. /// <summary>
  305. /// 结束已运行的程序
  306. /// </summary>
  307. private static void StopSameProcess()
  308. {
  309. Process current = Process.GetCurrentProcess();
  310. Process[] processList = Process.GetProcesses();
  311. foreach (Process process in processList)
  312. {
  313. if (process.ProcessName.ToUpper() == "星火微课")
  314. {
  315. if (process.Id != current.Id) //忽略当前进程
  316. {
  317. try
  318. {
  319. process.Kill(); //结束进程
  320. }
  321. catch (Exception)
  322. {
  323. // ignored
  324. }
  325. }
  326. }
  327. }
  328. }
  329. /// <summary>
  330. /// 杀死正在运行的ffmpeg
  331. /// </summary>
  332. public static void Killffmpeg()
  333. {
  334. Process[] killProcessArray = Process.GetProcessesByName("ffmpeg");
  335. foreach (Process killProcess in killProcessArray)
  336. {
  337. killProcess.Kill();
  338. }
  339. }
  340. #endregion 杀死已存在的进程
  341. private void RegisterEvents()
  342. {
  343. //Task线程内未捕获异常处理事件
  344. TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; //Task异常
  345. //UI线程未捕获异常处理事件(UI主线程)
  346. DispatcherUnhandledException += App_DispatcherUnhandledException;
  347. //非UI线程未捕获异常处理事件(例如自己创建的一个子线程)
  348. AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
  349. }
  350. private static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
  351. {
  352. try
  353. {
  354. var exception = e.Exception as Exception;
  355. if (exception != null)
  356. {
  357. HandleException(exception);
  358. }
  359. }
  360. catch (Exception ex)
  361. {
  362. HandleException(ex);
  363. }
  364. finally
  365. {
  366. e.SetObserved();
  367. }
  368. }
  369. //非UI线程未捕获异常处理事件(例如自己创建的一个子线程)
  370. private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  371. {
  372. try
  373. {
  374. var exception = e.ExceptionObject as Exception;
  375. if (exception != null)
  376. {
  377. HandleException(exception);
  378. }
  379. }
  380. catch (Exception ex)
  381. {
  382. HandleException(ex);
  383. }
  384. }
  385. //UI线程未捕获异常处理事件(UI主线程)
  386. private static void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
  387. {
  388. try
  389. {
  390. HandleException(e.Exception);
  391. }
  392. catch (Exception ex)
  393. {
  394. HandleException(ex);
  395. }
  396. finally
  397. {
  398. e.Handled = true;
  399. }
  400. }
  401. private static void HandleException(Exception ex)
  402. {
  403. //记录日志
  404. LogHelper.WriteErrLog("未捕获异常:" + ex.Message, ex);
  405. Current.Shutdown();
  406. }
  407. #region 数据保存和读取
  408. /// <summary>
  409. /// 保存微课信息
  410. /// </summary>
  411. public static void SaveWkData()
  412. {
  413. try
  414. {
  415. VideoList = VideoList.Where((x, i) => VideoList.FindIndex(z => z.FileGuid == x.FileGuid) == i).ToList();
  416. WKData.VideoList = VideoList;
  417. if (WKDataList != null)
  418. {
  419. WKDataList.RemoveAll(x => x.WkPath == WKData.WkPath);
  420. }
  421. else
  422. {
  423. WKDataList = new List<Model_WKData>();
  424. }
  425. WKDataList.Add(WKData);
  426. string wkDateXmlStr = XmlUtilHelper.XmlSerialize(WKDataList);
  427. string savePath = FileToolsCommon.GetFileAbsolutePath("/Data/");
  428. FileToolsCommon.CreateDirectory(savePath);
  429. string saveName = savePath + "WkDate.d";
  430. FileToolsCommon.DeleteFile(saveName);
  431. FileToolsCommon.WriteText(saveName, wkDateXmlStr);
  432. }
  433. catch (Exception ex)
  434. {
  435. LogHelper.WriteErrLog("【微课数据保存】(SaveWkData)保存失败:" + ex.Message, ex);
  436. }
  437. }
  438. /// <summary>
  439. /// 读取微课信息
  440. /// </summary>
  441. public static void ReadWkData(string wkPath)
  442. {
  443. try
  444. {
  445. string savePath = FileToolsCommon.GetFileAbsolutePath("/Data/");
  446. FileToolsCommon.CreateDirectory(savePath);
  447. string saveName = savePath + "WkDate.d";
  448. //文件若存在则读取
  449. if (FileToolsCommon.IsExistFile(saveName))
  450. {
  451. string wkDateXmlStr = FileToolsCommon.FileToString(saveName);
  452. WKDataList = XmlUtilHelper.DESerializer<List<Model_WKData>>(wkDateXmlStr);
  453. foreach (Model_WKData wklist in WKDataList)
  454. {
  455. //移除找不到视频的微课数据
  456. wklist.VideoList.RemoveAll(x => !FileToolsCommon.IsExistFile(x.VideoPath));
  457. }
  458. if (WKDataList.Exists(x => x.WkPath == wkPath))
  459. {
  460. WKData = WKDataList.Find(x => x.WkPath == wkPath);
  461. VideoList = new List<Model_Video>();
  462. WKData.VideoList = WKData.VideoList.Where((x, i) => WKData.VideoList.FindIndex(z => z.FileGuid == x.FileGuid) == i).ToList();
  463. VideoList = WKData.VideoList;
  464. }
  465. }
  466. }
  467. catch (Exception ex)
  468. {
  469. LogHelper.WriteErrLog("【微课数据读取】(ReadWkData)读取失败:" + ex.Message, ex);
  470. }
  471. }
  472. /// <summary>
  473. /// 保存画板数据
  474. /// </summary>
  475. public static void SaveDraw()
  476. {
  477. try
  478. {
  479. if (PageDrawList == null)
  480. {
  481. return;
  482. }
  483. if (PageDrawList.Count < 1)
  484. {
  485. return;
  486. }
  487. FileToolsCommon.CreateDirectory(WKData.WkPath);
  488. string savePath = WKData.WkPath + "PageData.xml";
  489. FileToolsCommon.DeleteFile(savePath);
  490. string pageDataXmlStr = XmlUtilHelper.XmlSerialize(PageDrawList);
  491. FileToolsCommon.WriteText(savePath, pageDataXmlStr);
  492. }
  493. catch (Exception ex)
  494. {
  495. LogHelper.WriteErrLog("【画板数据保存】(SaveDraw)保存失败:" + ex.Message, ex);
  496. }
  497. }
  498. /// <summary>
  499. /// 读取文件
  500. /// </summary>
  501. public static void ReadDrawData()
  502. {
  503. try
  504. {
  505. PageDrawList = new List<Model_DrawData>();
  506. string savePath = WKData.WkPath + "PageData.xml";
  507. if (FileToolsCommon.IsExistFile(savePath))
  508. {
  509. string pageDataXmlStr = FileToolsCommon.FileToString(savePath);
  510. PageDrawList = XmlUtilHelper.DESerializer<List<Model_DrawData>>(pageDataXmlStr);
  511. }
  512. else
  513. {
  514. PageDrawList = new List<Model_DrawData>();
  515. }
  516. }
  517. catch (Exception ex)
  518. {
  519. LogHelper.WriteErrLog("【画板数据读取】(ReadDraw)读取失败:" + ex.Message, ex);
  520. }
  521. }
  522. #endregion 数据保存和读取
  523. #region 服务地址数据
  524. /// <summary>
  525. /// 服务地址存储到本地
  526. /// </summary>
  527. public static void SaveServiceAddressData()
  528. {
  529. try
  530. {
  531. if (ServiceAddress == null)
  532. {
  533. return;
  534. }
  535. string dateXmlStr = XmlUtilHelper.XmlSerialize(ServiceAddress);
  536. string savePath = DataPath;
  537. FileToolsCommon.CreateDirectory(savePath);
  538. string saveName = savePath + (isDebug ? "ServiceAddress_debug.xml" : "ServiceAddress_release.xml");
  539. Console.WriteLine(@"保存路径为:");
  540. FileToolsCommon.DeleteFile(saveName);
  541. FileToolsCommon.WriteText(saveName, dateXmlStr);
  542. }
  543. catch (Exception ex)
  544. {
  545. LogHelper.WriteErrLog("【服务地址存储】(SaveServiceAddressData)保存失败:" + ex.Message, ex);
  546. }
  547. }
  548. /// <summary>
  549. /// 从本地读取服务地址
  550. /// </summary>
  551. public static void ReadServiceAddressData()
  552. {
  553. try
  554. {
  555. string savePath = DataPath;
  556. FileToolsCommon.CreateDirectory(savePath);
  557. string saveName = savePath + (isDebug ? "ServiceAddress_debug.xml" : "ServiceAddress_release.xml");
  558. //文件若存在则读取
  559. if (FileToolsCommon.IsExistFile(saveName))
  560. {
  561. string dateXmlStr = FileToolsCommon.FileToString(saveName);
  562. ServiceAddress = XmlUtilHelper.DESerializer<Model_ServiceAddress>(dateXmlStr);
  563. SwitchAddress();
  564. }
  565. }
  566. catch (Exception ex)
  567. {
  568. LogHelper.WriteErrLog("【服务地址读取】(ReadServiceAddressData)读取失败:" + ex.Message, ex);
  569. }
  570. }
  571. /// <summary>
  572. /// 切换校内外网
  573. /// </summary>
  574. public static void SwitchAddress()
  575. {
  576. try
  577. {
  578. apiUrl = IsOutsideSchool ? ServiceAddress.wapi : ServiceAddress.napi;
  579. uploadUrl = (IsOutsideSchool ? ServiceAddress.wfile : ServiceAddress.nfile) + "/";
  580. showImageUrl = (IsOutsideSchool ? ServiceAddress.wdown : ServiceAddress.ndown) + "/static/";
  581. }
  582. catch (Exception ex)
  583. {
  584. LogHelper.WriteErrLog("【服务地址切换】(SwitchAddress)服务复制切换失败,请求地址为空!", ex);
  585. }
  586. }
  587. #endregion 服务地址数据
  588. /// <summary>
  589. /// 内存释放压缩
  590. /// </summary>
  591. /// <param name="e">
  592. /// </param>
  593. protected override void OnStartup(StartupEventArgs e)
  594. {
  595. RegisterEvents();
  596. base.OnStartup(e);
  597. }
  598. }
  599. }