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

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