Эх сурвалжийг харах

针对Action进行数据解析

章政 7 жил өмнө
parent
commit
761e4eba1b

+ 1 - 1
UAS_Web/Browser.Designer.cs

@@ -35,7 +35,7 @@
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(284, 261);
+            this.ClientSize = new System.Drawing.Size(950, 541);
             this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
             this.Name = "Browser";
             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

+ 2 - 9
UAS_Web/Browser.cs

@@ -1,6 +1,5 @@
 using System;
 using System.Diagnostics;
-using System.Runtime.InteropServices;
 using System.Windows.Forms;
 using UAS_Web.tool;
 using CefSharp;
@@ -11,12 +10,6 @@ namespace UAS_Web
     public partial class Browser : Form
     {
 
-        [DllImport("User32.dll")]
-        public static extern IntPtr GetForegroundWindow();     //获取活动窗口句柄  
-
-        [DllImport("User32.dll", CharSet = CharSet.Auto)]
-        public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);   //获取线程ID  
-
         private ChromiumWebBrowser webBrowser;
 
         public Browser()
@@ -26,9 +19,9 @@ namespace UAS_Web
             string path = "http://192.168.253.6/uas_dev/jsps/vendbarcode/login.jsp";
             webBrowser = new ChromiumWebBrowser(path)
             {
-                Dock = DockStyle.Fill
+                Dock = DockStyle.Fill 
             };
-            webBrowser.RegisterJsObject("", new BoundObject(), true);
+            //webBrowser.RegisterJsObject("", new BoundObject(), true);
             webBrowser.MenuHandler = new MenuHandler();
             webBrowser.RequestHandler = new RequestHandler();
             Controls.Add(webBrowser);

+ 0 - 4
UAS_Web/UAS_Web.csproj

@@ -104,14 +104,10 @@
     </Compile>
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
-    <Compile Include="tool\BoundObject.cs" />
-    <Compile Include="tool\ExceptionTestBoundObject.cs" />
     <Compile Include="tool\FilterManager.cs" />
-    <Compile Include="tool\FormatterConverter.cs" />
     <Compile Include="tool\MenuHandler.cs" />
     <Compile Include="tool\MessageFilter.cs" />
     <Compile Include="tool\RequestHandler.cs" />
-    <Compile Include="tool\SubBoundObject.cs" />
     <EmbeddedResource Include="Browser.resx">
       <DependentUpon>Browser.cs</DependentUpon>
     </EmbeddedResource>

+ 0 - 355
UAS_Web/tool/BoundObject.cs

