You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devicemap.apache.org by bd...@apache.org on 2012/10/02 15:34:35 UTC
svn commit: r1392912 [7/8] - in /incubator/devicemap/trunk/openddr/csharp:
./ DDR-Simple-API/ DDR-Simple-API/Exceptions/ DDR-Simple-API/Models/
DDR-Simple-API/Properties/ DDR-Simple-API/Simple/ OpenDDR-CSharp/
OpenDDR-CSharp/Builders/ OpenDDR-CSharp/Bu...
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Models/UserAgentFactory.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Models/UserAgentFactory.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Models/UserAgentFactory.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Models/UserAgentFactory.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,62 @@
+/**
+ * Copyright 2011 OpenDDR LLC
+ * This software is distributed under the terms of the GNU Lesser General Public License.
+ *
+ *
+ * This file is part of OpenDDR Simple APIs.
+ * OpenDDR Simple APIs is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * OpenDDR Simple APIs is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Simple APIs. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using W3c.Ddr.Simple;
+
+namespace Oddr.Models
+{
+ class UserAgentFactory
+ {
+ public static UserAgent newBrowserUserAgent(IEvidence evidence)
+ {
+ return newUserAgent(evidence.Get("user-agent"));
+ }
+
+ public static UserAgent newBrowserUserAgent(Dictionary<String, String> headers)
+ {
+ return newBrowserUserAgent(new ODDRHTTPEvidence(headers));
+ }
+
+ public static UserAgent newDeviceUserAgent(IEvidence evidence)
+ {
+ String ua = evidence.Get("x-device-user-agent");
+ if (ua == null || ua.Trim().Length < 2)
+ {
+ ua = evidence.Get("user-agent");
+ }
+ return newUserAgent(ua);
+ }
+
+ public static UserAgent newDeviceUserAgent(Dictionary<String, String> headers)
+ {
+ return newDeviceUserAgent(new ODDRHTTPEvidence(headers));
+ }
+
+ public static UserAgent newUserAgent(String realUserAgent)
+ {
+ return new UserAgent(realUserAgent);
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Models/Vocabularies/Vocabulary.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Models/Vocabularies/Vocabulary.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Models/Vocabularies/Vocabulary.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Models/Vocabularies/Vocabulary.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,52 @@
+/**
+ * Copyright 2011 OpenDDR LLC
+ * This software is distributed under the terms of the GNU Lesser General Public License.
+ *
+ *
+ * This file is part of OpenDDR Simple APIs.
+ * OpenDDR Simple APIs is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * OpenDDR Simple APIs is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Simple APIs. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Oddr.Models.Vocabularies
+{
+ public class Vocabulary
+ {
+ public String[] aspects
+ {
+ get;
+ set;
+ }
+ public Dictionary<String, VocabularyProperty> properties
+ {
+ get;
+ set;
+ }
+ public Dictionary<String, VocabularyVariable> vocabularyVariables
+ {
+ get;
+ set;
+ }
+ public String vocabularyIRI
+ {
+ get;
+ set;
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Models/Vocabularies/VocabularyProperty.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Models/Vocabularies/VocabularyProperty.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Models/Vocabularies/VocabularyProperty.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Models/Vocabularies/VocabularyProperty.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,54 @@
+/**
+ * Copyright 2011 OpenDDR LLC
+ * This software is distributed under the terms of the GNU Lesser General Public License.
+ *
+ *
+ * This file is part of OpenDDR Simple APIs.
+ * OpenDDR Simple APIs is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * OpenDDR Simple APIs is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Simple APIs. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+using System;
+
+namespace Oddr.Models.Vocabularies
+{
+ public class VocabularyProperty
+ {
+ public String[] aspects
+ {
+ get;
+ set;
+ }
+ public String defaultAspect
+ {
+ get;
+ set;
+ }
+ public String expr
+ {
+ get;
+ set;
+ }
+ public String name
+ {
+ get;
+ set;
+ }
+ public String type
+ {
+ get;
+ set;
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Models/Vocabularies/VocabularyVariable.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Models/Vocabularies/VocabularyVariable.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Models/Vocabularies/VocabularyVariable.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Models/Vocabularies/VocabularyVariable.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,53 @@
+/**
+ * Copyright 2011 OpenDDR LLC
+ * This software is distributed under the terms of the GNU Lesser General Public License.
+ *
+ *
+ * This file is part of OpenDDR Simple APIs.
+ * OpenDDR Simple APIs is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * OpenDDR Simple APIs is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Simple APIs. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Oddr.Models.Vocabularies
+{
+ public class VocabularyVariable
+ {
+ public String aspect
+ {
+ get; set;
+ }
+ public String id
+ {
+ get; set;
+ }
+ public String name
+ {
+ get; set;
+ }
+ public String vocabulary
+ {
+ get; set;
+ }
+
+ public override string ToString()
+ {
+ return "VocabularyVariable {" + " aspect=" + this.aspect + " id=" + this.id + " name=" + this.name + " vocabulary=" + this.vocabulary + '}';
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/ODDRService.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/ODDRService.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/ODDRService.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/ODDRService.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,993 @@
+/**
+ * Copyright 2011 OpenDDR LLC
+ * This software is distributed under the terms of the GNU Lesser General Public License.
+ *
+ *
+ * This file is part of OpenDDR Simple APIs.
+ * OpenDDR Simple APIs is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * OpenDDR Simple APIs is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Simple APIs. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using W3c.Ddr.Simple;
+using Oddr.Identificators;
+using Oddr.Vocabularies;
+using System.Text.RegularExpressions;
+using log4net;
+using W3c.Ddr.Models;
+using W3c.Ddr.Exceptions;
+using System.IO;
+using Oddr.Models.Devices;
+using Oddr.Documenthandlers;
+using Oddr.Builders.Devices;
+using Oddr.Builders;
+using Oddr.Builders.Browsers;
+using Oddr.Builders.OS;
+using Oddr.Models.Browsers;
+using OSModel = Oddr.Models.OS;
+using Oddr.Models;
+using Oddr.Models.Vocabularies;
+
+namespace Oddr
+{
+ /// <summary>
+ /// ODDR Implementation of IService.
+ /// </summary>
+ public class ODDRService : IService
+ {
+ public const String ASPECT_DEVICE = "device";
+ public const String ASPECT_WEB_BROWSER = "webBrowser";
+ public const String ASPECT_OPERATIVE_SYSTEM = "operativeSystem";
+ public const String ASPECT_GROUP = "group";
+ public const String ODDR_UA_DEVICE_BUILDER_PATH_PROP = "oddr.ua.device.builder.path";
+ public const String ODDR_UA_DEVICE_DATASOURCE_PATH_PROP = "oddr.ua.device.datasource.path";
+ public const String ODDR_UA_DEVICE_BUILDER_PATCH_PATHS_PROP = "oddr.ua.device.builder.patch.paths";
+ public const String ODDR_UA_DEVICE_DATASOURCE_PATCH_PATHS_PROP = "oddr.ua.device.datasource.patch.paths";
+ public const String ODDR_UA_BROWSER_DATASOURCE_PATH_PROP = "oddr.ua.browser.datasource.path";
+ public const String ODDR_UA_OPERATINGSYSTEM_DATASOURCE_PATH_PROP = "oddr.ua.operatingSystem.datasource.path";
+ public const String ODDR_UA_DEVICE_BUILDER_STREAM_PROP = "oddr.ua.device.builder.stream";
+ public const String ODDR_UA_DEVICE_DATASOURCE_STREAM_PROP = "oddr.ua.device.datasource.stream";
+ public const String ODDR_UA_DEVICE_BUILDER_PATCH_STREAMS_PROP = "oddr.ua.device.builder.patch.streams";
+ public const String ODDR_UA_DEVICE_DATASOURCE_PATCH_STREAMS_PROP = "oddr.ua.device.datasource.patch.streams";
+ public const String ODDR_UA_BROWSER_DATASOURCE_STREAM_PROP = "oddr.ua.browser.datasource.stream";
+ public const String ODDR_UA_OPERATINGSYSTEM_DATASOURCE_STREAM_PROP = "oddr.ua.operatingSystem.datasource.stream";
+ public const String ODDR_THRESHOLD_PROP = "oddr.threshold";
+ public const String ODDR_VOCABULARY_IRI = "oddr.vocabulary.device";
+ private const String ODDR_API_VERSION = "1.0.0";
+ private const String ODDR_DATA_VERSION = "2012";
+ private const int ODDR_DEFAULT_THRESHOLD = 70;
+ private String defaultVocabularyIRI = null;
+ private DeviceIdentificator deviceIdentificator = null;
+ private BrowserIdentificator browserIdentificator = null;
+ private OSIdentificator osIdentificator = null;
+ private VocabularyHolder vocabularyHolder = null;
+ private int threshold = ODDR_DEFAULT_THRESHOLD;
+ private const String GROUP_REGEXPR = "\\$([^ ]+)";
+ private Regex groupRegexprRegex = new Regex(GROUP_REGEXPR, RegexOptions.Compiled);
+ protected static readonly ILog logger = LogManager.GetLogger(typeof(ODDRService));
+
+
+ public string GetAPIVersion()
+ {
+ return ODDR_API_VERSION;
+ }
+
+ public string GetDataVersion()
+ {
+ return ODDR_DATA_VERSION;
+ }
+
+ /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
+ public IPropertyValue GetPropertyValue(IEvidence evdnc, string localPropertyName, string localAspectName, string vocabularyIRI)
+ {
+ return GetPropertyValue(evdnc, NewPropertyRef(NewPropertyName(localPropertyName, vocabularyIRI), localAspectName));
+ }
+
+ /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
+ public IPropertyValue GetPropertyValue(IEvidence evdnc, string localPropertyName)
+ {
+ return GetPropertyValue(evdnc, NewPropertyName(localPropertyName));
+ }
+
+ /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
+ public IPropertyValue GetPropertyValue(IEvidence evdnc, IPropertyName pn)
+ {
+ return GetPropertyValue(evdnc, NewPropertyRef(pn));
+ }
+
+ /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
+ public IPropertyValue GetPropertyValue(IEvidence evdnc, IPropertyRef pr)
+ {
+ return GetPropertyValues(evdnc, new IPropertyRef[] { pr }).GetValue(pr);
+ }
+
+ /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
+ public IPropertyValues GetPropertyValues(IEvidence evdnc, string localAspectName, string vocabularyIRI)
+ {
+ VocabularyProperty vocabularyProperty = vocabularyHolder.ExistProperty(localAspectName, null, vocabularyIRI, true);
+
+ IPropertyName propertyName = new ODDRPropertyName(localAspectName, vocabularyIRI);
+ IPropertyRef propertyRef = new ODDRPropertyRef(propertyName, vocabularyProperty.defaultAspect);
+
+ return GetPropertyValues(evdnc, new IPropertyRef[] { propertyRef });
+ }
+
+ /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
+ public IPropertyValues GetPropertyValues(IEvidence evdnc, string localAspectName)
+ {
+ return GetPropertyValues(evdnc, localAspectName, defaultVocabularyIRI);
+ }
+
+ /// <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;
+ }
+
+ 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>
+ /// 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;
+ }
+
+ 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;
+ }
+
+ public IEvidence NewHTTPEvidence(Dictionary<string, string> map)
+ {
+ return new ODDRHTTPEvidence(map);
+ }
+
+ public IEvidence NewHTTPEvidence()
+ {
+ return new ODDRHTTPEvidence();
+ }
+
+ /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
+ public IPropertyName NewPropertyName(string localPropertyName, string vocabularyIRI)
+ {
+ vocabularyHolder.ExistProperty(localPropertyName, null, vocabularyIRI, true);
+ return new ODDRPropertyName(localPropertyName, vocabularyIRI);
+ }
+
+ /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
+ public IPropertyName NewPropertyName(string localPropertyName)
+ {
+ return NewPropertyName(localPropertyName, defaultVocabularyIRI);
+ }
+
+ /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
+ public IPropertyRef NewPropertyRef(IPropertyName pn, string localAspectName)
+ {
+ vocabularyHolder.ExistProperty(pn.LocalPropertyName(), localAspectName, pn.Namespace(), true);
+ return new ODDRPropertyRef(pn, localAspectName);
+ }
+
+ /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
+ public IPropertyRef NewPropertyRef(IPropertyName pn)
+ {
+ VocabularyProperty vocabularyProperty = vocabularyHolder.ExistProperty(pn.LocalPropertyName(), null, pn.Namespace(), true);
+ return NewPropertyRef(pn, vocabularyProperty.defaultAspect);
+ }
+
+ /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
+ public IPropertyRef NewPropertyRef(string localPropertyName)
+ {
+ return NewPropertyRef(NewPropertyName(localPropertyName));
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/ODDRVocabularyService.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/ODDRVocabularyService.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/ODDRVocabularyService.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/ODDRVocabularyService.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,228 @@
+/**
+ * Copyright 2011 OpenDDR LLC
+ * This software is distributed under the terms of the GNU Lesser General Public License.
+ *
+ *
+ * This file is part of OpenDDR Simple APIs.
+ * OpenDDR Simple APIs is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * OpenDDR Simple APIs is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Simple APIs. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Oddr.Vocabularies;
+using W3c.Ddr.Models;
+using Oddr.Models.Vocabularies;
+using System.IO;
+using W3c.Ddr.Exceptions;
+using Oddr.Documenthandlers;
+
+namespace Oddr
+{
+ /// <summary>
+ /// The ODDRVocabularyService class is used by ODDRService at initialization time in order to parse the vocabularies xml files and to instantiate the vocabularyHolder.
+ /// </summary>
+ class ODDRVocabularyService
+ {
+ public const String DDR_CORE_VOCABULARY_PATH_PROP = "ddr.vocabulary.core.path";
+ public const String ODDR_VOCABULARY_PATH_PROP = "oddr.vocabulary.path";
+ public const String ODDR_LIMITED_VOCABULARY_PATH_PROP = "oddr.limited.vocabulary.path";
+ public const String DDR_CORE_VOCABULARY_STREAM_PROP = "ddr.vocabulary.core.stream";
+ public const String ODDR_VOCABULARY_STREAM_PROP = "oddr.vocabulary.stream";
+ public const String ODDR_LIMITED_VOCABULARY_STREAM_PROP = "oddr.limited.vocabulary.stream";
+ public const String ODDR_LIMITED_VOCABULARY_IRI = "limitedVocabulary";
+
+ public VocabularyHolder vocabularyHolder
+ {
+ private set;
+ get;
+ }
+
+ /// <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;
+
+ }
+
+ /// <summary>
+ /// Parse a vocabulary from a specified path.
+ /// </summary>
+ /// <param name="prop">The property name in Property class identifying the vocabulary to parse.</param>
+ /// <param name="path">The path of the vocabulary to parse.</param>
+ /// <returns>Return a VocabularyParser containing the parsed vocabulary model.</returns>
+ /// <exception cref="InitializationException">Throws when...</exception>
+ private VocabularyParser ParseVocabularyFromPath(String prop, String path)
+ {
+ VocabularyParser vocabularyParser;
+ FileStream stream = null;
+
+ try
+ {
+ stream = new FileStream(path, FileMode.Open, FileAccess.Read);
+
+ }
+ catch (IOException ex) {
+ throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not open " + prop + " : " + path));
+ }
+
+ try
+ {
+ vocabularyParser = new VocabularyParser(stream);
+
+ }
+ catch (ArgumentNullException ex) {
+ throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new InvalidOperationException("Can not instantiate VocabularyParser(Stream stream)"));
+
+ }
+
+ try
+ {
+ vocabularyParser.Parse();
+
+ }
+ catch (Exception ex) {
+ throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not parse document: " + path));
+ }
+
+ stream.Close();
+ return vocabularyParser;
+ }
+
+ /// <summary>
+ /// Parse a vocabulary from a specified input stream.
+ /// </summary>
+ /// <param name="prop">The property name in Property class identifying the vocabulary to parse.</param>
+ /// <param name="inputStream">The input stream of the vocabulary to parse.</param>
+ /// <returns>Return a VocabularyParser containing the parsed vocabulary model.</returns>
+ /// <exception cref="InitializationException">Throws when...</exception>
+ private VocabularyParser ParseVocabularyFromStream(String prop, Stream inputStream)
+ {
+ VocabularyParser vocabularyParser;
+ try
+ {
+ vocabularyParser = new VocabularyParser(inputStream);
+ }
+ catch (ArgumentNullException ex)
+ {
+ throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new InvalidOperationException("Can not instantiate VocabularyParser(Stream stream)"));
+
+ }
+
+ try
+ {
+ vocabularyParser.Parse();
+
+ }
+ catch (Exception ex) {
+ throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not parse document in property: " + prop));
+
+ }
+
+ inputStream.Close();
+ return vocabularyParser;
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/OpenDDR-CSharp.csproj
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/OpenDDR-CSharp.csproj?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/OpenDDR-CSharp.csproj (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/OpenDDR-CSharp.csproj Tue Oct 2 13:34:31 2012
@@ -0,0 +1,183 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{67A3A231-64F0-49F2-BD02-316995E7A737}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Oddr</RootNamespace>
+ <AssemblyName>OpenDdr</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <TargetFrameworkProfile>
+ </TargetFrameworkProfile>
+ <FileAlignment>512</FileAlignment>
+ <IsWebBootstrapper>false</IsWebBootstrapper>
+ <PublishUrl>publish\</PublishUrl>
+ <Install>true</Install>
+ <InstallFrom>Disk</InstallFrom>
+ <UpdateEnabled>false</UpdateEnabled>
+ <UpdateMode>Foreground</UpdateMode>
+ <UpdateInterval>7</UpdateInterval>
+ <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+ <UpdatePeriodically>false</UpdatePeriodically>
+ <UpdateRequired>false</UpdateRequired>
+ <MapFileExtensions>true</MapFileExtensions>
+ <ApplicationRevision>0</ApplicationRevision>
+ <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+ <UseApplicationTrust>false</UseApplicationTrust>
+ <BootstrapperEnabled>true</BootstrapperEnabled>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup>
+ <StartupObject>
+ </StartupObject>
+ </PropertyGroup>
+ <ItemGroup />
+ <ItemGroup>
+ <Reference Include="log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>lib\log4net.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.XML" />
+ <Reference Include="System.Xml.Linq" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Builders\Browsers\AndroidMobileBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\BlackBerryBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\ChromeBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\ChromeMobileBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\DefaultBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\DolfinBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\FennecBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\FirefoxBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\HintedResolutionBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\IEMobileBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\InternetExplorerBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\JasmineBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\KonquerorBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\LayoutEngineBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\NetFrontBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\NokiaBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\ObigoBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\OpenWaveBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\OperaBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\OperaMiniBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\PolarisBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\SafariBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\SafariMobileBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\SEMCBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\SilkBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\UPBrowserBuilder.cs" />
+ <Compile Include="Builders\Browsers\WebOsBrowserBuilder.cs" />
+ <Compile Include="Builders\Devices\AndroidDeviceBuilder.cs" />
+ <Compile Include="Builders\Devices\IDeviceBuilder.cs" />
+ <Compile Include="Builders\Devices\IOSDeviceBuilder.cs" />
+ <Compile Include="Builders\Devices\OrderedTokenDeviceBuilder.cs" />
+ <Compile Include="Builders\Devices\SimpleDeviceBuilder.cs" />
+ <Compile Include="Builders\Devices\SymbianDeviceBuilder.cs" />
+ <Compile Include="Builders\Devices\TwoStepDeviceBuilder.cs" />
+ <Compile Include="Builders\Devices\WinPhoneDeviceBuilder.cs" />
+ <Compile Include="Builders\IBuilder.cs" />
+ <Compile Include="Builders\OS\BlackBerryOSBuilder.cs" />
+ <Compile Include="Builders\OS\DefaultOSBuilder.cs" />
+ <Compile Include="Builders\OS\MozillaOSModelBuilder.cs" />
+ <Compile Include="Builders\OS\Mozilla\AndroidMozillaSubBuilder.cs" />
+ <Compile Include="Builders\OS\Mozilla\BadaMozillaSubBuilder.cs" />
+ <Compile Include="Builders\OS\Mozilla\BlackBerryMozillaSubBuilder.cs" />
+ <Compile Include="Builders\OS\Mozilla\BrewMozillaSubBuilder.cs" />
+ <Compile Include="Builders\OS\Mozilla\IOSMozillaSubBuilder.cs" />
+ <Compile Include="Builders\OS\Mozilla\LinuxMozillaSubBuilder.cs" />
+ <Compile Include="Builders\OS\Mozilla\MacOSXMozillaSubBuilder.cs" />
+ <Compile Include="Builders\OS\Mozilla\SymbianMozillaSubBuilder.cs" />
+ <Compile Include="Builders\OS\Mozilla\WebOSMozillaSubBuilder.cs" />
+ <Compile Include="Builders\OS\Mozilla\WinCEMozillaSubBuilder.cs" />
+ <Compile Include="Builders\OS\Mozilla\WinPhoneMozillaSubBuilder.cs" />
+ <Compile Include="Builders\OS\OperaOSModelBuilder.cs" />
+ <Compile Include="Caches\Cache.cs" />
+ <Compile Include="Caches\ICache.cs" />
+ <Compile Include="Documenthandlers\BrowserDatasourceParser.cs" />
+ <Compile Include="Documenthandlers\DeviceBuilderParser.cs" />
+ <Compile Include="Documenthandlers\DeviceDatasourceParser.cs" />
+ <Compile Include="Documenthandlers\OperatingSystemDatasourceParser.cs" />
+ <Compile Include="Documenthandlers\VocabularyParser.cs" />
+ <Compile Include="Identificators\BrowserIdentificator.cs" />
+ <Compile Include="Identificators\DeviceIdentificator.cs" />
+ <Compile Include="Identificators\IIdentificator.cs" />
+ <Compile Include="Identificators\OSIdentificator.cs" />
+ <Compile Include="Models\Browsers\Browser.cs" />
+ <Compile Include="Models\BufferedODDRHTTPEvidence.cs" />
+ <Compile Include="Models\BuiltObject.cs" />
+ <Compile Include="Models\Devices\Device.cs" />
+ <Compile Include="Models\ODDRHTTPEvidence.cs" />
+ <Compile Include="Models\ODDRPropertyName.cs" />
+ <Compile Include="Models\ODDRPropertyRef.cs" />
+ <Compile Include="Models\ODDRPropertyValue.cs" />
+ <Compile Include="Models\ODDRPropertyValues.cs" />
+ <Compile Include="Models\OS\OperatingSystem.cs" />
+ <Compile Include="Models\UserAgent.cs" />
+ <Compile Include="Models\UserAgentFactory.cs" />
+ <Compile Include="Models\Vocabularies\Vocabulary.cs" />
+ <Compile Include="Models\Vocabularies\VocabularyProperty.cs" />
+ <Compile Include="Models\Vocabularies\VocabularyVariable.cs" />
+ <Compile Include="ODDRService.cs" />
+ <Compile Include="ODDRVocabularyService.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Vocabularies\VocabularyHolder.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
+ <Visible>False</Visible>
+ <ProductName>Windows Installer 3.1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="oddr.properties" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\DDR-Simple-API\DDR-Simple-API.csproj">
+ <Project>{F802E34F-10F1-4334-9099-3F1579DC4F06}</Project>
+ <Name>DDR-Simple-API</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
\ No newline at end of file
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Properties/AssemblyInfo.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Properties/AssemblyInfo.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Properties/AssemblyInfo.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Properties/AssemblyInfo.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,33 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// Le informazioni generali relative a un assembly sono controllate dal seguente
+// set di attributi. Per modificare le informazioni associate a un assembly
+// occorre quindi modificare i valori di questi attributi.
+[assembly: AssemblyTitle("OpenDDR-CSharp")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("OpenDDR-CSharp")]
+[assembly: AssemblyCopyright("Copyright © 2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Se si imposta ComVisible su false, i tipi in questo assembly non saranno visibili
+// ai componenti COM. Se è necessario accedere a un tipo in questo assembly da
+// COM, impostare su true l'attributo ComVisible per tale tipo.
+[assembly: ComVisible(false)]
+
+// Se il progetto viene esposto a COM, il GUID che segue verrà utilizzato per creare l'ID della libreria dei tipi
+[assembly: Guid("ff8587ff-5965-412f-8ecf-43e780365439")]
+
+// Le informazioni sulla versione di un assembly sono costituite dai seguenti quattro valori:
+//
+// Numero di versione principale
+// Numero di versione secondario
+// Numero build
+// Revisione
+//
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
\ No newline at end of file
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Vocabularies/VocabularyHolder.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Vocabularies/VocabularyHolder.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Vocabularies/VocabularyHolder.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Vocabularies/VocabularyHolder.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,127 @@
+/**
+ * Copyright 2011 OpenDDR LLC
+ * This software is distributed under the terms of the GNU Lesser General Public License.
+ *
+ *
+ * This file is part of OpenDDR Simple APIs.
+ * OpenDDR Simple APIs is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * OpenDDR Simple APIs is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Simple APIs. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Oddr.Caches;
+using Oddr.Models.Vocabularies;
+using W3c.Ddr.Exceptions;
+using System.Diagnostics;
+
+namespace Oddr.Vocabularies
+{
+ public class VocabularyHolder
+ {
+ private Dictionary<String, Vocabulary> vocabularies = null;
+ private ICache vocabularyPropertyCache = new Cache();
+
+ public VocabularyHolder(Dictionary<String, Vocabulary> vocabularies)
+ {
+ this.vocabularies = new Dictionary<string,Vocabulary>(vocabularies);
+ }
+
+ /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
+ public void ExistVocabulary(String vocabularyIRI)
+ {
+ Vocabulary value = null;
+ if (!(vocabularies.TryGetValue(vocabularyIRI, out value)))
+ {
+ throw new NameException(NameException.VOCABULARY_NOT_RECOGNIZED, "unknow \"" + vocabularyIRI + "\" vocabulary");
+ }
+ }
+
+ /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when an aspect or property or vocabulary is not recognized</exception>
+ public VocabularyProperty ExistProperty(String propertyName, String aspect, String vocabularyIRI, bool throwsException)
+ {
+ String realAspect = aspect;
+ VocabularyProperty vocabularyProperty = (VocabularyProperty)vocabularyPropertyCache.GetCachedElement(propertyName + aspect + vocabularyIRI);
+
+ if (vocabularyProperty == null)
+ {
+ Vocabulary vocabulary = new Vocabulary();
+ if (vocabularies.TryGetValue(vocabularyIRI, out vocabulary))
+ {
+ Dictionary<String, VocabularyProperty> propertyMap = vocabulary.properties;
+
+ if (propertyMap.TryGetValue(propertyName, out vocabularyProperty))
+ {
+ if (realAspect != null && realAspect.Trim().Length > 0)
+ {
+ if (vocabularyProperty.aspects.Contains(realAspect))
+ {
+ vocabularyPropertyCache.SetCachedElement(propertyName + aspect + vocabularyIRI, vocabularyProperty);
+ return vocabularyProperty;
+
+ }
+ else
+ {
+ if (throwsException)
+ {
+ throw new NameException(NameException.ASPECT_NOT_RECOGNIZED, "unknow \"" + realAspect + "\" aspect");
+ }
+ return null;
+ }
+
+ }
+ else
+ {
+ return vocabularyProperty;
+ }
+
+ }
+ else
+ {
+ if (throwsException)
+ {
+ throw new NameException(NameException.PROPERTY_NOT_RECOGNIZED, "unknow \"" + propertyName + "\" property");
+ }
+ return null;
+ }
+
+ }
+ else
+ {
+ if (throwsException)
+ {
+ throw new NameException(NameException.VOCABULARY_NOT_RECOGNIZED, "unknow \"" + vocabularyIRI + "\" vacabulary");
+ }
+ return null;
+ }
+
+ }
+ else
+ {
+ return vocabularyProperty;
+ }
+ }
+
+ public VocabularyProperty ExistProperty(String propertyName, String aspect, String vocabularyIRI)
+ {
+ return ExistProperty(propertyName, aspect, vocabularyIRI, false);
+ }
+
+ public Dictionary<String, Vocabulary> GetVocabularies() {
+ return vocabularies;
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/oddr.properties
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/oddr.properties?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/oddr.properties (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/oddr.properties Tue Oct 2 13:34:31 2012
@@ -0,0 +1,11 @@
+oddr.ua.device.builder.path=/FILESYSTEM_PATH_TO_RESOURCES/BuilderDataSource.xml
+oddr.ua.device.datasource.path=/FILESYSTEM_PATH_TO_RESOURCES/DeviceDataSource.xml
+oddr.ua.device.builder.patch.paths=/FILESYSTEM_PATH_TO_RESOURCES/BuilderDataSourcePatch.xml
+oddr.ua.device.datasource.patch.paths=/FILESYSTEM_PATH_TO_RESOURCES/DeviceDataSourcePatch.xml
+oddr.ua.browser.datasource.path=/FILESYSTEM_PATH_TO_RESOURCES/BrowserDataSource.xml
+oddr.ua.operatingSystem.datasource.path=/FILESYSTEM_PATH_TO_RESOURCES/OperatingSystemDataSource.xml
+ddr.vocabulary.core.path=/FILESYSTEM_PATH_TO_RESOURCES/coreVocabulary.xml
+oddr.vocabulary.path=/FILESYSTEM_PATH_TO_RESOURCES/oddrVocabulary.xml
+oddr.limited.vocabulary.path=/FILESYSTEM_PATH_TO_RESOURCES/oddrLimitedVocabulary.xml
+oddr.vocabulary.device=http://www.openddr.org/oddr-vocabulary
+oddr.threshold=70
Propchange: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/oddr.properties
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDRTest/App.config
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDRTest/App.config?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDRTest/App.config (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDRTest/App.config Tue Oct 2 13:34:31 2012
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <configSections>
+ <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
+ </configSections>
+ <log4net>
+ <root>
+ <level value="DEBUG" />
+ <appender-ref ref="ConsoleAppender" />
+ </root>
+ <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
+ <layout type="log4net.Layout.PatternLayout">
+ <conversionPattern value="%date %logger - %message%newline" />
+ </layout>
+ </appender>
+ </log4net>
+</configuration>
\ No newline at end of file
Propchange: incubator/devicemap/trunk/openddr/csharp/OpenDDRTest/App.config
------------------------------------------------------------------------------
svn:eol-style = native