Category: .NET Core

Docker–fourth part–part 20

Time to push to docker

1. putting the docker password into the pipeline variables

2. Modifying the yaml

3. Waiting for build

Error in Docker:  Incorrect name or password

Now, I want to create 2 jobs to isolate Docker from the main build.

I encounter some errors in the yaml file . That shows fast in the AzureDevops, but you must figure what it is by reading the line

/azure-pipelines.yml: (Line: 8, Col: 7, Idx: 271) – (Line: 8, Col: 7, Idx: 271): Mapping values are not allowed in this context.

/azure-pipelines.yml: (Line: 45, Col: 3, Idx: 1225) – (Line: 45, Col: 4, Idx: 1226): While parsing a block mapping, did not find expected key.

Job Build Docker has an invalid name. Valid names may only contain alphanumeric characters and ‘_’ and may not start with a number.

(a name attribte was not indented, steps was not found before script, build name having spaces)

Now trying to build again. Error because I have put the password variable from Azure secret? Delete the variable, putting another variable with the same name, not secret. Works!

Now I have on docker hub a new image, ignatandrei/infovalutar  : https://hub.docker.com/r/ignatandrei/infovalutar

You can run with

docker run –rm -it -p 8080:8080  ignatandrei/infovalutar:latest

And then go to http://localhost:8080/swagger/

