Providing flexibility with .Net Core
As a company with mainly web developers, we often get requests from clients that are quite challenging. Recently one of these challenging requests found itself at my desk in the form of a very excited event planner. She was tasked with providing visitors at Nampo Harvest Day with some entertainment in the form of a little competition. Armed with her infectious excitement, notebook and pen, I couldn’t resist to hear what she had planned.
She explained: “We need a competition to entertain the visitors for about 2 to 3 minutes. We want them to listen to a couple of music clips and choose the corresponding image of the artist. There must be a time limit of 2 minutes to listen and they have to enter all their details when they are done. We will draw a winner at the end of each day who will win a R1 000. We will have 3 laptops at the event. We will provide the music clips as well as the album art. We want it web based for future use but we won’t have any internet connection while we are there. (at that specific event)”
Well everything was fine up until the last requirement mentioned. Web based with no internet connection… that was going to be quite something. So instead of shooting the idea down, I asked her to give me a couple of days to see what we could come up with as a solution. She agreed and left me with the impossible task of finding a way to use a website without an internet connection… I know what you are thinking. Websites and internet connections are quite fond of each other. But, nonetheless, I fought the urge to go against the common developer stereo type that we are always up for new a challenge and started doing some research.
After begging Google for some sort of solution and coming up with nothing, I thought maybe we should approach the problem a bit differently. Rather than staring at the wall of website with no internet, how about building software which can run locally and with minimal effort be scaled to web after the event for any future events. That seemed like a better solution. So, asking around in the office for any ideas, one of my co-developers suggested that maybe we should look at using Microsoft’s new open source (Developers all around the world contributes to the code base) library .Net Core (Pronounced: Dot Net Core). According to Microsoft it works cross platform (on multiple operating systems) and its open source. What more do you want?
So, following my co-worker’s idea, I started doing some research on this new open source framework. It all seemed fine and nothing special because I am a .Net developer and it seems that its all the same as normal .Net without some of the major functionalities (At that time still being built for the .Net core framework). That was until I realized that you could build a self-containing web application… What is that you might ask? Well that is a website that can run without internet, so to speak.
Normally, a website is built and hosted on a web server (a computer specifically for websites and web applications) which can be accessed via the internet with a web address pointed to the web server. But you need internet for that. So, with .Net Core, I can build a website or web application which has its own built-in web server. Awesome, right? I thought so too.
What this essentially meant was that we could build a website as we normally would and then just publish as a self-contained application and run it on the device(s) itself for the specific event where there wouldn’t be any internet connection. But it wasn’t that easy. We usually make use of Microsoft SQL server for our databases. This was a problem with a self-contained application because you would need to install MSSQL on the device as well and that would not be possible because you need to know what you are doing working with these enterprise-like software and we could not expect the client to do this. After some digging I found a neat little database called SQLite. It ticked all the boxes for our requirements and consisted only of a single file included in in the project. Things were looking good.
Next was adding functionality and database access in .Net Core. Easy, right? It is .Net framework after all. It’s not. The problem with open source this quick after it started, is that everything that you are used to in the normal .Net framework is not yet added to the source of .Net Core. It’s a process that takes time and a lot of bugs that need to be fixed. So, every built-in tool or library either works differently or needs to be added separately, which seems fine, until you realize that it is split up into little modules with different versions and different versions of one module means you need to update a list of other modules and so on. It takes quite some time to figure out and when searching online, you need to make sure that you are viewing documentation of the same version of .Net Core that you are using otherwise nothing will work. I will admit that is was quite frustrating in the beginning but after a while I found a liking to it. As a developer, one gets a better understanding of how the framework is put together.
Now that we had a working, self-contained web application, we needed to focus on flexibility. Since it’s a competition there would need to be an audited process of retrieving the winners. Normally we would take all the qualified entries and use a random number generated by software and draw the winner. The problem we now had was that each application instance was running on its own with its own database. Meaning at the end of the day we had three sets of entries, on three different devices. The devices were not connected to each other because the client did not have any networking knowledge and they would be quite remote, so there would not be any support to help with connectivity issues. We then came up with a double random process. The first random number will determine the device to draw the winner from and the second random number will determine the winner from the selected device’s entries.
We then added a check/setting so that if you do have an internet connection, that all entries will be sent to a centralized database hosted on a webserver and no double random process would be necessary.
The real flexibility of this self-contained application is that we can host it as a normal website or run it locally as a normal application. Yes, a website that opens when you run a .exe (executable) file. It’s quite something to see. When you have internet, you open your browser and go to the application as a normal website and if you don’t, you open the .exe file. Now that, is true flexibility.
For solutions like these and more feel free to contact us.
Written by staff member: Senior Developer Christian Kruger