You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devicemap.apache.org by es...@apache.org on 2014/07/09 23:42:03 UTC
svn commit: r1609313 - in
/incubator/devicemap/trunk/devicemap/csharp/DeviceMap: ./ Properties/ bin/
bin/Debug/ bin/Release/ data/ loaders/ obj/ obj/Debug/ obj/Debug/TempPE/
obj/Release/ obj/Release/TempPE/ parser/ util/
Author: esjr
Date: Wed Jul 9 21:42:02 2014
New Revision: 1609313
URL: http://svn.apache.org/r1609313
Log:
esjr
Added:
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/App.config
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/Constants.cs
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/DeviceMap.csproj
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/DeviceMap.pfx (with props)
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/DeviceMapClient.cs
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/DeviceMapException.cs
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/Properties/
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/Properties/AssemblyInfo.cs
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.dll (with props)
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.dll.config
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.pdb (with props)
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.vshost.exe (with props)
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.vshost.exe.config
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Release/
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Release/DeviceMap.dll (with props)
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Release/DeviceMap.dll.config
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Release/DeviceMap.pdb (with props)
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/data/
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/data/Device.cs
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/data/Pattern.cs
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/FileLoader.cs
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/ILoader.cs
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/Loader.cs
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/UrlLoader.cs
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache (with props)
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/DeviceMap.csproj.FileListAbsolute.txt
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/DeviceMap.dll (with props)
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/DeviceMap.pdb (with props)
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/TempPE/
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache (with props)
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/DeviceMap.csproj.FileListAbsolute.txt
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/DeviceMap.dll (with props)
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/DeviceMap.pdb (with props)
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/TempPE/
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/parser/
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/parser/XmlParser.cs
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/util/
incubator/devicemap/trunk/devicemap/csharp/DeviceMap/util/Util.cs
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/App.config
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/App.config?rev=1609313&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/csharp/DeviceMap/App.config (added)
+++ incubator/devicemap/trunk/devicemap/csharp/DeviceMap/App.config Wed Jul 9 21:42:02 2014
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
+ </startup>
+</configuration>
\ No newline at end of file
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/Constants.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/Constants.cs?rev=1609313&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/csharp/DeviceMap/Constants.cs (added)
+++ incubator/devicemap/trunk/devicemap/csharp/DeviceMap/Constants.cs Wed Jul 9 21:42:02 2014
@@ -0,0 +1,45 @@
+#region "Header"
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+#endregion ' Header
+//
+namespace DeviceMap
+{
+ public class Constants
+ {
+ public const string APP_NAME = "DeviceMap";
+ // data files
+ public const string BUILDER_DATA = "BuilderDataSource.xml";
+ public const string BUILDER_DATA_PATCH = "BuilderDataSourcePatch.xml";
+ public const string DEVICE_DATA = "DeviceDataSource.xml";
+
+ public const string DEVICE_DATA_PATCH = "DeviceDataSourcePatch.xml";
+
+ public const string DEVICEMAP_UA = "org.apache.devicemap.client";
+ public const string DEVICE_TOSTRING_FORMAT = "Id='{0}', ParentId='{1}', Type='{2}', Pattern={3}, Attributes={4}";
+ public const string HTTP_PREFIX = "http";
+ public const string RELEASE_VERSION = "1.0";
+ public const string SIMPLE = "simple";
+ public const string USER_AGENT_SPLIT = " |-|_|/|\\\\|\\[|\\]|\\(|\\)|;";
+
+ public const string VERSION_FORMAT = "Version : {0}, Build : {1}";
+ public const string CONFIG_ERROR_FORMAT = "Error in configuration file '{0}' : {1}.";
+ public const string CONFIG_ERROR_CONN_FORMAT = "Error in configuration file '{0}' : ConnectionString entry for DeviceMap is missing.";
+ public const string FILE_ERROR_FORMAT = "File '{0}' not found.";
+ public const string WEB_ERROR_FORMAT = "Web exception : {0}.";
+ }
+}
\ No newline at end of file
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/DeviceMap.csproj
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/DeviceMap.csproj?rev=1609313&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/csharp/DeviceMap/DeviceMap.csproj (added)
+++ incubator/devicemap/trunk/devicemap/csharp/DeviceMap/DeviceMap.csproj Wed Jul 9 21:42:02 2014
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{80034170-C27C-4AB9-A98F-F2FCCF83A8FA}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>c</RootNamespace>
+ <AssemblyName>DeviceMap</AssemblyName>
+ <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <PlatformTarget>AnyCPU</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|AnyCPU' ">
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup>
+ <StartupObject />
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.configuration" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Constants.cs" />
+ <Compile Include="data\Device.cs" />
+ <Compile Include="data\Pattern.cs" />
+ <Compile Include="DeviceMapClient.cs" />
+ <Compile Include="DeviceMapException.cs" />
+ <Compile Include="loaders\FileLoader.cs" />
+ <Compile Include="loaders\ILoader.cs" />
+ <Compile Include="loaders\Loader.cs" />
+ <Compile Include="loaders\UrlLoader.cs" />
+ <Compile Include="parser\XmlParser.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="util\Util.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ <None Include="DeviceMap.pfx" />
+ </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/devicemap/csharp/DeviceMap/DeviceMap.pfx
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/DeviceMap.pfx?rev=1609313&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/DeviceMap.pfx
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/DeviceMapClient.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/DeviceMapClient.cs?rev=1609313&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/csharp/DeviceMap/DeviceMapClient.cs (added)
+++ incubator/devicemap/trunk/devicemap/csharp/DeviceMap/DeviceMapClient.cs Wed Jul 9 21:42:02 2014
@@ -0,0 +1,204 @@
+#region "Header"
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+#endregion
+//
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text.RegularExpressions;
+//
+namespace DeviceMap
+{
+ /// <summary>
+ /// DeviceMap User-Agent Resolver
+ /// </summary>
+ /// <author>eberhard speer jr.</author>
+ /// <remarks>Apache DeviceMap Project .Net version
+ /// ported from Reza Naghibi's DeviceMapClient.java</remarks>
+ public sealed class DeviceMapClient
+ {
+ //
+ internal IDictionary<string, Device> devices;
+ internal IDictionary<string, List<Device>> patterns;
+
+ #region "Properties"
+ /// <summary>
+ /// Returns number of Devices in Device data
+ /// </summary>
+ /// <returns>Integer</returns>
+ /// <remarks>-</remarks>
+ public int DeviceCount
+ {
+ get { return devices.Count; }
+ }
+ /// <summary>
+ /// Returns number of Device Patterns in Device pattern data
+ /// </summary>
+ /// <returns>Integer</returns>
+ /// <remarks>-</remarks>
+ public int PatternCount
+ {
+ get { return patterns.Count; }
+ }
+ /// <summary>
+ /// Main Release and build version
+ /// </summary>
+ /// <returns>String</returns>
+ /// <remarks>-</remarks>
+ public string Version
+ {
+ get { return string.Format(Constants.VERSION_FORMAT, Constants.RELEASE_VERSION, System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()); }
+ }
+ #endregion
+
+ #region "Constructor"
+ /// <summary>
+ /// New Device User-Agent Resolver
+ /// </summary>
+ /// <remarks>-</remarks>
+ public DeviceMapClient()
+ {
+ devices = new Dictionary<string, Device>();
+ patterns = new Dictionary<string, List<Device>>();
+ devices = new Loader().Devices;
+ CreateIndex();
+ }
+ #endregion
+
+ #region "Methods"
+ /// <summary>
+ /// Create Device and Pattern Index
+ /// </summary>
+ /// <remarks>-</remarks>
+ private void CreateIndex()
+ {
+ foreach (Device device in devices.Values)
+ {
+ foreach (IList<string> patternset in device.Patterns.Patterns)
+ {
+ for (int i = 0; i <= patternset.Count - 1; i++)
+ {
+ string pattern = patternset[i];
+ // deal with duplicates
+ if (patterns.ContainsKey(pattern))
+ {
+ if (i == (patternset.Count - 1) && !patterns[pattern].Contains(device))
+ {
+ patterns[pattern].Add(device);
+ }
+ }
+ else
+ {
+ List<Device> subList = new List<Device>();
+ subList.Add(device);
+ if (patterns.ContainsKey(pattern))
+ {
+ patterns[pattern] = subList;
+ }
+ else
+ {
+ patterns.Add(pattern, subList);
+ }
+
+ }
+ }
+ }
+ }
+ }
+ #endregion
+
+ #region "Functions"
+ /// <summary>
+ /// Main Resolver function : Returns Attribute dictionary for device resolved from useragent
+ /// </summary>
+ /// <param name="useragent">user-agent string to resolve</param>
+ /// <returns>IDictionary(Of String, String)</returns>
+ /// <remarks>-</remarks>
+ public IDictionary<string, string> Map(string useragent)
+ {
+ if (string.IsNullOrEmpty(useragent))
+ {
+ return null;
+ }
+ Dictionary<string, IList<Device>> hits = new Dictionary<string, IList<Device>>();
+ Device winner = null;
+ string winnerStr = string.Empty;
+ // The Split
+ string[] parts = Regex.Split(useragent, " |-|_|/|\\\\|\\[|\\]|\\(|\\)|;");
+ for (int i = 0; i <= parts.Length - 1; i++)
+ {
+
+ string pattern = "";
+ int j = 0;
+ while (j < 4 && (j + i) < parts.Length)
+ {
+ if (!string.IsNullOrEmpty(parts[i + j]))
+ {
+ pattern += Util.Normalize(parts[i + j]);
+
+ if (patterns.ContainsKey(pattern))
+ {
+ hits[pattern] = patterns[pattern];
+ }
+ }
+ j += 1;
+ }
+
+ }
+ foreach (string hit in hits.Keys)
+ {
+ foreach (Device device in hits[hit])
+ {
+ if (device.Patterns.isValid(hits.Keys.ToList()))
+ {
+ if (winner != null)
+ {
+ if ("simple".Equals(winner.Type) && !"simple".Equals(device.Type))
+ {
+ winner = device;
+ winnerStr = hit;
+ }
+ else if (hit.Length > winnerStr.Length && (!"simple".Equals(device.Type) || device.Type.Equals(winner.Type)))
+ {
+ winner = device;
+ winnerStr = hit;
+ }
+ }
+ else
+ {
+ winner = device;
+ winnerStr = hit;
+ }
+ }
+ }
+ }
+ if (winner != null)
+ {
+ return winner.Attributes;
+ }
+ else
+ {
+ return null;
+ }
+ }
+ #endregion
+ }
+}
\ No newline at end of file
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/DeviceMapException.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/DeviceMapException.cs?rev=1609313&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/csharp/DeviceMap/DeviceMapException.cs (added)
+++ incubator/devicemap/trunk/devicemap/csharp/DeviceMap/DeviceMapException.cs Wed Jul 9 21:42:02 2014
@@ -0,0 +1,38 @@
+#region "Header"
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+#endregion
+//
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+/// <summary>
+/// DeviceMap Exception
+/// </summary>
+/// <remarks>-</remarks>
+[Serializable]
+public sealed class DeviceMapException : ApplicationException
+{
+ public DeviceMapException(string msg, Exception ex)
+ : base(msg, ex)
+ {
+ }
+}
\ No newline at end of file
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/Properties/AssemblyInfo.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/Properties/AssemblyInfo.cs?rev=1609313&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/csharp/DeviceMap/Properties/AssemblyInfo.cs (added)
+++ incubator/devicemap/trunk/devicemap/csharp/DeviceMap/Properties/AssemblyInfo.cs Wed Jul 9 21:42:02 2014
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("DeviceMap")]
+[assembly: AssemblyDescription(".Net version of DeviceMap Client")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("ASF")]
+[assembly: AssemblyProduct("DeviceMap")]
+[assembly: AssemblyCopyright("Copyright © ASF 2013")]
+[assembly: AssemblyTrademark("dmap_20130709")]
+[assembly: AssemblyCulture("")]
+[assembly: System.CLSCompliant(true)]
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("92d30cdd-0e93-4bd8-a588-9563cbbd51e4")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.7.7.27")]
+[assembly: AssemblyFileVersion("1.7.7.27")]
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.dll
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.dll?rev=1609313&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.dll
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.dll.config
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.dll.config?rev=1609313&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.dll.config (added)
+++ incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.dll.config Wed Jul 9 21:42:02 2014
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
+ </startup>
+</configuration>
\ No newline at end of file
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.pdb
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.pdb?rev=1609313&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.pdb
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.vshost.exe
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.vshost.exe?rev=1609313&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.vshost.exe
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.vshost.exe.config
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.vshost.exe.config?rev=1609313&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.vshost.exe.config (added)
+++ incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Debug/DeviceMap.vshost.exe.config Wed Jul 9 21:42:02 2014
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
+ </startup>
+</configuration>
\ No newline at end of file
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Release/DeviceMap.dll
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Release/DeviceMap.dll?rev=1609313&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Release/DeviceMap.dll
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Release/DeviceMap.dll.config
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Release/DeviceMap.dll.config?rev=1609313&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Release/DeviceMap.dll.config (added)
+++ incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Release/DeviceMap.dll.config Wed Jul 9 21:42:02 2014
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
+ </startup>
+</configuration>
\ No newline at end of file
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Release/DeviceMap.pdb
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Release/DeviceMap.pdb?rev=1609313&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/bin/Release/DeviceMap.pdb
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/data/Device.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/data/Device.cs?rev=1609313&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/csharp/DeviceMap/data/Device.cs (added)
+++ incubator/devicemap/trunk/devicemap/csharp/DeviceMap/data/Device.cs Wed Jul 9 21:42:02 2014
@@ -0,0 +1,116 @@
+#region "Header"
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+#endregion
+//
+using System.Collections.Generic;
+//
+namespace DeviceMap
+{
+ /// <summary>
+ /// Device data
+ /// </summary>
+ /// <author>eberhard speer jr.</author>
+ /// <remarks>Apache DeviceMap Project .Net version<br />
+ /// ported from Reza Naghibi's Device.java</remarks>
+ internal sealed class Device
+ {
+ //
+ private string builderType = string.Empty;
+ private string deviceId = string.Empty;
+ private string deviceParent = string.Empty;
+ private Pattern pattern;
+ private IDictionary<string, string> properties;
+
+ #region "Properties"
+ /// <summary>
+ /// Property dictionary
+ /// </summary>
+ /// <returns>IDictionary(Of String, String)</returns>
+ /// <remarks>-</remarks>
+ public IDictionary<string, string> Attributes
+ {
+ get { return properties; }
+ set { properties = value; }
+ }
+ /// <summary>
+ /// Unique Id
+ /// </summary>
+ /// <returns>String</returns>
+ /// <remarks>-</remarks>
+ public string Id
+ {
+ get { return deviceId; }
+ set { deviceId = value; }
+ }
+ /// <summary>
+ /// Unique Parent Id
+ /// </summary>
+ /// <returns>String</returns>
+ /// <remarks>-</remarks>
+ public string ParentId
+ {
+ get { return deviceParent; }
+ set { deviceParent = value; }
+ }
+ /// <summary cref="Pattern">
+ /// Pattern collection
+ /// </summary>
+ /// <returns>Pattern</returns>
+ /// <remarks>Collection of patterns to match with User-Agent string</remarks>
+ public Pattern Patterns
+ {
+ get { return pattern; }
+ }
+ /// <summary>
+ /// Builder type
+ /// </summary>
+ /// <returns>String</returns>
+ /// <remarks>used to destinguish between 'simple' and 'two-step' device builders</remarks>
+ public string Type
+ {
+ get { return builderType; }
+ set { builderType = value; }
+ }
+ #endregion
+
+ #region "Constructor"
+ /// <summary>
+ /// Default new Device
+ /// </summary>
+ /// <remarks>-</remarks>
+ public Device()
+ {
+ pattern = new Pattern();
+ }
+ #endregion
+
+ #region "Functions"
+ /// <summary>
+ /// To String override
+ /// </summary>
+ /// <returns>String</returns>
+ /// <remarks>-</remarks>
+ public override string ToString()
+ {
+ return string.Format(Constants.DEVICE_TOSTRING_FORMAT, deviceId, deviceParent, builderType, pattern.ToString(), properties.ToString());
+ }
+ #endregion
+ }
+}
\ No newline at end of file
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/data/Pattern.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/data/Pattern.cs?rev=1609313&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/csharp/DeviceMap/data/Pattern.cs (added)
+++ incubator/devicemap/trunk/devicemap/csharp/DeviceMap/data/Pattern.cs Wed Jul 9 21:42:02 2014
@@ -0,0 +1,137 @@
+#region "Header"
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+#endregion
+//
+using System.Collections.Generic;
+using System.Text;
+//
+namespace DeviceMap
+{
+ /// <summary>
+ /// Device Pattern data
+ /// </summary>
+ /// <author>eberhard speer jr.</author>
+ /// <remarks>Apache DeviceMap Project .Net version
+ /// ported from Reza Naghibi's Pattern.java</remarks>
+ internal sealed class Pattern
+ {
+ //
+ private IList<IList<string>> patternList;
+
+ #region "Properties"
+ /// <summary>
+ /// List of Patterns which <em>all</em> must occur in User-Agent string for a match
+ /// </summary>
+ /// <remarks>-</remarks>
+ public IList<string> AndPattern
+ {
+ set { patternList.Add(value); }
+ }
+ /// <summary>
+ /// List of Patterns of which <em>at least one</em> must occur in User-Agent string for a match
+ /// </summary>
+ /// <remarks>-</remarks>
+ public IList<string> OrPattern
+ {
+ set
+ {
+ foreach (string patternString in value)
+ {
+ AddPattern = patternString;
+ }
+ }
+ }
+ /// <summary>
+ /// List of Patterns to match with User-Agent string
+ /// </summary>
+ /// <remarks>-</remarks>
+ public string AddPattern
+ {
+ set
+ {
+ IList<string> subList = new List<string>();
+ subList.Add(value);
+ patternList.Add(subList);
+ }
+ }
+ /// <summary>
+ /// List of Patterns Lists to match with User-Agent string
+ /// </summary>
+ /// <returns>IList(Of IList(Of String))</returns>
+ /// <remarks></remarks>
+ public IList<IList<string>> Patterns
+ {
+ get { return patternList; }
+ }
+ #endregion
+
+ #region "Constructor"
+ /// <summary>
+ /// Default new Device Pattern data
+ /// </summary>
+ /// <remarks>-</remarks>
+ public Pattern()
+ {
+ patternList = new List<IList<string>>();
+ }
+ #endregion
+
+ #region "Functions"
+ /// <summary>
+ /// Returns true if one of the patterns in patternList occurs in Device Pattern data
+ /// </summary>
+ /// <param name="patternList">List(Of String)</param>
+ /// <returns>Boolean</returns>
+ /// <remarks>-</remarks>
+ public bool isValid(List<string> patternList)
+ {
+ bool found = false;
+ foreach (IList<string> patternset in Patterns)
+ {
+ foreach (string pattern in patternset)
+ {
+ if (!patternList.Contains(pattern))
+ {
+ goto patternsContinue;
+ }
+ }
+ found = true;
+ break;
+ patternsContinue: ;
+ }
+ return found;
+ }
+ /// <summary>
+ /// To String override
+ /// </summary>
+ /// <returns>String</returns>
+ /// <remarks>-</remarks>
+ public override string ToString()
+ {
+ StringBuilder builder = new StringBuilder();
+ foreach (List<string> sublist in patternList)
+ {
+ builder.AppendFormat("'{0}',", string.Join(",", sublist.ToArray()));
+ }
+ return builder.ToString().TrimEnd(',');
+ }
+ #endregion
+ }
+}
\ No newline at end of file
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/FileLoader.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/FileLoader.cs?rev=1609313&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/FileLoader.cs (added)
+++ incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/FileLoader.cs Wed Jul 9 21:42:02 2014
@@ -0,0 +1,87 @@
+#region "Header"
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+#endregion // Header
+//
+using System.IO;
+//
+namespace DeviceMap
+{
+ /// <summary>
+ /// Load XML resources from local file
+ /// </summary>
+ /// <remarks>-</remarks>
+ internal sealed class FileLoader //: ILoader
+ {
+ //
+ private long resLength { get; set; }
+ private StreamReader resReader { get; set; }
+ private string resUrl { get; set; }
+ //
+ #region "Properties"
+ /// <summary>
+ /// Resource path
+ /// </summary>
+ /// <returns>String</returns>
+ /// <remarks>-</remarks>
+ public string Path
+ {
+ get { return resUrl; }
+ }
+ /// <summary>
+ /// Returns the resource file length
+ /// </summary>
+ /// <returns>Long</returns>
+ /// <remarks>file length</remarks>
+ public long ResponseLength
+ {
+ get { return resLength; }
+ }
+ /// <summary>
+ /// Reader
+ /// </summary>
+ /// <returns>StreamReader</returns>
+ /// <remarks>-</remarks>
+ public StreamReader Reader
+ {
+ get { return resReader; }
+ }
+ #endregion // Properties
+
+ #region "Constructor"
+ /// <summary>
+ /// Load resource for path string
+ /// </summary>
+ /// <param name="filePath">path and file name of resource file</param>
+ /// <exception cref="ArgumentException">thrown when file does not exist</exception>
+ /// <remarks>-</remarks>
+ public FileLoader(string filePath)
+ {
+ resUrl = filePath.Trim();
+ if (File.Exists(resUrl))
+ {
+ resLength = new FileInfo(filePath).Length;
+ resReader = new StreamReader(resUrl);
+ }
+ else
+ {
+ throw new System.ArgumentException(string.Format(Constants.FILE_ERROR_FORMAT, resUrl));
+ }
+ }
+ #endregion ' Constructor
+ }
+}
\ No newline at end of file
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/ILoader.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/ILoader.cs?rev=1609313&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/ILoader.cs (added)
+++ incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/ILoader.cs Wed Jul 9 21:42:02 2014
@@ -0,0 +1,45 @@
+#region "Header"
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+#endregion ' Header
+//
+using System.IO;
+//
+namespace DeviceMap
+{
+ public interface ILoader
+ {
+ /// <summary>
+ /// Resource URI
+ /// </summary>
+ /// <returns>String</returns>
+ /// <remarks>-</remarks>
+ string Path { get; }
+ /// <summary>
+ /// Response Lenght
+ /// </summary>
+ /// <returns>Long</returns>
+ /// <remarks>-</remarks>
+ long ResponseLength { get; }
+ /// <summary>
+ /// Reader
+ /// </summary>
+ /// <returns>StreamReader</returns>
+ /// <remarks>-</remarks>
+ StreamReader Reader { get; }
+ }
+}
\ No newline at end of file
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/Loader.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/Loader.cs?rev=1609313&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/Loader.cs (added)
+++ incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/Loader.cs Wed Jul 9 21:42:02 2014
@@ -0,0 +1,300 @@
+#region "Header"
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+#endregion ' Header
+//
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.IO;
+//
+namespace DeviceMap
+{
+ /// <summary>
+ /// Load Device and Pattern data from StreamReader
+ /// </summary>
+ /// <author>eberhard speer jr.</author>
+ /// <remarks>-</remarks>
+ internal sealed class Loader
+ {
+ //
+ private IDictionary<string, Device> deviceList { get; set; }
+
+ #region "Properties"
+ /// <summary>
+ /// Returns Device data dictionary
+ /// </summary>
+ /// <returns>IDictionary(Of String, Device)</returns>
+ /// <remarks>-</remarks>
+ public IDictionary<string, Device> Devices
+ {
+ get { return deviceList; }
+ }
+ #endregion ' Properties
+
+ #region "Constructor"
+ /// <summary>
+ /// Default new Device data Loader
+ /// </summary>
+ /// <exception cref="DeviceMapException">Thrown when (InnerException)<ul>
+ /// <li>NullReferenceException : DeviceMap ConnectionStrings missing in config file</li>
+ /// <li>WebException : URL Loader exception</li>
+ /// <li>ArgumentException : File Loader exception</li>
+ /// <li>ArgumentException : Loader exception</li>
+ /// </ul>
+ /// </exception>
+ /// <remarks>-</remarks>
+ public Loader()
+ {
+ deviceList = new Dictionary<string, Device>();
+ try
+ {
+ string folder = ConfigurationManager.ConnectionStrings[Constants.APP_NAME].ToString().Trim().ToLowerInvariant();
+ // Devices
+ string[] devs = { Constants.DEVICE_DATA, Constants.DEVICE_DATA_PATCH };
+ string[] patts = { Constants.BUILDER_DATA, Constants.BUILDER_DATA_PATCH };
+ if (folder.StartsWith(Constants.HTTP_PREFIX))
+ {
+ char[] fs = { '/' };
+ folder = folder.TrimEnd(fs);
+
+ foreach (string xmlFile in devs)
+ {
+ LoadDeviceData(new UrlLoader(string.Format("{0}/{1}", folder, xmlFile)).Reader);
+ }
+ // Patterns
+ foreach (string xmlFile in patts)
+ {
+ LoadDevicePatterns(new UrlLoader(string.Format("{0}/{1}", folder, xmlFile)).Reader);
+ }
+ }
+ else
+ {
+ char[] bs = { '\\' };
+ folder = folder.TrimEnd(bs);
+ // Devices
+ foreach (string xmlFile in devs)
+ {
+ LoadDeviceData(new FileLoader(string.Format("{0}/{1}", folder, xmlFile)).Reader);
+ }
+ // Patterns
+ foreach (string xmlFile in patts)
+ {
+ LoadDevicePatterns(new FileLoader(string.Format("{0}/{1}", folder, xmlFile)).Reader);
+ }
+ }
+ }
+ catch (System.NullReferenceException ex)
+ {
+ throw new DeviceMapException(string.Format(Constants.CONFIG_ERROR_CONN_FORMAT, AppDomain.CurrentDomain.SetupInformation.ConfigurationFile), ex);
+ }
+ catch (System.Net.WebException ex)
+ {
+ throw new DeviceMapException(string.Format(Constants.WEB_ERROR_FORMAT, ex.Message), ex);
+ }
+ catch (System.ArgumentException ex)
+ {
+ throw new DeviceMapException(ex.Message, ex);
+ }
+ catch (System.Exception ex)
+ {
+ throw new DeviceMapException(ex.Message, ex);
+ }
+ }
+ #endregion ' Constructor
+
+ #region "Methods"
+ /// <summary>
+ /// Load Device data from StreamReader
+ /// </summary>
+ /// <param name="inSteam">StreamReader</param>
+ /// <remarks>-</remarks>
+ private void LoadDeviceData(StreamReader inSteam)
+ {
+ XmlParser parser = new XmlParser(inSteam);
+ string tag = string.Empty;
+ try
+ {
+ Device device = new Device();
+ Dictionary<string, string> attributes = new Dictionary<string, string>();
+ while ((tag = parser.NextTag).Length > 0)
+ {
+ if (tag.StartsWith("<device "))
+ {
+ device.Id = XmlParser.getAttribute(tag, "id");
+ device.ParentId = XmlParser.getAttribute(tag, "parentId");
+ }
+ else if (tag.Equals("</device>"))
+ {
+ if (!string.IsNullOrEmpty(device.Id))
+ {
+ attributes["id"] = device.Id;
+ device.Attributes = attributes;
+ if (Devices.ContainsKey(device.Id))
+ {
+ Devices[device.Id] = device;
+ }
+ else
+ {
+ Devices.Add(device.Id, device);
+ }
+ }
+ // reset
+ device = new Device();
+ attributes = new Dictionary<string, string>();
+ }
+ else if (tag.StartsWith("<property "))
+ {
+ string key = XmlParser.getAttribute(tag, "name");
+ string value = XmlParser.getAttribute(tag, "value");
+ attributes[key] = value;
+ }
+ }
+ }
+ catch (System.Exception ex)
+ {
+ throw new System.ArgumentException(string.Format("loadDeviceData : {0}", ex.Message), ex);
+ }
+ }
+ /// <summary>
+ /// Load Device Pattern data from StreamReader
+ /// </summary>
+ /// <param name="inStream">StreamReader</param>
+ /// <remarks></remarks>
+ private void LoadDevicePatterns(StreamReader inStream)
+ {
+ XmlParser parser = new XmlParser(inStream);
+ string tag = "";
+ try
+ {
+ string builder = "";
+ Device device = null;
+ string id = "";
+ List<string> patterns = new List<string>();
+ while ((tag = parser.NextTag).Length > 0)
+ {
+ if (tag.StartsWith("<builder "))
+ {
+ builder = XmlParser.getAttribute(tag, "class");
+ if (builder.LastIndexOf(".") >= 0)
+ {
+ builder = builder.Substring(builder.LastIndexOf(".") + 1);
+ }
+ }
+ else if (tag.StartsWith("<device "))
+ {
+ device = Devices[XmlParser.getAttribute(tag, "id")];
+ }
+ else if (tag.Equals("</device>"))
+ {
+ if (device != null)
+ {
+ if (builder.Equals("TwoStepDeviceBuilder"))
+ {
+ device.Patterns.AndPattern = patterns;
+ string unigram = "";
+ foreach (string pattern in patterns)
+ {
+ if (pattern.Contains(unigram))
+ {
+ unigram = pattern;
+ }
+ else
+ {
+ unigram += pattern;
+ }
+ }
+ device.Patterns.AddPattern = unigram;
+ }
+ else
+ {
+ device.Patterns.OrPattern = patterns;
+ }
+ if (builder.Equals("SimpleDeviceBuilder"))
+ {
+ device.Type = "simple";
+ }
+ else
+ {
+ device.Type = "weak";
+ }
+ }
+ else
+ {
+ Util.Log("ERROR: device not found: '" + id + "'");
+ }
+ // reset
+ device = null;
+ id = "";
+ patterns = new List<string>();
+ }
+ else if (tag.Equals("<value>"))
+ {
+ string pattern = Util.Normalize(parser.TagValue);
+ if (string.IsNullOrEmpty(pattern))
+ {
+ continue;
+ }
+ patterns.Add(pattern);
+ }
+ }
+ }
+ catch (System.Exception ex)
+ {
+ throw new System.ArgumentException(string.Format("loadDevicePatterns : {0}", ex.Message), ex);
+ }
+ }
+ /// <summary>
+ /// Recursively add Device's Parent Attributes
+ /// </summary>
+ /// <param name="device">Device</param>
+ /// <remarks>-</remarks>
+ private void MergeParent(Device device)
+ {
+ string parentId = device.ParentId;
+ if (string.IsNullOrEmpty(parentId))
+ {
+ return;
+ }
+ Device parent = null;
+ if (!deviceList.TryGetValue(parentId, out parent))
+ {
+ return;
+ }
+ MergeParent(parent);
+ foreach (string key in parent.Attributes.Keys)
+ {
+ if (!device.Attributes.ContainsKey(key))
+ {
+ device.Attributes[key] = parent.Attributes[key];
+ }
+ }
+ }
+ /// <summary>
+ /// Sets Parent device attributes
+ /// </summary>
+ /// <remarks>-</remarks>
+ private void setParentAttributes()
+ {
+ foreach (Device device in deviceList.Values)
+ {
+ MergeParent(device);
+ }
+ }
+ #endregion ' Methods
+ }
+}
\ No newline at end of file
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/UrlLoader.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/UrlLoader.cs?rev=1609313&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/UrlLoader.cs (added)
+++ incubator/devicemap/trunk/devicemap/csharp/DeviceMap/loaders/UrlLoader.cs Wed Jul 9 21:42:02 2014
@@ -0,0 +1,105 @@
+#region "Header"
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+#endregion ' Header
+//
+using System;
+using System.IO;
+using System.Net;
+/// <summary>
+/// Load XML resources from URL
+/// </summary>
+/// <remarks>-</remarks>
+internal sealed class UrlLoader //: ILoader
+{
+ /// <summary>
+ /// Resource URI
+ /// </summary>
+ /// <returns>String</returns>
+ /// <remarks>-</remarks>
+ public string Path
+ {
+ get
+ {
+ return this.resUrl;
+ }
+ }
+
+ /// <summary>
+ /// Reader
+ /// </summary>
+ /// <returns>StreamReader</returns>
+ /// <remarks>-</remarks>
+ public StreamReader Reader
+ {
+ get
+ {
+ return this.resReader;
+ }
+ }
+
+ private long resLength
+ {
+ get;
+ set;
+ }
+
+ public long ResponseLenght
+ {
+ get
+ {
+ return this.resLength;
+ }
+ }
+
+ private StreamReader resReader
+ {
+ get;
+ set;
+ }
+
+ private string resUrl
+ {
+ get;
+ set;
+ }
+
+ public UrlLoader(string url)
+ {
+ this.resLength = (long)-1;
+ this.resReader = null;
+ this.resUrl = string.Empty;
+ this.resUrl = url.Trim();
+ int resStatus = 0;
+ HttpWebRequest ddrRequest = (HttpWebRequest)WebRequest.Create(new Uri(this.resUrl));
+ ddrRequest.UserAgent = string.Format("{0} {1}", "org.apache.devicemap.client", "1.0");
+ ddrRequest.AllowAutoRedirect = false;
+ WebResponse ddrResponse = ddrRequest.GetResponse();
+ resStatus = (int)((HttpWebResponse)ddrResponse).StatusCode;
+ int num = resStatus;
+ if (num != 200)
+ {
+ if (num <= 299)
+ {
+ throw new ArgumentException(string.Format("Weird HTTP Status code : {0}", resStatus.ToString()));
+ }
+ throw new ArgumentException(string.Format("HTTP Status code : {0}", resStatus.ToString()));
+ }
+ this.resLength = ddrResponse.ContentLength;
+ this.resReader = new StreamReader(ddrResponse.GetResponseStream());
+ }
+}
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache?rev=1609313&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/DeviceMap.csproj.FileListAbsolute.txt
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/DeviceMap.csproj.FileListAbsolute.txt?rev=1609313&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/DeviceMap.csproj.FileListAbsolute.txt (added)
+++ incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/DeviceMap.csproj.FileListAbsolute.txt Wed Jul 9 21:42:02 2014
@@ -0,0 +1,5 @@
+C:\esdev\VS2013\ASF\csharp\DeviceMap\DeviceMap\bin\Debug\DeviceMap.dll.config
+C:\esdev\VS2013\ASF\csharp\DeviceMap\DeviceMap\bin\Debug\DeviceMap.dll
+C:\esdev\VS2013\ASF\csharp\DeviceMap\DeviceMap\bin\Debug\DeviceMap.pdb
+C:\esdev\VS2013\ASF\csharp\DeviceMap\DeviceMap\obj\Debug\DeviceMap.dll
+C:\esdev\VS2013\ASF\csharp\DeviceMap\DeviceMap\obj\Debug\DeviceMap.pdb
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/DeviceMap.dll
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/DeviceMap.dll?rev=1609313&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/DeviceMap.dll
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/DeviceMap.pdb
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/DeviceMap.pdb?rev=1609313&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/DeviceMap.pdb
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs?rev=1609313&view=auto
==============================================================================
(empty)
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs?rev=1609313&view=auto
==============================================================================
(empty)
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs?rev=1609313&view=auto
==============================================================================
(empty)
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache?rev=1609313&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/DeviceMap.csproj.FileListAbsolute.txt
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/DeviceMap.csproj.FileListAbsolute.txt?rev=1609313&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/DeviceMap.csproj.FileListAbsolute.txt (added)
+++ incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/DeviceMap.csproj.FileListAbsolute.txt Wed Jul 9 21:42:02 2014
@@ -0,0 +1,5 @@
+C:\esdev\VS2013\ASF\csharp\DeviceMap\DeviceMap\bin\Release\DeviceMap.dll.config
+C:\esdev\VS2013\ASF\csharp\DeviceMap\DeviceMap\bin\Release\DeviceMap.dll
+C:\esdev\VS2013\ASF\csharp\DeviceMap\DeviceMap\bin\Release\DeviceMap.pdb
+C:\esdev\VS2013\ASF\csharp\DeviceMap\DeviceMap\obj\Release\DeviceMap.dll
+C:\esdev\VS2013\ASF\csharp\DeviceMap\DeviceMap\obj\Release\DeviceMap.pdb
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/DeviceMap.dll
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/DeviceMap.dll?rev=1609313&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/DeviceMap.dll
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/DeviceMap.pdb
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/DeviceMap.pdb?rev=1609313&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/DeviceMap.pdb
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs?rev=1609313&view=auto
==============================================================================
(empty)
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs?rev=1609313&view=auto
==============================================================================
(empty)
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/obj/Release/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs?rev=1609313&view=auto
==============================================================================
(empty)
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/parser/XmlParser.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/parser/XmlParser.cs?rev=1609313&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/csharp/DeviceMap/parser/XmlParser.cs (added)
+++ incubator/devicemap/trunk/devicemap/csharp/DeviceMap/parser/XmlParser.cs Wed Jul 9 21:42:02 2014
@@ -0,0 +1,172 @@
+#region "Header"
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+#endregion
+//
+using System;
+using System.IO;
+using System.Text;
+//
+namespace DeviceMap
+{
+ /// <summary>
+ /// XML Parser
+ /// </summary>
+ /// <author>eberhard speer jr.</author>
+ /// <remarks>Apache DeviceMap Project .Net version
+ /// ported from Reza Naghibi's XMLParser.java</remarks>
+ internal sealed class XmlParser
+ {
+ //
+ private System.IO.StreamReader inStream;
+ private char pre = '\0';
+
+ #region "Properties"
+ /// <summary>
+ /// Returns next XML tag in StreamReader
+ /// </summary>
+ /// <returns>String</returns>
+ /// <remarks>-</remarks>
+ public string NextTag
+ {
+ get
+ {
+ StringBuilder localBuilder = new StringBuilder();
+
+ int i = 0;
+ bool start = false;
+
+ if (pre == '<')
+ {
+ localBuilder.Append(pre);
+ pre = '\0';
+ start = true;
+ }
+
+ while ((i = inStream.Read()) != -1)
+ {
+ char c = (char)i;
+ if (c == '<')
+ {
+ start = true;
+ localBuilder.Append(c);
+ }
+ else if (c == '>')
+ {
+ localBuilder.Append(c);
+ break;
+ }
+ else if (start)
+ {
+ localBuilder.Append(c);
+ }
+ }
+
+ return localBuilder.ToString();
+ }
+ }
+ /// <summary>
+ /// Returns XML tag value from StreamReader
+ /// </summary>
+ /// <returns>String</returns>
+ /// <remarks>-</remarks>
+ public string TagValue
+ {
+ get
+ {
+ StringBuilder localBuilder = new StringBuilder();
+ int i = 0;
+ while ((i = inStream.Read()) != -1)
+ {
+ char c = (char)i;
+ if (c == '<')
+ {
+ pre = '<';
+ break;
+ }
+ else
+ {
+ localBuilder.Append(c);
+ }
+ }
+ return localBuilder.ToString().Trim();
+ }
+ }
+ #endregion
+
+ #region "Constructor"
+ /// <summary>
+ /// Prevent parameterless new
+ /// </summary>
+ /// <remarks>-</remarks>
+ private XmlParser()
+ {
+ // Nice !
+ }
+ /// <summary>
+ /// New XmlParser for StreamReader
+ /// </summary>
+ /// <param name="stream">StreamReader</param>
+ /// <remarks>-</remarks>
+ public XmlParser(System.IO.StreamReader stream)
+ {
+ inStream = stream;
+ }
+ #endregion
+
+ #region "Functions"
+ /// <summary>
+ /// Returns Attribute (Device property) value of tag with name
+ /// </summary>
+ /// <param name="tag">XML tag</param>
+ /// <param name="name">Attribute name</param>
+ /// <returns>String</returns>
+ /// <remarks>-</remarks>
+ public static string getAttribute(string tag, string name)
+ {
+ int retpos = tag.ToLower().IndexOf(name.ToLower() + "=");
+ if (retpos == -1)
+ {
+ return "";
+ }
+ string result = tag.Substring(retpos + name.Length + 1);
+ if (result.StartsWith("\""))
+ {
+ result = result.Substring(1);
+ int endpos = result.IndexOf("\"");
+ if (endpos == -1)
+ {
+ return "";
+ }
+ result = result.Substring(0, endpos);
+ }
+ else
+ {
+ int endpos = result.IndexOf(" ");
+ if (endpos == -1)
+ {
+ return "";
+ }
+ result = result.Substring(0, endpos);
+ }
+ return result;
+ }
+ #endregion
+ }
+}
\ No newline at end of file
Added: incubator/devicemap/trunk/devicemap/csharp/DeviceMap/util/Util.cs
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/csharp/DeviceMap/util/Util.cs?rev=1609313&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/csharp/DeviceMap/util/Util.cs (added)
+++ incubator/devicemap/trunk/devicemap/csharp/DeviceMap/util/Util.cs Wed Jul 9 21:42:02 2014
@@ -0,0 +1,149 @@
+#region "Header"
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+#endregion
+//
+using System;
+using System.Collections;
+using System.Diagnostics;
+using System.IO;
+using System.Text;
+//
+namespace DeviceMap
+{
+ public sealed class Util
+ {
+ // Private
+ /// <summary>
+ /// Exception to string
+ /// </summary>
+ /// <param name="id">some id</param>
+ /// <param name="ex">Exception</param>
+ /// <returns>String</returns>
+ /// <remarks>-</remarks>
+ private static string ExceptionToString(string id, Exception ex)
+ {
+ StringBuilder result = new StringBuilder();
+ if (!string.IsNullOrEmpty(id))
+ {
+ result.AppendLine(string.Format("Id : {0}", id));
+ }
+ result.AppendLine(string.Format("Message : {0}", ex.Message));
+ if (ex.Data.Count != 0)
+ {
+ result.AppendLine("Data : ");
+ foreach (DictionaryEntry de in ex.Data)
+ {
+ result.AppendLine(de.Key.ToString());
+ }
+ }
+ result.AppendLine(string.Format("Source : {0}", ex.Source));
+ result.AppendLine(string.Format("TargetSite : {0}", ex.TargetSite.ToString()));
+ result.AppendLine(string.Format("StackTrace : {0}", ex.StackTrace));
+ return result.ToString();
+ }
+ // Public
+ /// <summary>
+ /// Returns directory of config file of running assembly
+ /// </summary>
+ /// <returns>String</returns>
+ /// <remarks>-</remarks>
+ public static string Home()
+ {
+ return new FileInfo(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile).DirectoryName;
+ }
+ /// <summary>
+ /// Console debug messages
+ /// </summary>
+ /// <param name="msg">message</param>
+ /// <remarks>-</remarks>
+ public static void Log(string msg)
+ {
+ Log(msg, null);
+ }
+ /// <summary>
+ /// Console debug exception messages
+ /// </summary>
+ /// <param name="msg">message</param>
+ /// <param name="e">Exception</param>
+ /// <remarks>-</remarks>
+ public static void Log(string msg, Exception e)
+ {
+ Console.WriteLine(string.Format("{0} - {1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff"), msg));
+ if (e != null)
+ {
+ Console.WriteLine("Exception");
+ Console.WriteLine(ExceptionToString("console", e));
+ }
+ }
+ /// <summary>
+ /// Normalize pattern to letters and digits only
+ /// </summary>
+ /// <param name="dirty">string to normalize</param>
+ /// <returns>String</returns>
+ /// <remarks>-</remarks>
+ public static string Normalize(string dirty)
+ {
+ if (string.IsNullOrEmpty(dirty))
+ {
+ return dirty;
+ }
+ dirty = dirty.ToLower().Trim().Replace("[bb]", "b");
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i <= dirty.Length - 1; i++)
+ {
+ System.Nullable<char> c = dirty[i];
+ if (char.IsLetter(Convert.ToChar(c)) || char.IsDigit(Convert.ToChar(c)))
+ {
+ builder.Append(c);
+ }
+ }
+ return builder.ToString();
+ }
+ // public static
+ /// <summary>
+ /// Log Object to Application Log
+ /// </summary>
+ /// <param name="entryStr">String</param>
+ /// <param name="type">EventLogEntryType</param>
+ /// <remarks></remarks>
+ public static void WriteEntry(string appName, string entryStr, EventLogEntryType type = EventLogEntryType.Warning, Exception ex = null)
+ {
+ using (EventLog myLog = new EventLog())
+ {
+ myLog.Source = appName;
+ if (!EventLog.SourceExists(myLog.Source))
+ {
+ EventLog.CreateEventSource(myLog.Source, "Application");
+ }
+ if (ex != null)
+ {
+ entryStr = string.Format("{0} : {1}", entryStr, ExceptionToString("ex", ex));
+ }
+ byte[] btText = Encoding.UTF8.GetBytes(entryStr);
+ if (btText.Length > 32766)
+ {
+ // The message string is longer than 32766 bytes.
+ entryStr = BitConverter.ToString(btText, 0, 32760);
+ }
+ myLog.WriteEntry(entryStr, type);
+ }
+ }
+ }
+}
\ No newline at end of file