From 727d826ce54a6d7191c15287b4af517d4fb13606 Mon Sep 17 00:00:00 2001 From: Jelle Maas Date: Tue, 21 Jun 2022 14:45:29 +0200 Subject: [PATCH 1/9] Change formats type to `string` and split with comma separator --- Epsilon.Cli/Startup.cs | 6 ++++-- Epsilon/Export/ExportOptions.cs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Epsilon.Cli/Startup.cs b/Epsilon.Cli/Startup.cs index fcefdd8f..c72c1ed4 100644 --- a/Epsilon.Cli/Startup.cs +++ b/Epsilon.Cli/Startup.cs @@ -63,9 +63,11 @@ private async Task ExecuteAsync() _logger.LogInformation("Targeting Canvas course: {CourseId}, at {Url}", _canvasSettings.CourseId, _canvasSettings.ApiUrl); var modules = await _collectionFetcher.GetAll(_canvasSettings.CourseId); - _logger.LogInformation("Attempting to use following formats: {Formats}", string.Join(", ", _exportOptions.Formats)); - var exporters = _exporterCollection.DetermineExporters(_exportOptions.Formats).ToArray(); + var formats = _exportOptions.Formats.Split(","); + var exporters = _exporterCollection.DetermineExporters(formats).ToArray(); + _logger.LogInformation("Attempting to use following formats: {Formats}", string.Join(", ", formats)); + foreach (var (format, exporter) in exporters) { _logger.LogInformation("Exporting to {Format} using {Exporter}...", format, exporter.GetType().Name); 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")); From e4dfa279e375038bec4a65cb07bef86dc0faba7f Mon Sep 17 00:00:00 2001 From: Jelle Maas Date: Tue, 21 Jun 2022 14:47:20 +0200 Subject: [PATCH 2/9] Use root configuration instead of configuration section --- Epsilon/Extensions/CoreServiceCollectionExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; } From 710611ded3954b6047875fdf7ccaf2a6084bc765 Mon Sep 17 00:00:00 2001 From: Jelle Maas Date: Tue, 28 Jun 2022 09:40:23 +0200 Subject: [PATCH 3/9] Fix exceptions not properly displaying in the console --- Epsilon.Cli/Program.cs | 21 +++++++++++--- Epsilon.Cli/Startup.cs | 43 +++++++++++++++++----------- Epsilon.Cli/appsettings.example.json | 13 +-------- 3 files changed, 44 insertions(+), 33 deletions(-) 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..ebf2201f 100644 --- a/Epsilon.Cli/Startup.cs +++ b/Epsilon.Cli/Startup.cs @@ -48,31 +48,40 @@ 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); - _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(", ", _exportOptions.Formats)); + var exporters = _exporterCollection.DetermineExporters(_exportOptions.Formats).ToArray(); - 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": [ { From 06edd58bf49f0fcbbe2291ba7006428df9088c7a Mon Sep 17 00:00:00 2001 From: Jelle Maas Date: Tue, 28 Jun 2022 10:26:33 +0200 Subject: [PATCH 4/9] Add all module item types according to documentation --- Epsilon.Canvas.Abstractions/Model/ModuleItem.cs | 3 +-- Epsilon.Canvas.Abstractions/Model/ModuleItemType.cs | 12 +++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) 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 From d80e190739cb8f138a93d1f2cf8f96ac6a5a35d1 Mon Sep 17 00:00:00 2001 From: Jelle Maas Date: Tue, 28 Jun 2022 21:27:46 +0200 Subject: [PATCH 5/9] Update application demo GIF --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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). From 0a52a3b66d79863b36d37c1284676c392bd3e8a0 Mon Sep 17 00:00:00 2001 From: Jelle Maas Date: Tue, 28 Jun 2022 22:33:35 +0200 Subject: [PATCH 6/9] Create code-analysis.yml --- .github/workflows/code-analysis.yml | 72 +++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) 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..89f73448 --- /dev/null +++ b/.github/workflows/code-analysis.yml @@ -0,0 +1,72 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "Code analysis" + +on: + push: + branches: [ "master", develop ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "master" ] + schedule: + - cron: '22 18 * * 5' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'csharp' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 From c8fb8acc9a44a0119ba46132f695507229e90e63 Mon Sep 17 00:00:00 2001 From: Jelle Maas Date: Tue, 28 Jun 2022 22:41:50 +0200 Subject: [PATCH 7/9] Remove comments and enable additional queries --- .github/workflows/code-analysis.yml | 37 ++--------------------------- 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/.github/workflows/code-analysis.yml b/.github/workflows/code-analysis.yml index 89f73448..eb074135 100644 --- a/.github/workflows/code-analysis.yml +++ b/.github/workflows/code-analysis.yml @@ -1,28 +1,16 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# name: "Code analysis" on: push: branches: [ "master", develop ] pull_request: - # The branches below must be a subset of the branches above branches: [ "master" ] schedule: - cron: '22 18 * * 5' jobs: analyze: - name: Analyze + name: Analyze code runs-on: ubuntu-latest permissions: actions: read @@ -33,40 +21,19 @@ jobs: fail-fast: false matrix: language: [ 'csharp' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] - # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support steps: - name: Checkout repository uses: actions/checkout@v3 - # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - - # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs - # queries: security-extended,security-and-quality + queries: security-extended,security-and-quality - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild uses: github/codeql-action/autobuild@v2 - # ℹ️ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - # If the Autobuild fails above, remove it and uncomment the following three lines. - # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. - - # - run: | - # echo "Run, Build Application using script" - # ./location_of_script_within_repo/buildscript.sh - - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 From 0bbf268fab47631d4ba380ac18d0a03874c1fbb4 Mon Sep 17 00:00:00 2001 From: Neal Geilen Date: Wed, 29 Jun 2022 08:51:04 +0200 Subject: [PATCH 8/9] Removed push from code-analysis.yml workflow --- .github/workflows/code-analysis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/code-analysis.yml b/.github/workflows/code-analysis.yml index eb074135..74942af4 100644 --- a/.github/workflows/code-analysis.yml +++ b/.github/workflows/code-analysis.yml @@ -1,10 +1,8 @@ name: "Code analysis" on: - push: - branches: [ "master", develop ] pull_request: - branches: [ "master" ] + branches: [ "master", develop ] schedule: - cron: '22 18 * * 5' From 0c6957e50081f66b65cfde8f0a6d85997ca7df3b Mon Sep 17 00:00:00 2001 From: Neal Geilen Date: Wed, 29 Jun 2022 08:54:12 +0200 Subject: [PATCH 9/9] Typo code-analysis.yml --- .github/workflows/code-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-analysis.yml b/.github/workflows/code-analysis.yml index 74942af4..e45bb7b7 100644 --- a/.github/workflows/code-analysis.yml +++ b/.github/workflows/code-analysis.yml @@ -2,7 +2,7 @@ name: "Code analysis" on: pull_request: - branches: [ "master", develop ] + branches: [ "master", "develop" ] schedule: - cron: '22 18 * * 5'