static async Task Main(string[] args)
        {
            IConfiguration configuration = AppSettingsFactory.GetAppSettings();

            ConsoleHelper.WriteLine("Starting client...", ConsoleColor.Yellow);
            var       clientIpEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 0);
            var       serverIpEndPoint = new IPEndPoint(IPAddress.Parse(configuration["ServerIpAddress"]), ProtocolSpecification.Port);
            TcpClient client           = new TcpClient(clientIpEndPoint);

            ConsoleHelper.WriteLine("Attempting connection to server...", ConsoleColor.Yellow);
            client.Connect(serverIpEndPoint);
            NetworkStream stream = client.GetStream();
            var           protocolCommunication = new ProtocolCommunication(stream);

            IPageNavigation navigation = new PageNavigation(protocolCommunication);

            navigation.GoToPage(IPageNavigation.LandingPage);

            while (navigation.Top() != null)
            {
                ConsoleHelper.Clear();
                await navigation.Top().RenderAsync();
            }

            await protocolCommunication.SendRequestAsync(new LogoutRequest());
        }
示例#2
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;
            }
        }
示例#3
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;
            }
        }
示例#4
0
 public void GoToPage()
 {
     _pageNavigation.GoToPage(PagePrefab.name);
 }
示例#5
0
 public void GoToPage <T>(T pagePrefab) where T : MonoBehaviour
 {
     _pageNavigation.GoToPage(pagePrefab.name);
 }