예제 #1
0
        /// <summary>
        ///   Constructor creates an instance of the class from a pointer address, and expands
        ///   the data packet into the originating channel name and message.
        /// </summary>
        /// <param name = "lpParam">A pointer the a COPYDATASTRUCT containing information required to
        ///   expand the DataGram.</param>
        private WinMsgDataGram(IntPtr lpParam)
        {
            allocatedMemory = false;

            dataStruct = (Native.COPYDATASTRUCT)Marshal.PtrToStructure(lpParam, typeof(Native.COPYDATASTRUCT));
            var bytes = new byte[dataStruct.cbData];

            Marshal.Copy(dataStruct.lpData, bytes, 0, dataStruct.cbData);

            string rawmessage;

            using (var stream = new MemoryStream(bytes))
            {
                var b = new BinaryFormatter();
                rawmessage = (string)b.Deserialize(stream);
            }

            dataGram = JsonConvert.DeserializeObject <DataGram>(rawmessage);
        }
예제 #2
0
        private TypedDataGram(DataGram dataGram)
        {
            Validate.That(dataGram).IsNotNull();

            this.dataGram = dataGram;
        }
예제 #3
0
 /// <summary>
 ///   Constructor which creates the data gram from a message and channel name.
 /// </summary>
 /// <param name = "serializer"></param>
 /// <param name = "channel">The channel through which the message will be sent.</param>
 /// <param name = "message">The string message to send.</param>
 internal WinMsgDataGram(string channel, string message)
 {
     allocatedMemory = false;
     dataStruct      = new Native.COPYDATASTRUCT();
     dataGram        = new DataGram(channel, message);
 }
예제 #4
0
 /// <summary>
 ///   Constructor used to create a new instance from a DataGram struct.
 /// </summary>
 /// <param name = "dataGram">The DataGram instance.</param>
 public MessageEventArgs(DataGram dataGram)
 {
     this.dataGram = dataGram;
 }