public static Client Authorize(string username, string password) { socket.Connect(new IPEndPoint(IPAddress.Parse(Host), Port)); SocketHandler TempSocketHandler = new SocketHandler(socket); Dictionary <string, string> RequestData = new Dictionary <string, string> { ["username"] = username, ["password"] = password }; Response response = TempSocketHandler.Request(new Request(type: RequestType.Authorize, data: RequestData)); if (response.Status == ResponseStatus.Error) { throw Error.Make(response.Data); } return(new Client(socketHandler: TempSocketHandler)); }
public Client(SocketHandler socketHandler) { SocketHandler = socketHandler; }
private static async Task Main(string[] args) { if (ConnectToServer(out var clientSocket)) { return; } _socketHandler = new SocketHandler(clientSocket); while (true) { PrintMenu(); int selectedOption; var optionWasValid = int.TryParse(Console.ReadLine(), out selectedOption); if (optionWasValid) { switch (selectedOption) { case 1: await HandleNewTopicAsync(); break; case 2: await HandleRemoveTopicAsync(); break; case 3: await HandleModifyTopicAsync(); break; case 4: await HandleNewPostAsync(); break; case 5: await HandleRemovePostAsync(); break; case 6: await HandleModifyPostAsync(); break; case 7: await HandleAssociatePostWithTopicAsync(); break; case 8: await HandleRemovePostAndTopicAssociationAsync(); break; case 9: await HandlePostFileUploadAsync(); break; case 11: await HandleListPostsByTopicAsync(); break; case 99: await HandleExitAsync(); return; } } } }