コード例 #1
0
        /// <summary>
        /// Deserializes the response XML for extensions into a 
        /// <see cref="HealthRecordItemExtension"/> or derived type based on the registered 
        /// extension handler.
        /// </summary>
        /// 
        /// <param name="extensionNav">
        /// The XML representation of the extension data.
        /// </param>
        /// 
        /// <returns>
        /// The <see cref="HealthRecordItemExtension"/> or derived class instance 
        /// representing the data in the XML.
        /// </returns>
        /// 
        /// <exception cref="System.Reflection.TargetInvocationException">
        /// If the constructor of the type being created throws an 
        /// exception. The inner exception is the exception thrown by the
        /// constructor.
        /// </exception>
        /// 
        /// <exception cref="MissingMethodException">
        /// The default constructor of the type being created is not public.
        /// If you registered the extension handler, be sure that the type you
        /// registered for the extension type class has a public default 
        /// constructor.
        /// </exception>
        /// 
        internal static HealthRecordItemExtension DeserializeExtension(
            XPathNavigator extensionNav)
        {
            HealthRecordItemExtension result = null;

            string source = extensionNav.GetAttribute("source", String.Empty);
            if (_extensionHandlers.ContainsKey(source))
            {
                HealthRecordItemTypeHandler handler = _extensionHandlers[source];
                result =
                    (HealthRecordItemExtension)Activator.CreateInstance(
                        handler.ItemTypeClass);
            }
            else
            {
                result = new HealthRecordItemExtension(source);
            }
            result.ParseXml(extensionNav);
            return result;
        }
    protected void Submit_Daily_Diet_Click(object sender, System.EventArgs e)
    {
        //Post Diet
        DietaryDailyIntake diet = new DietaryDailyIntake();
        int totalCarbs;
        int.TryParse(Txt_DailyDietCarbs.Text, out totalCarbs);
        diet.TotalCarbohydrates.Kilograms = totalCarbs * 1000;
        diet.CommonData.Note = Txt_DailyDietNote.Text;

        //Adding extension data
        string drinks = Txt_DailyDietAlcohol.Text;
        HealthRecordItemExtension extension =
            new HealthRecordItemExtension(_appDailyAlcoholExtensionName);
        diet.CommonData.Extensions.Add(extension);
        XPathNavigator navigator = extension.ExtensionData.CreateNavigator();
        navigator.InnerXml = @"<extension source=""" + _appDailyAlcoholExtensionName + @""">
                <alcoholic-drinks>" + drinks + "</alcoholic-drinks>";

        PersonInfo.SelectedRecord.NewItem(diet);
    }