public byte[] Serialize(PayloadDto dto)
 {
     // tutaj wrzucamy kod serializacji
     using (var stream = new MemoryStream())
     {
         var serializer = new BinaryFormatter();
         serializer.Serialize(stream, dto);
         return stream.GetBuffer();
     }
 }
示例#2
0
 public byte[] Serialize(PayloadDto dto)
 {
     // tutaj wrzucamy kod serializacji
     using (var stream = new MemoryStream())
     {
         var serializer = new BinaryFormatter();
         serializer.Serialize(stream, dto);
         return(stream.GetBuffer());
     }
 }
示例#3
0
 public static PayloadDto Create()
 {
     var dto = new PayloadDto();
     Random r = new Random();
     dto.Number = r.Next() % 1000;
     dto.Text = "str" + (r.Next()% 100).ToString();
     dto.TimeStamp = DateTime.Now;
     dto.List = Enumerable.Range(0, 3).Select(o => r.Next() % 100).ToArray();
     dto.Dict = Enumerable.Range('a', 3).ToDictionary(o => (int)o, o => ((char)o).ToString());
     dto.Span = TimeSpan.FromMilliseconds(r.NextDouble() * 1000);
     return dto;
 }
示例#4
0
        public static PayloadDto Create()
        {
            var    dto = new PayloadDto();
            Random r   = new Random();

            dto.Number    = r.Next() % 1000;
            dto.Text      = "str" + (r.Next() % 100).ToString();
            dto.TimeStamp = DateTime.Now;
            dto.List      = Enumerable.Range(0, 3).Select(o => r.Next() % 100).ToArray();
            dto.Dict      = Enumerable.Range('a', 3).ToDictionary(o => (int)o, o => ((char)o).ToString());
            dto.Span      = TimeSpan.FromMilliseconds(r.NextDouble() * 1000);
            return(dto);
        }
示例#5
0
        private void ProducerLoop()
        {
            while (true)
            {
                var dto = PayloadDto.Create();
                lock (_lock)
                {
                    var serialized = _serializer.Serialize(dto);

                    Console.WriteLine("Original data:");
                    Console.WriteLine("{0}", dto);

                    _queue.Enqueue(serialized);
                    Monitor.Pulse(_lock);
                }
                Thread.Sleep(5000);
            }
        }