Skip to content

Commit

Permalink
Add version info and improve start ui command
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe committed May 6, 2021
1 parent fae5c3e commit 5b82848
Show file tree
Hide file tree
Showing 41 changed files with 554 additions and 253 deletions.
Binary file removed images/logo_boost.png
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</PropertyGroup>

<PropertyGroup>
<Version Condition="$(Version) == ''">1.0.0</Version>
<Version Condition="$(Version) == ''">0.2.0</Version>
<Product>Boost</Product>
<Authors>Philippe Birbaum</Authors>
<Company>Swiss Life</Company>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;

Expand All @@ -25,4 +25,9 @@ public BoostCommandContext(Assembly toolAssembly)
public Action<IServiceCollection>? ConfigureWeb { get; }
public Assembly ToolAssembly { get; }
}

public class AppSettings
{
public string PackageId { get; set; } = "Boost.Tool";
}
}
17 changes: 17 additions & 0 deletions src/Tool/src/Boost.Abstractions/Infrastructure/BoostVersionInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Boost.Nuget;

namespace Boost.Infrastructure
{
public class BoostVersionInfo
{
public string PackageId { get; set; }

public string? Installed { get; set; }

public NugetPackageVersionInfo? Latest { get; set; }

public NugetPackageVersionInfo? PreRelease { get; set; }
public bool NewerAvailable { get; set; }
public bool NewerPreReleaseAvailable { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;

namespace Boost.Infrastructure
{
public class DataProtectorKeyRing
{
public Guid? ActiveKeyId { get; set; }

public IList<EncryptionKeySetting> Protectors { get; set; } = new List<EncryptionKeySetting>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;

namespace Boost.Infrastructure
{
public class EncryptionKeySetting
{
public Guid Id { get; set; }

public string Name { get; set; }

public Dictionary<string, string> Parameters { get; set; }
= new Dictionary<string, string>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,5 @@ public interface IUserDataProtector

public record KeyContext(Guid Id, IDictionary<string, string> Parameters);

public class DataProtectorKeyRing
{
public Guid? ActiveKeyId { get; set; }

public IList<EncryptionKeySetting> Protectors { get; set; } = new List<EncryptionKeySetting>();
}

public class EncryptionKeySetting
{
public Guid Id { get; set; }

public string Name { get; set; }

public Dictionary<string, string> Parameters { get; set; }
= new Dictionary<string, string>();
}

public enum EnryptionType
{
None,
X509Certificate
}

public record ProtectedData(byte[] Data, Guid KeyId);
}
10 changes: 10 additions & 0 deletions src/Tool/src/Boost.Abstractions/Infrastructure/IVersionChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Threading;
using System.Threading.Tasks;

namespace Boost.Infrastructure
{
public interface IVersionChecker
{
Task<BoostVersionInfo> GetVersionInfo(CancellationToken cancellationToken);
}
}
14 changes: 0 additions & 14 deletions src/Tool/src/Boost.Abstractions/Nuget/INugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,4 @@ public interface INugetService
{
Task<NugetPackageInfo?> GetNugetPackageInfoAsync(string packageId, CancellationToken cancellationToken);
}


public record PackageVersion(string Name, string Version)
{
public string? Reference { get; init; }
}

public record NugetPackageVersionInfo(string Version, DateTimeOffset Published);

public record NugetPackageInfo(string PackageId)
{
public NugetPackageVersionInfo? LatestStable { get; init; }
public NugetPackageVersionInfo? LatestPreRelease { get; init; }
}
}
8 changes: 8 additions & 0 deletions src/Tool/src/Boost.Abstractions/Nuget/NugetPackageInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Boost.Nuget
{
public record NugetPackageInfo(string PackageId)
{
public NugetPackageVersionInfo? LatestStable { get; init; }
public NugetPackageVersionInfo? LatestPreRelease { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using System;

namespace Boost.Nuget
{
public record NugetPackageVersionInfo(string Version, DateTimeOffset Published);
}
7 changes: 7 additions & 0 deletions src/Tool/src/Boost.Abstractions/Nuget/PackageVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Boost.Nuget
{
public record PackageVersion(string Name, string Version)
{
public string? Reference { get; init; }
}
}
6 changes: 4 additions & 2 deletions src/Tool/src/Boost.Abstractions/Web/IWebServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

namespace Boost.Web
{
public interface IWebServer
public interface IWebServer : IDisposable
{
public Task StartAsync(int port, string? path = null);
string LogLevel { get; set; }

public Task<string> StartAsync(int port);
Task StopAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static IServiceCollection AddBoost(this IServiceCollection services)
services.AddSingleton<ISecurityUtils, SecurityUtils>();
services.AddSingleton<IAuthTokenStore, UserDataAuthTokenStore>();
services.AddSingleton<IAuthTokenStoreReader, UserDataAuthTokenStoreReader>();
services.AddSingleton<IVersionChecker, VersionChecker>();

services.AddUserDataProtection();

Expand Down
42 changes: 39 additions & 3 deletions src/Tool/src/Boost.Core/Commands/OpenUICommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ public OpenUICommand(IWebServer webServer)
[Option("--path <PATH>", Description = "Url path")]
public string? Path { get; set; }

[Option("--log <level>", Description = "Log level: debug|info|warning|error")]
public string LogLevel { get; set; } = "warning";

public async Task OnExecute(IConsole console)
{
console.WriteLine("Starting Boost UI...");

var port = NetworkExtensions.GetAvailablePort(Port);

if (port != Port)
{
console.WriteLine($"Port {Port} is allready in use.", ConsoleColor.Red);
console.WriteLine($"Port {Port} is allready in use.", ConsoleColor.Yellow);
var useOther = Prompt.GetYesNo($"Start UI on port: {port}", true);

if (useOther)
Expand All @@ -46,9 +48,43 @@ public async Task OnExecute(IConsole console)
return;
}
}
_webServer.LogLevel = LogLevel;

var url = await _webServer.StartAsync(Port);

if (!Debugger.IsAttached)
{
if (Path is { })
{
url = url + $"/{Path}";
}

ProcessHelpers.OpenBrowser(url);
}
var stopMessage = "Press 'q' or 'esc' to stop";
Console.WriteLine(stopMessage);

await _webServer.StartAsync(Port, Path);
while (true)
{
ConsoleKeyInfo key = Console.ReadKey();
if (key.KeyChar == 'q' || key.Key == ConsoleKey.Escape)
{
break;
}
else
{
console.ClearLine();
console.WriteLine("Unknown command", ConsoleColor.Red);
Console.WriteLine(stopMessage);
}
}

console.WriteLine("Stopping boost....");
await _webServer.StopAsync();

_webServer.Dispose();
}

}

[Command(
Expand Down
67 changes: 67 additions & 0 deletions src/Tool/src/Boost.Core/Commands/VersionCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Threading.Tasks;
using Boost.Infrastructure;
using McMaster.Extensions.CommandLineUtils;

namespace Boost.Commands
{
[Command(
Name = "version",
FullName = "Version",
Description = "Get current Version and check for new version"), HelpOption]
public class VersionCommand : CommandBase
{
private readonly IVersionChecker _versionChecker;

public VersionCommand(IVersionChecker versionChecker
)
{
_versionChecker = versionChecker;
}

public async Task OnExecute(
CommandLineApplication app,
IConsole console)
{
BoostVersionInfo version = await _versionChecker.GetVersionInfo(CommandAborded);

if (version is { })
{
Console.WriteLine("Boost Version info");
Console.WriteLine("------------------");
Console.WriteLine($"Installed:\t{version.Installed}");

if (version.Latest is { })
{
Console.WriteLine(
$"Latest:\t\t{version.Latest.Version}" +
$" ({version.Latest.Published:d})");
}

if (version.PreRelease is { })
{
Console.WriteLine(
$"Latest Pre-Release:\t{version.PreRelease.Version}" +
$" ({version.PreRelease.Published:d})");
}

console.WriteLine();

if (version.NewerAvailable)
{
console.Write(
$"Run `dotnet tool update -g {version.PackageId}` " +
"to install latest stable version");
}


if (version.NewerPreReleaseAvailable)
{
console.Write(
$"Run `dotnet tool update -g {version.PackageId} --version {version.PreRelease!.Version}` " +
"to install latest pre release version");
}
}
}
}
}
3 changes: 2 additions & 1 deletion src/Tool/src/Boost.Core/Commands/WorkrootCommandUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public WorkrootCommandUtils(CommandLineApplication app, IConsole console)
{
case 0:
IWebServer? webServer = _app.GetRequiredService<IWebServer>();
await webServer.StartAsync(3003, "settings");
var url = await webServer.StartAsync(3003);
ProcessHelpers.OpenBrowser(url + "/settings");
break;
case 1:
//first ensure file exists
Expand Down
24 changes: 7 additions & 17 deletions src/Tool/src/Boost.Core/GraphQL/BoostQueries.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Boost.GraphQL;
using Boost.Infrastructure;
using HotChocolate.Execution.Configuration;
using HotChocolate;
using HotChocolate.Types;
using Microsoft.Extensions.DependencyInjection;

namespace Boost.Core.GraphQL
{
Expand All @@ -28,23 +28,13 @@ public BoostApplication GetAppliation()

return app;
}
}

public static class GraphQLServiceCollectionExtensions
{
public static IServiceCollection AddGraphQLServices(
this IServiceCollection services,
Action<IRequestExecutorBuilder>? configure = null)
public Task<BoostVersionInfo> GetVersionAsync(
[Service] IVersionChecker versionChecker,
CancellationToken cancellationToken)
{
IRequestExecutorBuilder builder = services.AddGraphQLServer()
.ModifyRequestOptions(m => m.IncludeExceptionDetails = true)
.AddQueryType(d => d.Name(RootTypes.Query))
.AddMutationType(d => d.Name(RootTypes.Mutation))
.AddBoostTypes();

configure?.Invoke(builder);
return versionChecker.GetVersionInfo(cancellationToken);

return services;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using Boost.GraphQL;
using HotChocolate;
using HotChocolate.Execution.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Boost.Core.GraphQL
{
public static class GraphQLServiceCollectionExtensions
{
public static IServiceCollection AddGraphQLServices(
this IServiceCollection services,
Action<IRequestExecutorBuilder>? configure = null)
{
IRequestExecutorBuilder builder = services.AddGraphQLServer()
.ModifyRequestOptions(m => m.IncludeExceptionDetails = true)
.AddQueryType(d => d.Name(RootTypes.Query))
.AddMutationType(d => d.Name(RootTypes.Mutation))
.AddBoostTypes();

configure?.Invoke(builder);

return services;
}
}
}
Loading

0 comments on commit 5b82848

Please sign in to comment.