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