Skip to content

Commit 293d969

Browse files
committed
Updated to version 3.11.0.
1 parent c1b03f7 commit 293d969

File tree

11 files changed

+2148
-74
lines changed

11 files changed

+2148
-74
lines changed

MyGeotabAPIAdapter.DataOptimizer/MyGeotabAPIAdapter.DataOptimizer.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<Authors>Geotab Inc.</Authors>
77
<Company>Geotab Inc.</Company>
88
<Product>MyGeotab API Adapter - DataOptimizer</Product>
9-
<AssemblyVersion>3.10.0.0</AssemblyVersion>
10-
<FileVersion>3.10.0.0</FileVersion>
9+
<AssemblyVersion>3.11.0.0</AssemblyVersion>
10+
<FileVersion>3.11.0.0</FileVersion>
1111
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
1212
<Description>A worker service designed to migrate data from the MyGeotab API Adapter database into another set of tables that are optimized for use by applications and data analysis tools. Additional columns are added to some of the tables and these are populated via interpolation or other query-based procedues.</Description>
1313
</PropertyGroup>

MyGeotabAPIAdapter.Database/DatabaseValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class DatabaseValidator : IDatabaseValidator
1717
// The required version of the middleware database for the current version of the middleware application. Any time the middleware database is updated as part of an application update:
1818
// 1. This value should be updated to reflect the application version at the time.
1919
// 2. Database changes should be included in a single script file and the filename should be formatted as "prefix_version_suffix.sql" (e.g. "MSSQL_3.0.0.0_InitialSchemaCreation.sql") where the version portion of the filename is equal to the value of this constant.
20-
const string RequiredDatabaseVersion = "3.10.0.0";
20+
const string RequiredDatabaseVersion = "3.11.0.0";
2121

2222
readonly IExceptionHelper exceptionHelper;
2323
readonly Logger logger = LogManager.GetCurrentClassLogger();

MyGeotabAPIAdapter.Database/MyGeotabAPIAdapter.Database.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<ItemGroup>
1010
<PackageReference Include="Dapper" Version="2.1.66" />
1111
<PackageReference Include="FastMember" Version="1.5.0" />
12-
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.2" />
12+
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.1.0" />
1313
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="17.14.15" />
1414
<PackageReference Include="NLog.Extensions.Logging" Version="6.0.2" />
1515
<PackageReference Include="Npgsql" Version="9.0.3" />

MyGeotabAPIAdapter.GeotabObjectMappers/GeotabTripDbTripObjectMapper.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ public List<DbTrip> CreateEntities(List<Trip> entitiesToMapTo)
1616
var dbTrips = new List<DbTrip>();
1717
foreach (var entity in entitiesToMapTo)
1818
{
19-
var dbTrip = CreateEntity(entity);
20-
dbTrip.RecordCreationTimeUtc = recordCreationTimeUtc;
21-
dbTrips.Add(dbTrip);
19+
if (entity.Device != null)
20+
{
21+
var dbTrip = CreateEntity(entity);
22+
dbTrip.RecordCreationTimeUtc = recordCreationTimeUtc;
23+
dbTrips.Add(dbTrip);
24+
}
2225
}
2326
return dbTrips;
2427
}

