public bool addUser(User user) { foreach(User u in this.availableUsers) { if(u.getName().CompareTo(user.getName()) == 0) { return false; } } availableUsers.Add(user); return true; }
private async void refreshUsers() { HavissIoTCommandBuilder commandBuilder =new HavissIoTCommandBuilder(); commandBuilder.getUsers(); if (Config.username.Length > 0) { if (Config.password.Length > 0) { commandBuilder.addUser(Config.username, Config.password); } else { commandBuilder.addUser(Config.username); } } string response = await SharedVariables.client.request(commandBuilder.getJsonString()); JObject jsonObject = null; JArray jsonArray = null; try { jsonObject = JObject.Parse(response); jsonArray = (JArray)jsonObject.GetValue("r"); } catch (Exception ex) { MessageDialog message = new MessageDialog(ex.Message, "Request parse error"); return; } List<string> usernames = new List<string>(); SharedVariables.userHandler.clearUsers(); foreach (JObject j in jsonArray) { try { string username = (string)j.GetValue("name"); bool OP = (bool)j.GetValue("isOP"); bool isProtected = (bool)j.GetValue("isProtected"); bool isPasswordProtected = (bool)j.GetValue("isPasswordProtected"); User user = new User(username, OP, isProtected, isPasswordProtected); SharedVariables.userHandler.addUser(user); usernames.Add(username); } catch (Exception ex) { MessageDialog message = new MessageDialog(ex.Message, "Request parse error"); return; } } available_users.ItemsSource = usernames; }