Пример #1
0
        /// <summary>
        /// Loads the last-saved configuration from isolated storage.
        /// </summary>
        /// <param name="name">The filename to use.</param>
        public void LoadSettings(string name)
        {
            string settingsXml = MobilePlatform.ReadTextFromFile(name);

            if (settingsXml != null)
            {
                XElement settings = XElement.Parse(settingsXml);

                string version = settings.Element("Version").Value;

                string applicationIdString = settings.Element("ApplicationId").Value;
                AppIdInstance             = new Guid(applicationIdString);
                AuthorizationSessionToken = settings.Element("AuthorizationSessionToken").Value;
                SharedSecret        = settings.Element("SharedSecret").Value;
                Country             = settings.Element("Country").Value;
                Language            = settings.Element("Language").Value;
                SessionSharedSecret = settings.Element("SessionSharedSecret").Value;

                // Create a temporary current record until we fetch the real one.
                XElement personIdNode = settings.Element("PersonId");
                if (settings.Element("PersonId") != null)
                {
                    Guid personId = new Guid(settings.Element("PersonId").Value);
                    Guid recordId = new Guid(settings.Element("RecordId").Value);

                    CurrentRecord            = new HealthVaultRecord(personId, recordId);
                    CurrentRecord.RecordName = settings.Element("RecordName").Value;
                }
            }
        }
Пример #2
0
        /// <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>
        /// Creates a new instance of the HealthVaultRecord class.
        /// </summary>
        /// <param name="personId">The id of the person.</param>
        /// <param name="personName">The name of the person.</param>
        /// <param name="recordXml">The full XML describing this record.</param>
        /// <returns>An instance of the HealthVaultRecord class.</returns>
        public static HealthVaultRecord Create(Guid personId, string personName, string recordXml)
        {
            HealthVaultRecord record = new HealthVaultRecord();

            record.PersonId = personId;
            record.PersonName = personName;
            record.Xml = recordXml;

            XElement recordNode = XElement.Parse(recordXml);

            record.RecordId = new Guid(recordNode.Attribute("id").Value);
            record.RecordName = recordNode.Value;

            // if there are any auth issues, we don't keep this record...
            string appRecordAuthAction = recordNode.Attribute("app-record-auth-action").Value;
            if (appRecordAuthAction != "NoActionRequired")
            {
                record = null;
            }

            return record;
        }
Пример #4
0
        /// <summary>
        /// Creates a new instance of the HealthVaultRecord class.
        /// </summary>
        /// <param name="personId">The id of the person.</param>
        /// <param name="personName">The name of the person.</param>
        /// <param name="recordXml">The full XML describing this record.</param>
        /// <returns>An instance of the HealthVaultRecord class.</returns>
        public static HealthVaultRecord Create(Guid personId, string personName, string recordXml)
        {
            HealthVaultRecord record = new HealthVaultRecord();

            record.PersonId   = personId;
            record.PersonName = personName;
            record.Xml        = recordXml;

            XElement recordNode = XElement.Parse(recordXml);

            record.RecordId   = new Guid(recordNode.Attribute("id").Value);
            record.RecordName = recordNode.Value;

            // if there are any auth issues, we don't keep this record...
            string appRecordAuthAction = recordNode.Attribute("app-record-auth-action").Value;

            if (appRecordAuthAction != "NoActionRequired")
            {
                record = null;
            }

            return(record);
        }