public static void Initialize(Context context)
 {
     if (mInstance == null)
     {
         mInstance = new AzureServiceAdapter(context);
     }
 }
Exemple #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_login);

            // This MobileServiceClient has been configured to communicate with the Azure Mobile App and
            // Azure Gateway using the application url. You're all set to start working with your Mobile App!
            //Microsoft.WindowsAzure.MobileServices.MobileServiceClient eHealthHeartRateClient = new Microsoft.WindowsAzure.MobileServices.MobileServiceClient("https://ehealthheartrate.azurewebsites.net");

            // Set our view from the "main" layout resource


            EditText etPassword = (EditText)FindViewById(Id.Password);
            EditText etUsername = (EditText)FindViewById(Id.Username);

            // TO DO: check how I can do this about Spinners

            Button blogin  = (Button)FindViewById(Id.Blogin);
            Button bsignup = (Button)FindViewById(Id.BSignUp);

            if (mClient == null)
            {
                AzureServiceAdapter.Initialize(this);
                mClient = AzureServiceAdapter.getInstance().getClient();
            }

            //IMobileServiceTable<Users> mTable = mClient.GetTable("Users", Users.class);  <-- as it was in java
            IMobileServiceTable <Users> mTable = mClient.GetTable <Users>();

            Toast.MakeText(this, "Welcome", ToastLength.Long).Show();


            // actions per button
            blogin.Click += async(sender, e) =>
            {
                Toast.MakeText(this, "login attempt as " + etUsername.Text.ToString(), ToastLength.Long).Show();
                try
                {
                    Users signinItem = await mTable.LookupAsync(UUID.NameUUIDFromBytes(Encoding.ASCII.GetBytes(etUsername.Text.ToString())).ToString());

                    System.Diagnostics.Debug.WriteLine("#########################################");
                    System.Diagnostics.Debug.WriteLine(signinItem);
                    System.Diagnostics.Debug.WriteLine("#########################################");
                    //Users item = ( Users )test_item;
                    //Debug.
                    if (signinItem != null)
                    {
                        if (signinItem.getpassword().Equals(etPassword.Text.ToString()))
                        {
                            current_username = signinItem.getusername();

                            Toast.MakeText(this, "Login Successfull", ToastLength.Long).Show();

                            Bundle itemBundle = new Bundle();
                            itemBundle.PutString("username", signinItem.getusername());
                            itemBundle.PutInt("age", Convert.ToInt32(signinItem.getdob()));
                            itemBundle.PutInt("height", signinItem.getheight());
                            itemBundle.PutInt("weight", signinItem.getweight());

                            var activity2 = new Intent(this, typeof(user_page));
                            activity2.PutExtra("currentUserBundle", itemBundle);
                            StartActivity(activity2);
                        }
                        else
                        {
                            current_username = "";
                            Toast.MakeText(this, "Login Failed, Invalid username or password", ToastLength.Long).Show();
                        }
                    }
                } catch (MobileServiceInvalidOperationException exp)
                {
                    if (exp.Message.Contains("The item does not exist"))
                    {
                        Toast.MakeText(this, "Username or Password are incorrect. Please try again.", ToastLength.Long).Show();
                        return;
                    }
                    else
                    {
                        Toast.MakeText(this, "Something went wrong :/ please try again!", ToastLength.Long).Show();
                    }
                }
            };

            // actions per button
            bsignup.Click += async(sender, e) =>
            {
                StartActivity(new Intent(this, typeof(SignUpActivity)));
            };
        }
Exemple #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_signup);

            // This MobileServiceClient has been configured to communicate with the Azure Mobile App and
            // Azure Gateway using the application url. You're all set to start working with your Mobile App!
            //Microsoft.WindowsAzure.MobileServices.MobileServiceClient eHealthHeartRateClient = new Microsoft.WindowsAzure.MobileServices.MobileServiceClient("https://ehealthheartrate.azurewebsites.net");

            // Set our view from the "main" layout resource

            EditText etFirstname            = (EditText)FindViewById(Id.etFirstName);
            EditText etLasttname            = (EditText)FindViewById(Id.etLastName);
            EditText etPassword             = (EditText)FindViewById(Id.etPassword);
            EditText etHeigth               = (EditText)FindViewById(Id.etHeight);
            EditText etWeigth               = (EditText)FindViewById(Id.etWeight);
            EditText etDob                  = (EditText)FindViewById(Id.etDob);
            EditText etUsername             = (EditText)FindViewById(Id.etUserName);
            EditText etDoctorName           = (EditText)FindViewById(Id.etDoctorName);
            Spinner  ganderSpinner          = (Spinner)FindViewById(Id.spinnerGnder);
            Spinner  healthConditionSpinner = (Spinner)FindViewById(Id.spinnerHealthCondiotion);

            // TODO: check how I can do this about Spinners
            string[]     data          = { "Female", "Male" };
            ArrayAdapter ganderAdapter = new ArrayAdapter(this,
                                                          Android.Resource.Layout.SimpleListItem1, data);

            ganderSpinner.Adapter = ganderAdapter;

            string[]     data1             = { "Healthy", "UnHealthy" };
            ArrayAdapter healthCondAdapter = new ArrayAdapter(this,
                                                              Android.Resource.Layout.SimpleListItem1, data1);

            healthConditionSpinner.Adapter = healthCondAdapter;

            Button bsignup = (Button)FindViewById(Id.Bsingnup);

            mClient = AzureServiceAdapter.getInstance().getClient();

            //IMobileServiceTable<Users> mTable = mClient.GetTable("Users", Users.class);  <-- as it was in java
            mTable = mClient.GetTable <Users>();
            Toast.MakeText(this, "Welcome", ToastLength.Long).Show();

            // actions per button
            bsignup.Click += async(sender, e) =>
            {
                if (!isInputValidate(etFirstname,
                                     etLasttname,
                                     etPassword,
                                     etHeigth,
                                     etWeigth,
                                     etDob,
                                     etUsername,
                                     etDoctorName))
                {
                    return;
                }
                //Newtonsoft.Json.Linq.JToken useritem;
                Users useritem;

                try
                {
                    // Checking out if username already exist in DB
                    useritem = await mTable.LookupAsync(UUID.NameUUIDFromBytes(Encoding.ASCII.GetBytes(etUsername.Text.ToString())).ToString());

                    // Getting to this line iff LookupAsync successfully finished
                    System.Diagnostics.Debug.WriteLine("Lookup requests return with success.");
                    etUsername.Error = "Username is already exists\n";
                    validInput       = false;
                    System.Diagnostics.Debug.WriteLine("User is already exists\n{0}\n", etUsername.Text.ToString());
                }
                // In case the user is valid (not exists in DB) we will create a new one
                catch (MobileServiceInvalidOperationException exp)
                {
                    if (exp.Message.Contains("The item does not exist"))
                    {
                        System.Diagnostics.Debug.WriteLine("Lookup requests return with failure.");
                        System.Diagnostics.Debug.WriteLine("The username is free, lts' send signup request!");

                        // SignUp Request
                        sendSignupReq(etFirstname,
                                      etLasttname,
                                      etPassword,
                                      etHeigth,
                                      etWeigth,
                                      etDob,
                                      etUsername,
                                      etDoctorName,
                                      ganderSpinner,
                                      healthConditionSpinner);

                        // Finaly Create a user Item
                        //Users item = json2UserItem(useritem);

                        // Enter prev_n, avg, deviation = 0 when creating the tables
                    }
                    else
                    {
                        Toast.MakeText(this, "Something went wrong :/ please try again!", ToastLength.Long).Show();
                    }
                }
            };
        }