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

4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. using ComeCapture;
  2. using Common.system;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Reflection;
  7. using System.Security.Principal;
  8. using System.Security.RightsManagement;
  9. using System.Threading;
  10. using System.Windows;
  11. using System.Windows.Documents;
  12. using System.Windows.Threading;
  13. using TStudyDigitalPen.HID;
  14. using XHWK.Model;
  15. namespace XHWK.WKTool
  16. {
  17. public partial class APP : Application
  18. {
  19. #region 全局变量
  20. /// <summary>
  21. /// 用户信息
  22. /// </summary>
  23. public static Model_UserInfo UserInfo=null;
  24. /// <summary>
  25. /// 接口返回消息
  26. /// </summary>
  27. public static string ServerMsg=string.Empty;
  28. /// <summary>
  29. /// 用户微课列表模型
  30. /// </summary>
  31. public static List<Model_WKData> WKDataList = null;
  32. /// <summary>
  33. /// 微课模型
  34. /// </summary>
  35. public static Model_WKData WKData = null;
  36. /// <summary>
  37. /// 微课视频列表
  38. /// </summary>
  39. public static List<Model_Video> VideoList = null;
  40. /// <summary>
  41. /// 画板模型
  42. /// </summary>
  43. public static List<Model_DrawData> PageDrawList = null;
  44. /// <summary>
  45. /// 录屏工具
  46. /// </summary>
  47. public static FFMpeg FFmpeg = new FFMpeg();
  48. /// <summary>
  49. /// 登陆状态 false 未登录 true已登陆
  50. /// </summary>
  51. public static bool IsLoginType = false;
  52. public static readonly Model_Page pageData = new Model.Model_Page();
  53. /// <summary>
  54. /// 防止图片地址重复
  55. /// </summary>
  56. public static long num = 9999;
  57. /// <summary>
  58. /// 导入图片路径
  59. /// </summary>
  60. public static string[] Paths = new string[] { };
  61. /// <summary>
  62. /// 截图图片路径
  63. /// </summary>
  64. public static string[] JPaths = new string[999];
  65. public static string ImgPath = string.Empty;
  66. /// <summary>
  67. /// 页码IP
  68. /// </summary>
  69. public static string[] OutPut = new string[] { };
  70. public static string CameraPosition = string.Empty;
  71. #region 点阵笔
  72. /// <summary>
  73. /// 点阵笔
  74. /// </summary>
  75. public static DigitalPenHID digitalPen;
  76. /// <summary>
  77. /// 笔序号
  78. /// </summary>
  79. public static string PenSerial;
  80. /// <summary>
  81. /// 笔状态,是否已连接
  82. /// </summary>
  83. public static bool PenStatus;
  84. #endregion
  85. #region 页面
  86. /// <summary>
  87. /// 主页面
  88. /// </summary>
  89. public static XHMicroLessonSystemWindow W_XHMicroLessonSystemWindow = null;
  90. /// <summary>
  91. /// 创建微课页面
  92. /// </summary>
  93. public static CreateAMicroLessonWindow W_CreateAMicroLessonWindow = null;
  94. /// <summary>
  95. /// 开始录像
  96. /// </summary>
  97. public static CountdownWindow W_CountdownWindow = null;
  98. /// <summary>
  99. /// 录像工具栏
  100. /// </summary>
  101. public static ScreenRecordingToolbarWindow W_ScreenRecordingToolbarWindow = null;
  102. /// <summary>
  103. /// 登陆
  104. /// </summary>
  105. public static LoginWindow W_LoginWindow = null;
  106. /// <summary>
  107. /// 截图
  108. /// </summary>
  109. public static JieTuWindow W_JieTuWindow = null;
  110. /// <summary>
  111. /// 批注
  112. /// </summary>
  113. public static PracticeWindow W_PracticeWindow = null;
  114. /// <summary>
  115. /// 我的视频
  116. /// </summary>
  117. public static FileDirectoryWindow fileDirectoryWindow = null;
  118. public static PrintWindow W_PrintWindow = null;
  119. #endregion
  120. #endregion
  121. [STAThread]
  122. private static void Main()
  123. {
  124. try
  125. {
  126. UserInfo = new Model_UserInfo();
  127. WKDataList = new List<Model_WKData>();
  128. WKData = new Model_WKData();
  129. VideoList = new List<Model_Video>();
  130. #region 强制以管理员方式运行 修改人:赵耀 修改时间:2020年9月7日
  131. WindowsIdentity identity = WindowsIdentity.GetCurrent();
  132. WindowsPrincipal principal = new WindowsPrincipal(identity);
  133. //判断当前登录用户是否为管理员
  134. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  135. {
  136. //如果是管理员,则直接运行
  137. W_CreateAMicroLessonWindow = new CreateAMicroLessonWindow();
  138. // 定义Application对象作为整个应用程序入口
  139. Application app = new Application();
  140. app.Run(W_CreateAMicroLessonWindow);
  141. //Application.Run(W_CreateAMicroLessonWindow);
  142. }
  143. else
  144. {
  145. //创建启动对象
  146. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
  147. startInfo.UseShellExecute = true;
  148. startInfo.WorkingDirectory = Environment.CurrentDirectory;
  149. startInfo.FileName = Assembly.GetExecutingAssembly().Location;
  150. //设置启动动作,确保以管理员身份运行
  151. startInfo.Verb = "runas";
  152. try
  153. {
  154. System.Diagnostics.Process.Start(startInfo);
  155. }
  156. catch
  157. {
  158. return;
  159. }
  160. //退出
  161. //Current.Shutdown();
  162. Environment.Exit(0);
  163. }
  164. #endregion
  165. }
  166. catch (Exception ex)
  167. {
  168. string ErrMessage = "【进程】(Main):进程意外关闭。 " + ex.Message;
  169. LogHelper.WriteErrLog(ErrMessage, ex);
  170. }
  171. StopSameProcess();
  172. Killffmpeg();
  173. LatticeFileHelper.RunPrintConfig();
  174. }
  175. #region 杀死已存在的进程
  176. /// <summary>
  177. /// 结束已运行的程序
  178. /// </summary>
  179. private static void StopSameProcess()
  180. {
  181. Process current = Process.GetCurrentProcess();
  182. Process[] processList = Process.GetProcesses();
  183. foreach (Process process in processList)
  184. {
  185. if (process.ProcessName.ToUpper() == "XHSCHOOL")
  186. {
  187. if (process.Id != current.Id) //忽略当前进程
  188. {
  189. try
  190. {
  191. process.Kill(); //结束进程
  192. }
  193. catch (Exception)
  194. {
  195. }
  196. }
  197. }
  198. }
  199. }
  200. /// <summary>
  201. /// 杀死正在运行的ffmpeg
  202. /// </summary>
  203. public static void Killffmpeg()
  204. {
  205. Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
  206. foreach (var KillProcess in KillProcessArray)
  207. {
  208. KillProcess.Kill();
  209. }
  210. }
  211. #endregion
  212. /// <summary>
  213. /// 错误处理
  214. /// </summary>
  215. /// <param name="sender"></param>
  216. /// <param name="e"></param>
  217. private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  218. {
  219. LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
  220. MessageBox.Show("程序异常." + Environment.NewLine + e.Exception.Message);
  221. e.Handled = true;
  222. }
  223. #region 数据保存和读取
  224. /// <summary>
  225. /// 保存微课信息
  226. /// </summary>
  227. public static void SaveWkData()
  228. {
  229. try
  230. {
  231. if (UserInfo == null)
  232. {
  233. return;
  234. }
  235. if (!string.IsNullOrWhiteSpace(APP.UserInfo.Username))
  236. {
  237. WKData.VideoList = VideoList;
  238. if (WKDataList != null)
  239. {
  240. WKDataList.RemoveAll(x => x.WkName == WKData.WkName);
  241. }
  242. else
  243. {
  244. WKDataList = new List<Model_WKData>();
  245. }
  246. WKDataList.Add(WKData);
  247. //string WkDateXmlStr = XmlUtilHelper.Serializer(typeof(Model_WKData), WKData);
  248. string WkDateXmlStr = XmlUtilHelper.XmlSerialize(WKDataList);
  249. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/");
  250. FileToolsCommon.CreateDirectory(SavePath);
  251. string SaveName = SavePath + "UserWkDate.d";
  252. FileToolsCommon.DeleteFile(SaveName);
  253. FileToolsCommon.WriteText(SaveName, WkDateXmlStr);
  254. }
  255. }
  256. catch (Exception ex)
  257. {
  258. LogHelper.WriteErrLog("【微课数据保存】(SaveWkData)保存失败:" + ex.Message, ex);
  259. }
  260. }
  261. /// <summary>
  262. /// 读取微课信息
  263. /// </summary>
  264. public static void ReadWkData()
  265. {
  266. try
  267. {
  268. if (UserInfo == null)
  269. {
  270. return;
  271. }
  272. if (!string.IsNullOrWhiteSpace(APP.UserInfo.Username))
  273. {
  274. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/");
  275. FileToolsCommon.CreateDirectory(SavePath);
  276. string SaveName = SavePath + "UserWkDate.d";
  277. //文件若存在则读取
  278. if (FileToolsCommon.IsExistFile(SaveName))
  279. {
  280. string WkDateXmlStr = FileToolsCommon.FileToString(SaveName);
  281. WKDataList = XmlUtilHelper.DESerializer<List<Model_WKData>>(WkDateXmlStr);
  282. }
  283. }
  284. }
  285. catch (Exception ex)
  286. {
  287. LogHelper.WriteErrLog("【微课数据读取】(ReadWkData)读取失败:" + ex.Message, ex);
  288. }
  289. }
  290. /// <summary>
  291. /// 保存画板数据
  292. /// </summary>
  293. public static void SaveDraw()
  294. {
  295. try
  296. {
  297. if (PageDrawList == null)
  298. {
  299. return;
  300. }
  301. if (PageDrawList.Count < 1)
  302. {
  303. return;
  304. }
  305. FileToolsCommon.CreateDirectory(WKData.WkPath);
  306. string SavePath = WKData.WkPath + "PageData.d";
  307. FileToolsCommon.DeleteFile(SavePath);
  308. string PageDataXmlStr = XmlUtilHelper.XmlSerialize(PageDrawList);
  309. FileToolsCommon.WriteText(SavePath, PageDataXmlStr);
  310. }
  311. catch (Exception ex)
  312. {
  313. LogHelper.WriteErrLog("【画板数据保存】(SaveDraw)保存失败:" + ex.Message, ex);
  314. }
  315. }
  316. /// <summary>
  317. /// 读取文件
  318. /// </summary>
  319. public static void ReadDrawData()
  320. {
  321. try
  322. {
  323. PageDrawList = new List<Model_DrawData>();
  324. FileToolsCommon.CreateDirectory(WKData.WkPath);
  325. string SavePath = WKData.WkPath + "PageData.d";
  326. if (FileToolsCommon.IsExistFile(SavePath))
  327. {
  328. string PageDataXmlStr = FileToolsCommon.FileToString(SavePath);
  329. PageDrawList = XmlUtilHelper.DESerializer<List<Model_DrawData>>(PageDataXmlStr);
  330. }
  331. }
  332. catch (Exception ex)
  333. {
  334. LogHelper.WriteErrLog("【画板数据读取】(ReadDraw)读取失败:" + ex.Message, ex);
  335. }
  336. }
  337. #endregion
  338. #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  339. /// <summary>
  340. /// 内存释放压缩
  341. /// </summary>
  342. /// <param name="e"></param>
  343. protected override void OnStartup(StartupEventArgs e)
  344. {
  345. //private LierdaCracker cracker = new LierdaCracker();
  346. //cracker.Cracker(5000);//间隔时间
  347. //base.OnStartup(e);
  348. new Thread(o =>
  349. {
  350. while (true)
  351. {
  352. try
  353. {
  354. //FreeMemoryHelper.SetDate();
  355. FreeMemoryHelper.ReallocateMemory();
  356. Thread.Sleep(20000);//暂定每20秒释放一次
  357. }
  358. catch (Exception ex)
  359. {
  360. LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
  361. }
  362. }
  363. }).Start();
  364. }
  365. #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  366. }
  367. }