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 XHWK.Model;
namespace XHWK.WKTool
{
public partial class APP : Application
{
#region 全局变量
///
/// 用户信息
///
public static Model_UserInfo UserInfo=null;
///
/// 接口返回消息
///
public static string ServerMsg=string.Empty;
///
/// 用户微课列表模型
///
public static List WKDataList = null;
///
/// 微课模型
///
public static Model_WKData WKData = null;
///
/// 微课视频列表
///
public static List VideoList = null;
///
/// 主页面
///
public static XHMicroLessonSystemWindow W_XHMicroLessonSystemWindow = null;
///
/// 录屏工具
///
public static FFMpeg FFmpeg = new FFMpeg();
///
/// 开始录像
///
public static CountdownWindow W_CountdownWindow = null;
///
/// 录像工具栏
///
public static ScreenRecordingToolbarWindow W_ScreenRecordingToolbarWindow = null;
///
/// 登陆
///
public static LoginWindow W_LoginWindow = null;
///
/// 截图
///
public static JieTuWindow W_JieTuWindow = null;
///
/// 批注
///
public static PracticeWindow W_PracticeWindow = null;
///
/// 登陆状态 false 未登录 true已登陆
///
public static bool IsLoginType = false;
public static readonly Model_Page pageData = new Model.Model_Page();
///
/// 防止图片地址重复
///
public static long num = 9999;
///
/// 导入图片路径
///
public static string[] Paths = new string[] { };
///
/// 截图图片路径
///
public static string[] JPaths = new string[999];
public static string ImgPath = string.Empty;
#endregion
[STAThread]
private static void Main()
{
// 定义Application对象作为整个应用程序入口
Application app = new Application();
UserInfo = new Model_UserInfo();
WKDataList = new List();
WKData = new Model_WKData();
VideoList = new List();
//app.DispatcherUnhandledException += MyApp_DispatcherUnhandledException;
CreateAMicroLessonWindow win = new CreateAMicroLessonWindow();
app.Run(win);
//LogHelper.WriteInfoLog("启动项目");
StopSameProcess();
LatticeFileHelper.RunPrintConfig();
}
///
/// 结束已运行的程序
///
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)
{
}
}
}
}
}
///
/// 错误处理
///
///
///
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;
}
///
/// 保存微课信息
///
public static void SaveWkData()
{
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();
}
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);
}
}
///
/// 读取微课信息
///
public static void ReadWkData()
{
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>(WkDateXmlStr);
if (WKDataList != null)
{
WKDataList.RemoveAll(x => x.WkName == WKData.WkName);
}
}
}
}
#region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
///
/// 内存释放压缩
///
///
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日
}
}