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

App.xaml.cs 21KB

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