chore: 初始化东安动力MES采集程序
This commit is contained in:
132
Common/02WebApiCall/WebApiCall/CallWebApi.SQLCommon.cs
Normal file
132
Common/02WebApiCall/WebApiCall/CallWebApi.SQLCommon.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DtWebApi
|
||||
{
|
||||
public class DataAccess
|
||||
{
|
||||
|
||||
public static bool ExecuteNonQuery(StringCollection sql, string connectionString, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "POST";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteNonQuery1";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", JsonConvert.SerializeObject(sql));
|
||||
|
||||
return new CallWebApi().InvokeWebapiBool(controlStr, actionStr, api, type, dic);
|
||||
}
|
||||
public static bool ExecuteNonQuery(string sql, string connectionString, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "POST";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteNonQuery";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
|
||||
return new CallWebApi().InvokeWebapiBool(controlStr, actionStr, api, type, dic);
|
||||
}
|
||||
|
||||
|
||||
public static bool ExecuteOutNum(string sql, string connectionString, out int count, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "POST";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteOutNum";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
|
||||
count = new CallWebApi().InvokeWebapiInt(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ExecuteDataset(string sql, string connectionString, out DataSet ds, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteDataset";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
ds = new CallWebApi().InvokeWebapiDataSet(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ExecuteDataTable(string sql, string connectionString, out DataTable dt, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteDataTable";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
dt = new CallWebApi().InvokeWebapiDataTable(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static bool ExecuteDataReader(string sql, string connectionString, out SqlDataReader dr, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteDataReader";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
dr = new CallWebApi().InvokeWebapiSqlDataReader(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ExecuteSql(string sql, string connectionString, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteSql";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
new CallWebApi().InvokeWebapiString(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
public static bool ExecuteSql(string sql, string connectionString, out DataTable dt, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteSqlDataTable";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
dt = new CallWebApi().InvokeWebapiDataTable(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
448
Common/02WebApiCall/WebApiCall/CallWebApi.cs
Normal file
448
Common/02WebApiCall/WebApiCall/CallWebApi.cs
Normal file
@@ -0,0 +1,448 @@
|
||||
using DoWhatPlc;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DtWebApi
|
||||
{
|
||||
public class OutGUID
|
||||
{
|
||||
/// <summary>
|
||||
/// 2021.10.25.LLX
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string Get_CS_GUID()
|
||||
{
|
||||
return Guid.NewGuid().ToString().ToUpper();
|
||||
}
|
||||
|
||||
}
|
||||
public partial class CallWebApi
|
||||
{
|
||||
public string InvokeWebapiString(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
string result = task.Result;
|
||||
return result;
|
||||
}
|
||||
public DataTable InvokeWebapiDataTable(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
DataTable dt = new DataTable();
|
||||
dt = JsonConvert.DeserializeObject<DataTable>(task.Result);
|
||||
return dt;
|
||||
}
|
||||
public DataSet InvokeWebapiDataSet(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
DataSet ds = new DataSet();
|
||||
try
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
ds = JsonConvert.DeserializeObject<DataSet>(task.Result);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
return ds;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public SqlDataReader InvokeWebapiSqlDataReader(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
SqlDataReader dr;
|
||||
dr = JsonConvert.DeserializeObject<SqlDataReader>(task.Result);
|
||||
return dr;
|
||||
}
|
||||
|
||||
public bool InvokeWebapiBool(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
string result = task.Result;
|
||||
return Convert.ToBoolean(result);
|
||||
}
|
||||
public int InvokeWebapiInt(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
string result = task.Result;
|
||||
return Convert.ToInt32(result);
|
||||
}
|
||||
#region WinFrom调用webapi接口通用方法
|
||||
public EngineValue InvokeWebapiEngineValue(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
//反序列化Json
|
||||
var rt = JsonConvert.DeserializeObject<EngineValue>(task.Result);
|
||||
return rt;
|
||||
}
|
||||
public ReturnValueObject InvokeWebapiReturnValueObject(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
//反序列化Json
|
||||
var rs = JsonConvert.DeserializeObject<ReturnValueString>(task.Result);
|
||||
if (rs == null) return null;
|
||||
var ro = rs.ReturnValueToObject();
|
||||
return ro;
|
||||
}
|
||||
public List<ReturnValueObject> InvokeWebapiReturnValueObjectList(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
//反序列化Json
|
||||
var rsList = JsonConvert.DeserializeObject< List < ReturnValueString > >(task.Result);
|
||||
List<ReturnValueObject> roList = new List<ReturnValueObject>();
|
||||
foreach(var rs in rsList)
|
||||
{
|
||||
var ro = rs.ReturnValueToObject();
|
||||
roList.Add(ro);
|
||||
}
|
||||
|
||||
return roList;
|
||||
}
|
||||
public void InvokeWebapiWritePLC(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
|
||||
}
|
||||
//public List<ReturnValueObject> InvokeWebapiReturnValueObjectList(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
//{
|
||||
// string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
// Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
// //反序列化Json
|
||||
// var rtList = JsonConvert.DeserializeObject<List<ReturnValueString>>(task.Result);
|
||||
|
||||
// List<ReturnValueObject> roList = new List<ReturnValueObject>();
|
||||
// foreach(var rt in rtList)
|
||||
// {
|
||||
// var ro = rt.ReturnValueToObject();
|
||||
// roList.Add(ro);
|
||||
// }
|
||||
// return roList;
|
||||
//}
|
||||
|
||||
public HashtableList InvokeWebapiHashtableList(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
//反序列化Json
|
||||
var rtList = JsonConvert.DeserializeObject<HashtableList>(task.Result);
|
||||
|
||||
return rtList;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new HashtableList();
|
||||
}
|
||||
|
||||
}
|
||||
public List<TagIDTagFormat> InvokeWebapiListTagFormat(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics=null)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
//反序列化Json
|
||||
var rtList = JsonConvert.DeserializeObject<List<TagIDTagFormat>>(task.Result);
|
||||
|
||||
return rtList;
|
||||
}
|
||||
public QualityDataSaveList InvokeWebapiQualityDataSaveList(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics = null)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
//反序列化Json
|
||||
var rtList = JsonConvert.DeserializeObject<QualityDataSaveList>(task.Result);
|
||||
|
||||
return rtList;
|
||||
}
|
||||
public List<string> InvokeWebapiListString(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
//反序列化Json
|
||||
var rtList = JsonConvert.DeserializeObject<List<string>>(task.Result);
|
||||
|
||||
return rtList;
|
||||
}
|
||||
catch(Exception err)
|
||||
{
|
||||
return new List<string>();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ConcurrentDictionary<string, TagFormat> InvokeWebapiConcurrentDictionaryTagFormat(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics = null)
|
||||
{
|
||||
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
//反序列化Json
|
||||
var rtList = JsonConvert.DeserializeObject<ConcurrentDictionary<string, TagFormat>>(task.Result);
|
||||
|
||||
return rtList;
|
||||
}
|
||||
|
||||
private async Task<string> InvokeWebapi(string url, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string result = string.Empty;
|
||||
HttpClient client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Add("authorization", "Basic YWRtaW46cGFzc3dvcmRAcmljZW50LmNvbQ==");//basic编码后授权码
|
||||
client.BaseAddress = new Uri(url);
|
||||
|
||||
client.Timeout = TimeSpan.FromSeconds(510);
|
||||
|
||||
if (type.ToLower() == "put")
|
||||
{
|
||||
HttpResponseMessage response;
|
||||
//包含复杂类型
|
||||
if (dics.Keys.Contains("input"))
|
||||
{
|
||||
if (dics != null)
|
||||
{
|
||||
foreach (var item in dics.Keys)
|
||||
{
|
||||
api = api.Replace(item, dics[item]).Replace("{", "").Replace("}", "");
|
||||
}
|
||||
}
|
||||
var contents = new StringContent(dics["input"], Encoding.UTF8, "application/json");
|
||||
response = client.PutAsync(api, contents).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
result = await response.Content.ReadAsStringAsync();
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
var content = new FormUrlEncodedContent(dics);
|
||||
response = client.PutAsync(api, content).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
result = await response.Content.ReadAsStringAsync();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else if (type.ToLower() == "post")
|
||||
{
|
||||
var content = new FormUrlEncodedContent(dics);
|
||||
|
||||
HttpResponseMessage response = client.PostAsync(api, content).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
result = await response.Content.ReadAsStringAsync();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else if (type.ToLower() == "get")
|
||||
{
|
||||
HttpResponseMessage response = client.GetAsync(api).Result;
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
result = await response.Content.ReadAsStringAsync();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
public static string Url_WebApi = System.Configuration.ConfigurationManager.AppSettings["Url_WebApi"];
|
||||
private string GetUrlWebApi(string controlStr,string actionStr,Dictionary<string,string> dic=null)
|
||||
{
|
||||
string url = Url_WebApi + "//api//" + controlStr + "//"+actionStr;
|
||||
//string url = Url_WebApi + "//api//" + controlStr+"1" + "//"+actionStr;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
if(dic!=null)
|
||||
{
|
||||
foreach (var item in dic)
|
||||
{
|
||||
string item_Value = Utils.UrlEncode(item.Value);
|
||||
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item_Value);
|
||||
i++;
|
||||
}
|
||||
if (i > 0)
|
||||
{
|
||||
url = url + "//?" + builder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
private string GetUrlWebApi(string controlStr, string actionStr)
|
||||
{
|
||||
string url = Url_WebApi + "//api//" + controlStr + "//" + actionStr;
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
#region 获取APP升级版本信息
|
||||
//public List<Versions> GetVersList()
|
||||
//{
|
||||
// string api = "";
|
||||
// List<Versions> list = new List<Versions>();
|
||||
// string url = "http://域名/api/Config/GetVersionList?ClientType=android";
|
||||
// Dictionary<string, string> dics = new Dictionary<string, string>();
|
||||
// Task<string> task = InvokeWebapi(url, api, "GET", dics);
|
||||
// string result = task.Result;
|
||||
// #region 解析结果集
|
||||
// if (result != null)
|
||||
// {
|
||||
// JObject jsonObj = null;
|
||||
// jsonObj = JObject.Parse(result);
|
||||
// DataInfo info = new DataInfo();
|
||||
// info.statusCode = Convert.ToInt32(jsonObj["statusCode"]);
|
||||
// info.message = jsonObj["message"].ToString();
|
||||
// if (info.statusCode == 1)
|
||||
// {
|
||||
// JArray jlist = JArray.Parse(jsonObj["data"].ToString());
|
||||
// for (int i = 0; i < jlist.Count; ++i) //遍历JArray
|
||||
// {
|
||||
// Versions ver = new Versions();
|
||||
// JObject tempo = JObject.Parse(jlist[i].ToString());
|
||||
// ver.VersionId = Convert.ToInt32(tempo["versionId"]);
|
||||
// ver.VersionNumber = tempo["versionNumber"].ToString();
|
||||
// ver.Description = tempo["description"].ToString();
|
||||
// ver.FilePath = tempo["filePath"].ToString();
|
||||
// ver.ClientType = tempo["clientType"].ToString();
|
||||
// ver.IsForce = Convert.ToInt32(tempo["isForce"]);
|
||||
// list.Add(ver);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// #endregion
|
||||
// return list;
|
||||
//}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class Post
|
||||
{
|
||||
public static string Postring(string url, Dictionary<string, string> dic)
|
||||
{
|
||||
string result = "";
|
||||
//url = "http://172.16.22.15:8000/" + url;
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
||||
req.Method = "POST";
|
||||
req.ContentType = "application/x-www-form-urlencoded";
|
||||
req.Proxy = null;
|
||||
|
||||
req.KeepAlive = false;
|
||||
|
||||
#region 添加Post 参数
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
foreach (var item in dic)
|
||||
{
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item.Value);
|
||||
i++;
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes(builder.ToString());
|
||||
req.ContentLength = data.Length;
|
||||
using (Stream reqStream = req.GetRequestStream())
|
||||
{
|
||||
reqStream.Write(data, 0, data.Length);
|
||||
reqStream.Close();
|
||||
}
|
||||
#endregion
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
|
||||
//获取响应内容
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
||||
{
|
||||
result = reader.ReadToEnd();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string Postring1(string url, string token, Dictionary<string, string> dic)
|
||||
{
|
||||
string results = "";
|
||||
//url = "http://172.16.22.15:8000/" + url;
|
||||
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
||||
req.Method = "POST";
|
||||
req.ContentType = "application/x-www-form-urlencoded";
|
||||
req.Headers.Add("Authorization", "Bearer " + token);
|
||||
#region 添加Post 参数
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
foreach (var item in dic)
|
||||
{
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item.Value);
|
||||
i++;
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes(builder.ToString());
|
||||
req.ContentLength = data.Length;
|
||||
try
|
||||
{
|
||||
using (Stream reqStream = req.GetRequestStream())
|
||||
{
|
||||
reqStream.Write(data, 0, data.Length);
|
||||
reqStream.Close();
|
||||
}
|
||||
#endregion
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
//获取响应内容
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
||||
{
|
||||
results = reader.ReadToEnd();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
return e.Message;
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
188
Common/02WebApiCall/WebApiCall/CallWebApiDT.SQLCommon.cs
Normal file
188
Common/02WebApiCall/WebApiCall/CallWebApiDT.SQLCommon.cs
Normal file
@@ -0,0 +1,188 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DtWebApiDT
|
||||
{
|
||||
public class PLC
|
||||
{
|
||||
public static void WritePLC(string tagID, string tagValue)
|
||||
{
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "WritePLC";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("tagID", tagID);
|
||||
dic.Add("tagValue", tagValue);
|
||||
string str = new CallWebApi().InvokeWebapiString(controlStr, actionStr, api, type, dic);
|
||||
|
||||
}
|
||||
public static string ReadPLC(string tagID)
|
||||
{
|
||||
string tagValue;
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("tagID", tagID);
|
||||
|
||||
tagValue = new CallWebApi().InvokeWebapiString(controlStr, actionStr, api, type, dic);
|
||||
return tagValue;
|
||||
}
|
||||
}
|
||||
public class DataAccess
|
||||
{
|
||||
|
||||
|
||||
public static void GetProjectCodeAndProjectName(out string ProjectCode,out string ProjectName)
|
||||
{
|
||||
ProjectCode = "";
|
||||
ProjectName = "";
|
||||
//return PP.ProjectCode + "|" + PP.ProjectName;
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "GetProjectCodeAndProjectName";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
|
||||
string str = new CallWebApi().InvokeWebapiString(controlStr, actionStr, api, type, dic);
|
||||
string[] strList = str.Split('|');
|
||||
try
|
||||
{
|
||||
ProjectCode = strList[0];
|
||||
ProjectName = strList[1];
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public static bool ExecuteNonQuery(StringCollection sql, string connectionString, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteNonQuery1";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", JsonConvert.SerializeObject(sql));
|
||||
|
||||
return new CallWebApi().InvokeWebapiBool(controlStr, actionStr, api, type, dic);
|
||||
}
|
||||
public static bool ExecuteNonQuery(string sql, string connectionString, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteNonQuery";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
|
||||
return new CallWebApi().InvokeWebapiBool(controlStr, actionStr, api, type, dic);
|
||||
}
|
||||
|
||||
|
||||
public static bool ExecuteOutNum(string sql, string connectionString, out int count, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteOutNum";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
|
||||
count = new CallWebApi().InvokeWebapiInt(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ExecuteDataset(string sql, string connectionString, out DataSet ds, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteDataset";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
|
||||
|
||||
dic.Add("sql", sql);
|
||||
ds = new CallWebApi().InvokeWebapiDataSet(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ExecuteDataTable(string sql, string connectionString, out DataTable dt, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteDataTable";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
dt = new CallWebApi().InvokeWebapiDataTable(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static bool ExecuteDataReader(string sql, string connectionString, out SqlDataReader dr, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteDataReader";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
dr = new CallWebApi().InvokeWebapiSqlDataReader(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ExecuteSql(string sql, string connectionString, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteSql";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
new CallWebApi().InvokeWebapiString(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
public static bool ExecuteSql(string sql, string connectionString, out DataTable dt, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteSqlDataTable";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
dt = new CallWebApi().InvokeWebapiDataTable(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
407
Common/02WebApiCall/WebApiCall/CallWebApiDT.cs
Normal file
407
Common/02WebApiCall/WebApiCall/CallWebApiDT.cs
Normal file
@@ -0,0 +1,407 @@
|
||||
using DoWhatPlc;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DtWebApiDT
|
||||
{
|
||||
public class OutGUID
|
||||
{
|
||||
/// <summary>
|
||||
/// 2021.10.25.LLX
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string Get_CS_GUID()
|
||||
{
|
||||
return Guid.NewGuid().ToString().ToUpper();
|
||||
}
|
||||
|
||||
}
|
||||
public class CallWebApi
|
||||
{
|
||||
|
||||
#region WinFrom调用webapi接口通用方法
|
||||
|
||||
public ReturnResult InvokeWebapiReturnResult(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
return JsonConvert.DeserializeObject<ReturnResult>(task.Result);
|
||||
}
|
||||
|
||||
public DataTable InvokeWebapiDataTable(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
DataTable dt = new DataTable();
|
||||
dt = JsonConvert.DeserializeObject<DataTable>(task.Result);
|
||||
return dt;
|
||||
}
|
||||
public DataSet InvokeWebapiDataSet(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
DataSet ds = new DataSet();
|
||||
try
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
ds = JsonConvert.DeserializeObject<DataSet>(task.Result);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
public SqlDataReader InvokeWebapiSqlDataReader(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
SqlDataReader dr;
|
||||
dr = JsonConvert.DeserializeObject<SqlDataReader>(task.Result);
|
||||
return dr;
|
||||
}
|
||||
|
||||
public Dictionary<String, String> InvokeWebapiDictionary(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
var dc = JsonConvert.DeserializeObject<Dictionary<String, String>>(task.Result);
|
||||
return dc;
|
||||
}
|
||||
public List<String> InvokeWebapiList(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
var dc = JsonConvert.DeserializeObject<List<String>>(task.Result);
|
||||
return dc;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="controlStr"></param>
|
||||
/// <param name="actionStr"></param>
|
||||
/// <param name="api"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="dics"></param>
|
||||
/// <returns>List<double[]> </returns>
|
||||
public List<double[]> InvokeWebapiListDoubleArray(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
var dc = JsonConvert.DeserializeObject<List<double[]>>(task.Result);
|
||||
return dc;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="controlStr"></param>
|
||||
/// <param name="actionStr"></param>
|
||||
/// <param name="api"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="dics"></param>
|
||||
/// <returns>List<List<double>></returns>
|
||||
public List<List<double>> InvokeWebapiListListDouble(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
var dc = JsonConvert.DeserializeObject<List<List<double>>>(task.Result);
|
||||
return dc;
|
||||
}
|
||||
public double[] InvokeWebapiDoubleArray(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
var dc = JsonConvert.DeserializeObject<double[]>(task.Result);
|
||||
return dc;
|
||||
}
|
||||
public string InvokeWebapiString(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
string result = "";
|
||||
try
|
||||
{
|
||||
result = task.Result;
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public bool InvokeWebapiBool(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
string result = task.Result;
|
||||
return Convert.ToBoolean(result);
|
||||
}
|
||||
public int InvokeWebapiInt(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
string result = task.Result;
|
||||
return Convert.ToInt32(result);
|
||||
}
|
||||
|
||||
|
||||
private async Task<string> InvokeWebapi(string url, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string result = string.Empty;
|
||||
HttpClient client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Add("authorization", "Basic YWRtaW46cGFzc3dvcmRAcmljZW50LmNvbQ==");//basic编码后授权码
|
||||
client.BaseAddress = new Uri(url);
|
||||
|
||||
client.Timeout = TimeSpan.FromSeconds(510);
|
||||
|
||||
if (type.ToLower() == "put")
|
||||
{
|
||||
HttpResponseMessage response;
|
||||
//包含复杂类型
|
||||
if (dics.Keys.Contains("input"))
|
||||
{
|
||||
if (dics != null)
|
||||
{
|
||||
foreach (var item in dics.Keys)
|
||||
{
|
||||
api = api.Replace(item, dics[item]).Replace("{", "").Replace("}", "");
|
||||
}
|
||||
}
|
||||
var contents = new StringContent(dics["input"], Encoding.UTF8, "application/json");
|
||||
response = client.PutAsync(api, contents).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
result = await response.Content.ReadAsStringAsync();
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
var content = new FormUrlEncodedContent(dics);
|
||||
response = client.PutAsync(api, content).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
result = await response.Content.ReadAsStringAsync();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else if (type.ToLower() == "post")
|
||||
{
|
||||
var content = new FormUrlEncodedContent(dics);
|
||||
|
||||
HttpResponseMessage response = client.PostAsync(api, content).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
result = await response.Content.ReadAsStringAsync();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else if (type.ToLower() == "get")
|
||||
{
|
||||
HttpResponseMessage response = client.GetAsync(api).Result;
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
result = await response.Content.ReadAsStringAsync();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
public static string Url_WebApi = System.Configuration.ConfigurationManager.AppSettings["Url_WebApiDT"];
|
||||
private string GetUrlWebApi(string controlStr, string actionStr, Dictionary<string, string> dic)
|
||||
{
|
||||
string url = Url_WebApi + "//api//" + controlStr + "//" + actionStr;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
//sql = Utils.UrlEncode(sql);
|
||||
|
||||
foreach (var item in dic)
|
||||
{
|
||||
|
||||
string item_Value = Utils.UrlEncode(item.Value);
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item_Value);
|
||||
i++;
|
||||
}
|
||||
if (i > 0)
|
||||
{
|
||||
url = url + "//?" + builder.ToString();
|
||||
}
|
||||
return url;
|
||||
}
|
||||
private string GetUrlWebApi(string controlStr, string actionStr)
|
||||
{
|
||||
string url = Url_WebApi + "//api//" + controlStr + "//" + actionStr;
|
||||
|
||||
return url;
|
||||
}
|
||||
#region 获取APP升级版本信息
|
||||
//public List<Versions> GetVersList()
|
||||
//{
|
||||
// string api = "";
|
||||
// List<Versions> list = new List<Versions>();
|
||||
// string url = "http://域名/api/Config/GetVersionList?ClientType=android";
|
||||
// Dictionary<string, string> dics = new Dictionary<string, string>();
|
||||
// Task<string> task = InvokeWebapi(url, api, "GET", dics);
|
||||
// string result = task.Result;
|
||||
// #region 解析结果集
|
||||
// if (result != null)
|
||||
// {
|
||||
// JObject jsonObj = null;
|
||||
// jsonObj = JObject.Parse(result);
|
||||
// DataInfo info = new DataInfo();
|
||||
// info.statusCode = Convert.ToInt32(jsonObj["statusCode"]);
|
||||
// info.message = jsonObj["message"].ToString();
|
||||
// if (info.statusCode == 1)
|
||||
// {
|
||||
// JArray jlist = JArray.Parse(jsonObj["data"].ToString());
|
||||
// for (int i = 0; i < jlist.Count; ++i) //遍历JArray
|
||||
// {
|
||||
// Versions ver = new Versions();
|
||||
// JObject tempo = JObject.Parse(jlist[i].ToString());
|
||||
// ver.VersionId = Convert.ToInt32(tempo["versionId"]);
|
||||
// ver.VersionNumber = tempo["versionNumber"].ToString();
|
||||
// ver.Description = tempo["description"].ToString();
|
||||
// ver.FilePath = tempo["filePath"].ToString();
|
||||
// ver.ClientType = tempo["clientType"].ToString();
|
||||
// ver.IsForce = Convert.ToInt32(tempo["isForce"]);
|
||||
// list.Add(ver);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// #endregion
|
||||
// return list;
|
||||
//}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class Post
|
||||
{
|
||||
public static string Postring(string url, Dictionary<string, string> dic)
|
||||
{
|
||||
string result = "";
|
||||
//url = "http://172.16.22.15:8000/" + url;
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
||||
req.Method = "POST";
|
||||
req.ContentType = "application/x-www-form-urlencoded";
|
||||
req.Proxy = null;
|
||||
|
||||
req.KeepAlive = false;
|
||||
|
||||
#region 添加Post 参数
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
foreach (var item in dic)
|
||||
{
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item.Value);
|
||||
i++;
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes(builder.ToString());
|
||||
req.ContentLength = data.Length;
|
||||
using (Stream reqStream = req.GetRequestStream())
|
||||
{
|
||||
reqStream.Write(data, 0, data.Length);
|
||||
reqStream.Close();
|
||||
}
|
||||
#endregion
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
|
||||
//获取响应内容
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
||||
{
|
||||
result = reader.ReadToEnd();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string Postring1(string url, string token, Dictionary<string, string> dic)
|
||||
{
|
||||
string results = "";
|
||||
//url = "http://172.16.22.15:8000/" + url;
|
||||
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
||||
req.Method = "POST";
|
||||
req.ContentType = "application/x-www-form-urlencoded";
|
||||
req.Headers.Add("Authorization", "Bearer " + token);
|
||||
#region 添加Post 参数
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
foreach (var item in dic)
|
||||
{
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item.Value);
|
||||
i++;
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes(builder.ToString());
|
||||
req.ContentLength = data.Length;
|
||||
try
|
||||
{
|
||||
using (Stream reqStream = req.GetRequestStream())
|
||||
{
|
||||
reqStream.Write(data, 0, data.Length);
|
||||
reqStream.Close();
|
||||
}
|
||||
#endregion
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
//获取响应内容
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
||||
{
|
||||
results = reader.ReadToEnd();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
return e.Message;
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
123
Common/02WebApiCall/WebApiCall/Opc.Demo.cs
Normal file
123
Common/02WebApiCall/WebApiCall/Opc.Demo.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using DoWhatPlc;
|
||||
using DtWebApi;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DtWebApi
|
||||
{
|
||||
public class OpcDemo
|
||||
{
|
||||
public static HashtableList GetHashtableList()
|
||||
{
|
||||
try
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "GetHashtableList";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
var rc = new CallWebApi().InvokeWebapiHashtableList(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
return new HashtableList();
|
||||
|
||||
}
|
||||
}
|
||||
public static List<TagIDTagFormat> ReadPLC_GroupMonitor(string opName)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC_GroupMonitor";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("opName", opName);
|
||||
var rc = new CallWebApi().InvokeWebapiListTagFormat(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
public static List<TagIDTagFormat> ReadPLC_GroupData_Qd(string opName)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC_GroupData_Qd";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("opName", opName);
|
||||
var rc = new CallWebApi().InvokeWebapiListTagFormat(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
|
||||
public static List<TagIDTagFormat> ReadPLC_GroupData(string opName)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC_GroupData";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("opName", opName);
|
||||
var rc = new CallWebApi().InvokeWebapiListTagFormat(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static List<string> Get_opNameList()
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "Get_opNameList";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiListString(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
public static List<string> Get_ipList()
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "Get_ipList";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiListString(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
|
||||
public static ConcurrentDictionary<string, TagFormat> Get_TagAdrListTagFormat(string ip, string group)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "Get_TagAdrListTagFormat";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("ip", ip);
|
||||
dic.Add("group", group);
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiConcurrentDictionaryTagFormat(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
|
||||
public static ConcurrentDictionary<string, TagFormat> ReadTagValue_tagAdrListTagFormat(string readWhat, string opOrIp)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadTagValue_tagAdrListTagFormat";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("readWhat", readWhat);
|
||||
dic.Add("opOrIp", opOrIp);
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiConcurrentDictionaryTagFormat(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
44
Common/02WebApiCall/WebApiCall/Opc.SaveData.cs
Normal file
44
Common/02WebApiCall/WebApiCall/Opc.SaveData.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using DoWhatPlc;
|
||||
using DtWebApi;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DtWebApi
|
||||
{
|
||||
public class SaveData
|
||||
{
|
||||
|
||||
public static QualityDataSaveList ReadPLC_Sync_DataList_MesRead(string opName)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC_Sync_DataList_MesRead";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("opName", opName);
|
||||
var rc = new CallWebApi().InvokeWebapiQualityDataSaveList(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
|
||||
public static object SaveQualityData_ByOnlyDataGroup(string opName, string tagID)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "SaveQualityData_ByOnlyDataGroup";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("opName", opName);
|
||||
dic.Add("tagID", tagID);
|
||||
var rc = new CallWebApi().InvokeWebapiBool(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
//SaveQualityData_ByOnlyDataGroup(string opName, string tagID)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
190
Common/02WebApiCall/WebApiCall/ReadPLC.cs
Normal file
190
Common/02WebApiCall/WebApiCall/ReadPLC.cs
Normal file
@@ -0,0 +1,190 @@
|
||||
using DoWhatPlc;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DtWebApi
|
||||
{
|
||||
public partial class ReadWritePLC
|
||||
{
|
||||
public static DataTable GetServerStatus()
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "GetServerStatus";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
return new CallWebApi().InvokeWebapiDataTable(controlStr, actionStr, api, type, dic);
|
||||
}
|
||||
//http://localhost:41186//api//PLC1//Write_TagValueByTagTypeName//?cmd=ConfirmOkGo&opName=OP020&tagValue=True
|
||||
//http://localhost:41186//api//PLC1//Read_TagValueByTagTypeName//?cmd=PalletInfo&opName=OP020
|
||||
public static object Read_TagValueByTagTypeName(string cmd, string opName)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "Read_TagValueByTagTypeName";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("cmd", cmd);
|
||||
dic.Add("opName", opName);
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiReturnValueObject(controlStr, actionStr, api, type, dic);
|
||||
if(rc.ValueType=="bool" || rc.ValueType == "boolean")
|
||||
{
|
||||
return Convert.ToInt32(rc.TagValue);
|
||||
}
|
||||
return rc.TagValue;
|
||||
}
|
||||
|
||||
public static object ReadPLC(string tagID)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("tagID", tagID);
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiReturnValueObject(controlStr, actionStr, api, type, dic);
|
||||
return rc.TagValue;
|
||||
}
|
||||
public static object ReadPLC(string tagTypeCodeID, string opName)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC_TagTypeCodeID";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("tagTypeCodeID", tagTypeCodeID);
|
||||
dic.Add("opName", opName);
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiReturnValueObject(controlStr, actionStr, api, type, dic);
|
||||
return rc.TagValue;
|
||||
}
|
||||
public static byte[] ReadByteData_Op(string OpName, string Adr, ushort Length)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadByteData_Op";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("OpName", OpName);
|
||||
dic.Add("Adr", Adr);
|
||||
dic.Add("Length", Length.ToString());
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiReturnValueObject(controlStr, actionStr, api, type, dic);
|
||||
|
||||
return JsonToByte(rc.TagValue.ToString());
|
||||
}
|
||||
|
||||
public static byte[] ReadByteData_Ip(string Ip, string Adr, ushort Length)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadByteData_Ip";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("Ip", Ip);
|
||||
dic.Add("Adr", Adr);
|
||||
dic.Add("Length", Length.ToString());
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiReturnValueObject(controlStr, actionStr, api, type, dic);
|
||||
|
||||
return JsonToByte(rc.TagValue.ToString());
|
||||
}
|
||||
|
||||
public static object WritePLC_Bytes_Op(string OpName, string Adr, byte[] bytes)
|
||||
{
|
||||
string bytesStr = ByteToJson(bytes);
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "WritePLC_Bytes_Op";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("OpName", OpName);
|
||||
dic.Add("Adr", Adr);
|
||||
dic.Add("bytes", bytesStr);
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiReturnValueObject(controlStr, actionStr, api, type, dic);
|
||||
|
||||
return rc.TagValue;
|
||||
}
|
||||
|
||||
public static object WritePLC_Bytes_Ip(string Ip, string Adr, byte[] bytes)
|
||||
{
|
||||
string bytesStr = ByteToJson(bytes);
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "WritePLC_Bytes_Ip";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("OpName", Ip);
|
||||
dic.Add("Adr", Adr);
|
||||
dic.Add("bytes", bytesStr);
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiReturnValueObject(controlStr, actionStr, api, type, dic);
|
||||
|
||||
return rc.TagValue;
|
||||
}
|
||||
static public string ByteToJson(byte[] bytes)
|
||||
{
|
||||
string convertJson = System.Text.Encoding.UTF8.GetString(bytes);
|
||||
return convertJson;
|
||||
}
|
||||
|
||||
static public byte[] JsonToByte(string strjson)
|
||||
{
|
||||
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(strjson);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
public static List<ReturnValueObject> ReadPLC(List<string> tagTypeCodeIDList, List<string> opNameList)
|
||||
{
|
||||
string tagTypeCodeID = JsonConvert.SerializeObject(tagTypeCodeIDList);
|
||||
string opName = JsonConvert.SerializeObject(opNameList);
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC_TagTypeCodeIDList";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("tagTypeCodeID", tagTypeCodeID);
|
||||
dic.Add("opName", opName);
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiReturnValueObjectList(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
|
||||
public static List<ReturnValueObject> ReadPLC_GroupData(string opName)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC_GroupData";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("opName", opName);
|
||||
|
||||
return new CallWebApi().InvokeWebapiReturnValueObjectList(controlStr, actionStr, api, type, dic);
|
||||
}
|
||||
public static ConcurrentDictionary<string, TagFormat> ReadPLC_OpName(string opName)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC_OpName";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("opName", opName);
|
||||
|
||||
return new CallWebApi().InvokeWebapiConcurrentDictionaryTagFormat(controlStr, actionStr, api, type, dic);
|
||||
}
|
||||
}
|
||||
}
|
||||
67
Common/02WebApiCall/WebApiCall/ReadWritePLCMesRead.cs
Normal file
67
Common/02WebApiCall/WebApiCall/ReadWritePLCMesRead.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using DoWhatPlc;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DtWebApi
|
||||
{
|
||||
public partial class ReadWritePLC
|
||||
{
|
||||
/// <summary>
|
||||
///<add key="9" value="EngineTypeID"/>
|
||||
///<add key = "10" value="EngineID"/>
|
||||
///<add key = "11" value="EngineType"/>
|
||||
///<add key = "80" value="PartPalletCode"/>
|
||||
///<add key = "22" value="PalletInfo"/>
|
||||
/// </summary>
|
||||
/// <param name="opName"></param>
|
||||
/// <param name="EngineTypeID">9</param>
|
||||
/// <param name="EngineType">11</param>
|
||||
/// <param name="EngineID">10</param>
|
||||
/// <param name="PartPallet_Code">80</param>
|
||||
public static void GetEngineTypeFromPLC(string opName, out int EngineTypeID, out string EngineType, out string EngineID, out int PartPallet_Code)
|
||||
{
|
||||
EngineTypeID = 0;
|
||||
EngineID = "-2";
|
||||
EngineType = "-2";
|
||||
PartPallet_Code = 0;
|
||||
|
||||
List<string> tagTypeCodeIDList = new List<string>();
|
||||
List<string> opNameList = new List<string>();
|
||||
tagTypeCodeIDList.Add("9");
|
||||
opNameList.Add(opName);
|
||||
tagTypeCodeIDList.Add("10");
|
||||
opNameList.Add(opName);
|
||||
tagTypeCodeIDList.Add("11");
|
||||
opNameList.Add(opName);
|
||||
tagTypeCodeIDList.Add("80");
|
||||
opNameList.Add(opName);
|
||||
List<ReturnValueObject> roList = ReadPLC(tagTypeCodeIDList, opNameList);
|
||||
foreach(var item in roList)
|
||||
{
|
||||
switch(item.TagTypeCodeID)
|
||||
{
|
||||
case "9":
|
||||
EngineTypeID = Convert.ToInt32( item.TagValue);
|
||||
break;
|
||||
case "10":
|
||||
EngineID = item.TagValue.ToString();
|
||||
break;
|
||||
case "11":
|
||||
EngineType = item.TagValue.ToString();
|
||||
break;
|
||||
case "80":
|
||||
PartPallet_Code = Convert.ToInt32(item.TagValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
82
Common/02WebApiCall/WebApiCall/Utils.cs
Normal file
82
Common/02WebApiCall/WebApiCall/Utils.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System.Text;
|
||||
|
||||
public static class Utils
|
||||
{
|
||||
public static string UrlEncode(this string str)
|
||||
{
|
||||
var encoding = UTF8Encoding.UTF8;
|
||||
byte[] bytes = encoding.GetBytes(str);
|
||||
int IsSafe = 0;
|
||||
int NoSafe = 0;
|
||||
for (int i = 0; i < bytes.Length; i++)
|
||||
{
|
||||
char ch = (char)bytes[i];
|
||||
if (ch == ' ')
|
||||
{
|
||||
IsSafe++;
|
||||
}
|
||||
else if (!IsSafeChar(ch))
|
||||
{
|
||||
NoSafe ++;
|
||||
}
|
||||
}
|
||||
if (IsSafe== 0 && NoSafe == 0)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
byte[] buffer = new byte[bytes.Length + (NoSafe * 2)];
|
||||
int num1 = 0;
|
||||
for (int j = 0; j < bytes.Length; j++)
|
||||
{
|
||||
byte num2 = bytes[j];
|
||||
char ch2 = (char)num2;
|
||||
if (IsSafeChar(ch2))
|
||||
{
|
||||
buffer[num1++] = num2;
|
||||
}
|
||||
else if (ch2 == ' ')
|
||||
{
|
||||
buffer[num1++] = 0x2B;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[num1++] = 0x25;
|
||||
buffer[num1++] = (byte)IntToHex((num2 >> 4) & 15);
|
||||
buffer[num1++] = (byte)IntToHex(num2 & 15);
|
||||
}
|
||||
}
|
||||
return encoding.GetString(buffer);
|
||||
}
|
||||
|
||||
private static bool IsSafeChar(char ch)
|
||||
{
|
||||
if ((((ch < 'a') || (ch > 'z')) && ((ch < 'A') || (ch > 'Z'))) && ((ch < '0') || (ch > '9')))
|
||||
{
|
||||
|
||||
switch (ch)
|
||||
{
|
||||
case '-':
|
||||
case '.':
|
||||
break; //安全字符
|
||||
case '+':
|
||||
case ',':
|
||||
return false; //非安全字符
|
||||
default: //非安全字符
|
||||
if (ch != '_')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private static char IntToHex(int n)
|
||||
{
|
||||
if (n <= 9)
|
||||
{
|
||||
return (char)(n + 0x30);
|
||||
}
|
||||
return (char)((n - 10) + 0x41);
|
||||
}
|
||||
}
|
||||
15
Common/02WebApiCall/WebApiCall/WbApi.cs
Normal file
15
Common/02WebApiCall/WebApiCall/WbApi.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WebApiCall
|
||||
{
|
||||
public class WbApi
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
129
Common/02WebApiCall/WebApiCall/WritePLC.cs
Normal file
129
Common/02WebApiCall/WebApiCall/WritePLC.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using DoWhatPlc;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DtWebApi
|
||||
{
|
||||
public partial class ReadWritePLC
|
||||
{
|
||||
// static object lockerReadWritePLC = new object();
|
||||
|
||||
public static void Write_TagValueByTagTypeID(string tagTypeCodeID, string opName, object tagValue)
|
||||
{
|
||||
//lock (lockerReadWritePLC)
|
||||
{
|
||||
var rs = new ReturnValueString("", tagValue, opName, tagTypeCodeID);
|
||||
var tagvalue = JsonConvert.SerializeObject(rs);
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "WritePLC_TagTypeCodeID";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("tagTypeCodeID", tagTypeCodeID);
|
||||
dic.Add("opName", opName);
|
||||
|
||||
ReturnValueString rv = new ReturnValueString();
|
||||
rv.TagTypeCodeID = tagTypeCodeID;
|
||||
rv.OpName = opName;
|
||||
rv.TagValue = tagValue.ToString();
|
||||
rv.ValueType = tagValue.GetType().Name.ToLower();
|
||||
dic.Add("tagValue", JsonConvert.SerializeObject(rv));
|
||||
|
||||
new CallWebApi().InvokeWebapiWritePLC(controlStr, actionStr, api, type, dic);
|
||||
}
|
||||
|
||||
}
|
||||
public static void Write_TagValueByTagID(string TagID, object tagValue)
|
||||
{
|
||||
WritePLC(TagID, tagValue);
|
||||
}
|
||||
public static void WritePLC(string tagTypeCodeID, string opName, object tagValue)
|
||||
{
|
||||
//lock (lockerReadWritePLC)
|
||||
{
|
||||
var rs = new ReturnValueString("", tagValue, opName, tagTypeCodeID);
|
||||
var tagvalue = JsonConvert.SerializeObject(rs);
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "WritePLC_TagTypeCodeID";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("tagTypeCodeID", tagTypeCodeID);
|
||||
dic.Add("opName", opName);
|
||||
|
||||
ReturnValueString rv = new ReturnValueString();
|
||||
rv.TagTypeCodeID = tagTypeCodeID;
|
||||
rv.OpName = opName;
|
||||
rv.TagValue = tagValue.ToString();
|
||||
rv.ValueType = tagValue.GetType().Name.ToLower();
|
||||
dic.Add("tagValue", JsonConvert.SerializeObject(rv));
|
||||
|
||||
|
||||
new CallWebApi().InvokeWebapiWritePLC(controlStr, actionStr, api, type, dic);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void WritePLC(string tagID, object tagValue)
|
||||
{
|
||||
//lock (lockerReadWritePLC)
|
||||
{
|
||||
var rs = new ReturnValueString(tagID, tagValue, "", "");
|
||||
var tagvalue = JsonConvert.SerializeObject(rs);
|
||||
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "WritePLC";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("tagID", tagID);
|
||||
|
||||
ReturnValueString rv = new ReturnValueString();
|
||||
rv.TagID = tagID;
|
||||
rv.TagValue = tagValue.ToString();
|
||||
rv.ValueType = tagValue.GetType().Name.ToLower();
|
||||
|
||||
dic.Add("tagValue", JsonConvert.SerializeObject(rv));
|
||||
|
||||
new CallWebApi().InvokeWebapiWritePLC(controlStr, actionStr, api, type, dic);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Write_TagValueByTagTypeName(string cmd, string opName, object tagValue)
|
||||
{
|
||||
// lock (lockerReadWritePLC)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "Write_TagValueByTagTypeName";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("cmd", cmd);
|
||||
dic.Add("opName", opName);
|
||||
|
||||
ReturnValueString rv = new ReturnValueString();
|
||||
rv.CmdPlcReadWrite = cmd;
|
||||
rv.OpName = opName;
|
||||
rv.TagValue = tagValue.ToString();
|
||||
rv.ValueType = tagValue.GetType().Name.ToLower();
|
||||
dic.Add("tagValue", JsonConvert.SerializeObject(rv)); ;
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiReturnValueObject(controlStr, actionStr, api, type, dic);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user