Esempio n. 1
0
        private static void HandleUserInput(CollaborationClient client)
        {
            ConsoleKeyInfo input;

            WriteInstructions();

            while ((input = Console.ReadKey()).Key != ConsoleKey.Enter)
            {
                Console.WriteLine();
                switch (input.Key)
                {
                case ConsoleKey.R:
                    //Let's generate some random filename
                    //TODO: this needs to be modified with appropriate logic
                    var filename = Guid.NewGuid().ToString().Split('-').Last() + ".ext";
                    try
                    {
                        var collaboration = client.BroadcastCollaborationRequestForFile(filename);
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine($"Collaboration request broadcast successfully for file {collaboration.Filename}, starting work now...");
                        Console.ResetColor();
                        workCancellationTokenSource = new CancellationTokenSource();
                        PerformWorkOnFile(collaboration.Filename, workCancellationTokenSource.Token);
                    } catch (Exception exc)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(exc.Message);
                        Console.ResetColor();
                    }
                    break;

                case ConsoleKey.S:
                    workCancellationTokenSource?.Cancel();
                    client.StopCollaboration();
                    Console.WriteLine("Work stopped");
                    WriteInstructions();
                    break;
                }
            }
            listeningCancellationTokenSource.Cancel();
        }