Thursday, March 16, 2017

REST Architecture Constraints

In this post, we will understand what is the REST? and What are the architecture Constraints for the REST

What is REST?

Representational State Transfer (REST) is a software architecture style consisting of guidelines and best practices for creating industry standard web services

What are the Constraints?

  • Uniform Interface
  • Statelessness (State to handle the request is contained within the request itself)
  • Client-Server
  • Cache
  • Layered System
  • Code on Demand


Uniform Interface
     Client should easily understand the interface, it should be uniform for all the clients(web,mobile)
Example
http://domain/api/HotelBooking/Book


Statelessness
Every Request to the server should pass all the required information. REST primarily uses HTTP Protocol which support the statelessness

Client-Server
    Maintain the clear separation between client and server. client and Server should have different code and changing one place shouldn't affect the other end

Cache
    Provide an ability to cache the response in the client side or if any middleware

Layered System
   It supports the multi layer architecture and it should allow to add/remove any additional layer without breaking the functionality

Code on Demand
    Allow independent code updates on both client(web browser upgrade) and server side(Database layer change)





Monday, April 22, 2013

Design Pattern in Microsoft.NET



Design Pattern
ASP.NET Example or Implementation
Adaptor and Bridge Pattern
List box,  Data Grid  and Tree View
Abstract Factory
Paint Graphics
Iterator and Composite Pattern
Enumeration interface
Singleton
Exceptions
Façade Pattern
ADO.NET Database connections
Proxy Pattern
 C# Timer



Creational
  • Abstract Factory Pattern
    • Provide an interface to create and return one of several families of related objects
      • E.g., FFT (Fast Fourier Transform )
  • Builder Pattern
    • Separate the construction the complex object from its representing so that several different representations can be created, depending on the needs of programs
  • Prototype Pattern
    • Start with an instantiated class and copies or clones it to make a new instances. These instance can then be further tailored using their public methods
  • Singleton
    • It's a class of which there can be no more than once instance. It provide a single global point  of access to that instance
Structural
  • Adapter Pattern
    • It can be used to make one class interface match another to make programming easier
  • Composite Pattern
    • It's a composition of objects, each of which may be either simple or itself a composite object
  • Proxy Pattern
    • It's frequently a simple object take place of a more complex object that may be invoked later
  • Flyweight Pattern
    • It's a pattern for sharing objects, where each instance does not contains it's own state but stores it externally
  • Façade Pattern
    • It used to make single class represent the entire subsystem
  • Bridge Pattern
    • It separates an object's interface from it's implementation, so you can vary them separately
  • Decorator Pattern
    • It used to add responsibilities to objects dynamically
Behavioral
  • Chain of Responsibility Pattern
    •  It allows a decoupling between objects by passing a request from one object to the next in a chain until the request is recognized.
  • Command Pattern
    • It utilizes simple objects to represent execution of software commands and allows you to support logging and undoable operations.  
  • Interpreter Pattern
    •  It provides a definition of how to include language elements in a program.
  • Iterator pattern
    • It defines how communication between objects can be simplified by using a separate object to keep all objects from having to know about each other.
  • Memento Pattern
    • It defines how you might save the contents of an instance of a class and restore it later.
  • Observer Pattern
    • It  defines the way a number of objects can be notified of  a change
  • State Pattern
    • It  allows an object to modify its behavior when its internal state changes.
  • Strategy Pattern
    • It encapsulates an algorithm inside an class
  • Template Method Pattern
    • It provides an abstract definition of an algorithm.
  • Visitor Pattern
    • It adds polymorphic functions to a class noninvasively



The above information is a good summary point to define and describe each design patterns. we could keep this as a reference point for technical interview.


Reference:

This note is picked from the following book. any body wants to learn in details
please check out this link
http://www.amazon.com/Design-Patterns-C-Software/dp/0321718933


 

Monday, December 24, 2012

Read Private Type using Visual Studio Unit Testing in C#

