GetProperty() public method

public GetProperty ( String field ) : String
field String
return String
 public OddrDeviceService(IFileProvider fileProvider, string pathToOddrProperties)
 {
     
     var properties = new Properties(fileProvider, pathToOddrProperties);
     _oddrService = new ODDRService(fileProvider);
     var defaultVocabularyIri = properties.GetProperty("oddr.vocabulary.device");
     _oddrService.Initialize(defaultVocabularyIri, properties);
 }
示例#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();
        }
        /// <summary>
        /// Initialize method.
        /// </summary>
        /// <param name="defaultVocabularyIRI"></param>
        /// <param name="prprts"></param>
        public void Initialize(string defaultVocabularyIRI, Properties prprts)
        {
            if (defaultVocabularyIRI == null || defaultVocabularyIRI.Trim().Length == 0)
            {
                throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new NullReferenceException("defaultVocabularyIRI can not be null"));
            }

            /*Initializing VocabularyHolder*/
            ODDRVocabularyService oddrVocabularyService = new ODDRVocabularyService();
            oddrVocabularyService.Initialize(prprts);

            vocabularyHolder = oddrVocabularyService.vocabularyHolder;
            vocabularyHolder.ExistVocabulary(defaultVocabularyIRI);

            String oddrUaDeviceBuilderPath = prprts.GetProperty(ODDR_UA_DEVICE_BUILDER_PATH_PROP);
            String oddrUaDeviceDatasourcePath = prprts.GetProperty(ODDR_UA_DEVICE_DATASOURCE_PATH_PROP);
            String oddrUaDeviceBuilderPatchPaths = prprts.GetProperty(ODDR_UA_DEVICE_BUILDER_PATCH_PATHS_PROP);
            String oddrUaDeviceDatasourcePatchPaths = prprts.GetProperty(ODDR_UA_DEVICE_DATASOURCE_PATCH_PATHS_PROP);
            String oddrUaBrowserDatasourcePaths = prprts.GetProperty(ODDR_UA_BROWSER_DATASOURCE_PATH_PROP);
            String oddrUaOperatingSystemDatasourcePaths = prprts.GetProperty(ODDR_UA_OPERATINGSYSTEM_DATASOURCE_PATH_PROP);

            Stream oddrUaDeviceBuilderStream = null;
            Stream oddrUaDeviceDatasourceStream = null;
            Stream[] oddrUaDeviceBuilderPatchStreams = null;
            Stream[] oddrUaDeviceDatasourcePatchStreams = null;
            Stream oddrUaBrowserDatasourceStream = null;
            Stream oddrUaOperatingSystemDatasourceStream = null;

            try
            {
                oddrUaDeviceBuilderStream = (Stream)prprts.Get(ODDR_UA_DEVICE_BUILDER_STREAM_PROP);
            }
            catch (Exception ex)
            {
                oddrUaDeviceBuilderStream = null;
            }
            try
            {
                oddrUaDeviceDatasourceStream = (Stream)prprts.Get(ODDR_UA_DEVICE_DATASOURCE_STREAM_PROP);
            }
            catch (Exception ex)
            {
                oddrUaDeviceDatasourceStream = null;
            }
            try
            {
                oddrUaDeviceBuilderPatchStreams = (Stream[])prprts.Get(ODDR_UA_DEVICE_BUILDER_PATCH_STREAMS_PROP);
            }
            catch (Exception ex)
            {
                oddrUaDeviceBuilderPatchStreams = null;
            }
            try
            {
                oddrUaDeviceDatasourcePatchStreams = (Stream[])prprts.Get(ODDR_UA_DEVICE_DATASOURCE_PATCH_STREAMS_PROP);
            }
            catch (Exception ex)
            {
                oddrUaDeviceDatasourcePatchStreams = null;
            }
            try
            {
                oddrUaBrowserDatasourceStream = (Stream)prprts.Get(ODDR_UA_BROWSER_DATASOURCE_STREAM_PROP);
            }
            catch (Exception ex)
            {
                oddrUaBrowserDatasourceStream = null;
            }
            try
            {
                oddrUaOperatingSystemDatasourceStream = (Stream)prprts.Get(ODDR_UA_OPERATINGSYSTEM_DATASOURCE_STREAM_PROP);
            }
            catch (Exception ex)
            {
                oddrUaOperatingSystemDatasourceStream = null;
            }

            String oddrThreshold = prprts.GetProperty(ODDR_THRESHOLD_PROP);

            if ((oddrUaDeviceBuilderPath == null || oddrUaDeviceBuilderPath.Trim().Length == 0) && oddrUaDeviceBuilderStream == null)
            {
                throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not find property " + ODDR_UA_DEVICE_BUILDER_PATH_PROP));
            }

            if ((oddrUaDeviceDatasourcePath == null || oddrUaDeviceDatasourcePath.Trim().Length == 0) && oddrUaDeviceDatasourceStream == null)
            {
                throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not find property " + ODDR_UA_DEVICE_DATASOURCE_PATH_PROP));
            }

            String[] oddrUaDeviceBuilderPatchPathArray = null;

            if (oddrUaDeviceBuilderPatchPaths != null && oddrUaDeviceBuilderPatchPaths.Trim().Length != 0)
            {
                oddrUaDeviceBuilderPatchPathArray = oddrUaDeviceBuilderPatchPaths.Split(",".ToCharArray());

            }
            else
            {
                oddrUaDeviceBuilderPatchPathArray = new String[0];
            }

            String[] ooddrUaDeviceDatasourcePatchPathArray = null;

            if (oddrUaDeviceDatasourcePatchPaths != null && oddrUaDeviceDatasourcePatchPaths.Trim().Length != 0)
            {
                ooddrUaDeviceDatasourcePatchPathArray = oddrUaDeviceDatasourcePatchPaths.Split(",".ToCharArray());

            }
            else
            {
                ooddrUaDeviceDatasourcePatchPathArray = new String[0];
            }

            if (oddrUaDeviceBuilderPatchStreams == null)
            {
                oddrUaDeviceBuilderPatchStreams = new Stream[0];
            }

            if (oddrUaDeviceDatasourcePatchStreams == null)
            {
                oddrUaDeviceDatasourcePatchStreams = new Stream[0];
            }

            if ((oddrUaBrowserDatasourcePaths == null || oddrUaBrowserDatasourcePaths.Trim().Length == 0) && oddrUaBrowserDatasourceStream == null)
            {
                throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not find property " + ODDR_UA_BROWSER_DATASOURCE_PATH_PROP));
            }

            if ((oddrUaOperatingSystemDatasourcePaths == null || oddrUaOperatingSystemDatasourcePaths.Trim().Length == 0) && oddrUaOperatingSystemDatasourceStream == null)
            {
                throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not find property " + ODDR_UA_OPERATINGSYSTEM_DATASOURCE_PATH_PROP));
            }

            if (oddrThreshold == null || oddrThreshold.Trim().Length == 0)
            {
                this.threshold = ODDR_DEFAULT_THRESHOLD;

            }
            else
            {
                try
                {
                    this.threshold = int.Parse(oddrThreshold);
                    if (this.threshold <= 0)
                    {
                        this.threshold = ODDR_DEFAULT_THRESHOLD;
                    }

                }
                catch (FormatException x)
                {
                    this.threshold = ODDR_DEFAULT_THRESHOLD;
                }
            }

            Dictionary<String, Device> devices = new Dictionary<String, Device>();

            Stream stream = null;

            try
            {
                if (oddrUaDeviceDatasourceStream != null)
                {
                    stream = oddrUaDeviceDatasourceStream;
                }
                else
                {
                    stream = new FileStream(oddrUaDeviceDatasourcePath, FileMode.Open);
                }

            }
            catch (IOException ex)
            {
                throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not open " + ODDR_UA_DEVICE_DATASOURCE_PATH_PROP + " " + oddrUaDeviceDatasourcePath));
            }

            /// TODO: Check stream. If stream is null DeviceDataSourceParser throws ArgumentNullException
            DeviceDatasourceParser deviceDatasourceParser = new DeviceDatasourceParser(stream, devices, vocabularyHolder);

            try
            {
                deviceDatasourceParser.Parse();
            }
            catch (Exception ex)
            {
                throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not parse " + ODDR_UA_DEVICE_DATASOURCE_PATH_PROP + " :" + oddrUaDeviceDatasourcePath));
            }

            try
            {
                stream.Close();
            }
            catch (IOException ex)
            {
                logger.Warn("", ex);
            }

            deviceDatasourceParser.patching = true;

            if (oddrUaDeviceDatasourcePatchStreams != null && oddrUaDeviceDatasourcePatchStreams.Length != 0)
            {
                for (int i = 0; i < oddrUaDeviceDatasourcePatchStreams.Length; i++)
                {
                    stream = oddrUaDeviceDatasourcePatchStreams[i];

                    try
                    {
                        deviceDatasourceParser.SetStream(stream);
                        deviceDatasourceParser.Parse();

                    }
                    catch (ArgumentNullException ane)
                    {
                        throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not open DeviceDatasource input stream " + i));
                    }
                    catch (Exception ex)
                    {
                        throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not parse DeviceDatasource input stream " + i));
                    }

                    try
                    {
                        stream.Close();

                    }
                    catch (IOException ex)
                    {
                        logger.Warn("", ex);
                    }
                }
            }
            else
            {
                for (int i = 0; i < ooddrUaDeviceDatasourcePatchPathArray.Length; i++)
                {
                    try
                    {
                        stream = new FileStream(ooddrUaDeviceDatasourcePatchPathArray[i], FileMode.Open);
                    }
                    catch (IOException ex)
                    {
                        throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not open " + ODDR_UA_DEVICE_DATASOURCE_PATH_PROP + " " + ooddrUaDeviceDatasourcePatchPathArray[i]));
                    }

                    try
                    {
                        deviceDatasourceParser.SetStream(stream);
                        deviceDatasourceParser.Parse();
                    }
                    catch (ArgumentNullException ane)
                    {
                        throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not open " + ODDR_UA_DEVICE_DATASOURCE_PATH_PROP + " :" + ooddrUaDeviceDatasourcePatchPathArray[i]));
                    }
                    catch (Exception ex)
                    {
                        throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not parse document: " + ooddrUaDeviceDatasourcePatchPathArray[i]));
                    }

                    try
                    {
                        stream.Close();
                    }
                    catch (IOException ex)
                    {
                        logger.Warn("", ex);
                    }
                }

            }

            List<IDeviceBuilder> builders = new List<IDeviceBuilder>();

            try
            {
                if (oddrUaDeviceBuilderStream != null)
                {
                    stream = oddrUaDeviceBuilderStream;
                }
                else
                {
                    stream = new FileStream(oddrUaDeviceBuilderPath, FileMode.Open);
                }

            }
            catch (IOException ex)
            {
                throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not open " + ODDR_UA_DEVICE_BUILDER_PATH_PROP + " " + oddrUaDeviceBuilderPath));
            }

            /// TODO: Check stream. If stream is null DeviceBuilderParser throws ArgumentNullException
            DeviceBuilderParser deviceBuilderParser = new DeviceBuilderParser(stream, builders);

            try
            {
                deviceBuilderParser.Parse();
            }
            catch (Exception ex)
            {
                throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not parse " + ODDR_UA_DEVICE_DATASOURCE_PATH_PROP + " :" + oddrUaDeviceBuilderPath));
            }

            try
            {
                stream.Close();

            }
            catch (IOException ex)
            {
                logger.Warn("", ex);
            }

            if (oddrUaDeviceBuilderPatchStreams != null && oddrUaDeviceBuilderPatchStreams.Length != 0)
            {
                for (int i = 0; i < oddrUaDeviceBuilderPatchStreams.Length; i++)
                {
                    stream = oddrUaDeviceBuilderPatchStreams[i];

                    try
                    {
                        deviceBuilderParser.SetStream(stream);
                        deviceBuilderParser.Parse();

                    }
                    catch (ArgumentNullException ane)
                    {
                        throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not open DeviceBuilder input stream " + i));
                    }
                    catch (Exception ex)
                    {
                        throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not parse DeviceBuilder input stream " + i));
                    }

                    try
                    {
                        stream.Close();
                    }
                    catch (IOException ex)
                    {
                        logger.Warn("", ex);
                    }
                }

            }
            else
            {
                for (int i = 0; i < oddrUaDeviceBuilderPatchPathArray.Length; i++)
                {
                    try
                    {
                        stream = new FileStream(oddrUaDeviceBuilderPatchPathArray[i], FileMode.Open);

                    }
                    catch (IOException ex)
                    {
                        throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not open " + ODDR_UA_DEVICE_BUILDER_PATCH_PATHS_PROP + " " + oddrUaDeviceBuilderPatchPathArray[i]));
                    }

                    try
                    {
                        deviceBuilderParser.SetStream(stream);
                        deviceBuilderParser.Parse();
                    }
                    catch (ArgumentNullException ane)
                    {
                        throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not open " + ODDR_UA_DEVICE_DATASOURCE_PATH_PROP + " :" + oddrUaDeviceBuilderPatchPathArray[i]));
                    }
                    catch (Exception ex)
                    {
                        throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not parse document: " + oddrUaDeviceBuilderPatchPathArray[i]));
                    }

                    try
                    {
                        stream.Close();

                    }
                    catch (IOException ex)
                    {
                        logger.Warn("", ex);
                    }
                }
            }

            try
            {
                if (oddrUaBrowserDatasourceStream != null)
                {
                    stream = oddrUaBrowserDatasourceStream;
                }
                else
                {
                    stream = new FileStream(oddrUaBrowserDatasourcePaths, FileMode.Open);
                }

            }
            catch (IOException ex)
            {
                throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not open " + ODDR_UA_BROWSER_DATASOURCE_PATH_PROP + " " + oddrUaBrowserDatasourcePaths));
            }

            /// TODO: Check stream. If stream is null BrowserDatasourceParser throws ArgumentNullException
            BrowserDatasourceParser browserDatasourceParser = new BrowserDatasourceParser(stream, vocabularyHolder);

            try
            {
                browserDatasourceParser.Parse();
            }
            catch (Exception ex)
            {
                throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not parse document: " + oddrUaBrowserDatasourcePaths));
            }

            try
            {
                stream.Close();
            }
            catch (IOException ex)
            {
                logger.Warn("", ex);
            }

            try
            {
                if (oddrUaOperatingSystemDatasourceStream != null)
                {
                    stream = oddrUaOperatingSystemDatasourceStream;
                }
                else
                {
                    stream = new FileStream(oddrUaOperatingSystemDatasourcePaths, FileMode.Open);
                }

            }
            catch (IOException ex)
            {
                throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not open " + ODDR_UA_OPERATINGSYSTEM_DATASOURCE_PATH_PROP + " " + oddrUaOperatingSystemDatasourcePaths));
            }

            /// TODO: Check stream. If stream is null OperatingSystemDatasourceParser throws ArgumentNullException
            OperatingSystemDatasourceParser operatingSystemDatasourceParser = new OperatingSystemDatasourceParser(stream, vocabularyHolder);

            try
            {
                operatingSystemDatasourceParser.Parse();

            }
            catch (Exception ex)
            {
                throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not parse document: " + oddrUaOperatingSystemDatasourcePaths));

            }

            try
            {
                stream.Close();

            }
            catch (IOException ex)
            {
                logger.Warn("", ex);
            }

            deviceIdentificator = new DeviceIdentificator(deviceBuilderParser.DeviceBuilders(), deviceDatasourceParser.devices);
            deviceIdentificator.CompleteInit();

            Dictionary<string, Browser> browsers = new Dictionary<string, Browser>(browserDatasourceParser.browsers);
            browserIdentificator = new BrowserIdentificator(new IBuilder[] { DefaultBrowserBuilder.Instance }, browsers);
            browserIdentificator.CompleteInit();

            Dictionary<string, OSModel.OperatingSystem> operatingSystems = new Dictionary<string, OSModel.OperatingSystem>(operatingSystemDatasourceParser.operatingSystems);
            osIdentificator = new OSIdentificator(new IBuilder[] { DefaultOSBuilder.Instance }, operatingSystems);
            osIdentificator.CompleteInit();

            deviceDatasourceParser = null;
            deviceBuilderParser = null;
            browserDatasourceParser = null;
            operatingSystemDatasourceParser = null;

            this.defaultVocabularyIRI = defaultVocabularyIRI;

            oddrVocabularyService = null;

            return;
        }
        /// <summary>
        /// Initialization funcion. It is called by ODDRService at initialization time in order to populate vocabulary holder.
        /// </summary>
        /// <param name="props">Properties object holding the configuration properties.</param>
        /// <exception cref="InitializationException">Throws when...</exception>
        public void Initialize(Properties props)
        {
            Dictionary<String, Vocabulary> vocabularies = new Dictionary<String, Vocabulary>();

            String ddrCoreVocabularyPath = props.GetProperty(DDR_CORE_VOCABULARY_PATH_PROP);
            String oddrVocabularyPath = props.GetProperty(ODDR_VOCABULARY_PATH_PROP);

            Stream ddrCoreVocabulayStream = null;
            Stream[] oddrVocabularyStream = null;
            try {
                ddrCoreVocabulayStream = props.Get(DDR_CORE_VOCABULARY_STREAM_PROP) as Stream;
            } catch (Exception ex) {
                ddrCoreVocabulayStream = null;
            }
            try {
                oddrVocabularyStream = props.Get(ODDR_VOCABULARY_STREAM_PROP) as Stream[];
            } catch (Exception ex) {
                oddrVocabularyStream = null;
            }

            if ((string.IsNullOrEmpty(ddrCoreVocabularyPath)) && ddrCoreVocabulayStream == null) {
                throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not find property " + DDR_CORE_VOCABULARY_PATH_PROP));
            }

            if ((string.IsNullOrEmpty(oddrVocabularyPath)) && oddrVocabularyStream == null) {
                throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not find property " + ODDR_VOCABULARY_PATH_PROP));
            }

            VocabularyParser vocabularyParser = null;
            Vocabulary vocabulary = null;

            if (ddrCoreVocabulayStream != null)
            {
                vocabularyParser = ParseVocabularyFromStream(DDR_CORE_VOCABULARY_STREAM_PROP, ddrCoreVocabulayStream);
            }
            else
            {
                vocabularyParser = ParseVocabularyFromPath(DDR_CORE_VOCABULARY_PATH_PROP, ddrCoreVocabularyPath);
            }
            vocabulary = vocabularyParser.vocabulary;
            vocabularies.Add(vocabulary.vocabularyIRI, vocabulary);

            if (oddrVocabularyStream != null)
            {
                foreach (Stream stream in oddrVocabularyStream)
                {
                    vocabularyParser = ParseVocabularyFromStream(ODDR_VOCABULARY_STREAM_PROP, stream);
                    vocabulary = vocabularyParser.vocabulary;
                    vocabularies.Add(vocabulary.vocabularyIRI, vocabulary);
                }
            }
            else
            {
                String[] oddrVocabularyPaths = oddrVocabularyPath.Split(",".ToCharArray());
                foreach (string p in oddrVocabularyPaths)
                {
                    p.Trim();
                }

                foreach (String oddVocabularyString in oddrVocabularyPaths)
                {
                    vocabularyParser = ParseVocabularyFromPath(ODDR_VOCABULARY_PATH_PROP, oddVocabularyString);
                    vocabulary = vocabularyParser.vocabulary;
                    vocabularies.Add(vocabulary.vocabularyIRI, vocabulary);
                }
            }

            String oddrLimitedVocabularyPath = props.GetProperty(ODDR_LIMITED_VOCABULARY_PATH_PROP);
            Stream oddrLimitedVocabularyStream = props.Get(ODDR_LIMITED_VOCABULARY_STREAM_PROP) as Stream;

            if (oddrLimitedVocabularyStream != null) {
                vocabularyParser = ParseVocabularyFromStream(ODDR_LIMITED_VOCABULARY_STREAM_PROP, oddrLimitedVocabularyStream);
                vocabulary = vocabularyParser.vocabulary;
                vocabularies.Add(ODDR_LIMITED_VOCABULARY_IRI, vocabulary);
            } else {
               if (!string.IsNullOrEmpty(oddrLimitedVocabularyPath)) {
                   vocabularyParser = ParseVocabularyFromPath(ODDR_LIMITED_VOCABULARY_PATH_PROP, oddrLimitedVocabularyPath);
                   vocabulary = vocabularyParser.vocabulary;
                   vocabularies.Add(ODDR_LIMITED_VOCABULARY_IRI, vocabulary);
                }
            }
            //vocabulary = vocabularyParser.vocabulary;
            //vocabularies.Add(ODDR_LIMITED_VOCABULARY_IRI, vocabulary);

            vocabularyHolder = new VocabularyHolder(vocabularies);

            vocabularyParser = null;
            vocabularies = null;
        }
		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 />";
			}
		}
示例#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;

			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 />";
			}
		}