@@ -1,355 +0,0 @@
-using CefSharp;
-using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace UAS_Web.tool
-{
-    class BoundObject
-    {
-        public int MyProperty { get; set; }
-
-        public string MyReadOnlyProperty { get; internal set; }
-        public Type MyUnconvertibleProperty { get; set; }
-        public SubBoundObject SubObject { get; set; }
-        public ExceptionTestBoundObject ExceptionTestObject { get; set; }
-
-        public int this[int i]
-        {
-            get { return i; }
-            set { }
-        }
-
-        public uint[] MyUintArray
-        {
-            get { return new uint[] { 7, 8 }; }
-        }
-
-        public int[] MyIntArray
-        {
-            get { return new[] { 1, 2, 3, 4, 5, 6, 7, 8 }; }
-        }
-
-        public Array MyArray
-        {
-            get { return new short[] { 1, 2, 3 }; }
-        }
-
-        public byte[] MyBytes
-        {
-            get { return new byte[] { 3, 4, 5 }; }
-        }
-
-        public BoundObject()
-        {
-            MyProperty = 42;
-            MyReadOnlyProperty = "I'm immutable!";
-            IgnoredProperty = "I am an Ignored Property";
-            MyUnconvertibleProperty = GetType();
-            SubObject = new SubBoundObject();
-            ExceptionTestObject = new ExceptionTestBoundObject();
-        }
-
-        public void TestCallback(IJavascriptCallback javascriptCallback)
-        {
-            //Task.Factory.StartNew(async () =>
-            //{
-            //    using (javascriptCallback)
-            //    {
-            //        //Computer computer = new Computer();
-            //        string response = JsonConvert.SerializeObject(new
-            //        {
-            //            //cpu_id = computer.CPU_Id,
-            //            //disk_id = computer.Disk_Id,
-            //            //host_name = computer.HostName,
-            //            //networkcard = computer.NetworkCard,
-            //            //serialNumber = computer.SerialNumber_Manufacturer_Product.Item1,
-            //            //manufacturer = computer.SerialNumber_Manufacturer_Product.Item2,
-            //            //product = computer.SerialNumber_Manufacturer_Product.Item3,
-            //        });
-            //        //await javascriptCallback.ExecuteAsync(null);
-            //    }
-            //});
-            //const int taskDelay = 1500;
-            //Task.Factory.StartNew(async () =>
-            //{
-            //    await TaskEx.Delay(taskDelay);
-
-            //    using (javascriptCallback)
-            //    {
-            //        //NOTE: Classes are not supported, simple structs are
-            //        var response = new CallbackResponseStruct("This callback from C# was delayed " + taskDelay + "ms");
-            //        await javascriptCallback.ExecuteAsync(response);
-            //    }
-            //});
-        }
-
-        //public string TestCallbackFromObject(SimpleClass simpleClass)
-        //{
-        //    if (simpleClass == null)
-        //    {
-        //        return "TestCallbackFromObject dictionary param is null";
-        //    }
-
-        //    IJavascriptCallback javascriptCallback = simpleClass.Callback;
-
-        //    if (javascriptCallback == null)
-        //    {
-        //        return "callback property not found or property is not a function";
-        //    }
-
-        //    const int taskDelay = 1500;
-
-        //    TaskEx.Run(async () =>
-        //    {
-        //        await TaskEx.Delay(taskDelay);
-
-        //        if (javascriptCallback != null)
-        //        {
-        //            using (javascriptCallback)
-        //            {
-        //                await javascriptCallback.ExecuteAsync("message from C# " + simpleClass.TestString + " - " + simpleClass.SubClasses[0].PropertyOne);
-        //            }
-        //        }
-        //    });
-
-        //    return "waiting for callback execution...";
-        //}
-
-        public int EchoMyProperty()
-        {
-            return MyProperty;
-        }
-
-        public string Repeat(string str, int n)
-        {
-            string result = String.Empty;
-            for (int i = 0; i < n; i++)
-            {
-                result += str;
-            }
-            return result;
-        }
-
-        public string EchoParamOrDefault(string param = "This is the default value")
-        {
-            return param;
-        }
-
-        public void EchoVoid()
-        {
-        }
-
-        public Boolean EchoBoolean(Boolean arg0)
-        {
-            return arg0;
-        }
-
-        public Boolean? EchoNullableBoolean(Boolean? arg0)
-        {
-            return arg0;
-        }
-
-        public SByte EchoSByte(SByte arg0)
-        {
-            return arg0;
-        }
-
-        public SByte? EchoNullableSByte(SByte? arg0)
-        {
-            return arg0;
-        }
-
-        public Int16 EchoInt16(Int16 arg0)
-        {
-            return arg0;
-        }
-
-        public Int16? EchoNullableInt16(Int16? arg0)
-        {
-            return arg0;
-        }
-
-        public Int32 EchoInt32(Int32 arg0)
-        {
-            return arg0;
-        }
-
-        public Int32? EchoNullableInt32(Int32? arg0)
-        {
-            return arg0;
-        }
-
-        public Int64 EchoInt64(Int64 arg0)
-        {
-            return arg0;
-        }
-
-        public Int64? EchoNullableInt64(Int64? arg0)
-        {
-            return arg0;
-        }
-
-        public Byte EchoByte(Byte arg0)
-        {
-            return arg0;
-        }
-
-        public Byte? EchoNullableByte(Byte? arg0)
-        {
-            return arg0;
-        }
-
-        public UInt16 EchoUInt16(UInt16 arg0)
-        {
-            return arg0;
-        }
-
-        public UInt16? EchoNullableUInt16(UInt16? arg0)
-        {
-            return arg0;
-        }
-
-        public UInt32 EchoUInt32(UInt32 arg0)
-        {
-            return arg0;
-        }
-
-        public UInt32? EchoNullableUInt32(UInt32? arg0)
-        {
-            return arg0;
-        }
-
-        public UInt64 EchoUInt64(UInt64 arg0)
-        {
-            return arg0;
-        }
-
-        public UInt64? EchoNullableUInt64(UInt64? arg0)
-        {
-            return arg0;
-        }
-
-        public Single EchoSingle(Single arg0)
-        {
-            return arg0;
-        }
-
-        public Single? EchoNullableSingle(Single? arg0)
-        {
-            return arg0;
-        }
-
-        public Double EchoDouble(Double arg0)
-        {
-            return arg0;
-        }
-
-        public Double? EchoNullableDouble(Double? arg0)
-        {
-            return arg0;
-        }
-
-        public Char EchoChar(Char arg0)
-        {
-            return arg0;
-        }
-
-        public Char? EchoNullableChar(Char? arg0)
-        {
-            return arg0;
-        }
-
-        public DateTime EchoDateTime(DateTime arg0)
-        {
-            return arg0;
-        }
-
-        public DateTime? EchoNullableDateTime(DateTime? arg0)
-        {
-            return arg0;
-        }
-
-        public Decimal EchoDecimal(Decimal arg0)
-        {
-            return arg0;
-        }
-
-        public Decimal? EchoNullableDecimal(Decimal? arg0)
-        {
-            return arg0;
-        }
-
-        public String EchoString(String arg0)
-        {
-            return arg0;
-        }
-
-        // TODO: This will currently not work, as it causes a collision w/ the EchoString() method. We need to find a way around that I guess.
-        //public String echoString(String arg)
-        //{
-        //    return "Lowercase echo: " + arg;
-        //}
-
-        public String lowercaseMethod()
-        {
-            return "lowercase";
-        }
-
-        public string ReturnJsonEmployeeList()
-        {
-            return "{\"employees\":[{\"firstName\":\"John\", \"lastName\":\"Doe\"},{\"firstName\":\"Anna\", \"lastName\":\"Smith\"},{\"firstName\":\"Peter\", \"lastName\":\"Jones\"}]}";
-        }
-
-        [JavascriptIgnore]
-        public string IgnoredProperty { get; set; }
-
-        [JavascriptIgnore]
-        public string IgnoredMethod()
-        {
-            return "I am an Ignored Method";
-        }
-
-        public string ComplexParamObject(object param)
-        {
-            if (param == null)
-            {
-                return "param is null";
-            }
-            return "The param type is:" + param.GetType();
-        }
-
-        public SubBoundObject GetSubObject()
-        {
-            return SubObject;
-        }
-
-        /// <summary>
-        /// Demonstrates the use of params as an argument in a bound object
-        /// </summary>
-        /// <param name="name">Dummy Argument</param>
-        /// <param name="args">Params Argument</param>
-        public string MethodWithParams(string name, params object[] args)
-        {
-            return "Name:" + name + ";Args:" + string.Join(", ", args.ToArray());
-        }
-
-        public string MethodWithoutParams(string name, string arg2)
-        {
-            return string.Format("{0}, {1}", name, arg2);
-        }
-
-        public string MethodWithoutAnything()
-        {
-            return "Method without anything called and returned successfully.";
-        }
-
-        public string MethodWithThreeParamsOneOptionalOneArray(string name, string optionalParam = null, params object[] args)
-        {
-            return "MethodWithThreeParamsOneOptionalOneArray:" + (name ?? "No Name Specified") + " - " + (optionalParam ?? "No Optional Param Specified") + ";Args:" + string.Join(", ", args.ToArray());
-        }
-    }
-}

