Exemple #1
0
        public void AppendMessage(CommMessage msg)
        {
            Logger.LogInfo(this, "AppendMessage() msg:'{0}'", msg.GetComponentName());

            byte[] writeByte = msg.ToByteArray();
            string fileName  = EventFilePath + msg.GetMessageTimestamp();

            Logger.LogDebug(this, "Writing '{0}' bytes in file '{1}'", writeByte.Length, fileName);
            File.WriteAllBytes(fileName + ".TMP", writeByte);
            Logger.LogDebug(this, "rename temp file '{0}' to '{1}'", fileName + ".TMP", fileName + ".BIN");
            File.Move(fileName + ".TMP", fileName + ".BIN");
        }
 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();
     }
 }
Exemple #3
0
        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();
        }