@wang_qi0307 5 роки тому
батько
коміт
864d9a6e3e

+ 7 - 0
HOZ.sln

@@ -23,6 +23,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Dedicated", "Dedicated", "{
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MeasureData", "MeasureData\MeasureData.csproj", "{12617585-8D9A-4AD4-B6C4-6894A48CEE9E}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebManager", "WebManager\WebManager.csproj", "{00319B6F-FAD0-46B5-B76B-7164DC5CA0D5}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -57,6 +59,10 @@ Global
 		{12617585-8D9A-4AD4-B6C4-6894A48CEE9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{12617585-8D9A-4AD4-B6C4-6894A48CEE9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{12617585-8D9A-4AD4-B6C4-6894A48CEE9E}.Release|Any CPU.Build.0 = Release|Any CPU
+		{00319B6F-FAD0-46B5-B76B-7164DC5CA0D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{00319B6F-FAD0-46B5-B76B-7164DC5CA0D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{00319B6F-FAD0-46B5-B76B-7164DC5CA0D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{00319B6F-FAD0-46B5-B76B-7164DC5CA0D5}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -69,6 +75,7 @@ Global
 		{14C99F54-B3C2-47CF-ADB3-E79FDD2D382F} = {371F2331-83C6-41DB-8D59-9232ECB09801}
 		{5674DD32-3A9F-4D74-B177-A693A75A0255} = {371F2331-83C6-41DB-8D59-9232ECB09801}
 		{12617585-8D9A-4AD4-B6C4-6894A48CEE9E} = {371F2331-83C6-41DB-8D59-9232ECB09801}
+		{00319B6F-FAD0-46B5-B76B-7164DC5CA0D5} = {371F2331-83C6-41DB-8D59-9232ECB09801}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {F291AB01-6941-478D-BA98-1C371698FFAD}

+ 1 - 1
HOZProject/FormUnitControl.Designer.cs

@@ -978,7 +978,6 @@
             // 
             // panelSEM
             // 
-            this.panelSEM.Controls.Add(this.panelFIB);
             this.panelSEM.Controls.Add(this.btnFrozen);
             this.panelSEM.Controls.Add(this.btnLive);
             this.panelSEM.Controls.Add(this.btnAutoStig);
@@ -1038,6 +1037,7 @@
             this.panelSEM.Controls.Add(this.btnContrastSet);
             this.panelSEM.Controls.Add(this.txtContrastSet);
             this.panelSEM.Controls.Add(this.btnTiltCorr);
+            this.panelSEM.Controls.Add(this.panelFIB);
             this.panelSEM.Dock = System.Windows.Forms.DockStyle.Bottom;
             this.panelSEM.Location = new System.Drawing.Point(0, 73);
             this.panelSEM.Name = "panelSEM";

+ 0 - 2
HOZProject/FormUnitControl.cs

@@ -690,9 +690,7 @@ namespace HOZProject
             //mf.Serialize(true, doc, root);
 
             //doc.Save("test.aaa");
-            
 
-            
         }
         #endregion
 

+ 2 - 2
HOZProject/Program.cs

@@ -17,8 +17,8 @@ namespace HOZProject
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
             //Application.Run(new FormUCMain());
-            //Application.Run(new FormUnitControl());
-            Application.Run(new FormMeasureTest());
+            Application.Run(new FormUnitControl());
+            //Application.Run(new FormMeasureTest());
         }
     }
 }

+ 244 - 0
WebManager/HttpRequestHelper.cs

@@ -0,0 +1,244 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.IO.Compression;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Text.RegularExpressions;
+
+
+namespace WebManager
+{
+    /// <summary>    
+    /// Http请求封装类,用于模拟登录等操作    
+    /// 工作原理:    
+    /// 1.通过chrome的NetWork面板,跟踪到请求过程中传递的 Request Headers    
+    /// 2.将Request Headers 附加到请求。    
+    /// 3.请求成功后,将HttpResponseHeader.SetCookie记录下来。    
+    /// 4.下次请求时,附加上第3步的cookie,即可模拟登录后操作。     
+    /// </summary>    
+    public class HttpRequestHelper    
+    {        
+        /// <summary>        
+        ///     cookie集合,用于模拟登陆        
+        /// </summary>        
+        private static readonly Dictionary<string, Cookie> CookieDic = new Dictionary<string, Cookie>();         
+        
+        /// <summary>        
+        ///     Http请求        
+        /// </summary>        
+        /// <param name="url"></param>        
+        /// <param name="method"></param>        
+        /// <param name="headers"></param>        
+        /// <param name="content"></param>        
+        /// <returns></returns>        
+        public static string DoRequest(string url, string method, string headers, string content)       
+        {         
+            var request = (HttpWebRequest)WebRequest.Create(url);        
+            request.Method = method;      
+            if (method.Equals("GET", StringComparison.InvariantCultureIgnoreCase))       
+            {            
+                request.MaximumAutomaticRedirections = 100;        
+                request.AllowAutoRedirect = false;            
+            }            
+            #region 1.设置Http头部          
+            if (!string.IsNullOrWhiteSpace(headers))    
+            {           
+                var hsplit = headers.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
+                foreach (var item in hsplit)
+                {
+                    if (!item.StartsWith(":"))
+                    {
+                        var kv = item.Split(':');
+                        if (kv.Length == 2)
+                        {
+                            var key = kv[0].Trim();
+                            var value = string.Join(":", kv.Skip(1)).Trim();
+                            #region  设置http头                
+                            switch (key.ToLower())
+                            {
+                                case "accept":
+                                    {
+                                        request.Accept = value;
+                                        break;
+                                    }
+                                case "host":
+                                    {
+                                        request.Host = value;
+                                        break;
+                                    }
+                                case "connection":
+                                    {
+                                        if (value == "keep-alive")
+                                            request.KeepAlive = true;
+                                        else
+                                            request.KeepAlive = false; //just test        
+                                        break;
+                                    }
+                                case "content-type":
+                                    {
+                                        request.ContentType = value;
+                                        break;
+                                    }
+                                case "user-agent":
+                                    {
+                                        request.UserAgent = value;
+                                        break;
+                                    }
+                                case "referer":
+                                    {
+                                        request.Referer = value;
+                                        break;
+                                    }
+                                case "content-length":
+                                    {
+                                        request.ContentLength = Convert.ToInt64(value);
+                                        break;
+                                    }
+                                case "expect":
+                                    {
+                                        request.Expect = value;
+                                        break;
+                                    }
+                                case "if-modified-since":
+                                    {
+                                        request.IfModifiedSince = Convert.ToDateTime(value);
+                                        break;
+                                    }
+                                case "cookie":
+                                    {
+                                        var cc = new CookieCollection();
+                                        var cookieString = value;
+                                        if (!string.IsNullOrWhiteSpace(cookieString))
+                                        {
+                                            var spilit = cookieString.Split(';');
+                                            foreach (var ci in spilit)
+                                            {
+                                                var arr = ci.Split('=');
+                                                if (kv.Length == 2)
+                                                    cc.Add(new Cookie(arr[0].Trim(), arr[1].Trim()));
+                                            }
+                                        }
+                                    }
+                                    break;
+                            }
+                            #endregion
+                        }
+                    } 
+                }   
+            }       
+            #endregion       
+
+            #region 2.设置cookie      
+            request.Headers[HttpRequestHeader.Cookie] = GetCookieStr();         
+            #endregion    
+
+            #region 3.发送请求数据       
+            if (!string.IsNullOrWhiteSpace(content))       
+            {        
+                var data = Encoding.UTF8.GetBytes(content);     
+                request.ContentLength = data.Length;     
+                using (var stream = request.GetRequestStream())     
+                {           
+                    stream.Write(data, 0, data.Length);       
+                    stream.Close();         
+                }           
+            }        
+            #endregion       
+            
+            var response = (HttpWebResponse)request.GetResponse();   
+            
+            #region 4.保存cookie,用于下次请求      
+            //var cookies = new CookieCollection();     
+            //var s = response.Headers[HttpResponseHeader.SetCookie].Replace("HttpOnly,", "").Replace("httponly,", "");     
+            //if (!string.IsNullOrWhiteSpace(s))     
+            //{         
+            //    var spilit = s.Split(';');      
+            //    foreach (var item in spilit)      
+            //    {             
+            //        var kv = item.Split('=');         
+            //        if (kv.Length == 2)         
+            //            cookies.Add(new Cookie(kv[0].Trim(), kv[1].Trim()));      
+            //    }      
+            //}           
+            //foreach (Cookie c in cookies)      
+            //    if (CookieDic.ContainsKey(c.Name))         
+            //        CookieDic[c.Name] = c;        
+            //    else            
+            //        CookieDic.Add(c.Name, c);   
+            #endregion     
+            
+            var result = GetResponse(response);     
+            return Unicode2String(result);    
+        }      
+        
+        /// <summary>    
+        /// 将Unicode转换为中文        
+        /// </summary>        
+        /// <param name="source"></param>        
+        /// <returns></returns>        
+        public static string Unicode2String(string source)     
+        {        
+            return new Regex(@"\\u([0-9A-F]{4})", RegexOptions.IgnoreCase).Replace(         
+                source, x => string.Empty + Convert.ToChar(Convert.ToUInt16(x.Result("$1"), 16)));  
+        }       
+        /// <summary>        
+        ///     从HttpWebResponse读取响应文本        
+        /// </summary>        
+        /// <param name="response"></param>        
+        /// <returns></returns>        
+        private static string GetResponse(HttpWebResponse response)      
+        {           
+            var defaultEncode = Encoding.UTF8;     
+            var contentType = response.ContentType;      
+            if (contentType.ToLower().Contains("gb2312"))       
+                defaultEncode = Encoding.GetEncoding("gb2312");   
+            else if (contentType.ToLower().Contains("gbk"))      
+                defaultEncode = Encoding.GetEncoding("gbk");      
+            else if (contentType.ToLower().Contains("zh-cn")) defaultEncode = Encoding.GetEncoding("zh-cn");        
+            string responseBody;      
+            if (response.ContentEncoding.ToLower().Contains("gzip"))    
+                using (var stream = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress))     
+                {       
+                    using (var reader = new StreamReader(stream))        
+                    {        
+                        responseBody = reader.ReadToEnd();        
+                    }        
+                }         
+            else if (response.ContentEncoding.ToLower().Contains("deflate"))     
+                using (var stream = new DeflateStream(response.GetResponseStream(), CompressionMode.Decompress))    
+                {       
+                    using (var reader = new StreamReader(stream, defaultEncode))          
+                    {             
+                        responseBody = reader.ReadToEnd();         
+                    }       
+                }     
+            else         
+                using (var stream = response.GetResponseStream())     
+                {                
+                    using (var reader = new StreamReader(stream, defaultEncode))            
+                    {          
+                        responseBody = reader.ReadToEnd();    
+                    }       
+                }      
+            return responseBody;    
+        }      
+        
+        private static string GetCookieStr()      
+        {          
+            var sb = new StringBuilder();   
+            foreach (var item in CookieDic)     
+                if (!item.Value.Expired)     
+                {           
+                    if (sb.Length == 0)    
+                        sb.Append(item.Key).Append("=").Append(item.Value.Value);      
+                    else              
+                        sb.Append("; ").Append(item.Key).Append(" = ").Append(item.Value.Value);     
+                }
+            return sb.ToString();     
+        } 
+    }
+}
+
+

+ 36 - 0
WebManager/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("WebManager")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("WebManager")]
+[assembly: AssemblyCopyright("Copyright ©  2020")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("00319b6f-fad0-46b5-b76b-7164dc5ca0d5")]
+
+// 程序集的版本信息由下列四个值组成: 
+//
+//      主版本
+//      次版本
+//      生成号
+//      修订号
+//
+// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
+//通过使用 "*",如下所示:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 50 - 0
WebManager/WebManager.csproj

