123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794 |
- using System;
- using System.CodeDom;
- using System.CodeDom.Compiler;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Net.Http.Headers;
- using System.Reflection;
- using System.Text;
- using System.Web.Script.Serialization;
- using System.Web.Services.Description;
- using System.Xml;
- namespace BaseLibComm
- {
- /// <summary>
- /// WebService 代理类
- /// </summary>
- public class WebServiceAgent
- {
- private object agent;
- private Type agentType;
- private const string CODE_NAMESPACE = "WebServiceAgent.Dynamic";
- private static jsonVMI[] vMI;
- /// <summary<
- /// Constructor
- /// </summary<
- /// <param name="url"<</param<
- public WebServiceAgent(string url)
- {
- try
- {
- XmlTextReader reader = new XmlTextReader(url + "?wsdl");
- //建立 WSDL格式文档
- ServiceDescription sd = ServiceDescription.Read(reader);
- //客户端代理
- ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
- sdi.AddServiceDescription(sd, null, null);
- //使用CodeDom 动态编译代理类
- CodeNamespace cn = new CodeNamespace(CODE_NAMESPACE);
- CodeCompileUnit ccu = new CodeCompileUnit();
- ccu.Namespaces.Add(cn);
- sdi.Import(cn, ccu);
- Microsoft.CSharp.CSharpCodeProvider icc = new Microsoft.CSharp.CSharpCodeProvider();
- CompilerParameters cp = new CompilerParameters();
- CompilerResults cr = icc.CompileAssemblyFromDom(cp, ccu);
- agentType = cr.CompiledAssembly.GetTypes()[0];
- agent = Activator.CreateInstance(agentType);
- WriteTextLog("日志", "初始化成功", DateTime.Now);
- }
- catch (Exception ex)
- {
- WriteTextLog("错误", ex.ToString(), DateTime.Now);
- throw;
- }
- }
- ///<summary>
- ///调用指定的方法
- ///</summary>
- ///<param name="methodName">方法名</param>
- ///<param name="args">动态参数</param>
- ///<returns>返回 Web service</returns>
- public string Invoke(string methodName, string args)
- {
- try
- {
- MethodInfo mi = agentType.GetMethod(methodName);
- ParameterInfo[] arrpi = mi.GetParameters();
- var pars = args.Trim().Split(',');
- ArrayList arr = new ArrayList();
- for (int i = 0; i < pars.Length; i++)
- {
- if (arrpi[i].ParameterType != typeof(string))
- {
- arr.Add(Convert.ChangeType(pars[i], arrpi[i].ParameterType));
- }
- else
- {
- arr.Add(pars[i].Replace("#",","));
- }
- }
- object ob = this.Invoke(mi, arr.ToArray());
- WriteTextLog("日志", ob.ToString(), DateTime.Now);
- return ob.ToString();
- }
- catch (Exception ex)
- {
- WriteTextLog("错误", ex.ToString(), DateTime.Now);
- throw;
- }
- }
- /// <summary>
- /// 调用指定的方法
- /// </summary>
- /// <param name="split">分隔符号</param>
- /// <param name="methodName">方法名</param>
- /// <param name="args">动态参数</param>
- /// <returns></returns>
- public string Invoke(string split, string methodName, string args)
- {
- try
- {
- MethodInfo mi = agentType.GetMethod(methodName);
- ParameterInfo[] arrpi = mi.GetParameters();
- var pars = args.Trim().Split(new[] { split }, StringSplitOptions.None);
- ArrayList arr = new ArrayList();
- for (int i = 0; i < pars.Length; i++)
- {
- if (arrpi[i].ParameterType != typeof(string))
- {
- arr.Add(Convert.ChangeType(pars[i], arrpi[i].ParameterType));
- }
- else
- {
- arr.Add(pars[i]);
- }
- }
- object ob = this.Invoke(mi, arr.ToArray());
- WriteTextLog("日志", ob.ToString(), DateTime.Now);
- return ob.ToString();
- }
- catch (Exception ex)
- {
- WriteTextLog("错误", ex.ToString(), DateTime.Now);
- throw;
- }
- }
- ///<summary>
- ///调用方法
- ///</summary>
- ///<param name="method">方法</param>
- ///<param name="args">参数</param>
- ///<returns>返回 Web service</returns>
- public object Invoke(MethodInfo method, params object[] args)
- {
- return method.Invoke(agent, args);
- }
- public MethodInfo[] Methods
- {
- get
- {
- return agentType.GetMethods();
- }
- }
- /// <summary>
- /// 写入日志到文本文件
- /// </summary>
- /// <param name="action">动作</param>
- /// <param name="strMessage">日志内容</param>
- /// <param name="time">时间</param>
- public static void WriteTextLog(string action, string strMessage, DateTime time)
- {
- string path = AppDomain.CurrentDomain.BaseDirectory + @"NetLog\";
- if (!Directory.Exists(path))
- Directory.CreateDirectory(path);
- string fileFullPath = path + time.ToString("yyyyMMdd") + ".txt";
- StringBuilder str = new StringBuilder();
- str.Append("Time: " + time.ToString() + "\r\n");
- str.Append("Action: " + action + "\r\n");
- str.Append("Message: " + strMessage + "\r\n");
- str.Append("-----------------------------------------------------------\r\n");
- StreamWriter sw;
- if (!File.Exists(fileFullPath))
- {
- sw = File.CreateText(fileFullPath);
- }
- else
- {
- sw = File.AppendText(fileFullPath);
- }
- sw.WriteLine(str.ToString());
- sw.Close();
- }
- /// <summary>
- /// 以Post方式提交命令
- /// </summary>
- public static string Post(string apiurl, string jsonString)
- {
- return Post(apiurl, jsonString, "utf-8");
- }
- /// <summary>
- /// 以Post方式提交命令
- /// </summary>
- public static string Post(string apiurl, string jsonString, string codingName)
- {
- try
- {
- WebRequest request = WebRequest.Create(@apiurl);
- request.Method = "POST";
- request.ContentType = "application/json";
- byte[] bs = Encoding.UTF8.GetBytes(jsonString);
- request.ContentLength = bs.Length;
- Stream newStream = request.GetRequestStream();
- newStream.Write(bs, 0, bs.Length);
- newStream.Close();
- WebResponse response = request.GetResponse();
- Stream stream = response.GetResponseStream();
- StreamReader reader = new StreamReader(stream, Encoding.GetEncoding(codingName));
- string resultJson = reader.ReadToEnd();
- return resultJson;
- //string Url, string postDataStr
- //HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
- //request.Method = "POST";
- //request.ContentType = "application/x-www-form-urlencoded";
- //request.ContentLength = postDataStr.Length;
- //StreamWriter writer = new StreamWriter(request.GetRequestStream(), Encoding.ASCII);
- //writer.Write(postDataStr);
- //writer.Flush();
- //HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- //string encoding = response.ContentEncoding;
- //if (encoding == null || encoding.Length < 1)
- //{
- // encoding = "UTF-8"; //默认编码
- //}
- //StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding));
- //string retString = reader.ReadToEnd();
- //return retString;
- }
- catch (Exception ex)
- {
- WriteTextLog("错误", ex.ToString(), DateTime.Now);
- throw;
- }
- }
- public static string Post(string url)
- {
- return PostByCoding(url, "utf-8");
- }
- public static string PostByCoding(string url, string codingName)
- {
- try
- {
- WebRequest request = WebRequest.Create(@url);
- byte[] bs = Encoding.UTF8.GetBytes(string.Empty);
- request.ContentType = "application/x-www-form-urlencoded";
- request.ContentLength = bs.Length;
- request.Method = "POST";
- System.IO.Stream RequestStream = request.GetRequestStream();
- RequestStream.Write(bs, 0, bs.Length);
- RequestStream.Close();
- System.Net.WebResponse response = request.GetResponse();
- StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(codingName));
- string ReturnVal = reader.ReadToEnd();
- reader.Close();
- response.Close();
- return ReturnVal;
- }
- catch (Exception ex)
- {
- WriteTextLog("错误", ex.ToString(), DateTime.Now);
- throw;
- }
- }
- /// <summary>
- /// Get方式提交
- /// </summary>
- /// <param name="url"></param>
- /// <returns></returns>
- public static string Get(string url)
- {
- return Get(url, "utf-8");
- }
- /// <summary>
- /// 异步Get
- /// </summary>
- /// <param name="url"></param>
- /// <returns></returns>
- public static string GetByHttpClient(string url)
- {
- HttpClient httpClient = new HttpClient();
- var response = httpClient.GetAsync(url).Result;
- string msg = response.Content.ReadAsStringAsync().Result;
- return msg;
- }
- /// <summary>
- /// 异步Post
- /// </summary>
- /// <param name="url"></param>
- /// <returns></returns>
- public static string PostByHttpClient(string url, string pars)
- {
- HttpClient httpClient = new HttpClient();
- MultipartFormDataContent form = new MultipartFormDataContent();
- string[] splits = pars.Split('&');
- foreach (var item in splits)
- {
- string[] keys = item.Split('=');
- string value = string.Empty;
- if (keys.Length > 1)
- {
- value = keys[1];
- }
- form.Add(new StringContent(value), keys[0]);
- }
- var response = httpClient.PostAsync(new Uri(url), form).Result;
- string msg = response.Content.ReadAsStringAsync().Result;
- return msg;
- }
- /// <summary>
- /// 文件下载
- /// </summary>
- /// <param name="url"></param>
- /// <param name="json">json字符串</param>
- /// <param name="filePath">文件保存路径</param>
- /// <returns></returns>
- public static string DownLoadByHttpClient(string url, string json, string filePath)
- {
- try
- {
- HttpClient httpClient = new HttpClient();
- StringContent content = new StringContent(json);
- content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
- var response = httpClient.PostAsync(new Uri(url), content).Result;
- var stream = response.Content.ReadAsStreamAsync().Result;
- StreamToFile(stream, filePath);
- return filePath;
- }
- catch (Exception ex)
- {
- WriteTextLog("错误", ex.ToString(), DateTime.Now);
- return "";
- }
-
- }
- /// <summary>
- /// VMI个案开发
- /// </summary>
- /// <param name="url"></param>
- /// <param name="filePath">保存的文件夹路径</param>
- /// <returns></returns>
- public static string DownLoadForVMI(string url, string filePath)
- {
- try
- {
- if (vMI == null)
- {
- return "";
- }
- else
- {
- JavaScriptSerializer js = new JavaScriptSerializer();
- string json = js.Serialize(vMI[0]);
- string result1=DownLoadByHttpClient(url + "/" + vMI[0].image, json, filePath+ vMI[0].image);
- json=js.Serialize(vMI[1]);
- string result2=DownLoadByHttpClient(url + "/" + vMI[1].image, json, filePath + vMI[1].image);
- vMI = null;
- return result1+","+ result2;
- }
- }
- catch (Exception ex)
- {
- WriteTextLog("错误", ex.ToString(), DateTime.Now);
- throw;
- }
-
- }
- /// <summary>
- /// 将 Stream 写入文件
- /// </summary>
- public static void StreamToFile(Stream stream, string fileName)
- {
- // 把 Stream 转换成 byte[]
- byte[] bytes = new byte[stream.Length];
- stream.Read(bytes, 0, bytes.Length);
- // 设置当前流的位置为流的开始
- stream.Seek(0, SeekOrigin.Begin);
- // 把 byte[] 写入文件
- FileStream fs = new FileStream(fileName, FileMode.Create);
- BinaryWriter bw = new BinaryWriter(fs);
- bw.Write(bytes);
- bw.Close();
- fs.Close();
- }
- /// <summary>
- /// Get方式提交
- /// </summary>
- /// <param name="url"></param>
- /// <param name="codingName">utf-8</param>
- /// <returns></returns>
- public static string Get(string url, string codingName)
- {
- try
- {
- // 设置参数
- HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
- CookieContainer cookieContainer = new CookieContainer();
- request.CookieContainer = cookieContainer;
- request.AllowAutoRedirect = true;
- request.Method = "GET";
- request.ContentType = "application/json";
- request.Headers.Add("charset", codingName);
- //发送请求并获取相应回应数据
- HttpWebResponse response = request.GetResponse() as HttpWebResponse;
- //直到request.GetResponse()程序才开始向目标网页发送Post请求
- Stream responseStream = response.GetResponseStream();
- StreamReader sr = new StreamReader(responseStream, Encoding.GetEncoding(codingName));
- //返回结果网页(html)代码
- string content = sr.ReadToEnd();
- return content;
- //HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
- //request.Method = "GET";
- //request.ContentType = "text/html;charset=UTF-8";
- //HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- //Stream myResponseStream = response.GetResponseStream();
- //StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
- //string retString = myStreamReader.ReadToEnd();
- //myStreamReader.Close();
- //myResponseStream.Close();
- //return retString;
- }
- catch (Exception ex)
- {
- WriteTextLog("错误", ex.ToString(), DateTime.Now);
- throw;
- }
- }
- /// <summary>
- /// Post请求
- /// </summary>
- /// <param name="url"></param>
- /// <returns></returns>
- public static string PostData(string url, string Pars)
- {
- return PostData(url, Pars, "utf-8");
- }
- /// <summary>
- /// Post请求
- /// </summary>
- /// <param name="url"></param>
- /// <returns></returns>
- public static string PostData(string url, string Pars, string codingName)
- {
- try
- {
- WebRequest request = WebRequest.Create(@url);
- byte[] bs = Encoding.UTF8.GetBytes(Pars);
- request.ContentType = "application/x-www-form-urlencoded";
- request.ContentLength = bs.Length;
- request.Method = "POST";
- System.IO.Stream RequestStream = request.GetRequestStream();
- RequestStream.Write(bs, 0, bs.Length);
- RequestStream.Close();
- System.Net.WebResponse response = request.GetResponse();
- StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(codingName));
- string ReturnVal = reader.ReadToEnd();
- reader.Close();
- response.Close();
- return ReturnVal;
- }
- catch (Exception ex)
- {
- WriteTextLog("错误", ex.ToString(), DateTime.Now);
- throw;
- }
- }
- public static string UploadByWebClient(string url, string Pars, string fileFormName, string filePath)
- {
- return UploadByWebClient(url, Pars, filePath, "utf-8");
- }
- public static string UploadByWebClient(string url, string Pars, string fileFormName, string filePath, string codingName)
- {
- try
- {
- var webclient = new WebClient();
- NameValueCollection nvc = new NameValueCollection();
- string[] splits = Pars.Split('&');
- foreach (var item in splits)
- {
- string[] keys = item.Split('=');
- string value = string.Empty;
- if (keys.Length > 1)
- {
- value = keys[1];
- }
- nvc.Add(keys[0], value);
- }
- webclient.QueryString = nvc;
- byte[] buffer = webclient.UploadFile(url, "POST", filePath);
- var msg = Encoding.GetEncoding(codingName).GetString(buffer);
- return msg;
- }
- catch (Exception ex)
- {
- WriteTextLog("错误", ex.ToString(), DateTime.Now);
- throw;
- }
- }
- /// <summary>
- /// 上传图片
- /// </summary>
- /// <param name="url"></param>
- /// <param name="Pars"></param>
- /// <param name="fileFormName">服务端标记key(不是文件名)</param>
- /// <param name="filePath">文件路径</param>
- /// <returns></returns>
- public static string UploadPostData(string url, string Pars, string fileFormName, string filePath)
- {
- if (Directory.Exists(filePath))
- {
- filePath = Directory.GetFiles(filePath).First();
- }
- string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x");
- byte[] boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
- request.ContentType = "multipart/form-data; boundary=" + boundary;
- request.Method = "POST";
- /*wr.KeepAlive = true;
- wr.Credentials = System.Net.CredentialCache.DefaultCredentials;*/
- Stream rs = request.GetRequestStream();
- string formdataTemplate = "Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}";
- string[] splits = Pars.Split('&');
- foreach (var item in splits)
- {
- string[] keys = item.Split('=');
- string value = string.Empty;
- if (keys.Length > 1)
- {
- value = keys[1];
- }
- rs.Write(boundarybytes, 0, boundarybytes.Length);
- string formitem = string.Format(formdataTemplate, keys[0], value);
- byte[] formitembytes = System.Text.Encoding.UTF8.GetBytes(formitem);
- rs.Write(formitembytes, 0, formitembytes.Length);
- }
- if (!string.IsNullOrEmpty(filePath))
- {
- rs.Write(boundarybytes, 0, boundarybytes.Length);
- /*string headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: {2}\r\n\r\n";
- string header = string.Format(headerTemplate, fileFormName, fileFormName, "text/html");*/
- string headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n\r\n";
- string header = string.Format(headerTemplate, fileFormName, Path.GetFileName(filePath));
- byte[] headerbytes = System.Text.Encoding.UTF8.GetBytes(header);
- rs.Write(headerbytes, 0, headerbytes.Length);
- //读取图片流
- byte[] byteFile = File.ReadAllBytes(filePath);
- rs.Write(byteFile, 0, byteFile.Length);
- }
- //结束分隔标记
- byte[] endBoundary = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
- rs.Write(endBoundary, 0, endBoundary.Length);
- rs.Close();
- WebResponse response = null;
- try
- {
- response = request.GetResponse();
- Stream stream2 = response.GetResponseStream();
- StreamReader reader2 = new StreamReader(stream2);
- string msg = reader2.ReadToEnd();
- return msg;
- }
- catch (Exception ex)
- {
- if (response != null)
- {
- response.Close();
- response = null;
- }
- return ex.ToString();
- }
- finally
- {
- request = null;
- }
- }
- /// <summary>
- /// 多文件上传
- /// </summary>
- /// <param name="url"></param>
- /// <param name="pars">附加参数格式:key=value&key=value</param>
- /// <param name="fileFormName">文件key多个用逗号分开</param>
- /// <param name="filePath">文件路径多个用逗号分开</param>
- /// <returns></returns>
- public static string UploadByHttpClient(string url, string pars, string fileFormName, string filePath)
- {
- try
- {
- HttpClient httpClient = new HttpClient();
- MultipartFormDataContent form = new MultipartFormDataContent();
- if (pars.Length > 0)
- {
- string[] splits = pars.Split('&');
- foreach (var item in splits)
- {
- string[] keys = item.Split('=');
- string value = string.Empty;
- if (keys.Length > 1)
- {
- value = keys[1];
- }
- form.Add(new StringContent(value), keys[0]);
- }
- }
- string[] fileFormNames = fileFormName.Split(',');
- string[] filePaths = filePath.Split(',');
- for (int i = 0; i < fileFormNames.Length; i++)
- {
- form.Add(new ByteArrayContent(File.ReadAllBytes(filePaths[i])), fileFormNames[i], Path.GetFileName(filePaths[i]));
- }
- var response = httpClient.PostAsync(new Uri(url), form).Result;
- WriteTextLog("状态", response.ToString(), DateTime.Now);
- string msg = response.Content.ReadAsStringAsync().Result;
- return msg;
- }
- catch (Exception ex)
- {
- WriteTextLog("错误", ex.ToString(), DateTime.Now);
- throw;
- }
- }
- public static string UploadByHttpClientForVMI(string url, string pars, string fileFormName, string filePath)
- {
- try
- {
- HttpClient httpClient = new HttpClient();
- MultipartFormDataContent form = new MultipartFormDataContent();
- if (pars.Length > 0)
- {
- string[] splits = pars.Split('&');
- foreach (var item in splits)
- {
- string[] keys = item.Split('=');
- string value = string.Empty;
- if (keys.Length > 1)
- {
- value = keys[1];
- }
- form.Add(new StringContent(value), keys[0]);
- }
- }
- string[] fileFormNames = fileFormName.Split(',');
- string[] filePaths = filePath.Split(',');
- for (int i = 0; i < fileFormNames.Length; i++)
- {
- if (filePaths[i].IndexOf(":")>-0 && filePaths[i].IndexOf(".")>0)
- {
- form.Add(new ByteArrayContent(File.ReadAllBytes(filePaths[i])), fileFormNames[i], Path.GetFileName(filePaths[i]));
- }
- else
- {
- form.Add(new StringContent(filePaths[i]), fileFormNames[i]);
- }
-
- }
- var response = httpClient.PostAsync(new Uri(url), form).Result;
- string str = response.ToString();
- str = str.Substring(0,str.IndexOf("Version")-2);
- WriteTextLog("状态", str, DateTime.Now);
- string msg = response.Content.ReadAsStringAsync().Result;
-
- //[{"elapsed_time":23.23218607902527,"front_new":0,"front_old":0,"image":"HZMC18102600WD_Pre_0120181027_083248_annotated.jpg","side":"FRONT","start_time":"2018-10-29 11:25:44.423392","token":"709c3ba8cf6ef60a80e44191cf58509c"},{"back_new":0,"back_old":0,"elapsed_time":23.23218607902527,"image":"HZMC18102600WD_Pre_0220181027_083304_annotated.jpg","side":"BACK","start_time":"2018-10-29 11:25:44.423392","token":"5ad24ec9fb478beab520c354c9d9bf3c"}]
- JavaScriptSerializer js = new JavaScriptSerializer();
- List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
- try
- {
-
- vMI = js.Deserialize<jsonVMI[]>(msg);
- list = js.Deserialize<List<Dictionary<string, object>>>(msg);
- foreach (var item in list)
- {
- item.Remove("image");
- item.Remove("token");
- item.Remove("side");
- }
- }
- catch
- {
- }
- WriteTextLog("记录", str + ";" + msg, DateTime.Now);
- return str + ";"+js.Serialize(list);
- }
- catch (Exception ex)
- {
- WriteTextLog("错误", ex.ToString(), DateTime.Now);
- throw;
- }
- }
- /// <summary>
- /// VMI个案开发
- /// </summary>
- /// <param name="url"></param>
- /// <param name="fileFormName">文件key多个用逗号分开</param>
- /// <param name="filePath">文件路径多个用逗号分开</param>
- /// <returns></returns>
- public static string UploadForVMI(string url, string fileFormName, string filePath)
- {
- try
- {
- string msg = UploadByHttpClientForVMI(url, "", fileFormName, filePath);
- return msg;
- }
- catch (Exception ex)
- {
- WriteTextLog("错误", ex.ToString(), DateTime.Now);
- throw;
- }
- }
- class jsonVMI
- {
- public int decision { get; set; }
- public string image { get; set; }
- public string side { get; set; }
- public string token { get; set; }
- }
- #region 格式
- //var objJson = new
- //{
- // unit_sn = dictStrAllData["unit_sn"],
- // serials = new
- // {
- // top_case = dictStrAllData["top_case"],
- // bottom_case = dictStrAllData["bottom_case"]
- // },
- // pass = dictStrAllData["pass"],
- // input_time = dictStrAllData["input_time"],
- // output_time = dictStrAllData["output_time"],
- // data = new
- // {
- // MeasurementA = dictStrAllData["MeasurementA"],
- // MeasurementB = dictStrAllData["MeasurementB"],
- // MeasurementC = dictStrAllData["MeasurementC"],
- // sw_version = dictStrAllData["sw_version"],
- // limits_version = dictStrAllData["limits_version"],
- // },
- // limits = new
- // {
- // MeasurementA = new
- // {
- // upper_limit = dictStrAllData["upper_limit_A"],
- // lower_limit = dictStrAllData["lower_limit_A"]
- // },
- // MeasurementB = new
- // {
- // upper_limit = dictStrAllData["upper_limit_B"]
- // },
- // MeasurementC = new
- // {
- // lower_limit = dictStrAllData["lower_limit_C"]
- // }
- // },
- // attr = new
- // {
- // ATTR1 = dictStrAllData["ATTR1"],
- // ATTR2 = dictStrAllData["ATTR2"]
- // },
- // blobs = new object[]
- // {
- // new { file_name = dictStrAllData["file_name_log"] },
- // new
- // {
- // file_name = dictStrAllData["file_name_image"],
- // retention_policy= dictStrAllData["retention_policy"]
- // }
- // }
- //};
- #endregion
- }
- }
|