2016 is coming to an end (What an year here in Brazil!), and we can see retrospectives everywhere. I don’t want to do a “What happened” or “What did I do” retrospective. Instead, I want to write about the open source projects I used along the year.
I use open source projects a lot (I don’t like to reinvent the wheel) and they help me a lot. Although many open source projects have a lot of collaborators, most of the time, they are an effort of a single developer (or a very small group of developers) that spend their own spare time to release these gems to the public, without asking anything in return (yes – they are a case of free as “free beer” and free as “freedom”). Nothing more fair than write some lines about them as a way to say “thank you”. So let’s go!
Microsoft open source projects
In the latest years, Microsoft released a lot of open source projects: Roslyn, .NET Core, Asp.NET core, Reactive Extensions, VSCode, TypeScrypt, SignalR and PowerShell are just some of the projects that can be cloned and modified as you will (do you know that Microsoft has the largest number of open source contributors to GitHub: http://www.networkworld.com/article/3120774/open-source-tools/microsoft-s-the-top-open-source-contributor-on-github.html ?).
Although releasing the core projects is something new, I’ve been using Microsoft open source code for a long time – when I started developing, their sample projects were the best way to learn how to use the technology, and this is already the case. If you haven’t checked, go to the Microsoft samples (https://github.com/Microsoft/Windows-universal-samples) to check how to use the newest technology for Windows 10.
So, the first in this retrospective is Microsoft – you can check its open source projects in https://opensource.microsoft.com/ (there were 193 projects there at the time) and in their GitHub: https://github.com/Microsoft (there were 42 pages of repositories there!).
If you develop for any of the XAML technologies and don’t use the MVVM pattern, shame on you! You should be using this pattern, as it eases the separation between business rules and UI, facilitates testing and enhances maintainability of your code.
The pattern is very easy to implement and you don’t need any special framework to use it, but using a framework will make things easier and enforce some good rules for your code. There are several MVVM frameworks out there (MVVM Light, Caliburn Micro, Calcium, MVVM Cross, Prism are some that come to my mind, now – maybe I can add to write an article about them – this can be on my resolutions for 2017 ), but the one I use the most is MVVM Light Toolkit (http://www.mvvmlight.net/ , source code at http://mvvmlight.codeplex.com/), a nice work from Laurent Bugnion, an old time MVP from Switzerland.
This framework is very easy to use, you must create your ViewModels derived from ViewModelBase and, when you need a command binding, you can use the RelayCommand class. For communication between ViewModels and Views, you can use the Messenger class for sending messages between them. There is a simple IoC container, so you can use dependency injection in your code (another nice feature to remove coupling).
The simplicity and ease of use is definitely a big plus in this framework and the only thing I can say now is “Thanks, Laurent” !
If you are adding Nuget packages to your project, this is the first project that appears in the list. If you need to process Json data (and most developers need it), you must use this project. It’s a high performance Json package and it’s even included in the template for a new Asp.Net project!
It is mainly developed by James Newton-King and you can find it in http://www.newtonsoft.com/json (source code at https://github.com/JamesNK/Newtonsoft.Json). It has a very good Json serializer/deserializer and you can even use Linq to process the Json data. If you want to see it in use, take a look at my article http://blogs.msmvps.com/bsonnino/2016/05/26/minifying-and-formatting-json-data-with-c/ or check my Json Minifier project at https://github.com/bsonnino/ProcessJson.
There are many open source IoC containers frameworks out there, and I like very much SimpleInjector, Unity and Ninject, but the one I use most is LightInject (http://www.lightinject.net , source code at https://github.com/seesharper/LightInject), a framework developed by Bernhard Richter. It’s very fast and lightweight and it works on most platforms I use to develop. It works fine with the IoC container available in MVVM Light, and you have several ways to resolve your dependencies.
I really recommend using an IoC container to break your dependencies and make your code more robust. Although it takes some time to get used to this kind of programming, it certainly pays it off when it comes to reusing code and debugging it.
Testing, oh, Testing! Testing is like flossing – everybody knows that they should do it, but very few (I would say nobody, but that would not be fair to some poor souls) really do it. When it comes to testing, I really think that one of the worst parts is to mock objects for the tests: create fake classes that do some fake behavior seems to me like some sin I am doing – I should not be doing that or I will go to hell.
FakeItEasy (https://fakeiteasy.github.io/ , source code at https://github.com/FakeItEasy/FakeItEasy) relieves me from that sin. With it, I am able to mock objects and create behaviors that simulate what I want in my tests. The quantity of source code this library saves me is really huge! Oh, and besides all the documentation you have for it, you can also have a free book, published by Syncfusion (one other thing I really recommend – their Succinctly series, now with 103 free ebooks, have fast documentation about a number of subjects: https://www.syncfusion.com/resources/techportal/ebooks): https://www.syncfusion.com/resources/techportal/details/ebooks/fakeiteasy. The only thing I regret in this library is the lack of support for faking under Windows 8 or Windows 10 (In this case, I have to try the LightMock library and see if it fits – another resolution for 2017).
By the name, you can think that this pack is for use in an ASP.NET program, but this is not the case. This framework parses HTML files, and you can use it in any .NET application. It’s wonderful when you want to do some web scraping: just load your HTML file into an HtmlDocument and you can easily get the data in it – you can parse the HTML and even change the data in it.
You can get this package at https://htmlagilitypack.codeplex.com/
If you need to manipulate Zip files in a .NET program, you can use DotNetZip (https://dotnetzip.codeplex.com/). With it, you can open zip files and add new files to them, extract or list the contents of a zip. You can even use Linq to query for entries you want. The files can have password encryption, and it also supports Zip64.
Logging is something that I always need for my programs. When it comes to UWP, there are not many options out there. One of them is Metrolog (https://github.com/onovotny/MetroLog), a very lightweight logging framework developed by Oren Novotny, that works fine with Windows 8/8.1 or UWP.
Although lightweight, it has many features, you can configure the destination of the logs, the logging format and it’s very easy to use: just configure the logging and get a logger with LogManagerFactory.GetDefaultLogger and you can start logging.
Although this project is under the Microsoft Github (https://github.com/Microsoft/UWPCommunityToolkit, website at https://developer.microsoft.com/en-us/windows/uwp-community-toolkit), it’s not entirely developed by Microsoft. This is a set of components developed by community developers and Microsoft employees, and features a set of components that are not in the UWP SDK.
You get there a set of controls, like the Hamburger menu, a Radial gauge or a listview with the “pull to refresh”, many new animations, some code helpers, like new converters or storage helpers, or even access to services like Bing, Facebook or Twitter.
This set of components can improve your UWP apps with minimal code, it’s highly recommended.
If you need some kind of structured storage in a UWP application, the best way to do it is using a Sqlite database. In this case, you should use Sqlite.NET (https://github.com/praeclarum/sqlite-net), a small ORM for SQLite databases.
It’s very easy to use and you can have a very good database to store your data in a UWP app, without having to resort to database commands. I really like ORMs, as they abstract the use of a database and use normal C# classes to store data. When you are using a local SQLite database, this ORM is really nice!
You won’t be using this library very often, but if you want to handle Alternate Data Streams, like I did in my article here, the Trinet.Core.IO.Ntfs (https://www.codeproject.com/Articles/2670/Accessing-alternative-data-streams-of-files-on-an , source code at https://github.com/hubkey/Trinet.Core.IO.Ntfs) will help you, without the need of adding P/Invokes and working with the Win32 API.
You can check its use in my article and take a look at the ADSs in your system (it surely worth to see what’s hidden in your files).
One missing component in WPF is the Folder Browser. Usual answers to this item is to add System.Windows.Forms as a reference to your project and use the Windows Forms component in the program. That’s something I really don’t like: why should I add Windows Forms to my WPF project if I don’t want to use it?
With the Vista Bridge project (now the Windows API Code Pack – https://blogs.msdn.microsoft.com/windowssdk/2009/06/12/windows-api-code-pack-for-microsoft-net-framework/), there were a lot of components that made the bridge between the Windows 32 API released by Vista and WPF.
WPFFolderBrowser (http://wpffolderbrowser.codeplex.com/) takes the work in The Code Pack and creates a Folder Browser for WPF without having to use Windows Forms.
Did you ever had the need to create a bitmap from scratch? Or to take a bitmap and change it? WriteableBitmapEx (https://github.com/teichgraf/WriteableBitmapEx/) is a library to manipulate bitmaps. It extends WriteableBitmaps and adds more processing to the bitmap manipulation.
It’s really fast and easy to use, and if you need to do something with a bitmap, you should really use it.
Cryptography is something that is needed in your apps from time to time. Windows 8/8.1 and UWP have cryptographic functions that work very well, but, if you need to have portable functions between UWP and full .NET (WPF, Windows Forms or ASP.NET), you should try PCLCrypto (https://github.com/AArnott/PCLCrypto), that uses façade assemblies to the real implementations in every platform.
This way, you use the native cryptographic assemblies for every platform without having to resort to conditional compilation.
Callisto (https://timheuer.github.io/callisto/ , source at https://github.com/timheuer/callisto) is a framework developed by Tim Heuer, a Microsoft Program Manager, and was very useful for Windows 8 apps, especially when there was no Flyout control – at that time, the best way to implement it was to use Callisto.
Now, that a Flyout control is in the SDK, there are still a lot to use in Callisto: the rating control, the numeric up/down and the custom dialog are just some I use normally. If you haven’t checked it, it’s worth giving a look at it.
There was a lot covered here. As you can see, I use open source a lot, and I know it’s a big effort to maintain these libraries up-to date, so I’d like to thank all the developers that maintain these libraries and release them as open source, in a way that anybody can analyze them and use them as source code examples, use them to improve their apps without asking anything in return.
And you, do you have any other library that you think it should be listed? Do you want to know more about any of these (maybe I can write an extra article about it)? If you have anything to comment, please place it in the comments section.