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 [5/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/Builders/OS/Mozilla/BlackBerryMozillaSubBuilder.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/BlackBerryMozillaSubBuilder.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/BlackBerryMozillaSubBuilder.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/BlackBerryMozillaSubBuilder.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,181 @@
+/**
+ * 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.Models;
+using System.Text.RegularExpressions;
+using OSModel = Oddr.Models.OS;
+
+namespace Oddr.Builders.OS.Mozilla
+{
+ public class BlackBerryMozillaSubBuilder : IBuilder
+ {
+ private const String VERSION_REGEXP = "(?:.*?Version.?((\\d+)\\.(\\d+)(?:\\.(\\d+))?(?:\\.(\\d+))?).*)|(?:.*?[Bb]lack.?[Bb]erry(?:\\d+)/((\\d+)\\.(\\d+)(?:\\.(\\d+))?(?:\\.(\\d+))?).*)|(?:.*?RIM.?Tablet.?OS.?((\\d+)\\.(\\d+)(?:\\.(\\d+))?(?:\\.(\\d+))?).*)";
+ private Regex versionRegex = new Regex(VERSION_REGEXP);
+
+ public bool CanBuild(UserAgent userAgent)
+ {
+ return userAgent.containsBlackBerryOrRim;
+ }
+
+ public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
+ {
+ OSModel.OperatingSystem model = new OSModel.OperatingSystem();
+
+ String rebuilded = userAgent.GetPatternElementsInside() + ";" + userAgent.GetPatternElementsPost();
+
+ String[] splittedTokens = rebuilded.Split(";".ToCharArray());
+ foreach (String tokenElement in splittedTokens)
+ {
+ if (versionRegex.IsMatch(tokenElement))
+ {
+ Match versionMatcher = versionRegex.Match(tokenElement);
+ GroupCollection groups = versionMatcher.Groups;
+
+ if (groups[11].Value != null && groups[11].Value.Trim().Length > 0)
+ {
+ model.SetVendor("Research In Motion");
+ model.SetModel("RIM Tablet OS");
+ model.majorRevision = "1";
+ model.confidence = 50;
+
+ if (groups[11].Value != null && groups[11].Value.Trim().Length > 0)
+ {
+ model.SetVersion(groups[11].Value);
+
+ }
+
+ if (groups[12].Value != null && groups[12].Value.Trim().Length > 0)
+ {
+ model.majorRevision = groups[12].Value;
+ model.confidence = 60;
+
+ }
+
+ if (groups[13].Value != null && groups[13].Value.Trim().Length > 0)
+ {
+ model.minorRevision = groups[13].Value;
+ model.confidence = 70;
+
+ }
+
+ if (groups[14].Value != null && groups[14].Value.Trim().Length > 0)
+ {
+ model.microRevision = groups[14].Value;
+ model.confidence = 80;
+
+ }
+
+ if (groups[15].Value != null && groups[15].Value.Trim().Length > 0)
+ {
+ model.nanoRevision = groups[15].Value;
+ model.confidence = 90;
+
+ }
+ return model;
+
+ }
+ else if ((groups[1] != null && groups[1].Value.Trim().Length > 0) || (groups[6] != null && groups[6].Value.Trim().Length > 0))
+ {
+ model.SetVendor("Research In Motion");
+ model.SetModel("Black Berry OS");
+ model.majorRevision = "1";
+ model.confidence = 40;
+
+ if (groups[1] != null && groups[1].Value.Trim().Length > 0)
+ {
+ if (groups[6] != null && groups[6].Value.Trim().Length > 0)
+ {
+ model.confidence = 100;
+
+ }
+ else
+ {
+ model.confidence = 80;
+ }
+
+ }
+ else if (groups[6] != null && groups[6].Value.Trim().Length > 0)
+ {
+ model.confidence = 90;
+ }
+
+ if (groups[1] != null && groups[1].Value.Trim().Length > 0)
+ {
+ model.SetVersion(groups[1].Value);
+
+ }
+ else if (groups[6] != null && groups[6].Value.Trim().Length > 0)
+ {
+ model.SetVersion(groups[6].Value);
+ }
+
+ if (groups[2] != null && groups[2].Value.Trim().Length > 0)
+ {
+ model.majorRevision = groups[2].Value;
+
+ }
+ else if (groups[7] != null && groups[7].Value.Trim().Length > 0)
+ {
+ model.majorRevision = groups[7].Value;
+ }
+
+ if (groups[3] != null && groups[3].Value.Trim().Length > 0)
+ {
+ model.minorRevision = groups[3].Value;
+
+ }
+ else if (groups[8] != null && groups[8].Value.Trim().Length > 0)
+ {
+ model.minorRevision = groups[8].Value;
+ }
+
+ if (groups[4] != null && groups[4].Value.Trim().Length > 0)
+ {
+ model.microRevision = groups[4].Value;
+
+ }
+ else if (groups[9] != null && groups[9].Value.Trim().Length > 0)
+ {
+ model.microRevision = groups[9].Value;
+ }
+
+ if (groups[5] != null && groups[5].Value.Trim().Length > 0)
+ {
+ model.nanoRevision = groups[5].Value;
+
+ }
+ else if (groups[10] != null && groups[10].Value.Trim().Length > 0)
+ {
+ model.nanoRevision = groups[10].Value;
+ }
+ return model;
+
+ }
+ }
+ }
+ return model;
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/BrewMozillaSubBuilder.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/BrewMozillaSubBuilder.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/BrewMozillaSubBuilder.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/BrewMozillaSubBuilder.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,86 @@
+/**
+ * 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 System.Text.RegularExpressions;
+using Oddr.Models;
+using OSModel = Oddr.Models.OS;
+
+namespace Oddr.Builders.OS.Mozilla
+{
+ public class BrewMozillaSubBuilder : IBuilder
+ {
+ private const String VERSION_REGEXP = ".*?(?:(?:Brew|BREW).?(?:MP)?).((\\d+)\\.(\\d+)(?:\\.(\\d+))?(?:\\.(\\d+))?(.*))";
+ private Regex versionRegex = new Regex(VERSION_REGEXP);
+
+ public bool CanBuild(UserAgent userAgent)
+ {
+ Regex brewRegex = new Regex(/*"(?i).*brew.*"*/".*brew.*", RegexOptions.IgnoreCase);
+ return (userAgent.GetPatternElementsInside() != null && brewRegex.IsMatch(userAgent.GetPatternElementsInside()));
+ }
+
+ public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
+ {
+ OSModel.OperatingSystem model = new OSModel.OperatingSystem();
+ model.majorRevision = "1";
+ model.SetVendor("Qualcomm");
+ model.SetModel("Brew");
+ model.confidence = 40;
+
+ string patternElementInside = userAgent.GetPatternElementsInside();
+ String[] splittedTokens = patternElementInside.Split(";".ToCharArray());
+ foreach (String tokenElement in splittedTokens)
+ {
+ if (versionRegex.IsMatch(tokenElement))
+ {
+ Match versionMatcher = versionRegex.Match(tokenElement);
+ GroupCollection groups = versionMatcher.Groups;
+
+ model.confidence = 90;
+ if (groups[1] != null && groups[1].Value.Trim().Length > 0)
+ {
+ model.SetVersion(groups[1].Value);
+ }
+ if (groups[2] != null && groups[2].Value.Trim().Length > 0)
+ {
+ model.majorRevision = groups[2].Value;
+ }
+ if (groups[3] != null && groups[3].Value.Trim().Length > 0)
+ {
+ model.minorRevision = groups[3].Value;
+ }
+ if (groups[4] != null && groups[4].Value.Trim().Length > 0)
+ {
+ model.microRevision = groups[4].Value;
+ }
+ if (groups[5] != null && groups[5].Value.Trim().Length > 0)
+ {
+ model.nanoRevision = groups[5].Value;
+ }
+ }
+ }
+ return model;
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/IOSMozillaSubBuilder.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/IOSMozillaSubBuilder.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/IOSMozillaSubBuilder.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/IOSMozillaSubBuilder.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,82 @@
+/**
+ * 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 System.Text.RegularExpressions;
+using Oddr.Models;
+using OSModel = Oddr.Models.OS;
+
+namespace Oddr.Builders.OS.Mozilla
+{
+ public class IOSMozillaSubBuilder : IBuilder
+ {
+ private const String VERSION_REGEXP = ".*(?:iPhone)?.?OS.?((\\d+)_(\\d+)(?:_(\\d+))?).*";
+ private Regex versionRegex = new Regex(VERSION_REGEXP);
+
+ public bool CanBuild(UserAgent userAgent)
+ {
+ return userAgent.containsIOSDevices;
+ }
+
+ public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
+ {
+ OSModel.OperatingSystem model = new OSModel.OperatingSystem();
+ model.majorRevision = "1";
+ model.SetVendor("Apple");
+ model.SetModel("iOS");
+ model.confidence = 40;
+
+ string patternElementsInside = userAgent.GetPatternElementsInside();
+ String[] splittedTokens = patternElementsInside.Split(";".ToCharArray());
+ foreach (String tokenElement in splittedTokens)
+ {
+ if (versionRegex.IsMatch(tokenElement))
+ {
+ Match versionMatcher = versionRegex.Match(tokenElement);
+ GroupCollection groups = versionMatcher.Groups;
+
+ model.confidence = 90;
+
+ if (groups[1] != null && groups[1].Value.Trim().Length > 0)
+ {
+ model.SetVersion(groups[1].Value);
+ }
+ if (groups[2] != null && groups[2].Value.Trim().Length > 0)
+ {
+ model.majorRevision = groups[2].Value;
+ }
+ if (groups[3] != null && groups[3].Value.Trim().Length > 0)
+ {
+ model.minorRevision = groups[3].Value;
+ }
+ if (groups[4] != null && groups[4].Value.Trim().Length > 0)
+ {
+ model.microRevision = groups[4].Value;
+ }
+ }
+ }
+ return model;
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/LinuxMozillaSubBuilder.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/LinuxMozillaSubBuilder.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/LinuxMozillaSubBuilder.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/LinuxMozillaSubBuilder.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,72 @@
+/**
+ * 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 System.Text.RegularExpressions;
+using Oddr.Models;
+using OSModel = Oddr.Models.OS;
+
+namespace Oddr.Builders.OS.Mozilla
+{
+ public class LinuxMozillaSubBuilder : IBuilder
+ {
+ private const String DESCRIPTION_REGEXP = ".*(X11;)?.*?Linux[^;]?([^;]*)?;.*";
+ private Regex descriptionRegex = new Regex(DESCRIPTION_REGEXP);
+
+ public bool CanBuild(UserAgent userAgent)
+ {
+ return (userAgent.completeUserAgent.Contains("Linux") && !userAgent.completeUserAgent.Contains("Android"));
+ }
+
+ public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
+ {
+ OSModel.OperatingSystem model = new OSModel.OperatingSystem();
+ model.majorRevision = "-";
+ model.SetVendor("-");
+ model.SetModel("Linux");
+
+ int confidence = 60;
+
+ if (descriptionRegex.IsMatch(userAgent.GetPatternElementsInside()))
+ {
+ Match descriptionMatcher = descriptionRegex.Match(userAgent.GetPatternElementsInside());
+ GroupCollection groups = descriptionMatcher.Groups;
+
+ if (groups[1] != null && groups[1].Value.Trim().Length > 0)
+ {
+ confidence += 10;
+ }
+ if (groups[2] != null && groups[2].Value.Trim().Length > 0)
+ {
+ model.SetDescription(groups[2].Value);
+ confidence += 10;
+ }
+ }
+
+ model.confidence = confidence;
+
+ return model;
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/MacOSXMozillaSubBuilder.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/MacOSXMozillaSubBuilder.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/MacOSXMozillaSubBuilder.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/MacOSXMozillaSubBuilder.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,82 @@
+/**
+ * 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 System.Text.RegularExpressions;
+using Oddr.Models;
+using OSModel = Oddr.Models.OS;
+
+namespace Oddr.Builders.OS.Mozilla
+{
+ public class MacOSXMozillaSubBuilder : IBuilder
+ {
+ private const String VERSION_REGEXP = ".*(?:(?:Intel)|(?:PPC)).?Mac OS X.?((\\d+)[_\\.](\\d+)(?:[_\\.](\\d+))?).*";
+ private Regex versionRegex = new Regex(VERSION_REGEXP);
+
+
+ public bool CanBuild(UserAgent userAgent)
+ {
+ return userAgent.completeUserAgent.Contains("Macintosh");
+ }
+
+ public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
+ {
+ OSModel.OperatingSystem model = new OSModel.OperatingSystem();
+ model.majorRevision = "-";
+ model.SetVendor("Apple");
+ model.SetModel("Mac OS X");
+
+ int confidence = 60;
+
+ if (versionRegex.IsMatch(userAgent.GetPatternElementsInside()))
+ {
+ Match versionMatcher = versionRegex.Match(userAgent.GetPatternElementsInside());
+ GroupCollection groups = versionMatcher.Groups;
+
+ model.confidence = 80;
+
+ if (groups[1] != null && groups[1].Value.Trim().Length > 0)
+ {
+ model.SetVersion(groups[1].Value);
+ }
+ if (groups[2] != null && groups[2].Value.Trim().Length > 0)
+ {
+ model.majorRevision = groups[2].Value;
+ }
+ if (groups[3] != null && groups[3].Value.Trim().Length > 0)
+ {
+ model.minorRevision = groups[3].Value;
+ }
+ if (groups[4] != null && groups[4].Value.Trim().Length > 0)
+ {
+ model.microRevision = groups[4].Value;
+ }
+ }
+
+ model.confidence = confidence;
+
+ return model;
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/SymbianMozillaSubBuilder.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/SymbianMozillaSubBuilder.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/SymbianMozillaSubBuilder.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/SymbianMozillaSubBuilder.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,112 @@
+/**
+ * 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 System.Text.RegularExpressions;
+using OSModel = Oddr.Models.OS;
+using Oddr.Models;
+
+namespace Oddr.Builders.OS.Mozilla
+{
+ public class SymbianMozillaSubBuilder : IBuilder
+ {
+ private const String VERSION_REGEXP = ".*Series.?60/(\\d+)(?:[\\.\\- ](\\d+))?(?:[\\.\\- ](\\d+))?.*";
+ private const String VERSION_EXTRA = ".*Symbian(?:OS)?/(.*)";
+ private Regex versionRegex = new Regex(VERSION_REGEXP);
+ private Regex versionExtraRegex = new Regex(VERSION_EXTRA);
+
+ public bool CanBuild(UserAgent userAgent)
+ {
+ return userAgent.containsSymbian;
+ }
+
+ public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
+ {
+ OSModel.OperatingSystem model = new OSModel.OperatingSystem();
+ model.majorRevision = "1";
+ model.SetVendor("Nokia");
+ model.SetModel("Symbian OS");
+ model.confidence = 40;
+
+ string patternElementsInside = userAgent.GetPatternElementsInside();
+ String[] splittedTokens = patternElementsInside.Split(";".ToCharArray());
+ foreach (String tokenElement in splittedTokens)
+ {
+ if (versionRegex.IsMatch(tokenElement))
+ {
+ Match versionMatcher = versionRegex.Match(tokenElement);
+ GroupCollection groups = versionMatcher.Groups;
+
+ model.SetDescription("Series60");
+ if (model.confidence > 40)
+ {
+ model.confidence = 100;
+
+ }
+ else
+ {
+ model.confidence = 90;
+ }
+
+ if (groups[1] != null && groups[1].Value.Trim().Length > 0)
+ {
+ model.majorRevision = groups[1].Value;
+ }
+ if (groups[2] != null && groups[2].Value.Trim().Length > 0)
+ {
+ model.minorRevision = groups[2].Value;
+ }
+ if (groups[3] != null && groups[3].Value.Trim().Length > 0)
+ {
+ model.microRevision = groups[3].Value;
+ }
+ }
+
+ if (versionExtraRegex.IsMatch(tokenElement))
+ {
+ Match versionExtraMatcher = versionExtraRegex.Match(tokenElement);
+ GroupCollection groups = versionExtraMatcher.Groups;
+
+ if (model.confidence > 40)
+ {
+ model.confidence = 100;
+
+ }
+ else
+ {
+ model.confidence = 85;
+ }
+
+ if (groups[1] != null && groups[1].Value.Trim().Length > 0)
+ {
+ string groupValueTrimmed = groups[1].Value.Trim();
+ model.SetVersion(groupValueTrimmed);
+ }
+ }
+ //TODO: inference VERSION_EXTRA/VERSION_REGEXP and vice-versa
+ }
+ return model;
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/WebOSMozillaSubBuilder.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/WebOSMozillaSubBuilder.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/WebOSMozillaSubBuilder.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/WebOSMozillaSubBuilder.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,86 @@
+/**
+ * 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 System.Text.RegularExpressions;
+using Oddr.Models;
+using OSModel = Oddr.Models.OS;
+
+namespace Oddr.Builders.OS.Mozilla
+{
+ public class WebOSMozillaSubBuilder : IBuilder
+ {
+ private const String VERSION_REGEXP = ".*?webOS.?((\\d+)\\.(\\d+)(?:\\.(\\d+))?(?:\\.(\\d+))?(.*))";
+ private Regex versionRegex = new Regex(VERSION_REGEXP);
+
+ public bool CanBuild(UserAgent userAgent)
+ {
+ return userAgent.GetPatternElementsInside().Contains("webOS");
+ }
+
+ public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
+ {
+ OSModel.OperatingSystem model = new OSModel.OperatingSystem();
+ model.majorRevision = "1";
+ model.SetVendor("Palm");
+ model.SetModel("Web OS");
+ model.confidence = 40;
+
+ string patternElementsInside = userAgent.GetPatternElementsInside();
+ String[] splittedTokens = patternElementsInside.Split(";".ToCharArray());
+
+ foreach (String tokenElement in splittedTokens)
+ {
+ if (versionRegex.IsMatch(tokenElement))
+ {
+ Match versionMatcher = versionRegex.Match(tokenElement);
+ GroupCollection groups = versionMatcher.Groups;
+
+ model.confidence = 90;
+ if (groups[1] != null && groups[1].Value.Trim().Length > 0)
+ {
+ model.SetVersion(groups[1].Value);
+ }
+ if (groups[2] != null && groups[2].Value.Trim().Length > 0)
+ {
+ model.majorRevision = groups[2].Value;
+ }
+ if (groups[3] != null && groups[3].Value.Trim().Length > 0)
+ {
+ model.minorRevision = groups[3].Value;
+ }
+ if (groups[4] != null && groups[4].Value.Trim().Length > 0)
+ {
+ model.microRevision = groups[4].Value;
+ }
+ if (groups[5] != null && groups[5].Value.Trim().Length > 0)
+ {
+ model.nanoRevision = groups[5].Value;
+ }
+ }
+ }
+ return model;
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/WinCEMozillaSubBuilder.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/WinCEMozillaSubBuilder.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/WinCEMozillaSubBuilder.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/WinCEMozillaSubBuilder.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,171 @@
+/**
+ * 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.Models;
+using System.Text.RegularExpressions;
+using OSModel = Oddr.Models.OS;
+
+namespace Oddr.Builders.OS.Mozilla
+{
+ public class WinCEMozillaSubBuilder : IBuilder
+ {
+ private const String VERSION_REGEXP = ".*Windows.?CE.?((\\d+)?\\.?(\\d+)?\\.?(\\d+)?).*";
+ private const String VERSION_MSIE_IEMOBILE = "(?:.*(?:MSIE).?(\\d+)\\.(\\d+).*)|(?:.*IEMobile.?(\\d+)\\.(\\d+).*)";
+ private Regex versionRegex = new Regex(VERSION_REGEXP);
+ private Regex versionMsieRegex = new Regex(VERSION_MSIE_IEMOBILE);
+
+ public bool CanBuild(UserAgent userAgent)
+ {
+ if (userAgent.containsWindowsPhone)
+ {
+ Regex winCeRegex = new Regex(".*Windows.?CE.*");
+ if (winCeRegex.IsMatch(userAgent.GetPatternElementsInside()))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
+ {
+ OSModel.OperatingSystem model = new OSModel.OperatingSystem();
+ model.majorRevision = "1";
+ model.SetVendor("Microsoft");
+ model.SetModel("Windows Phone");
+ model.confidence = 40;
+
+ string patternElementsInside = userAgent.GetPatternElementsInside();
+ String[] splittedTokens = patternElementsInside.Split(";".ToCharArray());
+ foreach (String tokenElement in splittedTokens)
+ {
+ if (versionRegex.IsMatch(tokenElement))
+ {
+ Match versionMatcher = versionRegex.Match(tokenElement);
+ GroupCollection groups = versionMatcher.Groups;
+
+ if (model.confidence > 40)
+ {
+ model.confidence = 95;
+
+ }
+ else
+ {
+ model.confidence = 85;
+ }
+
+ if (groups[1] != null && groups[1].Value.Trim().Length > 0)
+ {
+ model.SetDescription(groups[1].Value);
+ }
+ if (groups[2] != null && groups[2].Value.Trim().Length > 0)
+ {
+ model.majorRevision = groups[2].Value;
+ }
+ if (groups[3] != null && groups[3].Value.Trim().Length > 0)
+ {
+ model.minorRevision = groups[3].Value;
+ }
+ if (groups[4] != null && groups[4].Value.Trim().Length > 0)
+ {
+ model.microRevision = groups[4].Value;
+ }
+ }
+
+ if (versionMsieRegex.IsMatch(tokenElement))
+ {
+ Match versionMsieMatcher = versionMsieRegex.Match(tokenElement);
+ String version = model.GetVersion();
+ if (version == null || version.Length < 7)
+ {
+ version = "0.0.0.0";
+ }
+ String[] subVersion = version.Split(".".ToCharArray());
+ int count = 0;
+ GroupCollection groups = versionMsieMatcher.Groups;
+ for (int idx = 1; idx <= groups.Count; idx++)
+ {
+ if ((idx >= 1) && (idx <= 4) && groups[idx] != null && groups[idx].Value.Trim().Length > 0)
+ {
+ subVersion[idx - 1] = groups[idx].Value;
+ count++;
+ }
+ }
+ model.SetVersion(subVersion[0] + "." + subVersion[1] + "." + subVersion[2] + "." + subVersion[3]);
+
+ if (model.confidence > 40)
+ {
+ model.confidence = 95;
+
+ }
+ else
+ {
+ model.confidence = (count * 18);
+ }
+ }
+ }
+ SetWinCeVersion(model);
+ return model;
+ }
+
+ private void SetWinCeVersion(OSModel.OperatingSystem model)
+ {
+ //TODO: to be refined
+ String version = model.GetVersion();
+ if (version == null)
+ {
+ return;
+
+ }
+ else if (!model.majorRevision.Equals("1"))
+ {
+ return;
+ }
+
+ Regex winCEVersionRegex = new Regex(".*(\\d+).(\\d+).(\\d+).(\\d+).*");
+
+ if (winCEVersionRegex.IsMatch(version))
+ {
+ Match result = winCEVersionRegex.Match(version);
+ GroupCollection groups = result.Groups;
+
+ if (groups[1].Value.Equals("4"))
+ {
+ model.majorRevision = "5";
+
+ }
+ else if (groups[1].Value.Equals("6"))
+ {
+ model.majorRevision = "6";
+
+ if (groups[3].Value.Equals("7"))
+ {
+ model.minorRevision = "1";
+ }
+ }
+ }
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/WinPhoneMozillaSubBuilder.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/WinPhoneMozillaSubBuilder.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/WinPhoneMozillaSubBuilder.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/Mozilla/WinPhoneMozillaSubBuilder.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,120 @@
+/**
+ * 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 System.Text.RegularExpressions;
+using Oddr.Models;
+using OSModel = Oddr.Models.OS;
+
+namespace Oddr.Builders.OS.Mozilla
+{
+ public class WinPhoneMozillaSubBuilder : IBuilder
+ {
+ private const String VERSION_REGEXP = ".*Windows.?Phone.?(?:OS)?.?((\\d+)(?:\\.(\\d+))?(?:\\.(\\d+))?(?:\\.(\\d+))?).*";
+ private Regex versionRegex = new Regex(VERSION_REGEXP);
+
+ public bool CanBuild(UserAgent userAgent)
+ {
+ if (userAgent.containsWindowsPhone)
+ {
+ Regex windowsPhoneRegex = new Regex(".*Windows.?Phone.*");
+ if (windowsPhoneRegex.IsMatch(userAgent.GetPatternElementsInside() + userAgent.GetPatternElementsPost()))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
+ {
+ OSModel.OperatingSystem model = new OSModel.OperatingSystem();
+ model.SetVendor("Microsoft");
+ model.SetModel("Windows Phone");
+ model.confidence = 40;
+ bool isInPostMoz = false;
+
+ String toSplit = userAgent.GetPatternElementsInside();
+
+ if (!versionRegex.IsMatch(toSplit))
+ {
+ toSplit = userAgent.GetPatternElementsPost();
+ isInPostMoz = true;
+ }
+
+ String[] splittedTokens = toSplit.Split(";".ToCharArray());
+ foreach (String tokenElement in splittedTokens)
+ {
+ if (versionRegex.IsMatch(tokenElement))
+ {
+ Match versionMatcher = versionRegex.Match(tokenElement);
+ GroupCollection groups = versionMatcher.Groups;
+
+ if (isInPostMoz)
+ {
+ model.confidence = 85;
+
+ }
+ else
+ {
+ model.confidence = 90;
+ }
+
+ if (groups[1] != null && groups[1].Value.Trim().Length > 0)
+ {
+ model.SetVersion(groups[1].Value);
+ }
+
+ if (groups[2] != null && groups[2].Value.Trim().Length > 0)
+ {
+ model.majorRevision = groups[2].Value;
+ }
+
+ if (groups[3] != null && groups[3].Value.Trim().Length > 0)
+ {
+ model.minorRevision = groups[3].Value;
+ }
+
+ if (groups[4] != null && groups[4].Value.Trim().Length > 0)
+ {
+ model.microRevision = groups[4].Value;
+ }
+
+ if (groups[5] != null && groups[5].Value.Trim().Length > 0)
+ {
+ model.nanoRevision = groups[5].Value;
+ }
+ }
+
+ if (model.majorRevision.Equals("0") && model.minorRevision.Equals("0"))
+ {
+ model.majorRevision = "6";
+ model.minorRevision = "5";
+ }
+ model.SetDescription("Windows Phone " + model.majorRevision + "." + model.minorRevision + "." + model.microRevision + "." + model.nanoRevision);
+ }
+ return model;
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/MozillaOSModelBuilder.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/MozillaOSModelBuilder.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/MozillaOSModelBuilder.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/MozillaOSModelBuilder.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,91 @@
+/**
+ * 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.Models;
+using OSModel = Oddr.Models.OS;
+using Oddr.Builders.OS.Mozilla;
+
+namespace Oddr.Builders.OS
+{
+ public class MozillaOSModelBuilder : IBuilder
+ {
+ private IBuilder[] builders;
+
+ public MozillaOSModelBuilder()
+ {
+ builders = new IBuilder[]
+ {
+ new IOSMozillaSubBuilder(),
+ new AndroidMozillaSubBuilder(),
+ new WinPhoneMozillaSubBuilder(),
+ new BlackBerryMozillaSubBuilder(),
+ new SymbianMozillaSubBuilder(),
+ new WinCEMozillaSubBuilder(),
+ new BadaMozillaSubBuilder(),
+ new BrewMozillaSubBuilder(),
+ new WebOSMozillaSubBuilder(),
+ new LinuxMozillaSubBuilder(),
+ new MacOSXMozillaSubBuilder()
+ };
+ }
+
+ public bool CanBuild(UserAgent userAgent)
+ {
+ return userAgent.mozillaPattern;
+ }
+
+ public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
+ {
+ List<OSModel.OperatingSystem> founds = new List<OSModel.OperatingSystem>();
+ OSModel.OperatingSystem found = null;
+ foreach (IBuilder builder in builders) {
+ if (builder.CanBuild(userAgent)) {
+ OSModel.OperatingSystem builded = (OSModel.OperatingSystem) builder.Build(userAgent, confidenceTreshold);
+ if (builded != null) {
+ founds.Add(builded);
+ if (builded.confidence >= confidenceTreshold) {
+ found = builded;
+ break;
+ }
+ }
+ }
+ }
+
+ if (found != null) {
+ return found;
+
+ } else {
+ if (founds.Count > 0)
+ {
+ founds.Sort();
+ founds.Reverse();
+ return founds[0];
+ }
+
+ return null;
+ }
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/OperaOSModelBuilder.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/OperaOSModelBuilder.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/OperaOSModelBuilder.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Builders/OS/OperaOSModelBuilder.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,92 @@
+/**
+ * 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.Models;
+using OSModel = Oddr.Models.OS;
+using Oddr.Builders.OS.Mozilla;
+using Oddr.Builders.Devices;
+
+namespace Oddr.Builders.OS
+{
+ public class OperaOSModelBuilder : IBuilder
+ {
+ private IBuilder[] builders;
+
+ public OperaOSModelBuilder()
+ {
+ builders = new IBuilder[]
+ {
+ new AndroidMozillaSubBuilder(),
+ new SymbianMozillaSubBuilder(),
+ new WinCEMozillaSubBuilder(),
+ new WinPhoneDeviceBuilder()
+ };
+ }
+
+ public bool CanBuild(UserAgent userAgent)
+ {
+ return userAgent.operaPattern;
+ }
+
+ public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
+ {
+ List<OSModel.OperatingSystem> founds = new List<OSModel.OperatingSystem>();
+ OSModel.OperatingSystem found = null;
+ foreach (IBuilder builder in builders)
+ {
+ if (builder.CanBuild(userAgent))
+ {
+ OSModel.OperatingSystem builded = (OSModel.OperatingSystem)builder.Build(userAgent, confidenceTreshold);
+ if (builded != null)
+ {
+ founds.Add(builded);
+ if (builded.confidence >= confidenceTreshold)
+ {
+ found = builded;
+ break;
+ }
+ }
+ }
+ }
+
+ if (found != null)
+ {
+ return found;
+
+ }
+ else
+ {
+ if (founds.Count > 0)
+ {
+ founds.Sort();
+ founds.Reverse();
+ return founds[0];
+ }
+
+ return null;
+ }
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Caches/Cache.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Caches/Cache.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Caches/Cache.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Caches/Cache.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,99 @@
+/**
+ * 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 System.Runtime.CompilerServices;
+
+namespace Oddr.Caches
+{
+ public class Cache : ICache
+ {
+ private Dictionary<string, object> dic;
+ private Queue<String> queue;
+ private int cacheSize;
+
+ public Cache(int cacheSize)
+ {
+ Init(cacheSize);
+ }
+
+ public Cache()
+ {
+ Init(100);
+ }
+
+ private void Init(int cacheSize)
+ {
+ this.cacheSize = cacheSize;
+ this.dic = new Dictionary<string, object>(cacheSize);
+ this.queue = new Queue<string>(cacheSize);
+ }
+
+ [MethodImpl(MethodImplOptions.Synchronized)]
+ public object GetCachedElement(string id)
+ {
+ object toRet = null;
+ dic.TryGetValue(id, out toRet);
+ return toRet;
+ }
+
+ [MethodImpl(MethodImplOptions.Synchronized)]
+ public void SetCachedElement(string id, object value)
+ {
+ dic.Add(id, value);
+ queue.Enqueue(id);
+ if (dic.Count > cacheSize)
+ {
+ String toRemove = queue.Dequeue();
+ dic.Remove(toRemove);
+ }
+ }
+
+ [MethodImpl(MethodImplOptions.Synchronized)]
+ public void Clear()
+ {
+ dic.Clear();
+ queue.Clear();
+ }
+
+ [MethodImpl(MethodImplOptions.Synchronized)]
+ public int UsedEntries()
+ {
+ return dic.Count;
+ }
+
+ [MethodImpl(MethodImplOptions.Synchronized)]
+ public List<KeyValuePair<string, object>> GetAll()
+ {
+ List<KeyValuePair<string, object>> list = new List<KeyValuePair<string,object>>();
+
+ foreach (KeyValuePair<string, object> kvp in dic)
+ {
+ list.Add(kvp);
+ }
+
+ return list;
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Caches/ICache.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Caches/ICache.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Caches/ICache.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Caches/ICache.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,41 @@
+/**
+ * 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.Caches
+{
+ public interface ICache
+ {
+ Object GetCachedElement(String id);
+
+ void SetCachedElement(String id, Object value);
+
+ void Clear();
+
+ int UsedEntries();
+
+ List<KeyValuePair<String, Object>> GetAll();
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Documenthandlers/BrowserDatasourceParser.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Documenthandlers/BrowserDatasourceParser.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Documenthandlers/BrowserDatasourceParser.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Documenthandlers/BrowserDatasourceParser.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,173 @@
+/**
+ * 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.IO;
+using System.Linq;
+using System.Text;
+using System.Xml;
+using System.Xml.Linq;
+using Oddr.Models;
+using Oddr.Models.Browsers;
+using Oddr.Vocabularies;
+
+namespace Oddr.Documenthandlers
+{
+ public class BrowserDatasourceParser
+ {
+ private const String ELEMENT_BROWSERS = "Browsers";
+ private const String ELEMENT_BROWSER_DESCRIPTION = "browser";
+ private const String ELEMENT_PROPERTY = "property";
+ private const String ATTRIBUTE_BROWSER_ID = "id";
+ private const String ATTRIBUTE_PROPERTY_NAME = "name";
+ private const String ATTRIBUTE_PROPERTY_VALUE = "value";
+ private VocabularyHolder vocabularyHolder;
+ private XDocument doc;
+ public SortedDictionary<String, Browser> browsers
+ {
+ private set;
+ get;
+ }
+
+ public BrowserDatasourceParser(Stream stream)
+ {
+ Init(stream);
+ }
+
+ public BrowserDatasourceParser(Stream stream, VocabularyHolder vocabularyHolder)
+ {
+ Init(stream);
+ try
+ {
+ vocabularyHolder.ExistVocabulary(ODDRVocabularyService.ODDR_LIMITED_VOCABULARY_IRI);
+ this.vocabularyHolder = vocabularyHolder;
+ }
+ catch (Exception ex)
+ {
+ this.vocabularyHolder = null;
+ }
+
+ }
+
+ private void Init(Stream stream)
+ {
+ this.browsers = new SortedDictionary<string, Browser>(StringComparer.Ordinal);
+ XmlReader reader = null;
+ try
+ {
+ reader = XmlReader.Create(stream);
+ doc = XDocument.Load(reader);
+ }
+ catch (ArgumentNullException ex)
+ {
+ throw new ArgumentNullException(ex.Message, ex);
+ }
+ finally
+ {
+ if (reader != null)
+ {
+ ((IDisposable)reader).Dispose();
+ }
+ }
+ }
+
+ /// <exception cref="Exception">Thrown when...</exception>
+ public void Parse()
+ {
+ if (doc == null)
+ {
+ throw new Exception("Input stream is not valid");
+ }
+
+ BrowserWrapper[] browserArray = (from b in doc.Descendants(ELEMENT_BROWSERS).Descendants(ELEMENT_BROWSER_DESCRIPTION)
+ select new BrowserWrapper
+ {
+ id = b.Attribute(ATTRIBUTE_BROWSER_ID).Value,
+ properties = (from prop in b.Descendants(ELEMENT_PROPERTY)
+ select new StringPair
+ {
+ key = prop.Attribute(ATTRIBUTE_PROPERTY_NAME).Value,
+ value = prop.Attribute(ATTRIBUTE_PROPERTY_VALUE).Value,
+ }).ToArray<StringPair>(),
+ }).ToArray<BrowserWrapper>();
+
+ foreach (BrowserWrapper b in browserArray)
+ {
+ Browser browser = b.GetBrowser(vocabularyHolder);
+ browsers.Add(b.id, browser);
+ }
+ }
+
+
+ private class BrowserWrapper
+ {
+ public string id;
+ public StringPair[] properties;
+
+ public Browser GetBrowser(VocabularyHolder vocabularyHolder)
+ {
+ Dictionary<string, string> dic = new Dictionary<string, string>();
+
+ if (vocabularyHolder != null)
+ {
+ foreach (StringPair sp in properties)
+ {
+ try
+ {
+ //vocabularyHolder.ExistProperty(sp.key, ODDRService.ASPECT_WEB_BROWSER, ODDRVocabularyService.ODDR_LIMITED_VOCABULARY_IRI);
+ if (vocabularyHolder.ExistProperty(sp.key, ODDRService.ASPECT_WEB_BROWSER, ODDRVocabularyService.ODDR_LIMITED_VOCABULARY_IRI) != null)
+ {
+ dic.Add(sp.key, sp.value);
+ }
+ }
+ //catch (NameException ex)
+ //{
+ // //property non loaded
+ //}
+ catch (ArgumentException ae)
+ {
+ //Console.WriteLine(this.GetType().FullName + " " + sp.key + " already present in device " + id);
+ }
+ }
+ }
+ else
+ {
+ foreach (StringPair sp in properties)
+ {
+ dic.Add(sp.key, sp.value);
+ }
+ }
+
+ Browser b;
+ b = new Browser(dic);
+
+ return b;
+ }
+ }
+
+ private class StringPair
+ {
+ public string key;
+ public string value;
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Documenthandlers/DeviceBuilderParser.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Documenthandlers/DeviceBuilderParser.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Documenthandlers/DeviceBuilderParser.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Documenthandlers/DeviceBuilderParser.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,190 @@
+/**
+ * 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.Builders.Devices;
+using System.IO;
+using System.Xml;
+using System.Xml.Linq;
+using System.Reflection;
+
+namespace Oddr.Documenthandlers
+{
+ public class DeviceBuilderParser
+ {
+ private const string ELEMENT_BUILDERS = "Builders";
+ private const string BUILDER_DEVICE = "builder"; //Java source: private Object BUILDER_DEVICE = "builder";
+ private const String ELEMENT_DEVICE = "device";
+ private const String ELEMENT_PROPERTY = "property";
+ private const String ELEMENT_LIST = "list";
+ private const String ELEMENT_VALUE = "value";
+ private const String ATTRIBUTE_DEVICE_ID = "id";
+ private const string ATTRIBUTE_CLASS = "class";
+ private List<IDeviceBuilder> builders;
+ private XDocument doc;
+ private Dictionary<string, string> deviceBuilderClassMapper;
+
+
+ public DeviceBuilderParser(Stream stream)
+ {
+ Init(stream);
+ this.builders = new List<IDeviceBuilder>();
+ }
+
+ public DeviceBuilderParser(Stream stream, List<IDeviceBuilder> builders)
+ {
+ Init(stream);
+ this.builders = builders;
+ }
+
+ /// <exception cref="System.ArgumentNullException">Thrown when stream is null</exception>
+ private void Init(Stream stream)
+ {
+ try
+ {
+ SetStream(stream);
+ }
+ catch (ArgumentNullException ex)
+ {
+ throw new ArgumentNullException(ex.Message, ex);
+ }
+
+ deviceBuilderClassMapper = new Dictionary<string, string>();
+ deviceBuilderClassMapper.Add("org.openddr.simpleapi.oddr.builder.device.AndroidDeviceBuilder", "Oddr.Builders.Devices.AndroidDeviceBuilder");
+ deviceBuilderClassMapper.Add("org.openddr.simpleapi.oddr.builder.device.SymbianDeviceBuilder", "Oddr.Builders.Devices.SymbianDeviceBuilder");
+ deviceBuilderClassMapper.Add("org.openddr.simpleapi.oddr.builder.device.WinPhoneDeviceBuilder", "Oddr.Builders.Devices.WinPhoneDeviceBuilder");
+ deviceBuilderClassMapper.Add("org.openddr.simpleapi.oddr.builder.device.IOSDeviceBuilder", "Oddr.Builders.Devices.IOSDeviceBuilder");
+ deviceBuilderClassMapper.Add("org.openddr.simpleapi.oddr.builder.device.SimpleDeviceBuilder", "Oddr.Builders.Devices.SimpleDeviceBuilder");
+ deviceBuilderClassMapper.Add("org.openddr.simpleapi.oddr.builder.device.TwoStepDeviceBuilder", "Oddr.Builders.Devices.TwoStepDeviceBuilder");
+ }
+
+ /// <exception cref="System.ArgumentNullException">Thrown when stream is null</exception>
+ public void SetStream(Stream stream)
+ {
+ XmlReader reader = null;
+ try
+ {
+ reader = XmlReader.Create(stream);
+ doc = XDocument.Load(reader);
+ }
+ catch (ArgumentNullException ex)
+ {
+ throw new ArgumentNullException(ex.Message, ex);
+ }
+ finally
+ {
+ if (reader != null)
+ {
+ ((IDisposable)reader).Dispose();
+ }
+ }
+ }
+
+ /// <exception cref="Exception">Thrown when...</exception>
+ public void Parse()
+ {
+ if (doc == null)
+ {
+ throw new Exception("Input stream is not valid");
+ }
+
+ BuilderWrapper[] buildersWrapper = (from b in doc.Descendants(ELEMENT_BUILDERS).Descendants(BUILDER_DEVICE)
+ select new BuilderWrapper
+ {
+ attributeClass = b.Attribute(ATTRIBUTE_CLASS).Value,
+ devices = (from d in b.Descendants(ELEMENT_DEVICE)
+ select new DeviceWrapper
+ {
+ id = d.Attribute(ATTRIBUTE_DEVICE_ID).Value,
+ values = d.Element(ELEMENT_LIST).Descendants(ELEMENT_VALUE).Select(x => x.Value).ToList(),
+ }).ToList<DeviceWrapper>(),
+ }).ToArray<BuilderWrapper>();
+
+ foreach (BuilderWrapper bw in buildersWrapper)
+ {
+ IDeviceBuilder deviceBuilderInstance = null;
+
+ try
+ {
+ Type builderType = Type.GetType(deviceBuilderClassMapper[bw.attributeClass], true);
+ foreach (IDeviceBuilder deviceBuilder in builders)
+ {
+ if (deviceBuilder.GetType().Equals(builderType))
+ {
+ deviceBuilderInstance = deviceBuilder;
+ }
+ }
+
+ if (deviceBuilderInstance == null)
+ {
+ deviceBuilderInstance = (IDeviceBuilder)Activator.CreateInstance(builderType);
+ builders.Add(deviceBuilderInstance);
+ }
+
+ foreach (DeviceWrapper d in bw.devices)
+ {
+ deviceBuilderInstance.PutDevice(d.id, d.values);
+ }
+ }
+ catch (ArgumentNullException ane)
+ {
+ throw new ArgumentNullException("Argument is null", ane);
+ }
+ catch (TargetInvocationException tie)
+ {
+ throw new ArgumentException("Can not instantiate class: {0} described in device builder document due to constructor exception", deviceBuilderClassMapper[bw.attributeClass]);
+ }
+ catch (TypeLoadException tle)
+ {
+ throw new ArgumentException("Can not find class: {0} described in device builder document", deviceBuilderClassMapper[bw.attributeClass]);
+ }
+ catch (IOException ioe)
+ {
+ throw new ArgumentException("Can not find file: {0} described in device builder document", deviceBuilderClassMapper[bw.attributeClass]);
+ }
+ catch (Exception ex)
+ {
+ throw new ArgumentException("Can not instantiate class: {0} described in device builder document", deviceBuilderClassMapper[bw.attributeClass]);
+ }
+ }
+ }
+
+ private class BuilderWrapper
+ {
+ public string attributeClass;
+ public List<DeviceWrapper> devices;
+ }
+
+ private class DeviceWrapper
+ {
+ public string id;
+ public List<string> values;
+ }
+
+ public IDeviceBuilder[] DeviceBuilders()
+ {
+ return builders.ToArray<IDeviceBuilder>();
+ }
+ }
+}
Added: incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Documenthandlers/DeviceDatasourceParser.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Documenthandlers/DeviceDatasourceParser.cs?rev=1392912&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Documenthandlers/DeviceDatasourceParser.cs (added)
+++ incubator/devicemap/trunk/openddr/csharp/OpenDDR-CSharp/Documenthandlers/DeviceDatasourceParser.cs Tue Oct 2 13:34:31 2012
@@ -0,0 +1,283 @@
+/**
+ * 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.IO;
+using Oddr.Vocabularies;
+using Oddr.Models.Devices;
+using System.Xml;
+using System.Xml.Linq;
+using System.Diagnostics;
+using W3c.Ddr.Exceptions;
+
+namespace Oddr.Documenthandlers
+{
+ class DeviceDatasourceParser
+ {
+ private const String PROPERTY_ID = "id";
+ private const String ELEMENT_DEVICES = "Devices";
+ private const String ELEMENT_DEVICE = "device";
+ private const String ELEMENT_PROPERTY = "property";
+ private const String ATTRIBUTE_DEVICE_ID = "id";
+ private const String ATTRIBUTE_DEVICE_PARENT_ID = "parentId";
+ private const String ATTRIBUTE_PROPERTY_NAME = "name";
+ private const String ATTRIBUTE_PROPERTY_VALUE = "value";
+ private VocabularyHolder vocabularyHolder;
+ private XDocument doc;
+ public Dictionary<String, Device> devices
+ {
+ private set;
+ get;
+ }
+ public bool patching
+ {
+ set;
+ private get;
+ }
+
+ /// <exception cref="System.ArgumentNullException">Thrown when stream is null</exception>
+ public DeviceDatasourceParser(Stream stream)
+ {
+ try
+ {
+ Init(stream);
+ }
+ catch (ArgumentNullException ex)
+ {
+ throw new ArgumentNullException(ex.Message, ex);
+ }
+ this.devices = new Dictionary<string, Device>();
+ }
+
+ /// <exception cref="System.ArgumentNullException">Thrown when stream is null</exception>
+ public DeviceDatasourceParser(Stream stream, Dictionary<string, Device> devices)
+ {
+ try
+ {
+ Init(stream);
+ }
+ catch (ArgumentNullException ex)
+ {
+ throw new ArgumentNullException(ex.Message, ex);
+ }
+ this.devices = devices;
+ }
+
+ /// <exception cref="System.ArgumentNullException">Thrown when stream is null</exception>
+ public DeviceDatasourceParser(Stream stream, Dictionary<string, Device> devices, VocabularyHolder vocabularyHolder)
+ {
+ try
+ {
+ Init(stream);
+ }
+ catch (ArgumentNullException ex)
+ {
+ throw new ArgumentNullException(ex.Message, ex);
+ }
+ this.devices = devices;
+ try
+ {
+ vocabularyHolder.ExistVocabulary(ODDRVocabularyService.ODDR_LIMITED_VOCABULARY_IRI);
+ this.vocabularyHolder = vocabularyHolder;
+ }
+ catch (Exception ex)
+ {
+ this.vocabularyHolder = null;
+ }
+
+ }
+
+ /// <exception cref="System.ArgumentNullException">Thrown when stream is null</exception>
+ private void Init(Stream stream)
+ {
+ this.patching = false;
+ try
+ {
+ SetStream(stream);
+ }
+ catch (ArgumentNullException ex)
+ {
+ throw new ArgumentNullException(ex.Message, ex);
+ }
+
+ }
+
+ /// <exception cref="System.ArgumentNullException">Thrown when stream is null</exception>
+ public void SetStream(Stream stream)
+ {
+ XmlReader reader = null;
+ try
+ {
+ reader = XmlReader.Create(stream);
+ doc = XDocument.Load(reader);
+ }
+ catch (ArgumentNullException ex)
+ {
+ throw new ArgumentNullException(ex.Message, ex);
+ }
+ finally
+ {
+ if (reader != null)
+ {
+ ((IDisposable)reader).Dispose();
+ }
+ }
+ }
+
+ /// <exception cref="Exception">Thrown when input stream is not valid</exception>
+ public void Parse()
+ {
+ if (doc == null)
+ {
+ throw new Exception("Input stream is not valid");
+ }
+
+ DeviceWrapper[] deviceWrapperArray = (from d in doc.Descendants(ELEMENT_DEVICES).Descendants(ELEMENT_DEVICE)
+ where d.Attribute(ATTRIBUTE_DEVICE_PARENT_ID) != null
+ select new DeviceWrapper
+ {
+ id = d.Attribute(ATTRIBUTE_DEVICE_ID).Value,
+ parentId = d.Attribute(ATTRIBUTE_DEVICE_PARENT_ID).Value,
+ properties = (from prop in d.Descendants(ELEMENT_PROPERTY)
+ select new StringPair
+ {
+ key = prop.Attribute(ATTRIBUTE_PROPERTY_NAME).Value,
+ value = prop.Attribute(ATTRIBUTE_PROPERTY_VALUE).Value,
+ }).ToArray<StringPair>(),
+ }).ToArray<DeviceWrapper>();
+
+ DeviceWrapper[] deviceWrapperArray2 = (from d in doc.Descendants(ELEMENT_DEVICES).Descendants(ELEMENT_DEVICE)
+ where d.Attribute(ATTRIBUTE_DEVICE_PARENT_ID) == null
+ select new DeviceWrapper
+ {
+ id = d.Attribute(ATTRIBUTE_DEVICE_ID).Value,
+ properties = (from prop in d.Descendants(ELEMENT_PROPERTY)
+ select new StringPair
+ {
+ key = prop.Attribute(ATTRIBUTE_PROPERTY_NAME).Value,
+ value = prop.Attribute(ATTRIBUTE_PROPERTY_VALUE).Value,
+ }).ToArray<StringPair>(),
+ }).ToArray<DeviceWrapper>();
+
+ deviceWrapperArray = deviceWrapperArray.Concat(deviceWrapperArray2).ToArray();
+
+ foreach (DeviceWrapper dw in deviceWrapperArray)
+ {
+ Device device = dw.GetDevice(vocabularyHolder);
+
+ Device existDevice = null;
+ if (devices.TryGetValue(device.id, out existDevice))
+ {
+ if (patching)
+ {
+ existDevice.PutPropertiesMap(device.properties);
+ continue;
+ }
+ else
+ {
+ //TODO: WARNING already present
+ }
+ }
+
+ try
+ {
+ device.properties.Add(PROPERTY_ID, device.id);
+ }
+ catch (ArgumentException ae)
+ {
+ //Console.WriteLine(this.GetType().FullName + " " + PROPERTY_ID + " already exist in device " + device.id);
+ }
+
+ try
+ {
+ devices.Add(device.id, device);
+ }
+ catch (ArgumentException ae)
+ {
+ //Console.WriteLine(this.GetType().FullName + " " + device.id + " already exist in device " + device.id);
+ devices.Remove(device.id);
+ devices.Add(device.id, device);
+ }
+ }
+
+ }
+
+ private class DeviceWrapper
+ {
+ public string id;
+ public string parentId;
+ public StringPair[] properties;
+
+ public Device GetDevice(VocabularyHolder vocabularyHolder)
+ {
+ Dictionary<string, string> dic = new Dictionary<string, string>();
+
+ if (vocabularyHolder != null)
+ {
+ foreach (StringPair sp in properties)
+ {
+ try
+ {
+ //vocabularyHolder.ExistProperty(sp.key, ODDRService.ASPECT_DEVICE, ODDRVocabularyService.ODDR_LIMITED_VOCABULARY_IRI);
+ if (vocabularyHolder.ExistProperty(sp.key, ODDRService.ASPECT_DEVICE, ODDRVocabularyService.ODDR_LIMITED_VOCABULARY_IRI) != null)
+ {
+ //dic.Add(sp.key, sp.value);
+ dic[sp.key] = sp.value;
+ }
+ }
+ //catch (NameException ex)
+ //{
+ // Console.WriteLine(ex.Message);
+ // //property non loaded
+ //}
+ catch (ArgumentException ae)
+ {
+ //Console.WriteLine(this.GetType().FullName + " " + sp.key + " already present in device " + id);
+ }
+ }
+ }
+ else
+ {
+ foreach (StringPair sp in properties)
+ {
+ //dic.Add(sp.key, sp.value);
+ dic[sp.key] = sp.value;
+ }
+ }
+
+ Device d = new Device();
+ d.id = this.id;
+ d.parentId = this.parentId;
+ d.PutPropertiesMap(dic);
+
+ return d;
+ }
+ }
+
+ private class StringPair
+ {
+ public string key;
+ public string value;
+ }
+ }
+}