星火微课系统客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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. /// 服务地址API
  43. /// </summary>
  44. public static string ServiceAddressAPI = isDebug ? "http://scapitest.xhkjedu.com" : FileToolsCommon.GetConfigValue("ServiceAddressAPI");
  45. /// <summary>
  46. /// 接口地址
  47. /// </summary>
  48. public static string apiUrl = isDebug ? "http://schoolapitest.xhkjedu.com" : FileToolsCommon.GetConfigValue("APIRequestAddress");
  49. /// <summary>
  50. /// 图片地址
  51. /// </summary>
  52. public static string uploadUrl = isDebug ? "http://schoolfiletest.xhkjedu.com/" : FileToolsCommon.GetConfigValue("FileRequestAddress");
  53. /// <summary>
  54. /// 展示文件
  55. /// </summary>
  56. public static string showImageUrl = isDebug ? "http://schoolfiletest.xhkjedu.com/static/" : FileToolsCommon.GetConfigValue("SchoolfileRequestAddress") + "/static/";
  57. /// <summary>
  58. /// 认证接口地址
  59. /// </summary>
  60. public static string certapiUrl = isDebug ? "http://certapitest.xhkjedu.com" : FileToolsCommon.GetConfigValue("CertapiRequestAddress");
  61. /// <summary>
  62. /// TQL铺码服务地址
  63. /// </summary>
  64. public static string TmatrixCodeURL = FileToolsCommon.GetConfigValue("TmatrixCode");
  65. #endregion
  66. #region 配置项
  67. /// <summary>
  68. /// 是否输出测试记录日志
  69. /// </summary>
  70. public static bool IsOutputInfoLog = FileToolsCommon.GetConfigValue("IsOutputInfoLog") != "0";
  71. /// <summary>
  72. /// 是否隐藏录屏工具栏
  73. /// </summary>
  74. public static bool IsHideSRTool = FileToolsCommon.GetConfigValue("IsHideSRTool") != "0";
  75. /// <summary>
  76. /// 皮肤样式 0白 1蓝 2黑色
  77. /// </summary>
  78. public static string SkinStyle = FileToolsCommon.GetConfigValue("SkinStyle");
  79. /// <summary>
  80. /// 数据存放目录
  81. /// </summary>
  82. public static string DataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\XHMicroLesson\\";
  83. /// <summary>
  84. /// 摄像头位置
  85. /// </summary>
  86. public static string CameraPosition = string.Empty;
  87. /// <summary>
  88. /// 摄像头名
  89. /// </summary>
  90. public static string CameraName = "";
  91. /// <summary>
  92. /// 麦克风名
  93. /// </summary>
  94. public static string MicrophoneName = "";
  95. #endregion
  96. #region 记录数据
  97. /// <summary>
  98. /// 全局页面数据变量
  99. /// </summary>
  100. public static readonly Model_Page PageContextData = new Model.Model_Page();
  101. /// <summary>
  102. /// 录屏工具
  103. /// </summary>
  104. public static FFMpeg FFmpeg = new FFMpeg();
  105. /// <summary>
  106. /// 后台线程帮助类
  107. /// </summary>
  108. public static BackgroundWorkerHelper BackgroundWorkerHelper => BackgroundWorkerHelper.GetInstance();
  109. /// <summary>
  110. /// 签名
  111. /// </summary>
  112. public static string Signature = "";
  113. public static string secretKey = "nanhuakaizhangjianwangni";
  114. /// <summary>
  115. /// 用户信息
  116. /// </summary>
  117. public static Model_UserInfo UserInfo = null;
  118. /// <summary>
  119. /// 接口返回消息
  120. /// </summary>
  121. public static string ServerMsg = string.Empty;
  122. /// <summary>
  123. /// 登录状态 false 未登录 true已登录
  124. /// </summary>
  125. public static bool IsLoginType = false;
  126. /// <summary>
  127. /// 截图地址
  128. /// </summary>
  129. public static string ImgPath = string.Empty;
  130. /// <summary>
  131. /// 教材列表
  132. /// </summary>
  133. public static List<Model_TsubjectbookList> TsubjectbookList = null;
  134. /// <summary>
  135. /// 章节列表
  136. /// </summary>
  137. public static List<Model_DirectorList> DirectorList = null;
  138. /// <summary>
  139. /// 上传个人空间 入参
  140. /// </summary>
  141. public static Model_ResourceAddTwo ResourceAddTwo = null;
  142. /// <summary>
  143. /// 是否正在上传
  144. /// </summary>
  145. public static bool IsUpLoad = false;
  146. #endregion
  147. #region 微课数据记录
  148. /// <summary>
  149. /// 用户微课列表模型
  150. /// </summary>
  151. public static List<Model_WKData> WKDataList = null;
  152. /// <summary>
  153. /// 微课模型
  154. /// </summary>
  155. public static Model_WKData WKData = null;
  156. /// <summary>
  157. /// 微课视频列表
  158. /// </summary>
  159. public static List<Model_Video> VideoList = null;
  160. /// <summary>
  161. /// 画板模型
  162. /// </summary>
  163. public static List<Model_DrawData> PageDrawList = null;
  164. #endregion
  165. #region 点阵笔
  166. /// <summary>
  167. /// 点阵笔
  168. /// </summary>
  169. public static DigitalPenHID digitalPen;
  170. /// <summary>
  171. /// 笔序号
  172. /// </summary>
  173. public static string PenSerial;
  174. /// <summary>
  175. /// 笔状态,是否已连接
  176. /// </summary>
  177. public static bool PenStatus = false;
  178. /// <summary>
  179. /// 手写板状态,是否已连接
  180. /// </summary>
  181. public static bool BoardStatus = false;
  182. #endregion
  183. #region 腾千里手写笔
  184. ///// <summary>
  185. ///// 铺码服务请求
  186. ///// </summary>
  187. //public static DAL_TmatrixCode dAL_TmatrixCode;
  188. /// <summary>
  189. /// 腾千里手写笔事件
  190. /// </summary>
  191. public static PenEvents TQLPenevents;
  192. /// <summary>
  193. /// 腾千里手写笔是否已连接
  194. /// </summary>
  195. public static bool TQLPenStatus = false;
  196. #region 打印
  197. public static bool gbGenerateBGWithVImage = false;
  198. public static bool gbGenerateVImage = false;
  199. public static bool gbGenerateBGWithoutVImage = false;
  200. public static bool gbGenerateBGWithImage = false;
  201. public static bool gbGenPageSet = false;
  202. public static int[] gPointType = new int[4];
  203. public static int[] gPointDPI = new int[4];
  204. public static string gTMXElementFileName;
  205. public static string gNewProjectDirectory;
  206. public static bool gbElementFileExist { get; set; }
  207. #endregion
  208. #endregion
  209. #region 页面
  210. /// <summary>
  211. /// 主页面
  212. /// </summary>
  213. public static XHMicroLessonSystemWindow W_XHMicroLessonSystemWindow = null;
  214. /// <summary>
  215. /// 创建微课页面
  216. /// </summary>
  217. public static CreateAMicroLessonWindow W_CreateAMicroLessonWindow = null;
  218. /// <summary>
  219. /// 开始录像
  220. /// </summary>
  221. public static CountdownWindow W_CountdownWindow = null;
  222. /// <summary>
  223. /// 录像工具栏
  224. /// </summary>
  225. public static ScreenRecordingToolbarWindow W_ScreenRecordingToolbarWindow = null;
  226. /// <summary>
  227. /// 登录
  228. /// </summary>
  229. public static LoginWindow W_LoginWindow = null;
  230. /// <summary>
  231. /// 截图
  232. /// </summary>
  233. public static JieTuWindow W_JieTuWindow = null;
  234. /// <summary>
  235. /// 批注
  236. /// </summary>
  237. public static PracticeWindow W_PracticeWindow = null;
  238. /// <summary>
  239. /// 我的视频
  240. /// </summary>
  241. public static FileDirectoryWindow fileDirectoryWindow = null;
  242. /// <summary>
  243. /// 打印
  244. /// </summary>
  245. public static PrintWindow W_PrintWindow = null;
  246. /// <summary>
  247. /// 提示窗口
  248. /// </summary>
  249. public static PromptWindow W_PromptWindow = null;
  250. /// <summary>
  251. /// loding页面
  252. /// </summary>
  253. public static LoadDialog myloading;
  254. /// <summary>
  255. /// 上传页面
  256. /// </summary>
  257. public static UploadWindow W_UploadWindow = null;
  258. /// <summary>
  259. /// 最小化工具栏
  260. /// </summary>
  261. public static MinToolbar W_MinToolbar = null;
  262. /// <summary>
  263. /// 视频剪辑
  264. /// </summary>
  265. public static VideoClipWindow W_VideoClipWindow = null;
  266. /// <summary>
  267. /// 设备检测
  268. /// </summary>
  269. public static DeviceWindow W_DeviceWindow = null;
  270. #endregion
  271. #endregion
  272. [STAThread]
  273. private static void Main()
  274. {
  275. myloading = new LoadDialog();
  276. StopSameProcess();
  277. Killffmpeg();
  278. LatticeFileHelper.RunPrintConfig();
  279. try
  280. {
  281. UserInfo = new Model_UserInfo();
  282. WKDataList = new List<Model_WKData>();
  283. VideoList = new List<Model_Video>();
  284. #region 强制以管理员方式运行 修改人:赵耀 修改时间:2020年9月7日
  285. WindowsIdentity identity = WindowsIdentity.GetCurrent();
  286. WindowsPrincipal principal = new WindowsPrincipal(identity);
  287. //判断当前登录用户是否为管理员
  288. //if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  289. //{
  290. // //如果是管理员,则直接运行
  291. // W_CreateAMicroLessonWindow = new CreateAMicroLessonWindow();
  292. // // 定义Application对象作为整个应用程序入口
  293. // Application app = new Application();
  294. // app.Run(W_CreateAMicroLessonWindow);
  295. // //Application.Run(W_CreateAMicroLessonWindow);
  296. //}
  297. //else
  298. //{
  299. // //创建启动对象
  300. // System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  301. // {
  302. // UseShellExecute = true,
  303. // WorkingDirectory = Environment.CurrentDirectory,
  304. // FileName = Assembly.GetExecutingAssembly().Location,
  305. // //设置启动动作,确保以管理员身份运行
  306. // Verb = "runas"
  307. // };
  308. // try
  309. // {
  310. // System.Diagnostics.Process.Start(startInfo);
  311. // }
  312. // catch
  313. // {
  314. // return;
  315. // }
  316. // //退出
  317. // //Current.Shutdown();
  318. // Environment.Exit(0);
  319. //}
  320. #endregion
  321. try
  322. {
  323. if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "temp"))//清除临时文件
  324. {
  325. Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "temp", true);
  326. }
  327. }
  328. catch (Exception)
  329. {
  330. }
  331. //如果本地文件为空,弹出弹窗 输密匙
  332. //本地文件不为空, 解析
  333. if (!File.Exists(APP.DataPath + "signature.txt"))//上次登录时间为空 或者签名为空 或者上次登录时间不是今天 都需要输入密匙验证 ,否则只验证本地的签名
  334. {
  335. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  336. {
  337. //如果是管理员,则直接运行
  338. KeyVerification wins = new KeyVerification();
  339. // 定义Application对象作为整个应用程序入口
  340. Application app = new Application();
  341. SkinConfig.InitSkin();
  342. app.Run(wins);
  343. }
  344. else
  345. {
  346. //创建启动对象
  347. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  348. {
  349. UseShellExecute = true,
  350. WorkingDirectory = Environment.CurrentDirectory,
  351. FileName = Assembly.GetExecutingAssembly().Location,
  352. //设置启动动作,确保以管理员身份运行
  353. Verb = "runas"
  354. };
  355. try
  356. {
  357. System.Diagnostics.Process.Start(startInfo);
  358. }
  359. catch
  360. {
  361. return;
  362. }
  363. //退出
  364. //Current.Shutdown();
  365. Environment.Exit(0);
  366. }
  367. }
  368. else
  369. {
  370. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  371. {
  372. ProductVerification wins = new ProductVerification();
  373. Application app = new Application();
  374. SkinConfig.InitSkin();
  375. app.Run(wins);
  376. }
  377. else
  378. {
  379. //创建启动对象
  380. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  381. {
  382. UseShellExecute = true,
  383. WorkingDirectory = Environment.CurrentDirectory,
  384. FileName = Assembly.GetExecutingAssembly().Location,
  385. //设置启动动作,确保以管理员身份运行
  386. Verb = "runas"
  387. };
  388. try
  389. {
  390. System.Diagnostics.Process.Start(startInfo);
  391. }
  392. catch
  393. {
  394. return;
  395. }
  396. //退出
  397. //Current.Shutdown();
  398. Environment.Exit(0);
  399. }
  400. }
  401. }
  402. catch (Exception ex)
  403. {
  404. string ErrMessage = "【进程】(Main):进程意外关闭。 " + ex.Message;
  405. LogHelper.WriteErrLog(ErrMessage, ex);
  406. }
  407. }
  408. #region 杀死已存在的进程
  409. /// <summary>
  410. /// 结束已运行的程序
  411. /// </summary>
  412. private static void StopSameProcess()
  413. {
  414. Process current = Process.GetCurrentProcess();
  415. Process[] processList = Process.GetProcesses();
  416. foreach (Process process in processList)
  417. {
  418. if (process.ProcessName.ToUpper() == "星火微课")
  419. {
  420. if (process.Id != current.Id) //忽略当前进程
  421. {
  422. try
  423. {
  424. process.Kill(); //结束进程
  425. }
  426. catch (Exception)
  427. {
  428. }
  429. }
  430. }
  431. }
  432. }
  433. /// <summary>
  434. /// 杀死正在运行的ffmpeg
  435. /// </summary>
  436. public static void Killffmpeg()
  437. {
  438. Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
  439. foreach (Process KillProcess in KillProcessArray)
  440. {
  441. KillProcess.Kill();
  442. }
  443. }
  444. #endregion
  445. /// <summary>
  446. /// 错误处理
  447. /// </summary>
  448. /// <param name="sender"></param>
  449. /// <param name="e"></param>
  450. private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  451. {
  452. LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
  453. MessageWindow.Show("程序异常." + Environment.NewLine + e.Exception.Message);
  454. e.Handled = true;
  455. }
  456. #region 数据保存和读取
  457. /// <summary>
  458. /// 保存微课信息
  459. /// </summary>
  460. public static void SaveWkData()
  461. {
  462. try
  463. {
  464. VideoList = VideoList.Where((x, i) => VideoList.FindIndex(z => z.FileGuid == x.FileGuid) == i).ToList();
  465. WKData.VideoList = VideoList;
  466. if (WKDataList != null)
  467. {
  468. WKDataList.RemoveAll(x => x.WkPath == WKData.WkPath);
  469. }
  470. else
  471. {
  472. WKDataList = new List<Model_WKData>();
  473. }
  474. WKDataList.Add(WKData);
  475. //string WkDateXmlStr = XmlUtilHelper.Serializer(typeof(Model_WKData), WKData);
  476. string WkDateXmlStr = XmlUtilHelper.XmlSerialize(WKDataList);
  477. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/");
  478. FileToolsCommon.CreateDirectory(SavePath);
  479. string SaveName = SavePath + "WkDate.d";
  480. FileToolsCommon.DeleteFile(SaveName);
  481. FileToolsCommon.WriteText(SaveName, WkDateXmlStr);
  482. }
  483. catch (Exception ex)
  484. {
  485. LogHelper.WriteErrLog("【微课数据保存】(SaveWkData)保存失败:" + ex.Message, ex);
  486. }
  487. }
  488. /// <summary>
  489. /// 读取微课信息
  490. /// </summary>
  491. public static void ReadWkData(string WkPath)
  492. {
  493. try
  494. {
  495. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/");
  496. FileToolsCommon.CreateDirectory(SavePath);
  497. string SaveName = SavePath + "WkDate.d";
  498. //文件若存在则读取
  499. if (FileToolsCommon.IsExistFile(SaveName))
  500. {
  501. string WkDateXmlStr = FileToolsCommon.FileToString(SaveName);
  502. WKDataList = XmlUtilHelper.DESerializer<List<Model_WKData>>(WkDateXmlStr);
  503. foreach (Model_WKData wklist in WKDataList)
  504. {
  505. //移除找不到视频的微课数据
  506. wklist.VideoList.RemoveAll(x => !FileToolsCommon.IsExistFile(x.VideoPath));
  507. }
  508. if (WKDataList.Exists(x => x.WkPath == WkPath))
  509. {
  510. WKData = WKDataList.Find(x => x.WkPath == WkPath);
  511. VideoList = new List<Model_Video>();
  512. WKData.VideoList = WKData.VideoList.Where((x, i) => WKData.VideoList.FindIndex(z => z.FileGuid == x.FileGuid) == i).ToList();
  513. VideoList = WKData.VideoList;
  514. //List<Model_Video> companyList = WKData.VideoList;
  515. //VideoList = companyList.Where((x, i) => companyList.FindIndex(z => z.FileGuid == x.FileGuid) == i).ToList();
  516. //VideoList = companyList.Distinct().ToList();
  517. }
  518. }
  519. }
  520. catch (Exception ex)
  521. {
  522. LogHelper.WriteErrLog("【微课数据读取】(ReadWkData)读取失败:" + ex.Message, ex);
  523. }
  524. }
  525. /// <summary>
  526. /// 保存画板数据
  527. /// </summary>
  528. public static void SaveDraw()
  529. {
  530. try
  531. {
  532. if (PageDrawList == null)
  533. {
  534. return;
  535. }
  536. if (PageDrawList.Count < 1)
  537. {
  538. return;
  539. }
  540. FileToolsCommon.CreateDirectory(WKData.WkPath);
  541. string SavePath = WKData.WkPath + "PageData.d";
  542. FileToolsCommon.DeleteFile(SavePath);
  543. string PageDataXmlStr = XmlUtilHelper.XmlSerialize(PageDrawList);
  544. FileToolsCommon.WriteText(SavePath, PageDataXmlStr);
  545. }
  546. catch (Exception ex)
  547. {
  548. LogHelper.WriteErrLog("【画板数据保存】(SaveDraw)保存失败:" + ex.Message, ex);
  549. }
  550. }
  551. /// <summary>
  552. /// 读取文件
  553. /// </summary>
  554. public static void ReadDrawData()
  555. {
  556. try
  557. {
  558. PageDrawList = new List<Model_DrawData>();
  559. string SavePath = WKData.WkPath + "PageData.d";
  560. if (FileToolsCommon.IsExistFile(SavePath))
  561. {
  562. string PageDataXmlStr = FileToolsCommon.FileToString(SavePath);
  563. PageDrawList = XmlUtilHelper.DESerializer<List<Model_DrawData>>(PageDataXmlStr);
  564. }
  565. }
  566. catch (Exception ex)
  567. {
  568. LogHelper.WriteErrLog("【画板数据读取】(ReadDraw)读取失败:" + ex.Message, ex);
  569. }
  570. }
  571. #endregion
  572. #region 服务地址数据
  573. /// <summary>
  574. /// 服务地址存储到本地
  575. /// </summary>
  576. public static void SaveServiceAddressData()
  577. {
  578. try
  579. {
  580. if (ServiceAddress == null)
  581. {
  582. return;
  583. }
  584. string DateXmlStr = XmlUtilHelper.XmlSerialize(ServiceAddress);
  585. string SavePath = DataPath;
  586. FileToolsCommon.CreateDirectory(SavePath);
  587. string SaveName = SavePath + "ServiceAddress.d";
  588. FileToolsCommon.DeleteFile(SaveName);
  589. FileToolsCommon.WriteText(SaveName, DateXmlStr);
  590. }
  591. catch (Exception ex)
  592. {
  593. LogHelper.WriteErrLog("【服务地址存储】(SaveServiceAddressData)保存失败:" + ex.Message, ex);
  594. }
  595. }
  596. /// <summary>
  597. /// 从本地读取服务地址
  598. /// </summary>
  599. public static void ReadServiceAddressData()
  600. {
  601. try
  602. {
  603. string SavePath = DataPath;
  604. FileToolsCommon.CreateDirectory(SavePath);
  605. string SaveName = SavePath + "ServiceAddress.d";
  606. //文件若存在则读取
  607. if (FileToolsCommon.IsExistFile(SaveName))
  608. {
  609. string DateXmlStr = FileToolsCommon.FileToString(SaveName);
  610. ServiceAddress = XmlUtilHelper.DESerializer<Model_ServiceAddress>(DateXmlStr);
  611. SwitchAddress();
  612. }
  613. }
  614. catch (Exception ex)
  615. {
  616. LogHelper.WriteErrLog("【服务地址读取】(ReadServiceAddressData)读取失败:" + ex.Message, ex);
  617. }
  618. }
  619. /// <summary>
  620. /// 切换校内外网
  621. /// </summary>
  622. public static void SwitchAddress()
  623. {
  624. try
  625. {
  626. apiUrl = IsOutsideSchool ? ServiceAddress.wapi : ServiceAddress.napi;
  627. uploadUrl = (IsOutsideSchool ? ServiceAddress.wfile : ServiceAddress.nfile) + "/";
  628. showImageUrl = (IsOutsideSchool ? ServiceAddress.wdown : ServiceAddress.ndown) + "/static/";
  629. }
  630. catch (Exception ex)
  631. {
  632. LogHelper.WriteErrLog("【服务地址切换】(SwitchAddress)服务复制切换失败,请求地址为空!", ex);
  633. }
  634. }
  635. #endregion
  636. #region 检测安装Screen Capturer Recorder
  637. /// <summary>
  638. /// 检测是否安装了Screen Capturer Recorder
  639. /// </summary>
  640. /// <returns></returns>
  641. public static bool CheckScreenCapturerRecorder()
  642. {
  643. if (FileToolsCommon.CheckSoftWartInstallState("Screen Capturer Recorder"))
  644. {
  645. //已经安装
  646. return true;
  647. }
  648. else
  649. {
  650. return false;
  651. }
  652. }
  653. /// <summary>
  654. /// 安装Screen Capturer Recorder
  655. /// </summary>
  656. /// <returns></returns>
  657. public static bool InstallScreenCapturerRecorder()
  658. {
  659. Process InstallProcess = new Process();
  660. string StandardError = "";
  661. string StandardOutput = "";
  662. try
  663. {
  664. InstallProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/SSCR/Setup Screen Capturer Recorder v0.12.10.exe"); //绝对路径
  665. InstallProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
  666. InstallProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
  667. InstallProcess.StartInfo.RedirectStandardOutput = true;
  668. InstallProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
  669. InstallProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
  670. //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
  671. InstallProcess.ErrorDataReceived += new DataReceivedEventHandler(InstallProcess_ErrorDataReceived);
  672. InstallProcess.Start(); //启动线程
  673. InstallProcess.WaitForExit(); //阻塞等待进程结束
  674. StandardError = InstallProcess.StandardError.ReadToEnd();
  675. StandardOutput = InstallProcess.StandardOutput.ReadToEnd();
  676. int ExitCode = InstallProcess.ExitCode;
  677. InstallProcess.Close(); //关闭进程
  678. InstallProcess.Dispose(); //释放资源
  679. if (ExitCode == 0) //非0则为安装失败 1为取消安装
  680. {
  681. return true;
  682. }
  683. else
  684. {
  685. MessageBoxResult br = MessageWindow.Show("不安装环境将无法使用微课录制系统,是否现在安装?", "安装", MessageBoxButton.OKCancel);
  686. if (br == MessageBoxResult.OK)
  687. {
  688. return InstallScreenCapturerRecorder();
  689. }
  690. else
  691. {
  692. return false;
  693. }
  694. }
  695. }
  696. catch (Exception ex)
  697. {
  698. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + ex.Message, ex);
  699. if (string.IsNullOrWhiteSpace(StandardError))
  700. {
  701. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + StandardError, null);
  702. }
  703. if (string.IsNullOrWhiteSpace(StandardOutput))
  704. {
  705. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装返回信息:" + StandardOutput, null);
  706. }
  707. return false;
  708. }
  709. }
  710. /// <summary>
  711. /// 安装失败信息
  712. /// </summary>
  713. /// <param name="sender"></param>
  714. /// <param name="e"></param>
  715. private static void InstallProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
  716. {
  717. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + e.Data, null);
  718. //MessageWindow.Show(e.Data);
  719. }
  720. #endregion
  721. #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  722. /// <summary>
  723. /// 内存释放压缩
  724. /// </summary>
  725. /// <param name="e"></param>
  726. protected override void OnStartup(StartupEventArgs e)
  727. {
  728. //private LierdaCracker cracker = new LierdaCracker();
  729. //cracker.Cracker(5000);//间隔时间
  730. //base.OnStartup(e);
  731. new Thread(o =>
  732. {
  733. while (true)
  734. {
  735. try
  736. {
  737. //FreeMemoryHelper.SetDate();
  738. FreeMemoryHelper.ReallocateMemory();
  739. Thread.Sleep(20000);//暂定每20秒释放一次
  740. }
  741. catch (Exception ex)
  742. {
  743. LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
  744. }
  745. }
  746. }).Start();
  747. }
  748. #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  749. }
  750. }