|
|
|
using AksWebBrowser;
|
|
|
|
using AksWebBrowser.Common;
|
|
|
|
using AKSWebBrowser.Commen;
|
|
|
|
using CPF;
|
|
|
|
using CPF.Cef;
|
|
|
|
using CPF.Controls;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Net.Http;
|
|
|
|
using System.Net.Sockets;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Timers;
|
|
|
|
|
|
|
|
namespace AKS.EnterpriseLibrary.WebBrowser
|
|
|
|
{
|
|
|
|
public class FrmMain : Window
|
|
|
|
{
|
|
|
|
public int w = 1080;
|
|
|
|
public int h = 1920;
|
|
|
|
//public int h = 1080;
|
|
|
|
//public int w = 1920;
|
|
|
|
|
|
|
|
protected override void InitializeComponent()
|
|
|
|
{
|
|
|
|
//注册gb2312
|
|
|
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
|
|
|
LoadStyleFile("res://AksWebBrowser/StyleSheet.css");
|
|
|
|
//加载样式文件,文件需要设置为内嵌资源
|
|
|
|
Title = "控申业务专用浏览器";
|
|
|
|
CanResize = false;
|
|
|
|
ShowInTaskbar = true;
|
|
|
|
WindowState = WindowState.FullScreen;
|
|
|
|
//WindowState = WindowState.Maximized;
|
|
|
|
|
|
|
|
Children.Add(
|
|
|
|
new Border
|
|
|
|
{
|
|
|
|
Width = "100%",
|
|
|
|
Height = "100%",
|
|
|
|
Child = new Panel
|
|
|
|
{
|
|
|
|
Size = SizeField.Fill,
|
|
|
|
Children =
|
|
|
|
{
|
|
|
|
//Parame.videoV,
|
|
|
|
new CusWebBrowser
|
|
|
|
{
|
|
|
|
PresenterFor = this,
|
|
|
|
Name = nameof(Parame.webBrowser),
|
|
|
|
Bindings =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
nameof(CusWebBrowser.Title),
|
|
|
|
"Title",
|
|
|
|
this,
|
|
|
|
BindingMode.OneWayToSource
|
|
|
|
},
|
|
|
|
},
|
|
|
|
MarginTop=0,
|
|
|
|
MarginLeft=0,
|
|
|
|
MarginRight=0,
|
|
|
|
MarginBottom=0,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
private TextBox textBox;
|
|
|
|
protected override async void OnInitialized()
|
|
|
|
{
|
|
|
|
//窗体大小
|
|
|
|
this.Width = w;
|
|
|
|
this.Height = h;
|
|
|
|
//SetTaskStatus.Hidetask();
|
|
|
|
base.OnInitialized();
|
|
|
|
//初始化网络连接(硬件服务响应)
|
|
|
|
MainModel.DeviceControllerInit();
|
|
|
|
Parame.webBrowser = FindPresenterByName<CusWebBrowser>(nameof(Parame.webBrowser));
|
|
|
|
textBox = FindPresenterByName<TextBox>(nameof(textBox));
|
|
|
|
Parame.webBrowser.CusRequest.CusResquestEvent += CusRequest_CusResquestEvent;
|
|
|
|
//浏览器大小
|
|
|
|
Parame.webBrowser.Width = w;
|
|
|
|
Parame.webBrowser.Height = h;
|
|
|
|
Parame.webBrowser.Url = "http://127.0.0.1:8096/#/main-out";
|
|
|
|
//Parame.webBrowser.Url = Application.StartupPath + @"\html\index.html";
|
|
|
|
//开发者工具暂时只能支持Windows
|
|
|
|
//webBrowser.ShowDev();
|
|
|
|
//SetTaskStatus.Showtask();
|
|
|
|
Parame.webBrowser.LoadEnd += WebBrowser_LoadEnd;
|
|
|
|
this.Closing += MainWindow_Closing;
|
|
|
|
Parame.frm = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//关闭事件
|
|
|
|
private void MainWindow_Closing(object sender, ClosingEventArgs e)
|
|
|
|
{
|
|
|
|
MainModel.KillProcessByName("AksWebBrowser");
|
|
|
|
}
|
|
|
|
bool showDev = false;
|
|
|
|
private void WebBrowser_LoadEnd(object sender, LoadEndEventArgs e)
|
|
|
|
{
|
|
|
|
if (!showDev)
|
|
|
|
{
|
|
|
|
showDev = true;
|
|
|
|
Parame.webBrowser.ShowDev();
|
|
|
|
}
|
|
|
|
//获取设备
|
|
|
|
MainModel.GetSnIndex();
|
|
|
|
//打开高拍仪
|
|
|
|
if (MainModel.OpenSn(Parame.gpydevIndex) == "200")
|
|
|
|
{
|
|
|
|
Parame.isGPY = true;
|
|
|
|
}
|
|
|
|
//开启/关闭纠偏显示
|
|
|
|
MainModel.EnableDeskImage(1);
|
|
|
|
|
|
|
|
//开启定时
|
|
|
|
System.Timers.Timer timer = new System.Timers.Timer(1000);//3秒钟的时间间隔
|
|
|
|
timer.Elapsed += OnTimedEvent;
|
|
|
|
timer.AutoReset = true;//重复执行
|
|
|
|
timer.Enabled = true;//启动定时器
|
|
|
|
}
|
|
|
|
|
|
|
|
//矫正授权
|
|
|
|
private void OnTimedEvent(Object source, ElapsedEventArgs e)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
//获取授权
|
|
|
|
GetSQObject();
|
|
|
|
//检测服务是否启动
|
|
|
|
MainModel.StartShll();
|
|
|
|
}
|
|
|
|
catch { }
|
|
|
|
finally { }
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Writelog(string str, string dirName = @"logs")
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(str)) return;
|
|
|
|
|
|
|
|
var baseDir = AppDomain.CurrentDomain.BaseDirectory + dirName;
|
|
|
|
if (!Directory.Exists(baseDir))
|
|
|
|
{
|
|
|
|
Directory.CreateDirectory(baseDir);
|
|
|
|
}
|
|
|
|
string filePath = System.IO.Path.Combine(baseDir, DateTime.Now.ToString("yyyy-MM-dd") + "_log.txt");
|
|
|
|
using (StreamWriter sw = File.AppendText(filePath))
|
|
|
|
{
|
|
|
|
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "[" + str + "]" + "\r\n");
|
|
|
|
sw.Flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch { }
|
|
|
|
}
|
|
|
|
|
|
|
|
private void CusRequest_CusResquestEvent(CefPostData postData, CefRequest request)
|
|
|
|
{
|
|
|
|
string postParams = string.Empty;
|
|
|
|
if (postData != null)
|
|
|
|
{
|
|
|
|
//取提交的参数
|
|
|
|
CefPostData cefPostData = postData;
|
|
|
|
var elements = cefPostData.GetElements();
|
|
|
|
foreach (var element in elements)
|
|
|
|
{
|
|
|
|
if (element.ElementType == CefPostDataElementType.Bytes)
|
|
|
|
{
|
|
|
|
var bytes = element.GetBytes();
|
|
|
|
postParams = Encoding.UTF8.GetString(bytes);
|
|
|
|
//Console.WriteLine("请求参数:" + postParams);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Console.WriteLine("请求地址:" + request.Url.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
//调用JS内的JS方法
|
|
|
|
async void InvokeJS(CpfObject obj, RoutedEventArgs eventArgs)
|
|
|
|
{
|
|
|
|
var r = await Parame.webBrowser.ExecuteJavaScript("callback('调用绑定到JS里的C#方法')");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 或者可以用授权接口
|
|
|
|
/// </summary>
|
|
|
|
public void GetSQObject()
|
|
|
|
{
|
|
|
|
Task.Run(async () =>
|
|
|
|
{
|
|
|
|
var client = new HttpClient();
|
|
|
|
var request = new HttpRequestMessage(HttpMethod.Get, $"{Parame.apiUrl}/api/Interface/Getlist?Ytjbm={Parame.key}");
|
|
|
|
var response = await client.SendAsync(request);
|
|
|
|
List<Func> list = new List<Func>();
|
|
|
|
if (response.StatusCode.ToString() == "OK")
|
|
|
|
{
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
var body = await response.Content.ReadAsStringAsync();
|
|
|
|
JObject jo = (JObject)JsonConvert.DeserializeObject(body);
|
|
|
|
if (jo["IsSucceed"].ToString() == "True")
|
|
|
|
{
|
|
|
|
string result = jo["result"].ToString();
|
|
|
|
if (!string.IsNullOrEmpty("result"))
|
|
|
|
{
|
|
|
|
JArray array = (JArray)JsonConvert.DeserializeObject(result);
|
|
|
|
foreach (JObject item in array)
|
|
|
|
{
|
|
|
|
Func func = new Func()
|
|
|
|
{
|
|
|
|
Id = item["Id"].ToString(),
|
|
|
|
Platform = item["Platform"].ToString(),
|
|
|
|
Interfaceaddress = item["Interfaceaddress"].ToString(),
|
|
|
|
};
|
|
|
|
list.Add(func);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//// Log.Info("未获取授权");
|
|
|
|
//Utils.MessagesBox("未获取授权");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//// Log.Info("未获取授权");
|
|
|
|
//Utils.MessagesBox("未获取授权");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Parame.FuncObject = list;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|