Esempio n. 1
0
        private void AutoSuggestBox_KeyDown(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
        {
            if (isStrainListFull == false)
            {
                return;
            }

            if (StrainChosen != null)
            {
                if (StrainChosen.ToLower().Equals(StrainList.Text.ToLower()))
                {
                    if (e.Key == Windows.System.VirtualKey.Enter)
                    {
                        StrainList.IsSuggestionListOpen = false;
                        PagesUtilities.SleepSeconds(0.2);

                        SubmitString(null, null);
                    }
                }
                else
                {
                    UsageContext.ChosenStrain = null;
                }
            }
        }
Esempio n. 2
0
        private async void SubmitFeedback(object sender, TappedRoutedEventArgs e) // Send feedback to server
        {
            HttpResponseMessage res = null;
            UsageUpdateRequest  req;

            double[] ranks = new double[4];

            ranks = GetRanks(questionDictionary);

            try
            { // Build request for server
                progressRing.IsActive = true;
                GlobalContext.CurrentUser.UsageSessions.LastOrDefault().usageFeedback = questionDictionary;

                UsageData use    = GlobalContext.CurrentUser.UsageSessions.LastOrDefault();
                string    userId = GlobalContext.CurrentUser.Data.UserID;

                req = new UsageUpdateRequest(use.UsageStrain.Name, use.UsageStrain.ID,
                                             userId,
                                             ((DateTimeOffset)use.StartTime).ToUnixTimeMilliseconds(),
                                             ((DateTimeOffset)use.EndTime).ToUnixTimeMilliseconds(),
                                             ranks[0], ranks[1], ranks[2], use.HeartRateMax, use.HeartRateMin, (int)use.HeartRateAverage, ranks[3],
                                             questionDictionary);

                res = await HttpManager.Manager.Post(Constants.MakeUrl("usage"), req); // Send request

                if (res != null)
                { // Request sent successfully
                    if (res.IsSuccessStatusCode)
                    {
                        Status.Text = "Usage update Successful!";
                        var index = GlobalContext.CurrentUser.UsageSessions.Count - 1;
                        GlobalContext.CurrentUser.UsageSessions[index].UsageId = res.GetContent()["body"];
                        PagesUtilities.SleepSeconds(0.5);
                        Frame.Navigate(typeof(DashboardPage));
                    }
                    else
                    {
                        Status.Text = "Usage update failed! Status = " + res.StatusCode;
                    }
                }
                else
                {
                    Status.Text = "Usage update failed!\nPost operation failed";
                }

                Frame.Navigate(typeof(DashboardPage));
            }
            catch (Exception x)
            {
                AppDebug.Exception(x, "UsageUpdate");
            }
        }
Esempio n. 3
0
        private async void SendEmailAsync(object sender, RoutedEventArgs e)
        {
            HttpResponseMessage res = null;
            SendEmailRequest    req;

            if (EmailAddressBox.Text.IsValidEmail()) // Check email validity
            {
                try
                {
                    progressRing.IsActive = true;

                    // Send email request
                    req = new SendEmailRequest(EmailAddressBox.Text, FreeMessageBox.Text);
                    // Export usages
                    res = await HttpManager.Manager.Post(Constants.MakeUrl($"usage/export/{GlobalContext.CurrentUser.Data.UserID}"), req);

                    progressRing.IsActive = false;

                    if (res != null)
                    {
                        if (res.IsSuccessStatusCode)
                        { // Email sent successfully
                            await new MessageDialog($"An email was sent to {EmailAddressBox.Text} successfully", "Success").ShowAsync();
                        }
                        else
                        {
                            await new MessageDialog($"There was an error while sending the mail (status: {res.StatusCode}, message: \"{res.GetContent()["message"]}\"", "Error").ShowAsync();
                        }
                    }
                    else
                    {
                        await new MessageDialog($"There was an error with the server, response is empty.", "Error").ShowAsync();
                    }

                    PagesUtilities.SleepSeconds(1);
                    Frame.Navigate(typeof(DashboardPage));
                }
                catch (Exception x)
                {
                    AppDebug.Exception(x, "UsageUpdate");
                }
            }
            else
            { // Email address not valid
                await new MessageDialog("Invalid email address. Please try again").ShowAsync();
            }
        }
Esempio n. 4
0
        private async void EditRegister(object sender, RoutedEventArgs e)
        {
            HttpResponseMessage res = null;
            var user_id             = GlobalContext.CurrentUser.Data.UserID;


            try
            {
                progressRing.IsActive = true;

                PagesUtilities.GetAllCheckBoxesTags(EditNegativeEffectsGrid,
                                                    out List <int> intList);

                GlobalContext.RegisterContext.IntNegativePreferences = intList;
                res = await HttpManager.Manager.Post(Constants.MakeUrl($"edit/{user_id}"), GlobalContext.RegisterContext);


                if (res != null)
                {
                    if (res.IsSuccessStatusCode)
                    {
                        Status.Text = "Edit profile Successful!";
                        PagesUtilities.SleepSeconds(0.5);
                        Frame.Navigate(typeof(DashboardPage), res);
                    }
                    else
                    {
                        Status.Text = "Register failed! Status = " + res.StatusCode;
                    }
                }
                else
                {
                    Status.Text = "Register failed!\nPost operation failed";
                }
            }
            catch (Exception exc)
            {
                AppDebug.Exception(exc, "Register");
            }
            finally
            {
                progressRing.IsActive = false;
            }
        }
Esempio n. 5
0
        private async void StartSession(object sender, RoutedEventArgs e)
        {
            StartAction();

            bool useBand = UseBand.IsChecked.Value && isPaired && GlobalContext.Band.IsConnected();

            // Enter usage details
            UsageContext.Usage = new UsageData(UsageContext.ChosenStrain, DateTime.Now, useBand);

            if (!useBand)
            {
                Frame.Navigate(typeof(ActiveSession));
            }
            else // Use band, start acquiring heart rate
            {
                Acquiring.Visibility = Visibility.Visible;
                bool res = false;
                try
                { // Get heart rate
                    res = await Task.Run(() =>
                                         GlobalContext.Band.StartHeartRate(UsageContext.Usage.HeartRateChangedAsync));
                }
                catch (Exception x)
                {
                    AppDebug.Exception(x, "StartSession => StartHeartRate");
                }

                Acquiring.Visibility = Visibility.Collapsed;

                EndAction();
                if (res)
                { // Continue to active session with correct parameters
                    ContinueButton.Content = "Success!";
                    PagesUtilities.SleepSeconds(1);
                    Frame.Navigate(typeof(ActiveSession));
                }
                else
                {
                    await new MessageDialog("Try reconnecting the band, re-pairing and wear the band", "Failed!").ShowAsync();
                    return;
                }
            }
        }
Esempio n. 6
0
        private async void EndSessionAsync(object sender, RoutedEventArgs e)
        {
            try
            {
                var yesCommand = new UICommand("End Session", cmd =>
                {
                    AppDebug.Line("ending session...");
                    progressRing.IsActive = true;
                    try
                    {
                        if (UsageContext.Usage.UseBandData)
                        { // Stop band usage
                            GlobalContext.Band.StopHeartRate();
                            PagesUtilities.SleepSeconds(0.5);
                        }
                        UsageContext.Usage.EndUsage();
                    }
                    catch (Exception x)
                    {
                        AppDebug.Exception(x, "EndSession");
                    }
                    progressRing.IsActive = false;
                    Frame.Navigate(typeof(PostTreatment));
                });
                var noCommand = new UICommand("Continue Session", cmd =>
                {
                    AppDebug.Line("Cancel end session");
                });
                var dialog = new MessageDialog("Are you sure you want to end the session", "End Session")
                {
                    Options = MessageDialogOptions.None
                };
                dialog.Commands.Add(yesCommand);
                dialog.Commands.Add(noCommand);

                await dialog.ShowAsync();
            }
            catch (Exception x)
            {
                AppDebug.Exception(x, "Remove_Click");
            }
        }
        private async void OnPageLoaded(object sender, RoutedEventArgs e)
        {
            progressRing.IsActive     = true;
            UsageContext.ChosenStrain = null;
            if (GlobalContext.CurrentUser != null)
            { // Get recommended strains for user from server
                Message.Text = "Searching for matching strains based on your profile...";

                var user_id = GlobalContext.CurrentUser.Data.UserID;
                var url     = Constants.MakeUrl($"strains/recommended/{user_id}/"); // Build url for user

                try
                { // Send request to server
                    var res = await HttpManager.Manager.Get(url);

                    if (res == null)
                    {
                        progressRing.IsActive = false;
                        return;
                    }
                    // Successful request
                    PagesUtilities.SleepSeconds(0.2);

                    // Recommended strain list
                    strains = await Task.Run(() => HttpManager.ParseJson <SuggestedStrains>(res)); // Parsing JSON

                    if (strains.SuggestedStrainList.Count == 0)
                    {
                        ErrorNoStrainFound.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        switch (strains.Status)
                        {       // Status for match type
                        case 0: // Full match
                            Message.Text = $"Showing {strains.SuggestedStrainList.Count} exactly matched strains:";
                            break;

                        case 1:     // Partial match - medical match but positive dont
                            Message.Text = $"No exact matches found!\nTry updating your positive preferences.\nShowing {strains.SuggestedStrainList.Count} partially matching strains:";
                            break;

                        case 2:     // Partial match - medical and positive don't match
                            Message.Text = $"No exact matches found!\nTry updating your positive and medical preferences.\nShowing {strains.SuggestedStrainList.Count} partially matching strains:";
                            break;
                        }
                        Scroller.Height = Stack.ActualHeight - Message.ActualHeight - 20;

                        Random rnd = new Random();

                        foreach (var strain in strains.SuggestedStrainList)
                        { // **Random numbers**
                            strain.Rank           = rnd.Next(1, 100);
                            strain.NumberOfUsages = rnd.Next(0, 1000);
                        }

                        if (strains.Status != 0)
                        { // Calculate partal match rate
                            foreach (var strain in strains.SuggestedStrainList)
                            {
                                strain.MatchingPercent = strain / GlobalContext.CurrentUser;
                            }

                            strains.SuggestedStrainList.Sort(Strain.MatchComparison);
                            matchSortedStrains = new SuggestedStrains(strains.Status, new List <Strain>(strains.SuggestedStrainList));;
                        }

                        var names = $"[{string.Join(", ", from u in strains.SuggestedStrainList select $"{u.Name}")}]";
                        AppDebug.Line($"Status={strains.Status} Got {strains.SuggestedStrainList.Count} strains: {names}");

                        FillStrainList(strains);

                        foreach (var child in ButtonsGrid.Children)
                        { // Display buttons to choose strains
                            if (child.GetType() == typeof(Viewbox))
                            {
                                var b = (child as Viewbox).Child as RadioButton;
                                if (!((string)b.Tag == "match" && strains.Status == 0))
                                {
                                    b.IsEnabled = true;
                                }
                            }
                        }
                        ButtonsGrid.Opacity = 1;
                        //StrainList.Height = Scroller.ActualHeight;
                    }
                }
                catch (Exception x)
                {
                    AppDebug.Exception(x, "OnPageLoaded");
                    await new MessageDialog("Error while getting suggestions from the server", "Error").ShowAsync();
                }

                progressRing.IsActive = false;
            }
        }