small things can make a different

I want to read my class  private values to verify the unit testing using MS unit test.

Here is the sample code

Created the sample class named NumberChecker, it contains two private property and public method.
The method going to check, the passed number is greater than zero or not. based on that it's going to pass a different message back the client.


namespace PrivateTypeDemo
{
    public class NumberChecker
    {
        private const string Validmessage = "The Number is Greater than Zero";
        private const string DefaultMessage = "The Number is Zero or Less than Zero";
        public string ValidateNumber(int number)
        {
            return number > 0 ? Validmessage : DefaultMessage;
        }
    }
}
Here is the console application which consumes the library

namespace PrivateTypeDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            var numcheck = new NumberChecker();
            Console.WriteLine("Please Enter your Number");
            var  number = Convert.ToInt32(Console.ReadLine());
            var result = numcheck.ValidateNumber(number);
            Console.WriteLine(result);
 
 
        }
    }
}

Unit Test for the NumberCheck class
 [TestClass]
    public class NumberCheckerTest
    {
        [TestMethod]
        public void ValidateNumberTest()
        {
            var target = new NumberChecker();
            const int number = 15;
            var privateType = new PrivateType(target.GetType());
            var expected = privateType.GetStaticFieldOrProperty("Validmessage");
            string actual = target.ValidateNumber(number);
            Assert.AreEqual(expected, actual);
        }
        [TestMethod]
        public void ValidateNumber2Test()
        {
            var target = new NumberChecker();
            const int number = -5;
            var privateType = new PrivateType(target.GetType());
            var expected = privateType.GetStaticFieldOrProperty("DefaultMessage");
            string actual = target.ValidateNumber(number);
            Assert.AreEqual(expected, actual);
        }
        [TestMethod]
        public void NumberCheckerConstructorTest()
        {
            var target = new NumberChecker();
            Assert.IsNotNull(target);
        }
    }
The below lines does the magic of accessing the private type of the classes.This class is shipped part of the 
Microsoft.VisualStudio.TestTools.UnitTesting Assembly  which support this functionality in unit Testing

var privateType = new PrivateType(target.GetType());
var expected = privateType.GetStaticFieldOrProperty("DefaultMessage");

Here i am reading the value of DefaultMessage through the GetStaticFieldOrProperty Method in the PrivateType class
To Learn More about this,
PrivateType

Monday, October 29, 2012

Performance Measurement Tools

List of Performance Measurement Tools in Microsoft .NET


  • Visual Studio Sampling Profiler
              http://msdn.microsoft.com/en-us/library/ms242753.aspx
              http://msdn.microsoft.com/en-us/library/ms182372.aspx
  • Visual Studio Instrumentation Profiler
              http://dotnet.dzone.com/articles/profiling-application-visual-0
  • Visual Studio Allocation Profiler
              http://dotnet.dzone.com/articles/profiling-application-visual-1
  • Visual Studio Concurrency Profiler
              http://www.youtube.com/watch?v=Bofk3ecJOtk
              http://msdn.microsoft.com/en-us/magazine/ee336027.aspx
  • CLR Profiler
              http://msdn.microsoft.com/en-us/library/ff650691.aspx
  • Performance Monitoring
               http://msdn.microsoft.com/en-us/library/aa645516(v=vs.71).aspx
  • PerfView
              http://channel9.msdn.com/Series/PerfView-Tutorial
  • Windows Performance Toolkit
              http://msdn.microsoft.com/en-us/performance/cc825801.aspx
  • Process Monitor
             http://en.wikipedia.org/wiki/Process_Monitor
  • Entity Framework Profiler
            http://www.hibernatingrhinos.com/products/efprof
  • ANTS Memory Profiler
              http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/
  • .NET Memory Profiler
              http://memprofiler.com/


Sunday, October 21, 2012

Enable Wifi without the Wireless Router for Home Usage

