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(); } }
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()); } }
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; }
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); }
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); } }