Thread synchronisation with SemaphoreSlim and async delegate calls

Although running a parallel foreach that makes async calls is a pretty usual thing, I found my self in a very complicated situation, when async delegate calls got in the way!

The situation arise while I was trying to write a MemoryCache manager for my application (the manager was actually a wrapper of MemoryCache Class).

The following gist file, is a basic structure of what I was trying to do: Ask MemoryCacheManager for an item with AddOrGetExisting by passing a key to find the object and a generic delegate Func task that actually returns the object.
Read More »Thread synchronisation with SemaphoreSlim and async delegate calls

Mocking expected behaviour of SQL functions for Unit Testing with SQLite

While unit testing, I came across a method in an SQL repository class that was using a raw SQL query, and along with that, SQL Server’s newid() function. Since the complicated reason behind this decision was out of scope, I had to find a way to unit test that method…

SQLite was -of course- the first approach, but any attempt to actually test the method would nevertheless fail with the exception Microsoft.Data.Sqlite.SqliteException: 'SQLite Error 1: 'no such function: newid'.'.

Read More »Mocking expected behaviour of SQL functions for Unit Testing with SQLite

Simple website stress tool with C# and Apache HTTP server benchmarking tool

To be honest, I got bored trying to remember all switches and combinations of Apache’s benchmarking tool! Since I use it sort of rarely, I just wrapped it in a convenient -for me at least- app that I can use without having to remember or read anything!

This is my simple implementation of a website stress tool that uses Apache HTTP server benchmarking tool to get results for any request. Just follow the link for my github account, download, build, and use 🙂

Read More »Simple website stress tool with C# and Apache HTTP server benchmarking tool

ASP.NET MVC 5 with Razor Kendo UI: Dynamic Grid Creation – Columns, Ordering, Grouping and Paging

The requirements were simple! A grid that will load a whatever query, grouped by whatever columns, with filters enabled, paging and everything. Easy task with ASP.NET Telerik grids but not easy at all with Kendo UI!

Since we can’t have a ViewModel or Model for the grid (we don’t know what columns a whatever query has!), I came up with a rather different ViewModel that holds descriptions for columns, groups etc…:

Read More »ASP.NET MVC 5 with Razor Kendo UI: Dynamic Grid Creation – Columns, Ordering, Grouping and Paging

ASP.NET MVC 5: Custom AuthorizeAttribute for custom authentication

In a previous post I wrote about how you can should protect your web app from human errors made by developers, by enforcing authentication by default.

Since adding the AuthorizeAttribute to every action involves global filters, we can use that to add our own custom authentication, by inheriting AuthorizeAttributeand overriding the AuthorizeCore and HandleUnauthorizeRequest methods.

Read More »ASP.NET MVC 5: Custom AuthorizeAttribute for custom authentication

ASP.NET MVC 5: “Authorization” by default for your web app

Securing your MVC app is a tricky business! Although security is a huge topic, one of the problems that you might encounter is that unauthenticated users are allowed by default to execute every action in your web app. That behaviour is potentially unsafe because you have to remember to decorate your actions with the authorize attribute, and humans are prone to errors!

This is why, in my opinion, authentication should be enforced by default, or differently [Authorize] attribute should be added behind the scenes to every action.

Read More »ASP.NET MVC 5: “Authorization” by default for your web app

Export MS SQL Database schema with C#

A few days ago, I was searching for a way to export MS SQL schema of all databases of a server for backup and migration purposes. Although I found some tools, what I needed was a way to get stored procedures, functions, views, triggers and everything even if it was encrypted.

Since I couldn’t find a way to automate this (e.g. run it every night to backup schema of my server), I thought it would be a nice weekend project.

You can read more about it, or download project from https://github.com/georgekosmidis/mssql-schema-dump!

Read More »Export MS SQL Database schema with C#