예제 #1
0
        protected override void OnInitialized()
        {
            Whiteboard.OnStroke(async stroke =>
            {
                await _context.StrokeAsync(stroke);
                await _context.FlushAsync();
            });

            Whiteboard.OnWipe(async wipe =>
            {
                await _context.WipeAsync(wipe);
                await _context.FlushAsync();
            });

            Whiteboard.OnFill(async fill =>
            {
                await _context.FillAsync(fill);
                await _context.FlushAsync();
            });

            Whiteboard.OnClear(async clear =>
            {
                await _context.ClearAsync(clear);
                await _context.FlushAsync();
            });

            Whiteboard.OnUndo(async undo =>
            {
                System.Console.WriteLine("Undo");
                await _context.ClearAsync(Clear.All);
                foreach (var action in Whiteboard.Actions)
                {
                    if (action is Stroke stroke)
                    {
                        await _context.StrokeAsync(stroke);
                    }
                    else if (action is Wipe wipe)
                    {
                        await _context.WipeAsync(wipe);
                    }
                    else if (action is Fill fill)
                    {
                        await _context.FillAsync(fill);
                    }
                    else if (action is Clear clear)
                    {
                        await _context.ClearAsync(clear);
                    }
                }

                await _context.FlushAsync();
            });
        }