+ 0 - 70
UAS_Web/tool/ExceptionTestBoundObject.cs

@@ -1,70 +0,0 @@
-using CefSharp;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace UAS_Web.tool
-{
-    class ExceptionTestBoundObject
-    {
-        [DebuggerStepThrough]
-        private double DivisionByZero(int zero)
-        {
-            return 10 / zero;
-        }
-
-        [DebuggerStepThrough]
-        public double TriggerNestedExceptions()
-        {
-            try
-            {
-                try
-                {
-                    return DivisionByZero(0);
-                }
-                catch (Exception innerException)
-                {
-                    throw new InvalidOperationException("Nested Exception Invalid", innerException);
-                }
-            }
-            catch (Exception e)
-            {
-                throw new OperationCanceledException("Nested Exception Canceled", e);
-            }
-        }
-
-        [DebuggerStepThrough]
-        public int TriggerParameterException(int parameter)
-        {
-            return parameter;
-        }
-
-        public void TestCallbackException(IJavascriptCallback errorCallback, IJavascriptCallback errorCallbackResult)
-        {
-            const int taskDelay = 500;
-
-            //Task.Run(async () =>
-            //{
-            //    await TaskEx.Delay(taskDelay);
-
-            //    using (errorCallback)
-            //    {
-            //        JavascriptResponse result = await errorCallback.ExecuteAsync("This callback from C# was delayed " + taskDelay + "ms");
-            //        string resultMessage;
-            //        if (result.Success)
-            //        {
-            //            resultMessage = "Fatal: No Exception thrown in error callback";
-            //        }
-            //        else
-            //        {
-            //            resultMessage = "Exception Thrown: " + result.Message;
-            //        }
-            //        await errorCallbackResult.ExecuteAsync(resultMessage);
-            //    }
-            //});
-        }
-    }
-}

