public void SendStrokeInChunks(Guid strokeId, List <InkPoint> points, InkDrawingAttributes drawingAttributes, Action <byte[]> sendAction)
        {
            var isFirstChunk   = true;
            var chunksOfPoints = ChunksOfPoints(points, ChunkSize).ToList();

            for (short i = 0; i < chunksOfPoints.Count; i++)
            {
                var          chunk = chunksOfPoints[i];
                StrokePoints strokePoints;
                if (isFirstChunk)
                {
                    strokePoints = new StrokeDescription
                    {
                        IsPencil          = drawingAttributes.Kind == InkDrawingAttributesKind.Pencil,
                        DrawAsHighlighter = drawingAttributes.DrawAsHighlighter,
                        ColorValues       = new[] { drawingAttributes.Color.A, drawingAttributes.Color.R, drawingAttributes.Color.G, drawingAttributes.Color.B },
                        FitToCurve        = drawingAttributes.FitToCurve,
                        IgnorePressure    = drawingAttributes.IgnorePressure,
                        SizeValues        = new[] { drawingAttributes.Size.Width, drawingAttributes.Size.Height },
                        Opacity           = drawingAttributes.PencilProperties?.Opacity ?? 1.0
                    };
                    isFirstChunk = false;
                }
                else
                {
                    strokePoints = new StrokePoints();
                }
                strokePoints.Id               = strokeId;
                strokePoints.Order            = i;
                strokePoints.NumberOfPackages = (short)chunksOfPoints.Count;

                strokePoints.PointXValues   = chunk.Select(p => p.Position.X).ToArray();
                strokePoints.PointYValues   = chunk.Select(p => p.Position.Y).ToArray();
                strokePoints.PressureValues = chunk.Select(p => p.Pressure).ToArray();

                byte[] protobuf;
                using (var stream = new MemoryStream())
                {
                    Serializer.Serialize(stream, strokePoints);
                    protobuf = stream.ToArray();
                }

                var compressedProtobuf = protobuf.Compress();

                sendAction(compressedProtobuf);
            }
        }
        private async void StrokeChangeBrokerOnStrokeCollected(object sender, StrokeDescription strokeDescription)
        {
            if (idToStrokeMapping.ContainsKey(strokeDescription.Id))
            {
                return;
            }

            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                          () =>
            {
                lock (canvasChangeLock)
                {
                    InkDrawingAttributes inkDrawingAttributes;
                    if (strokeDescription.IsPencil)
                    {
                        inkDrawingAttributes = InkDrawingAttributes.CreateForPencil();
                        inkDrawingAttributes.PencilProperties.Opacity = strokeDescription.Opacity;
                    }
                    else
                    {
                        inkDrawingAttributes = new InkDrawingAttributes();
                        inkDrawingAttributes.DrawAsHighlighter = strokeDescription.DrawAsHighlighter;
                    }

                    inkDrawingAttributes.Color          = Color.FromArgb(strokeDescription.ColorValues[0], strokeDescription.ColorValues[1], strokeDescription.ColorValues[2], strokeDescription.ColorValues[3]);
                    inkDrawingAttributes.FitToCurve     = strokeDescription.FitToCurve;
                    inkDrawingAttributes.IgnorePressure = strokeDescription.IgnorePressure;
                    inkDrawingAttributes.Size           = new Size(strokeDescription.SizeValues[0], strokeDescription.SizeValues[1]);

                    strokeBuilder.SetDefaultDrawingAttributes(inkDrawingAttributes);

                    var points = new List <InkPoint>(strokeDescription.PointXValues.Length);
                    for (var i = 0; i < strokeDescription.PointXValues.Length; i++)
                    {
                        points.Add(new InkPoint(new Point(strokeDescription.PointXValues[i], strokeDescription.PointYValues[i]), strokeDescription.PressureValues[i]));
                    }

                    var newStroke = strokeBuilder.CreateStrokeFromInkPoints(points, Matrix3x2.Identity);
                    idToStrokeMapping[strokeDescription.Id] = newStroke;

                    canvas.InkPresenter.StrokeContainer.AddStroke(newStroke);
                }
            });
        }