web server port 9000 -> 7979
This commit is contained in:
@@ -8,16 +8,200 @@
|
||||
//180614 chi map 명령어 추가
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace FCOMMON
|
||||
{
|
||||
public static class AmkorRestfulService
|
||||
{
|
||||
|
||||
public class RestfulResultDataTable
|
||||
{
|
||||
/// <summary>
|
||||
/// 오류 및 기타상황의 메세지
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Restful 의 실행이 완료되었는가?
|
||||
/// </summary>
|
||||
public Boolean Complete { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Restful 실행 결과를 담고있는 RawBuffer
|
||||
/// </summary>
|
||||
public string Buffer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Restful Service 호출 URL
|
||||
/// </summary>
|
||||
public string Url { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 결과값
|
||||
/// </summary>
|
||||
public System.Data.DataTable Result { get; set; }
|
||||
public RestfulResultDataTable()
|
||||
{
|
||||
Complete = false;
|
||||
Message = string.Empty;
|
||||
Buffer = string.Empty;
|
||||
Url = string.Empty;
|
||||
Result = new System.Data.DataTable();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SPM사이트에서 SID검색을 합니다.
|
||||
/// </summary>
|
||||
/// <param name="sid"></param>
|
||||
/// <returns></returns>
|
||||
public static RestfulResultDataTable SPMSIDSearch(string sid)
|
||||
{
|
||||
var retval = new RestfulResultDataTable();
|
||||
retval.Url = "https://atknet.amkor.co.kr/spm/getActiveInventoryBySid/{0}";
|
||||
retval.Url = string.Format(retval.Url, sid);
|
||||
|
||||
Boolean isError;
|
||||
|
||||
retval.Buffer = GetFromUrl(retval.Url, out isError);
|
||||
|
||||
var cols = new string[] { "plant", "location", "quantity", "part_description", "batch_no", "serial", "costcenter", "responsible", "bin_location" };
|
||||
|
||||
retval.Result = new DataTable();
|
||||
foreach (var col in cols)
|
||||
retval.Result.Columns.Add(col);
|
||||
|
||||
try
|
||||
{
|
||||
var json = JArray.Parse(retval.Buffer);
|
||||
List<string> items = new List<string>();
|
||||
string[] data = new string[cols.Length];
|
||||
|
||||
for (int i = 0; i < json.Count; i++)
|
||||
{
|
||||
var jdata = json[i];
|
||||
for (int c = 0; c < cols.Length; c++)
|
||||
{
|
||||
var itemdata = jdata[cols[c]];
|
||||
if (itemdata != null) data[c] = itemdata.ToString();
|
||||
|
||||
}
|
||||
if (int.TryParse(data[2], out int value))
|
||||
{
|
||||
if (value > 0)
|
||||
retval.Result.Rows.Add(data);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
retval.Complete = retval.Result.Rows.Count > 0;
|
||||
}
|
||||
catch
|
||||
{
|
||||
retval.Complete = false;
|
||||
}
|
||||
|
||||
retval.Result.AcceptChanges();
|
||||
|
||||
//if (retval.Buffer.ToLower().Contains("error") || isError)
|
||||
//{
|
||||
// retval.Complete = false;
|
||||
// retval.Message = retval.Buffer;
|
||||
// RaiseMessage(true, "get_tms_info Error : " + retval.Buffer);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
|
||||
//string tmpBuffer = retval.Buffer;
|
||||
|
||||
//tmpBuffer = tmpBuffer.Replace((char)0x02, (char)0x0a);
|
||||
//tmpBuffer = tmpBuffer.Replace((char)0x03, (char)0x09);
|
||||
//retval.Result = GenerateDataTable(tmpBuffer);
|
||||
//}
|
||||
|
||||
return retval;
|
||||
}
|
||||
public class MessageEventArgs : EventArgs
|
||||
{
|
||||
public Boolean isError { get; set; }
|
||||
public string Message { get; set; }
|
||||
public MessageEventArgs(bool iserr_, string msg_)
|
||||
{
|
||||
this.isError = iserr_;
|
||||
this.Message = msg_;
|
||||
}
|
||||
}
|
||||
public static event EventHandler<MessageEventArgs> Message;
|
||||
|
||||
/// <summary>
|
||||
/// 웹서비스에서 받은 데이터 원문 메세지 입니다.
|
||||
/// </summary>
|
||||
public static event EventHandler<MessageEventArgs> RawMessage;
|
||||
private static void RaiseMessage(Boolean iserr, string msg)
|
||||
{
|
||||
if (Message != null)
|
||||
Message(null, new MessageEventArgs(iserr, msg));
|
||||
}
|
||||
private static void RaiseRawMessage(string url, string msg)
|
||||
{
|
||||
if (RawMessage != null)
|
||||
RawMessage(null, new MessageEventArgs(false, "URL : " + url + "\n" + msg));
|
||||
}
|
||||
public static int timeout = 10000;
|
||||
public static string LastQueryURL { get; private set; }
|
||||
public static string LastQueryBUF { get; private set; }
|
||||
|
||||
private static string GetFromUrl(string url, out Boolean isError, string authid = "", string authpw = "")
|
||||
{
|
||||
isError = false;
|
||||
string result = "";
|
||||
try
|
||||
{
|
||||
RaiseMessage(false, "GET : " + url);
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(url));
|
||||
request.Timeout = timeout;
|
||||
request.ReadWriteTimeout = timeout;
|
||||
|
||||
if (string.IsNullOrEmpty(authid) == false && string.IsNullOrEmpty(authpw) == false)
|
||||
{
|
||||
string authInfo = $"{authid}:{authpw}";
|
||||
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
|
||||
request.Headers["Authorization"] = "Basic " + authInfo;
|
||||
}
|
||||
|
||||
request.MaximumAutomaticRedirections = 4;
|
||||
request.MaximumResponseHeadersLength = 4;
|
||||
request.Credentials = CredentialCache.DefaultCredentials;
|
||||
var response = request.GetResponse() as HttpWebResponse;
|
||||
var txtReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
|
||||
result = txtReader.ReadToEnd();
|
||||
|
||||
LastQueryBUF = result;
|
||||
LastQueryURL = url;
|
||||
RaiseRawMessage(url, "RESULT\n" + result); //181026 - show data
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
isError = true;
|
||||
result = ex.Message.ToString();
|
||||
RaiseMessage(true, "GET-ERROR\n" + result);
|
||||
LastQueryBUF = string.Empty;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public static partial class Util
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user