[성현모] CPXV2 Init
This commit is contained in:
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using SystemX.Net.BaseProtocol;
|
||||
using SystemX.Net.Comm;
|
||||
using SystemX.Net.XAdaptor;
|
||||
using static SystemX.Net.XAdaptor.PC.XAdaptorPC;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC
|
||||
{
|
||||
[ComVisible(true)]
|
||||
[Guid("EF4648F0-5CAB-42CE-A184-F59D646FC1E3")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
|
||||
public interface IComXPCAdaptor
|
||||
{
|
||||
bool ComGetClientSocketConnect();
|
||||
bool ComGetClientStreamSocketConnect();
|
||||
bool ComGetClientInfo();
|
||||
bool ComGetAdaptorConnectState();
|
||||
|
||||
string ComGetCommandMessage();
|
||||
string ComGetStreamMessage();
|
||||
|
||||
Task<bool> ComClientTryConnet(int nCommandPortNum = int.MaxValue, int nStreamPortNum = int.MaxValue);
|
||||
Task<bool> ComClientTryDistributionConnet(int nCommandPortNum = int.MaxValue);
|
||||
Task<bool> WaitComClientTryDistributionConnet(int nCommandPortNum = int.MaxValue);
|
||||
|
||||
bool ComClientTryDisconnect();
|
||||
bool ComCheckConnectState();
|
||||
bool ComCheckConnectStreamState();
|
||||
|
||||
string ComSetConfigureFile(string strFilePos);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using SystemX.Net.BaseProtocol;
|
||||
using SystemX.Net.XAdaptor;
|
||||
using static SystemX.Net.XAdaptor.PC.XAdaptorPC;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC
|
||||
{
|
||||
public interface IUIM
|
||||
{
|
||||
/*
|
||||
* UNIQUE INFO METHOD(MAC ADDRESS)
|
||||
*/
|
||||
|
||||
//발행된 아이디 인지
|
||||
eResultCheck CheckIssuedID(string strProductID);
|
||||
|
||||
//맥 어드레스 무결성 체크
|
||||
eMacAddressType IsMacAddressForm(string strMacAddress);
|
||||
|
||||
//목록에 존재하는 맥어드레스 인지
|
||||
bool CheckListMacAddress(string strMacAddress);
|
||||
|
||||
//발행된 맥어드레스 인지
|
||||
eResultCheck CheckIssuedMacAddress(string strMacAddress);
|
||||
|
||||
//현재 발행 예정 대상 주소
|
||||
string GetToBeIssuedMacAddress(eMacAddressType type = eMacAddressType.Normal);
|
||||
|
||||
//총개수
|
||||
int GetTotalAddressNumber();
|
||||
|
||||
//발행 개수 확인
|
||||
int GetCurrentIssuedAddressNumber();
|
||||
|
||||
//남은 개수 확인
|
||||
int GetRemainAddressNumber();
|
||||
|
||||
string LookUpIDbyMacAddress(string strMacAddress);
|
||||
|
||||
string LookUpMacAddressbyID(ref string strProductID, eLookUpOption SetLookUpOption = eLookUpOption.CompareToSame, eMacAddressType type = eMacAddressType.Normal);
|
||||
|
||||
ResultIssued IssuanceRequest(string strProductID, bool bReissuance = false, eMacAddressType type = eMacAddressType.Normal);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using SystemX.Net.BaseProtocol;
|
||||
using SystemX.Net.XAdaptor;
|
||||
using static SystemX.Net.XAdaptor.PC.XAdaptorPC;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC
|
||||
{
|
||||
public interface IDataSaveTable
|
||||
{
|
||||
string GetTableName();
|
||||
}
|
||||
public interface IXPCAdaptor
|
||||
{
|
||||
//Common query object
|
||||
DataSet WaitUserQuery(string strQuery);
|
||||
|
||||
//bool Login(string strHost, string strSection, bool bUseUIM = false, bool bSimpleLookupOption = false);
|
||||
|
||||
/// <summary>
|
||||
/// Requires running the program with administrator privileges.
|
||||
/// </summary>
|
||||
/// <param name="bAutoApplyWinTime"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> WaitSyncTimeServer(bool bAutoApplyWinTime = true);
|
||||
|
||||
//bool WaitCheckServerState();
|
||||
|
||||
Task<bool> RestoreConnAfterConfirmConn(bool bRetryAutoConnect = true);
|
||||
|
||||
bool SetCustomPacket(params string[] strSetInfo);
|
||||
|
||||
/*
|
||||
bool WaitCheckTestList(uint nStationID, string strProdNo_C,
|
||||
string strTestType,
|
||||
string strTestCode,
|
||||
string strTestListVersion,
|
||||
string strProductionCode);
|
||||
*/
|
||||
|
||||
Task<bool> AsyncWaitCheckTestList(uint nStationID, string strProdNo_C,
|
||||
string strTestType,
|
||||
string strTestCode,
|
||||
string strTestListVersion,
|
||||
string strProductionCode);
|
||||
|
||||
bool QueryTestList(uint nStationID, string strProdNo_C,
|
||||
string strTestType,
|
||||
string strTestCode,
|
||||
string strTestListVersion,
|
||||
string strProductionCode);
|
||||
|
||||
/*
|
||||
bool WaitQueryTestList(uint nStationID, string strProdNo_C,
|
||||
string strTestType,
|
||||
string strTestCode,
|
||||
string strTestListVersion,
|
||||
string strProductionCode);
|
||||
*/
|
||||
Task<Tuple<string, int>> GetTestListQueryWithFilePath(string strFilePath, uint nStationID, string strProdNo_C,
|
||||
string strTestType,
|
||||
string strTestCode,
|
||||
string strTestListVersion,
|
||||
string strProductionCode,
|
||||
bool bCheckAfter = false);
|
||||
|
||||
Task<bool> AsyncWaitQueryTestList(uint nStationID, string strProdNo_C,
|
||||
string strTestType,
|
||||
string strTestCode,
|
||||
string strTestListVersion,
|
||||
string strProductionCode);
|
||||
|
||||
//File Transfer
|
||||
//FileSendRecvResult CPLogFileTransfer(string strFilePos, ushort usPalletIndex = 0);
|
||||
//bool CPLogFileTransfer(MemoryStream ms, ushort usPalletIndex);
|
||||
|
||||
Task<eFileSendRecvResult> AsyncCPLogFileTransfer(string strFilePos,
|
||||
string targetStationName,
|
||||
int targetTestListNo,
|
||||
string targetProcNo_P,
|
||||
string targetProcNo_C,
|
||||
string targetTestType,
|
||||
string targetTestCode,
|
||||
string targetVersion,
|
||||
string targetProdCode);
|
||||
|
||||
eFileSendRecvResult SendCustomFile(string strFilePos, bool bRecvResultWait = false, ushort usPalletIndex = 0);
|
||||
|
||||
eSetConfigFileResult SetConfigureFile(string strFilePos);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,165 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC.O2Sensor.NgCode
|
||||
{
|
||||
public static class DBSchemaMap
|
||||
{
|
||||
public const string ProcessListTableName = "INFO_PROCESS";
|
||||
public const string TableName_NGCode = "INFO_NGCode";
|
||||
public const string TableName_DetailData = "HIST_TestResultDatail";
|
||||
|
||||
public enum eHistAllTableList
|
||||
{
|
||||
HIST_ProdLoad = 0,
|
||||
HIST_CapDeassy,
|
||||
HIST_PreHeating,
|
||||
HIST_PreMeas,
|
||||
HIST_Leak,
|
||||
HIST_LaserTrim,
|
||||
HIST_LaserTrimVision,
|
||||
HIST_IsoRes,
|
||||
HIST_CapAssy,
|
||||
HIST_Function,
|
||||
HIST_OutSealPress,
|
||||
HIST_PinVision,
|
||||
HIST_PinLVDT,
|
||||
HIST_ProdUnload
|
||||
}
|
||||
public enum eHistProcTableList
|
||||
{
|
||||
HIST_ProdLoad = 0,
|
||||
HIST_CapDeassy,
|
||||
HIST_PreHeating,
|
||||
HIST_PreMeas,
|
||||
HIST_Leak,
|
||||
HIST_LaserTrim,
|
||||
HIST_LaserTrimVision,
|
||||
HIST_IsoRes,
|
||||
HIST_CapAssy,
|
||||
HIST_Function,
|
||||
HIST_OutSealPress,
|
||||
HIST_PinVision,
|
||||
HIST_PinLVDT
|
||||
}
|
||||
public enum eHistTableCommonCols
|
||||
{
|
||||
No,
|
||||
LogAccessKey,
|
||||
ProcNo,
|
||||
PalletNumber,
|
||||
PalletID,
|
||||
PIndex,
|
||||
ProdNo,
|
||||
ProdID,
|
||||
TestID,
|
||||
Result,
|
||||
Status,
|
||||
UpdateDT
|
||||
}
|
||||
public enum eHistTableCols
|
||||
{
|
||||
No,
|
||||
ProcNo,
|
||||
PalletNumber,
|
||||
PalletID,
|
||||
PIndex,
|
||||
ProdNo,
|
||||
ProdID,
|
||||
TestID,
|
||||
LogDataPath,
|
||||
LogData,
|
||||
Status,
|
||||
UpdateDT
|
||||
}
|
||||
|
||||
public enum eHistDetailTableCols
|
||||
{
|
||||
No,
|
||||
LogAccessKey,
|
||||
STEP,
|
||||
POSITION,
|
||||
MO,
|
||||
FNC_NAME,
|
||||
MIN_VALUE,
|
||||
MEASURE_VALUE,
|
||||
MAX_VALUE,
|
||||
DIM,
|
||||
CHECK_RETURN,
|
||||
SPENT_TIME,
|
||||
INFO,
|
||||
UpdateDT
|
||||
}
|
||||
|
||||
public enum eStat_ProdLoad
|
||||
{
|
||||
No,
|
||||
PalletID,
|
||||
Index,
|
||||
ProdNo,
|
||||
ProdID,
|
||||
SensorType,
|
||||
Status
|
||||
}
|
||||
|
||||
public enum eHist_ProdUnload
|
||||
{
|
||||
No,
|
||||
PalletID,
|
||||
Index,
|
||||
ProdNo,
|
||||
ProdID,
|
||||
Status,
|
||||
NGCode,
|
||||
Result,
|
||||
UpdateDT
|
||||
}
|
||||
|
||||
public enum eHist_LeakTest
|
||||
{
|
||||
No,
|
||||
LogAccessKey,
|
||||
ProcNo,
|
||||
PalletNumber,
|
||||
PalletID,
|
||||
PIndex,
|
||||
ProdNo,
|
||||
ProdID,
|
||||
SensorType,
|
||||
Status,
|
||||
TestID,
|
||||
Result,
|
||||
UpdateDT,
|
||||
Val_Min,
|
||||
Val_Max,
|
||||
Val_Meas
|
||||
}
|
||||
|
||||
public enum eNGCodeTable
|
||||
{
|
||||
NGCode,
|
||||
Description,
|
||||
ProcNo,
|
||||
TestID,
|
||||
StepNo,
|
||||
Type,
|
||||
ReworkType,
|
||||
CustomCode,
|
||||
Status,
|
||||
UpdateDT
|
||||
}
|
||||
|
||||
|
||||
public enum eReworkType
|
||||
{
|
||||
Retest,
|
||||
M_Rework,
|
||||
Rework,
|
||||
Scrap,
|
||||
Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,607 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SystemX.Net.XAdaptor.PC;
|
||||
using static SystemX.Net.XAdaptor.PC.O2Sensor.NgCode.DBSchemaMap;
|
||||
using static SystemX.Net.Platform.Common.Util.LogMessage;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC.O2Sensor.NgCode
|
||||
{
|
||||
public class NGCodeFinder
|
||||
{
|
||||
public enum eNGFlag
|
||||
{
|
||||
NG,
|
||||
ERROR
|
||||
}
|
||||
|
||||
public enum eNGDataType
|
||||
{
|
||||
CP,
|
||||
LEAK,
|
||||
CHECK
|
||||
}
|
||||
|
||||
public enum eJudgeType
|
||||
{
|
||||
MIN,
|
||||
MAX,
|
||||
CHECK
|
||||
}
|
||||
|
||||
public string UnsortedNGTitle { get; set; } = "Unknown";
|
||||
|
||||
DataTable NGCodeTable { get; set; }
|
||||
|
||||
XAdaptorPC refPCAdaptor;
|
||||
|
||||
public NGCodeFinder(XAdaptorPC refAdaptor)
|
||||
{
|
||||
refPCAdaptor = refAdaptor;
|
||||
|
||||
NGCodeTable = GetNGCodeTable();
|
||||
}
|
||||
public void InitialNgCodeTable()
|
||||
{
|
||||
NGCodeTable = GetNGCodeTable();
|
||||
}
|
||||
|
||||
private DataTable GetNGCodeTable()
|
||||
{
|
||||
DataTable dtResult = null;
|
||||
string strQuery = $"SELECT * FROM {DBSchemaMap.TableName_NGCode};";
|
||||
DataSet dtSetResult = refPCAdaptor.WaitSystemQuery(strQuery);
|
||||
|
||||
if(((dtSetResult != null) ? dtSetResult.Tables.Cast<DataTable>().Any(table => table.Rows.Count != 0) : false))
|
||||
dtResult = dtSetResult.Tables[0];
|
||||
|
||||
return dtResult;
|
||||
}
|
||||
public Dictionary<string, string> GetNGCodeDictionary(DataRow dtNGRow)
|
||||
{
|
||||
Dictionary<string, string> dicNg = new Dictionary<string, string>();
|
||||
|
||||
bool bDisplayMessage = true;
|
||||
try
|
||||
{
|
||||
if (dtNGRow == null)
|
||||
{
|
||||
dicNg.Add("NTH", "-");
|
||||
|
||||
bDisplayMessage = false;
|
||||
throw new Exception("-");
|
||||
}
|
||||
|
||||
string strProcNo = dtNGRow[eHistTableCommonCols.ProcNo.ToString()].ToString().Trim();
|
||||
string strTestID = dtNGRow[eHistTableCommonCols.TestID.ToString()].ToString().Trim();
|
||||
|
||||
string strResult = "";
|
||||
try
|
||||
{
|
||||
strResult = dtNGRow[eHistTableCommonCols.Result.ToString()].ToString().Trim();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
strResult = "0";
|
||||
}
|
||||
|
||||
if (strResult == "1" || strResult == "True")
|
||||
{
|
||||
dicNg.Add("PASS", "-");
|
||||
|
||||
bDisplayMessage = false;
|
||||
throw new Exception("-");
|
||||
}
|
||||
|
||||
|
||||
string strUnknwonCode = GetUnknownNGCode(strProcNo, strTestID);
|
||||
|
||||
List<DataRow> vdtNGCodeRow = GetNGCodeList(strProcNo, strTestID);
|
||||
|
||||
if (vdtNGCodeRow == null ? true : vdtNGCodeRow.Count <= 0)
|
||||
{
|
||||
dicNg.Add(strUnknwonCode, "-");
|
||||
|
||||
bDisplayMessage = false;
|
||||
throw new Exception("-");
|
||||
}
|
||||
|
||||
string strLogAccessKey = "";
|
||||
|
||||
List<DataRow> vdtDetailRow = null;
|
||||
List<DataRow> vdtHISTRow = null;
|
||||
|
||||
//LogAccessKey Exist - PC/DEVICE
|
||||
//Not exist - PLC
|
||||
try
|
||||
{
|
||||
strLogAccessKey = dtNGRow[eHistTableCommonCols.LogAccessKey.ToString()]?.ToString().Trim();
|
||||
vdtDetailRow = GetNGDetailRow(GetNGDetailData(strProcNo, strLogAccessKey));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
|
||||
DataRow dtNGDetailRow = null;
|
||||
DataRow dtNGHISTRow = null;
|
||||
|
||||
DataRow dtNGCodeRow = null;
|
||||
|
||||
if (vdtDetailRow != null && vdtDetailRow.Count > 0)
|
||||
dtNGDetailRow = vdtDetailRow[0];
|
||||
|
||||
/*
|
||||
if (vdtNGCodeRow[0][eNGCodeTable.CustomCode.ToString()].ToString().Trim() == eNGDataType.CP.ToString())
|
||||
dtNGCodeRow = GetNGCodeRowCPLog(vdtNGCodeRow, dtNGDetailRow);
|
||||
else if (vdtNGCodeRow[0][eNGCodeTable.CustomCode.ToString()].ToString().Trim() == eNGDataType.LEAK.ToString())
|
||||
dtNGCodeRow = GeNGCodeRowLeakLog(vdtNGCodeRow, dtNGRow);
|
||||
else
|
||||
{
|
||||
List<DataRow> vdtFoundRow = vdtNGCodeRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
|
||||
|
||||
if (vdtFoundRow.Count > 0)
|
||||
dtNGCodeRow = vdtFoundRow[0];
|
||||
else
|
||||
{
|
||||
dicNg.Add(strUnknwonCode, "-");
|
||||
|
||||
bDisplayMessage = false;
|
||||
throw new Exception("-");
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (vdtNGCodeRow.Where(x => x[eNGCodeTable.CustomCode.ToString()].ToString().Trim() == eNGDataType.CP.ToString()).ToList().Count > 0)
|
||||
dtNGCodeRow = GetNGCodeRowCPLog(vdtNGCodeRow, dtNGDetailRow);
|
||||
else if (vdtNGCodeRow.Where(x => x[eNGCodeTable.CustomCode.ToString()].ToString().Trim() == eNGDataType.LEAK.ToString()).ToList().Count > 0)
|
||||
{
|
||||
vdtHISTRow = GetNGHistRow(GetNGHistData(eHistAllTableList.HIST_Leak, strLogAccessKey));
|
||||
|
||||
if (vdtHISTRow != null && vdtHISTRow.Count > 0)
|
||||
dtNGHISTRow = vdtHISTRow[0];
|
||||
|
||||
dtNGCodeRow = GeNGCodeRowLeakLog(vdtNGCodeRow, dtNGHISTRow);
|
||||
}
|
||||
|
||||
if(dtNGCodeRow == null)
|
||||
{
|
||||
List<DataRow> vdtFoundRow = vdtNGCodeRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
|
||||
|
||||
if (vdtFoundRow.Count > 0)
|
||||
dtNGCodeRow = vdtFoundRow[0];
|
||||
else
|
||||
{
|
||||
dicNg.Add(strUnknwonCode, "-");
|
||||
|
||||
bDisplayMessage = false;
|
||||
throw new Exception("-");
|
||||
}
|
||||
}
|
||||
|
||||
if(dtNGCodeRow != null)
|
||||
dicNg.Add(dtNGCodeRow[eNGCodeTable.NGCode.ToString()].ToString().Trim(), dtNGCodeRow[eNGCodeTable.Status.ToString()].ToString().Trim());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (bDisplayMessage)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"NgCode<Exception> - NGCodeFinder - GetNGCodeDictionary()\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
}
|
||||
finally { }
|
||||
|
||||
return dicNg;
|
||||
}
|
||||
public string GetNGCode(DataRow dtNGRow)
|
||||
{
|
||||
if (dtNGRow == null)
|
||||
return "NTH";
|
||||
|
||||
string strProcNo = dtNGRow[eHistTableCommonCols.ProcNo.ToString()].ToString().Trim();
|
||||
string strTestID = dtNGRow[eHistTableCommonCols.TestID.ToString()].ToString().Trim();
|
||||
|
||||
string strResult = "";
|
||||
|
||||
try
|
||||
{
|
||||
strResult = dtNGRow[eHistTableCommonCols.Result.ToString()].ToString().Trim();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
strResult = "0";
|
||||
}
|
||||
|
||||
if (strResult == "1" || strResult == "True")
|
||||
return "PASS";
|
||||
|
||||
string strUnknwonCode = GetUnknownNGCode(strProcNo, strTestID);
|
||||
|
||||
List<DataRow> vdtNGCodeRow = GetNGCodeList(strProcNo, strTestID);
|
||||
|
||||
if (vdtNGCodeRow == null ? true : vdtNGCodeRow.Count <= 0)
|
||||
return strUnknwonCode;
|
||||
|
||||
string strLogAccessKey = "";
|
||||
List<DataRow> vdtDetailRow = null;
|
||||
List<DataRow> vdtHISTRow = null;
|
||||
|
||||
//LogAccessKey Exist - PC/DEVICE
|
||||
//Not exist - PLC
|
||||
try
|
||||
{
|
||||
strLogAccessKey = dtNGRow[eHistTableCommonCols.LogAccessKey.ToString()]?.ToString().Trim();
|
||||
vdtDetailRow = GetNGDetailRow(GetNGDetailData(strProcNo, strLogAccessKey));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DataRow dtNGDetailRow = null;
|
||||
DataRow dtNGHISTRow = null;
|
||||
|
||||
DataRow dtNGCodeRow = null;
|
||||
|
||||
bool bUnknownState = false;
|
||||
|
||||
try
|
||||
{
|
||||
if (vdtDetailRow != null && vdtDetailRow.Count > 0)
|
||||
dtNGDetailRow = vdtDetailRow[0];
|
||||
|
||||
/*
|
||||
if (vdtNGCodeRow[0][eNGCodeTable.CustomCode.ToString()].ToString().Trim() == eNGDataType.CP.ToString())
|
||||
dtNGCodeRow = GetNGCodeRowCPLog(vdtNGCodeRow, dtNGDetailRow);
|
||||
else if (vdtNGCodeRow[0][eNGCodeTable.CustomCode.ToString()].ToString().Trim() == eNGDataType.LEAK.ToString())
|
||||
dtNGCodeRow = GeNGCodeRowLeakLog(vdtNGCodeRow, dtNGRow);
|
||||
else
|
||||
{
|
||||
List<DataRow> vdtFoundRow = vdtNGCodeRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
|
||||
|
||||
if (vdtFoundRow.Count > 0)
|
||||
dtNGCodeRow = vdtFoundRow[0];
|
||||
else
|
||||
bUnknownState = true;
|
||||
}
|
||||
*/
|
||||
|
||||
if (vdtNGCodeRow.Where(x => x[eNGCodeTable.CustomCode.ToString()].ToString().Trim() == eNGDataType.CP.ToString()).ToList().Count > 0)
|
||||
dtNGCodeRow = GetNGCodeRowCPLog(vdtNGCodeRow, dtNGDetailRow);
|
||||
else if (vdtNGCodeRow.Where(x => x[eNGCodeTable.CustomCode.ToString()].ToString().Trim() == eNGDataType.LEAK.ToString()).ToList().Count > 0)
|
||||
{
|
||||
vdtHISTRow = GetNGHistRow(GetNGHistData (eHistAllTableList.HIST_Leak, strLogAccessKey));
|
||||
|
||||
if (vdtHISTRow != null && vdtHISTRow.Count > 0)
|
||||
dtNGHISTRow = vdtHISTRow[0];
|
||||
|
||||
dtNGCodeRow = GeNGCodeRowLeakLog(vdtNGCodeRow, dtNGHISTRow);
|
||||
}
|
||||
|
||||
if(dtNGCodeRow == null)
|
||||
{
|
||||
List<DataRow> vdtFoundRow = vdtNGCodeRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
|
||||
|
||||
if (vdtFoundRow.Count > 0)
|
||||
dtNGCodeRow = vdtFoundRow[0];
|
||||
else
|
||||
bUnknownState = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"NgCode<Exception> - NGCodeFinder - GetNGCode()\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
finally { }
|
||||
|
||||
if (bUnknownState)
|
||||
return strUnknwonCode;
|
||||
else
|
||||
{
|
||||
if (dtNGCodeRow != null)
|
||||
return dtNGCodeRow[eNGCodeTable.NGCode.ToString()].ToString().Trim();
|
||||
else
|
||||
return strUnknwonCode;
|
||||
|
||||
//return dtNGCodeRow[eNGCodeTable.NGCode.ToString()].ToString().Trim();
|
||||
}
|
||||
}
|
||||
|
||||
public List<DataRow> GetNGCodeList(string strProcNo, string strTestID)
|
||||
{
|
||||
List<DataRow> vdtRows = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (!(NGCodeTable == null))
|
||||
{
|
||||
/*
|
||||
vdtRows = (from dtRow in NGCodeTable.AsEnumerable()
|
||||
where dtRow[eNGCodeTable.ProcNo.ToString()].ToString().Trim() == strProcNo
|
||||
select dtRow).ToList();
|
||||
*/
|
||||
|
||||
vdtRows = (from dtRow in NGCodeTable.AsEnumerable()
|
||||
where dtRow[eNGCodeTable.ProcNo.ToString()].ToString().Trim() == strProcNo
|
||||
&& dtRow[eNGCodeTable.TestID.ToString()].ToString().Trim() == strTestID
|
||||
select dtRow).ToList();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"NgCode<Exception> - NGCodeFinder - GetNGCodeList()\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
finally { }
|
||||
|
||||
return vdtRows;
|
||||
}
|
||||
|
||||
public DataTable GetNGDetailData(string strProcNum, string strKeyCode)
|
||||
{
|
||||
DataTable dtResult = null;
|
||||
string strQuery = $"SELECT * FROM {TableName_DetailData}" + "_" + strProcNum + " WHERE " +
|
||||
$"No IN(SELECT No FROM {TableName_DetailData}" + "_" + strProcNum + " WHERE LogAccessKey = '" + strKeyCode +
|
||||
$"') ORDER BY {eHistDetailTableCols.STEP.ToString()} ASC;";
|
||||
|
||||
DataSet dtSet = refPCAdaptor.WaitSystemQuery(strQuery);
|
||||
|
||||
if (dtSet.Tables.Count > 0)
|
||||
dtResult = dtSet.Tables[0];
|
||||
|
||||
return dtResult;
|
||||
}
|
||||
|
||||
public List<DataRow> GetNGDetailRow(DataTable dtResult)
|
||||
{
|
||||
if(dtResult == null)
|
||||
return null;
|
||||
|
||||
List<DataRow> vRows = null;
|
||||
|
||||
try
|
||||
{
|
||||
List<string> vstrNGFlags = Enum.GetNames(typeof(eNGFlag)).ToList();
|
||||
vRows = (from unitRow in dtResult.AsEnumerable() where vstrNGFlags.Contains(unitRow[eHistDetailTableCols.CHECK_RETURN.ToString()].ToString().Trim()) select unitRow).ToList();
|
||||
|
||||
vRows = vRows.OrderBy(x => Convert.ToInt32(x[eHistDetailTableCols.STEP.ToString()].ToString().Trim())).Reverse().ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"NgCode<Exception> - NGCodeFinder - GetNGDetailRow()\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
finally { }
|
||||
|
||||
return vRows;
|
||||
}
|
||||
public DataTable GetNGHistData(eHistAllTableList setTable, string strKeyCode)
|
||||
{
|
||||
DataTable dtResult = null;
|
||||
string strQuery = $"SELECT * FROM {setTable.ToString()} WHERE " +
|
||||
$"No IN(SELECT No FROM {setTable.ToString()} WHERE LogAccessKey = '" + strKeyCode +
|
||||
$"') ORDER BY No DESC;";
|
||||
|
||||
DataSet dtSet = refPCAdaptor.WaitSystemQuery(strQuery);
|
||||
|
||||
if (dtSet.Tables.Count > 0)
|
||||
dtResult = dtSet.Tables[0];
|
||||
|
||||
return dtResult;
|
||||
}
|
||||
|
||||
public List<DataRow> GetNGHistRow(DataTable dtResult)
|
||||
{
|
||||
if (dtResult == null)
|
||||
return null;
|
||||
|
||||
string strNgResult = "0";
|
||||
List<DataRow> vRows = null;
|
||||
|
||||
try
|
||||
{
|
||||
vRows = (from unitRow in dtResult.AsEnumerable() where strNgResult == (unitRow[eHistTableCommonCols.Result.ToString()].ToString().Trim()) select unitRow).ToList();
|
||||
vRows = vRows.OrderBy(x => Convert.ToInt32(x[eHistDetailTableCols.STEP.ToString()].ToString().Trim())).Reverse().ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"NgCode<Exception> - NGCodeFinder - GetNGHistRow()\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
finally { }
|
||||
|
||||
return vRows;
|
||||
}
|
||||
|
||||
DataRow GeNGCodeRowLeakLog(List<DataRow> vdtRstRow, DataRow dtDetailNGRow)
|
||||
{
|
||||
List<DataRow> vFoundRow = null;
|
||||
|
||||
double dMVal = double.NaN;
|
||||
double dMin = double.NaN;
|
||||
double dMax = double.NaN;
|
||||
|
||||
if(dtDetailNGRow == null)
|
||||
{
|
||||
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
|
||||
|
||||
if(vFoundRow.Count > 0)
|
||||
return vFoundRow[0];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
double.TryParse(dtDetailNGRow[eHist_LeakTest.Val_Meas.ToString()].ToString().Trim(), out dMVal);
|
||||
double.TryParse(dtDetailNGRow[eHist_LeakTest.Val_Min.ToString()].ToString().Trim(), out dMin);
|
||||
double.TryParse(dtDetailNGRow[eHist_LeakTest.Val_Max.ToString()].ToString().Trim(), out dMax);
|
||||
|
||||
if (double.IsNaN(dMVal) ||
|
||||
double.IsNaN(dMin) ||
|
||||
double.IsNaN(dMax))
|
||||
{
|
||||
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
|
||||
|
||||
if(vFoundRow.Count > 0)
|
||||
return vFoundRow[0];
|
||||
}
|
||||
|
||||
if(dMVal < dMin)
|
||||
{
|
||||
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.MIN.ToString()).ToList();
|
||||
|
||||
if(vFoundRow.Count > 0)
|
||||
return vFoundRow[0];
|
||||
else
|
||||
{
|
||||
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
|
||||
|
||||
if (vFoundRow.Count > 0)
|
||||
return vFoundRow[0];
|
||||
}
|
||||
}
|
||||
else if(dMVal > dMax)
|
||||
{
|
||||
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.MAX.ToString()).ToList();
|
||||
|
||||
if(vFoundRow.Count > 0)
|
||||
return vFoundRow[0];
|
||||
else
|
||||
{
|
||||
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
|
||||
|
||||
if (vFoundRow.Count > 0)
|
||||
return vFoundRow[0];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
|
||||
|
||||
if (vFoundRow.Count > 0)
|
||||
return vFoundRow[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
DataRow GetNGCodeRowCPLog(List<DataRow> vdtRstRow, DataRow dtDetailNGRow)
|
||||
{
|
||||
List<DataRow> vFoundRow = null;
|
||||
|
||||
double dMVal = double.NaN;
|
||||
double dMin = double.NaN;
|
||||
double dMax = double.NaN;
|
||||
|
||||
if(dtDetailNGRow == null)
|
||||
{
|
||||
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
|
||||
|
||||
if(vFoundRow.Count > 0)
|
||||
return vFoundRow[0];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
double.TryParse(dtDetailNGRow[eHistDetailTableCols.MEASURE_VALUE.ToString()].ToString().Trim(), out dMVal);
|
||||
double.TryParse(dtDetailNGRow[eHistDetailTableCols.MIN_VALUE.ToString()].ToString().Trim(), out dMin);
|
||||
double.TryParse(dtDetailNGRow[eHistDetailTableCols.MAX_VALUE.ToString()].ToString().Trim(), out dMax);
|
||||
|
||||
int iGetStep = 0;
|
||||
int.TryParse(dtDetailNGRow[eHistDetailTableCols.STEP.ToString()].ToString().Trim(), out iGetStep);
|
||||
|
||||
if (double.IsNaN(dMVal) ||
|
||||
double.IsNaN(dMin) ||
|
||||
double.IsNaN(dMax))
|
||||
{
|
||||
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
|
||||
|
||||
if(vFoundRow.Count > 0)
|
||||
return vFoundRow[0];
|
||||
}
|
||||
else if(dMVal < dMin)
|
||||
{
|
||||
vFoundRow = vdtRstRow.Where(x => (x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.MIN.ToString()) &&
|
||||
(x[eNGCodeTable.StepNo.ToString()].ToString().Trim() == iGetStep.ToString())).ToList();
|
||||
|
||||
if(vFoundRow.Count > 0)
|
||||
return vFoundRow[0];
|
||||
else
|
||||
{
|
||||
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
|
||||
|
||||
if (vFoundRow.Count > 0)
|
||||
return vFoundRow[0];
|
||||
}
|
||||
}
|
||||
else if(dMVal > dMax)
|
||||
{
|
||||
vFoundRow = vdtRstRow.Where(x => (x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.MAX.ToString()) &&
|
||||
(x[eNGCodeTable.StepNo.ToString()].ToString().Trim() == iGetStep.ToString())).ToList();
|
||||
|
||||
if (vFoundRow.Count > 0)
|
||||
return vFoundRow[0];
|
||||
else
|
||||
{
|
||||
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
|
||||
|
||||
if (vFoundRow.Count > 0)
|
||||
return vFoundRow[0];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
|
||||
|
||||
if (vFoundRow.Count > 0)
|
||||
return vFoundRow[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
string GetUnknownNGCode(string strProcNo, string strTestID)
|
||||
{
|
||||
string strNGCodeResult = UnsortedNGTitle + ":" + strProcNo + "-" + strTestID;
|
||||
|
||||
return strNGCodeResult;
|
||||
}
|
||||
|
||||
public eReworkType GetReworkType(string strNGCode)
|
||||
{
|
||||
List<DataRow> vdtRstRow = (from dtNGRow in NGCodeTable.AsEnumerable() where dtNGRow[eNGCodeTable.NGCode.ToString()].ToString().Trim() == strNGCode select dtNGRow).ToList();
|
||||
eReworkType R_Type = eReworkType.Unknown;
|
||||
|
||||
if(vdtRstRow.Count == 0)
|
||||
return R_Type;
|
||||
|
||||
string strRType = "";
|
||||
|
||||
try
|
||||
{
|
||||
strRType = vdtRstRow[0][eNGCodeTable.ReworkType.ToString()].ToString().Trim();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"NgCode<Exception> - NGCodeFinder - GetReworkType()\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
finally { }
|
||||
|
||||
if (!Enum.TryParse(strRType, out R_Type))
|
||||
return R_Type;
|
||||
|
||||
return R_Type;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using static SystemX.Net.XAdaptor.PC.O2Sensor.NgCode.DBSchemaMap;
|
||||
using static SystemX.Net.Platform.Common.Util.LogMessage;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC.O2Sensor.NgCode
|
||||
{
|
||||
public class NGCodeMgr
|
||||
{
|
||||
public bool CONNECT { internal set; get; }
|
||||
|
||||
NGCodeFinder NGCodeFinder { get; set; }
|
||||
NGHistDBFinder HistFinder { get; set; }
|
||||
|
||||
XAdaptorPC refPCAdaptor;
|
||||
|
||||
public NGCodeMgr(XAdaptorPC refAdaptor)
|
||||
{
|
||||
refPCAdaptor = refAdaptor;
|
||||
|
||||
CreateInstances();
|
||||
}
|
||||
|
||||
bool CreateInstances()
|
||||
{
|
||||
try
|
||||
{
|
||||
HistFinder = new NGHistDBFinder(refPCAdaptor);
|
||||
NGCodeFinder = new NGCodeFinder(refPCAdaptor);
|
||||
|
||||
NGCodeFinder.InitialNgCodeTable();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"Error during initiating NG Code Manager Instance: " + ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"Recv NgTable.", ConsoleColor.White, LogMessageLevel.DEBUG);
|
||||
|
||||
return true;
|
||||
}
|
||||
public List<string> GetNGCodeHistory(string strProductID)
|
||||
{
|
||||
return HistFinder.GetNGCodeHistory(strProductID);
|
||||
}
|
||||
public Dictionary<eHistProcTableList, DataRow> GetProcResult(string strProductID, string strPalletID, bool bFirstNgFind)
|
||||
{
|
||||
return HistFinder.FindHistory(strProductID, strPalletID, bFirstNgFind);
|
||||
}
|
||||
public Tuple<eHistProcTableList, DataRow, bool> GetNGProcess(string strProductID, string strPalletID)
|
||||
{
|
||||
return HistFinder.FindNGHistory(strProductID, strPalletID);
|
||||
}
|
||||
public Dictionary<string, string> GetNGCodeDictionary(eHistProcTableList proc, DataRow dtRow)
|
||||
{
|
||||
Dictionary<string, string> dicNgCode = null;
|
||||
|
||||
dicNgCode = NGCodeFinder.GetNGCodeDictionary(dtRow);
|
||||
|
||||
return dicNgCode;
|
||||
}
|
||||
public string GetNGCode(eHistProcTableList proc, DataRow dtRow)
|
||||
{
|
||||
string strNGCode = string.Empty;
|
||||
|
||||
strNGCode = NGCodeFinder .GetNGCode(dtRow);
|
||||
|
||||
return strNGCode;
|
||||
}
|
||||
public eReworkType GetReworkType(string strNGCode)
|
||||
{
|
||||
return NGCodeFinder.GetReworkType(strNGCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,212 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SystemX.Net.XAdaptor.PC;
|
||||
using SystemX.Net.Platform.Common.ExtensionMethods;
|
||||
using static SystemX.Net.XAdaptor.PC.O2Sensor.NgCode.DBSchemaMap;
|
||||
using static SystemX.Net.Platform.Common.Util.LogMessage;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC.O2Sensor.NgCode
|
||||
{
|
||||
public class NGHistDBFinder
|
||||
{
|
||||
string SET_NG_HIST_TABLE_NAME = "HIST_TestNgResult";
|
||||
//Name - ProcNo - TestID
|
||||
Dictionary<eHistProcTableList, Tuple<int, string>> dicHistInfo;
|
||||
|
||||
XAdaptorPC refPCAdaptor;
|
||||
|
||||
public NGHistDBFinder(XAdaptorPC refAdaptor)
|
||||
{
|
||||
refPCAdaptor = refAdaptor;
|
||||
|
||||
dicHistInfo = new Dictionary<eHistProcTableList, Tuple<int, string>>();
|
||||
dicHistInfo.Add(eHistProcTableList.HIST_ProdLoad, new Tuple<int, string>(180, "PL"));
|
||||
dicHistInfo.Add(eHistProcTableList.HIST_CapDeassy, new Tuple<int, string>(180, "CDA"));
|
||||
dicHistInfo.Add(eHistProcTableList.HIST_PreHeating, new Tuple<int, string>(190, "PH"));
|
||||
dicHistInfo.Add(eHistProcTableList.HIST_PreMeas, new Tuple<int, string>(190, "PM"));
|
||||
dicHistInfo.Add(eHistProcTableList.HIST_Leak, new Tuple<int, string>(200, "LK"));
|
||||
dicHistInfo.Add(eHistProcTableList.HIST_LaserTrim, new Tuple<int, string>(210, "LT"));
|
||||
dicHistInfo.Add(eHistProcTableList.HIST_LaserTrimVision, new Tuple<int, string>(220, "LTV"));
|
||||
dicHistInfo.Add(eHistProcTableList.HIST_IsoRes, new Tuple<int, string>(220, "IR"));
|
||||
dicHistInfo.Add(eHistProcTableList.HIST_CapAssy, new Tuple<int, string>(230, "CA"));
|
||||
dicHistInfo.Add(eHistProcTableList.HIST_Function, new Tuple<int, string>(240, "FT"));
|
||||
dicHistInfo.Add(eHistProcTableList.HIST_OutSealPress, new Tuple<int, string>(250, "OSP"));
|
||||
dicHistInfo.Add(eHistProcTableList.HIST_PinVision, new Tuple<int, string>(260, "PV"));
|
||||
dicHistInfo.Add(eHistProcTableList.HIST_PinLVDT, new Tuple<int, string>(260, "LVDT"));
|
||||
}
|
||||
|
||||
public Dictionary<eHistProcTableList, DataRow> FindHistory(string strMESID, string strPalletID, bool bFristFailScan = false)
|
||||
{
|
||||
Dictionary<eHistProcTableList, DataRow> dicResult = new Dictionary<eHistProcTableList, DataRow>();
|
||||
|
||||
string strQuery = $"SELECT * FROM {SET_NG_HIST_TABLE_NAME.ToString()} WHERE No IN (SELECT No FROM {SET_NG_HIST_TABLE_NAME.ToString()} WHERE " +
|
||||
$"{eHistTableCommonCols.ProdID} = '{strMESID}' AND {eHistTableCommonCols.PalletID} = '{strPalletID}') " +
|
||||
$"ORDER BY {eHistTableCommonCols.ProcNo.ToString()};";
|
||||
|
||||
DataSet dsResult = null;
|
||||
|
||||
try
|
||||
{
|
||||
dsResult = refPCAdaptor.WaitSystemQuery(strQuery);
|
||||
DataRow dr = null;
|
||||
|
||||
foreach (eHistProcTableList tableName in Enum.GetValues(typeof(eHistProcTableList)))
|
||||
{
|
||||
int iProcNo = dicHistInfo[tableName].Item1;
|
||||
string strTestID = dicHistInfo[tableName].Item2;
|
||||
|
||||
bool bNgRowFind = false;
|
||||
dr = null;
|
||||
|
||||
foreach (var item in dsResult.Tables[0].Rows)
|
||||
{
|
||||
dr = item as DataRow;
|
||||
|
||||
int iIndex = dsResult.Tables[0].Rows.IndexOf(dr);
|
||||
|
||||
string strGetProcNo = dsResult.Tables[0].Rows[iIndex][eHistTableCommonCols.ProcNo.ToString()].ToString().Trim();
|
||||
string strGetTestID = dsResult.Tables[0].Rows[iIndex][eHistTableCommonCols.TestID.ToString()].ToString().Trim();
|
||||
|
||||
if (strGetProcNo == iProcNo.ToString() &&
|
||||
strGetTestID == strTestID)
|
||||
{
|
||||
bNgRowFind = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bNgRowFind)
|
||||
{
|
||||
dicResult.Add(tableName, dr);
|
||||
|
||||
//이력 존재시 NG
|
||||
if (bFristFailScan)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
dicResult.Add(tableName, null);
|
||||
|
||||
//이력 미 존재시 PASS
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"NgCode<Exception> - NGHistDBFinder - FindHistory()\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
finally { }
|
||||
|
||||
return dicResult;
|
||||
}
|
||||
public Tuple<eHistProcTableList, DataRow, bool> FindNGHistory(string strMESID, string strPalletID)
|
||||
{
|
||||
Tuple<eHistProcTableList, DataRow, bool> pairResult = null;
|
||||
Dictionary<eHistProcTableList, DataRow> dicResult = FindHistory(strMESID, strPalletID, true);
|
||||
|
||||
try
|
||||
{
|
||||
foreach (eHistProcTableList procTbl in Enum.GetValues(typeof(eHistProcTableList)))
|
||||
{
|
||||
DataRow dtRow = dicResult[procTbl];
|
||||
|
||||
if (dtRow == null)
|
||||
{
|
||||
if (pairResult == null)
|
||||
pairResult = new Tuple<eHistProcTableList, DataRow, bool>(procTbl, null, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
pairResult = new Tuple<eHistProcTableList, DataRow, bool>(procTbl, dtRow, false);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"NgCode<Exception> - NGHistDBFinder - FindNGHistory()\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
finally { }
|
||||
|
||||
return pairResult;
|
||||
}
|
||||
public List<string> GetOnloadedPalletIDs(string strMESID)
|
||||
{
|
||||
string strQuery = $"SELECT PalletID FROM {eHistAllTableList.HIST_ProdLoad.ToString()} WHERE {eHistTableCommonCols.ProdID} = '{strMESID}' ORDER BY {eHistTableCommonCols.UpdateDT.ToString()} DESC";
|
||||
|
||||
DataSet dtSet = refPCAdaptor.WaitSystemQuery(strQuery);
|
||||
|
||||
List<string> vstrPalletID = (from dtResult in dtSet.Tables[0].AsEnumerable()
|
||||
let strResult = dtResult[eHistTableCommonCols.PalletID.ToString()].ToString().Trim()
|
||||
select strResult).ToList();
|
||||
|
||||
return vstrPalletID;
|
||||
}
|
||||
public List<string> GetNGCodeHistory(string strMESID)
|
||||
{
|
||||
List<string> vstrNGCodes = null;
|
||||
|
||||
try
|
||||
{
|
||||
string strQuery = $"SELECT TOP 100 NGCode FROM {eHistAllTableList.HIST_ProdUnload.ToString()} WHERE {eHistTableCommonCols.ProdID} = '{strMESID}' ORDER BY {eHistTableCommonCols.UpdateDT.ToString()} DESC";
|
||||
|
||||
DataSet dtSet = refPCAdaptor.WaitSystemQuery(strQuery);
|
||||
|
||||
vstrNGCodes = (from dtResult in dtSet.Tables[0].AsEnumerable()
|
||||
let strResult = dtResult[eHist_ProdUnload.NGCode.ToString()].ToString().Trim()
|
||||
select strResult).ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"NgCode<Exception> - NGHistDBFinder - GetNGCodeHistory()\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
finally { }
|
||||
|
||||
return vstrNGCodes;
|
||||
}
|
||||
string SearchRecentResultQuery(string strTable, string strMESID)
|
||||
{
|
||||
string strQuery = $"SELECT * FROM {strTable}";
|
||||
|
||||
return strQuery;
|
||||
}
|
||||
public string GetCurrentPalletID(string strMESID)
|
||||
{
|
||||
string strColPalletID = "PalletID";
|
||||
string strProdLoadState = "STAT_ProdLoad";
|
||||
string strQuery = $"SELECT {strColPalletID} FROM {strProdLoadState} WHERE {eStat_ProdLoad.ProdID} = '{strMESID}'";
|
||||
|
||||
DataSet dsResult = refPCAdaptor.WaitSystemQuery(QueryProcessList);
|
||||
|
||||
List<string> vstrPalletID = (from dtResult in dsResult.Tables[0].AsEnumerable()
|
||||
where dtResult[strColPalletID].ToString().Trim() == strMESID
|
||||
let strResult = dtResult[strColPalletID].ToString().Trim()
|
||||
select strResult).ToList();
|
||||
|
||||
if(vstrPalletID.Count <= 0)
|
||||
return string.Empty;
|
||||
|
||||
return vstrPalletID[0];
|
||||
}
|
||||
public DataTable GetProcessList()
|
||||
{
|
||||
DataSet dsResult = refPCAdaptor.WaitSystemQuery(QueryProcessList);
|
||||
|
||||
return dsResult.Tables[0];
|
||||
}
|
||||
|
||||
string QueryProcessList = $"SELECT * FROM {DBSchemaMap.ProcessListTableName}";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SystemX.Common;
|
||||
using SystemX.Common.Serialization;
|
||||
using SystemX.Net.BaseProtocol;
|
||||
using SystemX.Net.XAdaptor.PC;
|
||||
using SystemX.Net.Schedule;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC.ProtocolMethod
|
||||
{
|
||||
public class CONNECT_STATE : ProtocolShell, IProtocol
|
||||
{
|
||||
public CONNECT_STATE(XAdaptorPC xAdaptor, int iPos)
|
||||
: base(xAdaptor, iPos)
|
||||
{
|
||||
}
|
||||
|
||||
public override void ExecuteProtocol(BASE_PROTOCOL GET_PROTOCOL,
|
||||
BASE_PROTOCOL.PROTOCOL_CODE CODE,
|
||||
HEADER_PACKET getHeader,
|
||||
object objData)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SystemX.Common;
|
||||
using SystemX.Common.Serialization;
|
||||
using SystemX.Net.BaseProtocol;
|
||||
using SystemX.Net.XAdaptor.PC;
|
||||
using SystemX.Net.Schedule;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC.ProtocolMethod
|
||||
{
|
||||
public class HOST_INFO_CHECK : ProtocolShell, IProtocol
|
||||
{
|
||||
public HOST_INFO_CHECK(XAdaptorPC xAdaptor, int iPos)
|
||||
: base(xAdaptor, iPos)
|
||||
{
|
||||
}
|
||||
|
||||
public override void ExecuteProtocol(BASE_PROTOCOL GET_PROTOCOL,
|
||||
BASE_PROTOCOL.PROTOCOL_CODE CODE,
|
||||
HEADER_PACKET getHeader,
|
||||
object objData)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SystemX.Common;
|
||||
using SystemX.Common.Serialization;
|
||||
using SystemX.Net.BaseProtocol;
|
||||
using SystemX.Net.XAdaptor.PC;
|
||||
using SystemX.Net.Schedule;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC.ProtocolMethod
|
||||
{
|
||||
public class INITILALIZE_INFO : ProtocolShell, IProtocol
|
||||
{
|
||||
public INITILALIZE_INFO(XAdaptorPC xAdaptor, int iPos)
|
||||
: base(xAdaptor, iPos)
|
||||
{
|
||||
}
|
||||
|
||||
public override void ExecuteProtocol(BASE_PROTOCOL GET_PROTOCOL,
|
||||
BASE_PROTOCOL.PROTOCOL_CODE CODE,
|
||||
HEADER_PACKET getHeader,
|
||||
object objData)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SystemX.Common.Protocol.SIA;
|
||||
using SystemX.Net.BaseProtocol;
|
||||
using SystemX.Net.XAdaptor.PC;
|
||||
using SystemX.Net.Schedule;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC.ProtocolMethod
|
||||
{
|
||||
public interface IProtocol
|
||||
{
|
||||
}
|
||||
|
||||
public class ProtocolShell
|
||||
{
|
||||
public XAdaptorPC xAdaptor_;
|
||||
|
||||
//protected CustomProtocol_ cp = new CustomProtocol_();
|
||||
|
||||
protected int nPos;
|
||||
|
||||
public ProtocolShell(XAdaptorPC xAdaptor, int iPos)
|
||||
{
|
||||
xAdaptor_ = xAdaptor;
|
||||
|
||||
nPos = iPos;
|
||||
}
|
||||
|
||||
public virtual void ExecuteProtocol(BASE_PROTOCOL GET_PROTOCOL,
|
||||
BASE_PROTOCOL.PROTOCOL_CODE CODE,
|
||||
HEADER_PACKET getHeader,
|
||||
object objData){ /*Virtual*/ }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,658 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using SystemX.Common;
|
||||
using SystemX.Common.Serialization;
|
||||
using SystemX.Net.BaseProtocol;
|
||||
using SystemX.Net.Comm;
|
||||
using SystemX.Net.XAdaptor;
|
||||
using SystemX.Net.XAdaptor.PC.O2Sensor.NgCode;
|
||||
using SystemX.Net.Schedule;
|
||||
using static SystemX.Net.Platform.Common.Util.LogMessage;
|
||||
using WTimer = System.Windows.Forms.Timer;
|
||||
using System.IO.Compression;
|
||||
using SystemX.Net.Comm.IIS_FTP;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC
|
||||
{
|
||||
public partial class XAdaptorPC : XAdaptorSystem, IXPCAdaptor, IUIM, IComXPCAdaptor, IDisposable
|
||||
{
|
||||
private IPEndPoint ClientCommandEP;
|
||||
private IPEndPoint ClientStreamEP;
|
||||
|
||||
private const int DISP_CONNECT_TIME_OUT = 5000;
|
||||
|
||||
private const int CONNECT_TIME_OUT = 10000;
|
||||
private const int COMMAND_TIME_OUT = 20000;
|
||||
|
||||
private const int FILE_SCAN_TIME = 250;
|
||||
private const int DEVICE_SCAN_TIME = 250;
|
||||
|
||||
private const int RETRY_TIME = 5000;
|
||||
|
||||
private const int LOGIN_TIMEOUT = 90000;
|
||||
|
||||
private const int OBJECT_ACCESS_WAITTIME = 5000;
|
||||
|
||||
private const int FILE_ACCESS_WAITTIME = 100;
|
||||
|
||||
private const int OBJECT_ACCESS_CHECKTIME = 250;
|
||||
|
||||
//1분 파일 전송 간격
|
||||
private const int FILE_SEND_INTERVAL_TIME = 10000;
|
||||
|
||||
//TODO : For Debug Test
|
||||
//5분 이상 파일전송이 없을경우
|
||||
private const int FILE_SEND_MAX_WAITTIME = 300000; // 300000;
|
||||
|
||||
private const int COMM_RETRY = 3;
|
||||
//private const double SESSION_TIMEOUT_SECOND = 300.0;
|
||||
|
||||
#if FALSE
|
||||
private AsyncComClientSocket ClientCommandSock;
|
||||
private AsyncComClientSocket ClientStreamSock;
|
||||
#else
|
||||
private AsyncClientSocket ClientCommandSock;
|
||||
private AsyncClientSocket ClientStreamSock;
|
||||
#endif
|
||||
|
||||
private Task taskRecvCommandProcess;
|
||||
private bool m_bTaskCommandBlock;
|
||||
|
||||
private Task taskRecvStreamProcess;
|
||||
private bool m_bTaskStreamBlock;
|
||||
|
||||
private Task taskSubProcess;
|
||||
private bool m_bTaskSubBlock;
|
||||
//
|
||||
private CancellationTokenSource CommandCTS;
|
||||
private CancellationToken CommandCT;
|
||||
|
||||
private CancellationTokenSource StreamCTS;
|
||||
private CancellationToken StreamCT;
|
||||
|
||||
private CancellationTokenSource SubCTS;
|
||||
private CancellationToken SubCT;
|
||||
//
|
||||
private bool bConnectCommandSocketFlag;
|
||||
private bool bConnectStreamSocketFlag;
|
||||
//
|
||||
private PacketFlowControl FlowCommandControl;
|
||||
private PacketFlowControl FlowStreamControl;
|
||||
|
||||
private event RecvWaitEventHandler RecvWaitEvent;
|
||||
|
||||
private WaitParameter waitCommandParam;
|
||||
private WaitParameter waitStreamParam;
|
||||
|
||||
internal class QueryDataSetResult
|
||||
{
|
||||
public XData xData;
|
||||
|
||||
public bool bQueryResult;
|
||||
|
||||
public DataSet QueryDataSet;
|
||||
|
||||
public string strVarParam1;
|
||||
public string strVarParam2;
|
||||
public string strVarParam3;
|
||||
|
||||
public bool bFileRecvResult;
|
||||
public bool bFileProcessResult;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
xData = null;
|
||||
|
||||
bQueryResult = false;
|
||||
|
||||
QueryDataSet = null;
|
||||
|
||||
strVarParam1 = string.Empty;
|
||||
strVarParam2 = string.Empty;
|
||||
strVarParam3 = string.Empty;
|
||||
|
||||
bFileRecvResult = false;
|
||||
bFileProcessResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
private QueryDataSetResult QueryResult = new QueryDataSetResult();
|
||||
|
||||
//Command Socket Retry Time
|
||||
private Stopwatch streCommandConnectWatch;
|
||||
//Stream Socket Retry Time
|
||||
private Stopwatch streStreamConnectWatch;
|
||||
//File Send & File Backup Time
|
||||
private Stopwatch stFileSendTime;
|
||||
private Stopwatch stBackupFileSendTime;
|
||||
|
||||
private Task tkReCommandConnect;
|
||||
private Task tkReStreamConnect;
|
||||
|
||||
private WTimer reConnectTimer;
|
||||
//
|
||||
private bool[] START_EVENT_TRIGGER;
|
||||
|
||||
private string strSetAdaptorConfigFilePos;
|
||||
private string strCheckCommandMsg;
|
||||
private string strCheckStreamMsg;
|
||||
|
||||
private static SemaphoreSlim _smpSlim = new SemaphoreSlim(1, 1);
|
||||
|
||||
private static bool bTaskSubLockState = false;
|
||||
|
||||
//private static readonly object objFileSendLock = new object();
|
||||
|
||||
private static bool bTaskCommandWaitLock = false;
|
||||
private static bool bTaskStreamWaitLock = false;
|
||||
|
||||
private bool bReqConnectFailed;
|
||||
private int nReqConnectNum;
|
||||
//
|
||||
private NGCodeMgr dbNgCodeFinder;
|
||||
|
||||
public NGCodeMgr GetNgCodeMgr()
|
||||
{
|
||||
if (dbNgCodeFinder != null)
|
||||
return dbNgCodeFinder;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
private enum TIMER_LOCK
|
||||
{
|
||||
RECONNECT_TIMER = 0
|
||||
}
|
||||
|
||||
private bool[] m_bTimerLock;
|
||||
|
||||
private void InitMember()
|
||||
{
|
||||
GetMiddlewareMessage = "OFF";
|
||||
|
||||
CommandCTS = new CancellationTokenSource();
|
||||
CommandCT = CommandCTS.Token;
|
||||
|
||||
StreamCTS = new CancellationTokenSource();
|
||||
StreamCT = StreamCTS.Token;
|
||||
|
||||
SubCTS = new CancellationTokenSource();
|
||||
SubCT = SubCTS.Token;
|
||||
//
|
||||
streCommandConnectWatch = new Stopwatch();
|
||||
streCommandConnectWatch.Start();
|
||||
|
||||
streStreamConnectWatch = new Stopwatch();
|
||||
streStreamConnectWatch.Start();
|
||||
|
||||
stFileSendTime = new Stopwatch();
|
||||
stFileSendTime.Start();
|
||||
|
||||
stBackupFileSendTime = new Stopwatch();
|
||||
stBackupFileSendTime.Start();
|
||||
//
|
||||
tkReCommandConnect = null;
|
||||
tkReStreamConnect = null;
|
||||
|
||||
strSetAdaptorConfigFilePos = string.Empty;
|
||||
|
||||
AdaptorInformation = new ClientConnInfo();
|
||||
//
|
||||
bConnectCommandSocketFlag = false;
|
||||
bConnectStreamSocketFlag = false;
|
||||
}
|
||||
|
||||
public XAdaptorPC()
|
||||
{
|
||||
InitMember();
|
||||
|
||||
/* For LeakTest */
|
||||
if (COMMON.FIX_INFO_MODE)
|
||||
{
|
||||
IPEndPoint CommandEp = null;
|
||||
IPEndPoint StreamEp = null;
|
||||
|
||||
CommandEp = new IPEndPoint(IPAddress.Parse("200.200.200.48"), 5124);
|
||||
StreamEp = new IPEndPoint(IPAddress.Parse("200.200.200.48"), 7124);
|
||||
|
||||
//TempCode
|
||||
//CommandEp = new IPEndPoint(IPAddress.Loopback, 5124);
|
||||
//StreamEp = new IPEndPoint(IPAddress.Loopback, 7124);
|
||||
|
||||
Initialize(CommandEp, StreamEp);
|
||||
}
|
||||
else
|
||||
{
|
||||
//For Normal Process
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
|
||||
public XAdaptorPC(IPEndPoint SetCommandEp = null, IPEndPoint SetStreamEp = null)
|
||||
{
|
||||
InitMember();
|
||||
|
||||
Initialize(SetCommandEp, SetStreamEp);
|
||||
}
|
||||
|
||||
~XAdaptorPC()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool bDisposing)
|
||||
{
|
||||
RecvWaitEvent -= RecvWaitEventCall;
|
||||
|
||||
if (bDisposing)
|
||||
{
|
||||
ClearCommandWatchTask();
|
||||
ClearStreamWatchTask();
|
||||
}
|
||||
|
||||
ClearCommandClientInstance();
|
||||
ClearStreamClientInstance();
|
||||
|
||||
// do releasing unmanaged resource (종결자가 없는 객체의 자원 해제)
|
||||
// i.e. close file handle of operating systems
|
||||
|
||||
// suppress calling of Finalizer
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private void SetRetryTimer()
|
||||
{
|
||||
reConnectTimer = new WTimer();
|
||||
reConnectTimer.Enabled = false;
|
||||
reConnectTimer.Interval = 1500;
|
||||
reConnectTimer.Tick += ReConnectTimer_Tick;
|
||||
reConnectTimer.Start();
|
||||
reConnectTimer.Enabled = true;
|
||||
}
|
||||
|
||||
private bool CheckConfigFileBuildEndPoint()
|
||||
{
|
||||
bool bCheckResult = true;
|
||||
|
||||
var sFilePath = "";
|
||||
|
||||
if (strSetAdaptorConfigFilePos.Length <= 0)
|
||||
sFilePath = Directory.GetCurrentDirectory() + @"\Configure\" + "ClientInformation.xml";
|
||||
else
|
||||
sFilePath = strSetAdaptorConfigFilePos;
|
||||
|
||||
if (File.Exists(sFilePath) == false)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"SystemX.Net.XAdaptor.PC Configuration file does not exist. " +
|
||||
"[SystemX.Net.XAdaptor.PC : XPCAdaptor.CheckConfigFileBuildEndPoint]", ConsoleColor.Yellow, LogMessageLevel.FATAL);
|
||||
|
||||
bCheckResult = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadInfo = new ClientInfo(sFilePath);
|
||||
|
||||
if (LoadInfo.Load() == false)
|
||||
{
|
||||
bCheckResult = false;
|
||||
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"SystemX.Net.XAdaptor.PC Configuration file loading Error. " +
|
||||
"[SystemX.Net.XAdaptor.PC : XPCAdaptor.CheckConfigFileBuildEndPoint]", ConsoleColor.Yellow, LogMessageLevel.FATAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
AdaptorInformation.CONNECT_IP = LoadInfo.CONNECT_IP;
|
||||
AdaptorInformation.SECTION = LoadInfo.SECTION;
|
||||
AdaptorInformation.HOST_ID = LoadInfo.HOST_ID;
|
||||
AdaptorInformation.TEST_CODE = LoadInfo.TEST_CODE;
|
||||
|
||||
AdaptorInformation.COMMAND_PORT = LoadInfo.COMMAND_PORT;
|
||||
AdaptorInformation.STREAM_PORT = LoadInfo.STREAM_PORT;
|
||||
|
||||
AdaptorInformation.LOGIN_RESULT = false;
|
||||
AdaptorInformation.LOGIN_MESSAGE = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
StateAdaptorConnect = bCheckResult;
|
||||
|
||||
if (ClientReadyEndPoint && bCheckResult)
|
||||
SetEpCommandStream();
|
||||
|
||||
return bCheckResult;
|
||||
}
|
||||
|
||||
private void SetDefaultConfig()
|
||||
{
|
||||
LoadInfo = new ClientInfo();
|
||||
LoadInfo.LOOP_BACK = false;
|
||||
|
||||
LoadInfo.CONNECT_IP = ClientCommandEP.Address.ToString();
|
||||
|
||||
LoadInfo.COMMAND_PORT = ClientCommandEP.Port;
|
||||
LoadInfo.STREAM_PORT = ClientStreamEP.Port;
|
||||
|
||||
LoadInfo.READ_INFO_STATE = true;
|
||||
|
||||
StateAdaptorConnect = true;
|
||||
}
|
||||
|
||||
private void SetEpCommandStream()
|
||||
{
|
||||
if (LoadInfo.LOOP_BACK)
|
||||
{
|
||||
ClientCommandEP = new IPEndPoint(IPAddress.Loopback, LoadInfo.COMMAND_PORT);
|
||||
ClientStreamEP = new IPEndPoint(IPAddress.Loopback, LoadInfo.STREAM_PORT);
|
||||
}
|
||||
else
|
||||
{
|
||||
ClientCommandEP = new IPEndPoint(IPAddress.Parse(LoadInfo.CONNECT_IP), LoadInfo.COMMAND_PORT);
|
||||
ClientStreamEP = new IPEndPoint(IPAddress.Parse(LoadInfo.CONNECT_IP), LoadInfo.STREAM_PORT);
|
||||
}
|
||||
}
|
||||
|
||||
private void AdaptorAbort(bool bForceClear = false)
|
||||
{
|
||||
ClearCommonVar();
|
||||
|
||||
ClearCommandWatchTask();
|
||||
ClearStreamWatchTask();
|
||||
|
||||
if (bForceClear == true)
|
||||
{
|
||||
try
|
||||
{
|
||||
XAdaptorLogWrite("AdaptorAbort - Command Socket Disconnect");
|
||||
XAdaptorLogWrite("AdaptorAbort - Stream Socket Disconnect");
|
||||
|
||||
streCommandConnectWatch.Restart();
|
||||
|
||||
streStreamConnectWatch.Restart();
|
||||
|
||||
thisConnInfo.ConnectCommandState = false;
|
||||
thisConnInfo.ConnectStreamState = false;
|
||||
|
||||
SubscribeConnectInfo.Initialize();
|
||||
|
||||
StateClientSocketConnect = false;
|
||||
StateClientGetInformation = false;
|
||||
StateClientStreamSocketConnect = false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"Abort socket all-clear information error. [SystemX.Net.XAdaptor.PC : XPCAdaptor.AdaptorAbort]\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
OnCommandDisconnectAlarm(null, null);
|
||||
OnStreamDisconnectAlarm(null, null);
|
||||
|
||||
ClearCommandClientInstance();
|
||||
ClearStreamClientInstance();
|
||||
}
|
||||
|
||||
private async void ReConnectTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
if (m_bTimerLock[(int)TIMER_LOCK.RECONNECT_TIMER] == false)
|
||||
{
|
||||
m_bTimerLock[(int)TIMER_LOCK.RECONNECT_TIMER] = true;
|
||||
|
||||
if(SubscribeConnectInfo.bSetChangeConnect)
|
||||
{
|
||||
if (SubscribeConnectInfo.bReqConnectAbort == false)
|
||||
SubscribeConnectInfo.bReqConnectAbort = true;
|
||||
else
|
||||
{
|
||||
if (bReqConnectFailed)
|
||||
{
|
||||
bReqConnectFailed = false;
|
||||
|
||||
if (nReqConnectNum < 2)
|
||||
{
|
||||
SubscribeConnectInfo.bSetChangeConnect = false;
|
||||
|
||||
await ComClientTryDistributionConnet();
|
||||
}
|
||||
else
|
||||
SubscribeConnectInfo.bSetChangeConnect = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ConnectStartStyleAuto == false)
|
||||
SubscribeConnectInfo.bSetChangeConnect = false;
|
||||
else
|
||||
{
|
||||
if (await ComClientTryConnet(SubscribeConnectInfo.nChangeCommandPort, SubscribeConnectInfo.nChangeStreamPort))
|
||||
SubscribeConnectInfo.bSetChangeConnect = false;
|
||||
else
|
||||
{
|
||||
AdaptorAbort();
|
||||
|
||||
bReqConnectFailed = true;
|
||||
nReqConnectNum++;
|
||||
|
||||
SubscribeConnectInfo.bReqConnectAbort = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (SubscribeConnectInfo.bUIMUseMode && SubscribeConnectInfo.bSessionStarted)
|
||||
{
|
||||
if (LoadInfo.SESSION_TIMEOUT_TIME_S > 0.0)
|
||||
{
|
||||
if (SubscribeConnectInfo.GetSessionTime().TotalSeconds >= LoadInfo.SESSION_TIMEOUT_TIME_S)
|
||||
{
|
||||
AdaptorAbort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
/*
|
||||
if (START_EVENT_TRIGGER[0])
|
||||
{
|
||||
START_EVENT_TRIGGER[0] = false;
|
||||
|
||||
//CommandConnectAlarmEvent?.BeginInvoke(null, null, null, null);
|
||||
//CommandConnectAlarmEvent?.Invoke(null, null);
|
||||
|
||||
OnCommandConnectAlarm(null, null);
|
||||
}
|
||||
if (START_EVENT_TRIGGER[1])
|
||||
{
|
||||
START_EVENT_TRIGGER[1] = false;
|
||||
|
||||
//StreamConnectAlarmEvent?.BeginInvoke(null, null, null, null);
|
||||
//StreamConnectAlarmEvent?.Invoke(null, null);
|
||||
|
||||
OnStreamConnectAlarm(null, null);
|
||||
}
|
||||
*/
|
||||
//
|
||||
/*
|
||||
//Command Stream Conn Check
|
||||
if (StateClientSocketConnect == false)
|
||||
goto ROUTINE_OUT;
|
||||
if (thisConnInfo.stCommandCheckTime.ElapsedMilliseconds >= 60000)
|
||||
{
|
||||
SendCommandConnectState();
|
||||
|
||||
thisConnInfo.OnCommandCheckTime();
|
||||
}
|
||||
//
|
||||
if (StateClientStreamSocketConnect == false)
|
||||
goto ROUTINE_OUT;
|
||||
if (thisConnInfo.stStreamCheckTime.ElapsedMilliseconds >= 60000)
|
||||
{
|
||||
SendStreamConnectState();
|
||||
|
||||
thisConnInfo.OnStreamCheckTime();
|
||||
}
|
||||
|
||||
ROUTINE_OUT:
|
||||
*/
|
||||
|
||||
m_bTimerLock[(int)TIMER_LOCK.RECONNECT_TIMER] = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void Initialize(IPEndPoint SetCommandEp = null, IPEndPoint SetStreamEp = null)
|
||||
{
|
||||
waitCommandParam = new WaitParameter();
|
||||
waitStreamParam = new WaitParameter();
|
||||
|
||||
mgrPRODTestList = CreateTestListMgr();
|
||||
|
||||
bReqConnectFailed = false;
|
||||
nReqConnectNum = 0;
|
||||
|
||||
//Ng code decoder
|
||||
dbNgCodeFinder = null;
|
||||
|
||||
ClientReadyEndPoint = false;
|
||||
|
||||
if (SetCommandEp != null && SetStreamEp != null)
|
||||
{
|
||||
ClientCommandEP = SetCommandEp;
|
||||
ClientStreamEP = SetStreamEp;
|
||||
|
||||
ClientReadyEndPoint = true;
|
||||
}
|
||||
|
||||
MessageOutput.PrintLogLevel = LogMessageLevel.INFO;
|
||||
|
||||
StateAdaptorConnect = true;
|
||||
//
|
||||
StateClientSocketConnect = false;
|
||||
StateClientStreamSocketConnect = false;
|
||||
//
|
||||
StateClientGetInformation = false;
|
||||
//
|
||||
ClientCommandSock = null;
|
||||
ClientStreamSock = null;
|
||||
|
||||
FlowCommandControl = null;
|
||||
FlowStreamControl = null;
|
||||
|
||||
RecvWaitEvent += RecvWaitEventCall;
|
||||
|
||||
thisConnInfo = new ClientInfoStore();
|
||||
//
|
||||
m_bTimerLock = new bool[10];
|
||||
Array.Clear(m_bTimerLock, 0, 10);
|
||||
//
|
||||
if (ClientReadyEndPoint == false)
|
||||
CheckConfigFileBuildEndPoint();
|
||||
else
|
||||
SetDefaultConfig();
|
||||
//
|
||||
if (StateAdaptorConnect)
|
||||
{
|
||||
;//
|
||||
}
|
||||
//
|
||||
thisConnInfo.OnCommandTime();
|
||||
thisConnInfo.OnCommandCheckTime();
|
||||
|
||||
thisConnInfo.OnStreamTime();
|
||||
thisConnInfo.OnStreamCheckTime();
|
||||
//
|
||||
//if (CLIENT_AUTO_CONNECT)
|
||||
SetRetryTimer();
|
||||
}
|
||||
|
||||
// TODO : FTP ALIS
|
||||
internal eFTPServiceStatus StartFTPService()
|
||||
{
|
||||
if (LoadInfo.FTP_Use)
|
||||
{
|
||||
ControlFTP = new CtrlFTP(LoadInfo.FTP_Use,
|
||||
IPAddress.Parse(LoadInfo.FTP_IPAddress), Convert.ToInt32(LoadInfo.FTP_Port),
|
||||
LoadInfo.FTP_Account, LoadInfo.FTP_Password);
|
||||
|
||||
if (ControlFTP.FTPConnState)
|
||||
return eFTPServiceStatus.Connected;
|
||||
else
|
||||
return eFTPServiceStatus.Disconnected;
|
||||
}
|
||||
else
|
||||
return eFTPServiceStatus.Unused;
|
||||
}
|
||||
|
||||
public DataSet WaitSystemQuery(string strQuery)
|
||||
{
|
||||
if (thisConnInfo.ConnectCommandState == false)
|
||||
return null;
|
||||
if (thisConnInfo.InitialInfoState == false)
|
||||
return null;
|
||||
if (LoadInfo.SIMPLE_LOOKUP_OPTION == true)
|
||||
return null;
|
||||
|
||||
DataSet dsReturnSet = null;
|
||||
|
||||
try
|
||||
{
|
||||
thisConnInfo.OnCommandTime();
|
||||
|
||||
try
|
||||
{
|
||||
QUERY_PACKET QueryPacket = new QUERY_PACKET();
|
||||
int iSizeQueryPacket = Marshal.SizeOf(QueryPacket);
|
||||
byte[] ucQueryPacketArray = new byte[iSizeQueryPacket];
|
||||
QueryPacket = (QUERY_PACKET)SystemXNetSerialization.RawDeSerialize(ucQueryPacketArray, QueryPacket.GetType());
|
||||
QueryPacket.objQueryText[0].Data = strQuery;
|
||||
ucQueryPacketArray = XCommons.SpecialObjectToByteStream(new BASE_PROTOCOL(BASE_PROTOCOL.PROTOCOL_CODE.SYSTEM_QUERY), QueryPacket);
|
||||
|
||||
byte ucGetLabel = FlowCommandControl.InsertSendQueue(DateTime.Now, ucQueryPacketArray, null, true);
|
||||
|
||||
WaitThreadJoin(waitCommandParam, FlowCommandControl, ucGetLabel);
|
||||
|
||||
if (QueryResult.QueryDataSet != null)
|
||||
{
|
||||
if (QueryResult.bQueryResult) //Query 문 실행 성공
|
||||
dsReturnSet = QueryResult.QueryDataSet;
|
||||
else //Query 문 실행 실패(구문 오류 또는 연결 오류)
|
||||
dsReturnSet = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"Internal use program query failure. [" + strQuery + "][SystemX.Net.XAdaptor.PC - IXPCAdaptor : XPCAdaptor.WaitSystemQuery]\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.FATAL);
|
||||
}
|
||||
finally
|
||||
{
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
return dsReturnSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,647 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using SystemX.Common;
|
||||
using SystemX.Common.Serialization;
|
||||
using SystemX.Net.BaseProtocol;
|
||||
using SystemX.Net.Comm;
|
||||
using SystemX.Net.XAdaptor.PC.O2Sensor.NgCode;
|
||||
using SystemX.Net.Schedule;
|
||||
using static SystemX.Net.Platform.Common.Util.LogMessage;
|
||||
using WTimer = System.Windows.Forms.Timer;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC
|
||||
{
|
||||
public partial class XAdaptorPC
|
||||
{
|
||||
protected override void OnCommandConnectAlarm(object sender, EventArgs e)
|
||||
{
|
||||
// Safely raise the event for all subscribers
|
||||
base.OnCommandConnectAlarm(sender, e);
|
||||
}
|
||||
protected override void OnStreamConnectAlarm(object sender, EventArgs e)
|
||||
{
|
||||
// Safely raise the event for all subscribers
|
||||
base.OnStreamConnectAlarm(sender, e);
|
||||
}
|
||||
|
||||
protected override void OnConnectionInfoRecv(object sender, EventArgs e)
|
||||
{
|
||||
// Safely raise the event for all subscribers
|
||||
base.OnConnectionInfoRecv(sender, e);
|
||||
}
|
||||
|
||||
protected override void OnCommandDisconnectAlarm(object sender, EventArgs e)
|
||||
{
|
||||
// Safely raise the event for all subscribers
|
||||
base.OnCommandDisconnectAlarm(sender, e);
|
||||
}
|
||||
protected override void OnStreamDisconnectAlarm(object sender, EventArgs e)
|
||||
{
|
||||
// Safely raise the event for all subscribers
|
||||
base.OnStreamDisconnectAlarm(sender, e);
|
||||
}
|
||||
|
||||
protected override void OnLoginAlarm(object sender, EventArgs e)
|
||||
{
|
||||
// Safely raise the event for all subscribers
|
||||
base.OnLoginAlarm(sender, e);
|
||||
}
|
||||
|
||||
protected override void OnQueryCall(object sender, ResultEventArgs e)
|
||||
{
|
||||
// Safely raise the event for all subscribers
|
||||
base.OnQueryCall(sender, e);
|
||||
}
|
||||
protected override void OnBeginQueryCall(object sender, ResultEventArgs e)
|
||||
{
|
||||
// Safely raise the event for all subscribers
|
||||
base.OnBeginQueryCall(sender, e);
|
||||
}
|
||||
|
||||
private void ClientCommandConnectEvent(object sender, ScheduleEvent e)
|
||||
{
|
||||
string strGetMsg = string.Empty;
|
||||
if (e != null)
|
||||
strGetMsg = e.STATE_MSG;
|
||||
|
||||
XAdaptorLogWrite("Command Socket Connect");
|
||||
|
||||
streCommandConnectWatch.Restart();
|
||||
|
||||
thisConnInfo.ConnectCommandState = true;
|
||||
|
||||
//ConnectCommandWaitEvent.Set();
|
||||
bConnectCommandSocketFlag = true;
|
||||
|
||||
thisConnInfo.OnCommandTime();
|
||||
thisConnInfo.OnCommandCheckTime();
|
||||
|
||||
StateClientSocketConnect = true;
|
||||
|
||||
//CommandConnectAlarmEvent?.BeginInvoke(null, null, null, null);
|
||||
//CommandConnectAlarmEvent?.Invoke(null, null);
|
||||
OnCommandConnectAlarm(null, null);
|
||||
}
|
||||
|
||||
private void ClientCommandErrorEvent(object sender, ScheduleEvent e)
|
||||
{
|
||||
string strGetMsg = string.Empty;
|
||||
if (e != null)
|
||||
strGetMsg = e.STATE_MSG;
|
||||
|
||||
XAdaptorLogWrite("Command Socket Disconnect");
|
||||
|
||||
ClearCommandWatchTask();
|
||||
|
||||
streCommandConnectWatch.Restart();
|
||||
|
||||
thisConnInfo.ConnectCommandState = false;
|
||||
|
||||
//ConnectCommandWaitEvent.Reset();
|
||||
bConnectCommandSocketFlag = false;
|
||||
|
||||
StateClientSocketConnect = false;
|
||||
StateClientGetInformation = false;
|
||||
|
||||
//SubscribeConnectInfo.Initialize();
|
||||
|
||||
//CommandDisconnectAlarmEvent?.BeginInvoke(null, null, null, null);
|
||||
//CommandDisconnectAlarmEvent?.Invoke(null, null);
|
||||
OnCommandDisconnectAlarm(null, null);
|
||||
}
|
||||
|
||||
private void ClientStreamConnectEvent(object sender, ScheduleEvent e)
|
||||
{
|
||||
string strGetMsg = string.Empty;
|
||||
|
||||
if (e != null)
|
||||
strGetMsg = e.STATE_MSG;
|
||||
|
||||
XAdaptorLogWrite("Stream Socket Connect");
|
||||
|
||||
stFileSendTime.Restart();
|
||||
stBackupFileSendTime.Restart();
|
||||
|
||||
streStreamConnectWatch.Restart();
|
||||
|
||||
thisConnInfo.ConnectStreamState = true;
|
||||
|
||||
//ConnectStreamWaitEvent.Set();
|
||||
bConnectStreamSocketFlag = true;
|
||||
|
||||
thisConnInfo.OnStreamTime();
|
||||
thisConnInfo.OnStreamCheckTime();
|
||||
|
||||
StateClientStreamSocketConnect = true;
|
||||
|
||||
//StreamConnectAlarmEvent?.BeginInvoke(null, null, null, null);
|
||||
//StreamConnectAlarmEvent?.Invoke(null, null);
|
||||
OnStreamConnectAlarm(null, null);
|
||||
}
|
||||
|
||||
private void ClientStreamErrorEvent(object sender, ScheduleEvent e)
|
||||
{
|
||||
string strGetMsg = string.Empty;
|
||||
if (e != null)
|
||||
strGetMsg = e.STATE_MSG;
|
||||
|
||||
XAdaptorLogWrite("Stream Socket Disconnect");
|
||||
|
||||
ClearStreamWatchTask();
|
||||
|
||||
streStreamConnectWatch.Restart();
|
||||
|
||||
thisConnInfo.ConnectStreamState = false;
|
||||
|
||||
//ConnectStreamWaitEvent.Reset();
|
||||
bConnectStreamSocketFlag = false;
|
||||
|
||||
StateClientStreamSocketConnect = false;
|
||||
|
||||
//SubscribeConnectInfo.Initialize();
|
||||
|
||||
//StreamDisconnectAlarmEvent?.BeginInvoke(null, null, null, null);
|
||||
//StreamDisconnectAlarmEvent?.Invoke(null, null);
|
||||
OnStreamDisconnectAlarm(null, null);
|
||||
}
|
||||
|
||||
private async Task<bool> SendCommandConnectState(bool bWaitRespons = false)
|
||||
{
|
||||
if (thisConnInfo.ConnectCommandState == false)
|
||||
return false;
|
||||
|
||||
if (thisConnInfo.stCommandCheckTime.ElapsedMilliseconds < 60000)
|
||||
return true;
|
||||
|
||||
bool bResult = true;
|
||||
|
||||
try
|
||||
{
|
||||
thisConnInfo.OnCommandTime();
|
||||
|
||||
try
|
||||
{
|
||||
PING_PACKET MakePingPacket = new PING_PACKET();
|
||||
int iSendSize = Marshal.SizeOf(MakePingPacket);
|
||||
byte[] ucSendArray = new byte[iSendSize];
|
||||
MakePingPacket = (PING_PACKET)SystemXNetSerialization.RawDeSerialize(ucSendArray, MakePingPacket.GetType());
|
||||
|
||||
MakePingPacket.objCheckMsg[0].Data = "Who?";
|
||||
|
||||
byte[] ucSendByteInfo = XCommons.SpecialObjectToByteStream(new BASE_PROTOCOL(BASE_PROTOCOL.PROTOCOL_CODE.CONNECT_STATE), MakePingPacket);
|
||||
|
||||
byte ucGetLabel = FlowCommandControl.InsertSendQueue(DateTime.Now, ucSendByteInfo, null, bWaitRespons);
|
||||
|
||||
thisConnInfo.OnCommandCheckTime();
|
||||
|
||||
if (bWaitRespons)
|
||||
{
|
||||
await WaitTaskJoin(waitCommandParam, FlowCommandControl, ucGetLabel, false).ConfigureAwait(false);
|
||||
|
||||
if (QueryResult.bQueryResult)
|
||||
bResult = true;
|
||||
else
|
||||
bResult = false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"Command Socket ping check error. [SystemX.Net.XAdaptor.PC : XPCAdaptor.SendCommandConnectState]\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
finally { }
|
||||
}
|
||||
finally
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
return bResult;
|
||||
}
|
||||
|
||||
private async Task<bool> SendStreamConnectState(bool bWaitRespons = false)
|
||||
{
|
||||
if (thisConnInfo.ConnectStreamState == false)
|
||||
return false;
|
||||
|
||||
if (thisConnInfo.stStreamCheckTime.ElapsedMilliseconds < 60000)
|
||||
return true;
|
||||
|
||||
bool bResult = true;
|
||||
|
||||
try
|
||||
{
|
||||
thisConnInfo.OnStreamTime();
|
||||
|
||||
try
|
||||
{
|
||||
PING_PACKET MakePingPacket = new PING_PACKET();
|
||||
int iSendSize = Marshal.SizeOf(MakePingPacket);
|
||||
byte[] ucSendArray = new byte[iSendSize];
|
||||
MakePingPacket = (PING_PACKET)SystemXNetSerialization.RawDeSerialize(ucSendArray, MakePingPacket.GetType());
|
||||
|
||||
MakePingPacket.objCheckMsg[0].Data = "Who?";
|
||||
|
||||
byte[] ucSendByteInfo = XCommons.SpecialObjectToByteStream(new BASE_PROTOCOL(BASE_PROTOCOL.PROTOCOL_CODE.CONNECT_STATE), MakePingPacket);
|
||||
|
||||
byte ucGetLabel = FlowStreamControl.InsertSendQueue(DateTime.Now, ucSendByteInfo, null, bWaitRespons);
|
||||
|
||||
thisConnInfo.OnStreamCheckTime();
|
||||
|
||||
if (bWaitRespons)
|
||||
{
|
||||
await WaitTaskJoin(waitStreamParam, FlowStreamControl, ucGetLabel, false).ConfigureAwait(false);
|
||||
|
||||
if (QueryResult.bQueryResult)
|
||||
bResult = true;
|
||||
else
|
||||
bResult = false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"Stream Socket ping check error. [SystemX.Net.XAdaptor.PC : XPCAdaptor.SendStreamConnectState]\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
finally { }
|
||||
}
|
||||
finally
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
return bResult;
|
||||
}
|
||||
|
||||
// The delegate must have the same signature as the method
|
||||
// it will call asynchronously.
|
||||
public delegate string AsyncMethodCaller(int callDuration, out int threadId);
|
||||
//public delegate void RecvWaitEventHandler(WaitParameter sender, EventArgs e);
|
||||
public delegate void RecvWaitEventHandler(WaitParameter sender, EventArgs e);
|
||||
|
||||
private void RecvWaitEventCall(WaitParameter sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"RecvWaitEventCall failed. [SystemX.Net.XAdaptor.PC.XPCAdaptor : XPCAdaptor.EventCall()]\r\n" + ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
finally
|
||||
{
|
||||
sender.nSignaled = 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void RecvWaitEnd(IAsyncResult ar)
|
||||
{
|
||||
// Retrieve the delegate.
|
||||
AsyncResult result = (AsyncResult)ar;
|
||||
}
|
||||
|
||||
/*
|
||||
private void WaitTskJoin(WaitParameter wp, PacketFlowControl getPF, byte ucGetLabel, bool bUseDataSet = true, long lTimeOut = COMMAND_TIME_OUT)
|
||||
{
|
||||
wp.Init(getPF);
|
||||
|
||||
Thread t = new Thread(delegate () {
|
||||
QueryResult.Initialize();
|
||||
QueryResult.xData = wp.TskCheckResult(ucGetLabel, lTimeOut);
|
||||
if (QueryResult.xData != null)
|
||||
{
|
||||
QueryResult.bQueryResult = QueryResult.xData.bReplayResult;
|
||||
|
||||
if (bUseDataSet)
|
||||
QueryResult.QueryDataSet = QueryResult.xData.objData as DataSet;
|
||||
else
|
||||
{
|
||||
QueryResult.QueryDataSet = null;
|
||||
|
||||
if (QueryResult.xData.objData is TRANSFER_PACKET)
|
||||
{
|
||||
TRANSFER_PACKET TransferResult = (TRANSFER_PACKET)QueryResult.xData.objData;
|
||||
|
||||
byte ucCheckLabel = QueryResult.xData.nLabel;
|
||||
|
||||
QueryResult.bFileRecvResult = TransferResult.bRecvResult;
|
||||
QueryResult.bFileProcessResult = TransferResult.bProcessResult;
|
||||
}
|
||||
else if (QueryResult.xData.objData is COMM_INFO_PACKET)
|
||||
{
|
||||
COMM_INFO_PACKET Result = (COMM_INFO_PACKET)QueryResult.xData.objData;
|
||||
|
||||
byte ucCheckLabel = QueryResult.xData.nLabel;
|
||||
}
|
||||
}
|
||||
|
||||
QueryResult.strVarParam1 = QueryResult.xData.HeaderPacket.objVarParam1[0].Data;
|
||||
QueryResult.strVarParam2 = QueryResult.xData.HeaderPacket.objVarParam2[0].Data;
|
||||
QueryResult.strVarParam3 = QueryResult.xData.HeaderPacket.objVarParam3[0].Data;
|
||||
}
|
||||
else
|
||||
getPF.STM.ClearLabel(ucGetLabel);
|
||||
});
|
||||
|
||||
t.Start();
|
||||
t.Join();
|
||||
}
|
||||
*/
|
||||
|
||||
private void WaitThreadJoin(WaitParameter wp, PacketFlowControl getPF, byte ucGetLabel, bool bUseDataSet = true, long lTimeOut = COMMAND_TIME_OUT)
|
||||
{
|
||||
wp.Init(getPF);
|
||||
|
||||
Thread t = new Thread(delegate ()
|
||||
{
|
||||
QueryResult.Initialize();
|
||||
QueryResult.xData = wp.ThreadWaitResult(ucGetLabel, lTimeOut);
|
||||
|
||||
if (QueryResult.xData != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
QueryResult.bQueryResult = QueryResult.xData.bReplayResult;
|
||||
|
||||
if (bUseDataSet)
|
||||
QueryResult.QueryDataSet = QueryResult.xData.objData as DataSet;
|
||||
else
|
||||
{
|
||||
QueryResult.QueryDataSet = null;
|
||||
|
||||
if (QueryResult.xData.objData is TRANSFER_PACKET)
|
||||
{
|
||||
TRANSFER_PACKET TransferResult = (TRANSFER_PACKET)QueryResult.xData.objData;
|
||||
|
||||
byte ucCheckLabel = QueryResult.xData.nLabel;
|
||||
|
||||
QueryResult.bFileRecvResult = TransferResult.bRecvResult;
|
||||
QueryResult.bFileProcessResult = TransferResult.bProcessResult;
|
||||
}
|
||||
else if (QueryResult.xData.objData is COMM_INFO_PACKET)
|
||||
{
|
||||
COMM_INFO_PACKET Result = (COMM_INFO_PACKET)QueryResult.xData.objData;
|
||||
|
||||
byte ucCheckLabel = QueryResult.xData.nLabel;
|
||||
}
|
||||
}
|
||||
|
||||
QueryResult.strVarParam1 = QueryResult.xData.HeaderPacket.objVarParam1[0].Data;
|
||||
QueryResult.strVarParam2 = QueryResult.xData.HeaderPacket.objVarParam2[0].Data;
|
||||
QueryResult.strVarParam3 = QueryResult.xData.HeaderPacket.objVarParam3[0].Data;
|
||||
}
|
||||
catch
|
||||
{
|
||||
QueryResult.bQueryResult = false;
|
||||
QueryResult.QueryDataSet = null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
;//
|
||||
}
|
||||
}
|
||||
else
|
||||
getPF.STM.ClearLabel(ucGetLabel);
|
||||
});
|
||||
|
||||
t.Start();
|
||||
t.Join();
|
||||
}
|
||||
|
||||
private async Task<bool> WaitTaskJoin(WaitParameter wp, PacketFlowControl getPF, byte ucGetLabel, bool bUseDataSet = true)
|
||||
{
|
||||
wp.Init(getPF);
|
||||
|
||||
bool bSetResult = true;
|
||||
|
||||
QueryResult.Initialize();
|
||||
QueryResult.xData = await wp.TaskWaitResult(ucGetLabel).ConfigureAwait(false);
|
||||
if (QueryResult.xData != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
QueryResult.bQueryResult = QueryResult.xData.bReplayResult;
|
||||
|
||||
if (bUseDataSet)
|
||||
QueryResult.QueryDataSet = QueryResult.xData.objData as DataSet;
|
||||
else
|
||||
{
|
||||
QueryResult.QueryDataSet = null;
|
||||
|
||||
if (QueryResult.xData.objData is TRANSFER_PACKET)
|
||||
{
|
||||
TRANSFER_PACKET TransferResult = (TRANSFER_PACKET)QueryResult.xData.objData;
|
||||
|
||||
byte ucCheckLabel = QueryResult.xData.nLabel;
|
||||
|
||||
QueryResult.bFileRecvResult = TransferResult.bRecvResult;
|
||||
QueryResult.bFileProcessResult = TransferResult.bProcessResult;
|
||||
}
|
||||
else if (QueryResult.xData.objData is COMM_INFO_PACKET)
|
||||
{
|
||||
COMM_INFO_PACKET Result = (COMM_INFO_PACKET)QueryResult.xData.objData;
|
||||
|
||||
byte ucCheckLabel = QueryResult.xData.nLabel;
|
||||
}
|
||||
}
|
||||
|
||||
QueryResult.strVarParam1 = QueryResult.xData.HeaderPacket.objVarParam1[0].Data;
|
||||
QueryResult.strVarParam2 = QueryResult.xData.HeaderPacket.objVarParam2[0].Data;
|
||||
QueryResult.strVarParam3 = QueryResult.xData.HeaderPacket.objVarParam3[0].Data;
|
||||
}
|
||||
catch
|
||||
{
|
||||
QueryResult.bQueryResult = false;
|
||||
QueryResult.QueryDataSet = null;
|
||||
|
||||
bSetResult = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
;//
|
||||
}
|
||||
|
||||
return bSetResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
getPF.STM.ClearLabel(ucGetLabel);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private XData ComWaitResult(byte nCheckLabel)
|
||||
{
|
||||
XData getXData = null;
|
||||
bool bWaitLabel = false;
|
||||
|
||||
if (nCheckLabel < 0 || nCheckLabel >= FlowCommandControl.STM.GetLabelSize())
|
||||
return getXData;
|
||||
|
||||
Stopwatch stWaitTImeWatch = new Stopwatch();
|
||||
stWaitTImeWatch.Start();
|
||||
|
||||
while (stWaitTImeWatch.ElapsedMilliseconds <= COMMAND_TIME_OUT)
|
||||
{
|
||||
Application.DoEvents();
|
||||
|
||||
getXData = FlowCommandControl.STM.CheckLabel(nCheckLabel, ref bWaitLabel);
|
||||
|
||||
if (bWaitLabel)
|
||||
break;
|
||||
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
|
||||
return getXData;
|
||||
}
|
||||
|
||||
public class WaitParameter
|
||||
{
|
||||
public int nSignaled;
|
||||
public bool tResult;
|
||||
|
||||
private PacketFlowControl fc;
|
||||
|
||||
public WaitParameter()
|
||||
{
|
||||
nSignaled = 0;
|
||||
tResult = false;
|
||||
}
|
||||
|
||||
public void Init(PacketFlowControl getFc)
|
||||
{
|
||||
nSignaled = 0;
|
||||
tResult = false;
|
||||
|
||||
fc = getFc;
|
||||
}
|
||||
|
||||
/*
|
||||
public XData TskCheckResult(byte nCheckLabel, long lTimeOut = COMMAND_TIME_OUT)
|
||||
{
|
||||
XData getXData = null;
|
||||
bool bWaitLabel = false;
|
||||
|
||||
if (nCheckLabel < 0 || nCheckLabel >= fc.STM.GetLabelSize())
|
||||
return getXData;
|
||||
|
||||
Stopwatch stWaitTImeWatch = new Stopwatch();
|
||||
stWaitTImeWatch.Start();
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (stWaitTImeWatch.ElapsedMilliseconds >= lTimeOut)
|
||||
break;
|
||||
|
||||
if (nSignaled == 1)
|
||||
{
|
||||
getXData = fc.STM.CheckLabel(nCheckLabel, ref bWaitLabel);
|
||||
|
||||
if (bWaitLabel)
|
||||
{
|
||||
tResult = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
|
||||
return getXData;
|
||||
}
|
||||
*/
|
||||
|
||||
public XData ThreadWaitResult(byte nCheckLabel, long lTimeOut = COMMAND_TIME_OUT)
|
||||
{
|
||||
XData getXData = null;
|
||||
bool bWaitLabel = false;
|
||||
|
||||
if (nCheckLabel < 0 || nCheckLabel >= fc.STM.GetLabelSize())
|
||||
return getXData;
|
||||
|
||||
Stopwatch stWaitTImeWatch = new Stopwatch();
|
||||
stWaitTImeWatch.Start();
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (stWaitTImeWatch.ElapsedMilliseconds > lTimeOut)
|
||||
{
|
||||
fc.SetRefSocketPacketClear();
|
||||
|
||||
break;
|
||||
}
|
||||
if (nSignaled == 1)
|
||||
{
|
||||
getXData = fc.STM.CheckLabel(nCheckLabel, ref bWaitLabel);
|
||||
|
||||
if (bWaitLabel)
|
||||
{
|
||||
tResult = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
|
||||
return getXData;
|
||||
}
|
||||
|
||||
public async Task<XData> TaskWaitResult(byte nCheckLabel)
|
||||
{
|
||||
XData getXData = null;
|
||||
bool bWaitLabel = false;
|
||||
|
||||
if (nCheckLabel < 0 || nCheckLabel >= fc.STM.GetLabelSize())
|
||||
return getXData;
|
||||
|
||||
Stopwatch stWaitTImeWatch = new Stopwatch();
|
||||
stWaitTImeWatch.Start();
|
||||
|
||||
while (true)
|
||||
{
|
||||
if(stWaitTImeWatch.ElapsedMilliseconds > COMMAND_TIME_OUT)
|
||||
{
|
||||
fc.SetRefSocketPacketClear();
|
||||
|
||||
break;
|
||||
}
|
||||
if (nSignaled == 1)
|
||||
{
|
||||
getXData = fc.STM.CheckLabel(nCheckLabel, ref bWaitLabel);
|
||||
|
||||
if (bWaitLabel)
|
||||
{
|
||||
tResult = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
await Task.Delay(1).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return getXData;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SystemX.Net.XAdaptor;
|
||||
using static SystemX.Net.Platform.Common.Util.LogMessage;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC
|
||||
{
|
||||
public partial class XAdaptorPC
|
||||
{
|
||||
private async Task<bool> CheckFileAccess(string strFilePos)
|
||||
{
|
||||
bool bAccessResult = true;
|
||||
|
||||
//File Access Check
|
||||
FileStream fs = null;
|
||||
|
||||
try
|
||||
{
|
||||
//0.1초 간격으로 3회 체크 후 성공 반환
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
fs = new FileStream(strFilePos, FileMode.Open, FileAccess.Read);
|
||||
|
||||
if (fs != null)
|
||||
{
|
||||
fs.Close();
|
||||
fs = null;
|
||||
}
|
||||
|
||||
await Task.Delay(100).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (fs != null)
|
||||
{
|
||||
fs.Close();
|
||||
fs = null;
|
||||
}
|
||||
|
||||
bAccessResult = false;
|
||||
|
||||
//File Access fail next file
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"Send file access check fail." + strFilePos + " [SystemX.Net.XAdaptor.PC : XPCAdaptor.WatchLogFolderScan]\r\n" + ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
|
||||
return bAccessResult;
|
||||
}
|
||||
private async Task<int> DirFileSearch(string strCreateName, string strSetPath, string fileExtension, bool bCpLogFileSend)
|
||||
{
|
||||
try
|
||||
{
|
||||
string[] dirs = Directory.GetDirectories(strSetPath);
|
||||
string[] files = Directory.GetFiles(strSetPath, $"*.{fileExtension}");
|
||||
|
||||
if (files.Length > 0)
|
||||
{
|
||||
foreach (string f in files)
|
||||
{
|
||||
if (await CheckFileAccess(f).ConfigureAwait(false))
|
||||
{
|
||||
if (FlowStreamControl.getRawQueueCnt() > 0)
|
||||
break;
|
||||
|
||||
//FileProcess
|
||||
if (bCpLogFileSend)
|
||||
{
|
||||
if (CPLogFileTransfer(f) == eFileSendRecvResult.FileProcSuccess)
|
||||
{
|
||||
Random randNumber = new Random();
|
||||
|
||||
string getFileName = Path.GetFileName(f);
|
||||
|
||||
if (File.Exists(strCreateName + getFileName))
|
||||
{
|
||||
File.Delete(strCreateName + getFileName);
|
||||
File.Move(f, strCreateName + getFileName);
|
||||
}
|
||||
else
|
||||
File.Move(f, strCreateName + getFileName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SendCustomFile(f) == eFileSendRecvResult.FileProcSuccess)
|
||||
{
|
||||
Random randNumber = new Random();
|
||||
|
||||
string getFileName = Path.GetFileName(f);
|
||||
|
||||
if (File.Exists(strCreateName + getFileName))
|
||||
{
|
||||
File.Delete(strCreateName + getFileName);
|
||||
File.Move(f, strCreateName + getFileName);
|
||||
}
|
||||
else
|
||||
File.Move(f, strCreateName + getFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//1 time 1 file slow process per 0.25 second
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (dirs.Length > 0)
|
||||
{
|
||||
foreach (string dir in dirs)
|
||||
{
|
||||
if (dir.IndexOf("Backup Folder") >= 0)
|
||||
continue;
|
||||
|
||||
await DirFileSearch(strCreateName, dir, fileExtension, bCpLogFileSend);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
|
||||
await Task.Delay(1).ConfigureAwait(false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,498 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using SystemX.Common;
|
||||
using SystemX.Common.Serialization;
|
||||
using SystemX.Net.BaseProtocol;
|
||||
using SystemX.Net.Comm;
|
||||
using SystemX.Net.Schedule;
|
||||
using static SystemX.Net.Platform.Common.Util.LogMessage;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC
|
||||
{
|
||||
[ComVisible(true)]
|
||||
[Guid("837C547C-E1EC-453E-BA98-2F5EEDFD6CF6")]
|
||||
[ClassInterface(ClassInterfaceType.None)]
|
||||
[ProgId("SystemX.Net.XAdaptor.PC.XAdaptorPC")]
|
||||
[ComDefaultInterface(typeof(IComXPCAdaptor))]
|
||||
public partial class XAdaptorPC
|
||||
{
|
||||
private string MakeDataSetToText(DataSet ds)
|
||||
{
|
||||
string strMakeText = string.Empty;
|
||||
string strMakeColInfo = "000@";
|
||||
string[] strRowTextArray = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (ds != null)
|
||||
{
|
||||
foreach (DataTable dt in ds.Tables)
|
||||
{
|
||||
strRowTextArray = new string[dt.Rows.Count];
|
||||
|
||||
foreach (DataColumn dc in dt.Columns)
|
||||
strMakeColInfo += dc.ColumnName + ",";
|
||||
|
||||
strMakeColInfo = strMakeColInfo.Remove(strMakeColInfo.Length - 1, 1);
|
||||
|
||||
strMakeColInfo += ";";
|
||||
|
||||
strMakeText = strMakeColInfo;
|
||||
|
||||
int iPos = 0;
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
string[] strRowTrimArray = new string[dr.ItemArray.Count()];
|
||||
for (int i = 0; i < dr.ItemArray.Count(); i++)
|
||||
strRowTrimArray[i] = dr.ItemArray[i].ToString().Trim();
|
||||
|
||||
strRowTextArray[iPos] = string.Join(",", strRowTrimArray);
|
||||
strRowTextArray[iPos] = strRowTextArray[iPos].Trim();
|
||||
|
||||
strMakeText += (iPos + 1).ToString("D3") + "@" + strRowTextArray[iPos] + ";";
|
||||
|
||||
iPos++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (strRowTextArray == null)
|
||||
strMakeText = "";
|
||||
else if (strRowTextArray.Count() <= 0)
|
||||
strMakeText = "";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
strMakeText = "";
|
||||
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"Dataset to text process fail. [SystemX.Net.XAdaptor.PC : XPCAdaptor.MakeDataSetToText]\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
|
||||
return strMakeText;
|
||||
}
|
||||
|
||||
[ComVisible(true)]
|
||||
public bool ComGetClientSocketConnect()
|
||||
{
|
||||
return StateClientSocketConnect;
|
||||
}
|
||||
|
||||
[ComVisible(true)]
|
||||
public bool ComGetClientStreamSocketConnect()
|
||||
{
|
||||
return StateClientStreamSocketConnect;
|
||||
}
|
||||
|
||||
[ComVisible(true)]
|
||||
public bool ComGetClientInfo()
|
||||
{
|
||||
return StateClientGetInformation;
|
||||
}
|
||||
|
||||
[ComVisible(true)]
|
||||
public bool ComGetAdaptorConnectState()
|
||||
{
|
||||
return StateAdaptorConnect;
|
||||
}
|
||||
|
||||
[ComVisible(true)]
|
||||
public string ComGetCommandMessage()
|
||||
{
|
||||
return strCheckCommandMsg;
|
||||
}
|
||||
|
||||
[ComVisible(true)]
|
||||
public string ComGetStreamMessage()
|
||||
{
|
||||
return strCheckCommandMsg;
|
||||
}
|
||||
|
||||
[ComVisible(true)]
|
||||
public async Task<bool> ComClientTryConnet(int nCommandPortNum = int.MaxValue, int nStreamPortNum = int.MaxValue)
|
||||
{
|
||||
bool bResult = true;
|
||||
|
||||
StateAdaptorConnect = true;
|
||||
|
||||
try
|
||||
{
|
||||
//ConnectCommandWaitEvent.Reset();
|
||||
//ConnectStreamWaitEvent.Reset();
|
||||
|
||||
bConnectCommandSocketFlag = false;
|
||||
bConnectStreamSocketFlag = false;
|
||||
|
||||
StateAdaptorConnect &= ClientCommandSet(SOCKET_TYPE.TCP, false, nCommandPortNum);
|
||||
StateAdaptorConnect &= ClientStreamSet(SOCKET_TYPE.TCP, false, nStreamPortNum);
|
||||
|
||||
Stopwatch stWaitConnect = new Stopwatch();
|
||||
stWaitConnect.Start();
|
||||
|
||||
while(stWaitConnect.ElapsedMilliseconds < CONNECT_TIME_OUT)
|
||||
{
|
||||
if(bConnectCommandSocketFlag)
|
||||
{
|
||||
await Task.Delay(100).ConfigureAwait(false);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
await Task.Delay(10).ConfigureAwait(false);
|
||||
}
|
||||
if(bConnectCommandSocketFlag)
|
||||
SetCommandWatchTask();
|
||||
else
|
||||
{
|
||||
bResult = false;
|
||||
|
||||
throw new Exception("Can not connect Command Socket.");
|
||||
}
|
||||
//
|
||||
stWaitConnect.Restart();
|
||||
while (stWaitConnect.ElapsedMilliseconds < CONNECT_TIME_OUT)
|
||||
{
|
||||
if (bConnectStreamSocketFlag)
|
||||
{
|
||||
await Task.Delay(100).ConfigureAwait(false);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
await Task.Delay(10).ConfigureAwait(false);
|
||||
}
|
||||
if (bConnectStreamSocketFlag)
|
||||
SetStreamWatchTask();
|
||||
else
|
||||
{
|
||||
bResult = false;
|
||||
|
||||
throw new Exception("Can not connect Stream Socket.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
bResult = false;
|
||||
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"Client Connection Attempt Error. [SystemX.Net.XAdaptor.PC - IComXPCAdaptor : XPCAdaptor.ComClientTryConnet]\r\n" +
|
||||
ex.Message, ConsoleColor.Red, LogMessageLevel.DEBUG);
|
||||
}
|
||||
finally
|
||||
{
|
||||
;//
|
||||
}
|
||||
|
||||
return bResult;
|
||||
}
|
||||
|
||||
[ComVisible(true)]
|
||||
public async Task<bool> ComClientTryDistributionConnet(int nCommandPortNum = int.MaxValue)
|
||||
{
|
||||
bool bResult = true;
|
||||
|
||||
StateAdaptorConnect = true;
|
||||
|
||||
thisConnInfo.stLoginTimeOut.Restart();
|
||||
|
||||
try
|
||||
{
|
||||
ClearCommandClientInstance();
|
||||
|
||||
//ConnectCommandWaitEvent.Reset();
|
||||
|
||||
bConnectCommandSocketFlag = false;
|
||||
|
||||
StateAdaptorConnect &= ClientCommandSet(SOCKET_TYPE.TCP, true, nCommandPortNum);
|
||||
|
||||
Stopwatch stWaitConnect = new Stopwatch();
|
||||
stWaitConnect.Start();
|
||||
|
||||
while (stWaitConnect.ElapsedMilliseconds < CONNECT_TIME_OUT)
|
||||
{
|
||||
if (bConnectCommandSocketFlag)
|
||||
{
|
||||
await Task.Delay(10).ConfigureAwait(false);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
await Task.Delay(10).ConfigureAwait(false);
|
||||
}
|
||||
if (bConnectCommandSocketFlag)
|
||||
SetCommandWatchTask();
|
||||
else
|
||||
{
|
||||
bResult = false;
|
||||
|
||||
throw new Exception("Can not connect Command Socket.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
bResult = false;
|
||||
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"Client Connection Attempt Error. [SystemX.Net.XAdaptor.PC - IComXPCAdaptor : XPCAdaptor.ComClientTryConnet]\r\n" +
|
||||
ex.Message, ConsoleColor.Red, LogMessageLevel.DEBUG);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (ClientCommandSock.SOCK_TYPE == SOCKET_TYPE.UDP && bResult)
|
||||
{
|
||||
COMM_INFO_PACKET ConnectCommSendInfo = new COMM_INFO_PACKET();
|
||||
int iSendSize = Marshal.SizeOf(ConnectCommSendInfo);
|
||||
byte[] ucSendArray = new byte[iSendSize];
|
||||
ConnectCommSendInfo = (COMM_INFO_PACKET)SystemXNetSerialization.RawDeSerialize(ucSendArray, ConnectCommSendInfo.GetType());
|
||||
|
||||
ConnectCommSendInfo.bPortDistribution = true;
|
||||
|
||||
ConnectCommSendInfo.usPortCommandNumber = (ushort)0;
|
||||
ConnectCommSendInfo.usPortStreamNumber = (ushort)0;
|
||||
|
||||
ConnectCommSendInfo.objConnLocalAddress[0].Data = ClientCommandSock.strGetLocalAddress;
|
||||
ConnectCommSendInfo.objConnLocalPort[0].Data = ClientCommandSock.strGetLocalPort;
|
||||
|
||||
byte[] ucSendByteInfo = XCommons.SpecialObjectToByteStream(new BASE_PROTOCOL(BASE_PROTOCOL.PROTOCOL_CODE.INITILALIZE_INFO), ConnectCommSendInfo);
|
||||
|
||||
FlowCommandControl.InsertSendQueue(DateTime.Now, ucSendByteInfo, null);
|
||||
}
|
||||
}
|
||||
|
||||
return bResult;
|
||||
}
|
||||
|
||||
[ComVisible(true)]
|
||||
public async Task<bool> WaitComClientTryDistributionConnet(int nCommandPortNum = int.MaxValue)
|
||||
{
|
||||
bool bResult = true;
|
||||
|
||||
StateAdaptorConnect = true;
|
||||
|
||||
thisConnInfo.stLoginTimeOut.Restart();
|
||||
|
||||
try
|
||||
{
|
||||
ClearCommandClientInstance();
|
||||
|
||||
//ConnectCommandWaitEvent.Reset();
|
||||
|
||||
bConnectCommandSocketFlag = false;
|
||||
|
||||
StateAdaptorConnect &= ClientCommandSet(SOCKET_TYPE.TCP, true, nCommandPortNum);
|
||||
|
||||
Stopwatch stWaitConnect = new Stopwatch();
|
||||
stWaitConnect.Start();
|
||||
|
||||
while (stWaitConnect.ElapsedMilliseconds < CONNECT_TIME_OUT)
|
||||
{
|
||||
if (bConnectCommandSocketFlag)
|
||||
{
|
||||
await Task.Delay(10).ConfigureAwait(false);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
await Task.Delay(10).ConfigureAwait(false);
|
||||
}
|
||||
if (bConnectCommandSocketFlag)
|
||||
SetCommandWatchTask();
|
||||
else
|
||||
{
|
||||
bResult = false;
|
||||
|
||||
throw new Exception("Can not connect Command Socket.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
bResult = false;
|
||||
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"Client Connection Attempt Error. [SystemX.Net.XAdaptor.PC - IComXPCAdaptor : XPCAdaptor.ComClientTryConnet]\r\n" +
|
||||
ex.Message, ConsoleColor.Red, LogMessageLevel.DEBUG);
|
||||
}
|
||||
//
|
||||
finally
|
||||
{
|
||||
if (bResult)
|
||||
{
|
||||
await Task.Delay(500).ConfigureAwait(false);
|
||||
|
||||
COMM_INFO_PACKET ConnectCommSendInfo = new COMM_INFO_PACKET();
|
||||
int iSendSize = Marshal.SizeOf(ConnectCommSendInfo);
|
||||
byte[] ucSendArray = new byte[iSendSize];
|
||||
ConnectCommSendInfo = (COMM_INFO_PACKET)SystemXNetSerialization.RawDeSerialize(ucSendArray, ConnectCommSendInfo.GetType());
|
||||
|
||||
ConnectCommSendInfo.bPortDistribution = true;
|
||||
|
||||
ConnectCommSendInfo.usPortCommandNumber = (ushort)0;
|
||||
ConnectCommSendInfo.usPortStreamNumber = (ushort)0;
|
||||
|
||||
byte[] ucSendByteInfo = XCommons.SpecialObjectToByteStream(new BASE_PROTOCOL(BASE_PROTOCOL.PROTOCOL_CODE.INITILALIZE_INFO), ConnectCommSendInfo);
|
||||
|
||||
FlowCommandControl.InsertSendQueue(DateTime.Now, ucSendByteInfo, null, PacketFlowControl.CommInfoManualToken, false);
|
||||
|
||||
await WaitTaskJoin(waitCommandParam, FlowCommandControl, PacketFlowControl.CommInfoManualToken, false);
|
||||
|
||||
if (QueryResult.bQueryResult)
|
||||
bResult = true;
|
||||
else
|
||||
bResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (bResult)
|
||||
{
|
||||
if (await ComClientTryConnet(SubscribeConnectInfo.nChangeCommandPort, SubscribeConnectInfo.nChangeStreamPort) == false)
|
||||
{
|
||||
AdaptorAbort();
|
||||
|
||||
bResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
return bResult;
|
||||
}
|
||||
|
||||
[ComVisible(true)]
|
||||
public bool ComClientTryDisconnect()
|
||||
{
|
||||
bool bResult = true;
|
||||
|
||||
try
|
||||
{
|
||||
ClearCommonVar();
|
||||
|
||||
ClearCommandWatchTask();
|
||||
ClearStreamWatchTask();
|
||||
|
||||
ClearCommandClientInstance();
|
||||
ClearStreamClientInstance();
|
||||
|
||||
this.ClientCommandErrorEvent(null, null);
|
||||
this.ClientStreamErrorEvent(null, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
bResult = false;
|
||||
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"Client Disconnect Attempt Error. [SystemX.Net.XAdaptor.PC - IComXPCAdaptor : XPCAdaptor.ComClientTryDisconnect]\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
|
||||
return bResult;
|
||||
}
|
||||
|
||||
[ComVisible(true)]
|
||||
public bool ComCheckConnectState()
|
||||
{
|
||||
bool bStatus = false;
|
||||
|
||||
try
|
||||
{
|
||||
thisConnInfo.OnCommandTime();
|
||||
|
||||
try
|
||||
{
|
||||
PING_PACKET MakePingPacket = new PING_PACKET();
|
||||
int iSendSize = Marshal.SizeOf(MakePingPacket);
|
||||
byte[] ucSendArray = new byte[iSendSize];
|
||||
MakePingPacket = (PING_PACKET)SystemXNetSerialization.RawDeSerialize(ucSendArray, MakePingPacket.GetType());
|
||||
|
||||
MakePingPacket.objCheckMsg[0].Data = "Who?";
|
||||
|
||||
byte[] ucSendByteInfo = XCommons.SpecialObjectToByteStream(new BASE_PROTOCOL(BASE_PROTOCOL.PROTOCOL_CODE.CONNECT_STATE), MakePingPacket);
|
||||
|
||||
byte ucGetLabel = FlowCommandControl.InsertSendQueue(DateTime.Now, ucSendByteInfo, null, true);
|
||||
|
||||
if (ComWaitResult(ucGetLabel) == null)
|
||||
{
|
||||
FlowCommandControl.STM.ClearLabel(ucGetLabel);
|
||||
}
|
||||
else
|
||||
bStatus = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"Command Socket ping check error. [SystemX.Net.XAdaptor.PC - IComXPCAdaptor : XPCAdaptor.ComCheckConnectState]\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
finally { }
|
||||
}
|
||||
finally
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
return bStatus;
|
||||
}
|
||||
|
||||
[ComVisible(true)]
|
||||
public bool ComCheckConnectStreamState()
|
||||
{
|
||||
try
|
||||
{
|
||||
thisConnInfo.OnStreamTime();
|
||||
|
||||
try
|
||||
{
|
||||
PING_PACKET MakePingPacket = new PING_PACKET();
|
||||
int iSendSize = Marshal.SizeOf(MakePingPacket);
|
||||
byte[] ucSendArray = new byte[iSendSize];
|
||||
MakePingPacket = (PING_PACKET)SystemXNetSerialization.RawDeSerialize(ucSendArray, MakePingPacket.GetType());
|
||||
|
||||
MakePingPacket.objCheckMsg[0].Data = "Who?";
|
||||
|
||||
byte[] ucSendByteInfo = XCommons.SpecialObjectToByteStream(new BASE_PROTOCOL(BASE_PROTOCOL.PROTOCOL_CODE.CONNECT_STATE), MakePingPacket);
|
||||
|
||||
FlowStreamControl.InsertSendQueue(DateTime.Now, ucSendByteInfo, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"Stream Socket ping check error. [SystemX.Net.XAdaptor.PC - IComXPCAdaptor: XPCAdaptor.ComCheckConnectStreamState]\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
finally { }
|
||||
}
|
||||
finally
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[ComVisible(true)]
|
||||
public string ComSetConfigureFile(string strFilePos)
|
||||
{
|
||||
if (File.Exists(strFilePos))
|
||||
{
|
||||
strSetAdaptorConfigFilePos = strFilePos;
|
||||
|
||||
if (CheckConfigFileBuildEndPoint())
|
||||
{
|
||||
return strFilePos;
|
||||
}
|
||||
else
|
||||
return "";
|
||||
}
|
||||
else
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,222 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using SystemX.Common;
|
||||
using SystemX.Common.Serialization;
|
||||
using SystemX.Net.BaseProtocol;
|
||||
using SystemX.Net.Schedule;
|
||||
using SystemX.Net.XAdaptor;
|
||||
using static SystemX.Net.Platform.Common.Util.LogMessage;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC
|
||||
{
|
||||
public partial class XAdaptorPC
|
||||
{
|
||||
private byte SendCallQuery(string strQueryCallID, params string[] strParameterValues)
|
||||
{
|
||||
QUERY_PACKET QueryPacket = new QUERY_PACKET();
|
||||
int iSizeQueryPacket = Marshal.SizeOf(QueryPacket);
|
||||
byte[] ucQueryPacketArray = new byte[iSizeQueryPacket];
|
||||
|
||||
QueryPacket = (QUERY_PACKET)SystemXNetSerialization.RawDeSerialize(ucQueryPacketArray, QueryPacket.GetType());
|
||||
|
||||
string strSendText = string.Empty;
|
||||
strSendText = "UserQueryCall;";
|
||||
|
||||
if (strParameterValues.Length > 0)
|
||||
{
|
||||
strSendText += (strQueryCallID + ";");
|
||||
|
||||
foreach (string strParam in strParameterValues)
|
||||
{
|
||||
strSendText += (strParam + ";");
|
||||
}
|
||||
|
||||
strSendText = strSendText.Remove(strSendText.Length - 1, 1);
|
||||
}
|
||||
else
|
||||
strSendText += strQueryCallID;
|
||||
|
||||
QueryPacket.objQueryText[0].Data = strSendText;
|
||||
|
||||
ucQueryPacketArray = XCommons.SpecialObjectToByteStream(new BASE_PROTOCOL(BASE_PROTOCOL.PROTOCOL_CODE.USER_QUERY), QueryPacket);
|
||||
|
||||
return FlowCommandControl.InsertSendQueue(DateTime.Now, ucQueryPacketArray, null, true);
|
||||
}
|
||||
|
||||
private DataSet WaitCallQueryLookUp(string strQueryCallID, params string[] strParameterValues)
|
||||
{
|
||||
if (thisConnInfo.ConnectCommandState == false)
|
||||
return null;
|
||||
if (thisConnInfo.InitialInfoState == false)
|
||||
return null;
|
||||
|
||||
DataSet dsReturnSet = null;
|
||||
|
||||
try
|
||||
{
|
||||
thisConnInfo.OnCommandTime();
|
||||
|
||||
try
|
||||
{
|
||||
byte ucGetLabel = SendCallQuery(strQueryCallID, strParameterValues);
|
||||
|
||||
WaitThreadJoin(waitCommandParam, FlowCommandControl, ucGetLabel);
|
||||
|
||||
if (QueryResult.QueryDataSet != null)
|
||||
{
|
||||
if (QueryResult.bQueryResult) //Query 문 실행 성공
|
||||
dsReturnSet = QueryResult.QueryDataSet;
|
||||
else //Query 문 실행 실패(구문 오류 또는 연결 오류)
|
||||
dsReturnSet = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"Registered query call error. [" + strQueryCallID + "][SystemX.Net.XAdaptor.PC - IXPCAdaptor : XPCAdaptor.WaitCallQuery]\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
finally
|
||||
{
|
||||
;//
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
return dsReturnSet;
|
||||
}
|
||||
|
||||
private DataSet WaitCallQuery(string strQueryCallID, params string[] strParameterValues)
|
||||
{
|
||||
if (thisConnInfo.ConnectCommandState == false)
|
||||
return null;
|
||||
if (thisConnInfo.InitialInfoState == false)
|
||||
return null;
|
||||
if (LoadInfo.SIMPLE_LOOKUP_OPTION == true)
|
||||
return null;
|
||||
|
||||
DataSet dsReturnSet = null;
|
||||
|
||||
try
|
||||
{
|
||||
thisConnInfo.OnCommandTime();
|
||||
|
||||
try
|
||||
{
|
||||
byte ucGetLabel = SendCallQuery(strQueryCallID, strParameterValues);
|
||||
|
||||
WaitThreadJoin(waitCommandParam, FlowCommandControl, ucGetLabel);
|
||||
|
||||
if (QueryResult.QueryDataSet != null)
|
||||
{
|
||||
if (QueryResult.bQueryResult) //Query 문 실행 성공
|
||||
dsReturnSet = QueryResult.QueryDataSet;
|
||||
else //Query 문 실행 실패(구문 오류 또는 연결 오류)
|
||||
dsReturnSet = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"Registered query call error. [" + strQueryCallID + "][SystemX.Net.XAdaptor.PC - IXPCAdaptor : XPCAdaptor.WaitCallQuery]\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
finally
|
||||
{
|
||||
;//
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
return dsReturnSet;
|
||||
}
|
||||
|
||||
public DataSet WaitUserQuery(string strQuery)
|
||||
{
|
||||
if (thisConnInfo.ConnectCommandState == false)
|
||||
return null;
|
||||
if (thisConnInfo.InitialInfoState == false)
|
||||
return null;
|
||||
if (LoadInfo.SIMPLE_LOOKUP_OPTION == true)
|
||||
return null;
|
||||
|
||||
string[] strCheck = strQuery.Split(' ');
|
||||
string strUpperText = string.Empty;
|
||||
|
||||
foreach (string strItem in strCheck)
|
||||
{
|
||||
strUpperText = strItem.ToUpper();
|
||||
|
||||
if (strUpperText.CompareTo("INSERT") == 0 ||
|
||||
strUpperText.CompareTo("UPDATE") == 0 ||
|
||||
strUpperText.CompareTo("DELETE") == 0)
|
||||
{
|
||||
MessageBox.Show("SQL control syntax other than SELECT syntax is not supported.", "XAdaptor", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
string strQueryText = strQuery.ToUpper();
|
||||
|
||||
DataSet dsReturnSet = null;
|
||||
|
||||
try
|
||||
{
|
||||
thisConnInfo.OnCommandTime();
|
||||
|
||||
try
|
||||
{
|
||||
QUERY_PACKET QueryPacket = new QUERY_PACKET();
|
||||
int iSizeQueryPacket = Marshal.SizeOf(QueryPacket);
|
||||
byte[] ucQueryPacketArray = new byte[iSizeQueryPacket];
|
||||
QueryPacket = (QUERY_PACKET)SystemXNetSerialization.RawDeSerialize(ucQueryPacketArray, QueryPacket.GetType());
|
||||
QueryPacket.objQueryText[0].Data = strQuery;
|
||||
ucQueryPacketArray = XCommons.SpecialObjectToByteStream(new BASE_PROTOCOL(BASE_PROTOCOL.PROTOCOL_CODE.SYSTEM_QUERY), QueryPacket);
|
||||
|
||||
byte ucGetLabel = FlowCommandControl.InsertSendQueue(DateTime.Now, ucQueryPacketArray, null, true);
|
||||
|
||||
WaitThreadJoin(waitCommandParam, FlowCommandControl, ucGetLabel);
|
||||
|
||||
if (QueryResult.QueryDataSet != null)
|
||||
{
|
||||
if (QueryResult.bQueryResult) //Query 문 실행 성공
|
||||
dsReturnSet = QueryResult.QueryDataSet;
|
||||
else //Query 문 실행 실패(구문 오류 또는 연결 오류)
|
||||
dsReturnSet = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"User program query call error. [" + strQuery + "][SystemX.Net.XAdaptor.PC - IXPCAdaptor : XPCAdaptor.WaitUserQuery]\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
finally
|
||||
{
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
return dsReturnSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,432 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using SystemX.Common;
|
||||
using SystemX.Common.Serialization;
|
||||
using SystemX.Net.BaseProtocol;
|
||||
using SystemX.Net.Schedule;
|
||||
using SystemX.Net.XAdaptor;
|
||||
using static SystemX.Net.Platform.Common.Util.LogMessage;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC
|
||||
{
|
||||
public partial class XAdaptorPC
|
||||
{
|
||||
public eResultCheck CheckIssuedID(string strProductID)
|
||||
{
|
||||
if(strProductID.Length <= 0)
|
||||
return eResultCheck.InvalidFormat;
|
||||
|
||||
DataSet dsResult = WaitCallQuery("ID_IsIssued", strProductID);
|
||||
|
||||
if (XCommons.isHasRow(dsResult))
|
||||
return eResultCheck.AlreadyIssued;
|
||||
else
|
||||
return eResultCheck.NotIssued;
|
||||
}
|
||||
|
||||
//맥 어드레스 무결성 체크
|
||||
public eMacAddressType IsMacAddressForm(string strMacAddress)
|
||||
{
|
||||
// IP4 ADDRESS (25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}
|
||||
/* IP6 ADDRESS
|
||||
(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:)
|
||||
{1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:)
|
||||
{1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4})
|
||||
{1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:)
|
||||
{1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})
|
||||
|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]
|
||||
{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}
|
||||
[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]
|
||||
{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]
|
||||
|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))
|
||||
*/
|
||||
// MAC ADDRESS
|
||||
// ([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}
|
||||
//^([[:xdigit:]]{2}[:.-]?){5}[[:xdigit:]]{2}$
|
||||
//^([0-9a-fA-F]{2}[:.-]?){5}[0-9a-fA-F]{2}$/g
|
||||
Regex r1 = new Regex("^([0-9a-fA-F]{2}){5}[0-9a-fA-F]{2}$");
|
||||
Regex r2 = new Regex("^([0-9a-fA-F]{2}[:]+){5}[0-9a-fA-F]{2}$");
|
||||
Regex r3 = new Regex("^([0-9a-fA-F]{2}[-]+){5}[0-9a-fA-F]{2}$");
|
||||
Regex r4 = new Regex("^([0-9a-fA-F]{2}[.]+){5}[0-9a-fA-F]{2}$");
|
||||
Regex r5 = new Regex("^([0-9a-fA-F]{2}[:.-]?){5}[0-9a-fA-F]{2}$");
|
||||
|
||||
bool b1 = r1.Match(strMacAddress).Success;
|
||||
bool b2 = r2.Match(strMacAddress).Success;
|
||||
bool b3 = r3.Match(strMacAddress).Success;
|
||||
bool b4 = r4.Match(strMacAddress).Success;
|
||||
bool b5 = r5.Match(strMacAddress).Success;
|
||||
|
||||
eMacAddressType type = eMacAddressType.Normal;
|
||||
|
||||
if (b5 == false)
|
||||
return eMacAddressType.InvalidMacAddressFormat;
|
||||
|
||||
if (b2)
|
||||
type = eMacAddressType.Colon;
|
||||
else if (b3)
|
||||
type = eMacAddressType.Hyphen;
|
||||
else if (b4)
|
||||
type = eMacAddressType.Dot;
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
private string MacAddressFormatRecalculation(string strMacAddress)
|
||||
{
|
||||
string strFindMacAddress = string.Empty;
|
||||
|
||||
foreach (char c in strMacAddress)
|
||||
{
|
||||
if (char.IsLetterOrDigit(c))
|
||||
strFindMacAddress += c;
|
||||
}
|
||||
|
||||
return strFindMacAddress;
|
||||
}
|
||||
|
||||
private string MacAddressFormatChange(string strText, eMacAddressType type)
|
||||
{
|
||||
string strChangeMacAddress = string.Empty;
|
||||
|
||||
int nPos = 0;
|
||||
foreach (char c in strText)
|
||||
{
|
||||
if(nPos / 2 == 1)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case eMacAddressType.Colon:
|
||||
strChangeMacAddress += ":";
|
||||
break;
|
||||
case eMacAddressType.Hyphen:
|
||||
strChangeMacAddress += "-";
|
||||
break;
|
||||
case eMacAddressType.Dot:
|
||||
strChangeMacAddress += ".";
|
||||
break;
|
||||
}
|
||||
|
||||
nPos = 0;
|
||||
}
|
||||
|
||||
if (char.IsLetterOrDigit(c))
|
||||
strChangeMacAddress += c;
|
||||
|
||||
nPos++;
|
||||
}
|
||||
|
||||
return strChangeMacAddress;
|
||||
}
|
||||
|
||||
|
||||
//목록에 존재하는 맥어드레스 인지
|
||||
public bool CheckListMacAddress(string strMacAddress)
|
||||
{
|
||||
if (IsMacAddressForm(strMacAddress) == eMacAddressType.InvalidMacAddressFormat)
|
||||
return false;
|
||||
|
||||
string strFindMacAddress = MacAddressFormatRecalculation(strMacAddress);
|
||||
|
||||
DataSet dsResult = WaitCallQuery("MacAddress_Check", strFindMacAddress);
|
||||
|
||||
if (XCommons.isHasRow(dsResult))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public eResultCheck CheckIssuedMacAddress(string strMacAddress)
|
||||
{
|
||||
if (IsMacAddressForm(strMacAddress) == eMacAddressType.InvalidMacAddressFormat)
|
||||
return eResultCheck.InvalidMacAddressFormat;
|
||||
|
||||
string strFindMacAddress = MacAddressFormatRecalculation(strMacAddress);
|
||||
|
||||
DataSet dsResult = WaitCallQuery("MacAddress_IsIssued", strFindMacAddress);
|
||||
|
||||
if (XCommons.isHasRow(dsResult))
|
||||
return eResultCheck.AlreadyIssued;
|
||||
else
|
||||
return eResultCheck.NotIssued;
|
||||
}
|
||||
private int GetCurrentQuantity()
|
||||
{
|
||||
int nCurCnt = int.MaxValue;
|
||||
|
||||
DataSet dsResult = WaitCallQuery("Check_Mac_Quantity");
|
||||
|
||||
try
|
||||
{
|
||||
if (XCommons.isHasRow(dsResult))
|
||||
{
|
||||
if (int.TryParse(dsResult.Tables[0].Rows[0][0].ToString(), out nCurCnt) == false)
|
||||
throw new Exception();
|
||||
}
|
||||
else
|
||||
nCurCnt = int.MinValue;
|
||||
}
|
||||
catch
|
||||
{
|
||||
nCurCnt = int.MinValue;
|
||||
}
|
||||
|
||||
return nCurCnt;
|
||||
}
|
||||
|
||||
//현재 발행 예정 대상 주소
|
||||
public string GetToBeIssuedMacAddress(eMacAddressType type = eMacAddressType.Normal)
|
||||
{
|
||||
int nGetCurrent = GetCurrentQuantity();
|
||||
|
||||
if (nGetCurrent == int.MaxValue || nGetCurrent == int.MinValue)
|
||||
return "";
|
||||
|
||||
DataSet dsResult = WaitCallQuery("MacAddress_ToBeIssuedCheck", nGetCurrent.ToString());
|
||||
|
||||
string strGetMacAddress = string.Empty;
|
||||
|
||||
if (XCommons.isHasRow(dsResult))
|
||||
{
|
||||
strGetMacAddress = dsResult.Tables[0].Rows[0][1].ToString();
|
||||
|
||||
strGetMacAddress = MacAddressFormatChange(strGetMacAddress, type);
|
||||
}
|
||||
|
||||
return strGetMacAddress;
|
||||
}
|
||||
|
||||
//총개수
|
||||
public int GetTotalAddressNumber()
|
||||
{
|
||||
DataSet dsResult = WaitCallQuery("Check_Mac_Quantity");
|
||||
|
||||
int nValue = 0;
|
||||
|
||||
if (XCommons.isHasRow(dsResult))
|
||||
{
|
||||
if (int.TryParse(dsResult.Tables[0].Rows[0][1].ToString(), out nValue) == false)
|
||||
nValue = -1;
|
||||
}
|
||||
|
||||
return nValue;
|
||||
}
|
||||
|
||||
//발행 개수 확인
|
||||
public int GetCurrentIssuedAddressNumber()
|
||||
{
|
||||
DataSet dsResult = WaitCallQuery("Check_Mac_Quantity");
|
||||
|
||||
int nValue = 0;
|
||||
|
||||
if (XCommons.isHasRow(dsResult))
|
||||
{
|
||||
if (int.TryParse(dsResult.Tables[0].Rows[0][0].ToString(), out nValue) == false)
|
||||
nValue = -1;
|
||||
}
|
||||
|
||||
return nValue;
|
||||
}
|
||||
|
||||
//남은 개수 확인
|
||||
public int GetRemainAddressNumber()
|
||||
{
|
||||
DataSet dsResult = WaitCallQuery("Check_Mac_Quantity");
|
||||
|
||||
int nValue1 = 0;
|
||||
int nValue2 = 0;
|
||||
|
||||
int nResult = 0;
|
||||
|
||||
if (XCommons.isHasRow(dsResult))
|
||||
{
|
||||
if (int.TryParse(dsResult.Tables[0].Rows[0][0].ToString(), out nValue1) == false)
|
||||
nValue1 = -1;
|
||||
if (int.TryParse(dsResult.Tables[0].Rows[0][1].ToString(), out nValue2) == false)
|
||||
nValue2 = -1;
|
||||
|
||||
if (nValue1 == -1 || nValue2 == -1)
|
||||
nResult = -1;
|
||||
else
|
||||
nResult = nValue2 - nValue1;
|
||||
}
|
||||
|
||||
return nResult;
|
||||
}
|
||||
|
||||
protected string GetTableValue(DataSet ds, string strParam1)
|
||||
{
|
||||
string strValue = string.Empty;
|
||||
|
||||
if (strParam1.Length > 0)
|
||||
{
|
||||
int nIndex = int.MaxValue;
|
||||
|
||||
if (int.TryParse(strParam1, out nIndex))
|
||||
strValue = ds.Tables[0].Rows[0][nIndex].ToString();
|
||||
else
|
||||
strValue = ds.Tables[0].Rows[0][strParam1].ToString();
|
||||
}
|
||||
else
|
||||
strValue = ds.Tables[0].Rows[0][0].ToString();
|
||||
|
||||
return strValue;
|
||||
}
|
||||
|
||||
public string LookUpIDbyMacAddress(string strMacAddress)
|
||||
{
|
||||
if (IsMacAddressForm(strMacAddress) == eMacAddressType.InvalidMacAddressFormat)
|
||||
return "InvalidMacAddressFormat";
|
||||
|
||||
string strFindMacAddress = MacAddressFormatRecalculation(strMacAddress);
|
||||
|
||||
DataSet dsResult = WaitCallQueryLookUp("LookUpID_ByMacAddress", strFindMacAddress);
|
||||
|
||||
string strValue = string.Empty;
|
||||
|
||||
if (XCommons.isHasRow(dsResult))
|
||||
strValue = GetTableValue(dsResult, QueryResult.strVarParam1);
|
||||
|
||||
return strValue;
|
||||
}
|
||||
|
||||
|
||||
public string LookUpMacAddressbyID(ref string strProductID, eLookUpOption SetLookUpOption = eLookUpOption.CompareToSame, eMacAddressType type = eMacAddressType.Normal)
|
||||
{
|
||||
DataSet dsResult = null;
|
||||
|
||||
if(SetLookUpOption == eLookUpOption.StartWith)
|
||||
dsResult = WaitCallQueryLookUp("LookUpMacAddress_ByLikeID", strProductID + "%");
|
||||
else if (SetLookUpOption == eLookUpOption.EndWith)
|
||||
dsResult = WaitCallQueryLookUp("LookUpMacAddress_ByLikeID", "%" + strProductID);
|
||||
else if(SetLookUpOption == eLookUpOption.ContainWith)
|
||||
dsResult = WaitCallQueryLookUp("LookUpMacAddress_ByLikeID", "%" + strProductID + "%");
|
||||
else
|
||||
dsResult = WaitCallQueryLookUp("LookUpMacAddress_ByID", strProductID);
|
||||
|
||||
string strGetMacAddress = string.Empty;
|
||||
|
||||
string strValue = string.Empty;
|
||||
|
||||
if (XCommons.isHasRow(dsResult))
|
||||
{
|
||||
strValue = GetTableValue(dsResult, QueryResult.strVarParam1);
|
||||
|
||||
strValue = MacAddressFormatChange(strValue, type);
|
||||
|
||||
strProductID = dsResult.Tables[0].Rows[0][4].ToString();
|
||||
}
|
||||
|
||||
return strValue;
|
||||
}
|
||||
|
||||
private string RequestMacAddressIssuance(string strProductID, ref string strRetrunMessage, out int nErrCode, bool bReissuance = false)
|
||||
{
|
||||
nErrCode = int.MinValue;
|
||||
|
||||
strRetrunMessage = string.Empty;
|
||||
|
||||
string strGetUniqueInfo = string.Empty;
|
||||
|
||||
if (thisConnInfo.ConnectCommandState == false)
|
||||
return "[Error] Need connect command socket.";
|
||||
if (thisConnInfo.InitialInfoState == false)
|
||||
return "[Error] Need InitialInfoState information.";
|
||||
if (LoadInfo.SIMPLE_LOOKUP_OPTION == true)
|
||||
return "[Error] Cannot do this in simple lookup mode.";
|
||||
|
||||
try
|
||||
{
|
||||
thisConnInfo.OnCommandTime();
|
||||
|
||||
try
|
||||
{
|
||||
PROCESS_PACKET MakeProcessPacket = new PROCESS_PACKET();
|
||||
int iSendSize = Marshal.SizeOf(MakeProcessPacket);
|
||||
byte[] ucSendArray = new byte[iSendSize];
|
||||
MakeProcessPacket = (PROCESS_PACKET)SystemXNetSerialization.RawDeSerialize(ucSendArray, MakeProcessPacket.GetType());
|
||||
|
||||
MakeProcessPacket.nStationID = 0;
|
||||
MakeProcessPacket.objProdNo_C[0].Data = "";
|
||||
MakeProcessPacket.objTestType[0].Data = "";
|
||||
MakeProcessPacket.objTestCode[0].Data = ((bReissuance == false) ? "ISSUANCE" : "REISSUANCE");
|
||||
MakeProcessPacket.objTestListFileVersion[0].Data = "";
|
||||
MakeProcessPacket.objProductionCode[0].Data = "";
|
||||
MakeProcessPacket.objProductID[0].Data = strProductID;
|
||||
|
||||
byte[] ucSendByteInfo = XCommons.SpecialObjectToByteStream(new BASE_PROTOCOL(BASE_PROTOCOL.PROTOCOL_CODE.PROCESS_QUERY, BASE_PROTOCOL.OPTION_CODE.GET_ISSUANCE_MACADDRESS), MakeProcessPacket);
|
||||
|
||||
byte ucGetLabel = FlowCommandControl.InsertSendQueue(DateTime.Now, ucSendByteInfo, null, true);
|
||||
|
||||
WaitThreadJoin(waitCommandParam, FlowCommandControl, ucGetLabel);
|
||||
|
||||
if (XCommons.isHasRow(QueryResult.QueryDataSet))
|
||||
strGetUniqueInfo = GetTableValue(QueryResult.QueryDataSet, QueryResult.strVarParam1);
|
||||
|
||||
int.TryParse(QueryResult.strVarParam3, out nErrCode);
|
||||
|
||||
strRetrunMessage = QueryResult.strVarParam2;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"MacAddress issuance request error. [SystemX.Net.XAdaptor.PC - IXPCAdaptor : RequestMacAddressIssuance]\r\n" +
|
||||
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
finally { }
|
||||
}
|
||||
finally
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
return strGetUniqueInfo;
|
||||
}
|
||||
|
||||
public ResultIssued IssuanceRequest(string strProductID, bool bReissuance = false, eMacAddressType type = eMacAddressType.Normal)
|
||||
{
|
||||
int nGetErrCode = 0;
|
||||
|
||||
string strGetErrMsg = string.Empty;
|
||||
|
||||
string strGetUniqueInfo = string.Empty;
|
||||
|
||||
if (strProductID.Length <= 0)
|
||||
return new ResultIssued(eResultIssued.InvalidFormat);
|
||||
|
||||
strGetUniqueInfo = RequestMacAddressIssuance(strProductID, ref strGetErrMsg, out nGetErrCode, bReissuance);
|
||||
|
||||
if(IsMacAddressForm(strGetUniqueInfo) != eMacAddressType.InvalidMacAddressFormat)
|
||||
strGetUniqueInfo = MacAddressFormatChange(strGetUniqueInfo, type);
|
||||
|
||||
eResultIssued riReturn = eResultIssued.None;
|
||||
|
||||
switch(nGetErrCode)
|
||||
{
|
||||
case 0:
|
||||
riReturn = eResultIssued.Success;
|
||||
break;
|
||||
case -2:
|
||||
riReturn = eResultIssued.AlreadyIssued;
|
||||
break;
|
||||
case -3:
|
||||
riReturn = eResultIssued.InformationWithoutIssuanceHistory;
|
||||
break;
|
||||
default:
|
||||
riReturn = eResultIssued.Failed;
|
||||
break;
|
||||
}
|
||||
|
||||
return new ResultIssued(riReturn, strGetUniqueInfo, strGetErrMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,412 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using SystemX.Common;
|
||||
using SystemX.Net.BaseProtocol;
|
||||
using SystemX.Net.XAdaptor.PC.O2Sensor.NgCode;
|
||||
using SystemX.Net.Schedule;
|
||||
using SystemX.Net.XAdaptor;
|
||||
using static SystemX.Net.Platform.Common.Util.LogMessage;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC
|
||||
{
|
||||
public partial class XAdaptorPC
|
||||
{
|
||||
//private async void SendCommandEvent(byte[] senderData, ScheduleEvent e)
|
||||
private void SendCommandEvent(byte[] senderData, ScheduleEvent e)
|
||||
{
|
||||
try
|
||||
{
|
||||
thisConnInfo.m_iSendCommandCnt++;
|
||||
|
||||
if (thisConnInfo.m_iSendCommandCnt + 1 == int.MaxValue)
|
||||
thisConnInfo.m_iSendCommandCnt = 0;
|
||||
|
||||
if (FlowCommandControl == null)
|
||||
return;
|
||||
|
||||
//소켓 샌드 행위 내부 결과
|
||||
if (e.PROCESS_RESULT == false)
|
||||
{
|
||||
//해당 패킷 횟수 상승 일단 회 차시 기록남기고 드랍
|
||||
FlowCommandControl.SendPacketCycle();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"General <SendCommandEvent> failed.[SystemX.Net.XAdaptor.PC.XPCAdaptor : SendCommandEvent]\r\n" + ex.Message,
|
||||
ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
}
|
||||
//private async void RecvCommandEvent(byte[] senderData, ScheduleEvent e)
|
||||
private void RecvCommandEvent(byte[] senderData, ScheduleEvent e)
|
||||
{
|
||||
try
|
||||
{
|
||||
thisConnInfo.m_iRecvCommandCnt++;
|
||||
|
||||
if (thisConnInfo.m_iRecvCommandCnt + 1 == int.MaxValue)
|
||||
thisConnInfo.m_iRecvCommandCnt = 0;
|
||||
|
||||
if (FlowCommandControl == null)
|
||||
return;
|
||||
|
||||
int iStoreCnt = senderData.Count();
|
||||
byte[] recvStoreBuffer = senderData;
|
||||
|
||||
//소켓 리시브 행위 결과 전송
|
||||
if (e.PROCESS_RESULT == false)
|
||||
{
|
||||
//받기 실패 단순 실패 응답
|
||||
FlowCommandControl.InsertSendQueue(DateTime.Now, XCommons.SetSimpleResponsPacket(new BASE_PROTOCOL(BASE_PROTOCOL.PROTOCOL_CODE.SIMPLE_RESPONSE), false), null, false, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
BASE_PROTOCOL GET_PROTOCOL = XCommons.GetHeaderProtocol(iStoreCnt, recvStoreBuffer);
|
||||
BASE_PROTOCOL.PROTOCOL_CODE GET_CODE = GET_PROTOCOL.GET_CURRENT_PROTOCOL;
|
||||
|
||||
//응답
|
||||
if (GET_CODE == BASE_PROTOCOL.PROTOCOL_CODE.SIMPLE_RESPONSE)
|
||||
{
|
||||
if (XCommons.GetSimpleResponsResult(iStoreCnt, recvStoreBuffer))
|
||||
FlowCommandControl.SetSendPacketDrop();
|
||||
else
|
||||
FlowCommandControl.SendPacketCycle();
|
||||
}
|
||||
//파일 끝 응답
|
||||
else if (GET_CODE == BASE_PROTOCOL.PROTOCOL_CODE.RAW_END)
|
||||
{
|
||||
if (XCommons.GetSimpleResponsResult(iStoreCnt, recvStoreBuffer))
|
||||
FlowCommandControl.RawStoreQueuePOP();
|
||||
else
|
||||
FlowStreamControl.RawStoreQueuePOP();
|
||||
}
|
||||
//일반 응답
|
||||
else
|
||||
{
|
||||
//성공 응답
|
||||
FlowCommandControl.InsertSendQueue(DateTime.Now, XCommons.SetSimpleResponsPacket(new BASE_PROTOCOL(BASE_PROTOCOL.PROTOCOL_CODE.SIMPLE_RESPONSE), true), null, false, false);
|
||||
|
||||
//받은 큐에 넣어놓기
|
||||
FlowCommandControl.InsertRecvQueue(senderData, null, e.nLABEL);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"General <RecvCommandEvent> failed.[SystemX.Net.XAdaptor.PC.XPCAdaptor : RecvCommandEvent]\r\n" + ex.Message,
|
||||
ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
}
|
||||
private async void WatchRecvCommandQueue()
|
||||
{
|
||||
await Task.Delay(250).ConfigureAwait(false);
|
||||
|
||||
thisConnInfo.OnCommandTime();
|
||||
thisConnInfo.OnCommandCheckTime();
|
||||
|
||||
while (!m_bTaskCommandBlock)
|
||||
{
|
||||
await Task.Delay(10).ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
CommandCT.ThrowIfCancellationRequested();
|
||||
}
|
||||
catch (OperationCanceledException CancelEx)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@" Work Canceled. [SystemX.Net.XAdaptor.PC.XPCAdaptor : RecvProcessTask.WatchRecvCommandQueue]\r\n" + CancelEx.Message,
|
||||
ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
|
||||
break;
|
||||
}
|
||||
//
|
||||
try
|
||||
{
|
||||
if (StateClientSocketConnect == false)
|
||||
continue;
|
||||
|
||||
if (thisConnInfo.stCommandCheckTime.ElapsedMilliseconds >= 60000)
|
||||
{
|
||||
await SendCommandConnectState().ConfigureAwait(false);
|
||||
|
||||
thisConnInfo.OnCommandCheckTime();
|
||||
}
|
||||
|
||||
if (bTaskCommandWaitLock == false)
|
||||
{
|
||||
bool bResult = QueryRecvCommandQueue();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//throw new CommonScheduleException("General Queue Process failed.[SystemX.Net.XAdaptor.PC.XPCAdaptor : RecvProcessTask.WatchRecvQueue]");
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"General Queue Process failed.[SystemX.Net.XAdaptor.PC.XPCAdaptor : RecvProcessTask.WatchRecvCommandQueue]\r\n" + ex.Message,
|
||||
ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool CommandQueueCheck()
|
||||
{
|
||||
if (ClientCommandSock == null)
|
||||
return false;
|
||||
|
||||
if (ClientCommandSock != null)
|
||||
{
|
||||
if (ClientCommandSock.CONNECT == false)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (FlowCommandControl == null)
|
||||
return false;
|
||||
|
||||
//Login 타임아웃
|
||||
if (thisConnInfo.bHostLoginState == false)
|
||||
{
|
||||
if (thisConnInfo.stLoginTimeOut.ElapsedMilliseconds >= LOGIN_TIMEOUT)
|
||||
{
|
||||
AdaptorAbort(true);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool QueryRecvCommandQueue()
|
||||
{
|
||||
bool bState = true;
|
||||
|
||||
try
|
||||
{
|
||||
if (CommandQueueCheck() == false)
|
||||
return false;
|
||||
|
||||
bTaskCommandWaitLock = true;
|
||||
|
||||
if (FlowCommandControl.GetCurrentRecvProcessData() != null)
|
||||
return false;
|
||||
|
||||
thisConnInfo.m_iSendCommandQueueSize = FlowCommandControl.GetSendQueueSize();
|
||||
thisConnInfo.m_iRecvCommandQueueSize = FlowCommandControl.GetRecvQueueSize();
|
||||
|
||||
if ((thisConnInfo.m_iSendCommandQueueSize + 1) == int.MaxValue)
|
||||
thisConnInfo.m_iSendCommandQueueSize = 0;
|
||||
if ((thisConnInfo.m_iRecvCommandQueueSize + 1) == int.MaxValue)
|
||||
thisConnInfo.m_iRecvCommandQueueSize = 0;
|
||||
|
||||
XData getXData = FlowCommandControl.GetResultPacketData();
|
||||
|
||||
if (getXData == null)
|
||||
return false;
|
||||
|
||||
BASE_PROTOCOL GET_PROTOCOL = getXData.BaseProtocol;
|
||||
BASE_PROTOCOL.PROTOCOL_CODE CODE = GET_PROTOCOL.GET_CURRENT_PROTOCOL;
|
||||
|
||||
HEADER_PACKET getHeader = getXData.HeaderPacket;
|
||||
object objData = getXData.objData;
|
||||
|
||||
thisConnInfo.OnCommandCheckTime();
|
||||
|
||||
switch (CODE)
|
||||
{
|
||||
case BASE_PROTOCOL.PROTOCOL_CODE.CONNECT_STATE:
|
||||
{
|
||||
PING_PACKET GetPingPacket = (PING_PACKET)objData;
|
||||
|
||||
string strGetMsg = GetPingPacket.objCheckMsg[0].Data;
|
||||
|
||||
strCheckCommandMsg = strGetMsg;
|
||||
|
||||
if (strCheckCommandMsg.IndexOf("TLRL") >= 0)
|
||||
{
|
||||
string[] getStationCheck = strCheckCommandMsg.Split(';');
|
||||
|
||||
if (getStationCheck.Length >= 2)
|
||||
{
|
||||
int nGetStaionID = Convert.ToInt32(getStationCheck[1]);
|
||||
|
||||
if (dicTestListNeedReload.ContainsKey(nGetStaionID))
|
||||
{
|
||||
if (dicTestListNeedReload[nGetStaionID] == false)
|
||||
dicTestListNeedReload[nGetStaionID] = true;
|
||||
}
|
||||
else
|
||||
dicTestListNeedReload.Add(nGetStaionID, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BASE_PROTOCOL.PROTOCOL_CODE.DATASET_TRANSEFER:
|
||||
{
|
||||
/*bQueryResult = getXData.bReplayResult;
|
||||
|
||||
if (bQueryResult)
|
||||
{
|
||||
//Query 문 실행 성공
|
||||
QueryDataSet = objData as DataSet;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Query 문 실행 실패(구문 오류 또는 연결 오류)
|
||||
QueryDataSet = null;
|
||||
}*/
|
||||
}
|
||||
break;
|
||||
case BASE_PROTOCOL.PROTOCOL_CODE.HOST_INFO_CHECK:
|
||||
{
|
||||
thisConnInfo.stLoginTimeOut.Restart();
|
||||
thisConnInfo.bHostLoginState = false;
|
||||
|
||||
SYSTEM_HOST_PACKET usPacket = (SYSTEM_HOST_PACKET)objData;
|
||||
|
||||
string strGetHostID = usPacket.objHostID[0].Data;
|
||||
string strGetSection = usPacket.objSection[0].Data;
|
||||
string strGetTestCode = usPacket.objTestCode[0].Data;
|
||||
string strGetMessage = usPacket.objMessage[0].Data;
|
||||
|
||||
if (strGetMessage.IndexOf("[SUCCESS]") >= 0)
|
||||
{
|
||||
thisConnInfo.bHostLoginState = true;
|
||||
|
||||
SubscribeConnectInfo.bSubscriberClientResult = true;
|
||||
|
||||
if (SubscribeConnectInfo.bUIMUseMode)
|
||||
{
|
||||
SubscribeConnectInfo.SessionTimeSet();
|
||||
|
||||
SubscribeConnectInfo.bSessionStarted = true;
|
||||
}
|
||||
}
|
||||
|
||||
AdaptorInformation.LOGIN_RESULT = thisConnInfo.bHostLoginState;
|
||||
AdaptorInformation.LOGIN_MESSAGE = strGetMessage;
|
||||
|
||||
OnLoginAlarm(null, null);
|
||||
|
||||
if (thisConnInfo.bHostLoginState)
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"Middleware login reply infomation : " + strGetMessage, ConsoleColor.Green, LogMessageLevel.DEBUG);
|
||||
else
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"The middleware connection will be closed after " + (LOGIN_TIMEOUT / 1000).ToString() + " seconds. ", ConsoleColor.Red, LogMessageLevel.DEBUG);
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"Middleware login reply infomation : " + strGetMessage, ConsoleColor.Red, LogMessageLevel.DEBUG);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BASE_PROTOCOL.PROTOCOL_CODE.SYSTEM_QUERY:
|
||||
{
|
||||
QUERY_PACKET usPacket = (QUERY_PACKET)objData;
|
||||
|
||||
string strGetQuery = usPacket.objQueryText[0].Data;
|
||||
}
|
||||
break;
|
||||
case BASE_PROTOCOL.PROTOCOL_CODE.USER_QUERY:
|
||||
break;
|
||||
case BASE_PROTOCOL.PROTOCOL_CODE.RAW_SIZE:
|
||||
break;
|
||||
case BASE_PROTOCOL.PROTOCOL_CODE.ETC:
|
||||
break;
|
||||
case BASE_PROTOCOL.PROTOCOL_CODE.INITILALIZE_INFO:
|
||||
{
|
||||
GetConnectionInfo = (COMM_INFO_PACKET)objData;
|
||||
|
||||
StateClientGetInformation = true;
|
||||
|
||||
if (ConnectStartStyleAuto == false)
|
||||
{
|
||||
//if (getXData.nLabel == PacketFlowControl.CommInfoManualToken)
|
||||
// break;
|
||||
if (GetConnectionInfo.objConnLocalAddress[0].Data.CompareTo("AUTO") == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
//ConnectionInfoRecvEvent?.BeginInvoke(null, null, null, null);
|
||||
//ConnectionInfoRecvEvent?.Invoke(null, null);
|
||||
|
||||
if (GetConnectionInfo.bPortDistribution == false)
|
||||
{
|
||||
OnConnectionInfoRecv(null, null);
|
||||
|
||||
thisConnInfo.InitialInfoState = true;
|
||||
}
|
||||
|
||||
SubscribeConnectInfo.Initialize();
|
||||
|
||||
if (GetConnectionInfo.bPortDistribution)
|
||||
{
|
||||
SubscribeConnectInfo.nChangeCommandPort = GetConnectionInfo.usPortCommandNumber;
|
||||
SubscribeConnectInfo.nChangeStreamPort = GetConnectionInfo.usPortStreamNumber;
|
||||
|
||||
AdaptorAbort();
|
||||
|
||||
SubscribeConnectInfo.bReqConnectAbort = false;
|
||||
SubscribeConnectInfo.bSetChangeConnect = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
string strSetInfoID = string.Empty;
|
||||
string strSetInfoKey = string.Empty;
|
||||
string strSetInfoTestCode = string.Empty;
|
||||
|
||||
if (LoginID.Length > 0)
|
||||
{
|
||||
//UIM 모드 : 사용자 프로그램(Session 존재)
|
||||
SubscribeConnectInfo.bUIMUseMode = true;
|
||||
|
||||
strSetInfoID = LoginID;
|
||||
strSetInfoKey = LoginKEY;
|
||||
|
||||
strSetInfoTestCode = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
strSetInfoID = LoadInfo.HOST_ID;
|
||||
strSetInfoKey = LoadInfo.SECTION;
|
||||
|
||||
strSetInfoTestCode = LoadInfo.TEST_CODE;
|
||||
}
|
||||
|
||||
if (Login(strSetInfoID, strSetInfoKey, strSetInfoTestCode,
|
||||
SubscribeConnectInfo.bUIMUseMode, LoadInfo.SIMPLE_LOOKUP_OPTION) == false)
|
||||
{
|
||||
AdaptorAbort();
|
||||
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"SystemX.Net.XAdaptor.PC Login Unknown Error. [SystemX.Net.PCAdaptor : XPCAdaptor.QueryRecvCommandQueue]", ConsoleColor.Red, LogMessageLevel.DEBUG);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
thisConnInfo.OffCommandTime();
|
||||
|
||||
RecvWaitEvent?.BeginInvoke(waitCommandParam, null, new AsyncCallback(RecvWaitEnd), null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @" General Queue Process <Command> failed.[SystemX.Net.XAdaptor.PC.XPCAdaptor : RecvProcessTask.QueryRecvCommandQueue]\r\n" + ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
|
||||
bState = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
bTaskCommandWaitLock = false;
|
||||
}
|
||||
|
||||
return bState;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,360 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SystemX.Common;
|
||||
using SystemX.Common.Archive;
|
||||
using SystemX.Net.BaseProtocol;
|
||||
using SystemX.Net.Schedule;
|
||||
using static SystemX.Net.Platform.Common.Util.LogMessage;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC
|
||||
{
|
||||
public partial class XAdaptorPC
|
||||
{
|
||||
//private async void SendStreamEvent(byte[] senderData, ScheduleEvent e)
|
||||
private void SendStreamEvent(byte[] senderData, ScheduleEvent e)
|
||||
{
|
||||
try
|
||||
{
|
||||
thisConnInfo.m_iSendStreamCnt++;
|
||||
|
||||
if (thisConnInfo.m_iSendStreamCnt + 1 == int.MaxValue)
|
||||
thisConnInfo.m_iSendStreamCnt = 0;
|
||||
|
||||
if (FlowStreamControl == null)
|
||||
return;
|
||||
|
||||
//소켓 샌드 행위 내부 결과
|
||||
if (e.PROCESS_RESULT == false)
|
||||
{
|
||||
//해당 패킷 횟수 상승 일단 회 차시 기록남기고 드랍
|
||||
FlowStreamControl.SendPacketCycle();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"General <SendStreamEvent> failed.[SystemX.Net.XAdaptor.PC.XPCAdaptor : SendStreamEvent]\r\n" + ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
}
|
||||
//private async void RecvStreamEvent(byte[] senderData, ScheduleEvent e)
|
||||
private void RecvStreamEvent(byte[] senderData, ScheduleEvent e)
|
||||
{
|
||||
try
|
||||
{
|
||||
thisConnInfo.m_iRecvStreamCnt++;
|
||||
|
||||
if (thisConnInfo.m_iRecvStreamCnt + 1 == int.MaxValue)
|
||||
thisConnInfo.m_iRecvStreamCnt = 0;
|
||||
|
||||
if (FlowStreamControl == null)
|
||||
return;
|
||||
|
||||
int iStoreCnt = senderData.Count();
|
||||
byte[] recvStoreBuffer = senderData;
|
||||
|
||||
//소켓 리시브 행위 결과 전송
|
||||
if (e.PROCESS_RESULT == false)
|
||||
{
|
||||
//받기 실패 단순 실패 응답
|
||||
FlowStreamControl.InsertSendQueue(DateTime.Now, XCommons.SetSimpleResponsPacket(new BASE_PROTOCOL(BASE_PROTOCOL.PROTOCOL_CODE.SIMPLE_RESPONSE), false), null, false, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
BASE_PROTOCOL GET_PROTOCOL = XCommons.GetHeaderProtocol(iStoreCnt, recvStoreBuffer);
|
||||
BASE_PROTOCOL.PROTOCOL_CODE GET_CODE = GET_PROTOCOL.GET_CURRENT_PROTOCOL;
|
||||
|
||||
//응답
|
||||
if (GET_CODE == BASE_PROTOCOL.PROTOCOL_CODE.SIMPLE_RESPONSE)
|
||||
{
|
||||
if (XCommons.GetSimpleResponsResult(iStoreCnt, recvStoreBuffer))
|
||||
FlowStreamControl.SetSendPacketDrop();
|
||||
else
|
||||
FlowStreamControl.SendPacketCycle();
|
||||
|
||||
thisConnInfo.OffStreamTime();
|
||||
}
|
||||
//파일 끝 응답
|
||||
else if (GET_CODE == BASE_PROTOCOL.PROTOCOL_CODE.RAW_END)
|
||||
{
|
||||
if (XCommons.GetSimpleResponsResult(iStoreCnt, recvStoreBuffer))
|
||||
FlowStreamControl.RawStoreQueuePOP();
|
||||
else
|
||||
FlowStreamControl.RawStoreQueuePOP();
|
||||
|
||||
thisConnInfo.OffStreamTime();
|
||||
}
|
||||
//일반 응답
|
||||
else
|
||||
{
|
||||
//성공 응답
|
||||
FlowStreamControl.InsertSendQueue(DateTime.Now, XCommons.SetSimpleResponsPacket(new BASE_PROTOCOL(BASE_PROTOCOL.PROTOCOL_CODE.SIMPLE_RESPONSE), true), null, false, false);
|
||||
|
||||
//받은 큐에 넣어놓기
|
||||
FlowStreamControl.InsertRecvQueue(senderData, null, e.nLABEL);
|
||||
|
||||
thisConnInfo.OffStreamTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"General <RecvStreamEvent> failed.[SystemX.Net.XAdaptor.PC.XPCAdaptor : RecvStreamEvent]\r\n" + ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
}
|
||||
private async void WatchRecvStreamQueue()
|
||||
{
|
||||
await Task.Delay(500).ConfigureAwait(false);
|
||||
|
||||
while (!StateClientGetInformation)
|
||||
{
|
||||
await Task.Delay(10).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
thisConnInfo.OnStreamTime();
|
||||
thisConnInfo.OnStreamCheckTime();
|
||||
|
||||
while (!m_bTaskStreamBlock)
|
||||
{
|
||||
await Task.Delay(10).ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
StreamCT.ThrowIfCancellationRequested();
|
||||
}
|
||||
catch (OperationCanceledException CancelEx)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @" Work Canceled. [SystemX.Net.XAdaptor.PC.XPCAdaptor : RecvProcessTask.WatchRecvStreamQueue]\r\n" + CancelEx.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
|
||||
break;
|
||||
}
|
||||
//
|
||||
try
|
||||
{
|
||||
if (StateClientStreamSocketConnect == false)
|
||||
continue;
|
||||
|
||||
if (thisConnInfo.stStreamCheckTime.ElapsedMilliseconds >= 60000)
|
||||
{
|
||||
await SendStreamConnectState().ConfigureAwait(false);
|
||||
|
||||
thisConnInfo.OnStreamCheckTime();
|
||||
}
|
||||
|
||||
if (bTaskStreamWaitLock == false)
|
||||
{
|
||||
bool bResult = QueryRecvStreamQueue();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// throw new CommonScheduleException("General Queue Process failed.[SystemX.Net.XAdaptor.PC.XPCAdaptor : RecvProcessTask.WatchRecvStreamQueue]");
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"General Queue Process failed.[SystemX.Net.XAdaptor.PC.XPCAdaptor : RecvProcessTask.WatchRecvStreamQueue]\r\n" + ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
//return true;
|
||||
}
|
||||
|
||||
private bool StreamQueueCheck()
|
||||
{
|
||||
if (ClientStreamSock == null)
|
||||
return false;
|
||||
|
||||
if (ClientStreamSock != null)
|
||||
{
|
||||
if (ClientStreamSock.CONNECT == false)
|
||||
return false;
|
||||
}
|
||||
//
|
||||
if (FlowStreamControl == null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool QueryRecvStreamQueue()
|
||||
{
|
||||
bool bState = true;
|
||||
|
||||
try
|
||||
{
|
||||
if (StreamQueueCheck() == false)
|
||||
return false;
|
||||
|
||||
bTaskStreamWaitLock = true;
|
||||
//
|
||||
if (FlowStreamControl.GetCurrentRecvProcessData() != null)
|
||||
return false;
|
||||
|
||||
thisConnInfo.m_iSendCommandQueueSize = FlowStreamControl.GetSendQueueSize();
|
||||
thisConnInfo.m_iRecvCommandQueueSize = FlowStreamControl.GetRecvQueueSize();
|
||||
|
||||
if ((thisConnInfo.m_iSendStreamQueueSize + 1) == int.MaxValue)
|
||||
thisConnInfo.m_iSendStreamQueueSize = 0;
|
||||
if ((thisConnInfo.m_iRecvStreamQueueSize + 1) == int.MaxValue)
|
||||
thisConnInfo.m_iRecvStreamQueueSize = 0;
|
||||
|
||||
XData getXData = FlowStreamControl.GetResultPacketData();
|
||||
|
||||
if (getXData == null)
|
||||
return false;
|
||||
|
||||
thisConnInfo.stStreamProcessTime.Restart();
|
||||
|
||||
BASE_PROTOCOL GET_PROTOCOL = getXData.BaseProtocol;
|
||||
BASE_PROTOCOL.PROTOCOL_CODE CODE = GET_PROTOCOL.GET_CURRENT_PROTOCOL;
|
||||
|
||||
HEADER_PACKET getHeader = getXData.HeaderPacket;
|
||||
object objData = getXData.objData;
|
||||
|
||||
thisConnInfo.OnStreamCheckTime();
|
||||
|
||||
switch (CODE)
|
||||
{
|
||||
case BASE_PROTOCOL.PROTOCOL_CODE.CONNECT_STATE:
|
||||
{
|
||||
PING_PACKET GetPingPacket = (PING_PACKET)objData;
|
||||
|
||||
string strGetMsg = GetPingPacket.objCheckMsg[0].Data;
|
||||
|
||||
strCheckStreamMsg = strGetMsg;
|
||||
|
||||
RecvWaitEvent?.BeginInvoke(waitStreamParam, null, new AsyncCallback(RecvWaitEnd), null);
|
||||
}
|
||||
break;
|
||||
case BASE_PROTOCOL.PROTOCOL_CODE.SYNC_TIME_SERVER:
|
||||
{
|
||||
TIME_PACKET GetTimePacket = (TIME_PACKET)objData;
|
||||
|
||||
string strGetMsg = GetTimePacket.objMsg[0].Data;
|
||||
|
||||
RecvWaitEvent?.BeginInvoke(waitStreamParam, null, new AsyncCallback(RecvWaitEnd), null);
|
||||
}
|
||||
break;
|
||||
case BASE_PROTOCOL.PROTOCOL_CODE.MIDDLEWARE_MESSAGE:
|
||||
{
|
||||
MESSAGE_PACKET GetMessagePacket = (MESSAGE_PACKET)objData;
|
||||
|
||||
string strGetMsg = GetMessagePacket.objMessage[0].Data;
|
||||
|
||||
GetMiddlewareMessage = strGetMsg;
|
||||
}
|
||||
break;
|
||||
case BASE_PROTOCOL.PROTOCOL_CODE.FILE_TRANSFER:
|
||||
{
|
||||
byte[] ucFileData = objData as byte[];
|
||||
}
|
||||
break;
|
||||
case BASE_PROTOCOL.PROTOCOL_CODE.TRANSFER_RESULT:
|
||||
{
|
||||
RecvWaitEvent?.BeginInvoke(waitStreamParam, null, new AsyncCallback(RecvWaitEnd), null);
|
||||
}
|
||||
break;
|
||||
case BASE_PROTOCOL.PROTOCOL_CODE.RAW_SIZE:
|
||||
{
|
||||
if (getHeader.uiSourDataNum > 1)
|
||||
{
|
||||
if (thisConnInfo.nFileRecvPos > 0)
|
||||
{
|
||||
if ((thisConnInfo.nFileRecvPos + 1) != getHeader.uiSourDataNum ||
|
||||
thisConnInfo.nFileRecvEndPos == 0)
|
||||
{
|
||||
thisConnInfo.nFileRecvPos = 0;
|
||||
thisConnInfo.nFileRecvEndPos = 0;
|
||||
|
||||
FlowStreamControl.InsertSendQueue(DateTime.Now, XCommons.SetSimpleResponsPacket(new BASE_PROTOCOL(BASE_PROTOCOL.PROTOCOL_CODE.RAW_END), false), null, false, false);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
if (getHeader.uiSourDataNum == 1)
|
||||
{
|
||||
thisConnInfo.lstRecvFileBytes = new List<Tuple<int, byte[]>>();
|
||||
thisConnInfo.lstRecvFileBytes.Clear();
|
||||
|
||||
thisConnInfo.lstRecvFileBytes.Add(new Tuple<int, byte[]>((int)getHeader.uiSourDataNum, objData as byte[]));
|
||||
|
||||
thisConnInfo.nFileRecvPos = (int)getHeader.uiSourDataNum;
|
||||
thisConnInfo.nFileRecvEndPos = (int)getHeader.uiDestDataNum;
|
||||
|
||||
thisConnInfo.strRecvFileName = getHeader.objOptionName[0].Data;
|
||||
thisConnInfo.strRecvExtension = getHeader.objOptionExtension[0].Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
thisConnInfo.lstRecvFileBytes.Add(new Tuple<int, byte[]>((int)getHeader.uiSourDataNum, objData as byte[]));
|
||||
|
||||
thisConnInfo.nFileRecvPos++;
|
||||
}
|
||||
//
|
||||
if (thisConnInfo.nFileRecvPos >= thisConnInfo.nFileRecvEndPos)
|
||||
{
|
||||
int iSize = 0;
|
||||
|
||||
foreach (Tuple<int, byte[]> tData in thisConnInfo.lstRecvFileBytes)
|
||||
iSize += tData.Item2.Count();
|
||||
|
||||
byte[] ucGetDatas = new byte[iSize];
|
||||
|
||||
int iCopyPos = 0;
|
||||
|
||||
foreach (Tuple<int, byte[]> tData in thisConnInfo.lstRecvFileBytes)
|
||||
{
|
||||
Array.Copy(tData.Item2, 0, ucGetDatas, iCopyPos, tData.Item2.Count());
|
||||
|
||||
iCopyPos += tData.Item2.Count();
|
||||
}
|
||||
|
||||
if (getHeader.usPalletIndex == ushort.MaxValue)
|
||||
{
|
||||
string strGetTestListCntID = getHeader.objVarParam1[0].Data;
|
||||
|
||||
QueryTestListProcess(ucGetDatas, strGetTestListCntID);
|
||||
|
||||
//Task<int> tkProcTestlist = new Task<int>(new Func<int>(() => QueryTestListProcess(ucGetDatas).Result));
|
||||
//tkProcTestlist.Start();
|
||||
|
||||
//PacketFlowControl.TestListResultToken
|
||||
if (FlowStreamControl.STM.GetLabel(getXData.nLabel) == getXData.nLabel)
|
||||
{
|
||||
FlowStreamControl.STM.SetLabel(getXData.nLabel, getXData);
|
||||
|
||||
RecvWaitEvent?.BeginInvoke(waitStreamParam, null, new AsyncCallback(RecvWaitEnd), null);
|
||||
}
|
||||
}
|
||||
|
||||
thisConnInfo.nFileRecvPos = 0;
|
||||
thisConnInfo.nFileRecvEndPos = 0;
|
||||
|
||||
FlowStreamControl.InsertSendQueue(DateTime.Now, XCommons.SetSimpleResponsPacket(new BASE_PROTOCOL(BASE_PROTOCOL.PROTOCOL_CODE.RAW_END), true), null, false, false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
thisConnInfo.lStreamTime = thisConnInfo.stStreamProcessTime.ElapsedMilliseconds;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @" General Queue Process <Stream> failed.[SystemX.Net.XAdaptor.PC.XPCAdaptor : PCAdaptor.QueryRecvStreamQueue]\r\n" + ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
|
||||
bState = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
bTaskStreamWaitLock = false;
|
||||
}
|
||||
|
||||
return bState;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,258 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SystemX.Common;
|
||||
using SystemX.Common.Archive;
|
||||
using SystemX.Net.BaseProtocol;
|
||||
using SystemX.Net.Schedule;
|
||||
|
||||
using static SystemX.Net.Platform.Common.Util.LogMessage;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC
|
||||
{
|
||||
public partial class XAdaptorPC
|
||||
{
|
||||
private async void WatchSubProcess()
|
||||
{
|
||||
await Task.Delay(500).ConfigureAwait(false);
|
||||
|
||||
while (!StateClientGetInformation)
|
||||
{
|
||||
await Task.Delay(10).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
while (!m_bTaskSubBlock)
|
||||
{
|
||||
await Task.Delay(10).ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
StreamCT.ThrowIfCancellationRequested();
|
||||
}
|
||||
catch (OperationCanceledException CancelEx)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @" Work Canceled. [SystemX.Net.XAdaptor.PC.XPCAdaptor : ProcessTask.WatchFailedFile]\r\n" + CancelEx.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
|
||||
break;
|
||||
}
|
||||
//
|
||||
try
|
||||
{
|
||||
if (StateClientStreamSocketConnect == false)
|
||||
continue;
|
||||
///
|
||||
/// 5분이상 기존 파일전송이 없을 경우
|
||||
///
|
||||
if (stFileSendTime.ElapsedMilliseconds < FILE_SEND_MAX_WAITTIME)
|
||||
goto ROUTINE_OUT;
|
||||
///
|
||||
/// 직전 전송이 10초 이상 일때(완전 처리 대기)
|
||||
///
|
||||
if (stBackupFileSendTime.ElapsedMilliseconds < FILE_SEND_INTERVAL_TIME)
|
||||
goto ROUTINE_OUT;
|
||||
|
||||
if (bTaskSubLockState)
|
||||
goto ROUTINE_OUT;
|
||||
|
||||
try
|
||||
{
|
||||
bTaskSubLockState = await _smpSlim.WaitAsync(100);
|
||||
|
||||
if (bTaskSubLockState == false)
|
||||
goto ROUTINE_OUT;
|
||||
|
||||
//Scan And Send File
|
||||
//오늘 포함 -6일전까지 검색
|
||||
string[] strYYYY = new string[7];
|
||||
string[] strMM = new string[7];
|
||||
string[] strdd = new string[7];
|
||||
|
||||
for (int i = 6; i >= 0; i--)
|
||||
{
|
||||
DateTime dtSet = DateTime.Today.AddDays(-i);
|
||||
strYYYY[i] = dtSet.ToString("yyyy");
|
||||
strMM[i] = dtSet.ToString("MM");
|
||||
strdd[i] = dtSet.ToString("dd");
|
||||
}
|
||||
//
|
||||
// 7일치 위치 확인
|
||||
//
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
string strGetRoot = Path.GetPathRoot(Environment.CurrentDirectory);
|
||||
|
||||
string DirPath = strGetRoot + $@"\XLog\FileFailedBackup\{LoadInfo.HOST_ID}\{LoadInfo.SECTION}\{strYYYY[i]}\{strMM[i]}\{strdd[i]}\";
|
||||
string DirMovePath = strGetRoot + $@"\XLog\FileFailedBackup\{LoadInfo.HOST_ID}\{LoadInfo.SECTION}\{strYYYY[i]}\{strMM[i]}\{strdd[i]}\History\";
|
||||
|
||||
//생성 폴더가 없을경우 SKIP
|
||||
if (Directory.Exists(DirPath) == false)
|
||||
continue;
|
||||
|
||||
if (Directory.Exists(DirMovePath) == false)
|
||||
Directory.CreateDirectory(DirMovePath);
|
||||
|
||||
string fileExtension = "zip";
|
||||
|
||||
string[] dirs = Directory.GetDirectories(DirPath);
|
||||
string[] files = Directory.GetFiles(DirPath, $"*.{fileExtension}", SearchOption.TopDirectoryOnly);
|
||||
|
||||
if (files.Length > 0)
|
||||
{
|
||||
string strExtractFilePos = string.Empty;
|
||||
string strOrgRemoveFilePos = string.Empty;
|
||||
|
||||
string strHeaderInfo = string.Empty;
|
||||
string strLogFileNameInfo = string.Empty;
|
||||
|
||||
foreach (string f in files)
|
||||
{
|
||||
strOrgRemoveFilePos = f;
|
||||
|
||||
strHeaderInfo = string.Empty;
|
||||
strLogFileNameInfo = string.Empty;
|
||||
|
||||
string[] strInfos = f.Split(';');
|
||||
|
||||
//파일정보 확인(로그 저장관련 정보)
|
||||
string strSetDateTime = strInfos[1];
|
||||
string strSetStationName = strInfos[2];
|
||||
int nSetTestListVariantNo = int.Parse(strInfos[3]);
|
||||
string strSetProcNoP = strInfos[4];
|
||||
string strSetProcNoC = strInfos[5];
|
||||
string strSetTestType = strInfos[6];
|
||||
string strSetTestCode = strInfos[7];
|
||||
string strSetVersion = strInfos[8];
|
||||
string strSetProdCode = strInfos[9];
|
||||
string strSetTestListCntID = strInfos[10];
|
||||
int nSetTryNo = int.Parse(strInfos[11]);
|
||||
|
||||
for (int n = 1; n < 10; n++)
|
||||
strHeaderInfo += (strInfos[n + 1] + ";");
|
||||
|
||||
strHeaderInfo = strHeaderInfo.Remove(strHeaderInfo.Length - 1, 1);
|
||||
|
||||
//압축해제 하여 로그 파일 추출
|
||||
using (FileStream fs = new FileStream(f, FileMode.Open))
|
||||
using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Update, false))
|
||||
{
|
||||
foreach (ZipArchiveEntry zae in zip.Entries)
|
||||
{
|
||||
strLogFileNameInfo = zae.FullName;
|
||||
|
||||
if (strLogFileNameInfo.IndexOf(".txt") >= 0)
|
||||
continue;
|
||||
|
||||
strExtractFilePos = DirPath + strLogFileNameInfo;
|
||||
|
||||
zae.ExtractToFile(strExtractFilePos, true);
|
||||
}
|
||||
}
|
||||
|
||||
//로그 파일 전송
|
||||
if (await AsyncFailedLogFileTransfer(strExtractFilePos,
|
||||
strSetStationName,
|
||||
nSetTestListVariantNo,
|
||||
strSetProcNoP,
|
||||
strSetProcNoC,
|
||||
strSetTestType,
|
||||
strSetTestCode,
|
||||
strSetVersion,
|
||||
strSetProdCode,
|
||||
strSetTestListCntID) == eFileSendRecvResult.FileProcSuccess)
|
||||
{
|
||||
//성공시
|
||||
string strCopyPos = DirMovePath;
|
||||
for (int n = 0; n < 10; n++)
|
||||
strCopyPos += (";" + strInfos[n + 1]);
|
||||
|
||||
strCopyPos += (";" + nSetTryNo.ToString() + ";.zip");
|
||||
|
||||
File.Copy(f, strCopyPos, true);
|
||||
|
||||
XAdaptorFileLogWrite(eSetFileLogCategory.FileLog, strYYYY[i], strMM[i], strdd[i], strHeaderInfo, strLogFileNameInfo, "FailedFileTrySend>Success");
|
||||
}
|
||||
else
|
||||
{
|
||||
//실패시
|
||||
nSetTryNo++;
|
||||
|
||||
string strTryNo = string.Empty;
|
||||
|
||||
string strCopyPos = string.Empty;
|
||||
|
||||
//재시도 3회 초과 일시 히스토리로 이동
|
||||
if (nSetTryNo > 3)
|
||||
{
|
||||
strCopyPos = DirMovePath;
|
||||
|
||||
strTryNo = "X";
|
||||
|
||||
XAdaptorFileLogWrite(eSetFileLogCategory.FileLog, strYYYY[i], strMM[i], strdd[i], strHeaderInfo, strLogFileNameInfo, "FailedFileTrySend>UnprocessableFile");
|
||||
}
|
||||
else
|
||||
{
|
||||
strCopyPos = DirPath;
|
||||
|
||||
strTryNo = nSetTryNo.ToString();
|
||||
|
||||
XAdaptorFileLogWrite(eSetFileLogCategory.FileLog, strYYYY[i], strMM[i], strdd[i], strHeaderInfo, strLogFileNameInfo, "FailedFileTrySend>Fail");
|
||||
}
|
||||
|
||||
for (int n = 0; n < 10; n++)
|
||||
strCopyPos += (";" + strInfos[n + 1]);
|
||||
|
||||
strCopyPos += (";" + strTryNo + ";.zip");
|
||||
|
||||
File.Copy(f, strCopyPos, true);
|
||||
}
|
||||
|
||||
//압축해제 파일 삭제
|
||||
File.Delete(strExtractFilePos);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
//성공시나 실패시 새로운 파일생성 되기 때문에 기존 파일 삭제
|
||||
if (strOrgRemoveFilePos != string.Empty)
|
||||
File.Delete(strOrgRemoveFilePos);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
stBackupFileSendTime.Restart();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (bTaskSubLockState)
|
||||
{
|
||||
try
|
||||
{
|
||||
_smpSlim.Release();
|
||||
}
|
||||
catch
|
||||
{
|
||||
;//smp release lock exception
|
||||
}
|
||||
|
||||
bTaskSubLockState = false;
|
||||
}
|
||||
}
|
||||
|
||||
ROUTINE_OUT:;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"General Queue Process failed.[SystemX.Net.XAdaptor.PC.XPCAdaptor : ProcessTask.WatchFailedFile]\r\n" + ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,413 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using SystemX.Common;
|
||||
using SystemX.Common.Archive;
|
||||
using SystemX.Common.Serialization;
|
||||
using SystemX.Net.BaseProtocol;
|
||||
using SystemX.Net.Comm;
|
||||
using SystemX.Net.XAdaptor.PC.O2Sensor.NgCode;
|
||||
using SystemX.Net.Schedule;
|
||||
using SystemX.Net.XAdaptor;
|
||||
using static SystemX.Net.Platform.Common.Util.LogMessage;
|
||||
using WTimer = System.Windows.Forms.Timer;
|
||||
|
||||
namespace SystemX.Net.XAdaptor.PC
|
||||
{
|
||||
public partial class XAdaptorPC
|
||||
{
|
||||
private bool QueryTestListProcess(byte[] ucGetDatas, string strGetTestListCntID)
|
||||
{
|
||||
bool bSetResult = false;
|
||||
|
||||
try
|
||||
{
|
||||
DataSet QueryTestList = null;
|
||||
QueryTestList = XDataArchive.DecompressByteToDataset(ucGetDatas);
|
||||
|
||||
(mgrPRODTestList as TProdTestListInfo).SetTestListDataSet(QueryTestList);
|
||||
(mgrPRODTestList as TProdTestListInfo).SetTestListCntID(strGetTestListCntID);
|
||||
|
||||
if (XCommons.isHasRow(mgrPRODTestList.getTestListDataSet()))
|
||||
{
|
||||
if (mgrPRODTestList.getTestListDataSet().Tables[0].Columns.Contains("TestListData"))
|
||||
{
|
||||
int iCol1 = mgrPRODTestList.getTestListDataSet().Tables[0].Columns.IndexOf("TestListData");
|
||||
mgrPRODTestList.getTestListDataSet().Tables[0].Columns[iCol1].ColumnMapping = MappingType.Hidden;
|
||||
}
|
||||
if (mgrPRODTestList.getTestListDataSet().Tables[0].Columns.Contains("FileName"))
|
||||
{
|
||||
int iCol2 = mgrPRODTestList.getTestListDataSet().Tables[0].Columns.IndexOf("FileName");
|
||||
}
|
||||
|
||||
bSetResult = true;
|
||||
}
|
||||
|
||||
base.ServerTestListLoadState = true;
|
||||
|
||||
//QueryCallEvent?.BeginInvoke(mgrPRODTestList.getTestListDataSet(), new ResultEventArgs(bSetResult), null, null);
|
||||
OnBeginQueryCall(mgrPRODTestList.getTestListDataSet(), new ResultEventArgs(bSetResult));
|
||||
}
|
||||
catch
|
||||
{
|
||||
bSetResult = false;
|
||||
}
|
||||
|
||||
finally
|
||||
{
|
||||
;//
|
||||
}
|
||||
|
||||
return bSetResult;
|
||||
}
|
||||
|
||||
/*
|
||||
private async void ClientCommandConnect()
|
||||
{
|
||||
dbNgCodeFinder = null;
|
||||
|
||||
ConnectCommandWaitEvent.Reset();
|
||||
StateAdaptorConnect &= ClientCommandSet(SOCKET_TYPE.TCP, false);
|
||||
|
||||
if (ConnectCommandWaitEvent.WaitOne(CONNECT_TIME_OUT))
|
||||
SetCommandWatchTask();
|
||||
else
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"SystemX.Net.XAdaptor.PC Command Connect Error.[SystemX.Net.PCAdaptor : XPCAdaptor.XPCAdaptor]", ConsoleColor.Red, LogMessageLevel.DEBUG);
|
||||
|
||||
await Task.Delay(1).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async void ClientStreamConnect()
|
||||
{
|
||||
ConnectStreamWaitEvent.Reset();
|
||||
StateAdaptorConnect &= ClientStreamSet(SOCKET_TYPE.TCP, false);
|
||||
|
||||
if (ConnectStreamWaitEvent.WaitOne(CONNECT_TIME_OUT))
|
||||
SetStreamWatchTask();
|
||||
else
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"SystemX.Net.XAdaptor.PC Stream Connect Error.[SystemX.Net.PCAdaptor : XPCAdaptor.XPCAdaptor]", ConsoleColor.Red, LogMessageLevel.DEBUG);
|
||||
|
||||
await Task.Delay(1).ConfigureAwait(false);
|
||||
}
|
||||
*/
|
||||
|
||||
private void ClearCommandClientInstance()
|
||||
{
|
||||
if (FlowCommandControl != null)
|
||||
{
|
||||
FlowCommandControl.Dispose();
|
||||
FlowCommandControl = null;
|
||||
}
|
||||
|
||||
if (ClientCommandSock != null)
|
||||
{
|
||||
ClientCommandSock.Comm_Connect_Event -= ClientCommandConnectEvent;
|
||||
ClientCommandSock.Socket_Error_Event -= ClientCommandErrorEvent;
|
||||
|
||||
ClientCommandSock.Comm_Send_Event -= SendCommandEvent;
|
||||
ClientCommandSock.Comm_Recv_Event -= RecvCommandEvent;
|
||||
|
||||
ClientCommandSock.Dispose();
|
||||
ClientCommandSock = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearStreamClientInstance()
|
||||
{
|
||||
if (FlowStreamControl != null)
|
||||
{
|
||||
FlowStreamControl.Dispose();
|
||||
FlowStreamControl = null;
|
||||
}
|
||||
|
||||
if (ClientStreamSock != null)
|
||||
{
|
||||
ClientStreamSock.Comm_Connect_Event -= ClientStreamConnectEvent;
|
||||
ClientStreamSock.Socket_Error_Event -= ClientStreamErrorEvent;
|
||||
|
||||
ClientStreamSock.Comm_Send_Event -= SendStreamEvent;
|
||||
ClientStreamSock.Comm_Recv_Event -= RecvStreamEvent;
|
||||
|
||||
ClientStreamSock.Dispose();
|
||||
ClientStreamSock = null;
|
||||
}
|
||||
}
|
||||
|
||||
private IPAddress GetConnectIPAddress()
|
||||
{
|
||||
IPAddress setIP = null;
|
||||
|
||||
if (LoadInfo.LOOP_BACK)
|
||||
setIP = IPAddress.Loopback;
|
||||
else
|
||||
{
|
||||
if (REF_CONNECT_IP.Length > 0)
|
||||
setIP = IPAddress.Parse(REF_CONNECT_IP);
|
||||
else
|
||||
setIP = IPAddress.Parse(LoadInfo.CONNECT_IP);
|
||||
}
|
||||
|
||||
return setIP;
|
||||
}
|
||||
|
||||
private int GetDistributionPort(Random r, int nStartPort)
|
||||
{
|
||||
//최대값 미만 + 1
|
||||
r.Next();
|
||||
return r.Next(nStartPort, nStartPort + 10);
|
||||
}
|
||||
|
||||
private bool ClientCommandSet(SOCKET_TYPE SOCK_TYPE, bool bUseRandDistribution = true, int nSetPortNumber = int.MaxValue)
|
||||
{
|
||||
thisConnInfo.bHostLoginState = true;
|
||||
|
||||
bool bClientStartState = true;
|
||||
//
|
||||
int nPortNumber = int.MaxValue;
|
||||
|
||||
if (nSetPortNumber == int.MaxValue)
|
||||
{
|
||||
nPortNumber = LoadInfo.COMMAND_PORT;
|
||||
}
|
||||
else
|
||||
nPortNumber = nSetPortNumber;
|
||||
|
||||
if (bUseRandDistribution)
|
||||
{
|
||||
Random r = new Random((int)(DateTime.Now.Ticks));
|
||||
|
||||
nPortNumber = GetDistributionPort(r, nPortNumber);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (ClientReadyEndPoint == false)
|
||||
{
|
||||
/*if (LoadInfo.LOOP_BACK)
|
||||
ClientCommandEP = new IPEndPoint(IPAddress.Loopback, nPortNumber);
|
||||
else
|
||||
ClientCommandEP = new IPEndPoint(IPAddress.Parse(LoadInfo.CONNECT_IP), nPortNumber);*/
|
||||
|
||||
if (LoadInfo.LOOP_BACK)
|
||||
ClientCommandEP = new IPEndPoint(GetConnectIPAddress(), nPortNumber);
|
||||
else
|
||||
ClientCommandEP = new IPEndPoint(GetConnectIPAddress(), nPortNumber);
|
||||
}
|
||||
|
||||
ClearCommandClientInstance();
|
||||
|
||||
//COMMAND
|
||||
#if FALSE
|
||||
ClientCommandSock = new AsyncComClientSocket(ClientCommandEP);
|
||||
#else
|
||||
ClientCommandSock = new AsyncClientSocket(SOCK_TYPE, ClientCommandEP);
|
||||
#endif
|
||||
|
||||
ClientCommandSock.Comm_Connect_Event += ClientCommandConnectEvent;
|
||||
ClientCommandSock.Socket_Error_Event += ClientCommandErrorEvent;
|
||||
|
||||
ClientCommandSock.Comm_Send_Event += SendCommandEvent;
|
||||
ClientCommandSock.Comm_Recv_Event += RecvCommandEvent;
|
||||
|
||||
FlowCommandControl = new PacketFlowControl(FlowControlType.Commnad, ClientCommandSock);
|
||||
|
||||
ClientCommandSock.Connect();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
bClientStartState = false;
|
||||
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"Client Command connect set failed.[SystemX.Net.XAdaptor.PC.XPCAdaptor : XPCAdaptor.ClientCommandSet()]\r\n" + ex.Message, ConsoleColor.Red, LogMessageLevel.DEBUG);
|
||||
}
|
||||
|
||||
return bClientStartState;
|
||||
}
|
||||
|
||||
private bool ClientStreamSet(SOCKET_TYPE SOCK_TYPE, bool bUseRandDistribution = true, int nSetPortNumber = int.MaxValue)
|
||||
{
|
||||
bool bClientStartState = true;
|
||||
|
||||
int nPortNumber = int.MaxValue;
|
||||
|
||||
if (nSetPortNumber == int.MaxValue)
|
||||
nPortNumber = LoadInfo.STREAM_PORT;
|
||||
else
|
||||
nPortNumber = nSetPortNumber;
|
||||
|
||||
if (bUseRandDistribution)
|
||||
{
|
||||
Random r = new Random((int)(DateTime.Now.Ticks));
|
||||
|
||||
nPortNumber = GetDistributionPort(r, nPortNumber);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (ClientReadyEndPoint == false)
|
||||
{
|
||||
if (LoadInfo.LOOP_BACK)
|
||||
ClientStreamEP = new IPEndPoint(GetConnectIPAddress(), nPortNumber);
|
||||
else
|
||||
ClientStreamEP = new IPEndPoint(GetConnectIPAddress(), nPortNumber);
|
||||
|
||||
/*if (LoadInfo.LOOP_BACK)
|
||||
ClientStreamEP = new IPEndPoint(IPAddress.Loopback, nPortNumber);
|
||||
else
|
||||
ClientStreamEP = new IPEndPoint(IPAddress.Parse(LoadInfo.CONNECT_IP), nPortNumber);*/
|
||||
}
|
||||
|
||||
ClearStreamClientInstance();
|
||||
|
||||
//STREAM
|
||||
#if FALSE
|
||||
ClientStreamSock = new AsyncComClientSocket(ClientStreamEP);
|
||||
#else
|
||||
ClientStreamSock = new AsyncClientSocket(SOCK_TYPE, ClientStreamEP);
|
||||
#endif
|
||||
|
||||
ClientStreamSock.Comm_Connect_Event += ClientStreamConnectEvent;
|
||||
ClientStreamSock.Socket_Error_Event += ClientStreamErrorEvent;
|
||||
|
||||
ClientStreamSock.Comm_Send_Event += SendStreamEvent;
|
||||
ClientStreamSock.Comm_Recv_Event += RecvStreamEvent;
|
||||
|
||||
FlowStreamControl = new PacketFlowControl(FlowControlType.Stream, ClientStreamSock);
|
||||
|
||||
ClientStreamSock.Connect();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
bClientStartState = false;
|
||||
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"Client Stream connect set failed.[SystemX.Net.XAdaptor.PC.XPCAdaptor : XPCAdaptor.ClientStreamSet()]\r\n" + ex.Message, ConsoleColor.Red, LogMessageLevel.DEBUG);
|
||||
}
|
||||
|
||||
return bClientStartState;
|
||||
}
|
||||
|
||||
private void ClearCommonVar()
|
||||
{
|
||||
SubscribeConnectInfo.bSessionStarted = false;
|
||||
}
|
||||
|
||||
private void ClearCommandWatchTask()
|
||||
{
|
||||
CommandCTS.Cancel();
|
||||
|
||||
if (taskRecvCommandProcess != null)
|
||||
{
|
||||
taskRecvCommandProcess.ContinueWith(t =>
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"taskRecvCommandProcess END. [SystemX.Net.XAdaptor.PC : XPCAdaptor.ClearWatchTask - Command]",
|
||||
ConsoleColor.White,
|
||||
LogMessageLevel.DEBUG);
|
||||
});
|
||||
|
||||
m_bTaskCommandBlock = true;
|
||||
|
||||
taskRecvCommandProcess.ConfigureAwait(false);
|
||||
//taskRecvCommandProcess.Wait();
|
||||
|
||||
taskRecvCommandProcess = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearStreamWatchTask()
|
||||
{
|
||||
StreamCTS.Cancel();
|
||||
|
||||
if (taskRecvStreamProcess != null)
|
||||
{
|
||||
taskRecvStreamProcess.ContinueWith(t =>
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"taskRecvStreamProcess END. [SystemX.Net.XAdaptor.PC : XPCAdaptor.ClearWatchTask - Stream]",
|
||||
ConsoleColor.White,
|
||||
LogMessageLevel.DEBUG);
|
||||
});
|
||||
|
||||
m_bTaskStreamBlock = true;
|
||||
|
||||
taskRecvStreamProcess.ConfigureAwait(false);
|
||||
//taskRecvStreamProcess.Wait();
|
||||
|
||||
taskRecvStreamProcess = null;
|
||||
}
|
||||
//
|
||||
SubCTS.Cancel();
|
||||
|
||||
if (taskSubProcess != null)
|
||||
{
|
||||
taskSubProcess.ContinueWith(t =>
|
||||
{
|
||||
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
|
||||
@"taskSubProcess END. [SystemX.Net.XAdaptor.PC : XPCAdaptor.ClearWatchTask - Stream(Sub)]",
|
||||
ConsoleColor.White,
|
||||
LogMessageLevel.DEBUG);
|
||||
});
|
||||
|
||||
m_bTaskSubBlock = true;
|
||||
|
||||
taskSubProcess.ConfigureAwait(false);
|
||||
//taskSubProcess.Wait();
|
||||
|
||||
taskSubProcess = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetCommandWatchTask()
|
||||
{
|
||||
if (StateAdaptorConnect == false)
|
||||
return;
|
||||
|
||||
ClearCommandWatchTask();
|
||||
|
||||
taskRecvCommandProcess = null;
|
||||
m_bTaskCommandBlock = false;
|
||||
|
||||
CommandCTS = new CancellationTokenSource();
|
||||
CommandCT = CommandCTS.Token;
|
||||
|
||||
taskRecvCommandProcess = new Task(new Action(WatchRecvCommandQueue), CommandCT);
|
||||
taskRecvCommandProcess.Start();
|
||||
}
|
||||
|
||||
private void SetStreamWatchTask()
|
||||
{
|
||||
if (StateAdaptorConnect == false)
|
||||
return;
|
||||
|
||||
ClearStreamWatchTask();
|
||||
|
||||
taskRecvStreamProcess = null;
|
||||
m_bTaskStreamBlock = false;
|
||||
|
||||
StreamCTS = new CancellationTokenSource();
|
||||
StreamCT = StreamCTS.Token;
|
||||
|
||||
taskRecvStreamProcess = new Task(new Action(WatchRecvStreamQueue), StreamCT);
|
||||
taskRecvStreamProcess.Start();
|
||||
//
|
||||
taskSubProcess = null;
|
||||
m_bTaskSubBlock = false;
|
||||
|
||||
SubCTS = new CancellationTokenSource();
|
||||
SubCT = StreamCTS.Token;
|
||||
|
||||
taskSubProcess = new Task(new Action(WatchSubProcess), SubCT);
|
||||
taskSubProcess.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user