public MessageRecord(CommMessage msg) { SourceIP = msg.GetSourceIP(); ComponentName = msg.GetComponentName(); MessageCommand = msg.GetMessageCommand(); MessageTimestamp = msg.GetMessageTimestamp(); IsBinary = msg.GetIsBinary(); if (IsBinary) { DataBinary = new byte[msg.GetDataSize()]; msg.Data.CopyTo(DataBinary, 0); } else { DataString = msg.GetDataString(); } }
//private async void OnNewFileWatcherEvent(FileWatcherEventArgs e) private void OnNewFileWatcherEvent(FileWatcherEventArgs e) { Logger.LogInfo(this, "OnNewFileWatcherEvent() filesCount:'{0}'", e.GetFileNameList().Count); foreach (String fileName in e.GetFileNameList()) { byte[] msg = File.ReadAllBytes(fileName); CommMessage commMessage = new CommMessage(msg); Console.WriteLine("-> Request FileName:{0}, data:{1}", fileName, commMessage.GetDataString()); while (!SendData(msg)) { Console.WriteLine("SendData fail... retry..."); //await PutTaskDelay(); } File.Delete(fileName); } e.Resume(); }
static void Main(string[] args) { CommMessage test = new CommMessage(); int sizeTest = test.GetMsgByteSize(); byte[] data = Encoding.Unicode.GetBytes("DATA ENCODED"); CommMessage msg = new CommMessage((ushort)1, false, "COMP01", DateTime.Now.ToString("yyyyMMddHHmmssffff"), (uint)data.Length, data); byte[] dataParsed = new byte[msg.GetMsgByteSize()]; msg.ToByteArray().CopyTo(dataParsed, 0); File.WriteAllBytes("TESTMSG.TMP", dataParsed); byte[] dataReaded = File.ReadAllBytes("TESTMSG.TMP"); CommMessage msgReaded = new CommMessage(dataReaded); Console.WriteLine(msgReaded.GetComponentName()); Console.WriteLine(msgReaded.GetDataString()); Console.ReadKey(); }