Recently I bought a Samsung mobile phone Y Series. To activate the Samsung app store and Google play store, it's asking me to connect via  WiFi . But i don't have a WiFi router with me. but i have 10 Mbps Airtel Broadband Connection











Now i have two options


  • I have to activate Air tel 3 G in my mobile to access all the Samsung apps
  • I need to buy the WiFi Router , so i could use my existing broad band connection
I don't want to spend extra money to activate 3G also WiFi router is extra overhead for me

I found this useful software for Windows 7, it will act as Virtual WiFi Router

Download the WiFi Router from here Download

 You can create a WiFi hotspot for WiFi Reverse Tethering for wifi supported mobiles and other wifi enabled computer to create a network and to share internet. Convert your PC into a WiFi hot spot for free.

Follow this instructions to configure it for the first time


Now enjoy the same speed in your mobile and save money

Tuesday, October 16, 2012

SOA Design Patterns

List of SOA(Service Orientated Architecture Link) Patterns for distributed system development

Foundation Structure Pattern

  • Service Host Pattern
  • Active Service Pattern
  • Transactional Service Pattern
  • Workflodize Pattern
  • Edge Component Pattern
Patterns for Performance, Scalability
  • Decoupled Invocation Pattern
  • Parallel Pipelines Pattern
  • Gridable Service Pattern
  • Service Instance Pattern
  • Virtual Endpoint Pattern
  • Service Watchdog Pattern
Security and Manageability
  • Secured Message Pattern
  • Secured Infrastructure Pattern
  • Service Firewall Pattern
  • Identity Provider Pattern
  • Service Monitor Pattern
Message Exchange Pattern
  • Request / Reply Pattern
  • Request / Reaction Pattern
  • Inversion of communication Pattern
  • Saga Pattern
Service Consumer Pattern
  • Reservation Pattern
  • Composite Front End Pattern
  • Client /Server / Service Pattern

Service Integration Pattern
  • Service Bus Pattern
  • Orchestration Pattern
  • Aggregated Reporting Pattern

Service Anti Pattern
  • Knot anti-pattern
  • Nano service anti-pattern
  • Transactional Integration anti-pattern

Reference




Read Event Log Information using LINQ PAD


Anyone tried the LINQ PAD. I found this is very useful to execute for query any short of information from different sources like database, xml, event logs, iis logs with the minimal code

In this blog, i am going to show a example, how we could pull the summary of the events using the LINQ PAD

Link to download LINQ PAD http://www.linqpad.net/


LINQPad is a free software utility for Microsoft .NET to interactively query SQL databases and other data sources such as OData or WCF Data Services using LINQ. LINQPad supports the following LINQ dialects:
  • LINQ to Objects
  • LINQ to SQL
  • Entity Framework
  • LINQ to XML
It also supports writing queries in SQL as well.

Download and install the LINQ PAD. Open the LINQ PAD and select a new query and select the language as C# Program

Code



void Main()
{
var serverList = new List
  {
  //List of Servers Name
  };
var eventCollection = new Dictionary();

int count = 0;
foreach (var list in serverList)
{
var eventLog = new EventLog(EVENTLOGNAME, list, SOURCENAME);
        foreach (EventLogEntry logEntry in eventLog.Entries)
        {
if (logEntry.TimeGenerated  >=  DateTime.Today)
{
if (eventCollection.ContainsKey(logEntry.InstanceId))
{
eventCollection[logEntry.InstanceId]++;
}
else
{
eventCollection.Add(logEntry.InstanceId, 1);
}
}

        }
Console.WriteLine("Summary of Server " + list);
foreach (var logs in eventCollection)
{
Console.WriteLine(logs.Key + "  " + logs.Value);
}
eventCollection.Clear();
}

}

// Define other methods and classes here


Sample Output

Summary of the Server "ServerName1"
Event ID   Number Of Times
100            7
106            15

Summary of the Server "ServerName2"
Event ID   Number Of Times
100            70
106            8