public IPropertyValue GetValue(IPropertyRef pr)
 {
     foreach (IPropertyValue propertyValue in properties)
     {
         if (propertyValue.PropertyRef().Equals(pr))
         {
             return propertyValue;
         }
     }
     return null;
 }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            string oddrPropertiesPath = args[0];
            string userAgent = args[1];

            var fileSystem = new FileSystem(@"C:\Dev\Git\OpenDDR-ASP.NET\OpenDDRSimpleTest");
            Properties props = new Properties(fileSystem, oddrPropertiesPath);

            Type stype = Type.GetType("Oddr.ODDRService, OpenDdr");

            IService openDDRService = ServiceFactory.newService(stype, props.GetProperty("oddr.vocabulary.device"), props, fileSystem);

            IPropertyName vendorDevicePropertyName = openDDRService.NewPropertyName("vendor", @"http://www.openddr.org/oddr-vocabulary");
            IPropertyRef vendorDeviceRef = openDDRService.NewPropertyRef(vendorDevicePropertyName, "device");

            IPropertyName modelDevicePropertyName = openDDRService.NewPropertyName("model", @"http://www.openddr.org/oddr-vocabulary");
            IPropertyRef modelDeviceRef = openDDRService.NewPropertyRef(modelDevicePropertyName, "device");

            IPropertyName vendorBrowserPropertyName = openDDRService.NewPropertyName("vendor", @"http://www.openddr.org/oddr-vocabulary");
            IPropertyRef vendorBrowserRef = openDDRService.NewPropertyRef(vendorBrowserPropertyName, "webBrowser");

            IPropertyName modelBrowserPropertyName = openDDRService.NewPropertyName("model", @"http://www.openddr.org/oddr-vocabulary");
            IPropertyRef modelBrowserRef = openDDRService.NewPropertyRef(modelBrowserPropertyName, "webBrowser");

            IPropertyRef[] propertyRefs = new IPropertyRef[] { vendorDeviceRef, modelDeviceRef, vendorBrowserRef, modelBrowserRef };

            IEvidence e = new BufferedODDRHTTPEvidence();
            e.Put("User-Agent", userAgent);

            IPropertyValues propertyValues = openDDRService.GetPropertyValues(e, propertyRefs);
            if (propertyValues.GetValue(vendorDeviceRef).Exists())
            {
                Console.WriteLine(propertyValues.GetValue(vendorDeviceRef).GetString());
            }

            if (propertyValues.GetValue(modelDeviceRef).Exists())
            {
                Console.WriteLine(propertyValues.GetValue(modelDeviceRef).GetString());
            }

            if (propertyValues.GetValue(vendorBrowserRef).Exists())
            {
                Console.WriteLine(propertyValues.GetValue(vendorBrowserRef).GetString());
            }

            if (propertyValues.GetValue(modelBrowserRef).Exists())
            {
                Console.WriteLine(propertyValues.GetValue(modelBrowserRef).GetString());
            }

            Console.WriteLine(((BufferedODDRHTTPEvidence) e).deviceFound.Get("is_wireless_device"));

            Console.ReadKey();
        }
Ejemplo n.º 3
0
        public IPropertyRef[] ListPropertyRefs()
        {
            List<IPropertyRef> propertyRefsList = new List<IPropertyRef>();
            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)
                {
                    VocabularyProperty vocabularyProperty = properties[propertyKey];
                    string[] aspects = vocabularyProperty.aspects;
                    IPropertyName propertyName = new ODDRPropertyName(propertyKey, vocabularyKey);
                    for (int i = 0; i < aspects.Length; i++)
                    {
                        IPropertyRef propertyRef = new ODDRPropertyRef(propertyName, aspects[i]);
                        propertyRefsList.Add(propertyRef);
                    }
                }
            }

            IPropertyRef[] propertyRefs = new IPropertyRef[propertyRefsList.Count];
            propertyRefs = propertyRefsList.ToArray();

            return propertyRefs;
        }
Ejemplo n.º 4
0
        /// <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;
        }
Ejemplo n.º 5
0
 /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
 public IPropertyValue GetPropertyValue(IEvidence evdnc, IPropertyRef pr)
 {
     return GetPropertyValues(evdnc, new IPropertyRef[] { pr }).GetValue(pr);
 }
