예제 #1
0
        private async Task <string> LoginServer(List <KeyValuePair <string, string> > values)
        {
            if (ExtraModules.IsInternet())
            {
                var httpClient = new HttpClient();
                var response   = await httpClient.PostAsync(ExtraModules.domain_address + "/login.php", new FormUrlEncodedContent(values));

                var responseString = await response.Content.ReadAsStringAsync();

                Debug.WriteLine("MainPage" + responseString);
                JsonObject root  = Windows.Data.Json.JsonValue.Parse(responseString).GetObject();
                string     error = root.GetNamedString("error");
                if (error.Equals("Success"))
                {
                    string username     = root.GetNamedString("Username");
                    string userid       = root.GetNamedString("UserId").ToString();
                    string auth_token   = root.GetNamedString("Auth_Token");
                    string organisation = root.GetNamedString("Organisation");
                    string login_time   = DateTime.Now.ToUniversalTime().ToString("yyyyMMddHHmmssfff");

                    this.database = App.database;

                    await Insert_UserDetails_In_Database(userid, username, organisation, login_time, auth_token);

                    return("success");
                }
                else
                {
                    return(error);
                }
            }
            return("Check internet Connection");
        }
예제 #2
0
        private async Task <bool> checkLogin()
        {
            if (ExtraModules.IsInternet())
            {
                var data = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("username", MainPageUsername.Text.ToString()),
                    new KeyValuePair <string, string>("password", MainPagePassword.Password.ToString())
                };
                string output = await LoginServer(data);

                if (output.Equals("success"))
                {
                    return(true);
                }
                else
                {
                    var messageDialog = new MessageDialog(output, "Error");
                    messageDialog.Commands.Add(new Windows.UI.Popups.UICommand("OK", null));
                    var dialogResult = await messageDialog.ShowAsync();
                }
            }
            return(false);  //this shud be uncommented for running with server
            //return true;
        }
예제 #3
0
        private async Task Uploadtoserver(List <KeyValuePair <string, string> > values)
        {
            if (ExtraModules.IsInternet())
            {
                var httpClient = new HttpClient();
                var response   = await httpClient.PostAsync(ExtraModules.domain_address + "/UpdateServerdata.php", new FormUrlEncodedContent(values));

                var responseString = await response.Content.ReadAsStringAsync();

                try
                {
                    Debug.WriteLine("Sync Output" + responseString);
                    // JsonObject root = Windows.Data.Json.JsonValue.Parse(responseString).GetObject();
                    // string error = root.GetNamedString("error");
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Exception in Sync");
                    Debug.WriteLine(ex.Message.ToString());
                }
            }
            else
            {
                Debug.WriteLine("Check internet Connection");
            }
        }
예제 #4
0
        private async Task <string> SignupServer(List <KeyValuePair <string, string> > values)
        {
            if (ExtraModules.IsInternet())
            {
                var httpClient = new HttpClient();
                var response   = await httpClient.PostAsync(ExtraModules.domain_address + "/signup.php", new FormUrlEncodedContent(values));

                var responseString = await response.Content.ReadAsStringAsync();

                Debug.WriteLine("Signup Output" + responseString);
                JsonObject root  = Windows.Data.Json.JsonValue.Parse(responseString).GetObject();
                string     error = root.GetNamedString("error");
                return(error);
            }
            return("Check internet Connection");
        }
예제 #5
0
        //sync functions
        private async void SettingsSynClicked(object sender, RoutedEventArgs e)
        {
            SettingsWaitTextBlock.Text       = "Syncing";
            SettingsWaitTextBlock.Visibility = Windows.UI.Xaml.Visibility.Visible;
            SettingsSyncButton.Visibility    = Windows.UI.Xaml.Visibility.Collapsed;
            settingsProgress.Visibility      = Windows.UI.Xaml.Visibility.Visible;
            if (ExtraModules.IsInternet())
            {
                string timestamp = await getTimeStamp();//"1/25/2014 3:34:06 AM";

                string userid = await getUserId();

                string auth_token = await getAuthToken();

                string statements = await sendToServer(timestamp, userid);

                var data = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("userid", userid),
                    new KeyValuePair <string, string>("auth_token", auth_token),
                    new KeyValuePair <string, string>("updatestatements", statements)
                };
                var datatorecieve = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("userid", userid),
                    new KeyValuePair <string, string>("auth_token", auth_token),
                    new KeyValuePair <string, string>("timestamp", timestamp)
                };

                await Uploadtoserver(data);
                await getfromserver(datatorecieve);

                SettingsWaitTextBlock.Text = "Done";
            }
            else
            {
                SettingsWaitTextBlock.Text = "Failed";
            }
            SettingsSyncButton.IsEnabled  = true;
            settingsProgress.Visibility   = Windows.UI.Xaml.Visibility.Collapsed;
            SettingsSyncButton.Visibility = Windows.UI.Xaml.Visibility.Visible;

            // SettingsWaitTextBlock.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
        }
예제 #6
0
        private async Task SignUpNewUser()
        {
            if (ExtraModules.IsInternet())
            {
                var data = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("username", MainPageSignUpUsername.Text),
                    new KeyValuePair <string, string>("password", MainPageSignUpPassword.Password.ToString()),
                    new KeyValuePair <string, string>("organisation", MainPageSignUpNGOName.Text),
                    new KeyValuePair <string, string>("email", MainPageSignUpEmail.Text)
                };
                string output = await SignupServer(data);

                var messageDialog = new MessageDialog(output, "");
                messageDialog.Commands.Add(new Windows.UI.Popups.UICommand("OK", null));
                var dialogResult = await messageDialog.ShowAsync();
            }
            return;
        }
예제 #7
0
        private async Task <string> getfromserver(List <KeyValuePair <string, string> > values)
        {
            if (ExtraModules.IsInternet())
            {
                var httpClient = new HttpClient();
                var response   = await httpClient.PostAsync(ExtraModules.domain_address + "/updatetomachine.php", new FormUrlEncodedContent(values));

                var responseString = await response.Content.ReadAsStringAsync();

                //Debug.WriteLine("Sync Output" + responseString);
                string error = responseString.ToString();
                //JsonObject root = Windows.Data.Json.JsonValue.Parse(responseString).GetObject();
                //string error = root.GetNamedString("query");
                await aftergetFromServer(error);

                string userid = await getUserId();

                updateTimeStamp(userid);
                return("done");
            }
            return("Check internet Connection");
        }