Category: exchange rates

European Central Bank- part 8

Because I have had last time a flop, now I decide to get the European Central Bank rates.

Going to https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html show the XML –  but not the XSD.

So now it is about how to transform from XML to C# classes –  and I remembered a discussion with https://siderite.dev/ – Visual Studio does now how to paste from XML to classes.  ( Edit=>PasteSpecial +> Paste XML as classes. Ensure that you have not space on the first line…)

Copy and paste fron BNR class, modify the URL to https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml

Now the program.cs looks like this

 


var nbr = new GetNBRExchange();
var list = nbr.GetActualRates();
await foreach (var e in list)
{
     Console.WriteLine($"1 {e.ExchangeFrom} = {e.ExchangeValue} {e.ExchangeTo}");
}

var ecb = new GetECBExchange();
list = ecb.GetActualRates();
await foreach (var e in list)
{
     Console.WriteLine($"1 {e.ExchangeFrom} = {e.ExchangeValue} {e.ExchangeTo}");
}

See the similarities ?

It is time for some interfaces . The simplest one is


public interface BankGetExchange
{
IAsyncEnumerable<ExchangeRates> GetActualRates();
}

And now the Program.cs looks like

static async Task Main(string[] args)
{

await ShowValues(new GetNBRExchange());
await ShowValues(new GetECBExchange());
}
public static async Task ShowValues(BankGetExchange bank)
{
var list = bank.GetActualRates();
await foreach (var e in list)
{
Console.WriteLine($"1 {e.ExchangeFrom} = {e.ExchangeValue} {e.ExchangeTo}");
}
}

and seems better now!

What can be improved ?  Well , to process both in parallel ( now they are processed one after another)
Another condition is not to display intermixed. So the code could stay like

So I ended with the following:

using InfoValutarShared;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace InfoValutarDOS
{
    class Program
    {
        static async Task Main()
        {
            var l = new List<Task<ExchangeRates[]>>
            {
                Rates(new GetNBRExchange()),
                Rates(new GetECBExchange()),

            };
            
            while (l.Count > 0)
            {
                var x = l.ToArray();

                var data = await Task.WhenAny(x);
                ShowValues(await data);
                l.Remove(data);
            }
        }
        public static async Task<ExchangeRates[]> Rates(BankGetExchange bank)
        {
            var list = bank.GetActualRates();
            return await list.ToArrayAsync();
            
                        
        }
        public static void ShowValues(ExchangeRates[] list)
        {
            foreach (var e in list)
            {
                Console.WriteLine($"1 {e.ExchangeFrom} = {e.ExchangeValue} {e.ExchangeTo}");
            }
        }


    }
}

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

Try to show the result online in docker with dotnet try- part 7

Trying to put the dotnet try in docker

Each line from here is taking time – save this as docker.console file

FROM mcr.microsoft.com/dotnet/core/sdk:3.0
RUN dotnet tool install -g –add-source “https://dotnet.myget.org/F/dotnet-try/api/v3/index.json” dotnet-try
ENV PATH=”$PATH:/root/.dotnet/tools”
#ENV ASPNETCORE_URLS=http://+:5000
CMD dotnet try –verbose –port 443
EXPOSE 443

 

I can run this by

docker build -f ./console.docker . -t drop
docker run –rm -it -p 5000:5000/tcp drop:latest

However , I cannot find a way to see the output of the dotnet try in the browser.

( Problem show below) .Raised a feature request

https://github.com/dotnet/try/issues/590

So spent time, but not happy ending

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

Show the software- artifacts and dotnettry –part 6

So I was about artifacts – what if I put the console as an artifact , to can show the work to other people ?  Read about artifacts at Github Actions at https://help.github.com/en/github/automating-your-workflow-with-github-actions/persisting-workflow-data-using-artifacts . Seems easy.  One indentation problem later and I have a 34 MB application that is attached to the current action and it is listing the exchange rates . Good.

