1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
5 using System
.Collections
.Generic
;
8 using System
.Net
.Sockets
;
9 using System
.Windows
.Forms
;
10 using System
.Threading
;
14 class SocketLogProcessor
16 public LogData
ProcessLog(StatoscopeForm ssForm
)
18 TcpClient client
= null;
19 bool bShouldLogToFile
= false;
20 string connectionName
= "";
22 using (ConnectMessageBox connectMsgBox
= new ConnectMessageBox())
24 bool successful
= false;
27 if (connectMsgBox
.ShowDialog() == DialogResult
.OK
)
31 client
= new TcpClient(connectMsgBox
.IpAddress
, connectMsgBox
.Port
);
32 bShouldLogToFile
= connectMsgBox
.logToFileCheckBox
.Checked
;
33 connectionName
= connectMsgBox
.ConnectionName
;
39 ConnectionErrorDialog ced
= new ConnectionErrorDialog();
40 ced
.errorLabel
.Text
+= connectMsgBox
.IpAddress
+ ":" + connectMsgBox
.Port
;
51 string logWriteFilename
= "";
55 SaveFileDialog fd
= new SaveFileDialog();
56 fd
.CheckFileExists
= false;
57 fd
.FileName
= "log.bin";
58 fd
.Filter
= "Binary log files (*.bin)|*.bin|All files (*.*)|*.*";
61 if (fd
.ShowDialog() == DialogResult
.OK
)
63 logWriteFilename
= fd
.FileName
;
67 SocketSessionInfo sessionInfo
= new SocketSessionInfo(connectionName
, logWriteFilename
);
68 SocketLogData logData
= new SocketLogData(sessionInfo
);
69 logData
.ProcessRecords();
71 List
<LogRange
> logRanges
= new List
<LogRange
>();
72 LogRange logRange
= new LogRange(logData
, null);
74 logRanges
.Add(logRange
);
75 ssForm
.AddToLogRangeList(logRange
);
77 ssForm
.CreateLogControlTabPage(logRanges
, connectionName
, null);
79 ThreadPool
.QueueUserWorkItem(new WaitCallback(ProcessSocketDataStreamCB
), new SSocketParseArgs(logData
, logWriteFilename
, client
));
84 struct SSocketParseArgs
86 public SocketLogData m_logData
;
87 public TcpClient m_client
;
89 public SSocketParseArgs(SocketLogData logData
, string logWriteFilename
, TcpClient client
)
92 m_logData
.m_logWriteFilename
= logWriteFilename
;
97 static void ProcessSocketDataStreamCB(object state
)
99 SSocketParseArgs args
= (SSocketParseArgs
)state
;
100 NetworkStream netStream
= args
.m_client
.GetStream();
102 if (args
.m_logData
.m_logWriteFilename
== "")
104 args
.m_logData
.m_logWriteFilename
= Path
.GetTempFileName();
105 args
.m_logData
.m_bTempFile
= true;
108 using (SocketLogBinaryDataStream logDataStream
= new SocketLogBinaryDataStream(netStream
, args
.m_logData
.m_logWriteFilename
))
112 args
.m_logData
.DataStream
= logDataStream
;
113 BinaryLogParser logParser
= new BinaryLogParser(logDataStream
, args
.m_logData
, "");
114 logParser
.ProcessDataStream();
122 args
.m_client
.Close();