Multi level Library

Fix could not determine type exception in N-Hibernate

nHibernate is something I used for 1 project over 5 years ago when I wanted to pull geospatial data from a PostgreSql database. It was straight forward to use and wasn’t as bound to a database as Entity Framework (EF) was at the time, and its performance was great.

Since then I have been using EF for Object Relational Mapping (ORM) tasks and have largely forgotten how to use nHibernate.

Recently I have moved to a outfit that use nHibernate, so I decided to refresh my understanding by adding nhibernate into a project I am working on at home.

I had a repository class that I had quickly set up using SQLCommand to query a test database, which I replaced with NHibernate mapping. The simple classes, where I queried one table worked fine and were easy to setup, however when I tried to set up a more complex example with 2 tables linked by a foreign key and a many-to-one relationship I came across an error in my unit testing.

Continue reading →

Polly: The fallback position

Parrot flying with Eagles

How many times in an application dependent on some external resource do you have to write a function or a maybe a whole module to deal with fallback cases? Perhaps the web service you call is down and you fallback to data cached from the last call, or a ftp site is not available so you send the third-party an automatic email to notify them. As developers we are constantly coding fallbacks.

Last week I gave a brief introduction to Polly a fault handling library built for .Net Standard and .Net Core. We looked at the wait and retry functionality that the library has, which would be useful if the external resource is having a blip, but what about if it is down, how do we gracefully degrade?

Continue reading →

Polly Introductions

Parrot flying with Eagles

Photo by Alexandre Debiève on Unsplash

Having seen mention of Polly on Scott Hanselmann’s blog and heard Dylan Reisenberger enthusiastically talk about it on  .Net Rocks, I was keen to have a look at this library and see what it can do.

Any type of integration relies on an IO operation that often out of control of the developer, we use web services that can go down, open and read files from remote servers that can be suddenly inaccessible, rely on database connections that can drop. Adding code to deal with this has always been essential to any integration module.

As an example I have created small console application that opens and reads an excel file, that is already open causing an IOException. I will add the Polly library to this and set up a policy to retry the operation while prompting the user to close the file.

Continue reading →

Upload files to FTP using the WINSCP .Net library


Applications like Filezilla and WinSCP are great simple to use FTP/SFTP clients. However what about if you want to automate uploading files. Imagine you have a brilliant SSIS package, that extracts, manipulates and formats just the right data into the correct format, using SQL Server agent to run  your package early in the morning to take advantage of the gap in transactions hitting the database server. You want these extracted data files to be sent to a third party without you needing to log in open WINSCP  or Filezilla and manually upload them.

That is what we are going to look at today, a few simple methods for zipping some files and uploading them in an application that can then be set to run on a schedule with something like Windows Task Scheduler.

Continue reading →

AX Integration: Royal Mail Shipping API Part 5 – Security

RoyalMail               Dyn-AX12_v_rgb

We are building an integration between the Royal Mail SOAP Shipping API and Microsoft Dynamics AX 2012 R2. In parts 1-3 we have built a C# component to add some helper methods for interacting with the Royal Mail client proxy. In part 4 we called this client proxy in X++ and used our helper methods to extend the headers we send with the request message.

Now that we have the service client, we need to add WS Security headers to the request message to pass the Royal Mail authentication.

Continue reading →

AX Integration: Royal Mail Shipping API Part 4

RoyalMail               Dyn-AX12_v_rgb

We are building an integration between the Royal Mail SOAP Shipping API and Microsoft Dynamics AX 2012 R2. In parts 1 , 2 and 3 we have built using Windows Communication Foundation (WCF) some components to handle SOAP elements we need to add to the request message and security headers.

In this part we are going to create a proxy client in X++ and call some of the code we have previously written. We are going to take advantage of X++ ability to use .Net assemblies, including the code we have previously created and deployed to the AOT.

Note: I am going to show the declaration of variables alongside the assignation, getting and setting of the objects, for ease of explanation. However in X++ all variables are declared at the top of the method. The summary of the method at the end of the article will show the proper structure.

Continue reading →