+ 22 - 6
UAS_Web/tool/FilterManager.cs

@@ -9,20 +9,36 @@ namespace UAS_Web.tool
 
         public static IResponseFilter CreateFilter(string guid)
         {
-            lock (dataList)
+            try
             {
-                var filter = new MessageFilter();
-                dataList.Add(guid, filter);
-                return filter;
+                lock (dataList)
+                {
+                    var filter = new MessageFilter();
+                    dataList.Add(guid, filter);
+                    return filter;
+                }
             }
+            catch (System.Exception e)
+            {
+                System.Console.WriteLine("插入报错" + e.Message.ToString());
+            }
+            return null;
         }
 
         public static IResponseFilter GetFileter(string guid)
         {
-            lock (dataList)
+            try
+            {
+                lock (dataList)
+                {
+                    return dataList[guid];
+                }
+            }
+            catch (System.Exception e)
             {
-                return dataList[guid];
+                System.Console.WriteLine("读取报错" + e.Message.ToString());
             }
+            return null;
         }
     }
 }

BIN
UAS_Web/tool/Fnthex32.dll


+ 0 - 93
UAS_Web/tool/FormatterConverter.cs

@@ -1,93 +0,0 @@
-using System;
-using System.Runtime.Serialization;
-
-namespace UAS_Web.tool
-{
-    class FormatterConverter : IFormatterConverter
-    {
-        public object Convert(object value, TypeCode typeCode)
-        {
-            return value;
-        }
-
-        public object Convert(object value, Type type)
-        {
-            throw new NotImplementedException();
-        }
-
-        public bool ToBoolean(object value)
-        {
-            throw new NotImplementedException();
-        }
-
-        public byte ToByte(object value)
-        {
-            throw new NotImplementedException();
-        }
-
-        public char ToChar(object value)
-        {
-            throw new NotImplementedException();
-        }
-
-        public DateTime ToDateTime(object value)
-        {
-            throw new NotImplementedException();
-        }
-
-        public decimal ToDecimal(object value)
-        {
-            throw new NotImplementedException();
-        }
-
-        public double ToDouble(object value)
-        {
-            throw new NotImplementedException();
-        }
-
-        public short ToInt16(object value)
-        {
-            throw new NotImplementedException();
-        }
-
-        public int ToInt32(object value)
-        {
-            throw new NotImplementedException();
-        }
-
-        public long ToInt64(object value)
-        {
-            throw new NotImplementedException();
-        }
-
-        public sbyte ToSByte(object value)
-        {
-            throw new NotImplementedException();
-        }
-
-        public float ToSingle(object value)
-        {
-            throw new NotImplementedException();
-        }
-
-        public string ToString(object value)
-        {
-            throw new NotImplementedException();
-        }
-
-        public ushort ToUInt16(object value)
-        {
-            throw new NotImplementedException();
-        }
-
-        public uint ToUInt32(object value)
-        {
-            throw new NotImplementedException();
-        }
-
-        public ulong ToUInt64(object value)
-        {
-            throw new NotImplementedException();
-        }
-    }
-}

