星火微课系统客户端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 3 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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://schoolfiletest.xhkjedu.com/static/" : FileToolsCommon.GetConfigValue("SchoolfileRequestAddress") + "/static/";
  53. /// <summary>
  54. /// 认证接口地址
  55. /// </summary>
  56. public static string certapiUrl = isDebug ? "http://certapitest.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[4];
  195. public static int[] gPointDPI = new int[4];
  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 FileDirectoryWindow fileDirectoryWindow = null;
  234. /// <summary>
  235. /// 打印
  236. /// </summary>
  237. public static PrintWindow W_PrintWindow = null;
  238. /// <summary>
  239. /// 提示窗口
  240. /// </summary>
  241. public static PromptWindow W_PromptWindow = null;
  242. /// <summary>
  243. /// loding页面
  244. /// </summary>
  245. public static LoadDialog myloading;
  246. /// <summary>
  247. /// 上传页面
  248. /// </summary>
  249. public static UploadWindow W_UploadWindow = null;
  250. /// <summary>
  251. /// 最小化工具栏
  252. /// </summary>
  253. public static MinToolbar W_MinToolbar = null;
  254. /// <summary>
  255. /// 视频剪辑
  256. /// </summary>
  257. public static VideoClipWindow W_VideoClipWindow = null;
  258. /// <summary>
  259. /// 设备检测
  260. /// </summary>
  261. public static DeviceWindow W_DeviceWindow = null;
  262. #endregion
  263. #endregion
  264. [STAThread]
  265. private static void Main()
  266. {
  267. myloading = new LoadDialog();
  268. StopSameProcess();
  269. Killffmpeg();
  270. LatticeFileHelper.RunPrintConfig();
  271. try
  272. {
  273. UserInfo = new Model_UserInfo();
  274. WKDataList = new List<Model_WKData>();
  275. VideoList = new List<Model_Video>();
  276. #region 强制以管理员方式运行 修改人:赵耀 修改时间:2020年9月7日
  277. WindowsIdentity identity = WindowsIdentity.GetCurrent();
  278. WindowsPrincipal principal = new WindowsPrincipal(identity);
  279. //判断当前登录用户是否为管理员
  280. //if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  281. //{
  282. // //如果是管理员,则直接运行
  283. // W_CreateAMicroLessonWindow = new CreateAMicroLessonWindow();
  284. // // 定义Application对象作为整个应用程序入口
  285. // Application app = new Application();
  286. // app.Run(W_CreateAMicroLessonWindow);
  287. // //Application.Run(W_CreateAMicroLessonWindow);
  288. //}
  289. //else
  290. //{
  291. // //创建启动对象
  292. // System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  293. // {
  294. // UseShellExecute = true,
  295. // WorkingDirectory = Environment.CurrentDirectory,
  296. // FileName = Assembly.GetExecutingAssembly().Location,
  297. // //设置启动动作,确保以管理员身份运行
  298. // Verb = "runas"
  299. // };
  300. // try
  301. // {
  302. // System.Diagnostics.Process.Start(startInfo);
  303. // }
  304. // catch
  305. // {
  306. // return;
  307. // }
  308. // //退出
  309. // //Current.Shutdown();
  310. // Environment.Exit(0);
  311. //}
  312. #endregion
  313. try
  314. {
  315. if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "temp"))//清除临时文件
  316. {
  317. Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "temp", true);
  318. }
  319. }
  320. catch (Exception)
  321. {
  322. }
  323. //如果本地文件为空,弹出弹窗 输密匙
  324. //本地文件不为空, 解析
  325. if (!File.Exists(APP.DataPath + "signature.txt"))//上次登录时间为空 或者签名为空 或者上次登录时间不是今天 都需要输入密匙验证 ,否则只验证本地的签名
  326. {
  327. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  328. {
  329. //如果是管理员,则直接运行
  330. KeyVerification wins = new KeyVerification();
  331. // 定义Application对象作为整个应用程序入口
  332. Application app = new Application();
  333. SkinConfig.InitSkin();
  334. app.Run(wins);
  335. }
  336. else
  337. {
  338. //创建启动对象
  339. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  340. {
  341. UseShellExecute = true,
  342. WorkingDirectory = Environment.CurrentDirectory,
  343. FileName = Assembly.GetExecutingAssembly().Location,
  344. //设置启动动作,确保以管理员身份运行
  345. Verb = "runas"
  346. };
  347. try
  348. {
  349. System.Diagnostics.Process.Start(startInfo);
  350. }
  351. catch
  352. {
  353. return;
  354. }
  355. //退出
  356. //Current.Shutdown();
  357. Environment.Exit(0);
  358. }
  359. }
  360. else
  361. {
  362. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  363. {
  364. ProductVerification wins = new ProductVerification();
  365. Application app = new Application();
  366. SkinConfig.InitSkin();
  367. app.Run(wins);
  368. }
  369. else
  370. {
  371. //创建启动对象
  372. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  373. {
  374. UseShellExecute = true,
  375. WorkingDirectory = Environment.CurrentDirectory,
  376. FileName = Assembly.GetExecutingAssembly().Location,
  377. //设置启动动作,确保以管理员身份运行
  378. Verb = "runas"
  379. };
  380. try
  381. {
  382. System.Diagnostics.Process.Start(startInfo);
  383. }
  384. catch
  385. {
  386. return;
  387. }
  388. //退出
  389. //Current.Shutdown();
  390. Environment.Exit(0);
  391. }
  392. }
  393. }
  394. catch (Exception ex)
  395. {
  396. string ErrMessage = "【进程】(Main):进程意外关闭。 " + ex.Message;
  397. LogHelper.WriteErrLog(ErrMessage, ex);
  398. }
  399. }
  400. #region 杀死已存在的进程
  401. /// <summary>
  402. /// 结束已运行的程序
  403. /// </summary>
  404. private static void StopSameProcess()
  405. {
  406. Process current = Process.GetCurrentProcess();
  407. Process[] processList = Process.GetProcesses();
  408. foreach (Process process in processList)
  409. {
  410. if (process.ProcessName.ToUpper() == "星火微课")
  411. {
  412. if (process.Id != current.Id) //忽略当前进程
  413. {
  414. try
  415. {
  416. process.Kill(); //结束进程
  417. }
  418. catch (Exception)
  419. {
  420. }
  421. }
  422. }
  423. }
  424. }
  425. /// <summary>
  426. /// 杀死正在运行的ffmpeg
  427. /// </summary>
  428. public static void Killffmpeg()
  429. {
  430. Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
  431. foreach (Process KillProcess in KillProcessArray)
  432. {
  433. KillProcess.Kill();
  434. }
  435. }
  436. #endregion
  437. /// <summary>
  438. /// 错误处理
  439. /// </summary>
  440. /// <param name="sender"></param>
  441. /// <param name="e"></param>
  442. private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  443. {
  444. LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
  445. MessageWindow.Show("程序异常." + Environment.NewLine + e.Exception.Message);
  446. e.Handled = true;
  447. }
  448. #region 数据保存和读取
  449. /// <summary>
  450. /// 保存微课信息
  451. /// </summary>
  452. public static void SaveWkData()
  453. {
  454. try
  455. {
  456. VideoList = VideoList.Where((x, i) => VideoList.FindIndex(z => z.FileGuid == x.FileGuid) == i).ToList();
  457. WKData.VideoList = VideoList;
  458. if (WKDataList != null)
  459. {
  460. WKDataList.RemoveAll(x => x.WkPath == WKData.WkPath);
  461. }
  462. else
  463. {
  464. WKDataList = new List<Model_WKData>();
  465. }
  466. WKDataList.Add(WKData);
  467. //string WkDateXmlStr = XmlUtilHelper.Serializer(typeof(Model_WKData), WKData);
  468. string WkDateXmlStr = XmlUtilHelper.XmlSerialize(WKDataList);
  469. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/");
  470. FileToolsCommon.CreateDirectory(SavePath);
  471. string SaveName = SavePath + "WkDate.d";
  472. FileToolsCommon.DeleteFile(SaveName);
  473. FileToolsCommon.WriteText(SaveName, WkDateXmlStr);
  474. }
  475. catch (Exception ex)
  476. {
  477. LogHelper.WriteErrLog("【微课数据保存】(SaveWkData)保存失败:" + ex.Message, ex);
  478. }
  479. }
  480. /// <summary>
  481. /// 读取微课信息
  482. /// </summary>
  483. public static void ReadWkData(string WkPath)
  484. {
  485. try
  486. {
  487. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/");
  488. FileToolsCommon.CreateDirectory(SavePath);
  489. string SaveName = SavePath + "WkDate.d";
  490. //文件若存在则读取
  491. if (FileToolsCommon.IsExistFile(SaveName))
  492. {
  493. string WkDateXmlStr = FileToolsCommon.FileToString(SaveName);
  494. WKDataList = XmlUtilHelper.DESerializer<List<Model_WKData>>(WkDateXmlStr);
  495. foreach (Model_WKData wklist in WKDataList)
  496. {
  497. //移除找不到视频的微课数据
  498. wklist.VideoList.RemoveAll(x => !FileToolsCommon.IsExistFile(x.VideoPath));
  499. }
  500. if (WKDataList.Exists(x => x.WkPath == WkPath))
  501. {
  502. WKData = WKDataList.Find(x => x.WkPath == WkPath);
  503. VideoList = new List<Model_Video>();
  504. WKData.VideoList = WKData.VideoList.Where((x, i) => WKData.VideoList.FindIndex(z => z.FileGuid == x.FileGuid) == i).ToList();
  505. VideoList = WKData.VideoList;
  506. //List<Model_Video> companyList = WKData.VideoList;
  507. //VideoList = companyList.Where((x, i) => companyList.FindIndex(z => z.FileGuid == x.FileGuid) == i).ToList();
  508. //VideoList = companyList.Distinct().ToList();
  509. }
  510. }
  511. }
  512. catch (Exception ex)
  513. {
  514. LogHelper.WriteErrLog("【微课数据读取】(ReadWkData)读取失败:" + ex.Message, ex);
  515. }
  516. }
  517. /// <summary>
  518. /// 保存画板数据
  519. /// </summary>
  520. public static void SaveDraw()
  521. {
  522. try
  523. {
  524. if (PageDrawList == null)
  525. {
  526. return;
  527. }
  528. if (PageDrawList.Count < 1)
  529. {
  530. return;
  531. }
  532. FileToolsCommon.CreateDirectory(WKData.WkPath);
  533. string SavePath = WKData.WkPath + "PageData.d";
  534. FileToolsCommon.DeleteFile(SavePath);
  535. string PageDataXmlStr = XmlUtilHelper.XmlSerialize(PageDrawList);
  536. FileToolsCommon.WriteText(SavePath, PageDataXmlStr);
  537. }
  538. catch (Exception ex)
  539. {
  540. LogHelper.WriteErrLog("【画板数据保存】(SaveDraw)保存失败:" + ex.Message, ex);
  541. }
  542. }
  543. /// <summary>
  544. /// 读取文件
  545. /// </summary>
  546. public static void ReadDrawData()
  547. {
  548. try
  549. {
  550. PageDrawList = new List<Model_DrawData>();
  551. string SavePath = WKData.WkPath + "PageData.d";
  552. if (FileToolsCommon.IsExistFile(SavePath))
  553. {
  554. string PageDataXmlStr = FileToolsCommon.FileToString(SavePath);
  555. PageDrawList = XmlUtilHelper.DESerializer<List<Model_DrawData>>(PageDataXmlStr);
  556. }
  557. }
  558. catch (Exception ex)
  559. {
  560. LogHelper.WriteErrLog("【画板数据读取】(ReadDraw)读取失败:" + ex.Message, ex);
  561. }
  562. }
  563. #endregion
  564. #region 服务地址数据
  565. /// <summary>
  566. /// 服务地址存储到本地
  567. /// </summary>
  568. public static void SaveServiceAddressData()
  569. {
  570. try
  571. {
  572. if (ServiceAddress == null)
  573. {
  574. return;
  575. }
  576. string DateXmlStr = XmlUtilHelper.XmlSerialize(ServiceAddress);
  577. string SavePath = DataPath;
  578. FileToolsCommon.CreateDirectory(SavePath);
  579. string SaveName = SavePath + "ServiceAddress.d";
  580. FileToolsCommon.DeleteFile(SaveName);
  581. FileToolsCommon.WriteText(SaveName, DateXmlStr);
  582. }
  583. catch (Exception ex)
  584. {
  585. LogHelper.WriteErrLog("【服务地址存储】(SaveServiceAddressData)保存失败:" + ex.Message, ex);
  586. }
  587. }
  588. /// <summary>
  589. /// 从本地读取服务地址
  590. /// </summary>
  591. public static void ReadServiceAddressData()
  592. {
  593. try
  594. {
  595. string SavePath = DataPath;
  596. FileToolsCommon.CreateDirectory(SavePath);
  597. string SaveName = SavePath + "ServiceAddress.d";
  598. //文件若存在则读取
  599. if (FileToolsCommon.IsExistFile(SaveName))
  600. {
  601. string DateXmlStr = FileToolsCommon.FileToString(SaveName);
  602. ServiceAddress = XmlUtilHelper.DESerializer<Model_ServiceAddress>(DateXmlStr);
  603. SwitchAddress();
  604. }
  605. }
  606. catch (Exception ex)
  607. {
  608. LogHelper.WriteErrLog("【服务地址读取】(ReadServiceAddressData)读取失败:" + ex.Message, ex);
  609. }
  610. }
  611. /// <summary>
  612. /// 切换校内外网
  613. /// </summary>
  614. public static void SwitchAddress()
  615. {
  616. try
  617. {
  618. apiUrl = IsOutsideSchool ? ServiceAddress.wapi : ServiceAddress.napi;
  619. uploadUrl = (IsOutsideSchool ? ServiceAddress.wfile : ServiceAddress.nfile) + "/";
  620. showImageUrl = (IsOutsideSchool ? ServiceAddress.wdown : ServiceAddress.ndown) + "/static/";
  621. }
  622. catch (Exception ex)
  623. {
  624. LogHelper.WriteErrLog("【服务地址切换】(SwitchAddress)服务复制切换失败,请求地址为空!", ex);
  625. }
  626. }
  627. #endregion
  628. #region 检测安装Screen Capturer Recorder
  629. /// <summary>
  630. /// 检测是否安装了Screen Capturer Recorder
  631. /// </summary>
  632. /// <returns></returns>
  633. public static bool CheckScreenCapturerRecorder()
  634. {
  635. if (FileToolsCommon.CheckSoftWartInstallState("Screen Capturer Recorder"))
  636. {
  637. //已经安装
  638. return true;
  639. }
  640. else
  641. {
  642. return false;
  643. }
  644. }
  645. /// <summary>
  646. /// 安装Screen Capturer Recorder
  647. /// </summary>
  648. /// <returns></returns>
  649. public static bool InstallScreenCapturerRecorder()
  650. {
  651. Process InstallProcess = new Process();
  652. string StandardError = "";
  653. string StandardOutput = "";
  654. try
  655. {
  656. InstallProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/SSCR/Setup Screen Capturer Recorder v0.12.10.exe"); //绝对路径
  657. InstallProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
  658. InstallProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
  659. InstallProcess.StartInfo.RedirectStandardOutput = true;
  660. InstallProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
  661. InstallProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
  662. //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
  663. InstallProcess.ErrorDataReceived += new DataReceivedEventHandler(InstallProcess_ErrorDataReceived);
  664. InstallProcess.Start(); //启动线程
  665. InstallProcess.WaitForExit(); //阻塞等待进程结束
  666. StandardError = InstallProcess.StandardError.ReadToEnd();
  667. StandardOutput = InstallProcess.StandardOutput.ReadToEnd();
  668. int ExitCode = InstallProcess.ExitCode;
  669. InstallProcess.Close(); //关闭进程
  670. InstallProcess.Dispose(); //释放资源
  671. if (ExitCode == 0) //非0则为安装失败 1为取消安装
  672. {
  673. return true;
  674. }
  675. else
  676. {
  677. MessageBoxResult br = MessageWindow.Show("不安装环境将无法使用微课录制系统,是否现在安装?", "安装", MessageBoxButton.OKCancel);
  678. if (br == MessageBoxResult.OK)
  679. {
  680. return InstallScreenCapturerRecorder();
  681. }
  682. else
  683. {
  684. return false;
  685. }
  686. }
  687. }
  688. catch (Exception ex)
  689. {
  690. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + ex.Message, ex);
  691. if (string.IsNullOrWhiteSpace(StandardError))
  692. {
  693. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + StandardError, null);
  694. }
  695. if (string.IsNullOrWhiteSpace(StandardOutput))
  696. {
  697. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装返回信息:" + StandardOutput, null);
  698. }
  699. return false;
  700. }
  701. }
  702. /// <summary>
  703. /// 安装失败信息
  704. /// </summary>
  705. /// <param name="sender"></param>
  706. /// <param name="e"></param>
  707. private static void InstallProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
  708. {
  709. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + e.Data, null);
  710. //MessageWindow.Show(e.Data);
  711. }
  712. #endregion
  713. #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  714. /// <summary>
  715. /// 内存释放压缩
  716. /// </summary>
  717. /// <param name="e"></param>
  718. protected override void OnStartup(StartupEventArgs e)
  719. {
  720. //private LierdaCracker cracker = new LierdaCracker();
  721. //cracker.Cracker(5000);//间隔时间
  722. //base.OnStartup(e);
  723. new Thread(o =>
  724. {
  725. while (true)
  726. {
  727. try
  728. {
  729. //FreeMemoryHelper.SetDate();
  730. FreeMemoryHelper.ReallocateMemory();
  731. Thread.Sleep(20000);//暂定每20秒释放一次
  732. }
  733. catch (Exception ex)
  734. {
  735. LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
  736. }
  737. }
  738. }).Start();
  739. }
  740. #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  741. }
  742. }