コード例 #1
0
 private void SetupCurrentUserElementGroup()
 {
     currentUser = localDb.GetCurrentUser();
     if (currentUser != null)
     {
         CurrentUserInfoText1.Text       = $"{currentUser.Name} - {currentUser.UserId}";
         CurrentNetworkInfoText1.Text    = "Join to existing network or create new one";
         UserNameEditText.Visibility     = ViewStates.Invisible;
         CreateNewUserButton.Visibility  = ViewStates.Invisible;
         DeleteProfileButton.Visibility  = ViewStates.Visible;
         NetworkNameEditText.Enabled     = true;
         NetworkPasswordEditText.Enabled = true;
     }
     else
     {
         CurrentUserInfoText1.Text       = "User was not found. Please create a new one.";
         CurrentNetworkInfoText1.Text    = "Create new user before cteating or join to the network";
         UserNameEditText.Visibility     = ViewStates.Visible;
         CreateNewUserButton.Visibility  = ViewStates.Visible;
         DeleteProfileButton.Visibility  = ViewStates.Invisible;
         NetworkNameEditText.Enabled     = false;
         NetworkPasswordEditText.Enabled = false;
     }
     DeleteProfileButton.Visibility = ViewStates.Visible;
 }
コード例 #2
0
 public void RegisterNewNetwork(string name, string pass)
 {
     try
     {
         localDb = new SQLiteDataService();
         using (var client = new HttpClient())
         {
             var     currentUser = localDb.GetCurrentUser();
             Network net         = new Network()
             {
                 Name = name, Password = pass, CreatorUserId = currentUser.UserId
             };
             var     response = client.PostAsJsonAsync <Network>(APP_PATH + "/api/network/CreateNewNetwork", net);
             Network deserializedNetwork;
             if (response.Result.StatusCode == HttpStatusCode.Created)
             {
                 deserializedNetwork = JsonConvert.DeserializeObject <Network>(response.Result.Content.ReadAsStringAsync().Result);
                 SQLiteDataService localBD = new SQLiteDataService();
                 localBD.AddCurrentNetwork(deserializedNetwork);
                 currentUser.NetworkId = deserializedNetwork.NetworkId;
             }
             else
             {
                 System.Diagnostics.Debug.WriteLine($"Got wrong response StatusCode while creating new network: {response.Result.StatusCode}");
                 Log.Error($"Got wrong response StatusCode while creating new network: {response.Result.StatusCode}");
             }
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine($"Couldn't create new network: {e}");
         Log.Error(e, "Couldn't create new network");
     }
 }
コード例 #3
0
        public void DeleteProfile()
        {
            SQLiteDataService localBD = new SQLiteDataService();
            //localBD.DeleteAllCurrentUsers();
            CurrentUser curUS = localBD.GetCurrentUser();

            using (var client = new HttpClient())
            {
                try
                {
                    var response = client.DeleteAsync($"{APP_PATH}/api/user/DeleteUser?id={curUS.UserId}");
                    if (response.Result.StatusCode == HttpStatusCode.OK)
                    {
                        localBD.DeleteAllCurrentUsers();
                        localBD.DeleteAllCurrentNetworks();
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine($"Got wrong response StatusCode while creating new network: {response.Result.StatusCode}");
                        Log.Error($"Got wrong response StatusCode while deleting current user: {response.Result.StatusCode}");
                    }
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine($"Couldn't delete user: {e}");
                    Log.Error(e, "Couldn't delete user");
                }
            }
        }
コード例 #4
0
 public bool JoinToNetwork(string name, string pass)
 {
     try
     {
         localDb = new SQLiteDataService();
         using (var client = new HttpClient())
         {
             var     currentUser = localDb.GetCurrentUser();
             var     tt          = $"{APP_PATH}/api/network/GetNetwork?name={name}&pass={pass}";
             var     response    = client.GetAsync($"{APP_PATH}/api/network/GetNetwork?name={name}&pass={pass}");
             Network deserializedNetwork;
             if (response.Result.StatusCode == HttpStatusCode.Found)
             {
                 deserializedNetwork = JsonConvert.DeserializeObject <Network>(response.Result.Content.ReadAsStringAsync().Result);
                 SQLiteDataService localBD = new SQLiteDataService();
                 localBD.AddCurrentNetwork(deserializedNetwork);
                 currentUser.NetworkId = deserializedNetwork.NetworkId;
                 return(true);
             }
             else if (response.Result.StatusCode == HttpStatusCode.NotFound)
             {
                 return(false);
             }
             else
             {
                 System.Diagnostics.Debug.WriteLine($"Got wrong response StatusCode while creating new network: {response.Result.StatusCode}");
                 Log.Error($"Got wrong response StatusCode while creating new network: {response.Result.StatusCode}");
                 return(false);
             }
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine($"Couldn't get a network: {e}");
         Log.Error(e, "Couldn't get a network");
         return(false);
     }
 }