-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- DATA: Updated the Lite data files for September data - EXAMPLE/BUILD: Added all profiles example, and removed unnecessary - FEAT: WebProvider.Download now returns status code. - BUILD: Made sure every project in the solution is using x64 as the target - BUG/TEST: Changed the path which the auto update tests use. Former-commit-id: 914443b86b5d1d13ac225aa4ce65413ed1c7ed54
- Loading branch information
Showing
14 changed files
with
486 additions
and
202 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using FiftyOne.Example.Illustration.AllProfiles; | ||
using FiftyOne.Tests.Integration; | ||
|
||
namespace FiftyOne.Tests.Example | ||
{ | ||
[TestClass] | ||
public class AllProfiles | ||
{ | ||
[TestMethod] | ||
[TestCategory("Example"), TestCategory("Unit")] | ||
public void LiteExamples_All_Profiles() | ||
{ | ||
Program.Run( | ||
Utils.GetDataFile(Constants.LITE_PATTERN_V32)); | ||
} | ||
[TestMethod] | ||
[TestCategory("Example"), TestCategory("Unit")] | ||
public void PremiumExamples_All_Profiles() | ||
{ | ||
Program.Run( | ||
Utils.GetDataFile(Constants.PREMIUM_PATTERN_V32)); | ||
} | ||
[TestMethod] | ||
[TestCategory("Example"), TestCategory("Unit")] | ||
public void EnterpriseExamples_All_Profiles() | ||
{ | ||
Program.Run( | ||
Utils.GetDataFile(Constants.ENTERPRISE_PATTERN_V32)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.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>{EA6A83FE-D698-4E4D-821E-1B5BCC22D501}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>All_Profiles</RootNamespace> | ||
<AssemblyName>All Profiles</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<TargetFrameworkProfile /> | ||
</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 Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> | ||
<DebugSymbols>true</DebugSymbols> | ||
<OutputPath>bin\x64\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<DebugType>full</DebugType> | ||
<PlatformTarget>x64</PlatformTarget> | ||
<ErrorReport>prompt</ErrorReport> | ||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> | ||
<Prefer32Bit>true</Prefer32Bit> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> | ||
<OutputPath>bin\x64\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<Optimize>true</Optimize> | ||
<DebugType>pdbonly</DebugType> | ||
<PlatformTarget>x64</PlatformTarget> | ||
<ErrorReport>prompt</ErrorReport> | ||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> | ||
<Prefer32Bit>true</Prefer32Bit> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<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.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\FoundationV3\FiftyOne.Foundation 4.csproj"> | ||
<Project>{9d658044-fb65-4939-8449-a3a1debbb31a}</Project> | ||
<Name>FiftyOne.Foundation 4</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
/** | ||
* This Source Code Form is copyright of 51Degrees Mobile Experts Limited. | ||
* Copyright (c) 2015 51Degrees Mobile Experts Limited, 5 Charlotte Close, | ||
* Caversham, Reading, Berkshire, United Kingdom RG4 7BY | ||
* | ||
* This Source Code Form is the subject of the following patent | ||
* applications, owned by 51Degrees Mobile Experts Limited of 5 Charlotte | ||
* Close, Caversham, Reading, Berkshire, United Kingdom RG4 7BY: | ||
* European Patent Application No. 13192291.6; and | ||
* United States Patent Application Nos. 14/085,223 and 14/085,301. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. | ||
* | ||
* If a copy of the MPL was not distributed with this file, You can obtain | ||
* one at http://mozilla.org/MPL/2.0/. | ||
* | ||
* This Source Code Form is "Incompatible With Secondary Licenses", as | ||
* defined by the Mozilla Public License, v. 2.0. | ||
*/ | ||
|
||
/* | ||
<tutorial> | ||
All profiles example of using 51Degrees device detection. | ||
The example shows how to: | ||
<ol> | ||
<li>Initialise the 51Degrees data set | ||
<p><pre class="prettyprint lang-cs"> | ||
string fileName = args[0]; | ||
DataSet dataSet = StreamFactory.Create(fileName, false); | ||
</pre></p> | ||
<li>Open an output file to write the results to | ||
<p><pre class="prettyprint lang-cs"> | ||
StreamWriter fout = new StreamWriter(outputFile); | ||
</pre></p> | ||
<li>Write a header to the output file with the property names in | ||
<p><pre class="prettyprint lang-cs"> | ||
fout.Write("Id"); | ||
foreach (Property property in hardwareProperties) | ||
{ | ||
fout.Write("," + property.Name); | ||
} | ||
fout.Write("\n"); | ||
</pre></p> | ||
<li>Get all hardware profiles as an array | ||
<p><pre class="prettyprint lang-cs"> | ||
Profile[] hardwareProfiles = dataSet.Hardware.Profiles; | ||
</pre></p> | ||
<li>Get the values of a required property from a profile to write | ||
to the CSV file | ||
<p><pre class="prettyprint lang-cs"> | ||
foreach (Value value in profile.Values) | ||
{ | ||
if (value.Property == property) | ||
{ | ||
// Append this value to the string. | ||
values += value.ToString(); | ||
} | ||
} | ||
</pre></p> | ||
</ol> | ||
This tutorial assumes you are building this from within the | ||
51Degrees Visual Studio solution. Running the executable produced | ||
inside Visual Studio will ensure all the command line arguments | ||
are preset correctly. If you are running outside of Visual Studio, | ||
make sure to add the path to a 51Degrees data file as an argument. | ||
</tutorial> | ||
*/ | ||
using System; | ||
using System.Linq; | ||
using FiftyOne.Foundation.Mobile.Detection.Entities; | ||
using FiftyOne.Foundation.Mobile.Detection.Factories; | ||
using System.IO; | ||
|
||
namespace FiftyOne.Example.Illustration.AllProfiles | ||
{ | ||
public class Program | ||
{ | ||
// Snippet Start | ||
public static void Run(string fileName) | ||
{ | ||
// DataSet is the object used to interact with the data file. | ||
// StreamFactory creates Dataset with pool of binary readers to | ||
// perform device lookup using file on disk. | ||
DataSet dataSet = StreamFactory.Create(fileName, false); | ||
|
||
// Name of the output file results will be saved to. | ||
string outputFile = "AllProfilesOutput.csv"; | ||
|
||
// Get all the hardware profiles from the hardware component. | ||
Profile[] hardwareProfiles = dataSet.Hardware.Profiles; | ||
|
||
// Get all the hardware properties from the hardware component. | ||
// For the full list of properties see: | ||
// https://51degrees.com/resources/property-dictionary | ||
Property[] hardwareProperties = dataSet.Hardware.Properties; | ||
|
||
// Opens and output file. | ||
StreamWriter fout = new StreamWriter(outputFile); | ||
|
||
Console.WriteLine("Starting All Profiles Example."); | ||
|
||
// Print CSV headers to output file. | ||
fout.Write("Id"); | ||
foreach (Property property in hardwareProperties) | ||
{ | ||
fout.Write("," + property.Name); | ||
} | ||
fout.Write("\n"); | ||
|
||
// Loop over all devices. | ||
foreach (Profile profile in hardwareProfiles) | ||
{ | ||
// Write the device's profile id. | ||
fout.Write(profile.ProfileId); | ||
|
||
foreach (Property property in hardwareProperties) | ||
{ | ||
// Print the profile's values for the property. | ||
fout.Write(","); | ||
fout.Write(getProfileValues(profile, property)); | ||
} | ||
fout.Write("\n"); | ||
} | ||
|
||
fout.Close(); | ||
|
||
Console.WriteLine("Output Written to " + outputFile); | ||
|
||
// Finally close the dataset, releasing resources and file locks. | ||
dataSet.Dispose(); | ||
} | ||
|
||
/// <summary> | ||
/// Constructs a "|" separated string of all the values the profile has | ||
/// which relate to the supplied property. | ||
/// </summary> | ||
/// <param name="profile">Profile to get the values from.</param> | ||
/// <param name="property">Property to get the values for.</param> | ||
/// <returns>string of properties for the requested profile | ||
/// and property.</returns> | ||
static string getProfileValues(Profile profile, Property property) | ||
{ | ||
string values = ""; | ||
|
||
if (property.Category == "Javascript") | ||
{ | ||
// Prevents big chunks of javascript overrides from | ||
// being writen. | ||
return "N/A"; | ||
} | ||
|
||
bool firstValue = true; | ||
|
||
// Look though all the values in the profile and check if | ||
// they relate to the requested property. | ||
foreach (Value value in profile.Values) | ||
{ | ||
if (value.Property == property) | ||
{ | ||
if (!firstValue) | ||
{ | ||
// There are multiple values, so separate them. | ||
values += "|"; | ||
} | ||
else | ||
{ | ||
firstValue = false; | ||
} | ||
// Append this value to the string. | ||
values += value.ToString(); | ||
} | ||
} | ||
|
||
// Return the values string. | ||
return values; | ||
} | ||
// Snippet End | ||
|
||
static void Main(string[] args) | ||
{ | ||
string fileName = args.Length > 0 ? args[0] : "../../../../../data/51Degrees-LiteV3.2.dat"; | ||
Run(fileName); | ||
|
||
// Waits for a character to be pressed. | ||
Console.ReadKey(); | ||
} | ||
} | ||
} |
Oops, something went wrong.