Gal Segal's Blog

Thoughts of a programmer with a soul

Dec 10

Unit Testing Log4Net Wrapper

Tags:

writing

Log4Net is an industry standard for logging. Almost every developer uses it in some point in his/hers professional life. I am no exception, and I needed to write a LogManager wrapper and unit test it.

Continue reading...
Jan 31

Simple Process Manager

Tags:

Simple Process Manager

It is a common matter to have an operation in the server that requires few steps. Sometimes it is necessary that all the steps will complete successfully, and if one fails, a rollback should be made. SQL has the transaction term to support this kind of situation, and I’m about to show how it can be done in code.

Continue reading...
Jan 26

Why Inheritance Doesn’t Scale

Tags:

Why Inheritance Doesn’t Scale

OO Programmer tend to use inheritance as a way of code reuse, a best practice and for better maintainability. I am no exception. But there are times where inheritance can become your worst enemy, and instead of making your life easier, complicate stuff to the point you are lost.

Continue reading...
Dec 14

WCF Client Proxy Creation Process

Tags:

WCF Client Proxy Creation Process

WCF enables us to consume a service in 2 ways: adding a service reference or by creating the proxy yourself. Both methods do the same thing – create a proxy class and and using it with the channel factory. Both cases are good, and its a matter of preference which one you use. I tend to use the second one – I prefer creating my proxy and add reference to the service dlls in the consuming app.

Continue reading...
Oct 24

Thread Safe High Performance Capped Queue

Tags:

Thread Safe High Performance Capped Queue

Lately I was busy creating a new infrastructure for our logging system. I work on OpenBook – a website that gets a lot of traffic and involves with many different business processes. I started logging errors, info data and more with the excellent log4net to files, but has the logs got bigger and longer it became almost impossible to track it. We also use several IIS servers behind a load – balancer, and the result is a lot of logs on many different servers.

I wanted to create an infrastructure that will be able to have the lowest footprint on the production server, but still be able to log a lot of message to some storage (SQL server, NoSQL server, files..).

Continue reading...
Oct 6

ReaderWriterLockSlim Extension Method

Tags:

locker

ReaderWriterLockSlim was introduced in .net 3.5 as a better and more stable locker that allows multiple reads and single write capabilities on a synced resource. Using it is fairly a simple task: for reader you wrap your resource with “EnterReadLock()” and “ExitReadLock()”, similar approach for writing. But problem lurk around the corner when it is not used correctly…

Continue reading...
Sep 21

MVC Routing Legacy URLs

Tags: ,

Premazzi_Luigi-ZZZ-Saddled_Horse_and_a_Horseman._Study1

When moving a web application from WebForms to MVC framework I found sometimes “.aspx” and “.ashx” URLs from the old website sniking into my new clean and carved URLs. This issue can be addressed specifically by targeting the relevant “aspx” URLs and redirecting to a desired place, but it can get a bit messy. I found a more generic way of doing so by creating a new “Legacy Route” that will redirect all legacy requests to the new home page

Continue reading...
Sep 14

MVC Output Cache With Cache Profiles

Tags: ,

Dream

MVC and Output Cache are a good match, and since MVC3 this match is even better. But there are some occasions where this match is not good enough. I recently discovered an unwelcome behavior when dealing with ajax and had to come up with a solution.

Continue reading...
Aug 30

Object Mapper Extension Method

Tags: ,

sunflower by pforty

Many times I need a small piece of code that will help me map one object to another. I see it a lot when dealing with view models : taking a business object and modeling it to serve the needs of the presentation layer.
So I came up with a simple extension method:

Continue reading...