コード例 #1
0
        internal static ThingBase DeserializeItem(XPathNavigator thingNav)
        {
            ThingBase result;
            Guid      typeId = GetTypeId(thingNav);

            ThingTypeHandler handler = null;

            if (typeId == s_applicationSpecificId)
            {
                // Handle application specific health item records by checking for handlers
                // for the application ID and subtype tag. If the handler doesn't exist
                // the default handler will be picked up below.

                AppDataKey appDataKey = GetAppDataKey(thingNav);

                if (appDataKey != null)
                {
                    if (s_appSpecificHandlers.ContainsKey(appDataKey.AppId))
                    {
                        if (s_appSpecificHandlers[appDataKey.AppId].ContainsKey(appDataKey.SubtypeTag))
                        {
                            handler =
                                s_appSpecificHandlers[appDataKey.AppId][appDataKey.SubtypeTag];
                        }
                    }
                }
            }

            if (handler == null &&
                TypeHandlers.ContainsKey(typeId))
            {
                handler = TypeHandlers[typeId];
            }

            if (handler != null)
            {
                result = (ThingBase)Activator.CreateInstance(handler.ItemTypeClass);
            }
            else
            {
                result = new ThingBase(typeId);
            }

            result.ParseXml(thingNav, thingNav.OuterXml);

            return(result);
        }
コード例 #2
0
        private static AppDataKey GetAppDataKey(XPathNavigator thingNav)
        {
            AppDataKey     result   = null;
            XPathNavigator appIdNav =
                thingNav.SelectSingleNode("data-xml/app-specific/format-appid");

            XPathNavigator subtypeNav =
                thingNav.SelectSingleNode("data-xml/app-specific/format-tag");

            if (appIdNav != null && subtypeNav != null)
            {
                result = new AppDataKey
                {
                    AppId      = appIdNav.Value,
                    SubtypeTag = subtypeNav.Value
                };
            }

            return(result);
        }