using Common.system;
using System;
using System.IO;
using System.Text;
using System.Windows;
using XHWK.Model;
using XHWK.WKTool.DAL;
using XHWK.WKTool.Skin;
namespace XHWK.WKTool
{
///
/// ProductVerification.xaml 的交互逻辑
///
/*
本地解密 解密成功 日期在有效期内 ,判断当天是否调用添加历史接口,没有则调用
解密失败 或解密获取的时间 过期 , 跳到输入code 激活界面
*/
public partial class ProductVerification : Window
{
private readonly XHApi registerController = new XHApi();
private int serverReturnCode = 0;
public ProductVerification()
{
InitializeComponent();
WindowStartupLocation = WindowStartupLocation.CenterScreen;
Topmost = true;
APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationDecryptServering, InvokeActivationDecryptServerCompate);
}
///
/// 激活信息--验证签名是否过期-调用
///
///
private object InvokeActivationDecryptServering()
{
return APP.ServerMsg;
}
///
/// 激活信息--验证签名是否过期-返回结果
///
///
public void InvokeActivationDecryptServerCompate(object obj)
{
//解析
try
{
APP.Signature = System.IO.File.ReadAllText(APP.DataPath + "signature.txt", Encoding.Default);
string decrypt = DataProvider.TripleDESDecrypt(APP.Signature, APP.secretKey);
decrypt = decrypt.Replace("\u0001", "").Replace("\u0007", "").Trim();
Model_Signatures msgBean = JsonHelper.JsonToObj(decrypt);
long currentTimeTimestamp = DataProvider.TimestampTotalSeconds(); //当前时间 时间戳
if (msgBean.endtime > currentTimeTimestamp)//条件成立 解析成功 code 在有效期内
{
if (File.Exists(APP.DataPath + "signatureTime.txt"))
{
string signatureTime = System.IO.File.ReadAllText(APP.DataPath + "signatureTime.txt", Encoding.Default);
string currentTime = DateTime.Now.ToLongDateString().ToString();//当前时间
if (signatureTime != currentTime)
{
APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationAddHistoryServering, InvokeActivationAddHistoryServerCompate);
}
}
Dispatcher.Invoke(new Action(() =>
{
Hide();
CreateAMicroLessonWindow win = new CreateAMicroLessonWindow();
win.Show();
Close();
}));
}
else//时间失效
{
Dispatcher.Invoke(new Action(() =>
{
Hide();
KeyVerification wins = new KeyVerification
{
Topmost = true
};
wins.ShowDialog();
Close();
}));
}
}
catch (Exception ex) //解析失败 输code
{
LogHelper.WriteErrLog("ProductVerification(解析失败)" + ex.Message, ex);
Dispatcher.Invoke(new Action(() =>
{
Hide();
KeyVerification wins = new KeyVerification
{
Topmost = true
};
wins.ShowDialog();
Close();
}));
}
}
///
/// 激活信息--添加激活历史-调用
///
///
private object InvokeActivationAddHistoryServering()
{
serverReturnCode = registerController.ActivationAddHistory();
return APP.ServerMsg;
}
///
/// 激活信息--添加激活历史-返回结果
///
///
public void InvokeActivationAddHistoryServerCompate(object obj)
{
if (!Directory.Exists(APP.DataPath))
{
Directory.CreateDirectory(APP.DataPath);
}
string ApplicationData = APP.DataPath + "signatureTime.txt";
string currentTime = DateTime.Now.ToLongDateString().ToString();//当前时间
System.IO.File.WriteAllText(ApplicationData, currentTime, Encoding.Default);//存放签名验证日期
}
///
/// 关闭弹窗
///
///
///
private void close_click(object sender, RoutedEventArgs e)
{
closeAction();
}
///
/// 退出程序
///
private void closeAction()
{
Dispatcher.Invoke(new Action(() =>
{
System.Environment.Exit(0);
}));
}
~ProductVerification()
{
//Console.WriteLine("{0}被销毁", this);
Dispose(false);
}
public void Dispose()
{
//Console.WriteLine("{0}被手动销毁", this);
Dispose(true);
GC.SuppressFinalize(this);
}
private bool disposed;
protected void Dispose(bool disposing)
{
//Console.WriteLine("{0}被自动销毁", this);
if (!disposed)
{
if (disposing)
{
//托管资源释放
}
//非托管资源释放
// ...
}
disposed = true;
}
}
}