+ 31 - 19
UAS_Web/tool/RequestHandler.cs

@@ -1,9 +1,5 @@
 using CefSharp;
 using System;
-using System.IO;
-using System.Runtime.Serialization;
-using System.Windows.Forms;
-using Newtonsoft.Json;
 using System.Collections.Generic;
 using System.Text.RegularExpressions;
 
@@ -14,30 +10,46 @@ namespace UAS_Web.tool
         public event Action<byte[]> NotifyMsg;
         IResponseFilter IRequestHandler.GetResourceResponseFilter(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response)
         {
-            var url = new Uri(request.Url);
-            if (url.AbsoluteUri.ToUpper().Contains(".ACTION"))
+            switch (request.Url.Substring(request.Url.LastIndexOf("/") + 1))
             {
-                var filter = FilterManager.CreateFilter(request.Identifier.ToString()) as MessageFilter;
-                //string str = System.Text.Encoding.UTF8.GetString(filter.dataAll.ToArray());
-                return filter;
+                case "default?type=printer":
+                    //MessageFilter filter = FilterManager.CreateFilter(request.Identifier.ToString()) as MessageFilter;
+                    //return filter;
+                case "zplPrint.action":
+                    MessageFilter filter = FilterManager.CreateFilter(request.Identifier.ToString()) as MessageFilter;
+                    return filter;
+                default:
+                    break;
             }
             return null;
         }
 
-        void filter_NotifyData(byte[] data)
+        void IRequestHandler.OnResourceLoadComplete(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, UrlRequestStatus status, long receivedContentLength)
         {
-            NotifyMsg?.Invoke(data);
+            switch (request.Url.Substring(request.Url.LastIndexOf("/") + 1))
+            {
+                case "default?type=printer":
+                    //MessageFilter filter = FilterManager.GetFileter(request.Identifier.ToString()) as MessageFilter;
+                    //string str = System.Text.Encoding.UTF8.GetString(filter.dataAll.ToArray());
+                    //filter_NotifyData(filter.dataAll.ToArray());
+                    //Console.WriteLine(str);
+                    break;
+                case "zplPrint.action":
+                    MessageFilter filter = FilterManager.GetFileter(request.Identifier.ToString()) as MessageFilter;
+                    string str = System.Text.Encoding.UTF8.GetString(filter.dataAll.ToArray());
+                    filter_NotifyData(filter.dataAll.ToArray());
+                    //Console.WriteLine(str);
+                    break;
+                default:
+                    break;
+            }
         }
 
-        void IRequestHandler.OnResourceLoadComplete(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, UrlRequestStatus status, long receivedContentLength)
+        void filter_NotifyData(byte[] data)
         {
-            if (request.Url.ToUpper().Contains(".ACTION"))
+            if (NotifyMsg != null)
             {
-                var filter = FilterManager.GetFileter(request.Identifier.ToString()) as MessageFilter;
-                string str = System.Text.Encoding.UTF8.GetString(filter.dataAll.ToArray());
-                Console.WriteLine(str);
-                Dictionary<string, object> dic = ToDictionary(str);
-                filter_NotifyData(filter.dataAll.ToArray());
+                NotifyMsg(data);
             }
         }
 
@@ -97,7 +109,7 @@ namespace UAS_Web.tool
 
         public void OnResourceRedirect(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, ref string newUrl)
         {
-            //Console.WriteLine("OnResourceRedirect");
+
         }
 
         bool IRequestHandler.OnResourceResponse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response)