Category: .NET Core

.NET Core And Angular at CodeCamp Bucuresti

I have presented on Saturday at https://bucuresti.codecamp.ro/ a technical talk about how to make a fast POC that can run on Web, Desktop and Mobile , The presentation will show a clear example of code that is necessary for that ( code at https://github.com/ignatandrei/angNetCoreDemo/  ).

You can see working demo without CORS at https://ang-net-core.herokuapp.com/ , with CORS at https://ignatandrei.github.io/AngNetCoreDemo/ and a Mobile app at https://app.bitrise.io/artifact/9332781/p/ef7a0b7e945d69e01697390dcef867de

It was a good opportunity to learn something new at the conference – many good technical tracks and old friends that is an opportunity to see again.

Latest commits notes from github

For AOP with Roslyn I want to automatically get the latest commits message before doing a new commit.

This was  solved easily using https://github.com/octokit/octokit.net 

The code is  very simple:

public async Task<DateForCommit[]> BetweenLatest2Commits()
{
           
var client = new GitHubClient(new ProductHeaderValue("GitBetweenCommits"));
var rep = await client.Repository.Get(Author, RepositoryName);
var relLatest = await client.Repository.Release.GetLatest(rep.Id);
var relAll = await client.Repository.Release.GetAll(rep.Id, new ApiOptions() { PageSize = int.MaxValue - 1 });
var relBeforeLatest = relAll.OrderByDescending(it => it.CreatedAt).Skip(1).FirstOrDefault();

var dateLatest = relLatest.CreatedAt;
var dateBeforeLatest = relBeforeLatest.CreatedAt;

var commits = await client.Repository.Commit.GetAll(rep.Id, ApiOptions.None);
var res = commits
    .Where(it => 
    it.Commit.Author.Date >= dateBeforeLatest
    &&
    it.Commit.Author.Date<=dateLatest
    )
    .Select(it => new DateForCommit()
    {
        Author = it.Commit.Author.Name,
        Message = it.Commit.Message,
        CommitDate = it.Commit.Author.Date.DateTime
    })
    .ToArray();
return res;
}

It works also as a .NET Global tool
Install with

dotnet tool install –global dotnet-gcr

run with

dotnet gcr

for example for https://github.com/ignatandrei/AOP_With_Roslyn the arguments are

dotnet gcr ignatandrei AOP_With_Roslyn

NuGet at https://www.nuget.org/packages/dotnet-gcr/

Full Code at https://github.com/ignatandrei/GitCommitsBetweenReleases
enjoy

Circular references on .NET , Entity Framework and WebAPI

Imagine having a class Department( ID, Name) and Employee ( ID , Name, IDDepartment) . You want to return in the WebAPI the Departments with the Employee . It is simple to wrote this code:


[HttpGet]
public IEnumerable<Department> Get([FromServices] MyTestDatabaseContext context)
{
var departments = context.Department.Include(iterator=>iterator.Employee).ToArray();
return departments;
}

But the problem is with circular references when serializing  : The Department has a list of  Employees  that have a Department that have a list of Employees that …

 

 

Solution 1 :  Delete/Comment from the EF generated code what you do not need ( in this case , the Department reference that the Employee has)


public partial class Employee
{
public int Idemployee { get; set; }
public string NameEmployee { get; set; }
public int Iddepartment { get; set; }

//public Department IddepartmentNavigation { get; set; }
}

Solution 2 : Nullify the reference


[HttpGet]
public IEnumerable<Department> Get([FromServices] MyTestDatabaseContext context)
{
var departments = context.Department.Include(iterator=>iterator.Employee).ToArray();
foreach (var dep in departments)
{
foreach (var emp in dep.Employee)
{
emp.IddepartmentNavigation = null;
}
}
return departments;
}

( maybe this should be add to the partial class of the employee ?)

 

 

Solution 3: Handle circular references in serialization


services
.AddMvc()
.AddJsonOptions(opt =>
{
opt.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
opt.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
});

Solution 4: Make a read DDD design. Read https://siderite.blogspot.com/2018/08/client-models-vs-data-transfer-objects.html

Interpreter–part 7 of n–thank you

