void GetThingsCompleted(object sender, HealthVaultResponseEventArgs e) { if (e.ErrorText == null) { XElement responseNode = XElement.Parse(e.ResponseXml); // using LINQ to get the latest reading of blood pressure state var readings = (from thingNode in responseNode.Descendants("thing") orderby Convert.ToDateTime(thingNode.Element("eff-date").Value) ascending select thingNode).ToList(); Deployment.Current.Dispatcher.BeginInvoke(() => { BloodPressureModel bloodPressureState = new BloodPressureModel(); foreach (var item in readings) { bloodPressureState.Parse(item); _data.Add(new GraphItem { Name = bloodPressureState.When.ToShortDateString(), Value = bloodPressureState.Systolic.ToString() }); } progressOverlay.Hide(); }); } else { Dispatcher.BeginInvoke(() => { MessageBox.Show(e.ErrorText); }); } }
void GetThingsCompleted(object sender, HealthVaultResponseEventArgs e) { ObservableCollection<EmotionalStateModel> emotionList = new ObservableCollection<EmotionalStateModel>(); SetProgressBarVisibility(false); if (e.ErrorText == null) { XElement responseNode = XElement.Parse(e.ResponseXml); foreach (XElement thing in responseNode.Descendants("thing")) { DateTime when = Convert.ToDateTime(thing.Element("eff-date").Value); EmotionalStateModel emotionalState = new EmotionalStateModel(); emotionalState.When = when; emotionalState.Parse(thing.Descendants("data-xml").Descendants("emotion").Single()); Dispatcher.BeginInvoke( () => { DoItemAdd( emotionalState.When, emotionalState.Mood, emotionalState.Stress, emotionalState.Wellbeing); }); } } }
void DoShellAuthentication(object sender, HealthVaultResponseEventArgs e) { SetProgressBarVisibility(false); App.HealthVaultService.SaveSettings(App.SettingsFilename); string url; if (_addingRecord) { url = App.HealthVaultService.GetUserAuthorizationUrl(); } else { url = App.HealthVaultService.GetApplicationCreationUrl(); } App.HealthVaultShellUrl = url; // If we are using hosted browser via the hosted browser page Uri pageUri = new Uri("/HostedBrowser.xaml", UriKind.RelativeOrAbsolute); Deployment.Current.Dispatcher.BeginInvoke(() => { NavigationService.Navigate(pageUri); }); }
/// <summary> /// Process the list of authorized people and continue the flow. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The event arguments.</param> private static void GetAuthorizedPeopleCompleted(object sender, HealthVaultResponseEventArgs e) { AuthenticationCheckState state = (AuthenticationCheckState)e.Request.UserState; if (e.ErrorText != null) { state.AuthenticationCompletedHandler(state.Service, e); return; } XElement response = XElement.Parse(e.ResponseXml); XElement responseResults = response.Descendants("response-results").Single(); state.Service.Records.Clear(); foreach (XElement personInfo in responseResults.Elements("person-info")) { Guid personId = new Guid(personInfo.Element("person-id").Value); string personName = personInfo.Element("name").Value; // If we loaded our settings, the current record is incomplete. We will try // to match it to one that we got back... HealthVaultRecord currentRecord = state.Service.CurrentRecord; state.Service.CurrentRecord = null; foreach (XElement recordNode in personInfo.Elements("record")) { HealthVaultRecord record = HealthVaultRecord.Create(personId, personName, HealthVaultService.GetOuterXml(recordNode)); if (record != null) { state.Service.Records.Add(record); if ((currentRecord != null) && (currentRecord.PersonId == record.PersonId) && (currentRecord.RecordId == record.RecordId)) { state.Service.CurrentRecord = record; } } } } if (state.Service.Records.Count != 0) { // all done state.AuthenticationCompletedHandler(state.Service, null); } else { // unsuccessful, restart from scratch... state.Service.ClearProvisioningInformation(); BeginAuthenticationCheck(state); } }
/// <summary> /// Invoke the calling application's callback. /// </summary> /// <param name="request">The request.</param> /// <param name="resultText">The raw response.</param> /// <param name="response">The response object.</param> /// <param name="errorText">The error text, or null if successful. </param> private void InvokeApplicationResponseCallback( HealthVaultRequest request, string resultText, HealthVaultResponse response, string errorText) { HealthVaultResponseEventArgs eventArgs = new HealthVaultResponseEventArgs(request, resultText, response); eventArgs.ErrorText = errorText; if (request.ResponseCallback != null) { request.ResponseCallback(this, eventArgs); } }
/// <summary> /// Processes the CAST information and re-issues the original request. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The event args.</param> private void RefreshSessionTokenCompleted(object sender, HealthVaultResponseEventArgs e) { SendPostEventArgs args = (SendPostEventArgs)e.Request.UserState; // any error just gets returned to the application. if (e.ErrorText != null) { InvokeApplicationResponseCallback(args.HealthVaultRequest, args.ResponseData, e.Response, e.Response.ErrorMessage); return; } // if the CAST was successful the results were saved and // the original request is restarted. SaveCastCallResults(e.ResponseXml); BeginSendRequest(args.HealthVaultRequest); }
/// <summary> /// Save the new application info and continue the process. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The event arguments.</param> private static void NewApplicationCreationInfoCompleted(object sender, HealthVaultResponseEventArgs e) { AuthenticationCheckState state = (AuthenticationCheckState)e.Request.UserState; if (e.ErrorText != null) { state.AuthenticationCompletedHandler(state.Service, e); return; } XElement response = XElement.Parse(e.ResponseXml); XNamespace responseNamespace = "urn:com.microsoft.wc.methods.response.NewApplicationCreationInfo"; XElement info = response.Element(responseNamespace + "info"); state.Service.AppIdInstance = new Guid(info.Element("app-id").Value); state.Service.SharedSecret = info.Element("shared-secret").Value; state.Service.ApplicationCreationToken = info.Element("app-token").Value; state.ShellAuthRequiredHandler(state.Service, e); }
/// <summary> /// Handle the response from the CAST call and continue the flow. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The event arguments.</param> private static void CastCallCompleted(object sender, HealthVaultResponseEventArgs e) { AuthenticationCheckState state = (AuthenticationCheckState)e.Request.UserState; if (e.ErrorCode == ErrorInvalidApp) { state.Service.SharedSecret = null; // force creation of app from scratch... state.Service.AppIdInstance = Guid.Empty; } else if (e.ErrorText != null) { state.ShellAuthRequiredHandler(state.Service, e); return; } else { state.Service.SaveCastCallResults(e.ResponseXml); } BeginAuthenticationCheck(state); }
void GetThingsCompleted(object sender, HealthVaultResponseEventArgs e) { ObservableCollection<EmotionalStateModel> emotionList = new ObservableCollection<EmotionalStateModel>(); SetProgressBarVisibility(false); if (e.ErrorText == null) { XElement responseNode = XElement.Parse(e.ResponseXml); foreach (XElement thing in responseNode.Descendants("thing")) { EmotionalStateModel emotionalState = new EmotionalStateModel(); emotionalState.Parse(thing); Dispatcher.BeginInvoke( () => { DoItemAdd( emotionalState.When, emotionalState.Mood, emotionalState.Stress, emotionalState.Wellbeing, emotionalState.Note); }); } } }
void AuthenticationCompleted(object sender, HealthVaultResponseEventArgs e) { SetProgressBarVisibility(false); if (e != null && e.ErrorText != null) { SetRecordName(e.ErrorText); return; } if (App.HealthVaultService.CurrentRecord == null) { App.HealthVaultService.CurrentRecord = App.HealthVaultService.Records[0]; } App.HealthVaultService.SaveSettings(App.SettingsFilename); if (App.HealthVaultService.CurrentRecord != null) { SetRecordName(App.HealthVaultService.CurrentRecord.RecordName); // We are only interested in the last item HealthVaultMethods.GetThings(BloodPressureModel.TypeId, null, null, null, GetThingsCompleted); SetProgressBarVisibility(true); } }
void GetThingsCompleted(object sender, HealthVaultResponseEventArgs e) { SetProgressBarVisibility(false); if (e.ErrorText == null) { XElement responseNode = XElement.Parse(e.ResponseXml); // using LINQ to get the latest reading of blood pressure state XElement latestReading = (from thingNode in responseNode.Descendants("thing") orderby Convert.ToDateTime(thingNode.Element("eff-date").Value) descending select thingNode).FirstOrDefault<XElement>(); if (latestReading != null) { BloodPressureModel bloodPressureState = new BloodPressureModel(); bloodPressureState.Parse(latestReading); Deployment.Current.Dispatcher.BeginInvoke(() => { txtLastUpdated.Text = string.Format("When - {0}, Systolic - {1}, Diastolic - {2}", bloodPressureState.When.ToString("MMM dd, yyyy"), bloodPressureState.Systolic, bloodPressureState.Diastolic); }); } else { Deployment.Current.Dispatcher.BeginInvoke(() => { txtLastUpdated.Text = "No readings! Time to track blood pressure."; }); } } }
void GetThingsCompleted(object sender, HealthVaultResponseEventArgs e) { SetProgressBarVisibility(false); if (e.ErrorText == null) { XElement responseNode = XElement.Parse(e.ResponseXml); foreach (XElement thing in responseNode.Descendants("thing")) { EmotionalStateModel emotionalState = new EmotionalStateModel(); emotionalState.Parse(thing); this.emotionList.Add(emotionalState); } } /* * Algorithm * 1. Read last 1 month's readings * 2. Weight 50% to 4th week * 3. Weight 25% to 1-3 week * 4. Weight 25% to how many readings (Good is 4/wk) */ DateTime time50p = baseTime.Subtract(new TimeSpan(7,0,0,0)); DateTime time30p = baseTime.Subtract(new TimeSpan(14, 0, 0, 0)); int m = 0; int s = 0; int w = 0; int c50 = 0; int c30 = 0; int c20 = 0; foreach (EmotionalStateModel emotion in emotionList) { if (emotion.When >= time50p) { m += (int)emotion.Mood * 50 ; s += (int)emotion.Stress * 50 ; w += (int)emotion.Wellbeing * 50; c50++; } else if (emotion.When >= time30p) { m += (int)emotion.Mood * 30; s += (int)emotion.Stress * 30 ; w += (int)emotion.Wellbeing * 30; c30++; } else { m += (int)emotion.Mood * 20; s += (int)emotion.Stress * 20; w += (int)emotion.Wellbeing * 20; c20++; } } // Final numbers int c = 50 * c50 + 30 * c30 + 20 * c20; m = m / c; s = s /c; w = w / c; EmotionalStateModel resultEmotion = new EmotionalStateModel(); resultEmotion.Mood = (Mood) m; resultEmotion.Stress = (Stress) s; resultEmotion.Wellbeing = (Wellbeing) w; RenderPlantValue(resultEmotion); }
void GetThingsCompleted(object sender, HealthVaultResponseEventArgs e) { SetProgressBarVisibility(false); if (e.ErrorText == null) { XElement responseNode = XElement.Parse(e.ResponseXml); // using linq to get the latest reading of emotional state XElement latestEmotion = (from thingNode in responseNode.Descendants("thing") orderby Convert.ToDateTime(thingNode.Element("eff-date").Value) descending select thingNode).FirstOrDefault<XElement>(); EmotionalStateModel emotionalState = new EmotionalStateModel(); emotionalState.Parse(latestEmotion.Descendants("data-xml").Descendants("emotion").Single()); string lastTime = Convert.ToDateTime(latestEmotion.Element("eff-date").Value).ToString(); Deployment.Current.Dispatcher.BeginInvoke(() => { c_LastUpdated.Text += lastTime; c_MoodSlider.Value = (double)emotionalState.Mood; c_StressSlider.Value = (double)emotionalState.Stress; c_WellbeingSlider.Value = (double)emotionalState.Wellbeing; this.DataContext = this; //c_Mood.Text += System.Enum.GetName(typeof(Mood), emotionalState.Mood); //c_Stress.Text += System.Enum.GetName(typeof(Stress), emotionalState.Stress); //c_Wellbeing.Text += System.Enum.GetName(typeof(Wellbeing), emotionalState.Wellbeing); }); } }
void GetThingsCompleted(object sender, HealthVaultResponseEventArgs e) { SetProgressBarVisibility(false); if (e.ErrorText == null) { XElement responseNode = XElement.Parse(e.ResponseXml); // using LINQ to get the latest reading of emotional state XElement latestEmotion = (from thingNode in responseNode.Descendants("thing") orderby Convert.ToDateTime(thingNode.Element("eff-date").Value) descending select thingNode).FirstOrDefault<XElement>(); if (latestEmotion != null) { EmotionalStateModel emotionalState = new EmotionalStateModel(); emotionalState.Parse(latestEmotion); Deployment.Current.Dispatcher.BeginInvoke(() => { c_LastUpdated.Text += string.Format("{0} - \nMood:{1}, Stress:{2}, Wellbeing:{3}", emotionalState.When.ToString("MMM dd, yyyy"), System.Enum.GetName(typeof(Mood), emotionalState.Mood), System.Enum.GetName(typeof(Stress), emotionalState.Stress), System.Enum.GetName(typeof(Wellbeing), emotionalState.Wellbeing)); this.DataContext = this; }); } else { Deployment.Current.Dispatcher.BeginInvoke(() => { c_LastUpdated.Text = "No readings! Time to track mood."; this.DataContext = this; }); } } }
void PutThingsCompleted(object sender, HealthVaultResponseEventArgs e) { SetProgressBarVisibility(false); if (e.ErrorText != null) { SetErrorMesasge(e.ErrorText); } else { SetUserToast("Mood successfully saved!"); } }
void PutThingsCompleted(object sender, HealthVaultResponseEventArgs e) { SetProgressBarVisibility(false); if (e.ErrorText != null) { SetErrorMesasge(e.ErrorText); } else { Dispatcher.BeginInvoke(() => { HealthVaultMethods.GetThings(BloodPressureModel.TypeId, null, null, null, GetThingsCompleted); var messagePrompt = new MessagePrompt { Title = "Info", Message = "Blood Pressure information saved successfully." }; messagePrompt.Show(); }); } }