Friday, September 21, 2018

Setting up a Dockerfile to publish a .net or .netcore application in a Windows container

Docker has been gaining significant traction lately, most of it can be credited to it's ability to create portable lightweight containers very quickly for continuous deployments and sprawling testing and staging environments. These environments would require a Dockerfile to carry a set of steps and instructions that would be needed to successfully restore, build and publish a .net or .netcore application.

Let's begin right away with the 1st step; selecting a build SDK image. For .net applications it would be microsoft/dotnet-framework:4.7.1-sdk and for .netcore applications we'll use microsoft/dotnet:2.1-sdk. Both of these are Windows images. The following would be the first step of our Dockerfile:

# Build SDK image
FROM microsoft/dotnet-framework:4.7.1-sdk AS build-env   # .net

FROM microsoft/dotnet:2.1-sdk AS build-env               # .netcore

Sunday, September 2, 2018

Notifications - using Firebase Realtime database

Building successful applications for the web or mobile devices come with few key must haves. One of these must haves is a feature we all love to rely on - notifications. This feature varies in how it can be implemented in an application, and comes with a wide array of possibilities. There was a time when the only way to find out if we have a new email was to log in to the email service form the browser and check for any new mail. Then came desktop clients that would show a dialog on the side of the screen when a new mail arrived. Slowly we started receiving notifications for other products through emails. Over time notifications could be received through SMS, a secondary option to notifications through email. Now all notifications can be received as push notifications on our mobile devices and smartwatches.

As of now, notifications can be received through emails, pushed on to our handheld devices, or  are shown to us when we log in to the application. There are many ways to implement notifications in an application but at the moment we will be talking about how to use capabilities of Firebase Realtime database to our advantage.

Sunday, June 10, 2018

Using System.Drawing to create an image thumbnail cropped at 1:1

Creating a thumbnail for an image is very easy if you are developing for .Net Framework or .Net Core, since both platforms offer the System.Drawing packages. The tricky solution is cropping the image in perfect square format without distorting or stretching the image.

The following code shows how to exactly do a center crop while generating a thumbnail, the original image needs to be scaled down to match size of the thumbnail while maintaining the aspect ratio first, then moved to an offset calculated previously such that the final drawing removes the pixels that were supposed to be cut off during the cropping. The offset represents the number of pixels of that side that require to be cropped off.

It should be kept in mind that on .Net Core the package must cover all platforms. For that case there are three nuget packages available for .Net Core for Windows, Linux, and OSX each.