Example #1
0
        private TypedDataGram(DataGram dataGram, ISerializer serializer)
        {
            Validate.That(dataGram).IsNotNull();

            objectSerializer = serializer;
            this.dataGram    = dataGram;
        }
        private TypedDataGram(DataGram dataGram, ISerializer serializer)
        {
            dataGram.Requires("dataGram").IsNotNull();
            serializer.Requires("serializer").IsNotNull();

            objectSerializer = serializer;
            this.dataGram    = dataGram;
        }
        internal WinMsgDataGram(ISerializer serializer, string channel, string dataType, string message)
        {
            serializer.Requires("serializer").IsNotNull();

            this.serializer = serializer;
            allocatedMemory = false;
            dataStruct = new Native.COPYDATASTRUCT();
            dataGram = new DataGram(channel, dataType, message);
        }
        private void SendToChannel(string channel, string dataType, string message)
        {
            channel.Requires("channel").IsNotNull();
            dataType.Requires("dataType").IsNotNull();
            message.Requires("message").IsNotNullOrWhiteSpace();

            var topic = topicRepository.GetTopic(channel);
            var dataGram = new DataGram(channel, dataType, message);
            var data = serializer.Serialize(dataGram);

            publisherService.Publish(topic, dataGram.Channel, data);
        }
        public void GivenADatagramThenWhenSerializedAssertSuccess()
        {
            // arrange
            var dataGram = new DataGram(channel, assemblyQualifiedName, message);

            // act
            var result = serializer.Serialize(dataGram);

            // assert
            Assert.That(result, Is.StringContaining(channel));
            Assert.That(result, Is.StringContaining(message));
            Assert.That(result, Is.StringContaining(assemblyQualifiedName));
            Assert.That(result, Is.StringContaining("1.1"));
        }
        private WinMsgDataGram(IntPtr lpParam, ISerializer serializer)
        {
            serializer.Requires("serializer").IsNotNull();

            this.serializer = serializer;
            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 = serializer.Deserialize<DataGram>(rawmessage);
        }
 public XDMessageEventArgs(DataGram dataGram)
 {
     DataGram = dataGram;
 }
        private void SendToChannel(string channelName, string dataType, string message)
        {
            channelName.Requires("channelName").IsNotNullOrWhiteSpace();
            dataType.Requires("dataType").IsNotNullOrWhiteSpace();
            message.Requires("message").IsNotNullOrWhiteSpace();

            var fileName = Guid.NewGuid().ToString();
            var folder = GetChannelDirectory(channelName);
            var filePath = Path.Combine(folder, string.Concat(fileName, ".msg"));

            using (var writer = File.CreateText(filePath))
            {
                var dataGram = new DataGram(channelName, dataType, message);
                writer.Write(serializer.Serialize(dataGram));
                writer.Flush();
            }

            ThreadPool.QueueUserWorkItem(CleanUpMessages, new FileInfo(filePath).Directory);
        }
        /// <summary>
        /// 	The implementation of IXDBroadcast, used to broadcast a new message to other processes. This creates a unique
        /// 	file on the filesystem. The temporary files are cleaned up after a pre-defined timeout.
        /// </summary>
        /// <param name = "channelName"></param>
        /// <param name = "dataType"></param>
        /// <param name = "message"></param>
        private void SendToChannel(string channelName, string dataType, string message)
        {
            Validate.That(channelName).IsNotNullOrEmpty();
            Validate.That(dataType).IsNotNullOrEmpty();
            Validate.That(message).IsNotNullOrEmpty();

            // create temporary name
            string fileName = Guid.NewGuid().ToString();
            string folder = GetChannelDirectory(channelName);
            string filePath = Path.Combine(folder, string.Concat(fileName, ".msg"));
            // write the message to the temp file, which will trigger listeners in other processes
            using (var writer = File.CreateText(filePath))
            {
                // write out the channel name and message, this allows for invalid
                // characters in the channel name.
                var dataGram = new DataGram(channelName, dataType, message);
                writer.Write(serializer.Serialize(dataGram));
                writer.Flush();
            }
            // return as fast as we can, leaving a clean up task
            ThreadPool.QueueUserWorkItem(CleanUpMessages, new FileInfo(filePath).Directory);
        }
        private void SendToChannel(string channel, string dataType, string message)
        {
            Validate.That(channel).IsNotNull();
            Validate.That(dataType).IsNotNull();
            Validate.That(message).IsNotNullOrEmpty();

            var topic = topicRepository.GetTopic(channel);
            var dataGram = new DataGram(channel, dataType, message);
            var data = serializer.Serialize(dataGram);

            publisherService.Publish(topic, dataGram.Channel, data);
        }