public IPropertyValues GetPropertyValues(IEvidence evdnc) { Device deviceFound = null; Browser browserFound = null; OSModel.OperatingSystem osFound = null; bool deviceIdentified = false; bool browserIdentified = false; bool osIdentified = false; UserAgent deviceUA = null; UserAgent browserUA = null; ODDRPropertyValues ret = new ODDRPropertyValues(); Dictionary<String, Vocabulary> vocabularies = vocabularyHolder.GetVocabularies(); foreach (String vocabularyKey in vocabularies.Keys) { Vocabulary vocabulary = vocabularies[vocabularyKey]; Dictionary<String, VocabularyProperty> properties = vocabulary.properties; foreach (String propertyKey in properties.Keys) { IPropertyName propertyName = new ODDRPropertyName(propertyKey, vocabularyKey); VocabularyProperty vocabularyProperty = properties[propertyKey]; string[] aspects = vocabularyProperty.aspects; for (int i = 0; i < aspects.Length; i++) { IPropertyRef propertyRef = new ODDRPropertyRef(propertyName, aspects[i]); if (ASPECT_DEVICE.Equals(propertyRef.AspectName())) { if (!deviceIdentified) { if (deviceUA == null) { deviceUA = UserAgentFactory.newDeviceUserAgent(evdnc); } if (evdnc is BufferedODDRHTTPEvidence) { deviceFound = ((BufferedODDRHTTPEvidence)evdnc).deviceFound; } if (deviceFound == null) { deviceFound = deviceIdentificator.Get(deviceUA, this.threshold) as Device; } if (evdnc is BufferedODDRHTTPEvidence) { ((BufferedODDRHTTPEvidence)evdnc).deviceFound = deviceFound; } deviceIdentified = true; } String property = null; if (deviceFound != null) { property = deviceFound.Get(propertyRef.LocalPropertyName()); ret.addProperty(new ODDRPropertyValue(property, vocabularyProperty.type, propertyRef)); } else { ret.addProperty(new ODDRPropertyValue(null, vocabularyProperty.type, propertyRef)); } continue; } else if (ASPECT_WEB_BROWSER.Equals(propertyRef.AspectName())) { if (!browserIdentified) { if (browserUA == null) { browserUA = UserAgentFactory.newBrowserUserAgent(evdnc); } if (evdnc is BufferedODDRHTTPEvidence) { browserFound = ((BufferedODDRHTTPEvidence)evdnc).browserFound; } if (browserFound == null) { browserFound = browserIdentificator.Get(browserUA, this.threshold) as Browser; } if (evdnc is BufferedODDRHTTPEvidence) { ((BufferedODDRHTTPEvidence)evdnc).browserFound = browserFound; } browserIdentified = true; } String property = null; if (browserFound != null) { property = browserFound.Get(propertyRef.LocalPropertyName()); ret.addProperty(new ODDRPropertyValue(property, vocabularyProperty.type, propertyRef)); } else { ret.addProperty(new ODDRPropertyValue(null, vocabularyProperty.type, propertyRef)); } continue; } else if (ASPECT_OPERATIVE_SYSTEM.Equals(propertyRef.AspectName())) { if (!osIdentified) { if (deviceUA == null) { deviceUA = UserAgentFactory.newDeviceUserAgent(evdnc); } if (evdnc is BufferedODDRHTTPEvidence) { osFound = ((BufferedODDRHTTPEvidence)evdnc).osFound; } if (osFound == null) { osFound = osIdentificator.Get(deviceUA, this.threshold) as OSModel.OperatingSystem; } if (evdnc is BufferedODDRHTTPEvidence) { ((BufferedODDRHTTPEvidence)evdnc).osFound = osFound; } osIdentified = true; } String property = null; if (osFound != null) { property = osFound.Get(propertyRef.LocalPropertyName()); ret.addProperty(new ODDRPropertyValue(property, vocabularyProperty.type, propertyRef)); } else { ret.addProperty(new ODDRPropertyValue(null, vocabularyProperty.type, propertyRef)); } continue; } } } } return ret; }
/// <summary> /// /// </summary> /// <param name="evdnc"></param> /// <param name="prs"></param> /// <returns></returns> /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception> public IPropertyValues GetPropertyValues(IEvidence evdnc, IPropertyRef[] prs) { Device deviceFound = null; Browser browserFound = null; OSModel.OperatingSystem osFound = null; bool deviceIdentified = false; bool browserIdentified = false; bool osIdentified = false; UserAgent deviceUA = null; UserAgent browserUA = null; ODDRPropertyValues ret = new ODDRPropertyValues(); Dictionary<String, Vocabulary> vocabularies = vocabularyHolder.GetVocabularies(); foreach (IPropertyRef propertyRef in prs) { VocabularyProperty vocabularyProperty = vocabularyHolder.ExistProperty(propertyRef.LocalPropertyName(), propertyRef.AspectName(), propertyRef.Namespace(), true); Vocabulary vocabulary = null; string nameSpace = propertyRef.Namespace(); if (vocabularies.TryGetValue(nameSpace, out vocabulary)) { if (ASPECT_DEVICE.Equals(propertyRef.AspectName())) { if (!deviceIdentified) { if (deviceUA == null) { deviceUA = UserAgentFactory.newDeviceUserAgent(evdnc); } if (evdnc is BufferedODDRHTTPEvidence) { deviceFound = ((BufferedODDRHTTPEvidence)evdnc).deviceFound; } if (deviceFound == null) { deviceFound = deviceIdentificator.Get(deviceUA, this.threshold) as Device; } if (evdnc is BufferedODDRHTTPEvidence) { ((BufferedODDRHTTPEvidence)evdnc).deviceFound = deviceFound; } deviceIdentified = true; } String property = null; if (deviceFound != null) { property = deviceFound.Get(propertyRef.LocalPropertyName()); ret.addProperty(new ODDRPropertyValue(property, vocabularyProperty.type, propertyRef)); } else { ret.addProperty(new ODDRPropertyValue(null, vocabularyProperty.type, propertyRef)); } continue; } else if (ASPECT_WEB_BROWSER.Equals(propertyRef.AspectName())) { //TODO: evaluate ua-pixels header in evidence if (!browserIdentified) { if (browserUA == null) { browserUA = UserAgentFactory.newBrowserUserAgent(evdnc); } if (evdnc is BufferedODDRHTTPEvidence) { browserFound = ((BufferedODDRHTTPEvidence)evdnc).browserFound; } if (browserFound == null) { browserFound = browserIdentificator.Get(browserUA, this.threshold) as Browser; } if (evdnc is BufferedODDRHTTPEvidence) { ((BufferedODDRHTTPEvidence)evdnc).browserFound = browserFound; } browserIdentified = true; } String property = null; if (browserFound != null) { property = browserFound.Get(propertyRef.LocalPropertyName()); ret.addProperty(new ODDRPropertyValue(property, vocabularyProperty.type, propertyRef)); } else { ret.addProperty(new ODDRPropertyValue(null, vocabularyProperty.type, propertyRef)); } continue; } else if (ASPECT_OPERATIVE_SYSTEM.Equals(propertyRef.AspectName())) { //TODO: evaluate ua-os header in evidence if (!osIdentified) { if (deviceUA == null) { deviceUA = UserAgentFactory.newDeviceUserAgent(evdnc); } if (evdnc is BufferedODDRHTTPEvidence) { osFound = ((BufferedODDRHTTPEvidence)evdnc).osFound; } if (osFound == null) { osFound = osIdentificator.Get(deviceUA, this.threshold) as OSModel.OperatingSystem; } if (evdnc is BufferedODDRHTTPEvidence) { ((BufferedODDRHTTPEvidence)evdnc).osFound = osFound; } osIdentified = true; } String property = null; if (osFound != null) { property = osFound.Get(propertyRef.LocalPropertyName()); ret.addProperty(new ODDRPropertyValue(property, vocabularyProperty.type, propertyRef)); } else { ret.addProperty(new ODDRPropertyValue(null, vocabularyProperty.type, propertyRef)); } continue; } } } return ret; }