Item-based exception handling in LINQ

Last week I rewrote some of my client’s code after having discovered a number of bugs. More specifically, a lot of errors came up in LINQ methods such as Where and Select. In order to capture what exactly was going wrong there, I have added a new extension method to the IEnumerable interface, allowing item-based exception handling on collections and LINQ statements.
Continue reading “Item-based exception handling in LINQ”

Developing timerjobs in C# with Quartz.NET

At some point, any developer will have to write some code that must be executed at regular intervals. In SharePoint for instance, timerjobs were (!) very easy to create. In .NET, you could choose between scheduled tasks and windows services. While I was doing research on the ideal replacement for timerjobs in the new SharePoint app model, I came across Quartz.NET. In this post, I will show you which code you need to create timerjobs.

Continue reading “Developing timerjobs in C# with Quartz.NET”

Replacing file extensions from uppercase to lowercase

Here’s a very simple utility that recursively finds uppercase file extensions and makes those who are lowercase. For once, it’s not written in C# but in good old DOS. If you paste this code in a CMD file, you’ll have a working program. If you execute this cmd, it will take the current folder as the root and it will process all files and subfolders.

Nowadays you would use PowerShell but this is a way to provide a quick fix to your users.

Retrieving blog posts using C# and the WordPress REST API

As part of my new professional website that I hope to release later this year, I thought it would be a good idea to dedicate a part of my site to this blog. Instead of choosing the rather traditional way of integrating blogs (e.g. embedded HTML snippets), I have chosen to take a look at its Web API. In this article, I will focus on one scenario: working with blog posts.

Continue reading “Retrieving blog posts using C# and the WordPress REST API”

Tutorial on creating loosely coupled applications with MEF

When I first read about MEF (Managed Extensibility Framework), I thought it was a great concept to create plugin-based applications, allowing customers to customize some behavior of the application for instance. Putting the whole concept into reality is something different, so in this article I will give a brief overview of the steps to take to get started with MEF.

Continue reading “Tutorial on creating loosely coupled applications with MEF”

Creating SQL schemas using Entity Framework Code First

As you might have read in my previous post, I used SQL schemas to partition data between tenants. Being part of the true definition of SaaS, a new tenant should be up and running within minutes without any human intervention. With my suggested approach, we need to do two things:

  • Registering a new tenant
  • Attaching users to the tenant

In this article, I am going to focus on the first item whereas the second one shouldn’t be a big deal if you are planning to create software as a service.

Continue reading “Creating SQL schemas using Entity Framework Code First”

Multi-tenancy with ASP.NET MVC and Entity Framework

Until recently I have never had the time to concentrate on cloud application development. All of the projects (non-SharePoint related) I have ever worked on were dedicated to only one customer, so the multi tenancy challenge never came up. Although my own website is hosted on Azure, I realized I had to create my own project to gain some knowledge on this area. There are many books and web pages available regarding cloud development, but for a very good reason none of those give really specific examples: it all depends on what you want to achieve. In this article, I will cover one scenario that is quickly to implement with the knowledge many .NET developers probably still have, which is developing a **ASP.NET MVC application with Entity Framework which ensures storage in one database with multiple schemas.

Continue reading “Multi-tenancy with ASP.NET MVC and Entity Framework”

Parallel looping and returning 1 collection in C#

An interesting feature in .NET 4.5 is the ability to process collection in parallel. Along with the async/await feature, you can really improve the performance of your application with a few simple steps. Whereas both components are documented really well, I thought this would be a walk in the park. However, you should pay attention when you want to return a collection that was modified in the parallel block. If you don’t, you might be missing a few items in the list.

Continue reading “Parallel looping and returning 1 collection in C#”

C# and the Spotify Web Api: part I (authorization)

Curious about the possibility of displaying Spotify playlists on my website, I investigated the Spotify Web API. Initially, I thought everything seemed quite easy, but then I got to the authentication and authorization section. As it turned out, it is not that simple but after trial and error, I got what I wanted. Here’s what I did.

Continue reading “C# and the Spotify Web Api: part I (authorization)”

Repository pattern in SharePoint

A few months ago, I had an assignment for a multinational beverage company to implement a publication system for their products across Europe. Along with a few other consultants and managers from another unit in my company, they had decided to go for a SharePoint solution as this seemed to meet all business requirements: centralized master data management with the ability to generate XML – and Word (or other human friendly) documents. I got on the project a few months later only to discover that the suggested approach could never work: the entire data model (entirely relational and normalized) was made with many SharePoint lists and the data was retrieved with JSOM. With a limited budget and a tight deadline, the best thing to do was to make a proper design with a solid architecture and minimal amount of code and complexity. The best alternative here was to build a custom SharePoint solution with a custom ORM layer. I considered LINQ 2 SharePoint but in this project where nothing was certain and everything changed rapidly, I quickly decided that a custom ORM layer was the most suitable. If I had the choice to start from scratch, I definitively would have chosen to go for the combination EF + BCS. As this MSDN article explains, the repository pattern is pretty much the way to go when it comes to building a generic, high quality and lightweight data access layer. This also counts for SharePoint solutions, as Chris O’Brien confirms in an old article. Although many articles cover this topic, I never was quite satisfied with the technical solution that was provided.

In what follows is a very simple yet powerful way of creating a generic data access layer for SharePoint (both CSOM and SSOM).
Continue reading “Repository pattern in SharePoint”