Sonar Overview


Sonar in a nutshell

Sonar is mainly a Web portal that stores everything about your builds and helps you navigate into all this data. Quality metrics are gathered by plugins of various tools (that may not come with Sonar), into a central database. The Web portal is composed of customizable dashboards, made out of customizable widgets, which can display data in various forms, with the ability to easily compare with previous builds, or see the progression through the last days or month. A drill down logic starting from any metric (such as Line of Code, violations, unit tests and coverage, etc.) will allow you to pinpoint the projects, files, and lines of code that are at the origin of their values. Various plugins (there are commercial ones) are available: they can group projects and aggregate their data, or see stats per developer for example. You can define quality profiles and select the rules that you want to apply to your projects (each rule is tied to a plugin), and create alerts when those rules obey certain conditions (too many violations, or coverage too low for the simplest).


Why Sonar and TFS?

Because Sonar is a great complement to TFS. It is not always easy to get the exact report we want: you’ll find reporting services and Excel reports which have to be set up with date ranges, and solutions filters. So you may have spent quite some time to configure a SharePoint dashboard. You can’t easily set thresholds that fail your builds according to some various metrics conditions. I mean, if all of this is possible because TFS is highly customizable, it is not all centralized in a single fully featured UI, and requires to use various products or technologies. Builds do not compare to each other (only the duration, and the GUI is fixed). While Excel shines at connecting to the TFS warehouse or cube, you need to be an Excel dude in order to navigate, slice, aggregate, compare data about build results. Third party tools don’t store their data into the build reports in a structured way, so you won’t get their metrics directly in the cube. While all this is possible with, really, it is not there as easily as we would want, and that is why Sonar is becoming so popular in the .NET world (and not especially with TFS).

Keep in mind that TFS is about so much more than Sonar. TFS links Work Items to code, allowing you to get an insight of real semantics in your projects (bugs and requests influence for example). Sonar focuses *only* onto the quality of your code, instantly and over time.

So we all know that Sonar is a Java application but it proves to be useful even in the .NET world, thanks to the hard work of a few pioneers to write java plugins that would launch our favorite everyday tools (FxCop, StyleCop, Gendarme) and tests frameworks (with Gallio and various coverage technologies), there it is, waiting for us.

The plan to integrate Sonar

Integrating Sonar means that our TFS Builds will launch a Sonar analysis on our projects.

For simplicity’s sake, I’ve not represented TFS components such as build controllers, agents, etc. What is important here, is that the TFS build calls something named “Sonar runner”. This Sonar runner launches a JVM with a bootstrap that launches each plugin you have configured in your Sonar server. Each Sonar plugin then launches the appropriate native tools, gets their results and publishes them into the Sonar server. The data is stored in the Sonar database.


Redis Overview

StackExchange.Redis Client libraries

At the time of writing there are two popular and actively developed C# client libraries for Redis available:

  • ServiceStack.Redis – created by Demis Bellot of ServiceStack fame and based on Miguel de Icaza’s redis-sharp project,
  • BookSleeve – mantained by Mark Gravell and as I understand used by Stack Exchange.

Before making a choice I would suggest trying both of them and deciding which API and capabilities better suit your project.

BookSleeve has non-blocking (asynchronous) API, provides thread-safe connection object, while ServiceStack implementation provides JSON serialization, connection pool like client factory and uses convention to simplify POCO object persistence.

In this article I will use ServiceStack.Redis, but remember that BookSleeve has been proved in a big real-world web application and is also very capable.

