Skip to content

test #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,27 @@ Generated_Code #added for RIA/Silverlight projects
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML

# Unwanted build and project files and folders
*.dll.refresh
*.r0*
*.r1*
*.r2*
*.r3*
*.r4*
*.r5*
*.r6*
*.r7*
*.r8*
*.r9*

# Unwanted IIS support files and folders
aspnet_client
_vti_cnf

# Unwanted IDE files and folders
_notes

# Unwanted temp, debug, cache and thumbnail files
Thumbs.db
.DS_Store
1 change: 1 addition & 0 deletions DDR-Simple-API/DDR-Simple-API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
<Compile Include="Exceptions\DDRException.cs" />
Expand Down
48 changes: 43 additions & 5 deletions DDR-Simple-API/Models/Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace W3c.Ddr.Models
{
Expand All @@ -41,9 +42,14 @@ public Properties()

public Properties(String file)
{
Reload(file);
Reload(file, "");
}

public Properties(String oddrPropertiesFilename, String relativeWebPath)
{
ReloadWeb(oddrPropertiesFilename, relativeWebPath);
}

public String GetProperty(String field, String defValue)
{
return (GetProperty(field) == null) ? (defValue) : (GetProperty(field));
Expand All @@ -52,6 +58,7 @@ public String GetProperty(String field, String defValue)
public String GetProperty(String field)
{
object oval = null;

if (list.TryGetValue(field, out oval))
{
return oval as string;
Expand Down Expand Up @@ -100,21 +107,38 @@ public void Save(String filename)

public void Reload()
{
Reload(this.filename);
Reload(this.filename, "");
}

public void Reload(String filename)
public void ReloadWeb(String oddrPropertiesFilename, String relativeWebPath)
{
if (!relativeWebPath.EndsWith("/"))
{
relativeWebPath += "/";
}

if (oddrPropertiesFilename.StartsWith("/"))
{
oddrPropertiesFilename = oddrPropertiesFilename.TrimStart('/');
}

oddrPropertiesFilename = HttpContext.Current.Server.MapPath(relativeWebPath + oddrPropertiesFilename);

Reload(oddrPropertiesFilename, relativeWebPath);
}

public void Reload(String filename, String relativeWebPath)
{
this.filename = filename;
list = new Dictionary<String, object>();

if (System.IO.File.Exists(filename))
LoadFromFile(filename);
LoadFromFile(filename, relativeWebPath);
else
System.IO.File.Create(filename);
}

private void LoadFromFile(String file)
private void LoadFromFile(String file, String relativeWebPath)
{
foreach (String line in System.IO.File.ReadAllLines(file))
{
Expand All @@ -136,6 +160,20 @@ private void LoadFromFile(String file)

try
{
if (!String.IsNullOrEmpty(relativeWebPath))
{
if (!relativeWebPath.EndsWith("/"))
{
relativeWebPath += "/";
}

if (value.Contains("/FILESYSTEM_PATH_TO_RESOURCES/"))
{
value = value.Replace("/FILESYSTEM_PATH_TO_RESOURCES/", relativeWebPath);
value = HttpContext.Current.Server.MapPath(value);
}
}

//ignore dublicates
list.Add(key, value);
}
Expand Down
16 changes: 14 additions & 2 deletions OpenDDR-CSharp.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual C# Express 2010
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenDDR-CSharp", "OpenDDR-CSharp\OpenDDR-CSharp.csproj", "{67A3A231-64F0-49F2-BD02-316995E7A737}"
ProjectSection(ProjectDependencies) = postProject
{F802E34F-10F1-4334-9099-3F1579DC4F06} = {F802E34F-10F1-4334-9099-3F1579DC4F06}
Expand All @@ -10,6 +10,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DDR-Simple-API", "DDR-Simpl
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenDDRTest", "OpenDDRTest\OpenDDRTest.csproj", "{C1ECDE8F-0B77-422D-B4B6-0CF2239C7FA2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenDDRWebTest", "OpenDDRWebTest\OpenDDRWebTest\OpenDDRWebTest.csproj", "{AFBB0ACD-D9D9-4EED-8DBC-4E5A0EA7EDBD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -50,6 +52,16 @@ Global
{C1ECDE8F-0B77-422D-B4B6-0CF2239C7FA2}.Release|Mixed Platforms.Build.0 = Release|x86
{C1ECDE8F-0B77-422D-B4B6-0CF2239C7FA2}.Release|x86.ActiveCfg = Release|x86
{C1ECDE8F-0B77-422D-B4B6-0CF2239C7FA2}.Release|x86.Build.0 = Release|x86
{AFBB0ACD-D9D9-4EED-8DBC-4E5A0EA7EDBD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AFBB0ACD-D9D9-4EED-8DBC-4E5A0EA7EDBD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AFBB0ACD-D9D9-4EED-8DBC-4E5A0EA7EDBD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{AFBB0ACD-D9D9-4EED-8DBC-4E5A0EA7EDBD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{AFBB0ACD-D9D9-4EED-8DBC-4E5A0EA7EDBD}.Debug|x86.ActiveCfg = Debug|Any CPU
{AFBB0ACD-D9D9-4EED-8DBC-4E5A0EA7EDBD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AFBB0ACD-D9D9-4EED-8DBC-4E5A0EA7EDBD}.Release|Any CPU.Build.0 = Release|Any CPU
{AFBB0ACD-D9D9-4EED-8DBC-4E5A0EA7EDBD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{AFBB0ACD-D9D9-4EED-8DBC-4E5A0EA7EDBD}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{AFBB0ACD-D9D9-4EED-8DBC-4E5A0EA7EDBD}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
153 changes: 153 additions & 0 deletions OpenDDR-CSharp/Builders/Browsers/ChromeMobileBrowserBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/**
* 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 Oddr.Models.Browsers;

namespace Oddr.Builders.Browsers
{
class ChromeMobileBrowserBuilder : LayoutEngineBrowserBuilder
{
private const String VERSION_REGEXP = "(?:.*Chrome/([0-9\\.]+).*?)|(?:.*CriOS/([0-9\\.]+).*?)";
private const String SAFARI_REGEXP = ".*Safari/([0-9\\.]+).*?";
private static Regex versionRegex = new Regex(VERSION_REGEXP, RegexOptions.Compiled);
private static Regex safariRegex = new Regex(SAFARI_REGEXP, RegexOptions.Compiled);

protected override Browser BuildBrowser(UserAgent userAgent, string layoutEngine, string layoutEngineVersion, int hintedWidth, int hintedHeight)
{
if (!userAgent.mozillaPattern || !userAgent.completeUserAgent.Contains("Mobile"))
{
return null;
}

int confidence = 70;
Browser identified = new Browser();

identified.SetVendor("Google");
identified.SetModel("Chrome");

if (versionRegex.IsMatch(userAgent.completeUserAgent))
{
Match versionMatcher = versionRegex.Match(userAgent.completeUserAgent);
GroupCollection groups = versionMatcher.Groups;
if (groups[1] != null && groups[1].Value.Trim().Length > 0)
{
identified.SetVersion(groups[1].Value);
string versionFullString = groups[1].Value;
String[] version = versionFullString.Split(".".ToCharArray());

if (version.Length > 0)
{
identified.majorRevision = version[0];
}

if (version.Length > 1)
{
identified.minorRevision = version[1];
confidence += 10;
}

if (version.Length > 2)
{
identified.microRevision = version[2];
}

if (version.Length > 3)
{
identified.nanoRevision = version[3];
}
}
else if (groups[2] != null && groups[2].Value.Trim().Length > 0)
{
identified.SetVersion(groups[2].Value);
string versionFullString = groups[2].Value;
String[] version = versionFullString.Split(".".ToCharArray());

if (version.Length > 0)
{
identified.majorRevision = version[0];
}

if (version.Length > 1)
{
identified.minorRevision = version[1];
confidence += 10;
}

if (version.Length > 2)
{
identified.microRevision = version[2];
}

if (version.Length > 3)
{
identified.nanoRevision = version[3];
}
}
}
else
{
//fallback version
identified.SetVersion("18.0");
identified.majorRevision = "18";
}

if (layoutEngine != null)
{
identified.SetLayoutEngine(layoutEngine);
identified.SetLayoutEngineVersion(layoutEngineVersion);

if (layoutEngine.Equals(LayoutEngineBrowserBuilder.APPLEWEBKIT))
{
confidence += 10;
}
}

if (safariRegex.IsMatch(userAgent.completeUserAgent))
{
Match safariMatch = safariRegex.Match(userAgent.completeUserAgent);
GroupCollection groups = safariMatch.Groups;
if (groups[1] != null && groups[1].Value.Trim().Length > 0)
{
identified.SetReferenceBrowser("Safari");
identified.SetReferenceBrowserVersion(groups[1].Value);
confidence += 10;
}
}

identified.SetDisplayWidth(hintedWidth);
identified.SetDisplayHeight(hintedHeight);
identified.confidence = confidence;

return identified;
}

public override bool CanBuild(UserAgent userAgent)
{
return ((userAgent.containsAndroid || userAgent.containsIOSDevices) && (userAgent.completeUserAgent.Contains("Chrome") || userAgent.completeUserAgent.Contains("CriOS")));
}
}
}
3 changes: 2 additions & 1 deletion OpenDDR-CSharp/Builders/Browsers/DefaultBrowserBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ private DefaultBrowserBuilder()
builders = new IBuilder[]
{
new OperaMiniBrowserBuilder(),
new ChromeMobileBrowserBuilder(),
new FennecBrowserBuilder(),
new SafariMobileBrowserBuilder(),
new SilkBrowserBuilder(),
new AndroidMobileBrowserBuilder(),
Expand All @@ -55,7 +57,6 @@ private DefaultBrowserBuilder()
new IEMobileBrowserBuilder(),
new NokiaBrowserBuilder(),
new BlackBerryBrowserBuilder(),
new FennecBrowserBuilder(),
new WebOsBrowserBuilder(),
new InternetExplorerBrowserBuilder(),
new ChromeBrowserBuilder(),
Expand Down
39 changes: 38 additions & 1 deletion OpenDDR-CSharp/Builders/Browsers/FennecBrowserBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,43 @@ protected override Browser BuildBrowser(UserAgent userAgent, string layoutEngine
}

}
else if (firefoxVersionRegex.IsMatch(userAgent.completeUserAgent))
{
Match firefoxMatcher = firefoxVersionRegex.Match(userAgent.completeUserAgent);
GroupCollection groups = firefoxMatcher.Groups;
if (groups[1] != null && groups[1].Value.Trim().Length > 0)
{
identified.SetVersion(groups[1].Value);

string versionFullString = groups[1].Value;
String[] version = versionFullString.Split(".".ToCharArray());

if (version.Length > 0)
{
identified.majorRevision = version[0];
if (identified.majorRevision.Length == 0)
{
identified.majorRevision = "1";
}
}

if (version.Length > 1)
{
identified.minorRevision = version[1];
confidence += 10;
}

if (version.Length > 2)
{
identified.microRevision = version[2];
}

if (version.Length > 3)
{
identified.nanoRevision = version[3];
}
}
}
else
{
//fallback version
Expand Down Expand Up @@ -128,7 +165,7 @@ protected override Browser BuildBrowser(UserAgent userAgent, string layoutEngine

public override bool CanBuild(UserAgent userAgent)
{
return userAgent.completeUserAgent.Contains("Fennec");
return (userAgent.completeUserAgent.Contains("Fennec") || (userAgent.completeUserAgent.Contains("Firefox") && userAgent.completeUserAgent.Contains("Mobile")));
}
}
}
Loading