/// <summary> /// Constructor to detect type of json request /// </summary> /// <param name="input">Input json</param> public JsonManager(string input, TcpClient client) { try { this._client = client; this._user = new User(); this._user.ParseUser(input); } catch (Exception) { throw; } }
/// <summary> /// Initialize /// </summary> /// <param name="client"></param> private void Initialize(TcpClient client) { // Initialize classes this._user = new User(); this._logger = new ResponseLogger("ResponseLogger"); // Initialize varianles this._request = string.Empty; this._buffer = new byte[2048]; //1024 }
public string Post(User user) { return user.Email + " " + user.Password; }
public User ParseUser(string input) { string[] lines = input.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); string js = lines[13].Trim(); dynamic json = (JArray)JsonConvert.DeserializeObject(js); // 5 items in array // Value // Name // [{"name":"name","value":"Pasha"}, // {"name":"age","value":"19"}, // {"name":"email","value":"*****@*****.**"}, // {"name":"phone","value":"+380123122132"}, // {"name":"password","value":"123456"}] // Parse json from registration form try { this._user = new User() { Name = json[0]["value"], Age = json[1]["value"], Email = json[2]["value"], Phone = json[3]["value"], Password = json[4]["value"], MyToken = new Token() }; _usersInSystem.Add(this._user); CurrentUser = this._user; this.TypeRequest = TypeJsonRequest.Registration; } catch (ArgumentOutOfRangeException) { // Parse json from log in form this._user = new User() { Email = json[0]["value"], Password = json[1]["value"], MyToken = new Token() }; CurrentUser = this.FindUserByEmail(this._user.Email); this.TypeRequest = TypeJsonRequest.LogIn; } return this._user; }