And that was all! ( pipeline definition at https://dev.azure.com/ignatandrei0674/InfoValutar/_build?definitionId=5&_a=summary )

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

Docker–third part–part 19

Trying different  codes in the csproj to add dynamically content from a folder ( including the dll’s copied there ) and to retrieve in the output directory: ( reading from internet of all those stuff)

Version 1:

<!–<Target Name=”ContentsBeforeBuild” AfterTargets=”BeforeBuild”>
<ItemGroup>
<Content Include=”plugins\**” />
</ItemGroup>
</Target>—>

Version 2:

<!–<Content Update=”plugins\**\*.dll” CopyToOutputDirectory=”Always” LinkBase=”plugins”>

</Content>—>

Version 3:
<!–<Content Update=”$([System.IO.Directory]::GetFiles(‘$(ProjectDir)plugins’, ‘*.*’, SearchOption.AllDirectories))” CopyToOutputDirectory=”PreserveNewest”>–>

<!–</Content>—>

Version 4: – works!

<ItemGroup>
<None Remove=”plugins\” />
<Content Include=”plugins\**\*.dll” CopyToOutputDirectory=”Always”/>
</ItemGroup>

 

Now, I want to make this docker each time that I modify  and show to the end users to test it.

However, this should be not in the same process as running the tests  – the tests should be very fast in order to see problems – the making of release software could take minutes.

Going to https://dev.azure.com/ignatandrei0674/ and making a new project to deal with this.Creating new project, integrating with GitHub – seamless integration with .NET Core – even created a azure-pipelines.yml for me.

Extra bonus: GitHub actions runs on Ubuntu. I will put Azure to run on Windows. This way, I know that the build of the project works either way

Now, a different error in docker:

Access to the path ‘C:\app\InfoValutar\InfoValutarDOS\obj\InfoValutarDOS.csproj.nuget.dgspec.json’ is denied.

Oh, forgot to put a .dockerignore . First I put where the docker file was –big mistake. Should be put where the folder to be included is!

Now ,a different error in docker

Access to the path ‘C:\app\InfoValutar\InfoValutarWebAPI\InfoValutarWebAPI.xml’ is denied.

Oh, give me a break! Delete the .xml and add later to .gitignore and .dockerignore ( as full path, I do not want to ignore ALL xml files)

I works now!!!!

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

Docker–second part–part 18

Now , I must replace all with powershell files. Some problem  – if I build twice, it says : resource already exists. So I need to add

–Force

parameter.

Now pushing to GitHub https://github.com/ignatandrei/InfoValutar/commit/2c487963da53f04f94a0a7b060999f8e27635179

and see if it works. No, error on .sln build.

ObjectNotFound: (/home/runner/work/I\u2026nfoValutar/plugins”

Apparently, it is a Unicode character ?

Try to save as ASCII file. Waiting for GitHub action to do it’s magic.

Same Error – now putting some messages with echo to see what is there

echo “args 0 ”  $args[0]
echo “args 1 ” $args[1]
$a= Get-Location
echo $a
echo now copy

Now waiting for GitHub actions to display – it does NOT show the console from powershell, just the error!

Putting in After Build to copy the plugins.

Same error. Looking very, very attentive to the command , I see now. Can you see ?

pwsh $(ProjectDir)preBuild.ps1 “”$(RepoRoot)plugins\”  “$(TargetDir)”

Apparently, pwsh from Windows is more forgetful than the Linux one… ( or it is not the same ? Maybe because I have powershell on my PC ?)

Now ( after deleting double double quotes) shows also the powershell messages!

Now I can make docker!

And the first problem arises. When building the .sln , it copies to the output folder the plugins. But not when publish the csproj.

Try with –no-build when publish and adding

<RuntimeIdentifiers>win10-x64;linux-x64</RuntimeIdentifiers>

to the .csproj

Now, dotnet publish does not copy the plugins  – I should copy by hand ?

So – figure that I do not copy to the final output – but direct to the project.

1. I should copy there in the build event of the project – modify the arguments to have copy in the plugins folder

2. I should include in the .csproj any new plugins:

<Content Include=”plugins\**”>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

Error duplicate items  – found it was

<Content Update=”plugins\**” CopyToOutputDirectory=”PreserveNewest”>

3. Do not include in GitHub – already done – plugins folder is not included

Now trying to execute in swagger to give list of plugins / banks => internal server error

Trying to publish without single file => give empty list /banks. Let’s see  -but next time

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

Docker–first part–part 17

Trying to put the web into docker. In order to have easy builds for the developer , we copy the sln, then the csproj , then dotnet restore, then copy files. This way we get advantage of Docker caching.

Created dockerForWebAPI.txt

and run

docker build -f dockerForWebAPI.txt  -t infovalutar ..

Docker has not recursive copy – https://github.com/moby/moby/issues/15858

Solution: copy the .csproj one by one. ( other solution:  .tar file and copy the .csproj into tar, then use ADD command)

So copy the .sln with

COPY InfoValutar/*.sln ./

Then trying to copy files

Version 1

COPY  InfoValutar/InfoValutarDOS/InfoValutarDOS.csproj ./

( not good, same dir)

Version 2

COPY  InfoValutar/InfoValutarDOS/InfoValutarDOS.csproj ./app/InfoValutarDOS/InfoValutarDOS.csproj

(not good , discovered that creates another app folder – thanks for the docker run –rm -it infovalutar:latest /bin/bash )

Version 3

COPY  InfoValutar/InfoValutarDOS/InfoValutarDOS.csproj ./InfoValutarDOS/InfoValutarDOS.csproj

Good. Now copy files and build solution

And now it is the moment when echo and xcopy for plugins will bite me  – no xcopy on linux….

The only thing that I know to work in WIndows and Linux is … Powershell.

Any .NET Core 3 has this – run pwsh. It remains to install to my directory –  see https://andrewlock.net/new-in-net-core-3-local-tools/

The version of powershell on my PC differs from the version on Windows Container from GitHub actions.  Switch to Ubuntu.

Again – does not work . Try with pwsh –Command.

It does work on GitHub actions but NOT on my PC ( does not recognize command. ) . Thinking different pwsh version.

But on thing is the same  – running file.

Create a powershell file

Copy-Item -Path $args[0] -Destination $args[1] –Recurse

and running this file with

pwsh $(ProjectDir)pb.ps1 “$(TargetDir)”  “$(SolutionDir)plugins\$(ProjectName)”

( Do not forget to run first

dotnet tool restore

in the solution folder!)

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

Swagger/OpenAPI –part 16

In order to see the WebAPI, Swagger is a default technology. Reading https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger?view=aspnetcore-3.0 , seems to have 2 options: Swashbuckle and NSwag. Looking at github repositories, both have > 2k stars, active development, tutorials. The only thing that I see more at NSwag are generators for Angular.

Integrated NSwag as for the tutorial from https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-nswag?view=aspnetcore-3.0&tabs=visual-studio . There is a small problem – when I try the swagger , I should put explicit the version. However, a not experienced user can not see this value.

Trying to put documentation : when I go to Project=>Properties=>Build and click the XML documentation, shows the full path to the XML. I do not need this!  So I edit the .csproj directly and change from full path to file

Also, because I want to be sure to have documentation, I change “warnings to errors”.

So now I must document Program and main(removed public from startup.cs and createwebhost – to not document)

Total: 6 changes , https://github.com/ignatandrei/InfoValutar/commit/4fbff903c4510acbcb219d0263ae89736e9f2d8d

So now I can browse to swagger

However, I should indicate to people that swagger is enabled to invite them browse to this – and this is easy to do in Kestrel, right ? Just take the address of the url …

So, trying in Program.cs to find the adresses:

var build = CreateHostBuilder(args).Build();
var s = build.Services.GetService(typeof(KestrelServerOptions));
var s1 = build.Services.GetService(typeof(IServer));
var s2 = build.Services.GetService(typeof(IServerAddressesFeature));
build.Run();

 

Not a chance – not yet configured. So , next chance is in Startup.cs

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//other code
var sa = app.ServerFeatures.Get<IServerAddressesFeature>();
var urls =string.Join(",", sa.Addresses.Select(it => it + "swagger"));
Console.WriteLine("please use " + urls);

( for this, you must not use IIS Express, but rather the project)

 

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

Repairing the build and versioning–part 15

Now , after copy the plugins, the build is not working.

Thnking about the build events, I realize that to find same copy command on Linux and Windows is difficult – so Windows it is.

( and, BTW , In LInux the macro $(SolutionDir ) does not work use  repoRoot

https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2019

https://github.com/Microsoft/msbuild/issues/2397

)

Switch windows-latest on https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idruns-on 

Now tests are failing – repairing the tests.

I realize that I cannot build just the csproj – the solution sln knows the order in which to build the projects- but the .csproj does not. So now building the sln and then publish

Now giving error in Github, but not on local. More, there was a not repeatable . I figured was because of the parallel builds so this is the final line

dotnet build –configuration Release InfoValutar/InfoValutar.sln /m:1

Now it works!

The only programming thing that I have done is to add versioning , https://github.com/microsoft/aspnet-api-versioning/wiki/How-to-Version-Your-Service . I do tend to say that the URL is a Unique Identifier – so I want the versioning be part of the URL.

As advised by https://github.com/microsoft/aspnet-api-versioning/wiki/Versioning-via-the-URL-Path

I added the pacakage Microsoft.AspNetCore.Mvc.Versioning and

services.AddApiVersioning();

and on the controller

[ApiVersion( “1.0” )]

[Route(“api/v{version:apiVersion}/[controller]/[action]”)]

and now I can access

api/v1.0/TodayRates/banks

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

Plugin copy and caching- part 14

I have had 2 problems to solve

  1. How to put the plugins for the console and web api ?
  2. How to cache the data  ? ( plugins / exchange rates)

 

The solution for the first problem should be easy for the programmer PC, and for the deploying the application ( console/ web api/ etc )There are several solutions :

  1. Each plugin knows where to copy the dll ( console/web api)
  2. The application ( console / webapi) knows a special place from which to copy the plugin definition

 

I tend to agree with both – but mostly with the second. So … the idea is as follows:

The plugin builds and copy the output to a special folder, named “plugins” ( what a surprise, righyt?)

The console /webapi copies the folder plugins under his directory

 

The only problem here is that we should ensure that plugins are build first, even if the application does NOT have reference to them.

For this, there is a special menu in VS for solution, namely “build order” – you go to this –and after to the second tab, project dependencies. For the console and web I select as dependency the two loading projects – InfoValutarNBR and InfoValutarECB. The changes are reflected into the sln file

I could have done this on just the InfoValutarLoadingLibs project – but maybe I can have another way to load the libraries ( not so much for the moment )

So now I begin to modify what happens

after build events for InfoValutarNBR and InfoValutarECB

xcopy “$(TargetDir)*.*” “$(SolutionDir)plugins\$(ProjectName)” /E /F /I /Y /R

and pre build events for InfoValutarDOS and InfoValutarWebAPI.

Now, there are several things to do:

  1. Add to .gitignore the plugins folder to not put into the source control( ok)
  2. Write some documentation about the process
  3. Think about linux/docker compiling – there is a xcopy there  ?

 

About the documentation –  I just did. More, I create a InfoValutarPluginStarter , in order for others to copy this project and make a new plugin.

Realized also that the WebAPI could be simpler

[HttpGet(“{bank}”)]
public IAsyncEnumerable<ExchangeRates> Rates([FromRoute] string bank)

And also that I should throw another exception if Bank is null or empty:

if(string.IsNullOrWhiteSpace(bank))
throw new ArgumentNullException($”{nameof(bank)} cannot be empty”);

 

For docker compiling – next time

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

Creating the WebAPI–part 13

I am now tired of continuously improving the console application – so now some work that others can see really.  Creating the WebAPI is simple as a project  – and I was amazed to see a WeatherForecast controller.

I need just to be able to see the today exchange rates via API . So created a TodayRates , modify the launchSettings.json in order to start with my controller.

I need the plugin that loads to be a global dependency. So I add as a Singletion in the services

services.AddSingleton< LoadExchangeProviders>(new LoadExchangeProviders(“plugins”));

and then I inject into the controller constructor ( I can do in the method also, but many methods needs the same dependency )

public TodayRates(ILogger<TodayRates> logger, LoadExchangeProviders prov)
{
_logger = logger;
_prov = prov;
}

 

Now I need a method to see what are the banks / plugins that are loaded . Linq to the rescue :

 

[HttpGet]
public IEnumerable<string> Banks()
{
return _prov
.LoadExchange()
.Select(it=>it.Bank)
.ToArray();
}

Now we should load the data from the provider to show actual rates

public async IAsyncEnumerable<ExchangeRates> Rates(string bank)
{
var provBank = _prov
.LoadExchange()
.FirstOrDefault(it => string.Equals(bank, it.Bank, StringComparison.InvariantCultureIgnoreCase));

switch (provBank)
{
case null:
yield return null;
break;
default:
{
await foreach (var data in provBank.GetActualRates())
{
yield return data;
}

break;
}
}

}

 

All good. There are  3 problems:

  1. How to put the plugins for the console and web api ?
  2. How to cache the data  ? ( plugins / exchange rates)
  3. Should we throw an exception when a bank does not exists, instead of returning null ?

 

Thinking of this code, I realized that I begin to put logic into controllers. So – let’s move from the controller to the business.

For example, now I have this:

[HttpGet]
public IEnumerable<string> Banks()
{
return _prov.Banks();
}

 

And this

[HttpGet]
public IAsyncEnumerable<ExchangeRates> Rates(string bank)
{
return _prov.Rates(bank);
}

So now I can change in the Business Layer without problems.

Looking at the Console Application vs  WebAPI, I realized that are different. The console is loading the whole data from the providers – the WebAPI is loading on demand.  We could do for the console the same behavior  – but the console is loading very fast all data.

For the answer at

Should we throw an exception when a bank does not exists, instead of returning null ?

– seems to be yes.

So instead of

case null:
yield return null;
I put

case null:
throw new ArgumentOutOfRangeException(nameof(bank),$”cannot find {bank}”);

 

For the 2 questions, the answer next time.

 

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

Documentation and refactoring for plugins and wrong code coverage – part 12

I realized that will be no documentation for plugins – until I create one .

Figured also that each plugin should have a name  -to understand from where he grabs data – so some code involved code.

 

Asking when and if the plugins are copied to the application  – not found yet an answer…

 

Now the user can choose what bank he wants to see data ? We could do this for the console application –  and I think that is the moment to play with Icaza  Gui Terminal https://github.com/migueldeicaza/gui.cs  – Created buttons to display plugins (NBR and ECB ). Will not work if many plugins will come – but it is ok for the moment.

Discovered the window for code coverage – read https://github.com/tonerdo/coverlet/blob/master/Documentation/VSTestIntegration.md

Some error when writing the .runsettings file – discovered from command line ( GUI does not show)

Reading the docs , https://docs.microsoft.com/en-us/visualstudio/test/using-code-coverage-to-determine-how-much-code-is-being-tested?view=vs-2019#analyze-code-coverage , it says that is not available for community…

Back to square 1 after 1 hour- just made documentation.

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

Loading data from NBR / ECB as plugins–part 11

Modified project – instead of one project that have the NBR and ECB exchange rates,I have now 4
1. Common interfaces / classes

2 NBR loading( first plugin)

3 ECB loading ( second plugin)

4 plugin loading project

 

Going to .NET Standard 2.1 and trying to load the NuGet https://github.com/natemcmaster/DotNetCorePlugins/blob/master/docs/what-are-shared-types.md .

Does not load. Going back to .NET Core 2.0  – some result.

RTFM – not supported .NET Standard  https://github.com/natemcmaster/DotNetCorePlugins/issues/24

So created a .NET Standard dll and changed from

<TargetFramework>netstandard2.0</TargetFramework>

to

<TargetFramework>netcoreapp3.0</TargetFramework>

Copied the code from https://github.com/natemcmaster/DotNetCorePlugins/blob/master/samples/hello-world/HostApp/Program.cs .

Loaded 0 plugins.

Put plugins in plugins directory – again 0 plugins.

Read the code copied – I must create separate folders for each plugin – makes sense, because we can have plugin diamond dependency – see here https://github.com/natemcmaster/DotNetCorePlugins/blob/master/docs/what-are-shared-types.md

Put in separate folder – error in this line

// This assumes the implementation of IPlugin has a parameterless constructor
var plugin = Activator.CreateInstance(pluginType) as BankGetExchange;

 

Apparently , this code does NOT mean to have a parameterless contructor – even if seems from the code


public class GetNBRExchange: BankGetExchange
{
private readonly HttpClient httpClient;

public GetNBRExchange(HttpMessageHandler handler = null)
{
if (handler != null)
httpClient = new HttpClient(handler, disposeHandler: false);
else
httpClient = new HttpClient();
}

 

So small modification to preserve tests and default code:


public class GetNBRExchange: BankGetExchange
{
private readonly HttpClient httpClient;
public GetNBRExchange() : this(null)
{

}
public GetNBRExchange(HttpMessageHandler handler)
{
if (handler != null)
httpClient = new HttpClient(handler, disposeHandler: false);
else
httpClient = new HttpClient();
}

Now it works …

You can find modifications here

https://github.com/ignatandrei/InfoValutar/commit/0e4cf6b83bb5f4cbab71e9e8c96ae719771fcae1 – total 13 changed files….

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

Andrei Ignat weekly software news(mostly .NET)

* indicates required

Please select all the ways you would like to hear from me:

You can unsubscribe at any time by clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.