init: 潍柴发动机线 中央控制程序 项目首次入库
This commit is contained in:
208
SCADA/WebAPI/AnalysisMsg.cs
Normal file
208
SCADA/WebAPI/AnalysisMsg.cs
Normal file
@@ -0,0 +1,208 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SlMesDbIterface;
|
||||
using System.Net.Mail;
|
||||
using PLMTEST;
|
||||
using System.Collections;
|
||||
using System.Drawing.Imaging;
|
||||
using DataLinkMesWork;
|
||||
using MesWork;
|
||||
|
||||
|
||||
namespace WebApi
|
||||
{
|
||||
|
||||
public class msgResHeader
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务ID
|
||||
/// </summary>
|
||||
public string taskId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
/// <summary>
|
||||
/// 返回结果
|
||||
/// </summary>
|
||||
public string code
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
/// <summary>
|
||||
/// 返回消息
|
||||
/// </summary>
|
||||
public string msg
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
/// <summary>
|
||||
/// 返回消息2
|
||||
/// </summary>
|
||||
public string message
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
/// <summary>
|
||||
/// 返回结果集
|
||||
/// </summary>
|
||||
public string returnData
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
public class syncOrderReq
|
||||
{
|
||||
/// <summary>
|
||||
/// 指令类型
|
||||
/// </summary>
|
||||
public string type
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
/// <summary>
|
||||
/// 工位号
|
||||
/// </summary>
|
||||
public string opName
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
/// <summary>
|
||||
/// 数值
|
||||
/// </summary>
|
||||
public string value
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
public class AnalysisMsg
|
||||
{
|
||||
/// <summary>
|
||||
/// UUID生成
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string UuidUtil()
|
||||
{
|
||||
string result = Guid.NewGuid().ToString();
|
||||
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 重新判断是否申请上线
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static string MisFunction(string url, string str)
|
||||
{
|
||||
var result = new msgResHeader();
|
||||
result.taskId = UuidUtil();
|
||||
result.code = "0";
|
||||
result.msg = "";
|
||||
result.returnData = "";
|
||||
|
||||
string errorMessage = "";
|
||||
try
|
||||
{
|
||||
/*
|
||||
15 系统健康
|
||||
5 传递机型(AMS)
|
||||
66 允许PLC工作(AMS)
|
||||
34 发动机上线报警标志
|
||||
20 AMS保存完数据(AMS)
|
||||
112 发动机上线报警代码
|
||||
73 机型标志(AMS)
|
||||
74 变速箱总成编号(AMS)
|
||||
75 产品型号(AMS)
|
||||
116 缸体打印码
|
||||
117 订单号
|
||||
|
||||
14 系统健康(PLC)
|
||||
2 工件到位(PLC)
|
||||
43 申请零件编号(PLC)
|
||||
44 传递机型(PLC)
|
||||
63 禁用MES(PLC)
|
||||
9 机型标志(PLC)
|
||||
10 变速箱总成编号(PLC)
|
||||
11 产品型号(PLC)
|
||||
80 托盘编号(PLC)
|
||||
22 0空托盘,1合格件,2不合格件(PLC)
|
||||
19 质量数据可以读数据(PLC)
|
||||
21 质量数据工位合格标志(PLC)
|
||||
23 0正常件,1返修件(PLC)
|
||||
39 缸体打印码(PLC)
|
||||
40 订单号(PLC)
|
||||
120 上线缸体码(PLC)
|
||||
*/
|
||||
// 解析订单内容,存储数据库,根据实际业务来写
|
||||
syncOrderReq BaseData = JsonHelper.JsonDeserialize<syncOrderReq>(str);
|
||||
string OpName = BaseData.opName;
|
||||
switch (BaseData.type)
|
||||
{
|
||||
case "1": // 重新申请上线
|
||||
// 判断是否有工件到位与申请上线 与 没有MES传递机型
|
||||
int workStart = Convert.ToInt32(MesWorkForm.ReadPLC(2, OpName));
|
||||
int partLoad = Convert.ToInt32(MesWorkForm.ReadPLC(43, OpName));
|
||||
int MESEngineType = Convert.ToInt32(MesWorkForm.ReadPLC(5, OpName));
|
||||
if (workStart == 1 && partLoad == 1 && MESEngineType == 0)
|
||||
{
|
||||
// 符合条件写入 e 重新调用 申请上线
|
||||
OpcData.CustomeEvetnArgs e = new OpcData.CustomeEvetnArgs();
|
||||
//MesWorkForm.UseMisFuntion(e);
|
||||
e.TagID = 111;
|
||||
e.OpName = OpName;
|
||||
e.TagTypeID = 11;
|
||||
e.IsFirstValue = "0";
|
||||
e.TagTypeCodeID = 43;
|
||||
e.TagValue = "1";
|
||||
MesWorkForm mewForm = new MesWorkForm();
|
||||
mewForm.UseMisFuntion(e);
|
||||
|
||||
result.message = "写入数据成功";
|
||||
result.code = "200";
|
||||
result.returnData = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
result.message = "当前不满足触发条件 workStart:" + workStart + " partLoad:" + partLoad + " MESEngineType:" + MESEngineType;
|
||||
result.code = "201";
|
||||
result.returnData = "";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (errorMessage != "")
|
||||
{
|
||||
result.message = errorMessage;
|
||||
result.code = "501";
|
||||
result.returnData = "ERROR";
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
result.message = "501";
|
||||
result.msg = err.Message;
|
||||
result.returnData = "ERROR";
|
||||
}
|
||||
return JsonConvert.SerializeObject(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
39
SCADA/WebAPI/CALL_Interfalce_WebAPI.cs
Normal file
39
SCADA/WebAPI/CALL_Interfalce_WebAPI.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using MesWork;
|
||||
|
||||
namespace CentralControl
|
||||
{
|
||||
internal class CALL_Interfalce_WebAPI
|
||||
{
|
||||
public static ResponseBody_WebAPI_Boms Get_BOMs_ByWebAPI(string lineid, string productcode)
|
||||
{
|
||||
var m_msgRequest = new RequestBody_WebAPI_Boms
|
||||
{
|
||||
lineId = lineid,
|
||||
productCode = productcode
|
||||
};
|
||||
|
||||
return RequestPost_Boms_AMS_To_SAP(m_msgRequest);
|
||||
}
|
||||
public static ResponseBody_WebAPI_Boms RequestPost_Boms_AMS_To_SAP(RequestBody_WebAPI_Boms m_msg)
|
||||
{
|
||||
var demoData = JsonConvert.SerializeObject(m_msg);
|
||||
return JsonConvert.DeserializeObject<ResponseBody_WebAPI_Boms>(HttpCli.Post(MesWorkForm.WebAPI_Url_Boms, demoData));
|
||||
|
||||
//var Gen_ProductPlan = File.ReadAllText("C:\\项目\\AMS计划下达.json");
|
||||
//return JsonConvert.DeserializeObject<ResponseBody_WebAPI_Boms>(Gen_ProductPlan);
|
||||
}
|
||||
|
||||
public static ResponseBody_WebAPI_Boms RequestPost_UploadMeasureData_To_SAP(string demoData)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<ResponseBody_WebAPI_Boms>(HttpCli.Post(MesWorkForm.WebAPI_Url_Quality, demoData));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
350
SCADA/WebAPI/HttpCli.cs
Normal file
350
SCADA/WebAPI/HttpCli.cs
Normal file
@@ -0,0 +1,350 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CentralControl
|
||||
{
|
||||
public class HttpCli
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 指定Url地址使用Get 方式获取全部字符串
|
||||
/// </summary>
|
||||
/// <param name="url">请求链接地址</param>
|
||||
/// <returns></returns>
|
||||
public static string Get(string url)
|
||||
{
|
||||
string result = "";
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
try
|
||||
{
|
||||
//获取内容
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
result = reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
stream.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void GetFile(string url,string path)
|
||||
{
|
||||
WebRequest request = WebRequest.Create(url);
|
||||
WebResponse response = request.GetResponse();
|
||||
if (response.ContentType.ToLower().Length > 0)
|
||||
{
|
||||
using (Stream reader = response.GetResponseStream())
|
||||
{
|
||||
using (FileStream writer = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
|
||||
{
|
||||
byte[] buffer = new byte[1024];
|
||||
int c = 0;
|
||||
while ((c = reader.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
writer.Write(buffer, 0, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
//HttpContext
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] GetFile_Bytes(string url)
|
||||
{
|
||||
byte[] bytesAll = null;
|
||||
WebRequest request = WebRequest.Create(url);
|
||||
WebResponse response = request.GetResponse();
|
||||
if (response.ContentType.ToLower().Length > 0)
|
||||
{
|
||||
using (Stream reader = response.GetResponseStream())
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
while (true)
|
||||
{
|
||||
int sz = reader.Read(buffer, 0, 1024);
|
||||
if (sz == 0) break;
|
||||
ms.Write(buffer, 0, sz);
|
||||
}
|
||||
bytesAll = ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
//如是图片
|
||||
//System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
|
||||
|
||||
return bytesAll;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void FGHJ()
|
||||
{
|
||||
|
||||
// Create a 'WebRequest' object with the specified url.
|
||||
WebRequest myWebRequest = WebRequest.Create("http://www.contoso.com");
|
||||
|
||||
// Send the 'WebRequest' and wait for response.
|
||||
WebResponse myWebResponse = myWebRequest.GetResponse();
|
||||
|
||||
// Obtain a 'Stream' object associated with the response object.
|
||||
Stream ReceiveStream = myWebResponse.GetResponseStream();
|
||||
|
||||
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
|
||||
|
||||
// Pipe the stream to a higher level stream reader with the required encoding format.
|
||||
StreamReader readStream = new StreamReader(ReceiveStream, encode);
|
||||
Console.WriteLine("\nResponse stream received");
|
||||
Char[] read = new Char[256];
|
||||
|
||||
// Read 256 charcters at a time.
|
||||
int count = readStream.Read(read, 0, 256);
|
||||
Console.WriteLine("HTML...\r\n");
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
// Dump the 256 characters on a string and display the string onto the console.
|
||||
String str = new String(read, 0, count);
|
||||
Console.Write(str);
|
||||
count = readStream.Read(read, 0, 256);
|
||||
}
|
||||
|
||||
Console.WriteLine("");
|
||||
// Release the resources of stream object.
|
||||
readStream.Close();
|
||||
|
||||
// Release the resources of response object.
|
||||
myWebResponse.Close();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送Get请求
|
||||
/// </summary>
|
||||
/// <param name="url">地址</param>
|
||||
/// <param name="dic">请求参数定义</param>
|
||||
/// <returns></returns>
|
||||
public static string Get(string url, Dictionary<string, string> dic)
|
||||
{
|
||||
string result = "";
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.Append(url);
|
||||
if (dic.Count > 0)
|
||||
{
|
||||
builder.Append("?");
|
||||
int i = 0;
|
||||
foreach (var item in dic)
|
||||
{
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item.Value);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(builder.ToString());
|
||||
//添加参数
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
try
|
||||
{
|
||||
//获取内容
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
result = reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
stream.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 指定Post地址使用Get 方式获取全部字符串
|
||||
/// </summary>
|
||||
/// <param name="url">请求后台地址</param>
|
||||
/// <returns></returns>
|
||||
public static string Post(string url)
|
||||
{
|
||||
string result = "";
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
||||
req.Method = "POST";
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
//获取内容
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
||||
{
|
||||
result = reader.ReadToEnd();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 指定Post地址使用Get 方式获取全部字符串
|
||||
/// </summary>
|
||||
/// <param name="url">请求后台地址</param>
|
||||
/// <returns></returns>
|
||||
public static string Post(string url, Dictionary<string, string> dic)
|
||||
{
|
||||
string result = "";
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
||||
req.Method = "POST";
|
||||
req.ContentType = "application/x-www-form-urlencoded";
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 指定Post地址使用Get 方式获取全部字符串
|
||||
/// </summary>
|
||||
/// <param name="url">请求后台地址</param>
|
||||
/// <param name="content">Post提交数据内容(utf-8编码的)</param>
|
||||
/// <returns></returns>
|
||||
public static string Post(string url, string content)
|
||||
{
|
||||
string result = "";
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
||||
req.Headers.Add("token", "factory2"); //如果接口需要鉴权, 把"token"换成自己需要的
|
||||
req.Method = "POST";
|
||||
req.ContentType = "application/json";
|
||||
|
||||
#region 添加Post 参数
|
||||
byte[] data = Encoding.UTF8.GetBytes(content);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Http下载文件
|
||||
/// </summary>
|
||||
/// <param name="uri">下载地址</param>
|
||||
/// <param name="filefullpath">存放完整路径(含文件名)</param>
|
||||
/// <param name="size">每次多的大小</param>
|
||||
/// <returns>下载操作是否成功</returns>
|
||||
|
||||
public static bool DownLoadFiles(string uri, string filefullpath, int size = 1000000)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(filefullpath))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(filefullpath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
string fileDirectory = System.IO.Path.GetDirectoryName(filefullpath);
|
||||
|
||||
if (!Directory.Exists(fileDirectory))
|
||||
{
|
||||
Directory.CreateDirectory(fileDirectory);
|
||||
}
|
||||
|
||||
FileStream fs = new FileStream(filefullpath, FileMode.Create);
|
||||
|
||||
byte[] buffer = new byte[size];
|
||||
|
||||
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
|
||||
|
||||
request.Timeout = 100000;
|
||||
|
||||
request.AddRange((int)fs.Length);
|
||||
|
||||
Stream ns = request.GetResponse().GetResponseStream();
|
||||
|
||||
long contentLength = request.GetResponse().ContentLength;
|
||||
|
||||
int length = ns.Read(buffer, 0, buffer.Length);
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
fs.Write(buffer,0 , length);
|
||||
buffer = new byte[size];
|
||||
length = ns.Read(buffer, 0, buffer.Length);
|
||||
}
|
||||
|
||||
fs.Close();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
52
SCADA/WebAPI/IOrderController.cs
Normal file
52
SCADA/WebAPI/IOrderController.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using System.Collections.Concurrent;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Threading;
|
||||
using SlMesDbIterface;
|
||||
using PLMTEST;
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using System.IO;
|
||||
using ExternalDataSync;
|
||||
|
||||
|
||||
/////http://127.0.0.1:9981/api/IOrder/InsertOrder
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
namespace WebApi
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[RoutePrefix("api/IOrder")]
|
||||
public class IOrderController : ApiController
|
||||
{
|
||||
readonly string headUrl = "IOrder/";
|
||||
|
||||
/// <summary>
|
||||
/// 生产工单下发
|
||||
/// </summary>
|
||||
/// <param name="jobj"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public HttpResponseMessage MisFunction([FromBody] JObject jobj)
|
||||
{
|
||||
return new HttpResponseMessage
|
||||
{
|
||||
Content = new StringContent(AnalysisMsg.MisFunction(headUrl + System.Reflection.MethodBase.GetCurrentMethod().Name, jobj.ToString()), Encoding.GetEncoding("UTF-8"), "application/json")
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
151
SCADA/WebAPI/InitServer.cs
Normal file
151
SCADA/WebAPI/InitServer.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.Cors;
|
||||
using System.Web.Http.SelfHost;
|
||||
|
||||
namespace WebApi
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class InitServer
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
HttpSelfHostConfiguration config = null;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
HttpSelfHostServer server = null;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="port"></param>
|
||||
public InitServer(int port)
|
||||
{
|
||||
config = new HttpSelfHostConfiguration($"http://0.0.0.0:{port}");
|
||||
|
||||
config.EnableCors(new EnableCorsAttribute("*", "*", "*"));
|
||||
|
||||
config.MapHttpAttributeRoutes();
|
||||
|
||||
//config.Routes.MapHttpRoute(
|
||||
// name: "DefaultApi",
|
||||
// routeTemplate: "api/{controller}/{id}",
|
||||
// defaults: new { id = RouteParameter.Optional }
|
||||
//);
|
||||
|
||||
// 自定义路由匹配到action
|
||||
config.Routes.MapHttpRoute(
|
||||
name: "API Default",
|
||||
routeTemplate: "api/{controller}/{action}/{id}",
|
||||
defaults: new { id = RouteParameter.Optional }
|
||||
);
|
||||
|
||||
server = new HttpSelfHostServer(config);
|
||||
|
||||
server.OpenAsync().Wait();
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="port"></param>
|
||||
public void Init(int port)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
public void Close()
|
||||
{
|
||||
server.CloseAsync();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class JsonContentNegotiator : IContentNegotiator
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private readonly JsonMediaTypeFormatter _jsonFormatter;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="formatter"></param>
|
||||
public JsonContentNegotiator(JsonMediaTypeFormatter formatter)
|
||||
{
|
||||
_jsonFormatter = formatter;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="formatters"></param>
|
||||
/// <returns></returns>
|
||||
public ContentNegotiationResult Negotiate(Type type, HttpRequestMessage request, IEnumerable<MediaTypeFormatter> formatters)
|
||||
{
|
||||
var result = new ContentNegotiationResult(_jsonFormatter, new MediaTypeHeaderValue("application/json"));
|
||||
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);
|
||||
|
||||
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();
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
111
SCADA/WebAPI/PP.cs
Normal file
111
SCADA/WebAPI/PP.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace CentralControl
|
||||
{
|
||||
|
||||
public class RequestBody_WebAPI_Boms
|
||||
{
|
||||
public string lineId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string productCode
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
public class ResponseBody_WebAPI_Boms
|
||||
{
|
||||
public string code
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = "";
|
||||
public string message
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = "";
|
||||
public List<DataBody_WebAPI_Boms> Data
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
}
|
||||
public class DataBody_WebAPI_Boms
|
||||
{
|
||||
/*
|
||||
(name="bomHeaderId",value="bom头id")
|
||||
(name ="materialId",value ="物料id")
|
||||
(name="materialCode".value="物料编码")
|
||||
(name="materialName" value="物料名称"
|
||||
(name="quanity",value="量”
|
||||
(name="keyFlag",value="是否关键件,1是,0否")
|
||||
(name ="operationId",value="工位id")
|
||||
(name=operationCode,value="工位编码")
|
||||
(name="assginedSupplierId",value="指定供应商id")
|
||||
(name="assginedSupplierCode".value="指定供应商code")
|
||||
*/
|
||||
public string bomHeaderId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string materialId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string materialCode
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string materialName
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string quanity
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string keyFlag
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string operationId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string operationCode
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string assginedSupplierId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string assginedSupplierCode
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user