基线 SVN r240

SVN-Revision: r240
This commit is contained in:
cyf
2025-02-06 06:46:06 +00:00
commit ab56a9bcf7
5317 changed files with 902274 additions and 0 deletions
@@ -0,0 +1,64 @@
using Lskj.Business;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xilium.CefGlue;
namespace Lskj.Control.BrowserSetting
{
public class BsClient : CefClient
{
public FrmWebBrowser frmWebBrowser;
public int rightKeyFlag;
public event EventHandler OnCreated;
private readonly CefLifeSpanHandler lifeSpanHandler;
private readonly CefDownloadHandler downloadHandler;
private readonly CefKeyboardHandler keyboardHandler;
private readonly CefFocusHandler focusHandler;
private readonly CefRequestHandler requestHandler;
private readonly CefContextMenuHandler contextMenuHandler;
public BsClient(int RightKeyFlag = 0)
{
if (SystemInfo.Instance.BrowserRight) RightKeyFlag = 1;
lifeSpanHandler = new BsLifeSpanHandler(this);
downloadHandler = new BsDownloadHandler(this);
keyboardHandler = new BsKeyboardHandler();
focusHandler = new BsFocusHandler();
requestHandler = new BsRequestHandler();
contextMenuHandler = new BsContextMenuHandler(RightKeyFlag);
}
protected override CefLifeSpanHandler GetLifeSpanHandler()
{
return lifeSpanHandler;
}
protected override CefDownloadHandler GetDownloadHandler()
{
return downloadHandler;
}
protected override CefKeyboardHandler GetKeyboardHandler()
{
return keyboardHandler;
}
protected override CefFocusHandler GetFocusHandler()
{
return focusHandler;
}
protected override CefRequestHandler GetRequestHandler()
{
return requestHandler;
}
protected override CefContextMenuHandler GetContextMenuHandler()
{
return contextMenuHandler;
}
public void Created(CefBrowser cefBrowser)
{
if (OnCreated != null)
{
OnCreated(cefBrowser, EventArgs.Empty);
}
}
}
}
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xilium.CefGlue;
namespace Lskj.Control.BrowserSetting
{
public class BsContextMenuHandler : CefContextMenuHandler
{
private int rightKeyFlag;
public BsContextMenuHandler(int RightKeyFlag)
{
this.rightKeyFlag = RightKeyFlag;
}
protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model)
{
if (rightKeyFlag == 1)
{
model.Clear();
}
base.OnBeforeContextMenu(browser, frame, state, model);
}
}
}
@@ -0,0 +1,184 @@
using Lskj.Business.Impl;
using Lskj.Control;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using System.Windows.Forms;
using Xilium.CefGlue;
using Lskj.Control.Model;
namespace Lskj.Control.BrowserSetting
{
public class BsDownloadHandler : CefDownloadHandler
{
private BsClient BsClient;
public BsDownloadHandler(BsClient bsClient)
{
BsClient = bsClient;
}
protected override void OnBeforeDownload(CefBrowser browser, CefDownloadItem downloadItem, string suggestedName, CefBeforeDownloadCallback callback)
{
//callback.Continue(string.Empty, true);
try
{
string tipMsg = string.Empty; int vsNum = 0;
if (string.IsNullOrWhiteSpace(downloadItem.SuggestedFileName))
{
if (BsClient != null && BsClient.frmWebBrowser != null)
{
BsClient.frmWebBrowser.Invoke(new Action(() =>
{
MessageUtil.Show("当前文档类型不支持预览");
}));
}
if (BsClient != null && BsClient.frmWebBrowser != null && BsClient.frmWebBrowser.Parent != null && BsClient.frmWebBrowser.Parent.Name.Equals("previewFrm"))
{
browser.GetHost().CloseBrowser();
}
else if (BsClient != null && BsClient.frmWebBrowser != null)
{
BsClient.frmWebBrowser.LoadUrl("file:///C:/Users/asus/Desktop/errorFileNotFound.html");//加载错误异常,文件不存在
}
return;
}
string[] webpaths = Regex.Split(downloadItem.Url, "fileRoot/", RegexOptions.IgnoreCase);
string webpath = webpaths[webpaths.Length-1];
string szFilename = downloadItem.Url.Substring(downloadItem.Url.LastIndexOf('/') + 1);//简单处理文件名,实际中还需要单独处理,这里有BUG
string SzFileName = HttpUtility.UrlDecode(szFilename);
string[] szName = SzFileName.Split('/');
string fileTitle = szName[szName.Length - 1];
//downfile(e.Url, e.Filename, tempPath);
if (fileTitle.Contains("?")) fileTitle = fileTitle.Substring(0, fileTitle.LastIndexOf('?'));
DataRow rowItem = AttachImpl.GetTempletFile(fileTitle, webpath);
string topname = downloadItem.SuggestedFileName.Substring(0, downloadItem.SuggestedFileName.LastIndexOf(".") - 1);
bool isMultipleLoad = downloadItem.Url.Contains("downLoadTemp") && Regex.IsMatch(topname, @"^[+-]?\d*[.]?\d*$");
if (downloadItem.Url.StartsWith("blob"))
{
callback.Continue(string.Empty, true);
//Download(downloadItem.Url, fileTitle);
//return;
}
else if (rowItem != null || isMultipleLoad)
{
try
{
bool success = rowItem != null ? AttachImpl.CheckAttachOperation(2, "", Convert.ToInt32(rowItem["fileId"]), "", 0, out tipMsg) == 1 : isMultipleLoad;
if (success)
{
Download(downloadItem.Url, fileTitle);
return;
}
else
{
MessageBox.Show(tipMsg);
//MessageUtil.Show(tipMsg);
}
}
catch (Exception ex)
{
MessageBox.Show("下载失败!\r\n" + ex.Message);
//MessageUtil.Show("下载失败!\r\n" + ex.Message);
}
}
else
{
MessageBox.Show("未找到下载项");
}
//browser.GetHost().CloseBrowser();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
protected override void OnDownloadUpdated(CefBrowser browser, CefDownloadItem downloadItem, CefDownloadItemCallback callback)
{
//if (downloadItem.IsComplete)
//{
// MessageBox.Show("下载成功");
// if (browser.IsPopup && !browser.HasDocument)
// {
// //browser.GetHost().ParentWindowWillClose();
// browser.GetHost().CloseBrowser();
// }
//}
//downloadItem.IsComplete
//if (downloadItem.IsComplete) {
// string tipMsg = string.Empty; int vsNum = 0;
// DataRow rowItem = AttachImpl.GetTempletFile(downloadItem.SuggestedFileName);
// string topname = downloadItem.SuggestedFileName.Substring(0, downloadItem.SuggestedFileName.LastIndexOf(".") - 1);
// bool isMultipleLoad = downloadItem.Url.Contains("downLoadTemp") && Regex.IsMatch(topname, @"^[+-]?\d*[.]?\d*$");
// if (rowItem != null || isMultipleLoad)
// {
// try
// {
// bool success = rowItem != null ? AttachImpl.CheckAttachOperation(2, "", Convert.ToInt32(rowItem["fileId"]), "", 0, out tipMsg) == 1 : isMultipleLoad;
// if (success)
// {
// string szFilename = downloadItem.Url.Substring(downloadItem.Url.LastIndexOf('/') + 1);//简单处理文件名,实际中还需要单独处理,这里有BUG
// string SzFileName = HttpUtility.UrlDecode(szFilename);
// string[] szName = SzFileName.Split('/');
// //downfile(e.Url, e.Filename, tempPath);
// Download(downloadItem.Url, szName[szName.Length - 1]);
// return;
// }
// else
// {
// MessageUtil.Show(tipMsg);
// }
// }
// catch (Exception ex)
// {
// MessageUtil.Show("下载失败!\r\n" + ex.Message);
// }
// }
// else
// {
// MessageUtil.Show("未找到下载项");
// }
// //browser.GetHost().CloseBrowser();
//}
}
/// <summary>
/// <para>说明:定义服务器文件地址,含文件名。客户端接收地址及文件名由客户端自行定义</para>
/// <para>创建人:王一帆</para>
/// <para>创建日期: </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="URL">The URL.</param>
/// <param name="FileName">Name of the file.</param>
public static void Download(string URL, string FileName)
{
FrmSelectDownload frmSelectDownload = new FrmSelectDownload();
frmSelectDownload.URL = URL;
frmSelectDownload.FileName = FileName;
frmSelectDownload.Show();
//SaveFileDialog saveFileDialog = new SaveFileDialog();
//saveFileDialog.FileName = FileName;
//saveFileDialog.Title = "下载模板文件到";
//saveFileDialog.RestoreDirectory = true;
////点了保存按钮进入
//if (saveFileDialog.ShowDialog() == DialogResult.OK)
//{
// string localFilePath = System.IO.Path.GetFullPath(saveFileDialog.FileName);//获得文件路径,含文件名
// string fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1);//获取文件名,不带路径
// string FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));//获取文件路径,不带文件名
// FrmDownload frm = new FrmDownload(URL, FileName, localFilePath);
// frm.Show();
//}
}
}
}
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xilium.CefGlue;
namespace Lskj.Control.BrowserSetting
{
class BsFocusHandler : CefFocusHandler
{
protected override bool OnSetFocus(CefBrowser browser, CefFocusSource source)
{
return true;//返回 false 以允许设置焦点,或返回 true 以取消设置焦点
}
}
}
@@ -0,0 +1,71 @@
using Lskj.Business;
using Lskj.Control;
using Lskj.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Xilium.CefGlue;
namespace Lskj.Control.BrowserSetting
{
public class BsKeyboardHandler : CefKeyboardHandler
{
protected override bool OnKeyEvent(CefBrowser browser, CefKeyEvent keyEvent, IntPtr osEvent)
{
switch (keyEvent.WindowsKeyCode)
{
case 123://功能键 F12 的KeyCode
if (keyEvent.EventType.Equals(CefKeyEventType.RawKeyDown))
{
if (ERPInfo.Instance.UserName.Equals("管理员"))
{
//创建 CefWindowInfo 对象
var wi = CefWindowInfo.Create();
//开发者工具以独立窗口弹出 窗口名 DevTools
wi.SetAsPopup(IntPtr.Zero, "DevTools");
//弹出开发者工具
browser.GetHost().ShowDevTools(wi, new BsClient(), new CefBrowserSettings(), new CefPoint(0, 0));
}
}
break;
case 116://功能键 F5 的KeyCode
if (keyEvent.EventType.Equals(CefKeyEventType.RawKeyDown))
{
//刷新
browser.Reload();
}
break;
case 27:
if (keyEvent.EventType.Equals(CefKeyEventType.RawKeyDown))
{
browser.GetMainFrame().ExecuteJavaScript("{document.webkitExitFullscreen()}", browser.GetMainFrame().Url, 0);
}
break;
case 113://功能键 F2 的KeyCode
if (keyEvent.EventType.Equals(CefKeyEventType.RawKeyDown))
{
try
{
if ((SystemInfo.Instance.HiddenUrl&&ERPInfo.Instance.UserName.Equals("管理员"))|| !SystemInfo.Instance.HiddenUrl)
{
//弹出当前网址
string NUrl = browser.GetMainFrame().Url + "";
MessageBox.Show(string.Format("Url:{0}已复制到粘贴板", NUrl));
System.Windows.Forms.Clipboard.SetText(NUrl);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
break;
}
return false;
}
}
}
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xilium.CefGlue;
namespace Lskj.Control.BrowserSetting
{
public class BsLifeSpanHandler : CefLifeSpanHandler
{
private BsClient BsClient;
public BsLifeSpanHandler(BsClient bsClient)
{
BsClient = bsClient;
}
protected override void OnAfterCreated(Xilium.CefGlue.CefBrowser browser)
{
base.OnAfterCreated(browser);
BsClient.Created(browser);
}
protected override void OnBeforeClose(CefBrowser browser)
{
base.OnBeforeClose(browser);
}
}
}
@@ -0,0 +1,314 @@
using DevExpress.Utils;
using DevExpress.XtraTab;
using Lskj.Business;
using Lskj.Business.Impl;
using Lskj.Control.Model;
using Lskj.Data;
using Lskj.Model;
using Lskj.Util;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Xilium.CefGlue;
namespace Lskj.Control.BrowserSetting
{
public class BsOpenModuleHandler : CefV8Handler
{
public BsOpenModuleHandler()
{
}
protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
{
if (name == "OpenModule" && arguments.Length == 5)
{
string arg0 = arguments[0].GetStringValue();
string arg1 = arguments[1].GetStringValue();
string arg2 = arguments[2].GetStringValue();
string arg3 = arguments[3].GetStringValue();
string arg4 = arguments[4].GetStringValue();
if (ERPInfo.Instance.MainControl.InvokeRequired)
{
ERPInfo.Instance.MainControl.Invoke(new Action(() =>
{
OpenModule(arg0, arg1, arg2, arg3, arg4);
}));
}
else
{
OpenModule(arg0, arg1, arg2, arg3, arg4);
}
returnValue = CefV8Value.CreateUndefined();
exception = null;
return true;
}
else if (name == "OpenOnRightClick" && arguments.Length == 4)
{
var arrayItem = arguments[0].GetStringValue(); // Assuming arrayItem is an array or object
var rightId = arguments[1].GetStringValue();
var MenuName = arguments[2].GetStringValue();
var mMenuCode = arguments[3].GetStringValue();
if (ERPInfo.Instance.MainControl.InvokeRequired)
{
ERPInfo.Instance.MainControl.Invoke(new Action(() =>
{
OpenRightModule(arrayItem, rightId, MenuName, mMenuCode);
}));
}
else
{
OpenRightModule(arrayItem, rightId, MenuName, mMenuCode);
}
returnValue = CefV8Value.CreateUndefined();
exception = null;
return true;
}
returnValue = null;
exception = "Invalid method call";
return false;
}
/// <summary>
/// <para>说明:调用右键方法</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-18 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="arrayItem"></param>
/// <param name="rightId"></param>
/// <param name="MenuName"></param>
/// <param name="mMenuCode"></param>
public static void OpenRightModule(string arrayItem, string rightId, string MenuName, string mMenuCode)
{
DataRow item = BaseImpl.GetDataRowResult(string.Format(@"select * from P_systempopupmenu where id='{0}'", rightId));
if (item != null)
{
GridRightMenuModel menuModel = new GridRightMenuModel(item);
BaseRightMenu menu = new BaseRightMenu();
menu.Model = new DynamicModel(new string[] { MenuName, ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, "1", mMenuCode });
//DataRow[] dataRows = JsonHandler.ParseJsonArrayToDataRows(arrayItem);
//JArray jArray = (JArray)JsonConvert.DeserializeObject(arrayItem);
DataTable dataTable = JsonConvert.DeserializeObject<DataTable>(arrayItem);
if (dataTable != null && dataTable.Rows.Count > 0)
{
menu.ExecRightMenu(menuModel, dataTable.Select());
}
}
else
{
MessageUtil.Show("未找到右键id");
}
}
/// <summary>
/// <para>说明:打开模块</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-18 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="menuId">The menu identifier.</param>
/// <param name="menuName">Name of the menu.</param>
/// <param name="modelFlag">The model flag.</param>
/// <param name="
/// Params">The URL parameters.</param>
public static void OpenModule(string menuId, string menuName, string dllName, string modelFlag, string urlParams)
{
try
{
// 验证参数
if (string.IsNullOrWhiteSpace(dllName))
{
MessageUtil.Show(ResourceKeys.NotFoundMenu);
return;
}
// 验证权限
int purview = 1;
if (!string.IsNullOrEmpty(menuId))
{
// 验证权限
purview = MainImpl.GetUserPurviewsByMenuId(menuId);
if (purview == 0)
{
MessageUtil.Show(ResourceKeys.UnPurview);
return;
}
}
LogUtil.WriteDebug(urlParams + "", "操作模块", menuName, menuName);
DllModule module = new DllModule
{
DllName = ReplaceDllFileName(dllName),
Id = menuId,
Name = menuName
};
string[] args = new string[]{
menuName,
ERPInfo.Instance.UserId,
ERPInfo.Instance.UserName,
purview + "",
urlParams,
menuId
};
dllName = MainImpl.GetDefaultValue(dllName);
if (SystemInfo.Instance.SoftOpenMode)
{
foreach (XtraTabPage tablepage in ERPInfo.Instance.PageControl.TabPages)
{
if (tablepage.Text == menuName)
{
MessageUtil.Show("已设置不能打开多个相同模块!");
ERPInfo.Instance.PageControl.SelectedTabPage = tablepage;
return;
}
}
}
if (dllName.ToLower().Contains(".exe"))
{
WinHelper.WinExec(dllName);
}
else if (dllName.ToLower().IndexOf("http:", StringComparison.OrdinalIgnoreCase) != -1 ||
dllName.ToLower().IndexOf("www.", StringComparison.OrdinalIgnoreCase) != -1 ||
dllName.ToLower().IndexOf("ftp:", StringComparison.OrdinalIgnoreCase) != -1)
{
Process.Start(dllName);
}
else
{
if (dllName.ToLower().EndsWith(".lsp"))
{
//MessageBox.Show(PubUtil.AbsolutelyLibPath + dllName+" "+ menuName+" "+purview+" "+urlParams);
// 打开delphi程序
DelphiHelper.LoadDelphiDll(PubUtil.AbsolutelyLibPath + dllName, "", menuName, "", "", purview, urlParams);
}
else
{
// 打开module程序
AddModuleToTab(module, args);
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:特殊dll模块处理</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-04-20 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="dllName">Name of the DLL.</param>
/// <returns>System.String.</returns>
private static string ReplaceDllFileName(string dllName)
{
switch (dllName.ToLower().Trim())
{
case "pubspec.dll":
dllName = "Lskj.PubSpec.dll";
break;
}
return dllName;
}
/// <summary>
/// <para>说明:添加模块到tab中</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-16 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="tabMain">The tab main.</param>
/// <param name="module">The module.</param>
/// <param name="args">The arguments.</param>
public static void AddModuleToTab(DllModule module, string[] args)
{
try
{
string guid = Guid.NewGuid().ToString();
XtraTabPage tp = new XtraTabPage();
ERPInfo.Instance.selectFormModleId = module.Id;
IForm iform = FormHelper.LoadDllForm(module.DllName, args);
// 菜单打开的模块默认最大化,界面FormState设置为Normal模式,否则会出现界面不是全屏,会显示默认阴影界面
//iform.SubForm.WindowState = _frmMain.WindowState;
iform.SubForm.WindowState = FormWindowState.Normal; ;
Form form = iform.SubForm; // 表示组成应用程序的用户界面的窗口或对话框。
form.Tag = guid;
tp.Text = module.Name;
tp.Tag = guid;
// 这个必须有不然会提示:"不能向tabControl中添加顶级控件"
form.TopLevel = false;
//form.Location = new Point(0, 0);
form.Dock = DockStyle.Fill;//客户需要缩放
form.AutoSize = true;
//form.Width = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
//form.Height = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height - MinusTheHeight;
form.FormBorderStyle = FormBorderStyle.None;
tp.AutoScroll = true;
tp.Controls.Add(form);
tp.ShowCloseButton = DefaultBoolean.True;
tp.Dock = DockStyle.Fill;
//module.Tag = "1";
module.Tag = guid;
module.ModuleForm = form;
form.Show();
if (args != null && !string.IsNullOrEmpty(args[4] + ""))
{
ModuleModel moduleModel = new ModuleModel(MainImpl.GetSystemdllTab(args[4] + ""));
if (!string.IsNullOrEmpty(moduleModel.SearchCondFormModuleCode))
{
ModuleConditionsPanelEx mcpex = new ModuleConditionsPanelEx();
mcpex.InitializeControl(new ModuleModel(MainImpl.GetSystemdllTab(moduleModel.SearchCondFormModuleCode)), null, null, true);
if (StaticControl.ConditionsPanelDic.ContainsKey(args[4] + ""))
{
StaticControl.ConditionsPanelDic[args[4] + ""].Dispose();
StaticControl.ConditionsPanelDic[args[4] + ""] = mcpex;
}
else
{
StaticControl.ConditionsPanelDic.Add(args[4] + "", mcpex);
}
DialogResult dialogResult = mcpex.ShowDialog();
}
}
ERPInfo.Instance.PageControl.TabPages.Add(tp);
ERPInfo.Instance.PageControl.SelectedTabPage = tp;
ERPInfo.Instance.ModuleForms.Add(guid, module);
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(ex.InnerException != null ? ex.InnerException.Message : ex.Message);
LogHelper.Instance.WriteError(ex);
//LogUtil.WriteError("打开" + module.Name + "模块失败!", ex);
}
}
}
}
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xilium.CefGlue;
namespace Lskj.Control.BrowserSetting
{
public class BsRenderProcessHandler : CefRenderProcessHandler
{
private BsOpenModuleHandler bsOpenModuleHandler;
protected override void OnWebKitInitialized()
{
bsOpenModuleHandler = new BsOpenModuleHandler();
string extensionCode = @"
var boundObject;
if (!boundObject)
boundObject = {};
(function()
{
boundObject.OpenModule = function(menuId, menuName, dllName, modelFlag, urlParams)
{
native function OpenModule();
return OpenModule(menuId, menuName, dllName, modelFlag, urlParams);
};
boundObject.OpenOnRightClick = function(arrayItem, rightId,MenuName,mMenuCode)
{
native function OpenOnRightClick();
return OpenOnRightClick(arrayItem, rightId,MenuName,mMenuCode);
};
})();
";
CefRuntime.RegisterExtension("boundObject", extensionCode, bsOpenModuleHandler);
base.OnWebKitInitialized();
}
}
}
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xilium.CefGlue;
namespace Lskj.Control.BrowserSetting
{
public class BsRequestHandler : CefRequestHandler
{
protected override CefResourceRequestHandler GetResourceRequestHandler(CefBrowser browser, CefFrame frame, CefRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling)
{
return null;
}
protected override bool OnBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, bool userGesture, bool isRedirect)
{
//DemoApp.BrowserMessageRouter.OnBeforeBrowse(browser, frame);
return base.OnBeforeBrowse(browser, frame, request, userGesture, isRedirect);
}
protected override void OnRenderProcessTerminated(CefBrowser browser, CefTerminationStatus status)
{
//browser.StopLoad();
browser.Reload();
//DemoApp.BrowserMessageRouter.OnRenderProcessTerminated(browser);
}
}
}
@@ -0,0 +1,351 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
namespace Lskj.Control.BrowserSetting
{
public static class HttpTools
{
public enum Encode
{
Default = 0,
UTF8 = 1
}
public static CookieContainer cookie = new CookieContainer(); // 用于记录访问网页时cookie数据
public static CookieCollection cookieCollection;
private static string ContentType = string.Empty;// "application/x-www-form-urlencoded";
private static string Accept = string.Empty;//"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
private static string UserAgent = string.Empty;//"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14";
private static Encode EncodeMode = Encode.Default;
public enum Method
{
POST = 0,
GET = 1
}
public static void setting(string contentType, string accept, string userAgent, Encode encode = Encode.Default)
{
ContentType = contentType;
Accept = accept;
UserAgent = userAgent;
EncodeMode = encode;
}
/// <summary>
/// post数据到指定的网址,获取cookie数据,和返回页
/// </summary>
public static HttpWebResponse Post(string url, string postData, Dictionary<string, string> pmsDic, Dictionary<string, string> headerDic, Method method)
{
if (method == Method.POST)
{
return Post(url, postData, pmsDic, headerDic, method, out cookieCollection);
}
else
{
return Get(url, postData, pmsDic, headerDic, method, out cookieCollection);
}
}
/// <summary>
/// post数据到指定的网址,获取cookie数据,和返回页
/// </summary>
public static HttpWebResponse Post(string url, string postData, Dictionary<string, string> pmsDic, Dictionary<string, string> headerDic, Method method, out CookieCollection cookieCollection)
{
HttpWebResponse httpWebResponse = null;
try
{
HttpWebRequest httpWebRequest;
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.CookieContainer = cookie;
httpWebRequest.ContentType = ContentType;
//httpWebRequest.Referer = url;
httpWebRequest.Accept = Accept;
httpWebRequest.UserAgent = UserAgent;
httpWebRequest.Method = method == Method.POST ? "POST" : "GET";
byte[] byteRequest = null;
if (headerDic != null)
{
foreach (var item in headerDic)
{
if (item.Key.Equals("Content-Type"))
{
httpWebRequest.ContentType = item.Value;
}
else
{
httpWebRequest.Headers.Add(item.Key, item.Value);
}
}
}
if (!string.IsNullOrEmpty(postData))
{
switch (EncodeMode)
{
case Encode.Default:
byteRequest = Encoding.Default.GetBytes(postData);
break;
case Encode.UTF8:
byteRequest = Encoding.UTF8.GetBytes(postData);
break;
}
httpWebRequest.ContentLength = byteRequest.Length;
Stream stream = httpWebRequest.GetRequestStream();
stream.Write(byteRequest, 0, byteRequest.Length);
stream.Close();
}
else if (pmsDic != null)
{
StringBuilder builder = new StringBuilder();
int i = 0;
foreach (var item in pmsDic)
{
if (i > 0)
builder.Append("&");
builder.AppendFormat("{0}={1}", item.Key, item.Value);
i++;
}
switch (EncodeMode)
{
case Encode.Default:
byteRequest = Encoding.Default.GetBytes(builder.ToString());
break;
case Encode.UTF8:
byteRequest = Encoding.UTF8.GetBytes(builder.ToString());
break;
}
httpWebRequest.ContentLength = byteRequest.Length;
Stream stream = httpWebRequest.GetRequestStream();
stream.Write(byteRequest, 0, byteRequest.Length);
stream.Close();
}
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
cookieCollection = cookie.GetCookies(new Uri(url));
return httpWebResponse;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
cookieCollection = null;
return httpWebResponse;
}
}
/// <summary>
/// Get到指定的网址,获取cookie数据,和返回页
/// </summary>
public static HttpWebResponse Get(string url, string postData, Dictionary<string, string> pmsDic, Dictionary<string, string> headerDic, Method method, out CookieCollection cookieCollection)
{
HttpWebResponse httpWebResponse = null;
try
{
StringBuilder builder = new StringBuilder(url);
if (pmsDic != null && pmsDic.Count > 0)
{
builder.Append("?");
int i = 0;
foreach (var item in pmsDic)
{
if (i > 0)
builder.Append("&");
builder.AppendFormat("{0}={1}", item.Key, item.Value);
i++;
}
}
HttpWebRequest httpWebRequest;
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(builder.ToString());
httpWebRequest.CookieContainer = cookie;
httpWebRequest.ContentType = ContentType;
//httpWebRequest.Referer = url;
httpWebRequest.Accept = Accept;
httpWebRequest.UserAgent = UserAgent;
httpWebRequest.Method = method == Method.POST ? "POST" : "GET";
byte[] byteRequest = null;
if (headerDic != null)
{
foreach (var item in headerDic)
{
if (item.Key.Equals("Content-Type"))
{
httpWebRequest.ContentType = item.Value;
}
else
{
httpWebRequest.Headers.Add(item.Key, item.Value);
}
}
}
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
cookieCollection = cookie.GetCookies(new Uri(builder.ToString()));
return httpWebResponse;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
cookieCollection = null;
return httpWebResponse;
}
}
public static HttpWebResponse Post(string url, string postData, Dictionary<string, string> dic, Method method, out CookieCollection cookieCollection, out string result)
{
result = "";
HttpWebResponse httpWebResponse = null;
try
{
HttpWebRequest httpWebRequest;
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.CookieContainer = cookie;
httpWebRequest.ContentType = ContentType;
//httpWebRequest.Referer = url;
httpWebRequest.Accept = Accept;
httpWebRequest.UserAgent = UserAgent;
httpWebRequest.Method = method == Method.POST ? "POST" : "GET";
byte[] byteRequest = null;
if (!string.IsNullOrEmpty(postData))
{
switch (EncodeMode)
{
case Encode.Default:
byteRequest = Encoding.Default.GetBytes(postData);
break;
case Encode.UTF8:
byteRequest = Encoding.UTF8.GetBytes(postData);
break;
}
httpWebRequest.ContentLength = byteRequest.Length;
}
else
{
StringBuilder builder = new StringBuilder();
int i = 0;
if (dic != null)
{
foreach (var item in dic)
{
if (i > 0)
builder.Append("&");
builder.AppendFormat("{0}={1}", item.Key, item.Value);
i++;
}
}
switch (EncodeMode)
{
case Encode.Default:
byteRequest = Encoding.Default.GetBytes(builder.ToString());
break;
case Encode.UTF8:
byteRequest = Encoding.UTF8.GetBytes(builder.ToString());
break;
}
httpWebRequest.ContentLength = byteRequest.Length;
}
Stream stream = httpWebRequest.GetRequestStream();
stream.Write(byteRequest, 0, byteRequest.Length);
stream.Close();
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8);
result = streamReader.ReadToEnd();
streamReader.Close();
responseStream.Close();
cookieCollection = cookie.GetCookies(new Uri(url));
return httpWebResponse;
}
catch (Exception)
{
cookieCollection = null;
return httpWebResponse;
}
}
public static HttpWebResponse Post(string url, string postData, Dictionary<string, string> dic, Dictionary<string, string> headerDic, Method method, out CookieCollection cookieCollection, out string result)
{
result = "";
HttpWebResponse httpWebResponse = null;
try
{
HttpWebRequest httpWebRequest;
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.CookieContainer = cookie;
httpWebRequest.ContentType = ContentType;
//httpWebRequest.Referer = url;
httpWebRequest.Accept = Accept;
httpWebRequest.UserAgent = UserAgent;
httpWebRequest.Method = method == Method.POST ? "POST" : "GET";
byte[] byteRequest = null;
if (headerDic != null)
{
foreach (var item in headerDic)
{
if (item.Key.Equals("Content-Type"))
{
httpWebRequest.ContentType = item.Value;
}
else
{
httpWebRequest.Headers.Add(item.Key, item.Value);
}
}
}
if (!string.IsNullOrEmpty(postData))
{
switch (EncodeMode)
{
case Encode.Default:
byteRequest = Encoding.Default.GetBytes(postData);
break;
case Encode.UTF8:
byteRequest = Encoding.UTF8.GetBytes(postData);
break;
}
httpWebRequest.ContentLength = byteRequest.Length;
}
else
{
StringBuilder builder = new StringBuilder();
int i = 0;
if (dic != null)
{
foreach (var item in dic)
{
if (i > 0)
builder.Append("&");
builder.AppendFormat("{0}={1}", item.Key, item.Value);
i++;
}
}
switch (EncodeMode)
{
case Encode.Default:
byteRequest = Encoding.Default.GetBytes(builder.ToString());
break;
case Encode.UTF8:
byteRequest = Encoding.UTF8.GetBytes(builder.ToString());
break;
}
httpWebRequest.ContentLength = byteRequest.Length;
}
Stream stream = httpWebRequest.GetRequestStream();
stream.Write(byteRequest, 0, byteRequest.Length);
stream.Close();
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8);
result = streamReader.ReadToEnd();
streamReader.Close();
responseStream.Close();
cookie = httpWebRequest.CookieContainer;
cookieCollection = cookie.GetCookies(new Uri(url));
return httpWebResponse;
}
catch (Exception ex)
{
cookieCollection = null;
result = ex.Message;
return httpWebResponse;
}
}
}
}
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Lskj.Control.BrowserSetting
{
public class NativeMethod
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
}
}