Category: azure

TILT- ConnectionSecrets in Azure–part 7

There is relatively easy to use – just go to your web app in Azure, Configuration, ConnectionStrings and add your data.

This tutorial is based on the following article:

https://docs.microsoft.com/en-us/azure/app-service/tutorial-dotnetcore-sqldb-app

The .NET Core code is simple:

services.AddDbContext<MyDatabaseContext>(options =>
         options.UseSqlServer(Configuration.GetConnectionString(“AZURE_SQL_CONNECTIONSTRING”)));

Tools used:

https://portal.azure.com/

TILT–CI and CD–part 6

Because the Source Control is Github and has Actions when submitting the code, I use this.

Also, when creating an Azure WebSite , you can integrate with Github and he will add the yaml for you and the secrets to deploy

I have added also badge to see the result of the action in the readme file. Deploy to Azure build

For the moment , just swagger available to see that the deploy was successfull . Results at https://tiltwebapp.azurewebsites.net/swagger

Tools used:

https://portal.azure.com/#create/Microsoft.WebSite

Github Actions: https://github.com/ignatandrei/TILT/actions

TILT- database–part 3

The Azure options for creating a database are enough to stay to think about:

I will create an Azure Sql Database – now more options

To choose one should evaluate deeply https://docs.microsoft.com/en-us/azure/azure-sql/database/features-comparison

And if you want to evaluate the cost, here are some prices: https://azure.microsoft.com/en-us/pricing/details/azure-sql-managed-instance/single/

I will go with Sql Managed instances

When creating , the admin password must be 16 characters long , contain numbers and non-alphanumeric characters, and must be different from the user password.

And the message is

“Deploying Managed Instance is a long running operation taking up to 6 hours to complete.”

So back to square 1 and create a Sql database.

Now must understand pricing – here is the link: https://docs.microsoft.com/ro-ro/azure/azure-sql/database/purchasing-models

This was fast – now I can access the database and create tables.

Tools used:

portal.azure.com

FileExtension–part 6 – CI/CD

So now how to make visible all those coding ?

For tests –CodeCov,  https://app.codecov.io/gh/ignatandrei/FileExtension hosts for free to see the coverage

For documentation – ReadTheDocs,  https://fileextension.readthedocs.io/en/latest/ hosts for free.

For packaging  – NuGEt https://www.nuget.org/packages/FileExtension/

For more detailed analysis Sonar https://sonarcloud.io/summary/overall?id=ignatandrei_FileExtension can show code smells and bugs and more

GitHub actions https://github.com/ignatandrei/FileExtension/actions allows me to run all those automatically and gather results

For showing a website – Azure  – https://fileextension.azurewebsites.net/ can show the usage.

I was thinking that it is enough for the people to understand the application

Exchange rates–what I have done in 37 hours–part 38

What I have create for now in 37 hours :

  1. A source control – https://github.com/ignatandrei/InfoValutar
  2. A plugin based software – you can use to load any kind of exchange rates, for anywhere , provided that you implement the interface – see implementation
  3. Tests for some of the code
  4. Deployment:
  5. A SqlServer database – to store datas
  6. An Azure Function  – https://azurefuncloaddata20191205080713.azurewebsites.net/ –  to load data at time based cron intervals
  7. A GitHub action to compile ,run tests , – https://github.com/ignatandrei/InfoValutar/actions
  8. An AzureDevops CI + CD  to do all 1-6 things +code coverage + deploy https://dev.azure.com/ignatandrei0674/InfoValutar/_build?definitionId=5&_a=summary

 

I did say it is a nice work for 37 hours of work, right ?

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

Azure functions – final–part 37

So , I said, now just retrieve data – and put on database:

try
             {
                 log.Info(“trying to save”);
                 ISave save = new SaveSqlServer(null);
                 await save.Save(data.ToArray());
             }
             catch(Exception ex)
             {
                 log.Error($”ERROR !! {ex.Message}”);
             }

This gives me a new whole error:

ERROR !! Could not load type ‘System.IAsyncDisposable’ from assembly ‘netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’.

Ok. Coming from start: What I want ? To save recent data into the database and checking at regular times. How to do that ? Simple . Just call https://infovalutar.azurewebsites.net/api/v1.0/save/LoadAndSaveAll

Good. So this should be the code:

log.Info($”LOAD from website: {DateTime.Now}”);
             Console.WriteLine(“————————!!”);
             var url = “https://infovalutar.azurewebsites.net/api/v1.0/save/LoadAndSaveAll”;
             var http = new HttpClient();
             var data = await http.GetStringAsync(url);
             log.Info($”obtaining data {data}”);

And … it works flawless! – For BNR – for ECB it shows just a record. That is somehow strange – the coding was almost the same

Now it is time to wrote some more tests  -and to find if ECB is loading more than 1 record. Yes, it is.

Then the problem is when saving? Or when loading ?

I have the result of saving :

public class ResultsLoadBankData
     {
         public string Bank { get; internal set; }
         public int NrRecords { get; internal set; }
         public bool HasSuccess { get; internal set; }
         public string ErrorMessage { get; internal set; }
     }

