[성현모] CPXV2 Init
This commit is contained in:
@ -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