123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- using ComeCapture;
- using Common.system;
-
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Security.RightsManagement;
- using System.Threading;
- using System.Windows;
- using System.Windows.Threading;
-
- using TStudyDigitalPen.HID;
-
- using XHWK.Model;
-
- namespace XHWK.WKTool
- {
- public partial class APP : Application
- {
- #region 全局变量
- /// <summary>
- /// 用户信息
- /// </summary>
- public static Model_UserInfo UserInfo=null;
- /// <summary>
- /// 接口返回消息
- /// </summary>
- public static string ServerMsg=string.Empty;
- /// <summary>
- /// 用户微课列表模型
- /// </summary>
- public static List<Model_WKData> WKDataList = null;
- /// <summary>
- /// 微课模型
- /// </summary>
- public static Model_WKData WKData = null;
- /// <summary>
- /// 微课视频列表
- /// </summary>
- public static List<Model_Video> VideoList = null;
- public static List<Model_DrawData> PageDrawList = null;
- /// <summary>
- /// 录屏工具
- /// </summary>
- public static FFMpeg FFmpeg = new FFMpeg();
- /// <summary>
- /// 登陆状态 false 未登录 true已登陆
- /// </summary>
- public static bool IsLoginType = false;
- public static readonly Model_Page pageData = new Model.Model_Page();
- /// <summary>
- /// 防止图片地址重复
- /// </summary>
- public static long num = 9999;
- /// <summary>
- /// 导入图片路径
- /// </summary>
- public static string[] Paths = new string[] { };
- /// <summary>
- /// 截图图片路径
- /// </summary>
- public static string[] JPaths = new string[999];
- public static string ImgPath = string.Empty;
- /// <summary>
- /// 页码IP
- /// </summary>
- public static string[] OutPut = new string[] { };
- #region 点阵笔
- /// <summary>
- /// 点阵笔
- /// </summary>
- public static DigitalPenHID digitalPen;
- /// <summary>
- /// 笔序号
- /// </summary>
- public static string PenSerial;
- /// <summary>
- /// 笔状态,是否已连接
- /// </summary>
- public static bool PenStatus;
- #endregion
- #region 页面
- /// <summary>
- /// 主页面
- /// </summary>
- public static XHMicroLessonSystemWindow W_XHMicroLessonSystemWindow = null;
- /// <summary>
- /// 创建微课页面
- /// </summary>
- public static CreateAMicroLessonWindow W_CreateAMicroLessonWindow = null;
- /// <summary>
- /// 开始录像
- /// </summary>
- public static CountdownWindow W_CountdownWindow = null;
- /// <summary>
- /// 录像工具栏
- /// </summary>
- public static ScreenRecordingToolbarWindow W_ScreenRecordingToolbarWindow = null;
- /// <summary>
- /// 登陆
- /// </summary>
- public static LoginWindow W_LoginWindow = null;
- /// <summary>
- /// 截图
- /// </summary>
- public static JieTuWindow W_JieTuWindow = null;
- /// <summary>
- /// 批注
- /// </summary>
- public static PracticeWindow W_PracticeWindow = null;
- #endregion
- #endregion
-
- [STAThread]
- private static void Main()
- {
- // 定义Application对象作为整个应用程序入口
- Application app = new Application();
- UserInfo = new Model_UserInfo();
- WKDataList = new List<Model_WKData>();
- WKData = new Model_WKData();
- VideoList = new List<Model_Video>();
- //app.DispatcherUnhandledException += MyApp_DispatcherUnhandledException;
- W_CreateAMicroLessonWindow = new CreateAMicroLessonWindow();
- app.Run(W_CreateAMicroLessonWindow);
- //LogHelper.WriteInfoLog("启动项目");
- StopSameProcess();
- Killffmpeg();
- LatticeFileHelper.RunPrintConfig();
- }
- /// <summary>
- /// 结束已运行的程序
- /// </summary>
- private static void StopSameProcess()
- {
- Process current = Process.GetCurrentProcess();
- Process[] processList = Process.GetProcesses();
- foreach (Process process in processList)
- {
- if (process.ProcessName.ToUpper() == "XHSCHOOL")
- {
- if (process.Id != current.Id) //忽略当前进程
- {
- try
- {
- process.Kill(); //结束进程
- }
- catch (Exception)
- {
- }
- }
- }
- }
- }
-
- /// <summary>
- /// 错误处理
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
- {
- LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
- MessageBox.Show("程序异常." + Environment.NewLine + e.Exception.Message);
- e.Handled = true;
- }
-
- #region 数据保存和读取
- /// <summary>
- /// 保存微课信息
- /// </summary>
- public static void SaveWkData()
- {
- try
- {
- if (UserInfo == null)
- {
- return;
- }
- if (!string.IsNullOrWhiteSpace(APP.UserInfo.Username))
- {
- WKData.VideoList = VideoList;
- if (WKDataList != null)
- {
- WKDataList.RemoveAll(x => x.WkName == WKData.WkName);
- }
- else
- {
- WKDataList = new List<Model_WKData>();
- }
- WKDataList.Add(WKData);
- //string WkDateXmlStr = XmlUtilHelper.Serializer(typeof(Model_WKData), WKData);
- string WkDateXmlStr = XmlUtilHelper.XmlSerialize(WKDataList);
- string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/");
- FileToolsCommon.CreateDirectory(SavePath);
- string SaveName = SavePath + "UserWkDate.d";
- FileToolsCommon.DeleteFile(SaveName);
- FileToolsCommon.WriteText(SaveName, WkDateXmlStr);
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【微课数据保存】(SaveWkData)保存失败:" + ex.Message, ex);
- }
- }
- /// <summary>
- /// 读取微课信息
- /// </summary>
- public static void ReadWkData()
- {
- try
- {
- if (UserInfo == null)
- {
- return;
- }
- if (!string.IsNullOrWhiteSpace(APP.UserInfo.Username))
- {
- string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/");
- FileToolsCommon.CreateDirectory(SavePath);
- string SaveName = SavePath + "UserWkDate.d";
- //文件若存在则读取
- if (FileToolsCommon.IsExistFile(SaveName))
- {
- string WkDateXmlStr = FileToolsCommon.FileToString(SaveName);
- WKDataList = XmlUtilHelper.DESerializer<List<Model_WKData>>(WkDateXmlStr);
- }
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【微课数据读取】(ReadWkData)读取失败:" + ex.Message, ex);
- }
- }
- /// <summary>
- /// 保存画板数据
- /// </summary>
- public static void SaveDraw()
- {
- try
- {
- if (PageDrawList == null)
- {
- return;
- }
- if (PageDrawList.Count < 1)
- {
- return;
- }
- FileToolsCommon.CreateDirectory(WKData.WkPath);
- string SavePath = WKData.WkPath + "PageData.d";
- FileToolsCommon.DeleteFile(SavePath);
- string PageDataXmlStr = XmlUtilHelper.XmlSerialize(PageDrawList);
- FileToolsCommon.WriteText(SavePath, PageDataXmlStr);
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【画板数据保存】(SaveDraw)保存失败:" + ex.Message, ex);
- }
- }
- /// <summary>
- /// 读取文件
- /// </summary>
- public static void ReadDrawData()
- {
- try
- {
- PageDrawList = new List<Model_DrawData>();
- FileToolsCommon.CreateDirectory(WKData.WkPath);
- string SavePath = WKData.WkPath + "PageData.d";
- if (FileToolsCommon.IsExistFile(SavePath))
- {
- string PageDataXmlStr = FileToolsCommon.FileToString(SavePath);
- PageDrawList = XmlUtilHelper.DESerializer<List<Model_DrawData>>(PageDataXmlStr);
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【画板数据读取】(ReadDraw)读取失败:" + ex.Message, ex);
- }
- }
- #endregion
- /// <summary>
- /// 杀死正在运行的ffmpeg
- /// </summary>
- public static void Killffmpeg()
- {
- Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
- foreach (var KillProcess in KillProcessArray)
- {
- KillProcess.Kill();
- }
- }
- #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
-
- /// <summary>
- /// 内存释放压缩
- /// </summary>
- /// <param name="e"></param>
- protected override void OnStartup(StartupEventArgs e)
- {
- //private LierdaCracker cracker = new LierdaCracker();
- //cracker.Cracker(5000);//间隔时间
- //base.OnStartup(e);
- new Thread(o =>
- {
- while (true)
- {
- try
- {
- //FreeMemoryHelper.SetDate();
- FreeMemoryHelper.ReallocateMemory();
- Thread.Sleep(20000);//暂定每20秒释放一次
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
- }
- }
- }).Start();
- }
-
- #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
- }
- }
|