In our days you cannot build a project without help from other projects.  So it is your project – it is build on the shoulder of others( https://en.wikipedia.org/wiki/Standing_on_the_shoulders_of_giants )

Add a third party notice and thanks others that contributes with components to your project.

I have discovered https://github.com/KrystianKolad/DotnetThx  – and running it gives me that :

—————————————————————
Package:InterpreterDll
Page:https://github.com/ignatandrei/interpreter
Andrei Ignat
—————————————————————
—————————————————————
Package:McMaster.Extensions.CommandLineUtils
Page:https://github.com/natemcmaster/CommandLineUtils
Nate McMaster
—————————————————————
—————————————————————
Package:McMaster.Extensions.CommandLineUtils-max
Page:https://github.com/natemcmaster/CommandLineUtils-max
Nate McMaster
—————————————————————
—————————————————————
Package:McMaster.Extensions.CommandLineUtils-max2
Page:https://github.com/natemcmaster/CommandLineUtils-max2
Nate McMaster
—————————————————————
—————————————————————
Package:CommandLine.Core.CommandLineUtils
Page:https://github.com/mthamil/CommandLine.Core
Matt Hamilton
—————————————————————
—————————————————————
Package:CommandLineUtils.Extensions
Page:https://github.com/mthamil/CommandLine.Core
Matt Hamilton
—————————————————————
—————————————————————
Package:FormatWith
Page:https://github.com/crozone/FormatWith
Ryan Crosby
—————————————————————
—————————————————————
Package:netfx-System.StringFormatWith
Page:http://netfx.codeplex.com/
Henri Wiechers,  Daniel Cazzulino,  kzu,  Clarius
—————————————————————
—————————————————————
Package:netfx-System.StringFormatWith.Tests
Page:http://netfx.codeplex.com/
Henri Wiechers,  Daniel Cazzulino,  kzu,  Clarius
—————————————————————
—————————————————————
Package:DocumentFormat.OpenXml
Page:https://github.com/OfficeDev/Open-XML-SDK
Microsoft
—————————————————————
—————————————————————
Package:ZXing.Net
Page:https://github.com/micjahn/ZXing.Net/
Michael Jahn
—————————————————————
—————————————————————
Package:Google.Protobuf
Page:https://github.com/google/protobuf
Google Inc.
—————————————————————
—————————————————————
Package:ExcelNumberFormat
Page:https://github.com/andersnm/ExcelNumberFormat
ExcelNumberFormat developers
—————————————————————
—————————————————————
Package:NUnit.Runners
Page:http://nunit.org/
Charlie Poole
—————————————————————
—————————————————————
Package:WebP.Touch
Page:https://github.com/molinch/WebP.Touch
Daniel Luberda, Molinet Fabien, Cosmin Gordea
—————————————————————
—————————————————————
Package:BclContrib-ParseFormat
Page:http://code.google.com/p/bclcontrib-parseformat/
Sky Morey
—————————————————————
—————————————————————
Package:SmartFormat.NET
Page:https://github.com/scottrippey/SmartFormat.NET
Scott Rippey,axuno gGmbH,Bernhard Millauer and other contributors.
—————————————————————
—————————————————————
Package:SFD.StringFormat
Page:
AdamSpeight2008
—————————————————————
—————————————————————
Package:ActionMessageFormat
Page:https://github.com/mntone/Data.Amf
mntone and qwerty
—————————————————————
—————————————————————
Package:FileFormatWavefront
Page:https://github.com/dwmkerr/file-format-wavefront
Dave Kerr
—————————————————————
—————————————————————
Package:String.Format.Js
Page:http://mstr.se/sffjs
Daniel Mester Pirttijärvi
—————————————————————
—————————————————————
Package:ActionMessageFormat.UWP
Page:https://github.com/tor4kichi/Data.Amf
tor4kichi
—————————————————————
—————————————————————
Package:jQuery.dateFormat
Page:https://github.com/phstc/jquery-dateFormat
Pablo Cantero
—————————————————————
—————————————————————
Package:TMU-BioTextMining.i2b2.Format
Page:https://sites.google.com/site/hongjiedai/projects/tmuclinicalnet
Hong-Jie Dai
—————————————————————
—————————————————————
Package:Estat.Sri.Ws.Format.Sdmx
Page:https://webgate.ec.europa.eu/CITnet/stash/projects/SDMXRI/repos/nsiws.net/browse
Eurostat
—————————————————————
—————————————————————
Package:FormatProviders
Page:
AdamSpeight2008
—————————————————————
—————————————————————
Package:Microsoft.CodeAnalysis.CSharp
Page:https://github.com/dotnet/roslyn
Microsoft
—————————————————————
—————————————————————
Package:Microsoft.CodeAnalysis.CSharp.Workspaces
Page:https://github.com/dotnet/roslyn
Microsoft
—————————————————————
—————————————————————
Package:Microsoft.CodeAnalysis.CSharp.Scripting
Page:https://github.com/dotnet/roslyn
Microsoft
—————————————————————
—————————————————————
Package:Microsoft.CodeAnalysis.CSharp.Features
Page:https://github.com/dotnet/roslyn
Microsoft
—————————————————————
—————————————————————
Package:Microsoft.CodeAnalysis.CSharp.Extensions
Page:https://github.com/denis-tsv/Microsoft.CodeAnalysis.CSharp.Extensions
Denis Tsvettsih
—————————————————————
—————————————————————
Package:Sawmill.Microsoft.CodeAnalysis.CSharp
Page:https://github.com/benjamin-hodgson/Sawmill
benjamin.hodgson
—————————————————————
—————————————————————
Package:Forked-MS.CodeAnalysis.CSharp-KeywordAlias
Page:https://github.com/rickardp/roslyn
Rickard
—————————————————————
—————————————————————
Package:Roslynator.CodeFixes
Page:http://github.com/JosefPihrt/Roslynator
Josef Pihrt
—————————————————————
—————————————————————
Package:Roslynator.Analyzers
Page:http://github.com/JosefPihrt/Roslynator
Josef Pihrt
—————————————————————
—————————————————————
Package:Ben.Demystifier-RoslynScriptingCompatibility
Page:https://github.com/molinch/Ben.Demystifier-RoslynScriptingCompatibility
ben_a_adams molinch
—————————————————————
—————————————————————
Package:Microsoft.CodeAnalysis.Compilers
Page:https://github.com/dotnet/roslyn
Microsoft
—————————————————————
—————————————————————
Package:Microsoft.CodeAnalysis
Page:https://github.com/dotnet/roslyn
Microsoft
—————————————————————
—————————————————————
Package:Microsoft.CodeAnalysis.Workspaces.MSBuild
Page:https://github.com/dotnet/roslyn
Microsoft
—————————————————————
—————————————————————
Package:Microsoft.CodeAnalysis.CSharp.Scripting
Page:https://github.com/dotnet/roslyn
Microsoft
—————————————————————
—————————————————————
Package:Ben.Demystifier-RoslynScriptingCompatibility
Page:https://github.com/molinch/Ben.Demystifier-RoslynScriptingCompatibility
ben_a_adams molinch
—————————————————————
—————————————————————
Package:Newtonsoft.Json
Page:https://www.newtonsoft.com/json
James Newton-King
—————————————————————
—————————————————————
Package:Amplified.ValueObjects.Newtonsoft.Json
Page:https://github.com/Nillerr/Amplified.ValueObjects
Nicklas Jensen
—————————————————————
—————————————————————
Package:CommonSerializer.Newtonsoft.Json
Page:https://github.com/BrannonKing/CommonSerializer
Brannon King
—————————————————————
—————————————————————
Package:Remote.Linq.Newtonsoft.Json
Page:https://github.com/6bee/Remote.Linq
Christof Senn
—————————————————————
—————————————————————
Package:aqua-core-newtonsoft-json
Page:https://github.com/6bee/aqua-core
Christof Senn
—————————————————————
—————————————————————
Package:RestSharp.Newtonsoft.Json.NetCore
Page:https://github.com/Alterdata/RestSharp.Newtonsoft.Json.NetCore
Bernardo Esbérard
—————————————————————
—————————————————————
Package:Newtonsoft.Json.FSharp
Page:
Henrik Feldt,  Logibit AB
—————————————————————
—————————————————————
Package:Orleans.Serialization.Newtonsoft.Json
Page:https://github.com/OrleansContrib/orleans.serialization.json
Daniel Marbach
—————————————————————
—————————————————————
Package:Newtonsoft.Json.Net20.dll
Page:
wx1983@gmail.com
—————————————————————
—————————————————————
Package:Sfa.Core.Newtonsoft.Json
Page:https://github.com/SkillsFundingAgency/Core
Skills Funding Agency
—————————————————————
—————————————————————
Package:NServiceBus.Newtonsoft.Json
Page:https://docs.particular.net/nuget/NServiceBus.Newtonsoft.Json
Particular Software
—————————————————————
—————————————————————
Package:RestSharp.Newtonsoft.Json
Page:https://github.com/adamfisher/RestSharp.Serializers.Newtonsoft.Json
Adam Fisher
—————————————————————
—————————————————————
Package:Bridge.Newtonsoft.Json
Page:https://github.com/bridgedotnet/Bridge.Newtonsoft.Json
Object.NET, Inc.
—————————————————————
—————————————————————
Package:Gu.SerializationAsserts.Newtonsoft.Json
Page:https://github.com/JohanLarsson/Gu.SerializationAsserts
Johan Larsson
—————————————————————
—————————————————————
Package:RestSharp.Newtonsoft.Json.Extensions
Page:https://github.com/i4004/RestSharp.Newtonsoft.Json.Extensions
Alexander Krylkov
—————————————————————
—————————————————————
Package:Mgazza.Newtonsoft.Json
Page:https://github.com/mgazza/Optional
Mark Gascoyne
—————————————————————
—————————————————————
Package:Newtonsoft.Json.Akshay
Page:
Akshay.Shingnapurkar, Yuvraj.Repe
—————————————————————
—————————————————————
Package:WampSharp.NewtonsoftJson
Page:https://wampsharp.net/
CodeSharp
—————————————————————
—————————————————————
Package:Pollock.Newtonsoft.Json
Page:
wallymathieu
—————————————————————
—————————————————————
Package:Lykke.WampSharp.NewtonsoftJson
Page:https://github.com/LykkeCity/WampSharp
Lykke
—————————————————————
—————————————————————
Package:coverlet.msbuild
Page:http://github.com/tonerdo/coverlet
tonerdo
—————————————————————
—————————————————————
Package:Microsoft.CodeAnalysis.CSharp.Scripting
Page:https://github.com/dotnet/roslyn
Microsoft
—————————————————————
—————————————————————
Package:Ben.Demystifier-RoslynScriptingCompatibility
Page:https://github.com/molinch/Ben.Demystifier-RoslynScriptingCompatibility
ben_a_adams molinch
—————————————————————
—————————————————————
Package:Microsoft.NET.Test.Sdk
Page:https://github.com/microsoft/vstest/
Microsoft
—————————————————————
—————————————————————
Package:MSTest.TestAdapter
Page:https://github.com/microsoft/testfx
Microsoft
—————————————————————
—————————————————————
Package:MSTestX.TestAdapter
Page:https://github.com/dotMorten/MSTestX
Morten Nielsen
—————————————————————
—————————————————————
Package:MSTest.TestFramework
Page:https://github.com/microsoft/testfx
Microsoft
—————————————————————
—————————————————————
Package:MSTest.TestFramework
Page:https://github.com/microsoft/testfx
Microsoft
—————————————————————
—————————————————————
Package:MSTest.TestAdapter
Page:https://github.com/microsoft/testfx
Microsoft
—————————————————————
—————————————————————
Package:Microsoft.UnitTestFramework.Extensions
Page:https://github.com/Microsoft/mstest-extensions/wiki
Microsoft
—————————————————————
—————————————————————
Package:Nosnitor.TestFramework.Extensions.MSTest
Page:
Nosnitor Corporation
—————————————————————
—————————————————————
Package:Riganti.Selenium.MSTest2Integration
Page:https://github.com/riganti/selenium-utils
Ladislav Šesták
—————————————————————
—————————————————————
Package:LightBDD.MsTest2
Page:https://github.com/LightBDD/LightBDD
Wojciech Kotlarski
—————————————————————
—————————————————————
Package:Shouldly
Page:http://shouldly.github.com/
Shouldly
—————————————————————
—————————————————————
Package:Sollertes.Bdd.Shouldly
Page:https://github.com/Sollertes/BDD
Marcin Markowski
—————————————————————
—————————————————————
Package:ITLibrium.BDD.Shouldly
Page:https://github.com/itlibrium/BDD
Marcin Markowski
—————————————————————
—————————————————————
Package:Mgazza.Shouldly
Page:https://github.com/mgazza/Optional
Mark Gascoyne
—————————————————————
—————————————————————
Package:Shouldly.EqualityExtensions
Page:https://github.com/whortleberrybearer/shouldly
whortleberrybearer
—————————————————————
—————————————————————
Package:NorwegianShouldly
Page:https://github.com/eaardal/norwegian-shouldly
This language wrapper: Eirik Årdal. Original Shouldly: See Shouldly NuGet package

A whole bunch of packages – that it is clear that helps my project.

Interpreter–part 4 of n – Deploy

Series:

  1. http://msprogrammer.serviciipeweb.ro/2018/07/16/interpreterpart-1-of-n/ – Idea
  2. http://msprogrammer.serviciipeweb.ro/2018/07/23/interpreterpart-2-of-n/ – Coding
  3. http://msprogrammer.serviciipeweb.ro/2018/07/30/interpreterpart-3-of-n/ – Testing
  4. http://msprogrammer.serviciipeweb.ro/2018/08/06/interpreterpart-4-of-n/  – Deploy
  5. http://msprogrammer.serviciipeweb.ro/2018/08/13/interpreterpart-5-of-n/ – Documentation
  6. http://msprogrammer.serviciipeweb.ro/2018/08/20/interpreterpart-6-of-n/ – Ecosystem / usage

 

 

After done the testing part, we can deploy the Interpreter . That means uploading to some package sources, as Nuget.org or myget.org. I choose Nuget.org .

For this, first we should package the applicatiuon. We right click the project, select properties, and then package tab.

Enter the details ,. save , then right click the project again and click “Publish” and fisnish.

In the folder “bin\Debug\netcoreapp2.1\publish” you will find the InterpreterDll.1.0.0.nupkg file. This file you will upload to nuget.org. For this, you have to login to nuget.rog and go to https://www.nuget.org/account/Packages

After submitting , you will find the package at https://www.nuget.org/packages/InterpreterDll/ .

From this, you can testit by downloading directly  from nuget feed .

First deploy was simple  – but we want to do this with a button click.

 

But we want more – every time a new code is pushed to github  -the tests should run automatically and a new interpreter package will be created. For this we can choose VisualStudio.com site , integrate with our github repository and create a build release.

I am going to https://ignatandrei.visualstudio.com/ and create a new project.  For this , I will integrate with GitHub and push a new build. Also,  in this definition of build have a publish task that allows to publish as an artifacty the .nupkg that next we will put on github / nuget

Interpreter–part 3 of n -Testing

Series:

  1. http://msprogrammer.serviciipeweb.ro/2018/07/16/interpreterpart-1-of-n/ – Idea
  2. http://msprogrammer.serviciipeweb.ro/2018/07/23/interpreterpart-2-of-n/ – Coding
  3. http://msprogrammer.serviciipeweb.ro/2018/07/30/interpreterpart-3-of-n/ – Testing
  4. http://msprogrammer.serviciipeweb.ro/2018/08/06/interpreterpart-4-of-n/  – Deploy
  5. http://msprogrammer.serviciipeweb.ro/2018/08/13/interpreterpart-5-of-n/ – Documentation
  6. http://msprogrammer.serviciipeweb.ro/2018/08/20/interpreterpart-6-of-n/ – Ecosystem / usage

 

 

Now that we do not have just the interpreter part 1 idea, but also interpreter part 2 coding , we can test the application.

For this we should write test for everything that we wrote in the interpreter part 1  idea  .

That gives us a bunch of tests functions:

void InterpretDateTime();
void InterpretDateTimeUtcNow();
void InterpretEnv();
void InterpretGuid();
void InterpretSettingsFile();
void InterpretStaticOneParameter();
void InterpretStaticParameterString();
void InterpretStaticTwoParameterString();

 

We run those test with VS or

dotnet test

and we think that is ok.

Nope. We should , to be sure,to have the code coverage – means that we verify what we have tested . You can start from here : https://dotnetthoughts.net/code-coverage-in-netcore-with-coverlet/

The first iteration for my project gives to me

Assemblies: 1
Classes: 2
Files: 2
Covered lines: 196
Uncovered lines: 17
Coverable lines: 213
Total lines: 313
Line coverage: 92%
Branch coverage: 84.60%

That it is pretty solid.

Interpreter–part 2 of n – Coding

Series:

  1. http://msprogrammer.serviciipeweb.ro/2018/07/16/interpreterpart-1-of-n/ – Idea
  2. http://msprogrammer.serviciipeweb.ro/2018/07/23/interpreterpart-2-of-n/ – Coding
  3. http://msprogrammer.serviciipeweb.ro/2018/07/30/interpreterpart-3-of-n/ – Testing
  4. http://msprogrammer.serviciipeweb.ro/2018/08/06/interpreterpart-4-of-n/  – Deploy
  5. http://msprogrammer.serviciipeweb.ro/2018/08/13/interpreterpart-5-of-n/ – Documentation
  6. http://msprogrammer.serviciipeweb.ro/2018/08/20/interpreterpart-6-of-n/ – Ecosystem / usage

 

 

Now that we have the idea from interpreter part 1 of what we want to do, start coding thinking about what the code will look like.

We want simple use, like

string textToInterpret = "Export#now:yyyyMMddHHmmss#.csv";
var i = new Interpret();
var nameFile = i.InterpretText(textToInterpret);

So we will have just a function, InterpretText , that will have as a parameter a string and returns the interpreted string.

Now we can start the coding part   .This  is somewhat harder – we make separate functions to interpret environment variables, interpret datetime, guid, interpret file json, and interpret with static functions

For this we will create separate functions , that know how to deal with those cases ( The edge case is loading assemblies – you do not want this time consuming to be done every time you interpret – or to load if it is not necessary)

After this  , in order to have a source control, you upload the code on GitHub : https://github.com/ignatandrei/Interpreter

 

Interpreter–part 1 of n – Idea

Series:

  1. http://msprogrammer.serviciipeweb.ro/2018/07/16/interpreterpart-1-of-n/ – Idea
  2. http://msprogrammer.serviciipeweb.ro/2018/07/23/interpreterpart-2-of-n/ – Coding
  3. http://msprogrammer.serviciipeweb.ro/2018/07/30/interpreterpart-3-of-n/ – Testing
  4. http://msprogrammer.serviciipeweb.ro/2018/08/06/interpreterpart-4-of-n/  – Deploy
  5. http://msprogrammer.serviciipeweb.ro/2018/08/13/interpreterpart-5-of-n/ – Documentation
  6. http://msprogrammer.serviciipeweb.ro/2018/08/20/interpreterpart-6-of-n/ – Ecosystem / usage

 

 

For Stankins I need a custom interpreter of serialized data. What this means, exactly ?

Let’ suppose I have an appsetting file with a connection string

{
“SqlServerConnectionString”: “Server=(local)\\SQL2016;Database=tempdb;Trusted_Connection=True;”
}

If I use directly this connection from code, fine( Please be sure that you read carefully https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.1&tabs=basicconfiguration ).

The idea is to have some settings that is generating all time from data. Let’s suppose you have to write a .csv file with some data.You want to be unique every time . The common idea is to hardcode the file with the date time :

string file = “SendTo”+ DateTime.Now.ToString(“yyyyMMdd”) + “.csv”

What if the the name of the file should be serialized  ?  You retrieve from config the first part ( “SendTo”) , append the datetime format and the .csv. Later, you figure a better idea – to have a GUID. You will modify the code again and wrote

string file = “SendTo”+ Guid.NewGuid().ToString(“N”) + “.csv”

What if you will have something like storing the fle name in a appSettings.json like

{

“fileName”:”file:SendTo#now:yyyyMMdd#.csv”

}

retrieve with configuration

var builder = new ConfigurationBuilder()
.AddJsonFile(filePath);
var config = builder.Build();

var fileName = config[“fileName”]

and then interpret:

var i = new Interpret();
var str = i.InterpretText(fileName );

 

This will give you in the str the string SendTo20180710.csv.

Next time, when you want Guid, you just modify the appSettings.json

{

“fileName”:”SendTo#guid:N#”.csv”

}

The code remains the same for interpret:

var i = new Interpret();
var str = i.InterpretText(fileName );

 

but the result will be different ,with the guid into the filename

What I intend to support:

-file: appSettings.json

-env: environment

-static: static functions with one variable

-guid: Guid.NewGuid

-now : datetime

But the idea is that I have a class that serializes itself as follow:

{

“ConnectionString”:”#file:SqlServerConnectionString#”,

“FileName”: “SendTo#now:yyyyMMdd#.csv”,

“DriveRoot”:”@static:Path.GetPathRoot(#static:Directory.GetCurrentDirectory()#)@”

“NameSln”:”@static:System.IO.Path.GetFileNameWithoutExtension(#env:solutionPath#)@”,

“newFileName”:”#guid:N#.csv”

}

The first item will be interpreted as ConnectionString : “Server=(local)\\SQL2016;Database=tempdb;Trusted_Connection=True;”

The second item will be interpreted as FileName: “SendTo20180710.csv”

The third item will call the static functions( Directory.GetCurrentDirectory() , Path.GetPathRoot)   from C# and return the result

The fourth item will call Environment variable solutionPath  and give back as an argument to the static function System.IO.Path.GetFileNameWithoutExtension

The fifth will call Guid.NewGuid().ToString(“N”)

All in all, it is another redirection and interpreting of data.

 

Angular , CORS and .NET Core SignalR

I have written a .NET Core  SignalR + Agular Observable of continously delivering the data. (http://msprogrammer.serviciipeweb.ro/2018/06/25/net-core-signalr-hub-angular-observable/ )

The setup is that .NET WebAPI resides in Visual Studio Project ( .sln. .csproj) and Angular Project is separate in another folder.

There are some settings in the development to be done in order to work

  1. Setting CORS in .NET Core  ( not really necessary- see below)
  2. Usually you will not need to set CORS in .NET Core if you plan to deliver Angular and .NET Core in the same site.

    But anyway, to allow anyoneto call you API , you will do something like this :

    services.AddCors();
    services.AddMvc();
    //...
     app.UseCors(it =>it.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
    //if (env.IsDevelopment())
    //{
    //    app.UseDeveloperExceptionPage();
    //}
    
    

    Of course, you can set for a domain, a header , and so on

    Also , do not forget to handle CORS errors – either by commenting the developer exception page, either by using a custom middleware, like https://blog.jonathaneckman.io/handling-net-core-web-api-exceptions-with-an-aurelia-fetch-interceptor/

  3. Setting  CORS like it does not exists for Angular
  4. For this:

    In the Angular environment.ts put those:

    export const environment = {

    production: false, //put also in the prod

    urlAPI:’/’

    }

    • In production: deliver AOT Angular compiled in the same folder with the .NET
    • This will ensure that , when you send the Angular AOT build with .NET Core WebAPI in the same site, it will work. NO CORS involved 😉

    • In development: This mean Angular ng server intercepting  calls

    Then create a file named proxy.conf.js and put this to redirect:

    const PROXY_CONFIG = [
        {
          context: [
              "/employees",
              "/api",                
          ],
          target: "http://&lt;url to the .NET Core API&gt;/",
          secure: false,
          "changeOrigin": true,
          "logLevel": "debug",
          ws: true
        }
    ]
    module.exports = PROXY_CONFIG;
    
    

    Then run:

    ng serve –proxy-config proxy.conf.js –open

  • Setting SignalR for Angular in development
  • See ws: true in previous proxy.conf.js ? That is all, if you run

    ng serve –proxy-config proxy.conf.js –open

    From unstructured data to application

    Imagine that you have this kind of texts:

    Alpert of Metz – 11th-century – France – Medieval writers
    Aimoin of Fleury – c. 960 – c. 1010 – France – Medieval writers
    Amulo Lugdunensis (Archbishop of Lyon) – 9th-century – France – Medieval writers
    Amulo Lugdunensis (Archbishop of Lyon) – 9th-century – France / Carolingian Empire – Medieval writers
    Andrew of Fleury – 11th-century – France – Medieval writers
    Angelomus of Luxeuil – 9th-century – Francia / France – Medieval writers

    Vitsentzos or Vikentios Kornaros or Vincenzo Cornaro – c. 1553 – c. 1614 – Kingdom of Candia / Crete / Greece – Renaissance

    Adrianus of Tyre – c. 113 – c. 193 – Greece / Roman Empire – Ancient & Classical writers

    How transform this unstrcutured data to make an application that search like in the picture below ( just the R from CRUD )?

    Detailing  the tools:

    1.  Transforming data: Excel + VBA – to parse from the text the name, country / countries , years period  movement and generate insert  /stored procedurees call

    2. Storing+ retrieving data: Sql Server – creating tables and stored procedures to insert / retrieving data

    3. Acessing data: .NET Core – to make WebAPI to export as WebAPI HTTP endpoints t

    4. Display data:

    5. Deploy:

    • RedfHat OpenShift to deploy site
    • Azure to have sql server on the web

    Hours or work ~ 20 . And hey, it works!