Пример #1
0
        public static async void Initialize(Window window)
        {
            var mouseManager = new MouseManager(window);

            Console.WriteLine("Current mouse id: " + mouseManager.CurrentMouseId);

            var ftpServer = new FtpServer("clipboard", Servers);

            var socketServer = new SocketServer();

            socketServer.Message += async(sender, args) =>
            {
                switch (args.Message.Action)
                {
                case Action.Connect:
                    await AddServer(args.Message.Text);

                    var mouseId = mouseManager.CurrentMouseId;
                    FtpServer.FixName(ref mouseId);
                    ftpServer.SyncMouse(mouseId);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            };

            var clipboardManager = new ClipboardManager();

            clipboardManager.Copy += async(sender, eventArgs) =>
            {
                Console.WriteLine("ONCOPY");
                await ftpServer.SetClipboard(mouseManager.CurrentMouseId, clipboardManager);
            };

            clipboardManager.Ready += async(sender, args) =>
            {
                await ftpServer.SetClipboard(mouseManager.CurrentMouseId, clipboardManager);
            };

            mouseManager.MouseChange += (sender, args) =>
            {
                if (args.ChangeType != MouseChangeType.Removed)
                {
                    return;
                }

                Console.WriteLine("Mouse removed, syncing mouse files to everyone: " + args.MouseId);
                // Nieuwe muis connected, override clipboard
                clipboardManager.SetClipboardFromMetadata(ftpServer, args.MouseId);
            };

            await UpdateServers();

            foreach (var server in Servers)
            {
                Console.WriteLine(server);
            }

            Console.WriteLine("DONE");
        }