Ejemplo n.º 6
0
		protected void Page_Load(object sender, EventArgs eArgs)
		{
			IService openDDRService = null;
			IPropertyRef[] propertyRefs = null;

			IPropertyName vendorDevicePropertyName = null;
			IPropertyRef vendorDeviceRef = null;

			IPropertyName modelDevicePropertyName = null;
			IPropertyRef modelDeviceRef = null;

			IPropertyName vendorBrowserPropertyName = null;
			IPropertyRef vendorBrowserRef = null;

			IPropertyName modelBrowserPropertyName = null;
			IPropertyRef modelBrowserRef = null;

			string userAgent = Request.UserAgent;

			if (Application["oddr"] == null)
			{
				try
				{
				    var fileSystem = new FileSystem(Path.Combine(HostingEnvironment.ApplicationPhysicalPath,"/resources/"));
                    var props = new Properties(fileSystem,"oddr.properties");

					Type stype = Type.GetType("Oddr.ODDRService, OpenDdr");

					openDDRService = ServiceFactory.newService(stype, props.GetProperty("oddr.vocabulary.device"), props, fileSystem);
					Application["oddr"] = openDDRService;

					vendorDevicePropertyName = openDDRService.NewPropertyName("vendor", @"http://www.openddr.org/oddr-vocabulary");
					vendorDeviceRef = openDDRService.NewPropertyRef(vendorDevicePropertyName, "device");
					Application["vendorDevicePropertyName"] = vendorDevicePropertyName;
					Application["vendorDeviceRef"] = vendorDeviceRef;

					modelDevicePropertyName = openDDRService.NewPropertyName("model", @"http://www.openddr.org/oddr-vocabulary");
					modelDeviceRef = openDDRService.NewPropertyRef(modelDevicePropertyName, "device");
					Application["modelDevicePropertyName"] = modelDevicePropertyName;
					Application["modelDeviceRef"] = modelDeviceRef;

					vendorBrowserPropertyName = openDDRService.NewPropertyName("vendor", @"http://www.openddr.org/oddr-vocabulary");
					vendorBrowserRef = openDDRService.NewPropertyRef(vendorBrowserPropertyName, "webBrowser");
					Application["vendorBrowserPropertyName"] = vendorBrowserPropertyName;
					Application["vendorBrowserRef"] = vendorBrowserRef;

					modelBrowserPropertyName = openDDRService.NewPropertyName("model", @"http://www.openddr.org/oddr-vocabulary");
					modelBrowserRef = openDDRService.NewPropertyRef(modelBrowserPropertyName, "webBrowser");
					Application["modelBrowserPropertyName"] = modelBrowserPropertyName;
					Application["modelBrowserRef"] = modelBrowserRef;

					propertyRefs = new IPropertyRef[] { vendorDeviceRef, modelDeviceRef, vendorBrowserRef, modelBrowserRef };
					Application["propertyRefs"] = propertyRefs;
				}
				catch (Exception exc)
				{
					Output.InnerHtml += "<br />ERROR: " + exc.ToString() + "<br />";
				}
			}

			else
			{
				openDDRService = (IService)Application["oddr"];

				vendorDevicePropertyName = (IPropertyName)Application["vendorDevicePropertyName"];
				vendorDeviceRef = (IPropertyRef)Application["vendorDeviceRef"];

				modelDevicePropertyName = (IPropertyName)Application["modelDevicePropertyName"];
				modelDeviceRef = (IPropertyRef)Application["modelDeviceRef"];

				vendorBrowserPropertyName = (IPropertyName)Application["vendorBrowserPropertyName"];
				vendorBrowserRef = (IPropertyRef)Application["vendorBrowserRef"];

				modelBrowserPropertyName = (IPropertyName)Application["modelBrowserPropertyName"];
				modelBrowserRef = (IPropertyRef)Application["modelBrowserRef"];

				propertyRefs = (IPropertyRef[])Application["propertyRefs"];
			}

			try
			{
				IEvidence e = new BufferedODDRHTTPEvidence();
				e.Put("User-Agent", userAgent);

				IPropertyValues propertyValues = openDDRService.GetPropertyValues(e, propertyRefs);

				if (propertyValues.GetValue(vendorDeviceRef).Exists())
				{
					Output.InnerHtml += "<p>Vendor Device Ref: " + propertyValues.GetValue(vendorDeviceRef).GetString() + "</p>";
				}

				if (propertyValues.GetValue(modelDeviceRef).Exists())
				{
					Output.InnerHtml += "<p>Mobile Device Ref: " + propertyValues.GetValue(modelDeviceRef).GetString() + "</p>";
				}

				if (propertyValues.GetValue(vendorBrowserRef).Exists())
				{
					Output.InnerHtml += "<p>Vendor: " + propertyValues.GetValue(vendorBrowserRef).GetString() + "</p>";
				}

				if (propertyValues.GetValue(modelBrowserRef).Exists())
				{
					Output.InnerHtml += "<p>Model: " + propertyValues.GetValue(modelBrowserRef).GetString() + "</p>";
				}

				Output.InnerHtml += "<p>Dual orientation: " + ((BufferedODDRHTTPEvidence)e).deviceFound.Get("dual_orientation") + "</p>";

				Output.InnerHtml += "<p>Tablet: " + ((BufferedODDRHTTPEvidence)e).deviceFound.Get("is_tablet") + "</p>";

				Output.InnerHtml += "<p>Wireless device: " + ((BufferedODDRHTTPEvidence)e).deviceFound.Get("is_wireless_device") + "</p>";

				Output.InnerHtml += "<p>Mobile browser: " + ((BufferedODDRHTTPEvidence)e).deviceFound.Get("mobile_browser") + "</p>";
			}
			catch (Exception exc)
			{
				Output.InnerHtml += "<br />ERROR2: " + exc.ToString() + "<br />";
			}
		}