MyGeotabAPIAdapter/MyGeotabAPIAdapter.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<Product>MyGeotab API Adapter</Product>
1010
<Description>A .NET Core (C#) Worker Service designed to use the MyGeotab .NET API and serve as a broker between a MyGeotab database and an associated "Virtual Geotab Database". Intended for use when direct utilization of the MyGeotab SDK is not an option. Modify as required to meet individual solution objectives.</Description>
1111
<Copyright></Copyright>
12-
<Version>3.10.0.0</Version>
13-
<InformationalVersion>3.10.0.0</InformationalVersion>
12+
<Version>3.11.0.0</Version>
13+
<InformationalVersion>3.11.0.0</InformationalVersion>
1414
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
1515
</PropertyGroup>
1616

@@ -26,6 +26,8 @@
2626
<ItemGroup>
2727
<PackageReference Include="Geotab.Checkmate.ObjectModel" Version="11.83.265" />
2828
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.7" />
29+
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="9.0.7" />
30+
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="9.0.7" />
2931
<PackageReference Include="Microsoft.NETCore.Platforms" Version="7.0.4" />
3032
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
3133
<PackageReference Include="NLog.Extensions.Logging" Version="6.0.2" />

MyGeotabAPIAdapter/Program.cs

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,52 +29,50 @@
2929
using NLog;
3030
using NLog.Extensions.Logging;
3131
using Microsoft.Extensions.Options;
32+
using System.Threading.Tasks;
3233

3334
namespace MyGeotabAPIAdapter
3435
{
3536
/// <summary>
36-
/// The main program. Handles initialization of logging and configuration settings and instantiates the <see cref="Worker"/> class, which is responsible for execution of application logic.
37+
/// The main program. Handles initialization of logging and configuration settings and instantiates the application's services.
3738
/// </summary>
3839
public class Program
3940
{
40-
public static void Main(string[] args)
41+
/// <summary>
42+
/// The main entry point for the application.
43+
/// </summary>
44+
/// <param name="args">Command-line arguments.</param>
45+
public static async Task Main(string[] args)
4146
{
4247
var logger = LogManager.GetCurrentClassLogger();
4348
try
4449
{
45-
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production";
50+
var hostBuilder = Host.CreateDefaultBuilder(args);
4651

47-
var config = new ConfigurationBuilder()
48-
.SetBasePath(System.IO.Directory.GetCurrentDirectory())
49-
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
50-
.AddJsonFile($"appsettings.{environment}.json", optional: true, reloadOnChange: true)
51-
.Build();
52-
53-
CreateHostBuilder(args, config).Build().Run();
54-
}
55-
catch (Exception ex)
56-
{
57-
// NLog: catch any exception and log it.
58-
logger.Error(ex, $"Stopped application because of exception: \nMESSAGE [{ex.Message}]; \nSOURCE [{ex.Source}]; \nSTACK TRACE [{ex.StackTrace}]");
59-
}
60-
finally
61-
{
62-
// Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
63-
LogManager.Shutdown();
64-
}
65-
}
52+
// Conditionally configure the host for Windows Service or Linux Systemd.
53+
if (OperatingSystem.IsWindows())
54+
{
55+
hostBuilder.UseWindowsService(options =>
56+
{
57+
// Set the name for the Windows service.
58+
options.ServiceName = "MyGeotabAPIAdapter";
59+
});
60+
}
61+
else if (OperatingSystem.IsLinux())
62+
{
63+
hostBuilder.UseSystemd();
64+
}
6665

67-
public static IHostBuilder CreateHostBuilder(string[] args, IConfiguration config) =>
68-
Host.CreateDefaultBuilder(args)
69-
// Configure logging with NLog.
70-
.ConfigureLogging((context, logging) =>
66+
hostBuilder.ConfigureLogging((context, logging) =>
7167
{
7268
logging.ClearProviders();
7369
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
74-
logging.AddNLog(config);
70+
// NLog configuration is loaded from appsettings.json by the default builder.
71+
logging.AddNLog();
7572
})
7673
.ConfigureServices((hostContext, services) =>
7774
{
75+
// Dependency injection registrations:
7876
IConfiguration configuration = hostContext.Configuration;
7977
HttpClient httpClient = new();
8078
services
@@ -526,5 +524,21 @@ public static IHostBuilder CreateHostBuilder(string[] args, IConfiguration confi
526524
;
527525
}
528526
});
527+
528+
var host = hostBuilder.Build();
529+
await host.RunAsync();
530+
}
531+
catch (Exception ex)
532+
{
533+
// NLog: catch any exception and log it.
534+
logger.Error(ex, $"Stopped application because of exception: \nMESSAGE [{ex.Message}]; \nSOURCE [{ex.Source}]; \nSTACK TRACE [{ex.StackTrace}]");
535+
throw; // Re-throw the exception to ensure the process terminates with an error code.
536+
}
537+
finally
538+
{
539+
// Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
540+
LogManager.Shutdown();
541+
}
542+
}
529543
}
530544
}

0 commit comments

Comments
 (0)