コード例 #1
0
        private void receiveStrokeAndAddToCanvas()
        {
            SignedStroke stroke = StrokeBitConverter.GetSignedStroke(remoteStream);

            lanCanvas.ManualHandler.AddSignedStroke(stroke);
            StrokeReceived(stroke);
        }
コード例 #2
0
ファイル: PainterSender.cs プロジェクト: Cendrb/LANPaint
 public void SendStroke(SignedStroke stroke)
 {
     lock (stream)
     {
         sendBeginByte();
         stream.WriteByte(Commands.CS_SEND_STROKE);
         StrokeBitConverter.Serialize(stream, stroke);
     }
 }
コード例 #3
0
ファイル: PainterSender.cs プロジェクト: Cendrb/LANPaint
 public void SendPointerStroke(SignedPointerStroke pointer)
 {
     lock (stream)
     {
         sendBeginByte();
         stream.WriteByte(Commands.CS_SEND_POINTER);
         StrokeBitConverter.Serialize(stream, pointer);
     }
 }
コード例 #4
0
        /// <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;
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Converts all the data from canvas to the given stream
        /// </summary>
        /// <param name="target">Target stream for the serialized data</param>
        public void Serialize(Stream target)
        {
            target.Write(BitConverter.GetBytes(generator.ActiveId), 0, sizeof(UInt32));
            target.Write(BitConverter.GetBytes(Width), 0, sizeof(double));
            target.Write(BitConverter.GetBytes(Height), 0, sizeof(double));
            IEnumerator <Stroke> enumerator = canvas.Dispatcher.Invoke(new Func <IEnumerator <Stroke> >(() => canvas.Strokes.GetEnumerator()));

            while (enumerator.MoveNext())
            {
                if (enumerator.Current is SignedPointerStroke)
                {
                    target.WriteByte(StrokeBitConverter.SIGNED_POINTER_STROKE_SIGNAL);
                    StrokeBitConverter.Serialize(target, (SignedPointerStroke)enumerator.Current);
                }
                else
                {
                    target.WriteByte(StrokeBitConverter.SIGNED_STROKE_SIGNAL);
                    StrokeBitConverter.Serialize(target, (SignedStroke)enumerator.Current);
                }
            }
            target.WriteByte(StrokeBitConverter.STROKES_END);
        }