And I modified to this

public class ResultsLoadBankData
     {
         public string Bank { get; internal set; }
         public int NrRecordsLoaded { get; internal set; }
         public int NrRecordsSaved { get; internal set; }

        public bool HasSuccess { get; internal set; }
         public string ErrorMessage { get; internal set; }
     }

Also , there were many other small modifications when loading data.

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

Azure function–solving my own code problems–part 35

1. My fault – the plugins does not exists in output

this should be added to the output in order to the plugins to be copied to the output directory

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

2. Deploying  , I should see what it is convenient: context.FunctionDirectory  OR context.FunctionAppDirectory

log.LogInformation($”!!! C# Timer trigger function executed at: {DateTime.Now} next {myTimer.FormatNextOccurrences(1)} “);
var folder = Path.Combine(context.FunctionDirectory, “plugins”);
log.LogInformation($”!!! Folder {folder} Folder exists: {Directory.Exists(folder)}”);

folder = Path.Combine(context.FunctionAppDirectory, “plugins”);
log.LogInformation($”!!!Folder {folder} Folder exists: {Directory.Exists(folder)}”);

3. Plugins loading – missing dll’s

Because I work with Nate Mc Master Plugins  , https://github.com/natemcmaster/DotNetCorePlugins, I encounter the  error “ could not load file or assembly ‘System.Runtime.Loader, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

I was trying self-contained in building Azure  – does not publish the file ‘System.Runtime.Loader . But the InfoValutarLoadingLibs/InfoValutarLoadingLibs.csproj it does!

Solution : publish self contained loading libs, build azure function , copy files from loading libs to azure function project

4. Now encountering this one:

https://github.com/Azure/Azure-Functions/issues/1250

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 regularly–deploy plugins–Azure Function–part 34

Now I have broken the build. Why ?Because of the docker file – to be optimized on local, I copy ecah csproj one by one and the I do dotnet restore. (If docker had a glob patttern! ) . So each time that I put a new project, the build will fail!

Trying now from the Azure Function to load the plugins . Apparently, the deploying does not deploy also the plugins ( Application Insights , connected to the Azure function ,is your friend – it can show you all kind of messages)

But now I have a problem copying the plugins. I do in azure Function like I have done with the other projects;

A post-build event

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

and a file prebuild.ps1 file that says

echo “args 0 ”  $args[0]
echo “args 1 ” $args[1]
$a= Get-Location
echo $a
echo now copy
Copy-Item -Path $args[0] -Destination $args[1] -Recurse -Force

For all other projects it is working. For the azure function, it gives an error at the compiling time on CI ( not on local! )

/bin/sh: 3: /tmp/tmpdd44ee8bfe4f49dca815035fe3a451ee.exec.cmd: Syntax error: Unterminated quoted string

I found the problem

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

Now, a different error raises on Github CI when compiling the Azure Function:

The specified framework ‘Microsoft.NETCore.App’, version ‘2.1.0’ was not found.

The problem  is here: https://github.com/Azure/azure-functions-vs-build-sdk/blob/master/src/Microsoft.NET.Sdk.Functions.MSBuild/Targets/Microsoft.NET.Sdk.Functions.targets 

<_FunctionsTaskFramework Condition=” ‘$(MSBuildRuntimeType)’ == ‘Core'”>netcoreapp2.1</_FunctionsTaskFramework>

I try to build into an netcoreapp3.0 docker container. I must install 2.1, probably.

For github actions:

– name: Setup .NET Core 2.1
       uses: actions/setup-dotnet@v1
       with:
         dotnet-version: 2.1.802

    – name: Setup .NET Core 3.0
       uses: actions/setup-dotnet@v1
       with:
         dotnet-version: 3.0.100

Not working!

But a new idea – what if I have the project not up-to-date  ? And indeed , the nuget for azure functions was not update. Now it works for GitHub actions!https://github.com/ignatandrei/InfoValutar/actions

Now , back to work  – I want to deploy the plugins in the Azure Function

Reading about ExecutionContext – ok. Reading about difference between FunctionAppDirectory and  FunctionDirectory  –https://github.com/Azure/azure-functions-host/wiki/Retrieving-information-about-the-currently-running-function . Ok – I want FunctionDirectory – I think it is just for this function.

For uploading files and folder, there are 2 ideas:

  1. to have included in .csproj ( do not want the plugins to be included !)
  2. To include in the zip file https://docs.microsoft.com/en-us/azure/azure-functions/deployment-zip-push 

So CI / CD to the rescue. I will do in AzureDevOps – 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

Loading data at regular intervals–Azure function –part 33

I need to load data at scheduled intervals – it is normal that the exchange rates are published every day.

So what options we have in Azure?

  1. WebJobs
  2. Worker Roles
  3. Azure functions

After reading a lot, I decide on Azure Functions – it is the new kid on the block and battle tested. More, it has something called Durable , https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-overview?tabs=csharp that seems very promising

I create the function in the Azure Portal –  just account that creation is not milliseconds, but seconds. And be sure that you craete under the same resource group as the previous resources.

The I create the function project template in Visual Studio.  Trying to deploy from Visual Studio – after configuring , the endpoint on Azureshows error. Thinking  – guess the problem – I configured the endpoint with Linux – and on my PC I have Windows. Deleting and creating another one – with Windows Containers. And now an error:”Requested feature is not available in resource group infovalutarRG. Please try using a different resource group or create a new one”

No wonder why is a DevOps thing nowadays…

Going back to Visual Studio – figuring “ Publish” has an edit – and I can see there that I can select on what OS I can publish to. => error on deploy. Investigating the logs – not understanding the error ( not enough details)

Ok –  now I want to create the Azure Function from within Visual Studio. Let’s see. Now publishing works, the website show a nice interface ( your functions is up and running) . But , even if successfully deployed, does not show my function!

Trying to get the deployment profile from the Azure WebSite – says that it cannot find the function. However, it is just a time caching problem. Some seconds later it shows the function!

Moral : do not rush. Caching is a bitch nowadays.

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

Refactoring ,AzureConnectionString, rss, asmx–part 28

Now, I want to see that I can read from the database the exchange rates. For this, in Azure WebAPP I go to Settings => Configuration and add my connection string.

But now I have a problem: I must read from the configuration.  So back on DI with InMemory class – I inject from ASP.NET Core the Configuration and in the tests I construct directly with null.

IConfiguration configuration;

public InMemoryDB(IConfiguration config)
{
this.configuration = config;

}
private string GetConRead(string name)
{
return configuration?.GetConnectionString(name);
}

 

Also, for easy retrieving from URL , I modify from

public async Task<ExchangeRates[]> Rates(string bank,string fromDate, string toDate)

( that generates the url : https://infovalutar.azurewebsites.net/api/v1.0/FromDB/Rates?bank=bnr&fromDate=20010101&toDate=20500101 )

to

[HttpGet(“{bank}/{fromDate}/{toDate}”)]
public async Task<ExchangeRates[]> Rates([FromRoute] string bank, [FromRoute]string fromDate, [FromRoute]string toDate)

( that generates the URL: https://infovalutar.azurewebsites.net/api/v1.0/rates/bnr/20010101/20100101 )

 

( I have also modified the route on the controller to [Route(“api/v{version:apiVersion}/rates”)] )

The modifications are at https://github.com/ignatandrei/InfoValutar/commit/aeda74e071a333e800a36936d2d3fc685b4b3ac8 .

The bad part – the deploy takes now 7 minutes…( running tests first …)

I have to implement now the following (

www.infovalutar.ro/bnr/2004/10/10/EUR

www.infovalutar.ro/bnr/azi/eur

www.infovalutar.ro/2004/6/4/eur.bnr

http://www.infovalutar.ro/bnr/rss

http://infovalutar.ro/curs.asmx?wsdl

 

I will implement first into the rates API , then I will redirect.

For example, the first one is like this: www.infovalutar.ro/bnr/2004/10/10/EUR and www.infovalutar.ro/2004/6/4/eur.bnr can be implemented like this:

 

[HttpGet(“{year}/{month}/{day}/{exchange}.{bank}”)]
[HttpGet(“{bank}/{year}/{month}/{day}/{exchange}”)]
public async Task<ExchangeRates> RatesOnDate([FromRoute] string bank,
[FromRoute]int year, [FromRoute]int month,
[FromRoute] int day, [FromRoute] string exchange)

 

 

What about the rss ? There is a package called System.ServiceModel.Syndication in .NET Core  – and we can use for RSS like this:

[HttpGet(“{bank}/rss”)]
public async Task<IActionResult> GetRssFeed(string bank)
{
var data= await ret.TodayRates(bank);
var items = data
.Select(it =>
new SyndicationItem(
it.ExchangeTo,
it.ExchangeValue.ToString(),
new Uri($”http://www.infovalutar.ro/bnr/{it.Date.Year}/{it.Date.Month}/{it.Date.Day}/{it.ExchangeTo}”))
)
.ToArray();

var feed = new SyndicationFeed(
“Curs Valutar”,
“CursValutar, case, banci”,
new Uri( “http://www.infovalutar.ro/”),
items
);
feed.Language = “ro-ro”;
feed.TimeToLive = TimeSpan.FromSeconds(30);
using var sw = new StringWriter();
using var rssWriter = XmlWriter.Create(sw);

var rssFormatter = new Rss20FeedFormatter(feed,false);
rssFormatter.WriteTo(rssWriter);
rssWriter.Close();
return Content(sw.ToString(), “text/xml”);
}

 

What about http://infovalutar.ro/curs.asmx?wsdl ? Found https://devblogs.microsoft.com/dotnet/custom-asp-net-core-middleware-example/ article , that says”it has no support for message security, WSDL generation, duplex channels, non-HTTP transports” – so I do not want to do. Maybe something should be left…

So , now , how I can now intercept calls like

www.infovalutar.ro/bnr/2004/10/10/EUR

www.infovalutar.ro/bnr/azi/eur

www.infovalutar.ro/2004/6/4/eur.bnr

http://www.infovalutar.ro/bnr/rss

? There is no controller ! So – middleware to help!

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.