private void receiveStrokeAndAddToCanvas() { SignedStroke stroke = StrokeBitConverter.GetSignedStroke(remoteStream); lanCanvas.ManualHandler.AddSignedStroke(stroke); StrokeReceived(stroke); }
/// <summary> /// Wipes all the previous data and loads them from the given stream /// </summary> /// <param name="source">The data source</param> public void Deserialize(Stream source) { byte[] idBytes = new byte[sizeof(UInt32)]; source.Read(idBytes, 0, idBytes.Length); generator.ActiveId = BitConverter.ToUInt32(idBytes, 0); byte[] widthBytes = new byte[sizeof(double)]; source.Read(widthBytes, 0, widthBytes.Length); Width = BitConverter.ToDouble(widthBytes, 0); byte[] heightBytes = new byte[sizeof(double)]; source.Read(heightBytes, 0, heightBytes.Length); Height = BitConverter.ToDouble(heightBytes, 0); canvas.Dispatcher.Invoke(new Action(() => canvas.Strokes.Clear())); StrokeCollection strokes = canvas.Dispatcher.Invoke <StrokeCollection>(new Func <StrokeCollection>(() => canvas.Strokes)); bool end = false; byte[] command = new byte[1]; while (!end) { source.Read(command, 0, command.Length); switch (command[0]) { case StrokeBitConverter.SIGNED_POINTER_STROKE_SIGNAL: canvas.Dispatcher.Invoke(new Action(() => strokes.Add(StrokeBitConverter.GetSignedPointerStroke(source)))); break; case StrokeBitConverter.SIGNED_STROKE_SIGNAL: canvas.Dispatcher.Invoke(new Action(() => strokes.Add(StrokeBitConverter.GetSignedStroke(source)))); break; case StrokeBitConverter.STROKES_END: end = true; break; default: Console.WriteLine("Unknown data command received"); end = true; break; } } }