@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{00319B6F-FAD0-46B5-B76B-7164DC5CA0D5}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>WebManager</RootNamespace>
+    <AssemblyName>WebManager</AssemblyName>
+    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <Deterministic>true</Deterministic>
+    <TargetFrameworkProfile />
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>..\bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="HttpRequestHelper.cs" />
+    <Compile Include="WebResult.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>

+ 100 - 0
WebManager/WebResult.cs

@@ -0,0 +1,100 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WebManager
+{
+    public class WebResult
+    {
+        /// <summary>
+        /// 数据定义
+        /// </summary>
+        private String webServer_IP = "";
+        private String webServer_Port = "";
+        private String webServer_Path = "";
+        private String Url = "";
+        private const String Post = "Post";
+        private const String Content_Type= "Content-Type:application/json";
+
+        /// <summary>
+        /// 构造函数
+        /// </summary>
+        /// <param name="ws_ip">WebServer的IP地址</param>
+        /// <param name="ws_port">WebServer的端口号</param>
+        /// <param name="ws_path">WebServer的项目名</param>
+        public WebResult(String ws_ip,String ws_port,String ws_path)
+        {
+            this.webServer_IP = ws_ip;
+            this.webServer_Port = ws_port;
+            this.webServer_Path = ws_path;
+            //更新Web网址
+            Update_Url();
+        }
+
+        /// <summary>
+        /// 更新Web网址
+        /// </summary>
+        private void Update_Url()
+        {
+            if (this.webServer_Path.Substring(0, 1) != "/")
+            {
+                this.webServer_Path = "/" + this.webServer_Path;
+            }
+            this.Url = "http://" + this.webServer_IP + ":" + this.webServer_Port + this.webServer_Path;
+        }
+
+        /// <summary>
+        /// WebServer的IP地址
+        /// </summary>
+        public String WebServer_IP
+        {
+            //get { return this.webServer_IP; }
+            set
+            {
+                this.webServer_IP = value;
+                Update_Url();
+            }
+        }
+
+        /// <summary>
+        /// WebServer的端口号
+        /// </summary>
+        public String WebServer_Port
+        {
+            //get { return this.webServer_IP; }
+            set
+            {
+                this.webServer_Port = value;
+                Update_Url();
+            }
+        }
+
+        /// <summary>
+        /// WebServer的项目名
+        /// </summary>
+        public String WebServer_Path
+        {
+            //get { return this.webServer_IP; }
+            set
+            {
+                this.webServer_Path = value;
+                Update_Url();
+            }
+        }
+
+        public String RequestString(String postString)
+        {
+            try
+            {
+                String res = HttpRequestHelper.DoRequest(this.Url, Post, Content_Type, postString);
+                return res;
+            }
+            catch
+            {
+                return "";
+            }
+        }
+    }
+}