-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
232 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: DWAPI Bot Tag & Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
|
||
jobs: | ||
build: | ||
name: Create Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup .NET Core | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: 3.1.201 | ||
- name: Install dependencies | ||
run: dotnet restore | ||
- name: Build | ||
run: dotnet build --configuration Release --no-restore | ||
- name: Test | ||
run: dotnet test --no-restore --verbosity normal | ||
|
||
- name: Pub .NET Core | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: 3.1.201 | ||
- name: Publish | ||
run: dotnet publish --configuration Release -o dwapi-bot | ||
- name: Zip Folder | ||
run: zip -r dwapi-bot.zip dwapi-bot | ||
|
||
- name: Create Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: Release ${{ github.ref }} | ||
draft: false | ||
prerelease: false | ||
|
||
- name: Upload Release Asset | ||
id: upload-release-asset | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./dwapi-bot.zip | ||
asset_name: dwapi-bot.zip | ||
asset_content_type: application/zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Collections.Generic; | ||
using Dwapi.Bot.Core.Application.Matching.Commands; | ||
using Dwapi.Bot.SharedKernel.Enums; | ||
|
||
namespace Dwapi.Bot.Core.Domain.Indices.Dto | ||
{ | ||
public class ScanDto | ||
{ | ||
public bool AllSites { get; set; } | ||
public int[] Sites { get; set; } | ||
|
||
public List<ScanSubject> GenerateCommands(List<int> siteCodes) | ||
{ | ||
var commands=new List<ScanSubject>(); | ||
if (AllSites) | ||
{ | ||
foreach (var site in siteCodes) | ||
{ | ||
commands.Add(new ScanSubject(site.ToString())); | ||
} | ||
} | ||
else | ||
{ | ||
foreach (var site in Sites) | ||
{ | ||
commands.Add(new ScanSubject(site.ToString())); | ||
} | ||
} | ||
return commands; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Dwapi.Bot.Core.Domain.Indices.Dto | ||
{ | ||
public class SubjectSiteDto | ||
{ | ||
public int SiteCode { get; set; } | ||
public string FacilityName { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return $"{SiteCode},{FacilityName}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using CSharpFunctionalExtensions; | ||
using Dwapi.Bot.Core.Application.Configs.Queries; | ||
using Dwapi.Bot.Core.Application.Indices.Commands; | ||
using Dwapi.Bot.Core.Application.Matching.Commands; | ||
using Dwapi.Bot.Core.Domain.Configs; | ||
using Dwapi.Bot.Core.Domain.Indices; | ||
using Dwapi.Bot.Core.Domain.Indices.Dto; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Serilog; | ||
|
||
namespace Dwapi.Bot.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
public class WorkerController : Controller | ||
{ | ||
private readonly IMediator _mediator; | ||
private readonly ISubjectIndexRepository _repository; | ||
|
||
public WorkerController(IMediator mediator, ISubjectIndexRepository repository) | ||
{ | ||
_mediator = mediator; | ||
_repository = repository; | ||
} | ||
|
||
[HttpPost("Refresh")] | ||
public async Task<ActionResult> Get(RefreshIndex command) | ||
{ | ||
if (command.BatchSize <= 0) | ||
return BadRequest(); | ||
|
||
try | ||
{ | ||
var results = await _mediator.Send(command); | ||
|
||
if (results.IsSuccess) | ||
return Ok("Refreshing..."); | ||
|
||
throw new Exception(results.Error); | ||
} | ||
catch (Exception e) | ||
{ | ||
var msg = $"Error executing {nameof(RefreshIndex)}(s)"; | ||
Log.Error(e, msg); | ||
return StatusCode(500, $"{msg} {e.Message}"); | ||
} | ||
} | ||
|
||
[HttpPost("Scan")] | ||
public async Task<ActionResult> Get(ScanDto command) | ||
{ | ||
var results = new List<Result>(); | ||
var siteCodes = new List<int>(); | ||
|
||
if (null==command) | ||
return BadRequest(); | ||
|
||
try | ||
{ | ||
if (command.AllSites) | ||
{ | ||
var sites = await _repository.GetSubjectSiteDtos(); | ||
siteCodes.AddRange(sites.Select(x=>x.SiteCode).ToList()); | ||
} | ||
else | ||
{ | ||
siteCodes = command.Sites.ToList(); | ||
} | ||
|
||
var commands = command.GenerateCommands(siteCodes); | ||
foreach (var scanCommand in commands) | ||
{ | ||
var result= await _mediator.Send(scanCommand); | ||
results.Add(result); | ||
} | ||
|
||
if (results.Any(x=>!x.IsFailure)) | ||
return Ok("Scanning..."); | ||
|
||
var scb=new StringBuilder("Errors scanning:"); | ||
foreach (var result in results) | ||
{ | ||
scb.AppendLine(result.Error); | ||
} | ||
throw new Exception(scb.ToString()); | ||
} | ||
catch (Exception e) | ||
{ | ||
var msg = $"Error executing {nameof(ScanSubject)}(s)"; | ||
Log.Error(e, msg); | ||
return StatusCode(500, $"{msg} {e.Message}"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
{ | ||
{ | ||
"profiles": { | ||
"Dwapi.Bot": { | ||
"commandName": "Project", | ||
"launchBrowser": false, | ||
"applicationUrl": "https://localhost:5001;http://localhost:5000", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"applicationUrl": "https://localhost:5001;http://localhost:5000" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters