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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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 : Application
  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 = null;
  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 = null;
  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 = null;
  142. /// <summary>
  143. /// 微课模型
  144. /// </summary>
  145. public static Model_WKData WKData = null;
  146. /// <summary>
  147. /// 微课视频列表
  148. /// </summary>
  149. public static List<Model_Video> VideoList = null;
  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 CreateAMicroLessonWindow W_CreateAMicroLessonWindow = null;
  204. /// <summary>
  205. /// 开始录像
  206. /// </summary>
  207. public static CountdownWindow W_CountdownWindow = null;
  208. /// <summary>
  209. /// 录像工具栏
  210. /// </summary>
  211. public static ScreenRecordingToolbarWindow W_ScreenRecordingToolbarWindow = null;
  212. /// <summary>
  213. /// 登录
  214. /// </summary>
  215. public static LoginWindow W_LoginWindow = null;
  216. /// <summary>
  217. /// 截图
  218. /// </summary>
  219. public static JieTuWindow W_JieTuWindow = null;
  220. /// <summary>
  221. /// 批注
  222. /// </summary>
  223. public static PracticeWindow W_PracticeWindow = null;
  224. /// <summary>
  225. /// 提示窗口
  226. /// </summary>
  227. public static PromptWindow W_PromptWindow = null;
  228. /// <summary>
  229. /// loding页面
  230. /// </summary>
  231. public static LoadDialog myloading;
  232. /// <summary>
  233. /// 上传页面
  234. /// </summary>
  235. public static UploadWindow W_UploadWindow = null;
  236. /// <summary>
  237. /// 最小化工具栏
  238. /// </summary>
  239. public static MinToolbar W_MinToolbar = null;
  240. /// <summary>
  241. /// 视频剪辑
  242. /// </summary>
  243. public static VideoClipWindow W_VideoClipWindow = null;
  244. #endregion 页面
  245. #endregion 全局变量
  246. public APP()
  247. {
  248. Console.WriteLine("初始化APP");
  249. LogHelper.InitLog4Net();
  250. myloading = new LoadDialog();
  251. StopSameProcess();
  252. Killffmpeg();
  253. try
  254. {
  255. UserInfo = new Model_UserInfo();
  256. WKDataList = new List<Model_WKData>();
  257. VideoList = new List<Model_Video>();
  258. #region 强制以管理员方式运行 修改人:赵耀 修改时间:2020年9月7日
  259. WindowsIdentity identity = WindowsIdentity.GetCurrent();
  260. WindowsPrincipal principal = new WindowsPrincipal(identity);
  261. #endregion 强制以管理员方式运行 修改人:赵耀 修改时间:2020年9月7日
  262. try
  263. {
  264. if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "Temp"))//清除临时文件
  265. {
  266. Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "Temp", true);
  267. }
  268. }
  269. catch (Exception)
  270. {
  271. }
  272. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  273. {
  274. SkinConfig.InitSkin();
  275. }
  276. else
  277. {
  278. //创建启动对象
  279. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  280. {
  281. UseShellExecute = true,
  282. WorkingDirectory = Environment.CurrentDirectory,
  283. FileName = Assembly.GetExecutingAssembly().Location,
  284. //设置启动动作,确保以管理员身份运行
  285. Verb = "runas"
  286. };
  287. try
  288. {
  289. System.Diagnostics.Process.Start(startInfo);
  290. }
  291. catch
  292. {
  293. return;
  294. }
  295. //退出
  296. //Current.Shutdown();
  297. Environment.Exit(0);
  298. }
  299. }
  300. catch (Exception ex)
  301. {
  302. string ErrMessage = "【进程】(Main):进程意外关闭。 " + ex.Message;
  303. LogHelper.WriteErrLog(ErrMessage, ex);
  304. }
  305. }
  306. #region 杀死已存在的进程
  307. /// <summary>
  308. /// 结束已运行的程序
  309. /// </summary>
  310. private static void StopSameProcess()
  311. {
  312. Process current = Process.GetCurrentProcess();
  313. Process[] processList = Process.GetProcesses();
  314. foreach (Process process in processList)
  315. {
  316. if (process.ProcessName.ToUpper() == "星火微课")
  317. {
  318. if (process.Id != current.Id) //忽略当前进程
  319. {
  320. try
  321. {
  322. process.Kill(); //结束进程
  323. }
  324. catch (Exception)
  325. {
  326. }
  327. }
  328. }
  329. }
  330. }
  331. /// <summary>
  332. /// 杀死正在运行的ffmpeg
  333. /// </summary>
  334. public static void Killffmpeg()
  335. {
  336. Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
  337. foreach (Process KillProcess in KillProcessArray)
  338. {
  339. KillProcess.Kill();
  340. }
  341. }
  342. #endregion 杀死已存在的进程
  343. private void RegisterEvents()
  344. {
  345. //Task线程内未捕获异常处理事件
  346. TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;//Task异常
  347. //UI线程未捕获异常处理事件(UI主线程)
  348. DispatcherUnhandledException += App_DispatcherUnhandledException;
  349. //非UI线程未捕获异常处理事件(例如自己创建的一个子线程)
  350. AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
  351. }
  352. private static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
  353. {
  354. try
  355. {
  356. var exception = e.Exception as Exception;
  357. if (exception != null)
  358. {
  359. HandleException(exception);
  360. }
  361. }
  362. catch (Exception ex)
  363. {
  364. HandleException(ex);
  365. }
  366. finally
  367. {
  368. e.SetObserved();
  369. }
  370. }
  371. //非UI线程未捕获异常处理事件(例如自己创建的一个子线程)
  372. private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  373. {
  374. try
  375. {
  376. var exception = e.ExceptionObject as Exception;
  377. if (exception != null)
  378. {
  379. HandleException(exception);
  380. }
  381. }
  382. catch (Exception ex)
  383. {
  384. HandleException(ex);
  385. }
  386. finally
  387. {
  388. //ignore
  389. }
  390. }
  391. //UI线程未捕获异常处理事件(UI主线程)
  392. private static void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
  393. {
  394. try
  395. {
  396. HandleException(e.Exception);
  397. }
  398. catch (Exception ex)
  399. {
  400. HandleException(ex);
  401. }
  402. finally
  403. {
  404. e.Handled = true;
  405. }
  406. }
  407. private static void HandleException(Exception ex)
  408. {
  409. //记录日志
  410. LogHelper.WriteErrLog("未捕获异常:" + ex.Message, ex);
  411. Current.Shutdown();
  412. }
  413. #region 数据保存和读取
  414. /// <summary>
  415. /// 保存微课信息
  416. /// </summary>
  417. public static void SaveWkData()
  418. {
  419. try
  420. {
  421. VideoList = VideoList.Where((x, i) => VideoList.FindIndex(z => z.FileGuid == x.FileGuid) == i).ToList();
  422. WKData.VideoList = VideoList;
  423. if (WKDataList != null)
  424. {
  425. WKDataList.RemoveAll(x => x.WkPath == WKData.WkPath);
  426. }
  427. else
  428. {
  429. WKDataList = new List<Model_WKData>();
  430. }
  431. WKDataList.Add(WKData);
  432. string WkDateXmlStr = XmlUtilHelper.XmlSerialize(WKDataList);
  433. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/");
  434. FileToolsCommon.CreateDirectory(SavePath);
  435. string SaveName = SavePath + "WkDate.d";
  436. FileToolsCommon.DeleteFile(SaveName);
  437. FileToolsCommon.WriteText(SaveName, WkDateXmlStr);
  438. }
  439. catch (Exception ex)
  440. {
  441. LogHelper.WriteErrLog("【微课数据保存】(SaveWkData)保存失败:" + ex.Message, ex);
  442. }
  443. }
  444. /// <summary>
  445. /// 读取微课信息
  446. /// </summary>
  447. public static void ReadWkData(string WkPath)
  448. {
  449. try
  450. {
  451. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/");
  452. FileToolsCommon.CreateDirectory(SavePath);
  453. string SaveName = SavePath + "WkDate.d";
  454. //文件若存在则读取
  455. if (FileToolsCommon.IsExistFile(SaveName))
  456. {
  457. string WkDateXmlStr = FileToolsCommon.FileToString(SaveName);
  458. WKDataList = XmlUtilHelper.DESerializer<List<Model_WKData>>(WkDateXmlStr);
  459. foreach (Model_WKData wklist in WKDataList)
  460. {
  461. //移除找不到视频的微课数据
  462. wklist.VideoList.RemoveAll(x => !FileToolsCommon.IsExistFile(x.VideoPath));
  463. }
  464. if (WKDataList.Exists(x => x.WkPath == WkPath))
  465. {
  466. WKData = WKDataList.Find(x => x.WkPath == WkPath);
  467. VideoList = new List<Model_Video>();
  468. WKData.VideoList = WKData.VideoList.Where((x, i) => WKData.VideoList.FindIndex(z => z.FileGuid == x.FileGuid) == i).ToList();
  469. VideoList = WKData.VideoList;
  470. }
  471. }
  472. }
  473. catch (Exception ex)
  474. {
  475. LogHelper.WriteErrLog("【微课数据读取】(ReadWkData)读取失败:" + ex.Message, ex);
  476. }
  477. }
  478. /// <summary>
  479. /// 保存画板数据
  480. /// </summary>
  481. public static void SaveDraw()
  482. {
  483. try
  484. {
  485. if (PageDrawList == null)
  486. {
  487. return;
  488. }
  489. if (PageDrawList.Count < 1)
  490. {
  491. return;
  492. }
  493. FileToolsCommon.CreateDirectory(WKData.WkPath);
  494. string SavePath = WKData.WkPath + "PageData.xml";
  495. FileToolsCommon.DeleteFile(SavePath);
  496. string PageDataXmlStr = XmlUtilHelper.XmlSerialize(PageDrawList);
  497. FileToolsCommon.WriteText(SavePath, PageDataXmlStr);
  498. }
  499. catch (Exception ex)
  500. {
  501. LogHelper.WriteErrLog("【画板数据保存】(SaveDraw)保存失败:" + ex.Message, ex);
  502. }
  503. }
  504. /// <summary>
  505. /// 读取文件
  506. /// </summary>
  507. public static void ReadDrawData()
  508. {
  509. try
  510. {
  511. PageDrawList = new List<Model_DrawData>();
  512. string SavePath = WKData.WkPath + "PageData.xml";
  513. if (FileToolsCommon.IsExistFile(SavePath))
  514. {
  515. string PageDataXmlStr = FileToolsCommon.FileToString(SavePath);
  516. PageDrawList = XmlUtilHelper.DESerializer<List<Model_DrawData>>(PageDataXmlStr);
  517. }
  518. else
  519. {
  520. PageDrawList = new List<Model_DrawData>();
  521. }
  522. }
  523. catch (Exception ex)
  524. {
  525. LogHelper.WriteErrLog("【画板数据读取】(ReadDraw)读取失败:" + ex.Message, ex);
  526. }
  527. }
  528. #endregion 数据保存和读取
  529. #region 服务地址数据
  530. /// <summary>
  531. /// 服务地址存储到本地
  532. /// </summary>
  533. public static void SaveServiceAddressData()
  534. {
  535. try
  536. {
  537. if (ServiceAddress == null)
  538. {
  539. return;
  540. }
  541. string DateXmlStr = XmlUtilHelper.XmlSerialize(ServiceAddress);
  542. string SavePath = DataPath;
  543. FileToolsCommon.CreateDirectory(SavePath);
  544. string SaveName = SavePath + (isDebug ? "ServiceAddress_debug.xml" : "ServiceAddress_release.xml");
  545. Console.WriteLine("保存路径为:");
  546. FileToolsCommon.DeleteFile(SaveName);
  547. FileToolsCommon.WriteText(SaveName, DateXmlStr);
  548. }
  549. catch (Exception ex)
  550. {
  551. LogHelper.WriteErrLog("【服务地址存储】(SaveServiceAddressData)保存失败:" + ex.Message, ex);
  552. }
  553. }
  554. /// <summary>
  555. /// 从本地读取服务地址
  556. /// </summary>
  557. public static void ReadServiceAddressData()
  558. {
  559. try
  560. {
  561. string SavePath = DataPath;
  562. FileToolsCommon.CreateDirectory(SavePath);
  563. string SaveName = SavePath + (isDebug ? "ServiceAddress_debug.xml" : "ServiceAddress_release.xml");
  564. //文件若存在则读取
  565. if (FileToolsCommon.IsExistFile(SaveName))
  566. {
  567. string DateXmlStr = FileToolsCommon.FileToString(SaveName);
  568. ServiceAddress = XmlUtilHelper.DESerializer<Model_ServiceAddress>(DateXmlStr);
  569. SwitchAddress();
  570. }
  571. }
  572. catch (Exception ex)
  573. {
  574. LogHelper.WriteErrLog("【服务地址读取】(ReadServiceAddressData)读取失败:" + ex.Message, ex);
  575. }
  576. }
  577. /// <summary>
  578. /// 切换校内外网
  579. /// </summary>
  580. public static void SwitchAddress()
  581. {
  582. try
  583. {
  584. apiUrl = IsOutsideSchool ? ServiceAddress.wapi : ServiceAddress.napi;
  585. uploadUrl = (IsOutsideSchool ? ServiceAddress.wfile : ServiceAddress.nfile) + "/";
  586. showImageUrl = (IsOutsideSchool ? ServiceAddress.wdown : ServiceAddress.ndown) + "/static/";
  587. }
  588. catch (Exception ex)
  589. {
  590. LogHelper.WriteErrLog("【服务地址切换】(SwitchAddress)服务复制切换失败,请求地址为空!", ex);
  591. }
  592. }
  593. #endregion 服务地址数据
  594. /// <summary>
  595. /// 内存释放压缩
  596. /// </summary>
  597. /// <param name="e">
  598. /// </param>
  599. protected override void OnStartup(StartupEventArgs e)
  600. {
  601. RegisterEvents();
  602. base.OnStartup(e);
  603. }
  604. }
  605. }