From e48a65920f6c032f4ac15d094506d8c96d466348 Mon Sep 17 00:00:00 2001 From: Jelle Maas Date: Wed, 29 Jun 2022 09:25:54 +0200 Subject: [PATCH] Release v1.0.0-beta3 (#32) * Change formats type to `string` and split with comma separator * Use root configuration instead of configuration section * Fix exceptions not properly displaying in the console * Add all module item types according to documentation * Update application demo GIF * Create code-analysis.yml * Remove comments and enable additional queries * Removed push from code-analysis.yml workflow * Typo code-analysis.yml Co-authored-by: Neal Geilen --- .github/workflows/code-analysis.yml | 37 ++++++++++++++++ .../Model/ModuleItem.cs | 3 +- .../Model/ModuleItemType.cs | 12 ++++-- Epsilon.Cli/Program.cs | 21 +++++++-- Epsilon.Cli/Startup.cs | 43 ++++++++++++------- Epsilon.Cli/appsettings.example.json | 13 +----- Epsilon/Export/ExportOptions.cs | 2 +- .../CoreServiceCollectionExtensions.cs | 2 +- README.md | 2 +- 9 files changed, 95 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/code-analysis.yml diff --git a/.github/workflows/code-analysis.yml b/.github/workflows/code-analysis.yml new file mode 100644 index 00000000..e45bb7b7 --- /dev/null +++ b/.github/workflows/code-analysis.yml @@ -0,0 +1,37 @@ +name: "Code analysis" + +on: + pull_request: + branches: [ "master", "develop" ] + schedule: + - cron: '22 18 * * 5' + +jobs: + analyze: + name: Analyze code + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'csharp' ] + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + queries: security-extended,security-and-quality + + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/Epsilon.Canvas.Abstractions/Model/ModuleItem.cs b/Epsilon.Canvas.Abstractions/Model/ModuleItem.cs index 370752d1..03462030 100644 --- a/Epsilon.Canvas.Abstractions/Model/ModuleItem.cs +++ b/Epsilon.Canvas.Abstractions/Model/ModuleItem.cs @@ -5,7 +5,6 @@ namespace Epsilon.Canvas.Abstractions.Model; public record ModuleItem( [property: JsonPropertyName("id")] int Id, [property: JsonPropertyName("title")] string Title, - [property: JsonPropertyName("type"), JsonConverter(typeof(JsonStringEnumConverter))] - ModuleItemType? Type, + [property: JsonPropertyName("type")] ModuleItemType? Type, [property: JsonPropertyName("content_id")] int? ContentId ); \ No newline at end of file diff --git a/Epsilon.Canvas.Abstractions/Model/ModuleItemType.cs b/Epsilon.Canvas.Abstractions/Model/ModuleItemType.cs index df34e50c..622413ce 100644 --- a/Epsilon.Canvas.Abstractions/Model/ModuleItemType.cs +++ b/Epsilon.Canvas.Abstractions/Model/ModuleItemType.cs @@ -1,10 +1,16 @@ -namespace Epsilon.Canvas.Abstractions.Model; +using System.Text.Json.Serialization; +namespace Epsilon.Canvas.Abstractions.Model; + +[JsonConverter(typeof(JsonStringEnumConverter))] public enum ModuleItemType { - Unknown, + File, Page, + Discussion, Assignment, + Quiz, SubHeader, - File, + ExternalUrl, + ExternalTool, } \ No newline at end of file diff --git a/Epsilon.Cli/Program.cs b/Epsilon.Cli/Program.cs index e6f8fd5a..12897371 100644 --- a/Epsilon.Cli/Program.cs +++ b/Epsilon.Cli/Program.cs @@ -25,7 +25,20 @@ IHostBuilder CreateHostBuilder(string[] args) }); } -await CreateHostBuilder(args) - .UseSerilog() - .Build() - .RunAsync(); \ No newline at end of file +try +{ + Log.Information("Starting up"); + + await CreateHostBuilder(args) + .UseSerilog() + .Build() + .RunAsync(); +} +catch (Exception ex) +{ + Log.Fatal(ex, "Application was unable to start due to fatal error"); +} +finally +{ + Log.CloseAndFlush(); +} \ No newline at end of file diff --git a/Epsilon.Cli/Startup.cs b/Epsilon.Cli/Startup.cs index fcefdd8f..6e2f0658 100644 --- a/Epsilon.Cli/Startup.cs +++ b/Epsilon.Cli/Startup.cs @@ -48,31 +48,42 @@ public Task StopAsync(CancellationToken cancellationToken) private async Task ExecuteAsync() { - var results = Validate(_canvasSettings).ToArray(); - if (results.Any()) + try { - foreach (var validationResult in results) + var results = Validate(_canvasSettings).ToArray(); + if (results.Any()) { - _logger.LogError("Error: {Message}", validationResult.ErrorMessage); + foreach (var validationResult in results) + { + _logger.LogError("Error: {Message}", validationResult.ErrorMessage); + } + + _lifetime.StopApplication(); + return; } - _lifetime.StopApplication(); - return; - } + _logger.LogInformation("Targeting Canvas course: {CourseId}, at {Url}", _canvasSettings.CourseId, _canvasSettings.ApiUrl); + var modules = await _collectionFetcher.GetAll(_canvasSettings.CourseId); - _logger.LogInformation("Targeting Canvas course: {CourseId}, at {Url}", _canvasSettings.CourseId, _canvasSettings.ApiUrl); - var modules = await _collectionFetcher.GetAll(_canvasSettings.CourseId); + var formats = _exportOptions.Formats.Split(","); + var exporters = _exporterCollection.DetermineExporters(formats).ToArray(); - _logger.LogInformation("Attempting to use following formats: {Formats}", string.Join(", ", _exportOptions.Formats)); - var exporters = _exporterCollection.DetermineExporters(_exportOptions.Formats).ToArray(); + _logger.LogInformation("Attempting to use following formats: {Formats}", string.Join(", ", formats)); - foreach (var (format, exporter) in exporters) + foreach (var (format, exporter) in exporters) + { + _logger.LogInformation("Exporting to {Format} using {Exporter}...", format, exporter.GetType().Name); + exporter.Export(modules, format); + } + } + catch (Exception ex) { - _logger.LogInformation("Exporting to {Format} using {Exporter}...", format, exporter.GetType().Name); - exporter.Export(modules, format); + _logger.LogError(ex, "Error occured:"); + } + finally + { + _lifetime.StopApplication(); } - - _lifetime.StopApplication(); } private static IEnumerable Validate(object model) diff --git a/Epsilon.Cli/appsettings.example.json b/Epsilon.Cli/appsettings.example.json index d94cac10..3f8f72d5 100644 --- a/Epsilon.Cli/appsettings.example.json +++ b/Epsilon.Cli/appsettings.example.json @@ -1,21 +1,10 @@ { - "Logging": { - "LogLevel": { - "Default": "Debug", - "System": "None", - "Microsoft": "None" - } - }, "Serilog": { "Using": [ "Serilog.Sinks.Console" ], "MinimumLevel": { - "Default": "Debug", - "Override": { - "Microsoft": "Error", - "System": "Error" - } + "Default": "Debug" }, "WriteTo": [ { diff --git a/Epsilon/Export/ExportOptions.cs b/Epsilon/Export/ExportOptions.cs index c0226793..be4ed1cb 100644 --- a/Epsilon/Export/ExportOptions.cs +++ b/Epsilon/Export/ExportOptions.cs @@ -4,7 +4,7 @@ public class ExportOptions { public string OutputName { get; set; } = "Epsilon-Export-{DateTime}"; - public List Formats { get; } = new(); + public string Formats { get; set; } = "console"; public string FormattedOutputName => OutputName .Replace("{DateTime}", DateTime.Now.ToString("ddMMyyyyHHmmss")); diff --git a/Epsilon/Extensions/CoreServiceCollectionExtensions.cs b/Epsilon/Extensions/CoreServiceCollectionExtensions.cs index 47e35cef..97d307cf 100644 --- a/Epsilon/Extensions/CoreServiceCollectionExtensions.cs +++ b/Epsilon/Extensions/CoreServiceCollectionExtensions.cs @@ -12,7 +12,7 @@ public static class CoreServiceCollectionExtensions public static IServiceCollection AddCore(this IServiceCollection services, IConfiguration config) { services.AddCanvas(config.GetSection("Canvas")); - services.AddExport(config.GetSection("Export")); + services.AddExport(config); return services; } diff --git a/README.md b/README.md index ed3605f5..cb78a9c8 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ These students usually have a personal course within Canvas (from Instructure), During each semester, it is requested to take note of all KPI's which have been proven. To aid in these efforts, this application will gather all your mastered/proven [KPI's](https://hbo-i.nl/domeinbeschrijving/) and export your KPI's to a file format (e.g., JSON, Exel, CSV). -![Application demo](https://i.imgur.com/nd4zKAT.gif) +![Application demo](https://user-images.githubusercontent.com/12190745/176268592-e863e4c3-47b4-4af5-aeca-298d53a37c33.gif) ## Usage Read how to use the application in our Wiki located [here](https://github.com/Typiqally/epsilon/wiki/How-to-use).