Ejemplo n.º 7
0
		protected void Page_Load(object sender, EventArgs eArgs)
		{
			IService openDDRService = null;
			IPropertyRef[] propertyRefs = null;

			IPropertyName vendorDevicePropertyName = null;
			IPropertyRef vendorDeviceRef = null;

			IPropertyName modelDevicePropertyName = null;
			IPropertyRef modelDeviceRef = null;

			IPropertyName vendorBrowserPropertyName = null;
			IPropertyRef vendorBrowserRef = null;

			IPropertyName modelBrowserPropertyName = null;
			IPropertyRef modelBrowserRef = null;

			IPropertyName modelBrowserPropertyVer = null;
			IPropertyRef modelBrowserVer = null;


			string userAgent = Request.UserAgent;

			// IE11 user agent that causes a null value for deviceFound
			// userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; MALC; rv:11.0) like Gecko";

			Output.InnerHtml += "<p>USER AGENT: " + userAgent + "</p>";

			if (Application["oddr"] == null)
			{
				try
				{
					Properties props = new Properties("oddr.properties", "/resources/");

					Type stype = Type.GetType("Oddr.ODDRService, OpenDdr");

					openDDRService = ServiceFactory.newService(stype, props.GetProperty("oddr.vocabulary.device"), props);
					Application["oddr"] = openDDRService;

					vendorDevicePropertyName = openDDRService.NewPropertyName("vendor", @"http://www.openddr.org/oddr-vocabulary");
					vendorDeviceRef = openDDRService.NewPropertyRef(vendorDevicePropertyName, "device");
					Application["vendorDevicePropertyName"] = vendorDevicePropertyName;
					Application["vendorDeviceRef"] = vendorDeviceRef;

					modelDevicePropertyName = openDDRService.NewPropertyName("model", @"http://www.openddr.org/oddr-vocabulary");
					modelDeviceRef = openDDRService.NewPropertyRef(modelDevicePropertyName, "device");
					Application["modelDevicePropertyName"] = modelDevicePropertyName;
					Application["modelDeviceRef"] = modelDeviceRef;

					vendorBrowserPropertyName = openDDRService.NewPropertyName("vendor", @"http://www.openddr.org/oddr-vocabulary");
					vendorBrowserRef = openDDRService.NewPropertyRef(vendorBrowserPropertyName, "webBrowser");
					Application["vendorBrowserPropertyName"] = vendorBrowserPropertyName;
					Application["vendorBrowserRef"] = vendorBrowserRef;

					modelBrowserPropertyName = openDDRService.NewPropertyName("model", @"http://www.openddr.org/oddr-vocabulary");
					modelBrowserRef = openDDRService.NewPropertyRef(modelBrowserPropertyName, "webBrowser");
					Application["modelBrowserPropertyName"] = modelBrowserPropertyName;
					Application["modelBrowserRef"] = modelBrowserRef;

					modelBrowserPropertyVer = openDDRService.NewPropertyName("version", @"http://www.openddr.org/oddr-vocabulary");
					modelBrowserVer = openDDRService.NewPropertyRef(modelBrowserPropertyVer, "webBrowser");
					Application["modelBrowserPropertyVer"] = modelBrowserPropertyVer;
					Application["modelBrowserVer"] = modelBrowserVer;

					propertyRefs = new IPropertyRef[] { vendorDeviceRef, modelDeviceRef, vendorBrowserRef, modelBrowserRef, modelBrowserVer };
					Application["propertyRefs"] = propertyRefs;
				}

				catch (Exception exc)
				{
					Output.InnerHtml += "<br />ERROR: " + exc.ToString() + "<br />";
				}
			}

			else
			{
				openDDRService = (IService)Application["oddr"];

				vendorDevicePropertyName = (IPropertyName)Application["vendorDevicePropertyName"];
				vendorDeviceRef = (IPropertyRef)Application["vendorDeviceRef"];

				modelDevicePropertyName = (IPropertyName)Application["modelDevicePropertyName"];
				modelDeviceRef = (IPropertyRef)Application["modelDeviceRef"];

				vendorBrowserPropertyName = (IPropertyName)Application["vendorBrowserPropertyName"];
				vendorBrowserRef = (IPropertyRef)Application["vendorBrowserRef"];

				modelBrowserPropertyName = (IPropertyName)Application["modelBrowserPropertyName"];
				modelBrowserRef = (IPropertyRef)Application["modelBrowserRef"];

				modelBrowserPropertyVer = (IPropertyName)Application["modelBrowserPropertyVer"];
				modelBrowserVer = (IPropertyRef)Application["modelBrowserVer"];

				propertyRefs = (IPropertyRef[])Application["propertyRefs"];
			}

			try
			{
				IEvidence e = new BufferedODDRHTTPEvidence();
				e.Put("User-Agent", userAgent);

				IPropertyValues propertyValues = openDDRService.GetPropertyValues(e, propertyRefs);

				if (propertyValues.GetValue(vendorDeviceRef).Exists())
				{
					Output.InnerHtml += "<p>Vendor Device Ref: " + propertyValues.GetValue(vendorDeviceRef).GetString() + "</p>";
				}

				if (propertyValues.GetValue(modelDeviceRef).Exists())
				{
					Output.InnerHtml += "<p>Mobile Device Ref: " + propertyValues.GetValue(modelDeviceRef).GetString() + "</p>";
				}

				if (propertyValues.GetValue(vendorBrowserRef).Exists())
				{
					Output.InnerHtml += "<p>Vendor: " + propertyValues.GetValue(vendorBrowserRef).GetString() + "</p>";
				}

				if (propertyValues.GetValue(modelBrowserRef).Exists())
				{
					Output.InnerHtml += "<p>Model: " + propertyValues.GetValue(modelBrowserRef).GetString() + "</p>";
				}

				if (propertyValues.GetValue(modelBrowserVer).Exists())
				{
					Output.InnerHtml += "<p>Version: " + propertyValues.GetValue(modelBrowserVer).GetString() + "</p>";
				}

				if (((BufferedODDRHTTPEvidence)e).deviceFound != null)
				{
					Output.InnerHtml += "<p>Dual orientation: " + ((BufferedODDRHTTPEvidence)e).deviceFound.Get("dual_orientation") + "</p>";

					Output.InnerHtml += "<p>Tablet: " + ((BufferedODDRHTTPEvidence)e).deviceFound.Get("is_tablet") + "</p>";

					Output.InnerHtml += "<p>Wireless device: " + ((BufferedODDRHTTPEvidence)e).deviceFound.Get("is_wireless_device") + "</p>";

					Output.InnerHtml += "<p>Mobile browser: " + ((BufferedODDRHTTPEvidence)e).deviceFound.Get("mobile_browser") + "</p>";
				}
			}

			catch (Exception exc)
			{
				Output.InnerHtml += "<br />ERROR2: " + exc.ToString() + "<br />";
			}
		}
 public ODDRPropertyValue(String value, String type, IPropertyRef propertyRef)
 {
     this.value = value == null ? value : value.Trim();
     this.type = type;
     this.propertyRef = propertyRef;
 }