Exemplo n.º 1
0
        private async Task LoadPage()
        {
            ConsoleHelper.WriteLine("Loading...\n", ConsoleColor.Yellow);

            var response = await _protocolCommunication.SendRequestAsync(new PhotoListRequest(_username));

            switch (response)
            {
            case ErrorResponse errorResponse:
                ConsoleHelper.WriteLine($"Error {errorResponse.ErrorId}: {errorResponse.Message}");
                ConsoleHelper.ReadKey();     // Pause
                _navigation.Back();
                break;

            case PhotoListResponse photoListResponse:
                var cacheLocation = $"cache/{_username}";
                if (Directory.Exists(cacheLocation))
                {
                    Directory.Delete(cacheLocation, true);
                }
                Directory.CreateDirectory(cacheLocation);

                // Move photos to cache
                var photoList = new List <(string, string)>();
                foreach (var photo in photoListResponse.Photos)
                {
                    var photoPath = $"{cacheLocation}/{photo.Name}";
                    File.Move(photo.File, photoPath);

                    photoList.Add((photo.Name, $"{photo.Name} - {photoPath}"));
                }

                _photoListMenu = new Menu(
                    options: photoList,
                    onSelect: photoName =>
                {
                    _navigation.GoToPage(
                        IPageNavigation.PhotoDetailsPage,
                        new Dictionary <string, string>
                    {
                        { "username", _username },
                        { "photoName", photoName },
                    }
                        );
                },
                    onEscPressed: () => _navigation.Back(),
                    escapeActionName: "Go back"
                    );
                break;

            default:
                ConsoleHelper.WriteLine($"Error: Unrecognized command {response.Id}");
                ConsoleHelper.ReadKey();     // Pause
                _navigation.Back();
                break;
            }
        }
Exemplo n.º 2
0
        private async Task LoadPage()
        {
            ConsoleHelper.WriteLine("Loading...\n", ConsoleColor.Yellow);

            var response = await _protocolCommunication.SendRequestAsync(new UserListRequest());

            switch (response)
            {
            case ErrorResponse errorResponse:
                ConsoleHelper.WriteLine($"Error {errorResponse.ErrorId}: {errorResponse.Message}");
                ConsoleHelper.ReadKey();     // Pause
                _navigation.Back();
                break;

            case UserListResponse userListResponse:
                // Move users to cache
                var userList = new List <(string, string)>();
                foreach (var user in userListResponse.Users)
                {
                    userList.Add((user.Username, user.Username));
                }

                _userListMenu = new Menu(
                    options: userList,
                    onSelect: username =>
                {
                    _navigation.GoToPage(
                        IPageNavigation.PhotoListPage,
                        new Dictionary <string, string> {
                        { "username", username }
                    }
                        );
                },
                    onEscPressed: () => _navigation.Back(),
                    escapeActionName: "Go back"
                    );
                break;

            default:
                ConsoleHelper.WriteLine($"Error: Unrecognized command {response.Id}");
                ConsoleHelper.ReadKey();     // Pause
                _navigation.Back();
                break;
            }
        }
Exemplo n.º 3
0
        private async Task LoadPage()
        {
            ConsoleHelper.WriteLine("Loading...\n", ConsoleColor.Yellow);

            var response = await _protocolCommunication.SendRequestAsync(
                new CommentListRequest(_username, _photoName)
                );

            switch (response)
            {
            case ErrorResponse errorResponse:
                ConsoleHelper.WriteLine($"Error {errorResponse.ErrorId}: {errorResponse.Message}");
                ConsoleHelper.ReadKey();     // Pause
                _navigation.Back();
                break;

            case CommentListResponse commentListResponse:
                // Move comments to cache
                var commentList = new List <(string, string)>();
                foreach (var comment in commentListResponse.Comments)
                {
                    commentList.Add(($"{comment.Username},{comment.PhotoName}", $"{comment.Text}"));
                }

                _commentListMenu = new Menu(
                    options: commentList,
                    onSelect: s => { },
                    onEscPressed: () => _navigation.Back(),
                    escapeActionName: "Go back"
                    );
                break;

            default:
                ConsoleHelper.WriteLine($"Error: Unrecognized command {response.Id}");
                ConsoleHelper.ReadKey();     // Pause
                _navigation.Back();
                break;
            }
        }