Now , after I have a working copy, I want to write all the ideas that this exchange rates application can do – put those on GitHub Issues –  see https://github.com/ignatandrei/InfoValutar/issues

Let’s try this:  https://github.com/ignatandrei/InfoValutar/issues/3 . : I want to others to play with my application – and dotnetry is an obvious choice.

Created a ConsoleDOS.md with the following

# Console

“`cs –source-file ./../InfoValutar/InfoValutarDOS/Program.cs –project ./../InfoValutar/InfoValutarDOS/InfoValutarDOS.csproj

“`

Running dotnet try in the folder  shows the file, however , when  running the program, error occurs

Program.cs(18,13): error CS8652: The feature ‘async streams’ is currently in Preview and *unsupported*. To use Preview features, use the ‘preview’ language version.

What? The project is compiling ok…

Trying to run the latest version of dotnet try

dotnet tool install -g –add-source “https://dotnet.myget.org/F/dotnet-try/api/v3/index.json” dotnet-try

and running my project again shows a different error:

 

Unhandled Exception: Unhandled exception. System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
 ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
 ---> System.ComponentModel.Win32Exception (0x80090304): The Local Security Authority cannot be contacted
   --- End of inner exception stack trace ---

Now it is time to solve this!

Apparently, reading again https://bnro.ro/Cursurile-pietei-valutare-in-format-XML-3424.aspx shows that needs TLS1.2

So this is the solution:


ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

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

Running CI tests- part 5

Now I want that every time I commit the project , the tests should be run. I do not want all the test, but just the ones without external dependencies.

For that , I decorate with

[Trait(“External”, “0”)]

and

[Trait(“External”, “1”)]

the ones that are using just local resources, respectively the internet.

I modify the dotnetcore.yml from Github to run the test by adding

– name: run tests

run: dotnet test –filter “External=0” InfoValutar/InfovalutarTest/InfovalutarTest.csproj

( be aware that VS does not work well with Github actions – I made from Github desktop)

( encounter an error because Data vs data  – Linux is case sensitive –  Windows is spoiling me)

Trying now to find how to put an issue automatically when something is wrong

Found https://github.com/technote-space/toc-generator  – good to have. No work from the first try. Modifying the yml to support more. Does not work, no matter what I do… Remains in the project- maybe latter.

Not found anything  similar. Thinking better , this is something that should be at the Action / Job level, not adding specific step. Searching at Settings / Actions, Settings / Notifications – nothing.

Searching the documentation – nothing ( GitHub actions still in beta) . However, found something interesting ; any action has artifacts.

Good . But time is up….

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

Badge, tests–live and mock–part 4

(This is the result of 1 hour per day auto-challenge as a full cycle developer)

Reading https://github.com/sdras/awesome-actions I discovered that I can easy add a badge that is building correctly.

Not working ( shows “ no status” ). Thinking about spaces –but no. Maybe a bug ? Resolving later…

Now it time to add some tests…

Moving first the Exchange Rates objects to a separate dll. Add a class for obtaining NBR exchange rates.

Modified the csproj to treat all warnings as errors . Figuring that I have forgot at the definition of the exchange rates the bank

Added live tests that finds the exchange rates on the internet.

Now we want not do the test with the internet open- but just looking now to how it is the parsing of the data from the . So we wnt to mock the HttpClient in .NET Core. Looking at the class, it has no interface ( bad, shame….) . So we cannot mock ?  Searching internet

Found https://github.com/richardszalay/mockhttp . So I copied from the internet the NBR XML, put into a file, mock the message handler , modified the constructor of the NBR – and …. error in parsing XML! Turns that there was an “\r\n” as the first line … and XML cannot do a trim …

Work done:

For reorganizing the project to support tests: working at 7 files: https://github.com/ignatandrei/InfoValutar/commit/2112817f929de6941e8c3fbbe113f1083521d855

For adding live tests: working at 3 files

https://github.com/ignatandrei/InfoValutar/commit/655dcea975d16a50183212b2070d47a30d2885d6

