Skip to content

Commit 64a0b23

Browse files
committed
Updated to use new locations of CodePRoject.com Sense service pages / split version info out into it's own config file (for reuse)
1 parent f559d4c commit 64a0b23

File tree

8 files changed

+68
-32
lines changed

8 files changed

+68
-32
lines changed

install/create_installer_win.bat

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ set installationDir=c:\CodeProject.SenseAI.Package
2424

2525
:: The location of the installation package that will be created. The convention is:
2626
:: CodeProject.SenseAI.<major>.<minor><patch>.zip
27-
set installationPackage=c:\CodeProject.SenseAI.0.0108.zip
27+
set installationPackage=c:\CodeProject.SenseAI.0.0109.zip
2828

2929
:: The location of the solution root directory relative to this script
3030
cd ..
@@ -58,6 +58,10 @@ set senseAPIDir=API
5858
:: The name of the startup settings file
5959
set settingsFile=CodeProject.SenseAI.json
6060

61+
:: The name of the version file for the SenseAI system. Stored in the API Server dir.
62+
:: TODO: Read this file to set the value of %installationPackage%
63+
set versionFile=version.json
64+
6165
:: .NET build configuration: [Debug | Release]
6266
set config=Release
6367

@@ -250,10 +254,10 @@ set analysisPath=%rootPath%\%srcDir%\%analysisLayerDir%\DeepStack\
250254
REM Note the space before the closing " https://stackoverflow.com/a/30244061
251255
if /i "%verbosity%"=="quiet" (
252256
robocopy "%analysisPath% " "%installationDir%\%srcDir%\%analysisLayerDir%\DeepStack " ^
253-
/XD venv "%modelsDir%" "%pythonDir%" /XF faceembedding.db /E !roboCopyFlags! > nul
257+
/XD venv __pycache__ "%modelsDir%" "%pythonDir%" /XF faceembedding.db /E !roboCopyFlags! > nul
254258
) else (
255259
robocopy "%analysisPath% " "%installationDir%\%srcDir%\%analysisLayerDir%\DeepStack " ^
256-
/XD venv "%modelsDir%" "%pythonDir%" /XF faceembedding.db /E !roboCopyFlags!
260+
/XD venv __pycache__ "%modelsDir%" "%pythonDir%" /XF faceembedding.db /E !roboCopyFlags!
257261
)
258262

259263
:: For YOLO

src/API/Server/FrontEnd/Controllers/StatusController.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
using System.Collections.Generic;
2-
using System.Linq;
1+
using System.Linq;
32

43
using Microsoft.AspNetCore.Http;
54
using Microsoft.AspNetCore.Mvc;
65
using Microsoft.Extensions.DependencyInjection;
76
using Microsoft.Extensions.Hosting;
8-
using Microsoft.Extensions.Options;
97

108
using CodeProject.SenseAI.API.Common;
119
using System.Threading.Tasks;
@@ -66,8 +64,8 @@ public ResponseBase GetVersion()
6664
{
6765
var response = new VersionResponse
6866
{
69-
message = VersionService.VersionInfo.Version,
70-
version = VersionService.VersionInfo,
67+
message = VersionService.VersionConfig.VersionInfo?.Version ?? string.Empty,
68+
version = VersionService.VersionConfig.VersionInfo,
7169
success = true
7270
};
7371

@@ -95,7 +93,17 @@ public async Task<ResponseBase> GetUpdateAvailable()
9593
}
9694
else
9795
{
98-
bool updateAvailable = VersionInfo.Compare(VersionService.VersionInfo, latest) < 0;
96+
VersionInfo? current = VersionService.VersionConfig.VersionInfo;
97+
if (current == null)
98+
{
99+
return new VersionUpdateResponse
100+
{
101+
message = "Unable to retrieve current version",
102+
success = false
103+
};
104+
}
105+
106+
bool updateAvailable = VersionInfo.Compare(current, latest) < 0;
99107
string message = updateAvailable
100108
? $"An update to version {latest.Version} is available"
101109
: "This is the current version";

src/API/Server/FrontEnd/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public static async Task Main(string[] args)
3131
.ConfigureAppConfiguration((hostingContext, config) =>
3232
{
3333
config.AddJsonFile(InstallConfig.InstallCfgFilename, reloadOnChange: true, optional: true);
34+
config.AddJsonFile(VersionConfig.VersionCfgFilename, reloadOnChange: true, optional: true);
3435
})
3536
.Build();
3637
var hostTask = host.RunAsync();

src/API/Server/FrontEnd/Startup.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using Microsoft.Extensions.Options;
1212
using Microsoft.OpenApi.Models;
1313

14-
using CodeProject.SenseAI.API.Common;
1514
using CodeProject.SenseAI.API.Server.Backend;
1615

1716
namespace CodeProject.SenseAI.API.Server.Frontend
@@ -85,9 +84,11 @@ public void ConfigureServices(IServiceCollection services)
8584
services.Configure<BackendOptions>(Configuration.GetSection(nameof(BackendOptions)))
8685
.AddQueueProcessing();
8786

88-
services.Configure<VersionInfo>(Configuration.GetSection(nameof(VersionInfo)));
87+
// Moved into its own file
88+
// services.Configure<VersionInfo>(Configuration.GetSection(nameof(VersionInfo)));
8989

9090
services.Configure<InstallConfig>(Configuration.GetSection(InstallConfig.InstallCfgSection));
91+
services.Configure<VersionConfig>(Configuration.GetSection(VersionConfig.VersionCfgSection));
9192

9293
services.AddBackendProcessRunner(Configuration);
9394

@@ -116,7 +117,7 @@ public void Configure(IApplicationBuilder app,
116117
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "CodeProject SenseAI API v1"));
117118
}
118119

