Skip to content

Commit e9b8269

Browse files
committed
Merge pull request #31 from iperform-software/feature_dotnet_implementation
Feature dotnet implementation
2 parents 144c6d4 + fa3587b commit e9b8269

23 files changed

+1317
-1
lines changed

dotnet/.nuget/NuGet.Config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<solution>
4+
<add key="disableSourceControlIntegration" value="true" />
5+
</solution>
6+
</configuration>

dotnet/.nuget/NuGet.exe

677 KB
Binary file not shown.

dotnet/.nuget/NuGet.targets

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
5+
6+
<!-- Enable the restore command to run before builds -->
7+
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>
8+
9+
<!-- Property that enables building a package from a project -->
10+
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
11+
12+
<!-- Determines if package restore consent is required to restore packages -->
13+
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>
14+
15+
<!-- Download NuGet.exe if it does not already exist -->
16+
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
17+
</PropertyGroup>
18+
19+
<ItemGroup Condition=" '$(PackageSources)' == '' ">
20+
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
21+
<!-- The official NuGet package source (https://nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
22+
<!--
23+
<PackageSource Include="https://nuget.org/api/v2/" />
24+
<PackageSource Include="https://my-nuget-source/nuget/" />
25+
-->
26+
</ItemGroup>
27+
28+
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
29+
<!-- Windows specific commands -->
30+
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
31+
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
32+
</PropertyGroup>
33+
34+
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
35+
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
36+
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
37+
<PackagesConfig>packages.config</PackagesConfig>
38+
</PropertyGroup>
39+
40+
<PropertyGroup>
41+
<!-- NuGet command -->
42+
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
43+
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
44+
45+
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
46+
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>
47+
48+
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
49+
50+
<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
51+
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>
52+
53+
<!-- Commands -->
54+
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir "$(SolutionDir) " </RestoreCommand>
55+
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties Configuration=$(Configuration) $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>
56+
57+
<!-- We need to ensure packages are restored prior to assembly resolve -->
58+
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
59+
RestorePackages;
60+
$(BuildDependsOn);
61+
</BuildDependsOn>
62+
63+
<!-- Make the build depend on restore packages -->
64+
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
65+
$(BuildDependsOn);
66+
BuildPackage;
67+
</BuildDependsOn>
68+
</PropertyGroup>
69+
70+
<Target Name="CheckPrerequisites">
71+
<!-- Raise an error if we're unable to locate nuget.exe -->
72+
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
73+
<!--
74+
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
75+
This effectively acts as a lock that makes sure that the download operation will only happen once and all
76+
parallel builds will have to wait for it to complete.
77+
-->
78+
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
79+
</Target>
80+
81+
<Target Name="_DownloadNuGet">
82+
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
83+
</Target>
84+
85+
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
86+
<Exec Command="$(RestoreCommand)"
87+
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
88+
89+
<Exec Command="$(RestoreCommand)"
90+
LogStandardErrorAsError="true"
91+
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
92+
</Target>
93+
94+
<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
95+
<Exec Command="$(BuildCommand)"
96+
Condition=" '$(OS)' != 'Windows_NT' " />
97+
98+
<Exec Command="$(BuildCommand)"
99+
LogStandardErrorAsError="true"
100+
Condition=" '$(OS)' == 'Windows_NT' " />
101+
</Target>
102+
103+
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
104+
<ParameterGroup>
105+
<OutputFilename ParameterType="System.String" Required="true" />
106+
</ParameterGroup>
107+
<Task>
108+
<Reference Include="System.Core" />
109+
<Using Namespace="System" />
110+
<Using Namespace="System.IO" />
111+
<Using Namespace="System.Net" />
112+
<Using Namespace="Microsoft.Build.Framework" />
113+
<Using Namespace="Microsoft.Build.Utilities" />
114+
<Code Type="Fragment" Language="cs">
115+
<![CDATA[
116+
try {
117+
OutputFilename = Path.GetFullPath(OutputFilename);
118+
119+
Log.LogMessage("Downloading latest version of NuGet.exe...");
120+
WebClient webClient = new WebClient();
121+
webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename);
122+
123+
return true;
124+
}
125+
catch (Exception ex) {
126+
Log.LogErrorFromException(ex);
127+
return false;
128+
}
129+
]]>
130+
</Code>
131+
</Task>
132+
</UsingTask>
133+
</Project>

dotnet/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# referer-parser .NET library
2+
3+
This is the .NET implementation of [referer-parser] [referer-parser], the library for extracting attribution data from referer _(sic)_ URLs.
4+
5+
The implementation uses the shared 'database' of known referers found in [`referers.yml`] [referers-yml].
6+
7+
## C\#
8+
9+
### Usage
10+
11+
Use referer-parser in C# like this:
12+
13+
```C#
14+
using RefererParser;
15+
16+
...
17+
18+
string refererUrl = "http://www.google.com/search?q=gateway+oracle+cards+denise+linn&hl=en&client=safari";
19+
string pageUrl = "http:/www.psychicbazaar.com/shop" // Our current URL
20+
21+
var referer = Parser.Parse(new Uri(refererUrl), pageUrl);
22+
23+
Console.WriteLine(r.Medium); // => "Search"
24+
Console.WriteLine(r.Source); // => "Google"
25+
Console.WriteLine(r.Term); // => "gateway oracle cards denise linn"
26+
```
27+
28+
### Installation
29+
30+
A NuGet Package is available, under package id RefererParser.
31+
32+
## Contributing
33+
34+
1. Fork it
35+
2. Create your feature branch (`git checkout -b my-new-feature`)
36+
3. Commit your changes (`git commit -am 'Add some feature'`)
37+
4. Push to the branch (`git push origin my-new-feature`)
38+
5. Create new Pull Request
39+
40+
## Copyright and license
41+
42+
The referer-parser .NET library is copyright 2013 iPerform Software.
43+
44+
Licensed under the [Apache License, Version 2.0] [license] (the "License");
45+
you may not use this software except in compliance with the License.
46+
47+
Unless required by applicable law or agreed to in writing, software
48+
distributed under the License is distributed on an "AS IS" BASIS,
49+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
50+
See the License for the specific language governing permissions and
51+
limitations under the License.
52+
53+
[snowplow]: https://github.com/snowplow/snowplow
54+
55+
[referer-parser]: https://github.com/snowplow/referer-parser
56+
[referers-yml]: https://github.com/snowplow/referer-parser/blob/master/referers.yml
57+
58+
[license]: http://www.apache.org/licenses/LICENSE-2.0

0 commit comments

Comments
 (0)