For mocking : working at 4 files

https://github.com/ignatandrei/InfoValutar/commit/d1e3eda3ca27f2614e6965500bf3e7ed28902f21

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

Source control and build–part 3

(This is the result of 1 hour per day auto-challenge as a full cycle developer)

I need to put somewhere the sources – GitHub seems the obvious choice. So I created https://github.com/ignatandrei/infoValutar/ and put there the project.

Now trying to help others to see the final result – and here GitHub actions can help build the project. GitHub actions already has a .NET Core  workflow . Moved to 3.0.100 version of .NET Core and also replacing dotnet build with dotnet publish to have a single file trimmed (https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0 ). Making error once ( the first argument of build should be the project , not the switches) and , after this, receiving error from github

MSBUILD : error MSB1009: Project file does not exist.

Switch: InfoValutarInfoValutarDOSInfoValutarDOS.csproj

Remember the / vs \ in Linux and Windows  ?

Apparently

dotnet publish InfoValutar\InfoValutarDOS\InfoValutarDOS.csproj -r win10-x64 -p:PublishSingleFile=true –self-contained

works in Windows, but not in Linux , but

dotnet publish InfoValutar/InfoValutarDOS/InfoValutarDOS.csproj -r win10-x64 -p:PublishSingleFile=true –self-contained

works both in Windows and Linux

Now reading about how to create a release.

The most comprehensive is https://github.com/actions/upload-release-asset . However, I need also a change log and a way to say automatically what release is.So I need the current day and time to name the release. However, too much for this kind – and not mention that GitHub Actions are in beta. So no need to spend too much on this. – better to go to AzureDevOps and let Azure DevOps handle the process.

But , for the moment, I have the Source Control activated and an automatic build of the first 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

Reading from internet–part 2

(This is the result of 1 hour per day auto-challenge as a full cycle developer)

After some searching, I have found this page https://bnro.ro/Cursurile-pietei-valutare-in-format-XML-3424.aspx where it says it has the latest BNR exchange rates in XML format – https://www.bnr.ro/nbrfxrates.xml – and it has also an xsd schema : https://www.bnr.ro/xsd/nbrfxrates.xsd ( Also I have discovered this page for mobile : https://bnro.ro/curs_mobil.aspx  -to be discussed later)

So we have a XSD and a XML on internet – to be read into C# classes . Plain and simple, right ?

Step 1 (technical):  From the XSD we should generate classes in C#. Searching on internet – found the first answer : https://www.liquid-technologies.com/online-xsd-to-cs-generator – not so good, since wants to have his own deserializer….

Trying the second options – found that I should launch VS Command – and put

xsd nbrfxrates.xsd /classes

Step 2(technical); Download the xml from the internet – use HttpClient

Step3(technical): Deserialize the JSON to see the data.

Step 4(technical): Deciding if exchange value should be float, decimal or double (http://net-informations.com/q/faq/float.html)

Step5(business): seeing multiplier ( currency multiplied by 100 )

And one hour passes…

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

Exchange rates–start project – part 1

(This is the result of 1 hour per day auto-challenge as a full cycle developer)

Long time ago I have made a site about exchange currency rates for National Bank of Romania( and l, later, also Central Europeean Bank ) . It was started on ~ 2004  – found image at https://web.archive.org/web/20041215090302/http://www.infovalutar.ro/

Then was passed via MVC1 – and it looks like in https://web.archive.org/web/20180227023708/http://www.infovalutar.ro/bnr

Now it is the moment to pass to .NET Core and Azure.

Here are some requirements:

  1. Must parse at specified times the exchange currencies from multiple banks
  2. Must show the exchange rates
  3. Must have a Web application, a Console one , a Mobile one
  4. Must be easy accessible to programmers – if they want to have the exchange rates ( rss, custom links)
  5. Must have a download link for all values
  6. Must have charts
  7. Must be easy to use – whatever that means

 

I will work at the applications 1 hour per day – and see what it is happening over the 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

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.