StackExchange.Redis is a high performance general purpose redis client for .NET languages (C# etc).


  • High performance multiplexed design, allowing for efficient use of shared connections from multiple calling threads
  • Abstraction over redis node configuration: the client can silently negotiate multiple redis servers for robustness and availability
  • Convenient access to the full redis feature-set
  • Full dual programming model both synchronous and asynchronous usage, without requiring “sync over async” usage of the TPL
  • Support for redis “cluster”



StackExchange.Redis can be installed via the nuget UI (as StackExchange.Redis), or via the nuget package manager console:

PM> Install-Package StackExchange.Redis

If you require a strong-named package (because your project is strong-named), then you may wish to use instead:

PM> Install-Package StackExchange.Redis.StrongName

(for further reading, see here)



Redis Fundamental

Using Redis with ASP.NET Web API

In this article I am going to show how to use Redis as a data store in a ASP.NET Web API application. I will implement a basic scenario that leverages ServiceStack.Redis library and its strongly typed Redis client, show how to model and store one-to-many relationships and how to use Web API dependency injection capabilities along with Autofac to inject repositories into controllers.

Client libraries

At the time of writing there are two popular and actively developed C# client libraries for Redis available:

  • ServiceStack.Redis – created by Demis Bellot of ServiceStack fame and based on Miguel de Icaza’s redis-sharp project,
  • BookSleeve – mantained by Mark Gravell and as I understand used by Stack Exchange.

Before making a choice I would suggest trying both of them and deciding which API and capabilities better suit your project.

BookSleeve has non-blocking (asynchronous) API, provides thread-safe connection object, while ServiceStack implementation provides JSON serialization, connection pool like client factory and uses convention to simplify POCO object persistence.

In this article I will use ServiceStack.Redis, but remember that BookSleeve has been proved in a big real-world web application and is also very capable.

Redis in a nutshell

If you are reading this article then very likely you already know what Redis is. If you are an experienced Redis user interested in ASP.NET Web API integration you can safely jump to the next part.

In order to use Redis efficiently and avoid potential pitfalls one needs to understand a little bit about how it works and how different it is from relational databases.I strongly recommend reading one of books or online materials available on the topic.

Simply put Redis is an in-memory key-value data store that supports durability.

In-memory and key-value sounds much like a memory cache – and indeed you can think of Redis as of a specialized and more advanced memory cache. Unlike other caches (such as memcached) Redis delivers richer feature set including things like sorted sets and even Lua scripting capabilities.

It’s main advantage over ‘traditional’ databases comes from the fact that it stores and retrieves data directly to / from operating memory – which means it is really fast.

Redis is simple and specialized – unlike relational databases it does not provide any table-like abstractions nor relational capabilities. Instead, it provides five fundamental data types along with specialized operations that can manipulate those types (stored values). This is why it is sometimes refered as a data structure server:

  • strings – the most basic and atomic type that can be used to store any data (integers, serialized POCO objects, etc.),
  • lists – lists of strings that are sored by insertion order,
  • sets – logical sets of strings,
  • hashes – maps between string-only keys and string values,
  • sorted sets – similar to sets, but each element is associated with a score that is being used to sort.

Examples of specialized

  • sets – SADD, SDIFF, SINTER, SUNION, etc.

Hopefully this should give you a basic feel for what Redis is about 🙂

Why would I use it?

Whether and how easily your application could benefit from Redis depends on its architecture, data volume, data complexity and experienced loads. When used correctly Redis can be bring major performance improvements and may help scale application out.

Here are some use cases I can think of:

  • as a main data store,
  • as one of multiple data stores, for example storing small, but frequently accessed information,
  • as a highly performant read-only view over your domain model,
  • as a cache.

Bearing in mind that Redis operates in memory, the first option is quite extreme and viable only if your data sets are small (or you can afford to have lots of RAM).

Because in this article I want to focus on ASP.NET Web API integration not architectural aspects I will choose this option.

By.. Vaibhav Gupta


Overview on Message Pack (A new Serialization format)

Message Pack 

I would like to Introduce a new binary serialization format. It lets you exchange data among multiple languages like JSON, but it’s faster and smaller.

MessagePack is can also play a big to achieve high performance and flexibility at the same time.

Overview on Message Pack

MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. But it’s faster and smaller. Small integers are encoded into a single byte, and typical short strings require only one extra byte in addition to the strings themselves.

Example: – JSON contains 27 bytes for below string but Message pack contains only 18bytes.

MessagePack for CLI

What is it?

This is MessagePack serialization/deserialization for CLI (Common Language Infrastructure) implementations such as .NET Framework, Silverlight, Mono (including Moonlight.) This library can be used from ALL CLS compliant languages such as C#, F#, Visual Basic, Iron Pyhton, Iron Ruby, PowerShell, C++/CLI or so.


You can serialize/deserialize objects as following:

  1. Create serializer viaMessagePackSerializer.Create generic method. This method creates dependent types serializers as well. 1. Invoke serializer as following: ** Pack method with destination Stream and target object for serialization. ** Unpack method with source Stream.


  • Fast and interoperable binary format serialization with simple API.
  • Generating pre-compiled assembly for rapid start up.
  • Flexible MessagePackObject which represents MessagePack type system naturally.


  • Binary files distributed via the NuGet package manager Cli.

Note :-  Redis is also supporting the Message pack which playing a big to achieve high performance.

For more details, please check with me on my email id or my number …

BizTalk Overview

Biz Talk  Overview


  • Microsoft BizTalk Server provides a development and execution environment that orchestrates business processes, both within and between businesses. BizTalk Server can handle business transactions that run as long as weeks or months.
  • BizTalk Server features include the ability to define business document specifications and how these documents have to be transformed when passed between applications, and the ability to monitor and log server activity.
  • The server provides a standard gateway for sending and receiving documents across the Internet, as well as providing a range of services that ensures data integrity, delivery, and security.
  • Microsoft BizTalk Server is an integration server product that enables you to develop, deploy, and manage integrated business processes and XML-based Web services.
  • Microsoft BizTalk Server enables you to connect diverse applications, and then to graphically create and modify business processes that use the services that those applications provide.
  • BizTalk Server engine provides a mechanism for specifying business rules, better ways to manage and monitor the applications built on it.
  • BizTalk supports many built-in data adapters. (SOAP, Message Queuing, FTP, HTTP, SMTP, SQL, EDI, File)
  • BizTalk supports many data format (Database, Formatted Text, HL7, XML)
  • BizTalk engine uses XML for all internal processing.

Need of Biz talk

  • BizTalk is great when dealing with frequent changes in how you do business with other businesses. For example, if you deal with a lot of businesses that have different message requirements, frequent network protocol changes, then BizTalk is for you. Also, many customers really like how easy it is to map the schemas of messages. For example, FName in MessageA can be easily mapped to FirstName in MessageB regardless of how the messages are structured.
  • What if the network protocol to receive and send these messages needs to change? How long would it take to change your custom application compared to a simple configuration change (no recompile necessary) in BizTalk. When you keep creating monolithic applications to handle your business to business (B2B) transactions, it becomes increasingly difficult to manage it and you find yourself trying to write an infrastructure to handle it. BizTalk provides all of this infrastructure for you. It has guaranteed delivery, standardized tracking, a business rules engine, redundancy, and much more.
  • BizTalk is a message conversion system. You give it MessageA and it converts it to MessageB. For example, if MessageA is an EDI (Electronic Data Interchange) message, then BizTalk is able to easily read the message and convert it into just about any other message type such as an XML document (MessageB). Will it convert a Word document to a PDF document? It can, but it was really designed to allow businesses to easily communicate with each other using practically any message format and nearly any network protocol.


  • Multiple adapters provide support for most industry standard transports (FTP, HTTP, File, SOAP, WCF, SQL, etc.)
  • Multiple accelerators are available that support for industry standard document formats (HIPAA, EDI, SWIFT)
  • RFID Platform
  • High availability
  • Fault tolerance
  • Scalability
  • End to end message tracking (including message body tracking if needed.
  • Messaging subsystem accommodates transactional messaging, i.e. BizTalk can send to/receive from trading partners within the context of a distributed transaction as long as the adapter supports transactions.
  • XLANGs workflow engine
  • Business Activity Monitoring
  • Business Rule Engine (BRE)
  • Management functionality via Management console
  • Integration with MOM
  • Integration with Enterprise Single Sign-On

If you will like my post, please leave the comments or need to know more …

How to get the Size of any Database in SQL Server

Data base Check

t.NAME AS TableName,
s.Name AS SchemaName,
p.rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
(SUM(a.total_pages) – SUM(a.used_pages)) * 8 AS UnusedSpaceKB
sys.tables t
sys.indexes i ON t.OBJECT_ID = i.object_id
sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
sys.allocation_units a ON p.partition_id = a.container_id
sys.schemas s ON t.schema_id = s.schema_id
AND t.is_ms_shipped = 0
t.Name, s.Name, p.Rows


WCF Hosting Fundamental


Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF we can build secure, reliable, transacted solutions that integrate across platforms. Using WCF, you can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application. An endpoint can be a client of a service that requests data from a service endpoint. The messages can be as simple as a single character or word sent as XML, or as complex as a stream of binary data.


Features of WCF

  • Multiple Message Patterns
  • Service Metadata, Data Contracts
  • Security
  • Multiple Transports and Encodings
  • Reliable and Queued Messages
  • Durable Messages
  • Transactions, Extensibility
  • AJAX and REST Support

Difference between WCF and Web Service

Features Web Service WCF
Hosting It can be hosted in IIS It can be hosted in IIS, windows activation service, Self-hosting, Windows service
Programming [WebService] attribute has to be added to the class [ServiceContraact] attribute has to be added to the class
Model [WebMethod] attribute represents the method exposed to client [OperationContract] attribute represents the method exposed to client
Operation One-way, Request- Response are the different operations supported in web service One-Way, Request-Response, Duplex are different type of operations supported in WCF
XML System.Xml.serialization name space is used for serialization System.Runtime.Serialization namespace is used for serialization
Encoding XML 1.0, MTOM(Message Transmission Optimization Mechanism), DIME, Custom XML 1.0, MTOM, Binary, Custom
Transports Can be accessed through HTTP, TCP, Custom Can be accessed through HTTP, TCP, Named pipes, MSMQ,P2P, Custom
Protocols Security Security, Reliable messaging, Transactions

WCF Fundamental

Some fundamental concepts in WCF which are given below :-

1. EndPoint :-

WCF Service is a program that exposes a collection of Endpoints. Each Endpoint is a portal for communicating with the world. It contains three part …

  • Address
  • Binding
  • Contract
  • Address: – Address is just like as WCF URL where this WCF service is hosted .Client will use this URL to connect to the service.


  • Binding :- Binding is used for  how client will communicate with service. There are different protocols available for the WCF to communicate to the Client. You can mention the protocol type based on your requirements.

A binding has several characteristics, including the following:-

  • Transport -Defines the base protocol to be used like HTTP, Named Pipes, TCP, and MSMQ are some type of protocols.
  • Encoding (Optional) – Three types of encoding are available-Text, Binary, or Message Transmission Optimization Mechanism (MTOM). MTOM is an interoperable message format that allows the effective transmission of attachments or large messages (greater than 64K).
  • Protocol(Optional) – Defines information to be used in the binding such as Security, transaction or reliable messaging capability
  • Contract :- Collection of operation that specifies what the endpoint will communicate with outside world. Usually name of the Interface will be mentioned in the Contract, so the client application will be aware of the operations which are exposed to the client. Each operation is a simple exchange pattern such as one-way, duplex and request/reply.

2. Binding

Simple definition for Binding describes how the client will communicate with service. We can understand with an example.

Consider a scenario say, I am creating a service that has to be used by two type of client. One of the client will access SOAP using http and other client will access Binary using

<endpoint address=”http://localhost:4090/ MyHostedService/ArthmeticOperation.svc”



<endpoint address=”net.tcp://localhost:4090/ MyHostedService/ArthmeticOperation.svc”



Note :-  Always enable serviceMetadata httpGetEnabled= true;


All services are exposed as contracts. Contract is a platform-neutral and standard way of describing what the service does. Mainly there are four types of contracts available in WCF.

  1. Data Contract
  2. Service Contract
  3. Message Contract
  4. Fault Contract
  5. Data Contract

A data contract is a formal agreement between a service and a client that abstractly describes the data to be exchanged.

Data contract can be explicit or implicit. Simple type such as int, string etc has an implicit data contract. User defined object are explicit or Complex type, for which you have to define a Data contract using [DataContract] and [DataMember] attribute.

A data contract can be defined as follows:

  • It describes the external format of data passed to and from service operations
  • It defines the structure and types of data exchanged in service messages
  • It maps a CLR type to an XML Schema
  • It defines how data types are serialized and deserialized. It is a versioning system that allows you to manage changes to structured data

Note :- We need to include System.Runtime.Serialization reference to the project. This assembly holds the DataContract andDataMember attribute.

  1. Service Contract

Service contract describes the operation that service provide. A Service can have more than one service contract but it should have at least one Service contract.

Service Contract can be define using [ServiceContract] and [OperationContract] attribute. [ServiceContract] attribute is similar to the [WebServcie] attribute in the WebService and [OpeartionContract] is similar to the [WebMethod] in WebService.

  • It describes the client-callable operations (functions) exposed by the service
  • It maps the interface and methods of your service to a platform-independent description
  • It describes message exchange patterns that the service can have with another party. Some service operations might be one-way; others might require a request-reply pattern
  • It is analogous to the element in WSDL

To create a service contract you define an interface with related methods representative of a collection of service operations, and then decorate the interface with the ServiceContract Attribute to indicate it is a service contract. Methods in the interface that should be included in the service contract are decorated with the OperationContract Attribute.

  1. Message Contract

Message is the packet of data which contains important information. WCF uses these messages to transfer information from Source to destination. Message contract can be applied to type using MessageContract attribute. Custom Header and Body can be included to message using ‘MessageHeader’ and ‘MessageBodyMember‘atttribute. Let us see the sample message contract definition.

WCF uses SOAP(Simple Object Access Protocol) Message format for communication. SOAP message contain Envelope, Header and Body.SOAP envelope contails name, namespace,header and body element. SOAP Hear contain important information which are not directly related to message. SOAP body contains information which is used by the target.

Message Pattern

It describes how the programs will exchange message each other. There are three way of communication between source and destination

  1. Simplex – It is one way communication. Source will send message to target, but target will not respond to the message.
  2. Request/Replay – It is two way communications, when source send message to the target, it will resend response message to the source. But at a time only one can send a message
  3. Duplex – It is two way communication, both source and target can send and receive message simultaniouly.

4. Fault Contract

Service that we develop might get error in come case. This error should be reported to the client in proper manner. Basically when we develop managed application or service, we will handle the exception using try- catch block. But these exceptions handlings are technology specific.

WCF Client

WCF client is a client application creates to expose the service operations as method. Any application can host a WCF client, including an application that host a service. Therefore it is possible to create a service that includes WCF clients of other services.

A client application is a managed application that uses a WCF client to communicate with another application. To create a client application for a WCF service requires the following steps:

  1. Get the Proxy class and service end point information

Using SvcUtil.exe we can create proxy class for the service and configuration information for endpoints. Example type the following sentence in the Visual studio command prompt, this will generate the class file and configuration file which contain information about the endpoints.

  1. Call operations.

Add this class files in the client application. Then create the object for this class and invoke the service operation. Configuration information we got from the above step has to be added to the client application configuration file. When the client application calls the first operation, WCF automatically opens the underlying channel. This underlying channel is closed, when the object is recycled.

//Creating the proxy on client side
MyCalculatorServiceProxy.MyServiceProxy proxy 
= new MyCalculatorServiceProxy.MyServiceProxy();
 Console.WriteLine("Counter: " + proxy.MyMethod());
  1. Close the WCF client object.

After using the object created in the above steps, we have to dispose the object. Channel will be closed with the service, when the object is cleared.

WCF Architecture



Contracts layer are next to that of Application layer. Developer will directly use this contract to develop the service. We are also going to do the same now. Let us see briefly what these contracts will do for us and we will also know that WCF is working on message system.

Service contracts

– Describe about the operation that service can provide. Example, Service provided to know the temperature of the city based on the zip code, this service we call as Service contract. It will be created using Service and Operational Contract attribute.

Data contract

– It describes the custom data type which is exposed to the client. This defines the data types, are passed to and from service. Data types like int, string are identified by the client because it is already mention in XML schema definition language document, but custom created class or datatype cannot be identified by the client e.g. Employee data type. By using DataContract we can make client aware that we are using Employee data type for returning or passing parameter to the method.

Message Contract

– Default SOAP message format is provided by the WCF runtime for communication between Client and service. If it is not meeting your requirements then we can create our own message format. This can be achieved by using Message Contract attribute.

Policies and Binding

– Specify conditions required to communicate with a service e.g security requirement to communicate with service, protocol and encoding used for binding.

Service Runtime

– It contains the behaviors that occur during runtime of service.

  • Throttling Behavior- Controls how many messages are processed.
  • Error Behavior – Specifies what occurs, when internal error occurs on the service.
  • Metadata Behavior – Tells how and whether metadata is available to outside world.
  • Instance Behavior – Specifies how many instance of the service has to be created while running.
  • Transaction Behavior – Enables the rollback of transacted operations if a failure occurs.
  • Dispatch Behavior – Controls how a message is processed by the WCF Infrastructure.


– Messaging layer is composed of channels. A channel is a component that processes a message in some way, for example, by authenticating a message. A set of channels is also known as a channel stack. Channels are the core abstraction for sending message to and receiving message from an Endpoint. Broadly we can categories channels as

  • Transport Channels

Handles sending and receiving message from network. Protocols like HTTP, TCP, name pipes and MSMQ.

  • Protocol Channels

Implements SOAP based protocol by processing and possibly modifying message. E.g. WS-Security and WS-Reliability.

Activation and Hosting

– Services can be hosted or executed, so that it will be available to everyone accessing from the client. WCF service can be hosted by following mechanism

  • IIS

Internet information Service provides number of advantages if a Service uses Http as protocol. It does not require Host code to activate the service, it automatically activates service code.

  • Windows Activation Service

(WAS) is the new process activation mechanism that ships with IIS 7.0. In addition to HTTP based communication, WCF can also use WAS to provide message-based activation over other protocols, such as TCP and named pipes.

  • Self-Hosting

WCF service can be self hosted as console application, Win Forms or WPF application with graphical UI.

  • Windows Service

WCF can also be hosted as a Windows Service, so that it is under control of the Service Control Manager (SCM).

WCF Hosting

In this part of the tutorial we are going to see the four different way of hosting the WCF service. WCF service cannot exist on its own; it has to be hosted in windows process called as host process. Single host process can host multiple servers and same service type can be hosted in multiple host process. As we discussed there are mainly four different way of hosting the WCF service.

  1. IIS Hosting
  2. Self-Hosting
  3. Windows Service
  4. Windows Activation Service
Feature Self-Hosting IIS Hosting WAS Hosting
Executable Process/ App Domain Yes Yes Yes
Configuration App.config Web.config Web.config
Activation Manual at startup Message-based Message-based
Idle-Time Management No Yes Yes
Health Monitoring No Yes Yes
Process Recycling No Yes Yes
Management Tools No Yes Yes