public ThingBase DeserializeItem(XPathNavigator thingNav) { ThingBase result; Guid typeId = new Guid(thingNav.SelectSingleNode("type-id").Value); Type handler = null; if (typeId == _applicationSpecificTypeId) { // 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) { var appSpecificHandlers = _thingTypeRegistrar.RegisteredAppSpecificHandlers; if (appSpecificHandlers.ContainsKey(appDataKey.AppId)) { if (appSpecificHandlers[appDataKey.AppId].ContainsKey(appDataKey.SubtypeTag)) { handler = appSpecificHandlers[appDataKey.AppId][appDataKey.SubtypeTag]; } } } } if (handler == null && _typeHandlers.ContainsKey(typeId)) { handler = _typeHandlers[typeId]; } if (handler != null) { result = (ThingBase)Activator.CreateInstance(handler); } else { result = new ThingBase(typeId); } result.ParseXml(thingNav, thingNav.OuterXml); return(result); }
private 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); }
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(); result.AppId = appIdNav.Value; result.SubtypeTag = subtypeNav.Value; } return result; }