/// <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); }
private TypedDataGram(DataGram dataGram) { Validate.That(dataGram).IsNotNull(); this.dataGram = dataGram; }
/// <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); }
/// <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; }