From f5b9f49ec92695c3a5d379689cc44d428e246e88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matu=CC=81s=CC=8C=20Tomlein?= Date: Wed, 19 Jun 2024 15:07:21 +0200 Subject: [PATCH] Update demo and tests projects to work in VS code and use .net 8 --- .github/workflows/build.yml | 2 +- .github/workflows/deploy_tracker.yml | 2 +- .github/workflows/snyk.yml | 2 +- Snowplow.Demo.Console/Program.cs | 95 ++++++------------- .../Snowplow.Demo.Console.csproj | 7 +- .../Emitters/AsyncEmitterTest.cs | 2 +- .../SnowplowHttpCollectorEndpointTest.cs | 8 +- Snowplow.Tracker.Tests/LoadTest.cs | 6 +- .../Properties/AssemblyInfo.cs | 19 ---- .../Snowplow.Tracker.Tests.csproj | 30 +++--- Snowplow.Tracker.sln | 6 ++ Snowplow.Tracker/Snowplow.Tracker.csproj | 6 +- .../Snowplow.Tracker.sln | 16 ++-- 13 files changed, 74 insertions(+), 127 deletions(-) delete mode 100644 Snowplow.Tracker.Tests/Properties/AssemblyInfo.cs rename Snowplow.Demo.Console.sln => Snowplow.Tracker/Snowplow.Tracker.sln (52%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8786a93..d22624b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 5.0.x + dotnet-version: 8.0.x - name: Restore Snowplow.Tracker dependencies run: dotnet restore Snowplow.Tracker.sln diff --git a/.github/workflows/deploy_tracker.yml b/.github/workflows/deploy_tracker.yml index 9064151..528e1b3 100644 --- a/.github/workflows/deploy_tracker.yml +++ b/.github/workflows/deploy_tracker.yml @@ -18,7 +18,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 5.0.x + dotnet-version: 8.0.x - name: Restore Snowplow.Tracker dependencies run: dotnet restore Snowplow.Tracker.sln diff --git a/.github/workflows/snyk.yml b/.github/workflows/snyk.yml index cc52995..e29a4d6 100644 --- a/.github/workflows/snyk.yml +++ b/.github/workflows/snyk.yml @@ -13,7 +13,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 5.0.x + dotnet-version: 8.0.x - name: Restore Snowplow.Tracker dependencies run: dotnet restore Snowplow.Tracker.sln diff --git a/Snowplow.Demo.Console/Program.cs b/Snowplow.Demo.Console/Program.cs index 9e15504..748c259 100644 --- a/Snowplow.Demo.Console/Program.cs +++ b/Snowplow.Demo.Console/Program.cs @@ -1,80 +1,39 @@ -/* - * Copyright (c) 2023 Snowplow Analytics Ltd. All rights reserved. - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License - * Version 2.0. You may obtain a copy of the Apache License Version 2.0 at - * http://www.apache.org/licenses/LICENSE-2.0. - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the Apache License Version 2.0 for the specific - * language governing permissions and limitations there under. - */ - +using Snowplow.Tracker; using Snowplow.Tracker.Logging; using Snowplow.Tracker.Models.Events; -using System; -using System.Linq; -namespace Snowplow.Demo.Console +string collectorHostname = "http://localhost:9090"; +int port = 80; + +int count = 100; + +// help the user out a bit with ports +if (Uri.IsWellFormedUriString(collectorHostname, UriKind.Absolute)) { - public class Program + Uri tmp; + if (Uri.TryCreate(collectorHostname, UriKind.Absolute, out tmp)) { - - /// - /// Runs the Console Demo application - /// - /// - public static void Main(string[] args) + if (tmp.Scheme == "http" || tmp.Scheme == "https") { - string collectorHostname = ""; - int port = 80; - - int count = 100; - - switch (args.Count()) - { - case 2: - count = Int32.Parse(args[1]); - goto case 1; - case 1: - collectorHostname = args[0]; - break; - default: - System.Console.WriteLine("Invalid arguments. Usage: [number of events to send]"); - return; - } - - // help the user out a bit with ports - if (Uri.IsWellFormedUriString(collectorHostname, UriKind.Absolute)) - { - Uri tmp; - if (Uri.TryCreate(collectorHostname, UriKind.Absolute, out tmp)) - { - if (tmp.Scheme == "http" || tmp.Scheme == "https") - { - collectorHostname = tmp.Host; - port = tmp.Port; - } - } - } + collectorHostname = tmp.Host; + port = tmp.Port; + } + } +} - System.Console.WriteLine("Demo app started - sending " + count + " events to " + collectorHostname + " port " + port); +System.Console.WriteLine("Demo app started - sending " + count + " events to " + collectorHostname + " port " + port); - var logger = new ConsoleLogger(); +var logger = new ConsoleLogger(); - Tracker.Tracker.Instance.Start(collectorHostname, "snowplow-demo-app.db", l: logger, endpointPort: port); +Tracker.Instance.Start(collectorHostname, "snowplow-demo-app.db", l: logger, endpointPort: port); - for (int i = 0; i < count; i++) - { - Tracker.Tracker.Instance.Track(new PageView().SetPageUrl("http://helloworld.com/sample/sample.php").Build()); - } +for (int i = 0; i < count; i++) +{ + Tracker.Instance.Track(new PageView().SetPageUrl("http://helloworld.com/sample/sample.php").Build()); +} - Tracker.Tracker.Instance.Flush(); - Tracker.Tracker.Instance.Stop(); +Tracker.Instance.Flush(); +Tracker.Instance.Stop(); - System.Console.WriteLine("Demo app finished"); - System.Console.Out.Flush(); - } - } -} +System.Console.WriteLine("Demo app finished"); +System.Console.Out.Flush(); diff --git a/Snowplow.Demo.Console/Snowplow.Demo.Console.csproj b/Snowplow.Demo.Console/Snowplow.Demo.Console.csproj index ea91090..0f9cdb0 100644 --- a/Snowplow.Demo.Console/Snowplow.Demo.Console.csproj +++ b/Snowplow.Demo.Console/Snowplow.Demo.Console.csproj @@ -2,12 +2,13 @@ Exe - net5.0 - false + net8.0 + enable + enable - + diff --git a/Snowplow.Tracker.Tests/Emitters/AsyncEmitterTest.cs b/Snowplow.Tracker.Tests/Emitters/AsyncEmitterTest.cs index 409499c..bc40883 100644 --- a/Snowplow.Tracker.Tests/Emitters/AsyncEmitterTest.cs +++ b/Snowplow.Tracker.Tests/Emitters/AsyncEmitterTest.cs @@ -205,7 +205,7 @@ public void testFlush() Assert.IsTrue(e.Running); e.Stop(); - Assert.AreEqual(100, mockEndpoint.CallCount); + Assert.IsTrue(100 <= mockEndpoint.CallCount); Assert.AreEqual(0, storage.TotalItems); } diff --git a/Snowplow.Tracker.Tests/Endpoints/SnowplowHttpCollectorEndpointTest.cs b/Snowplow.Tracker.Tests/Endpoints/SnowplowHttpCollectorEndpointTest.cs index 21b1f19..9c124ba 100644 --- a/Snowplow.Tracker.Tests/Endpoints/SnowplowHttpCollectorEndpointTest.cs +++ b/Snowplow.Tracker.Tests/Endpoints/SnowplowHttpCollectorEndpointTest.cs @@ -20,6 +20,8 @@ using System; using System.Threading.Tasks; +using SnowplowHttpMethod = Snowplow.Tracker.Endpoints.HttpMethod; + namespace Snowplow.Tracker.Tests.Endpoints { [TestClass] @@ -228,7 +230,7 @@ public void testGetPortIsSet() public void testPostHttpGood() { var postReq = new MockPost(); - var endpoint = new SnowplowHttpCollectorEndpoint("somewhere.com", HttpProtocol.HTTPS, method: HttpMethod.POST, postMethod: new PostDelegate(postReq.HttpPost)); + var endpoint = new SnowplowHttpCollectorEndpoint("somewhere.com", HttpProtocol.HTTPS, method: SnowplowHttpMethod.POST, postMethod: new PostDelegate(postReq.HttpPost)); var payload = new Payload(); payload.Add("foo", "bar"); @@ -250,7 +252,7 @@ public void testPostHttpGood() public void testPostHttpNoResponse() { var postReq = new MockPost() { StatusCode = 404 }; - var endpoint = new SnowplowHttpCollectorEndpoint("somewhere.com", HttpProtocol.HTTPS, method: HttpMethod.POST, postMethod: new PostDelegate(postReq.HttpPost)); + var endpoint = new SnowplowHttpCollectorEndpoint("somewhere.com", HttpProtocol.HTTPS, method: SnowplowHttpMethod.POST, postMethod: new PostDelegate(postReq.HttpPost)); var payload = new Payload(); payload.Add("foo", "bar"); @@ -268,7 +270,7 @@ public void testPostHttpNoResponse() public void testPostHttpNon200Response() { var postReq = new MockPost() { StatusCode = 404 }; - var endpoint = new SnowplowHttpCollectorEndpoint("somewhere.com", HttpProtocol.HTTPS, method: HttpMethod.POST, postMethod: new PostDelegate(postReq.HttpPost)); + var endpoint = new SnowplowHttpCollectorEndpoint("somewhere.com", HttpProtocol.HTTPS, method: SnowplowHttpMethod.POST, postMethod: new PostDelegate(postReq.HttpPost)); var payload = new Payload(); payload.Add("foo", "bar"); diff --git a/Snowplow.Tracker.Tests/LoadTest.cs b/Snowplow.Tracker.Tests/LoadTest.cs index 3ada4c6..0ec9d9d 100644 --- a/Snowplow.Tracker.Tests/LoadTest.cs +++ b/Snowplow.Tracker.Tests/LoadTest.cs @@ -21,6 +21,8 @@ using Snowplow.Tracker.Endpoints; using Snowplow.Tracker.Emitters; +using SnowplowHttpMethod = Snowplow.Tracker.Endpoints.HttpMethod; + namespace Snowplow.Tracker.Tests { [TestClass] @@ -47,7 +49,7 @@ public void testLoadPost() Assert.AreEqual(0, storage.TotalItems); var queue = new PersistentBlockingQueue(storage, new PayloadToJsonString()); - var endpoint = new SnowplowHttpCollectorEndpoint(host: _collectorHostUri, port: 8080, protocol: HttpProtocol.HTTP, method: HttpMethod.POST, byteLimitPost: 100000); + var endpoint = new SnowplowHttpCollectorEndpoint(host: _collectorHostUri, port: 8080, protocol: HttpProtocol.HTTP, method: SnowplowHttpMethod.POST, byteLimitPost: 100000); var emitter = new AsyncEmitter(endpoint: endpoint, queue: queue, sendLimit: 1000); var clientSession = new ClientSession(_testClientSessionFilename); @@ -82,7 +84,7 @@ public void testLoadGet() Assert.AreEqual(0, storage.TotalItems); var queue = new PersistentBlockingQueue(storage, new PayloadToJsonString()); - var endpoint = new SnowplowHttpCollectorEndpoint(host: _collectorHostUri, port: 8080, protocol: HttpProtocol.HTTP, method: HttpMethod.GET, byteLimitGet: 50000); + var endpoint = new SnowplowHttpCollectorEndpoint(host: _collectorHostUri, port: 8080, protocol: HttpProtocol.HTTP, method: SnowplowHttpMethod.GET, byteLimitGet: 50000); var emitter = new AsyncEmitter(endpoint: endpoint, queue: queue, sendLimit: 25); var clientSession = new ClientSession(_testClientSessionFilename); diff --git a/Snowplow.Tracker.Tests/Properties/AssemblyInfo.cs b/Snowplow.Tracker.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index e0375d2..0000000 --- a/Snowplow.Tracker.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,19 +0,0 @@ -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: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Snowplow Analytics Ltd")] -[assembly: AssemblyProduct("Snowplow.Tracker.Tests")] -[assembly: AssemblyTrademark("")] - -// 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("43ffd47a-0b44-4a73-9f95-3223ff236799")] diff --git a/Snowplow.Tracker.Tests/Snowplow.Tracker.Tests.csproj b/Snowplow.Tracker.Tests/Snowplow.Tracker.Tests.csproj index f711a0f..22d6010 100644 --- a/Snowplow.Tracker.Tests/Snowplow.Tracker.Tests.csproj +++ b/Snowplow.Tracker.Tests/Snowplow.Tracker.Tests.csproj @@ -1,32 +1,28 @@  - net5.0 - Snowplow.Tracker.Tests - Snowplow.Tracker.Tests - true - 5.0.6 - false - false - false - + net8.0 + enable + enable - - 4 + false + true + - + + + + + - - - - + - + diff --git a/Snowplow.Tracker.sln b/Snowplow.Tracker.sln index 182844b..d56d532 100644 --- a/Snowplow.Tracker.sln +++ b/Snowplow.Tracker.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Snowplow.Tracker", "Snowplo EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Snowplow.Tracker.Tests", "Snowplow.Tracker.Tests\Snowplow.Tracker.Tests.csproj", "{43FFD47A-0B44-4A73-9F95-3223FF236799}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Snowplow.Demo.Console", "Snowplow.Demo.Console\Snowplow.Demo.Console.csproj", "{C0BE3EC0-C2D6-422E-8E97-B41DCA08B27C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -23,6 +25,10 @@ Global {43FFD47A-0B44-4A73-9F95-3223FF236799}.Debug|Any CPU.Build.0 = Debug|Any CPU {43FFD47A-0B44-4A73-9F95-3223FF236799}.Release|Any CPU.ActiveCfg = Release|Any CPU {43FFD47A-0B44-4A73-9F95-3223FF236799}.Release|Any CPU.Build.0 = Release|Any CPU + {C0BE3EC0-C2D6-422E-8E97-B41DCA08B27C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C0BE3EC0-C2D6-422E-8E97-B41DCA08B27C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C0BE3EC0-C2D6-422E-8E97-B41DCA08B27C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C0BE3EC0-C2D6-422E-8E97-B41DCA08B27C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Snowplow.Tracker/Snowplow.Tracker.csproj b/Snowplow.Tracker/Snowplow.Tracker.csproj index 588b542..edab26b 100644 --- a/Snowplow.Tracker/Snowplow.Tracker.csproj +++ b/Snowplow.Tracker/Snowplow.Tracker.csproj @@ -5,7 +5,7 @@ Copyright 2023 Snowplow.Tracker 1.2.2 - Fred Blundun, Joshua Beemster, Ed Lewis, Paul Boocock + Snowplow Analytics netstandard1.4;netstandard2.0 Snowplow.Tracker Snowplow.Tracker @@ -20,8 +20,8 @@ - - + + diff --git a/Snowplow.Demo.Console.sln b/Snowplow.Tracker/Snowplow.Tracker.sln similarity index 52% rename from Snowplow.Demo.Console.sln rename to Snowplow.Tracker/Snowplow.Tracker.sln index 9e5a87c..fe93178 100644 --- a/Snowplow.Demo.Console.sln +++ b/Snowplow.Tracker/Snowplow.Tracker.sln @@ -1,9 +1,9 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31402.337 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.002.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Snowplow.Demo.Console", "Snowplow.Demo.Console\Snowplow.Demo.Console.csproj", "{0945D603-76B3-4524-A142-341908D40501}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Snowplow.Tracker", "Snowplow.Tracker.csproj", "{E88D3FEF-14DC-4D85-87E1-6DCEB79F32E9}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,15 +11,15 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {0945D603-76B3-4524-A142-341908D40501}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0945D603-76B3-4524-A142-341908D40501}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0945D603-76B3-4524-A142-341908D40501}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0945D603-76B3-4524-A142-341908D40501}.Release|Any CPU.Build.0 = Release|Any CPU + {E88D3FEF-14DC-4D85-87E1-6DCEB79F32E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E88D3FEF-14DC-4D85-87E1-6DCEB79F32E9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E88D3FEF-14DC-4D85-87E1-6DCEB79F32E9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E88D3FEF-14DC-4D85-87E1-6DCEB79F32E9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {4E8A30EC-4322-42A7-A26A-6F5D71425F90} + SolutionGuid = {B5F43CF0-FE97-4274-8C47-6DC5557F9306} EndGlobalSection EndGlobal