119-
InitializeIntallConfig(installConfig.Value, logger);
120+
InitializeInstallConfig(installConfig.Value, logger);
120121

121122
bool forceHttps = Configuration.GetValue<bool>(nameof(forceHttps));
122123
if (forceHttps)
@@ -137,7 +138,7 @@ public void Configure(IApplicationBuilder app,
137138
});
138139
}
139140

140-
private static void InitializeIntallConfig(InstallConfig installConfig, ILogger<Startup> logger)
141+
private static void InitializeInstallConfig(InstallConfig installConfig, ILogger<Startup> logger)
141142
{
142143

143144
if (installConfig is null || installConfig.Id == Guid.Empty)
@@ -148,6 +149,7 @@ private static void InitializeIntallConfig(InstallConfig installConfig, ILogger<
148149
installConfig.Id = Guid.NewGuid();
149150
var configValues = new { install = installConfig };
150151
var filePath = InstallConfig.InstallCfgFilename;
152+
151153
File.WriteAllText(filePath, System.Text.Json.JsonSerializer.Serialize(configValues,
152154
new System.Text.Json.JsonSerializerOptions { WriteIndented = true }));
153155
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using CodeProject.SenseAI.API.Common;
2+
3+
namespace CodeProject.SenseAI.API.Server.Frontend
4+
{
5+
/// <summary>
6+
/// Version instance config values.
7+
/// </summary>
8+
public class VersionConfig
9+
{
10+
internal static string VersionCfgFilename = "version.json";
11+
internal static string VersionCfgSection = "versionSection";
12+
13+
/// <summary>
14+
/// Gets or sets the version info
15+
/// </summary>
16+
public VersionInfo? VersionInfo { get; set; }
17+
}
18+
}

src/API/Server/FrontEnd/VersionService.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ public class VersionService
2222
/// <param name="versionOptions">The version Options instance.</param>
2323
/// <param name="installOptions">The install Options instance.</param>
2424
/// <param name="configuration">The Configuration instance</param>
25-
public VersionService(IOptions<VersionInfo> versionOptions,
25+
public VersionService(IOptions<VersionConfig> versionOptions,
2626
IOptions<InstallConfig> installOptions,
2727
IConfiguration configuration)
2828
{
2929
Configuration = configuration;
30-
VersionInfo = versionOptions.Value;
30+
VersionConfig = versionOptions.Value;
3131
InstallConfig = installOptions.Value;
3232
}
3333

@@ -39,7 +39,7 @@ public VersionService(IOptions<VersionInfo> versionOptions,
3939
/// <summary>
4040
/// Gets the version info for the current instance.
4141
/// </summary>
42-
public VersionInfo VersionInfo { get; }
42+
public VersionConfig VersionConfig { get; }
4343

4444
/// <summary>
4545
/// Gets the install config for the current instance.
@@ -79,14 +79,13 @@ public VersionService(IOptions<VersionInfo> versionOptions,
7979
if (version is not null)
8080
{
8181
// A small adjustment. The version info contains the file *name* not a file
82-
// URL, and that name is relative to the official download location. We
83-
// return just the name as a naive protection against man in the middle
84-
// attacks. The URL we send the user to will come from the local config
85-
// settings.
82+
// URL. We return just the name as a naive protection against man in the
83+
// middle attacks. The actual URL we send the user to will come from the
84+
// local config settings.
8685
if (!string.IsNullOrWhiteSpace(version.File))
8786
{
8887
string updateDownloadUrl = Configuration.GetValue<string>("UpdateDownloadUrl");
89-
version.File = updateDownloadUrl + version.File;
88+
version.File = updateDownloadUrl;
9089
}
9190

9291
Common.Logger.Log($"Latest version available is {version.Version}");

src/API/Server/FrontEnd/appsettings.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,11 @@
88
}
99
},
1010

11-
"VersionInfo": {
12-
"Major": 0,
13-
"Minor": 1,
14-
"Patch": 8,
15-
"PreRelease": "Beta1",
16-
"Build": 0,
17-
"File": "CodeProject.SenseAI.0.0108.zip"
18-
},
19-
2011
"AllowedHosts": "*",
2112
"ForceHttps": false,
22-
"UpdateCheckUrl": "https://www.codeproject.com/ai/version.aspx",
23-
"UpdateDownloadUrl": "https://www.codeproject.com/ai/sense/",
13+
14+
"UpdateCheckUrl": "https://www.codeproject.com/ai/sense/version.aspx",
15+
"UpdateDownloadUrl": "https://www.codeproject.com/ai/sense/latest.aspx",
2416

2517
"BackendOptions": {
2618
"ResponseTimeout": "00:00:30",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"versionSection": {
3+
"versionInfo": {
4+
"Major": 0,
5+
"Minor": 1,
6+
"Patch": 8,
7+
"PreRelease": "Beta1",
8+
"Build": 0,
9+
"File": "CodeProject.SenseAI.0.0108.zip"
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)