/// <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 + ".xml");

            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 CHBaseRecord(personId, recordId);
                }
            }
        }
        /// <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, CHBaseResponseEventArgs 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...
                CHBaseRecord currentRecord = state.Service.CurrentRecord;
                state.Service.CurrentRecord = null;

                foreach (XElement recordNode in personInfo.Elements("record"))
                {
                    CHBaseRecord record = CHBaseRecord.Create(personId, personName, CHBaseService.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 CHBaseRecord Create(Guid personId, string personName, string recordXml)
        {
            CHBaseRecord record = new CHBaseRecord();

            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);
        }
        /// <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 CHBaseRecord Create(Guid personId, string personName, string recordXml)
        {
            CHBaseRecord record = new CHBaseRecord();

            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;
        }
        /// <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 + ".xml");

            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 CHBaseRecord(personId, recordId);
                }
            }
        }