Minimal Web API

For a task at work, I needed a mock WebApi for mimicking behavior of 3rd party API, that is not accessible from my machine. Sure enough I proceeded using line of least possible resistance and selected ASP.NET MVC Web Application template and WebAPI and ended up with bloated project that scared the life out of me when I just looked at it. Seriously, Microsoft, you couldn’t do a simpler template? I am pretty sure, that having all sorts MVC thingies installed helps, although, I am not completely sold on EntityFramework that sneaks in as well. But I digress.

Without further ado, I present you minimal WebAPI. A project that contains only what it needs to, to behave as WebAPI and nothing more. Below, I will lead you step by step through the process of creating one yourself, but you can also clone a repository from GitHub. Be careful though, as solution only supports .NET 4.6.x.
[Read the rest of this entry…]

Custom software – Introduction

Custom software is software that is usually done for one client, one environment and limited user base. It’s specific use case means, it won’t be sold more than once, which translates to high enough price to cover development costs. And then some.

So why do companies decide to order and pay for custom software over and over again? Custom software has one big advantage over regular off-the-shelf one. It is adaptable to whims and fancies of a customer. Hence, the name custom. Now, here is a public secret. Companies, specially wealthy ones, dig adaptable. You see, where smaller companies don’t have (many) defined processes, big companies are set on tightly defined processes, usually certified by ISO 9001 or similar standard. Off-the-shelf solution is just not an option, as changing a process would cost a lot of money, time and resources.

As a developer with a career in building custom applications, I have done and seen my share of mistakes and fallen into several pitfalls. This series is here to help you (and also future me) avoid them as best as possible.

In part I of the series, I will be blabbering about project architecture and discover last year snow in monolith vs microservices debate. We will cover how to start, how to continue and how to take care of the accumulated tech debt.

Part II will be focused entirely on how to integrate your software with third party software. There is always something to integrate with in custom software business and it is better to be prepared.

Part III will touch the topic of what happens when your custom software gets resold to another and another and another customer. Main focus will be on how to handle new requirements and hopefully not mess up existing and future deployments.

Last but not least, a disclaimer. This series is made of findings I gathered in my career of building custom software. As many things in software, it definitely does not present the only right way. In some cases you might also find it completely wrong. Good. Let me know.

Windows 10 changes Slovenian locale (at last)

If you are a proud developer of software sold internationally or in Slovenia, you might pay a little attention to this. It has not been noted anywhere of importance and I discovered it by chance when one of the programs I am working on crashed.

Versions older than Windows 10 had the following Slovenian date and time format: “d.MM.yyyy”. As far as this can be understood from computing point of view, it is in conflict with Slovenian language rules.

So, in Windows 10, someone made a bold move and fixed said format to: “d. MM. yyyy”. Finally, one might say. Except, every possible application, relying on previous false date format, will now crash. This is specially true in C++ Ole objects, where calling COleDateTime::ParseDateTime with OS set language now fails, if string representation of date is in “d.MM.yyyy” format and OS primary language is Slovenian. Let me state here, that .NET handles date formatting without problems.

If you are targeting Windows 10 clients only, this is not a problem, per-se. You just need to make sure that there are spaces after each dot in date time string representation. If you are targeting multiple OS versions, you are cooked as older Windows, do not recognize new date time format.

I am still searching for least painful workaround, that would work on any Windows OS client. If anyone has an idea, you are more than welcome to share.

Know thy tools

A few years ago, I wrote a post on why I don’t trust 3rd party APIs. It has never been more true than today (in days of NuGet, npm and other package managers) when adding an API is a matter of seconds. Seriously, you don’t even have to break a sweat. Package managers and web searchers got you covered. We live in the days where even “evil” Microsoft decided to move to the good side of the force and went open-source. Right? APIs get updated more promptly than ever and they are available for just about anything. And code reuse saves you a lot of time. So why am I still skeptic about it?

[Read the rest of this entry…]

Quick tip: Extending column which is also (part of) primary key

At work, I got a short task of extending a varchar column in our database from 25 chars length to 50. The task seems easy enough. But, as things usually turn out, it contained a GOTCHA! The column was also a part of primary key on that table. Thus, I started to wonder. Can you resize a column that is part of primary key without recreating primary key itself?

I did some empirical experiment on MSSQL and Oracle RDBMS and came to a conclusion. You actually can just extend the length of a primary key column and primary key will auto-adjust.

Also, in case you are wondering, the same applies to all possible constraints on the table that include said column.

Mobile apps development: Part I – Environments

Recently, I started to learn how to do mobile apps. Instead of classic ToDo app, that everyone is so fond of, I decided I will do a bit more realistic application. It would include, for starters a first time initialization, that would run (what a surprise!) at first run of installed app. This initialization would check connection, register account on my server (using web api) and use SQLite as local persistent storage.

[Read the rest of this entry…]

Quick tip: Do proper exception handling

This might be a bit of a d’oh, but if you decide to handle exception, handle it properly. What do I mean by saying “properly”? Have you ever seen code like this?

This code is stupid. Exceptions are a sign of exceptional or unpredicted behaviour. Thus, they should be treated with all seriousness. The code above works fine, if no exception is thrown. However, we live in unpredictable world. Internet connection may die. Hard drive may crash. Computer can run out of memory. And, in the case above, as soon as exception is thrown, neither you nor user will have the slightest clue of what went wrong.

There are two ways to solve this:

  1. Re-throw exception using throw; statement and handle it later on or
  2. Handle it in catch part of statement.

 

I understand that sometimes you just don’t see the need to handle an exception, but the least you can do is write the exception to log file.

Quick Tip: Create custom server controls with a grain of salt

In asp.net world, creating custom server controls has become some sort of a standard. In fact, it is so easy to create a server control, that developers usually do it without thinking. The problem is, that server controls are a bit more complex than an average Joe would think. There are bunch of things you need to take care of, like handling client and server-side validation, handling control when view state is disabled etc. A developer must pay attention to these things, or weird bugs can start happening.

[Read the rest of this entry…]

Other developer essentials: Part IV – Google search

I don’t know about you, but I still have a vivid memory of the time before internet actually became useful. In those days, learning how to solve your problem included a lot of trial and error attempts and eventually a trip to local library. If finding a book on correct topic wasn’t enough of a challenge, finding a solution usually meant reading most of 800 page bible.

[Read the rest of this entry…]

Quick tip: Copying certificate serial number in windows has a glitch

The easiest way to obtain serial number of a certificate is to go to Internet options -> Content -> Certificates and double click the desired certificate. In the Details tab, there is a property list control with a row containing “Serial number” label in first column and value in second. When you click on it, the serial number is displayed in field below the properties list.

Certificate serial number

Certificate serial number

On Windows 8 and Server 2012 , selecting entire field content, pressing Ctrl + C and pasting it into Notepad or Notepad++ will display only text, without leading spaces. The problem is, the text contains special hidden characters in front and/or at the back of the pasted string. Characters are invisible to text editors, but are still there. You can see it, if you paste directly to Command prompt window.

Serial number pasted to command prompt

Serial number pasted to command prompt

On Windows 7 and Server 2008 and below serial number has visible “spaces” that represent those same hidden characters (as depicted in image of certificate details above) and user can select only real content of serial number field. Funny enough, if you access the field with code,  there are no special characters in the value.

As it is so easy to copy hidden special characters and as this “feature” caused major problems at one of the projects I support (not to mention hours used for debugging the issue), I created a small windows application that allows you to copy major properties (so far: Issuer, Issued to, Expiration date and Serial number) from all installed personal certificates in either Local machine or Current user certificate store to your clipboard. Source code of the application can be found on GitHub.