<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8738129253178686232</id><updated>2024-09-09T19:20:50.282-07:00</updated><title type='text'>Syed Nisar Bukhari</title><subtitle type='html'>Syed Nisar Bukhari is working as a Scientist in National Institute of Electronics and Information technology (NIELIT) Srinagar/Jammu (Department of Electronics and Information Technology,Ministry of Communications and Information Technology, Government of India).</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://syednisarbukhari.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://syednisarbukhari.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Syed Nisar Bukhari</name><uri>http://www.blogger.com/profile/13557733006614710346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHsq903LQfB_RB8a3dDw_BqfpGauwOV2VDH6f-72JrwfY6UpVfa4Z-hfYccTSCrMxSxBZgdFU1QrpuzY38mFY2F6GkyE7i4RWWBWurPn06hy4WDC0E6M2A_uNau_qv1g/s121/m.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>14</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8738129253178686232.post-9985058009520655</id><published>2013-01-14T07:37:00.001-08:00</published><updated>2013-01-14T07:37:52.063-08:00</updated><title type='text'>Socket Program in c-sharp</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;b&gt;Client and server implementation using socket programming:&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Socket -- an End-Point of To and From (Bidirectional) communication 
link between two programs (Server Program and Client Program ) running 
on the same network.&lt;br /&gt;
Details:Two programs are needed for communicating a socket 
application in C# using&lt;b&gt; &lt;/b&gt;TCP/IP Communication protocol. &lt;br /&gt;
A Server Socket Program ( Server ) and a Client 
Socket Program ( Client ) .
&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
   Server Socket Program running on a computer has a socket bound to a Port Number on the same computer and listening to the 
client&#39;s incoming requests.&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&amp;nbsp;Client Socket Program have to know the IP Address ( Hostname ) of 
the computer that the C# Server Socket Program resides.&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
   Once the connection is established between Server 
and Client , they can communicate (read or write ) through their own 
sockets.&lt;/div&gt;
Start the server and then make a connection to server by invoking the client..&lt;br /&gt;
Both client and server are on the same machine.&lt;br /&gt;
Two types of communication protocol can beused for Socket Programming in C#:&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;b&gt;&amp;nbsp;TCP/IP&lt;/b&gt;   ( Transmission Control Protocol/Internet protocol ) Communication&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;b&gt;UDP/IP&lt;/b&gt;   ( User Datagram Protocol/Internet protocol ) Communication . &lt;/li&gt;
&lt;/ol&gt;
&amp;nbsp;Server Implementation:Below is the source code for server implementation&lt;br /&gt;
&lt;br /&gt;
using System.Net.Sockets:&lt;br /&gt;
namespace Server&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; class Program&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static void Main(string[] args)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TcpListener serverSocket = new TcpListener(8888);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int requestCount = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TcpClient clientSocket = default(TcpClient);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; serverSocket.Start();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(&quot;...Server Started&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; clientSocket = serverSocket.AcceptTcpClient();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(&quot; ... Accept connection from client&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; requestCount = 0;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while ((true))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; requestCount = requestCount + 1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NetworkStream networkStream = clientSocket.GetStream();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; byte[] bytesFrom = new byte[10025];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf(&quot;$&quot;));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(&quot; ..... Data from client - &quot; + dataFromClient);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string serverResponse = &quot;Server response &quot; + Convert.ToString(requestCount);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Byte[] sendBytes = Encoding.ASCII.GetBytes(serverResponse);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; networkStream.Write(sendBytes, 0, sendBytes.Length);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; networkStream.Flush();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(&quot; ... &quot; + serverResponse);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; catch (Exception ex)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(ex.ToString());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; clientSocket.Close();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; serverSocket.Stop();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(&quot; ....exit&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.ReadLine();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;
&lt;br /&gt;
Client Implementation:Drag textbox,label and button control and drop them on form.In the code behind paste the following code&lt;br /&gt;
using System.Net.Sockets;&lt;br /&gt;namespace Client&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public partial class Form1 : Form&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public Form1()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InitializeComponent();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private void Form1_Load(object sender, EventArgs e)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; msg(&quot;Client Started&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; clientSocket.Connect(&quot;127.0.0.1&quot;, 8888);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; label1.Text = &quot;Client Socket Program - Server Connected ...&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void msg(string mesg)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; textBox1.Text = textBox1.Text + Environment.NewLine + &quot; --&amp;gt; &quot; + mesg;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private void button1_Click_1(object sender, EventArgs e)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NetworkStream serverStream = clientSocket.GetStream();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; byte[] outStream = System.Text.Encoding.ASCII.GetBytes(&quot;Message from Client$&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; serverStream.Write(outStream, 0, outStream.Length);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; serverStream.Flush();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; byte[] inStream = new byte[10025];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; serverStream.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string returndata = System.Text.Encoding.ASCII.GetString(inStream);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; msg(&quot;Data from Server : &quot; + returndata);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;Images:&lt;br /&gt;
1. Form Design:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE0z-cS6h1DQQEQusdVa3O5V2-oZDacPJV6ZiRbtTkYw-GoV0B36eb9wYtj9t47Q0l_8dTeB5rFe62ShlnR8LTAX0G3CEZu5SHe_7EwdX8Wide0Fae7xZ-HTbV1BOQKNSF1dVyyWyTm7A4/s1600/form.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;316&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE0z-cS6h1DQQEQusdVa3O5V2-oZDacPJV6ZiRbtTkYw-GoV0B36eb9wYtj9t47Q0l_8dTeB5rFe62ShlnR8LTAX0G3CEZu5SHe_7EwdX8Wide0Fae7xZ-HTbV1BOQKNSF1dVyyWyTm7A4/s320/form.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
2.&amp;nbsp; Client server snapshot (running mode)&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFXBUmwn6TWeYAIalpv1bEcQEj9K6_uXrb9Ch_q2J4scmJtwOPfR6vbilliJm3bTFwB2merDSzM_kI5YJP9C3fr9qyS8HabKRI-Me6fSi33-h0rvC0yJ5sh6dNyIo40CO1wU7-vIOSZyMB/s1600/cs.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;248&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFXBUmwn6TWeYAIalpv1bEcQEj9K6_uXrb9Ch_q2J4scmJtwOPfR6vbilliJm3bTFwB2merDSzM_kI5YJP9C3fr9qyS8HabKRI-Me6fSi33-h0rvC0yJ5sh6dNyIo40CO1wU7-vIOSZyMB/s640/cs.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Enjoy coding!!!!!&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://syednisarbukhari.blogspot.com/feeds/9985058009520655/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8738129253178686232/9985058009520655' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/9985058009520655'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/9985058009520655'/><link rel='alternate' type='text/html' href='http://syednisarbukhari.blogspot.com/2013/01/socket-program-in-c-sharp.html' title='Socket Program in c-sharp'/><author><name>Syed Nisar Bukhari</name><uri>http://www.blogger.com/profile/13557733006614710346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHsq903LQfB_RB8a3dDw_BqfpGauwOV2VDH6f-72JrwfY6UpVfa4Z-hfYccTSCrMxSxBZgdFU1QrpuzY38mFY2F6GkyE7i4RWWBWurPn06hy4WDC0E6M2A_uNau_qv1g/s121/m.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE0z-cS6h1DQQEQusdVa3O5V2-oZDacPJV6ZiRbtTkYw-GoV0B36eb9wYtj9t47Q0l_8dTeB5rFe62ShlnR8LTAX0G3CEZu5SHe_7EwdX8Wide0Fae7xZ-HTbV1BOQKNSF1dVyyWyTm7A4/s72-c/form.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8738129253178686232.post-1730158531867890882</id><published>2013-01-11T03:09:00.000-08:00</published><updated>2013-01-11T03:09:00.286-08:00</updated><title type='text'>String Searching:Knuth-Morris-Pratt Algorithm   </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-size: x-large;&quot;&gt;&lt;span style=&quot;font-family: Blackadder ITC;&quot;&gt;K&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;nuth, Morris and Pratt discovered first linear time string-matching algorithm 
by following a tight analysis of the na&lt;span style=&quot;font-size: medium;&quot;&gt;i&lt;/span&gt;ve algorithm.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h1&gt;
The Problem&lt;span style=&quot;font-size: medium;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;
&lt;h1&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;The problem that we are trying to deal with, is of course, exactly the same as the naive problem. Given some pattern &lt;em&gt;p, &lt;/em&gt;does it exist in some string &lt;em&gt;s&lt;/em&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/h1&gt;
&lt;br /&gt;
&lt;h1&gt;
Example&lt;/h1&gt;
Let’s say we have the following string and pattern,&lt;br /&gt;

&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;em&gt;s&lt;/em&gt; = “abra abracad abracadabra”&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;em&gt;p&lt;/em&gt; = “abracadabra”&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
Now if this were the naive approach, we would need quite a lot of 
comparisons – 154 to be exact! Before we start, it would be best to note
 that we’ll be using zero-based arrays for this. So since &lt;em&gt;s&lt;/em&gt; is really an array of characters, then s[0] would be referencing to the character ‘a’, and p[2] would be the character ‘r’.&lt;br /&gt;

We also need two more variables, name &lt;em&gt;i&lt;/em&gt; and &lt;em&gt;j&lt;/em&gt;. Here &lt;em&gt;i&lt;/em&gt; will be the indexes into &lt;em&gt;p&lt;/em&gt;, and &lt;em&gt;j&lt;/em&gt; will be the indexes into &lt;em&gt;s&lt;/em&gt;. Now, let’s start off with the first match-up,&lt;br /&gt;

&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;j = 012345678901234567890123&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;s = abra abracad abracadabra&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;p = abracadabra&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;i = 01234567890&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
Here we can see that p[0] and s[0] are equal, but then we reach s[4] 
and p[4]. Here we have a space character and the character ‘c’. Clearly 
they don’t match up. So what we need to do now is slide the pattern 
along. But this is the part that isn’t like the naive approach. Instead 
of sliding the pattern across by one, we slide the pattern across by a 
special value. You see, behind the scenes there is in fact a table &lt;em&gt;T&lt;/em&gt;. We’ll get to this later, but for now all you need to know is that we slide the pattern across to j=3 and reset i=0.&lt;br /&gt;

We get the value of j=3 from &lt;span style=&quot;font-family: Consolas;&quot;&gt;j = j+i-T[i] = 0+4–1 = 3&lt;/span&gt;. In this equation, j=0 because if you remember, &lt;em&gt;j&lt;/em&gt; will be the starting point. i=4 because this is the point of failure – the position in &lt;em&gt;p&lt;/em&gt; where we found our mismatch. And T[i]=1 because, well we’ll come to this later, for now take my word for it.&lt;br /&gt;

With these new values, we can now slide the pattern along:&lt;br /&gt;

&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;j = 012345678901234567890123&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;s = abra abracad abracadabra&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;p =&amp;nbsp;&amp;nbsp;&amp;nbsp; abracadabra&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;i =&amp;nbsp;&amp;nbsp;&amp;nbsp; 01234567890&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
Now we see that we find a mismatch at s[4] and p[1]. This is we slide
 the pattern along to j=4. If you wish to know why, it’s because j=3 and
 i=1 (which should be obvious) and T[i]=0, sticking them into that 
equation gives&lt;br /&gt;

&lt;span style=&quot;font-family: Consolas;&quot;&gt;j = j+i-T[i] = 3+1–0 = 4&lt;/span&gt;&lt;br /&gt;

Instead of drawing out all of the possible combinations, let’s jump ahead to:&lt;br /&gt;

&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;j = 012345678901234567890123&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;s = abra abracad abracadabra&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;p =&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; abracadabra&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;i =&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01234567890&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
Now this should be better to show off why this algorithm is better 
than the naive approach. Here we compare the characters again, and fail 
at s[12] and p[7]. But because of the way the algorithm works, we slide 
the pattern across by a huge amount,&lt;br /&gt;

&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;j = 012345678901234567890123&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;s = abra abracad abracadabra&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;p =&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; abracadabra&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;i =&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01234567890&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
I have actually skipped one step here, where we compare s[12] and 
p[0]. But as you can see the next step succeeds, and we find a match at 
j=13!&lt;br /&gt;

What’s more amazing is that we have only made 28 comparisons! A lot better than the naive approaches 154&lt;br /&gt;
&lt;h1&gt;
So what’s this &lt;em&gt;T&lt;/em&gt; table then!?&lt;/h1&gt;
Well we had to get to this part sooner or later, so we may as well 
explain this now. Besides the obvious as to why KMP differs from the 
naive approach, there is another reason. You see, the KMP algorithm has a
 pre-processing stage, that is, that it does (or rather creates) 
something from the given pattern before the algorithm even starts 
searching for the pattern.&lt;br /&gt;

This pre-processing stage is the &lt;em&gt;T&lt;/em&gt; table, and this is what it looked like for the above pattern:&lt;br /&gt;

&lt;table border=&quot;0&quot; cellpadding=&quot;2&quot; cellspacing=&quot;0&quot; style=&quot;width: 560px;&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;73&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;i&lt;/span&gt;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;43&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;0&lt;/span&gt;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;47&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;1&lt;/span&gt;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;46&quot;&gt;2&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;45&quot;&gt;3&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;45&quot;&gt;4&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;44&quot;&gt;5&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;43&quot;&gt;6&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;43&quot;&gt;7&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;42&quot;&gt;8&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;44&quot;&gt;9&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;43&quot;&gt;10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;81&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;p[i]&lt;/span&gt;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;48&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;a&lt;/span&gt;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;52&quot;&gt;b&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;50&quot;&gt;r&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;49&quot;&gt;a&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;49&quot;&gt;c&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;47&quot;&gt;a&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;46&quot;&gt;d&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;46&quot;&gt;a&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;44&quot;&gt;b&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;46&quot;&gt;r&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;45&quot;&gt;a&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;84&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;T[i]&lt;/span&gt;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;50&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;-1&lt;/span&gt;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;54&quot;&gt;0&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;52&quot;&gt;0&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;50&quot;&gt;0&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;50&quot;&gt;1&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;48&quot;&gt;0&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;47&quot;&gt;1&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;47&quot;&gt;0&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;45&quot;&gt;1&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;47&quot;&gt;2&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;45&quot;&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
Now this may look rather complex, but it really isn’t that hard to 
understand. First things first, the values of T[0] and T[1] are &lt;strong&gt;always&lt;/strong&gt; fixed, they never change. Therefore, T[0]=-1 and T[1]=0 &lt;strong&gt;all of the time&lt;/strong&gt;.
 This means that the main program begins from i=2. There is also another
 variable that we need to use, and we shall call this variable &lt;em&gt;sub&lt;/em&gt;, with initial value of sub=0.&lt;br /&gt;

And here is some pseudo-code to populate the &lt;em&gt;T&lt;/em&gt; table.&lt;br /&gt;

Remember. i=2 and sub=0.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt; &lt;span style=&quot;color: green;&quot;&gt;//whilst i doesn’t exceed the length of p&lt;br /&gt;
&lt;/span&gt;001&amp;nbsp;&amp;nbsp;&amp;nbsp; WHILE (i &amp;lt; length_of_p) DO:&lt;br /&gt;
&lt;span style=&quot;color: green;&quot;&gt;//we have a continued substring in p from the start of p&lt;br /&gt;
&lt;/span&gt;002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF (p[i-1] == p[sub]) THEN:&lt;br /&gt;
003&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sub=sub+1&lt;br /&gt;
004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; T[i] = sub&lt;br /&gt;
005&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i=i+1&lt;br /&gt;
&lt;span style=&quot;color: green;&quot;&gt;//if the substring stops, fall back to the start&lt;br /&gt;
&lt;/span&gt;006&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSE IF (sub &amp;gt; 0) THEN:&lt;br /&gt;
007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sub = T[sub]&lt;br /&gt;
&lt;span style=&quot;color: green;&quot;&gt;//we weren’t in a substring, so use default value&lt;br /&gt;
&lt;/span&gt;008&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSE&lt;br /&gt;
009&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; T[i] = 0&lt;br /&gt;
010&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i=i+1&lt;br /&gt;
011&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ENDIF&lt;br /&gt;
012&amp;nbsp;&amp;nbsp;&amp;nbsp; ENDWHILE&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;I am not going to walk through the whole process. So let’s start at i=7 and sub=0.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;Starting
 at line 002 we test to see if p[6] is equal to p[0]. Since ‘d’ is not 
equal to ‘a’ then we move onto the next statement. Here &lt;em&gt;sub&lt;/em&gt; is not greater than 0, so we move onto the final statement. With this we make T[7]=0 and increment &lt;em&gt;i&lt;/em&gt; to i=8.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;Now,
 starting back at the first IF statement, we test to see if p[7] equals 
p[0], and by surprise it does since ‘a’ = ‘a’. This means that we 
increment &lt;em&gt;sub&lt;/em&gt; to sub=1, we make T[8]=1 and increment &lt;em&gt;i&lt;/em&gt; again to i=9.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;Moving
 on again, we test p[8] to p[1] this time, since sub=1. This time we 
succeed again since ‘b’ = ‘b’. Therefore we increment &lt;em&gt;sub&lt;/em&gt; and &lt;em&gt;i&lt;/em&gt; to sub=2 and i=10. And obviously we set T[9]=2.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;I’ll leave T[10] up to you, as well as the ones I missed, but it should be obvious by now how this works.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;If
 you’re pondering why we need a –1 at the beginning, it’s so that if we 
fail on the very first character, we simply move along to the next 
character in the main string. As if this were just 0, we would not slide
 the pattern along.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;

&lt;br /&gt;
&lt;h1&gt;
The Main Algorithm&lt;/h1&gt;
&lt;span style=&quot;font-family: Arial;&quot;&gt;Now that we understand how the T table is created, the main algorithm for the KMP is very simple.&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;font-family: Arial;&quot;&gt;First of all, we have to remember that we have &lt;em&gt;s&lt;/em&gt; which is the string to search through, and &lt;em&gt;p&lt;/em&gt; which is the pattern to find. Then of course we have &lt;em&gt;i&lt;/em&gt; which is the current index into &lt;em&gt;p,&lt;/em&gt; and &lt;em&gt;j&lt;/em&gt; which is the current index into &lt;em&gt;s&lt;/em&gt;.&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;font-family: Arial;&quot;&gt;And here is the pseudo-code for the KMP,&lt;/span&gt;&lt;br /&gt;

&lt;blockquote&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;//while we don’t exceed the length of string s&lt;br /&gt;
&lt;/span&gt;001&amp;nbsp;&amp;nbsp;&amp;nbsp; WHILE (j+i &amp;lt; length_of_s) DO:&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;//character matching for parallel characters&lt;br /&gt;
&lt;/span&gt;002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF (p[i] == s[j+i]) THEN:&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;//reached the end of the pattern, match found.&lt;br /&gt;
&lt;/span&gt;003&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF (i == length_of_p –1) THEN:&lt;br /&gt;
004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RETURN j&lt;br /&gt;
005&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ENDIF&lt;br /&gt;
006&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i=i+1&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;//parallel characters don’t match, slide pattern along&lt;br /&gt;
&lt;/span&gt;007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSE&lt;br /&gt;
008&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; j=j+i-T[i]&lt;br /&gt;
009&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF (T[i] &amp;gt; –1)&lt;br /&gt;
010&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = T[i]&lt;br /&gt;
011&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSE&lt;br /&gt;
012&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = 0&lt;br /&gt;
013&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ENDIF&lt;br /&gt;
014&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ENDIF&lt;br /&gt;
015&amp;nbsp;&amp;nbsp;&amp;nbsp; ENDWHILE&lt;br /&gt;
016&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;//we reached the end of the string, match not found&lt;br /&gt;
&lt;/span&gt;017&amp;nbsp;&amp;nbsp;&amp;nbsp; RETURN length_of_s&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;font-family: Arial;&quot;&gt;This may look horribly daunting at 
first, but it really is very simple. Line 002 is simple the character by
 character matching process, matching parallel characters from the 
pattern and the string. If we reach the end of the pattern, return the 
position is &lt;em&gt;s&lt;/em&gt; where is it (line 004), otherwise, we still have a
 character by character match, so increment to the next character in the
 pattern for testing (line 006).&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;font-family: Arial;&quot;&gt;The real fun beginnings inside of 
the ELSE statement. Now line 008 should look very familiar. Yep, we came
 across it earlier. This line simply sets the new start position in 
string &lt;em&gt;s&lt;/em&gt; where we start matching the pattern against it again, and of course, you now know what the T table looks like.&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;font-family: Arial;&quot;&gt;The next part, from lines 009 to 013
 are a little more tricky to grasp. Basically, when we slide the pattern
 along, we don’t always need to re-test some of the characters from the 
pattern. This is because of the way the T table works, and it’s called 
backtracking. For example, if we have the following &lt;em&gt;s&lt;/em&gt; and &lt;em&gt;p&lt;/em&gt;:&lt;/span&gt;&lt;br /&gt;

&lt;ul&gt;
&lt;li&gt;j = 01234567890&lt;/li&gt;
&lt;li&gt;s = abcdab abcd&lt;/li&gt;
&lt;li&gt;p = abcdabd&lt;/li&gt;
&lt;li&gt;i = 0123456&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-family: Arial;&quot;&gt;We can see that the initial start 
point will fail at s[6] and p[6]. Now because of where is failed, T[6] 
is actually equal to the value 2. Therefore, we slide the pattern along 
to j = j + i + T[i] = 0 + 6 – 2 = 4:&lt;/span&gt;&lt;br /&gt;

&lt;ul&gt;
&lt;li&gt;j = 01234567890&lt;/li&gt;
&lt;li&gt;s = abcdab abcd&lt;/li&gt;
&lt;li&gt;p =&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; abcdabd&lt;/li&gt;
&lt;li&gt;i =&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0123456&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-family: Arial;&quot;&gt;But wait a second, we don’t need to compare the first 2 characters of &lt;em&gt;p&lt;/em&gt;
 again, because we know that they already match up due to the T table. 
Therefore, like is says at line 010, we start at index i = T[6] = 2. 
This saves us a lot of time from doing none needed comparisons!&lt;/span&gt;&lt;br /&gt;

&lt;span style=&quot;font-family: Arial;&quot;&gt;This backtracking only works if the value at T[i] is greater than 0. Otherwise, we just start at index i=0 in the pattern.&lt;/span&gt;&lt;br /&gt;

&lt;br /&gt;

&lt;h1&gt;
The Complexity&lt;/h1&gt;
&lt;span style=&quot;font-family: Arial;&quot;&gt;So, after all of this, what is the 
complexity of the KMP algorithm? Well the best part is that both the 
pre-processing phase and the main phase run in linear time. That is, the
 construction of the T table takes O(m) time, where m is the length of 
the pattern &lt;em&gt;p&lt;/em&gt;. Then, the main program itself takes O(n) time where n is the length of the string &lt;em&gt;s&lt;/em&gt;. Therefore the&amp;nbsp; overall time complexity is O(m+n).&lt;/span&gt;&lt;br /&gt;

&lt;br /&gt;
Source:computersciencesource.wordpress.com/2011/01/03/string-searching-the-knuth-morris-pratt-algorithm/ &lt;br /&gt;
Resources
&lt;span style=&quot;font-family: Consolas;&quot;&gt;[1] &lt;/span&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;http://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;br /&gt;
[2] University of Manchester, Advanced Algorithms 1 lecture notes by David Rydeheard&lt;br /&gt;
[3] Knuth-Morris-Pratt: An Analysis by Mireille Regnier&lt;br /&gt;
[4] &lt;a href=&quot;http://badgerati.com/tutorials/knuth-morris-pratt-algorithm/&quot;&gt;Badgerati Tutorials – Knuth-Morris-Pratt Algorithm&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;

&lt;br /&gt;


&lt;div class=&quot;wpadvert&quot; style=&quot;margin: 10px auto; overflow: hidden; padding: 0; position: relative; text-align: center; width: 300px;&quot;&gt;
&lt;a href=&quot;http://en.wordpress.com/about-these-ads/&quot; rel=&quot;nofollow&quot; style=&quot;display: block; font: 9px/1 sans-serif; position: absolute; text-align: left; text-decoration: underline;&quot;&gt;About these ads&lt;/a&gt;
&lt;div id=&quot;google_ads_div_wpcom_below_post_adsafe_ad_wrapper&quot;&gt;
&lt;div id=&quot;google_ads_div_wpcom_below_post_adsafe_ad_container&quot; style=&quot;display: inline-block;&quot;&gt;


&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&lt;/span&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://syednisarbukhari.blogspot.com/feeds/1730158531867890882/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8738129253178686232/1730158531867890882' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/1730158531867890882'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/1730158531867890882'/><link rel='alternate' type='text/html' href='http://syednisarbukhari.blogspot.com/2013/01/string-searchingknuth-morris-pratt.html' title='String Searching:Knuth-Morris-Pratt Algorithm   '/><author><name>Syed Nisar Bukhari</name><uri>http://www.blogger.com/profile/13557733006614710346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHsq903LQfB_RB8a3dDw_BqfpGauwOV2VDH6f-72JrwfY6UpVfa4Z-hfYccTSCrMxSxBZgdFU1QrpuzY38mFY2F6GkyE7i4RWWBWurPn06hy4WDC0E6M2A_uNau_qv1g/s121/m.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8738129253178686232.post-9145577487583806203</id><published>2012-11-23T08:17:00.003-08:00</published><updated>2012-11-23T08:24:33.531-08:00</updated><title type='text'>How to install an assembly in the Global Assembly Cache (GAC) in .NET</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;u&gt;&amp;nbsp;&lt;/u&gt;&lt;b&gt;What is a Shared Assembly?&lt;/b&gt;&lt;br /&gt;
A shared assembly is one that is used by multiple applications on the machine. A shared assembly must have a name that is globally unique. The .NET Framework supports these naming requirements through a technique called strong names. &lt;br /&gt;
Shared assemblies must have a &quot;strong name&quot; consisting of the name of the assembly, the version, a 64 bit hash of a public key (called a ´token´) and the culture.&lt;br /&gt;
&lt;br /&gt;
To create a strong name for an assembly (that is, to generate a public/private key pair), you&#39;ll have to use another utility called sn.exe.&lt;br /&gt;
&lt;br /&gt;
In this article, we will create a Visual C# 2010 class Library component called myGAC. We will also create a key file named mykeys.key. We will sign our component with this key file and place it in &lt;br /&gt;
To create a Component we have to create a Class Library project by using Visual Studio .NET. &lt;br /&gt;
&lt;b&gt;Step 1 : Open Visual Studio .NET&lt;/b&gt;&lt;br /&gt;
Create a new Class Library project named myGAC in Visual Studio .NET or in Visual c# 2010.&lt;br /&gt;
&lt;br /&gt;
Here is the code for the component. It just includes one method which returns a string. &lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
&lt;br /&gt;
namespace myGac&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public class Class1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public string GetName()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return &quot;Syed Nisar Bukahri&quot;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 2 : Generating Cryptographic Key Pair using the tool SN.Exe&lt;/b&gt;&lt;br /&gt;
Now, we will use the SN tool to generate the cryptographic key pair.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
sn -k &quot;C:\[DirectoryToPlaceKey]\[KeyName].key&quot; &lt;br /&gt;
Next, create a directory named mykeys in C:\ so that you can easily locate the key and access the key from the visual studio command prompt. &lt;br /&gt;
Type the following at the command prompt.&lt;br /&gt;
&lt;br /&gt;
sn -k &quot;C:\mykeys\mykeys.key&quot;&lt;br /&gt;
&lt;b&gt;Step 3 : Sign the component with the key&lt;/b&gt;&lt;br /&gt;
A key is generated, but it is not yet associated with the project&#39;s assembly.&lt;br /&gt;
&amp;nbsp;To establish the association, open the AssemblyInfo.cs file in Visual Studio 2010 Solution Explorer.Add the following to the &lt;br /&gt;
list of assembly attributes that are included in this file by default when a project is created in Visual Studio .NET or in Visual Studio 2005: &lt;br /&gt;
[assembly: AssemblyKeyFile(&quot;C:\\mykeys\\mk.key&quot;)]&lt;br /&gt;
&lt;br /&gt;
Note:Add this line just below the following line&lt;br /&gt;
[assembly: AssemblyTitle(&quot;ClassLibrary1&quot;)]&lt;br /&gt;
[assembly: AssemblyDescription(&quot;&quot;)]&lt;br /&gt;
[assembly: AssemblyConfiguration(&quot;&quot;)]&lt;br /&gt;
[assembly: AssemblyCompany(&quot;&quot;)]&lt;br /&gt;
[assembly: AssemblyProduct(&quot;ClassLibrary1&quot;)]&lt;br /&gt;
[assembly: AssemblyCopyright(&quot;Copyright ©&amp;nbsp; 2012&quot;)]&lt;br /&gt;
[assembly: AssemblyTrademark(&quot;&quot;)]&lt;br /&gt;
[assembly: AssemblyCulture(&quot;&quot;)]&lt;br /&gt;
...Add this line here.......&lt;br /&gt;
Now recompile/build the project and the assembly will be signed.&lt;br /&gt;
The next step is to install the assembly into the Global Assembly Cache.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 4 : Host the signed assembly in Global Assembly Cache&lt;/b&gt;&lt;br /&gt;
Using the Global Assembly Cache tool (Gacutil.exe)&lt;br /&gt;
You can use Gacutil.exe to add strong-named assemblies to the global assembly cache and to view the contents of the global assembly cache. &lt;br /&gt;
At the command prompt, type the following command:&lt;br /&gt;
&lt;br /&gt;
gacutil ­I &amp;lt;assembly name&amp;gt;&lt;br /&gt;
In this command, assembly name is the name of the assembly to install in the global assembly cache.&lt;br /&gt;
&lt;br /&gt;
The following example installs an assembly with the file name myGAC.dll into the global assembly cache.&lt;br /&gt;
&lt;br /&gt;
gacutil -I &quot;C:\[PathToBinDirectoryInVSProject]\myGAC.dll&quot;&lt;br /&gt;
&lt;br /&gt;
After hosting the assembly just go to WINNT\Assembly folder and you will find your assembly listed there.&lt;br /&gt;
Or if you are running windows 7 go to this location to locate the Assembly&lt;br /&gt;
C:\Windows\Microsoft.NET\assembly\GAC_MSIL&lt;br /&gt;
and here you will the folder in which is your signed assmbly&lt;br /&gt;
like myGac folder&lt;br /&gt;
In this will be another folder with name like&lt;br /&gt;
v4.0_1.0.0.0__e20b8219cca7baba&lt;br /&gt;
and in this folder will be your assemble stored with name as myGac.dll&lt;br /&gt;
&lt;b&gt;Step 5 : Test the assembly&lt;/b&gt;&lt;br /&gt;
Once you&#39;ve installed the assembly into the GAC, you can use it from other programs by creating a reference. &lt;br /&gt;
&lt;br /&gt;
Now, we will create a sample client application which uses our shared assembly.&lt;br /&gt;
&lt;br /&gt;
In our sample clientGACTest project, expand the project and then right-click on the References item. Select &quot;Add Reference&quot; from the popup menu, and the Add Reference dialog box is displayed.&lt;br /&gt;
&lt;br /&gt;
To refer an assembly in the GAC, just click on the Browse button and browse to the directory (C:\Windows\Microsoft.NET\assembly\GAC_MSIL\v4.0_1.0.0.0__e20b8219cca7baba) that contains the assembly (myGAC.dll). &lt;br /&gt;
Locate the assembly, select it, and click OK. &lt;br /&gt;
&lt;br /&gt;
Click on the myGAC reference in Solution Explorer and then examine the Properties pane. You&#39;ll see that the Copy Local property is set to False, Strong Name is true,Aliases is global and that the assembly version is 1.0.0.0&lt;br /&gt;
Just create a sample code as listed below :&lt;br /&gt;
&lt;br /&gt;
You can now compile and run the clientGAC program.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using myGac;&lt;br /&gt;
namespace ConsoleApplication2&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; class Program&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static void Main(string[] args)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Class1 c = new Class1();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string str = c.GetName();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(str);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.Read();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
And it will display the name &quot;Syed Nisar Bukhari&quot;&lt;br /&gt;
&lt;br /&gt;
This article describes how to generate a strong name for an assembly and to install a .dll file in the Global Assembly Cache. &lt;br /&gt;
The Global Assembly Cache (GAC) enables you to share assemblies across numerous applications.&lt;br /&gt;
&amp;nbsp;The GAC is automatically installed with the .NET runtime. Components are stored in C:\Windows\Microsoft.NET\assembly\GAC_MSIL\ or&amp;nbsp; C:\WINNT\Assembly. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Now time to practice!!!!&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://syednisarbukhari.blogspot.com/feeds/9145577487583806203/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8738129253178686232/9145577487583806203' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/9145577487583806203'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/9145577487583806203'/><link rel='alternate' type='text/html' href='http://syednisarbukhari.blogspot.com/2012/11/how-to-install-assembly-in-global.html' title='How to install an assembly in the Global Assembly Cache (GAC) in .NET'/><author><name>Syed Nisar Bukhari</name><uri>http://www.blogger.com/profile/13557733006614710346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHsq903LQfB_RB8a3dDw_BqfpGauwOV2VDH6f-72JrwfY6UpVfa4Z-hfYccTSCrMxSxBZgdFU1QrpuzY38mFY2F6GkyE7i4RWWBWurPn06hy4WDC0E6M2A_uNau_qv1g/s121/m.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8738129253178686232.post-7679789324950526618</id><published>2012-11-22T23:15:00.004-08:00</published><updated>2012-11-22T23:15:37.130-08:00</updated><title type='text'>How to Change the password for user sa of SQL Server</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
How to change the password of user sa of SQL Server&lt;br /&gt;
&lt;br /&gt;
Make a login to SQL Server using windows authentication&lt;br /&gt;
Go to Security-&amp;gt;Logins-&amp;gt;right click on &lt;b&gt;sa&lt;/b&gt;-&amp;gt;properties-&amp;gt;General tab and change the password&lt;br /&gt;
as&lt;br /&gt;
Password:&lt;br /&gt;
Confirm password:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Click on Ok &amp;nbsp; and you are done!!!!&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://syednisarbukhari.blogspot.com/feeds/7679789324950526618/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8738129253178686232/7679789324950526618' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/7679789324950526618'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/7679789324950526618'/><link rel='alternate' type='text/html' href='http://syednisarbukhari.blogspot.com/2012/11/how-to-change-password-for-user-sa-of.html' title='How to Change the password for user sa of SQL Server'/><author><name>Syed Nisar Bukhari</name><uri>http://www.blogger.com/profile/13557733006614710346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHsq903LQfB_RB8a3dDw_BqfpGauwOV2VDH6f-72JrwfY6UpVfa4Z-hfYccTSCrMxSxBZgdFU1QrpuzY38mFY2F6GkyE7i4RWWBWurPn06hy4WDC0E6M2A_uNau_qv1g/s121/m.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8738129253178686232.post-3268323513461400276</id><published>2012-11-22T23:10:00.005-08:00</published><updated>2012-11-22T23:10:53.614-08:00</updated><title type='text'>Connect Sql Sever 2008 remotely</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Open SQL Server Management studio&lt;br /&gt;
&lt;br /&gt;
In the server name type the machine name &amp;nbsp;say HP-HP&lt;br /&gt;
&amp;nbsp;Set authentication to SQL Server authentication&lt;br /&gt;
Specify Login and password&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheO_ZhxLNvSBKcfFLsb3cr4Th0MaI7mVK5-pUnNnecx4LJdbgC90jF03Ka5QmIMfbH6LE6lH44Dn12MV6-8Y2bXRJIJpyu2QttkHi3gQRBbazWLcRyR7YpgmLdPvFr8GXEh1iq3wkneVOV/s1600/sqlremote.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;242&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheO_ZhxLNvSBKcfFLsb3cr4Th0MaI7mVK5-pUnNnecx4LJdbgC90jF03Ka5QmIMfbH6LE6lH44Dn12MV6-8Y2bXRJIJpyu2QttkHi3gQRBbazWLcRyR7YpgmLdPvFr8GXEh1iq3wkneVOV/s320/sqlremote.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
Hope it helps....&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://syednisarbukhari.blogspot.com/feeds/3268323513461400276/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8738129253178686232/3268323513461400276' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/3268323513461400276'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/3268323513461400276'/><link rel='alternate' type='text/html' href='http://syednisarbukhari.blogspot.com/2012/11/connect-sql-sever-2008-remotely.html' title='Connect Sql Sever 2008 remotely'/><author><name>Syed Nisar Bukhari</name><uri>http://www.blogger.com/profile/13557733006614710346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHsq903LQfB_RB8a3dDw_BqfpGauwOV2VDH6f-72JrwfY6UpVfa4Z-hfYccTSCrMxSxBZgdFU1QrpuzY38mFY2F6GkyE7i4RWWBWurPn06hy4WDC0E6M2A_uNau_qv1g/s121/m.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheO_ZhxLNvSBKcfFLsb3cr4Th0MaI7mVK5-pUnNnecx4LJdbgC90jF03Ka5QmIMfbH6LE6lH44Dn12MV6-8Y2bXRJIJpyu2QttkHi3gQRBbazWLcRyR7YpgmLdPvFr8GXEh1iq3wkneVOV/s72-c/sqlremote.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8738129253178686232.post-1242173632724727151</id><published>2012-11-22T22:46:00.001-08:00</published><updated>2012-11-22T22:46:31.316-08:00</updated><title type='text'>Exception:Login failed for user &#39;IIS APPPOOL\ASP.NET v4.0</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
The fix to this exception is as:&lt;br /&gt;
Go to &amp;nbsp;&lt;b&gt;IIS7&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px;&quot;&gt;Application Pools -&amp;gt; Advanced Settings&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Change the&amp;nbsp;&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px;&quot;&gt;&lt;b&gt;ApplicationPoolIdentity&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px;&quot;&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;as&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px;&quot;&gt;In Process Model section change the identity to &lt;b&gt;Localsystem&lt;/b&gt;.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px;&quot;&gt;This will make your application run under&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; font-size: 14px; line-height: 18px; margin: 0px; padding: 1px 5px; vertical-align: baseline;&quot;&gt;&lt;b&gt;NT AUTHORITY\SYSTEM&lt;/b&gt;&lt;/code&gt;&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px;&quot;&gt;, which is an existing login for the database by default.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;img alt=&quot;AdvancedSettings&quot; src=&quot;http://i.stack.imgur.com/PcbL4.png&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Hope it helps.....&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://syednisarbukhari.blogspot.com/feeds/1242173632724727151/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8738129253178686232/1242173632724727151' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/1242173632724727151'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/1242173632724727151'/><link rel='alternate' type='text/html' href='http://syednisarbukhari.blogspot.com/2012/11/exceptionlogin-failed-for-user-iis.html' title='Exception:Login failed for user &#39;IIS APPPOOL\ASP.NET v4.0'/><author><name>Syed Nisar Bukhari</name><uri>http://www.blogger.com/profile/13557733006614710346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHsq903LQfB_RB8a3dDw_BqfpGauwOV2VDH6f-72JrwfY6UpVfa4Z-hfYccTSCrMxSxBZgdFU1QrpuzY38mFY2F6GkyE7i4RWWBWurPn06hy4WDC0E6M2A_uNau_qv1g/s121/m.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8738129253178686232.post-1500387052903655528</id><published>2012-10-14T23:38:00.000-07:00</published><updated>2012-10-14T23:38:12.752-07:00</updated><title type='text'>SQL SERVER : Error 3154: The backup set holds a backup of a database other than the existing database</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;h2 style=&quot;background-color: white; color: #333333; font-family: Georgia, Verdana, Arial, serif; font-size: 1.4em; font-weight: normal; letter-spacing: 1px; line-height: 19.450000762939453px; margin: 1em 0px 0px; padding: 0px;&quot;&gt;
&lt;div style=&quot;font-family: verdana, tahoma, arial, sans-serif; font-size: 12px; letter-spacing: normal; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: red; margin: 0px; padding: 0px;&quot;&gt;&lt;em style=&quot;margin: 0px; padding: 0px;&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 0px;&quot;&gt;Error 3154: The backup set holds a backup of a database other than the existing database&lt;/strong&gt;&lt;/em&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/h2&gt;
&lt;h2 style=&quot;background-color: white; color: #333333; font-family: Georgia, Verdana, Arial, serif; font-size: 1.4em; font-weight: normal; letter-spacing: 1px; line-height: 19.450000762939453px; margin: 1em 0px 0px; padding: 0px;&quot;&gt;
Here is the fix to this error:&lt;/h2&gt;
&lt;div&gt;
&lt;div style=&quot;background-color: white; color: #333333; font-family: verdana, tahoma, arial, sans-serif; font-size: 12px; line-height: 19.450000762939453px; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #333333; font-family: verdana, tahoma, arial, sans-serif; font-size: 12px; line-height: 19.450000762939453px; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;strong style=&quot;margin: 0px; padding: 0px;&quot;&gt;Steps:&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #333333; font-family: verdana, tahoma, arial, sans-serif; font-size: 12px; line-height: 19.450000762939453px; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
1) Use WITH REPLACE while using the RESTORE command&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: verdana, tahoma, arial, sans-serif; font-size: 12px; line-height: 19.450000762939453px; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #333333;&quot;&gt;2) Delete the older d&lt;/span&gt;atabase &lt;span style=&quot;color: #333333;&quot;&gt;which is conflicting and restore again using RESTORE command.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: verdana, tahoma, arial, sans-serif; font-size: 12px; line-height: 19.450000762939453px; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;code style=&quot;margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;color: blue; margin: 0px; padding: 0px;&quot;&gt;RESTORE DATABASE&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;margin: 0px; padding: 0px;&quot;&gt;Inventory&lt;/span&gt;&lt;span style=&quot;color: black; margin: 0px; padding: 0px;&quot;&gt;&lt;br style=&quot;margin: 0px; padding: 0px;&quot; /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; margin: 0px; padding: 0px;&quot;&gt;FROM DISK =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&#39;C:\BackupInventory.bak&#39;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; margin: 0px; padding: 0px;&quot;&gt;WITH&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: magenta; margin: 0px; padding: 0px;&quot;&gt;REPLACE&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-size: 12px; line-height: 19.450000762939453px; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;You are actually&lt;/span&gt;&lt;span style=&quot;color: magenta; font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: verdana, tahoma, arial, sans-serif;&quot;&gt;&amp;nbsp;trying to restore the database on another existing active database.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-size: 12px; line-height: 19.450000762939453px; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-size: 12px; line-height: 19.450000762939453px; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: verdana, tahoma, arial, sans-serif;&quot;&gt;Enjoy..this is the efficient fix&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://syednisarbukhari.blogspot.com/feeds/1500387052903655528/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8738129253178686232/1500387052903655528' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/1500387052903655528'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/1500387052903655528'/><link rel='alternate' type='text/html' href='http://syednisarbukhari.blogspot.com/2012/10/sql-server-error-3154-backup-set-holds.html' title='SQL SERVER : Error 3154: The backup set holds a backup of a database other than the existing database'/><author><name>Syed Nisar Bukhari</name><uri>http://www.blogger.com/profile/13557733006614710346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHsq903LQfB_RB8a3dDw_BqfpGauwOV2VDH6f-72JrwfY6UpVfa4Z-hfYccTSCrMxSxBZgdFU1QrpuzY38mFY2F6GkyE7i4RWWBWurPn06hy4WDC0E6M2A_uNau_qv1g/s121/m.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8738129253178686232.post-4732586110722573109</id><published>2012-10-06T07:01:00.000-07:00</published><updated>2012-10-06T07:01:13.374-07:00</updated><title type='text'>A potentially dangerous Request.Path value was detected from the client (:)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Sometimes you get the following exception when usually opening a page in web browser&lt;br /&gt;
&lt;b&gt;A potentially dangerous Request.Path value was detected from the client (:)&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;&lt;b&gt;Description: 
&lt;/b&gt;An unhandled exception occurred during the execution of the current web 
request. Please review the stack trace for more information about the error and 
where it originated in the code. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Exception Details: 
&lt;/b&gt;System.Web.HttpException: A potentially dangerous Request.Path value was 
detected from the client (:).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Source Error:&lt;/b&gt; &lt;br /&gt;&lt;br /&gt;
&lt;table bgcolor=&quot;#ffffcc&quot; style=&quot;width: 100%px;&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;An unhandled exception was generated during the execution of the 
current web request. Information regarding the origin and location of the 
exception can be identified using the exception stack trace below.&lt;/code&gt; 
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;&lt;b&gt;Stack Trace:&lt;/b&gt; &lt;br /&gt;&lt;br /&gt;
&lt;table bgcolor=&quot;#ffffcc&quot; style=&quot;width: 100%px;&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&lt;pre&gt;[HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (:).]
   System.Web.HttpRequest.ValidateInputIfRequiredByConfig() +8884233
   System.Web.PipelineStepManager.ValidateHelper(HttpContext context) +59
&lt;/pre&gt;
&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;hr color=&quot;silver&quot; size=&quot;1&quot; width=&quot;100%&quot; /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;
&lt;b&gt;Version Information:&lt;/b&gt; Microsoft .NET Framework Version:4.0.30319; ASP.NET 
Version:4.0.30319.1&amp;nbsp;&lt;/span&gt;&lt;!-- 
[HttpException]: A potentially dangerous Request.Path value was detected from the client (:).
   at System.Web.HttpRequest.ValidateInputIfRequiredByConfig()
   at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context)
--&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;&lt;b&gt;Solution:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;1.Check the url properly.Find out if there is any invalid character that has been accidently set as a part of the url.In my case when i got this exception,i did enough of google and all that....when &amp;nbsp;checked the url and i found that &quot;colon :&quot; &amp;nbsp;was getting appended to the url at the end.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;like this http://localhost/myapp/index.aspx&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;It is not always the case with colon...somtimes there may be some other unwanted character...This was the case with my problem...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;I removed the colon and the problem was fixed......................and closed all the windows from google search :)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;OR&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;These link may also be helpful&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.cryer.co.uk/brian/mswinswdev/ms_vbnet_server_error_potentially_dangerous.htm&quot;&gt;http://www.cryer.co.uk/brian/mswinswdev/ms_vbnet_server_error_potentially_dangerous.htm&lt;/a&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;a href=&quot;http://stackoverflow.com/questions/5967103/a-potentially-dangerous-request-path-value-was-detected-from-the-client&quot;&gt;http://stackoverflow.com/questions/5967103/a-potentially-dangerous-request-path-value-was-detected-from-the-client&lt;/a&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://syednisarbukhari.blogspot.com/feeds/4732586110722573109/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8738129253178686232/4732586110722573109' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/4732586110722573109'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/4732586110722573109'/><link rel='alternate' type='text/html' href='http://syednisarbukhari.blogspot.com/2012/10/a-potentially-dangerous-requestpath.html' title='A potentially dangerous Request.Path value was detected from the client (:)'/><author><name>Syed Nisar Bukhari</name><uri>http://www.blogger.com/profile/13557733006614710346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHsq903LQfB_RB8a3dDw_BqfpGauwOV2VDH6f-72JrwfY6UpVfa4Z-hfYccTSCrMxSxBZgdFU1QrpuzY38mFY2F6GkyE7i4RWWBWurPn06hy4WDC0E6M2A_uNau_qv1g/s121/m.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8738129253178686232.post-963555830464452025</id><published>2012-10-03T01:50:00.003-07:00</published><updated>2012-10-03T01:50:35.395-07:00</updated><title type='text'>SQL 2008 - &quot;Saving changes is not permitted.&quot; error message.. Whenever any change is made to the table in SQL Server 2008,the following message is displayed Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can&#39;t be re-created or enabled the option Prevent saving changes that require the table to be re-created. </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
The fix to this warning is as:&lt;/div&gt;
&lt;div&gt;
Open &lt;b&gt;SQL Server Management Studio (SSMS).&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
On the &lt;b&gt;Tools&lt;/b&gt; menu, click Options.&lt;/div&gt;
&lt;div&gt;
In the navigation pane of the &lt;b&gt;Options&lt;/b&gt; window, click &lt;b&gt;Designers.&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
Select or clear the&lt;b&gt; Prevent saving changes that require the table re-creation check box&lt;/b&gt;, and then click &lt;b&gt;OK.&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Note If you disable this option, you are not warned when you save the table that the changes that you made have changed the metadata structure of the table. In this case, data loss may occur when you save the table.&lt;/div&gt;
&lt;div&gt;
Risk of turning off the &quot;Prevent saving changes that require table re-creation&quot; option&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Although turning off this option can help you avoid re-creating a table, it can also lead to changes being lost. For example, suppose that you enable the Change Tracking feature in SQL Server 2008 to track changes to the table. When you perform an operation that causes the table to be re-created, you receive the error message that is mentioned in the &quot;Symptoms&quot; section. However, if you turn off this option, the existing change tracking information is deleted when the table is re-created. Therefore, we recommend that you do not work around this problem by turning off the option.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
To determine whether the Change Tracking feature is enabled for a table, follow these steps:&lt;/div&gt;
&lt;div&gt;
In SQL Server Management Studio, locate the table in Object Explorer.&lt;/div&gt;
&lt;div&gt;
Right-click the table, and then click Properties.&lt;/div&gt;
&lt;div&gt;
In the Table Properties dialog box, click Change Tracking.&lt;/div&gt;
&lt;div&gt;
If the value of the Change Tracking item is True, this option is enabled for the table. If the value is False, this option is disabled.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
When the Change Tracking feature is enabled, use Transact-SQL statements to change the metadata structure of the table.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Steps to reproduce the problem&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
In SQL Server Management Studio, create a table that contains a primary key in the Table Designer tool.&lt;/div&gt;
&lt;div&gt;
Right-click the database that contains this table, and then click Properties.&lt;/div&gt;
&lt;div&gt;
In the Database Properties dialog box, click Change Tracking.&lt;/div&gt;
&lt;div&gt;
Set the value of the Change Tracking item to True, and then click OK.&lt;/div&gt;
&lt;div&gt;
Right-click the table, and then click Properties.&lt;/div&gt;
&lt;div&gt;
In the Table Properties dialog box, click Change Tracking.&lt;/div&gt;
&lt;div&gt;
Set the value of the Change Tracking item to True, and then click OK.&lt;/div&gt;
&lt;div&gt;
On the Tools menu, click Options.&lt;/div&gt;
&lt;div&gt;
In the Options dialog box, click Designers.&lt;/div&gt;
&lt;div&gt;
Click to select the Prevent saving changes that require table re-creation check box, and then click OK.&lt;/div&gt;
&lt;div&gt;
In the Table Designer tool, change the Allow Nulls setting on an existing column.&lt;/div&gt;
&lt;div&gt;
Try to save the change to the table.&lt;/div&gt;
&lt;div&gt;
[Source:Microsoft]&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://syednisarbukhari.blogspot.com/feeds/963555830464452025/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8738129253178686232/963555830464452025' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/963555830464452025'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/963555830464452025'/><link rel='alternate' type='text/html' href='http://syednisarbukhari.blogspot.com/2012/10/sql-2008-saving-changes-is-not.html' title='SQL 2008 - &quot;Saving changes is not permitted.&quot; error message.. Whenever any change is made to the table in SQL Server 2008,the following message is displayed Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can&#39;t be re-created or enabled the option Prevent saving changes that require the table to be re-created. '/><author><name>Syed Nisar Bukhari</name><uri>http://www.blogger.com/profile/13557733006614710346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHsq903LQfB_RB8a3dDw_BqfpGauwOV2VDH6f-72JrwfY6UpVfa4Z-hfYccTSCrMxSxBZgdFU1QrpuzY38mFY2F6GkyE7i4RWWBWurPn06hy4WDC0E6M2A_uNau_qv1g/s121/m.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8738129253178686232.post-703518038636394217</id><published>2012-09-20T02:38:00.002-07:00</published><updated>2012-09-20T02:38:23.863-07:00</updated><title type='text'>SQL SERVER – FIX : ERROR : Cannot open database requested by the login. The login failed. Login failed for user ‘NT AUTHORITY\NETWORK SERVICE’.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;background-color: white; color: #333333; font-family: verdana, tahoma, arial, sans-serif; font-size: 12px; line-height: 19.450000762939453px; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
This error occurs when you have configured your application with IIS, and IIS goes to SQL Server and tries to login with credentials that do not have proper permissions. This error can also occur when replication or mirroring is set up.&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #333333; font-family: verdana, tahoma, arial, sans-serif; font-size: 12px; line-height: 19.450000762939453px; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;b&gt;Here is the solution:&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #333333; font-family: verdana, tahoma, arial, sans-serif; font-size: 12px; line-height: 19.450000762939453px; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
Go to SQL Server &amp;gt;&amp;gt; Security &amp;gt;&amp;gt; Logins and right click on NT AUTHORITY\NETWORK SERVICE and select Properties&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #333333; font-family: verdana, tahoma, arial, sans-serif; font-size: 12px; line-height: 19.450000762939453px; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;img alt=&quot;&quot; class=&quot;alignnone&quot; height=&quot;439&quot; src=&quot;http://www.pinaldave.com/bimg/errnt.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;468&quot; /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #333333; font-family: verdana, tahoma, arial, sans-serif; font-size: 12px; line-height: 19.450000762939453px; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
In newly opened screen of Login Properties, go to the “User Mapping” tab. Then, on the “User Mapping” tab, select the desired database – especially the database for which this error message is displayed. On the lower screen, check the role db_owner. Click OK.&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #333333; font-family: verdana, tahoma, arial, sans-serif; font-size: 12px; line-height: 19.450000762939453px; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;img alt=&quot;&quot; class=&quot;alignnone&quot; height=&quot;451&quot; src=&quot;http://www.pinaldave.com/bimg/errnt1.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #333333; font-family: verdana, tahoma, arial, sans-serif; font-size: 12px; line-height: 19.450000762939453px; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
Hope this solves your issue&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://syednisarbukhari.blogspot.com/feeds/703518038636394217/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8738129253178686232/703518038636394217' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/703518038636394217'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/703518038636394217'/><link rel='alternate' type='text/html' href='http://syednisarbukhari.blogspot.com/2012/09/sql-server-fix-error-cannot-open.html' title='SQL SERVER – FIX : ERROR : Cannot open database requested by the login. The login failed. Login failed for user ‘NT AUTHORITY\NETWORK SERVICE’.'/><author><name>Syed Nisar Bukhari</name><uri>http://www.blogger.com/profile/13557733006614710346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHsq903LQfB_RB8a3dDw_BqfpGauwOV2VDH6f-72JrwfY6UpVfa4Z-hfYccTSCrMxSxBZgdFU1QrpuzY38mFY2F6GkyE7i4RWWBWurPn06hy4WDC0E6M2A_uNau_qv1g/s121/m.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8738129253178686232.post-8817097909599869475</id><published>2012-09-13T04:22:00.004-07:00</published><updated>2012-09-13T04:22:45.684-07:00</updated><title type='text'>Manually configure IIS webserver for asp.net 4.0</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hi folks if you are getting this error &quot;Manually configure IIS webserver for asp.net 4.0&quot; then do the following&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;default prettyprint&quot;&gt;
&lt;/pre&gt;
&lt;pre class=&quot;default prettyprint&quot;&gt;&lt;code&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;default prettyprint&quot;&gt;&lt;code&gt;&lt;span class=&quot;pln&quot;&gt;1.Open visual studio command prompt in administrative mode.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;default prettyprint&quot;&gt;&lt;code&gt;&lt;span class=&quot;pln&quot;&gt;2.Then run this command&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;default prettyprint&quot;&gt;&lt;span class=&quot;pln&quot;&gt;       C&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;:\&lt;/span&gt;&lt;span class=&quot;typ&quot;&gt;Windows&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;typ&quot;&gt;Microsoft&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;NET&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;typ&quot;&gt;Framework&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;v4&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;lit&quot;&gt;0.30319&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;aspnet_regiis &lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;i&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;default prettyprint&quot;&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;default prettyprint&quot;&gt;&lt;span class=&quot;pln&quot;&gt;i.e., you have to reach to &lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;v4&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;lit&quot;&gt;0.30319 folder first,then run the command &lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;aspnet_regiis &lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;i&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;default prettyprint&quot;&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;default prettyprint&quot;&gt;&lt;span class=&quot;pln&quot;&gt;Here is the screen shot&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;default prettyprint&quot;&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6infnC0o7GLlQZm4n18PYGxhYt_GfVKT5nnxOOC6XodbAeoFEgTVDZshOcYqvrIJSjTjmd-X3TpVrOjfFoP1MknUn8Zvs50B_R4a9E5aoV97xzK0gr1Gogih9ipjclAbegXWaMDJp07CW/s1600/asp.net4.0+issue.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;323&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6infnC0o7GLlQZm4n18PYGxhYt_GfVKT5nnxOOC6XodbAeoFEgTVDZshOcYqvrIJSjTjmd-X3TpVrOjfFoP1MknUn8Zvs50B_R4a9E5aoV97xzK0gr1Gogih9ipjclAbegXWaMDJp07CW/s640/asp.net4.0+issue.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;pre class=&quot;default prettyprint&quot;&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;default prettyprint&quot;&gt;&lt;code&gt;&lt;span class=&quot;pln&quot;&gt;Hope this solves your problem&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://syednisarbukhari.blogspot.com/feeds/8817097909599869475/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8738129253178686232/8817097909599869475' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/8817097909599869475'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/8817097909599869475'/><link rel='alternate' type='text/html' href='http://syednisarbukhari.blogspot.com/2012/09/manually-configure-iis-webserver-for.html' title='Manually configure IIS webserver for asp.net 4.0'/><author><name>Syed Nisar Bukhari</name><uri>http://www.blogger.com/profile/13557733006614710346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHsq903LQfB_RB8a3dDw_BqfpGauwOV2VDH6f-72JrwfY6UpVfa4Z-hfYccTSCrMxSxBZgdFU1QrpuzY38mFY2F6GkyE7i4RWWBWurPn06hy4WDC0E6M2A_uNau_qv1g/s121/m.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6infnC0o7GLlQZm4n18PYGxhYt_GfVKT5nnxOOC6XodbAeoFEgTVDZshOcYqvrIJSjTjmd-X3TpVrOjfFoP1MknUn8Zvs50B_R4a9E5aoV97xzK0gr1Gogih9ipjclAbegXWaMDJp07CW/s72-c/asp.net4.0+issue.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8738129253178686232.post-772013256255740462</id><published>2012-09-13T01:35:00.001-07:00</published><updated>2012-09-13T01:35:26.407-07:00</updated><title type='text'>How to Install SQL SERVER – 2008 –A Step By Step Installation Guide </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div class=&quot;posttitle&quot; style=&quot;background-color: white; color: #333333; font-family: verdana, tahoma, arial, sans-serif; font-size: 12px; line-height: 19.450000762939453px; margin: 0px; padding: 0px;&quot;&gt;
&lt;h2 style=&quot;font-family: Georgia, Verdana, Arial, serif; font-size: 1.4em; font-weight: normal; letter-spacing: 1px; margin: 1em 0px 0px; padding: 0px;&quot;&gt;
How to Install SQL SERVER – 2008 –A Step By Step Installation Guide&amp;nbsp;&lt;/h2&gt;
&lt;/div&gt;
&lt;div class=&quot;entry&quot; style=&quot;background-color: white; color: #333333; font-family: verdana, tahoma, arial, sans-serif; font-size: 12px; line-height: 19.450000762939453px; margin: 1em 0px; overflow: hidden; padding: 0px 1em 0px 0px;&quot;&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
SQL SERVER 2008 Release Candidate 0 has been released for some time and I have got numorous request about how to install SQL Server 2008. I have created this step by step guide Installation Guide. Images are used to explain the process easier.&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;strong style=&quot;margin: 0px; padding: 0px;&quot;&gt;[Click On Images to See Larger Image]&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/20081.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;471&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/20081.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/20082.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;600&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/20082.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;445&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/20083.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;375&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/20083.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/20084.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;375&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/20084.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/20085.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;349&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/20085.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/20086.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;375&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/20086.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/20087.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;375&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/20087.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/20088.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;375&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/20088.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/20089.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;375&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/20089.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/200810.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;375&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/200810.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/200811.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;375&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/200811.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/200812.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;375&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/200812.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/200813.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;375&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/200813.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/200814.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;414&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/200814.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/200815.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;414&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/200815.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/200816.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;414&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/200816.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/200817.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;414&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/200817.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/200818.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;414&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/200818.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/200819.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;414&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/200819.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/200820.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;414&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/200820.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/200821.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;414&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/200821.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/200822.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;414&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/200822.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/200823.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;414&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/200823.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/200824.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;414&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/200824.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/200825.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;383&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/200825.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/200826.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/200827.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;358&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/200827.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;a href=&quot;http://www.pinaldave.com/bimg/2008/200828.jpg&quot; style=&quot;border-bottom-color: rgb(56, 79, 131); border-bottom-style: dashed; border-bottom-width: 1px; color: #384f83; margin: 0px; padding: 0px; text-decoration: none;&quot;&gt;&lt;img alt=&quot;&quot; scale=&quot;0&quot; src=&quot;http://www.pinaldave.com/bimg/2008small/200828.jpg&quot; style=&quot;background-image: url(http://s0.wp.com/wp-content/themes/pub/mistylook/img/shadow.gif); background-position: 100% 100%; background-repeat: no-repeat no-repeat; border-left-color: rgb(238, 238, 238); border-left-width: 1px; border-style: solid none none solid; border-top-color: rgb(238, 238, 238); border-top-width: 1px; height: auto; margin: 0px; max-width: 100%; padding: 4px 10px 10px 4px;&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.6em; margin-bottom: 0.7em; margin-top: 0.7em; padding: 0px; text-align: justify;&quot;&gt;
&lt;strong style=&quot;margin: 0px; padding: 0px;&quot;&gt;[Click On Images to See Larger Image]&lt;/strong&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://syednisarbukhari.blogspot.com/feeds/772013256255740462/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8738129253178686232/772013256255740462' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/772013256255740462'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/772013256255740462'/><link rel='alternate' type='text/html' href='http://syednisarbukhari.blogspot.com/2012/09/how-to-install-sql-server-2008-step-by.html' title='How to Install SQL SERVER – 2008 –A Step By Step Installation Guide '/><author><name>Syed Nisar Bukhari</name><uri>http://www.blogger.com/profile/13557733006614710346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHsq903LQfB_RB8a3dDw_BqfpGauwOV2VDH6f-72JrwfY6UpVfa4Z-hfYccTSCrMxSxBZgdFU1QrpuzY38mFY2F6GkyE7i4RWWBWurPn06hy4WDC0E6M2A_uNau_qv1g/s121/m.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8738129253178686232.post-6683162250674339111</id><published>2011-12-19T07:15:00.000-08:00</published><updated>2011-12-19T07:15:32.524-08:00</updated><title type='text'>C# Facade Design Pattern</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In real world a &lt;b&gt;facade&lt;/b&gt; or &lt;b&gt;façade&lt;/b&gt;&amp;nbsp; is generally one exterior side of a building usually, but not always, the front...:)&lt;br /&gt;
&lt;br /&gt;
The &lt;b&gt;facade pattern&lt;/b&gt; is a &lt;span style=&quot;color: black;&quot;&gt;software engineering design pattern&lt;a class=&quot;mw-redirect&quot; href=&quot;http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29&quot; title=&quot;Design pattern (computer science)&quot;&gt;&lt;/a&gt;&lt;/span&gt; commonly used with object oriented programming analogy to an architectural facade.A facade is an object that provides a simplified interface to a larger body of code, such as a class library. A facade can:
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;make a software library&lt;a class=&quot;mw-redirect&quot; href=&quot;http://en.wikipedia.org/wiki/Software_library&quot; title=&quot;Software library&quot;&gt;&lt;/a&gt; easier to use, understand and test, since the facade has convenient methods for common tasks;&lt;/li&gt;
&lt;li&gt;make code that uses the library more readable, for the same reason;&lt;/li&gt;
&lt;li&gt;reduce dependencies of outside code on the inner workings of a 
library, since most code uses the facade, thus allowing more flexibility
 in developing the system;&lt;/li&gt;
&lt;li&gt;wrap a poorly-designed collection of APIs with a single well-designed API (as per task needs).&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;Facade defines a higher-level interface that makes the subsystem easier 
to use. Facade&amp;nbsp; is one of the common and easiest patterns. It wrap a 
complicated subsystem with a simpler interface. As a developer we often 
use this facade pattern. Even some of them don&#39;t recognise while using 
it that its a facade patterns. I have tried to explain facade pattern by
 building a blog system.&lt;/li&gt;
&lt;li&gt;&lt;div align=&quot;justify&quot;&gt;
Facade design patterns&amp;nbsp; gives easier interface for 
common task. It provides simplified and uniform interface to a large 
subsystem of classes. For example in a shopping cart system&amp;nbsp; there could
 be many API’s related to register user, purchase,user detail, 
transactions etc so facade deals with all these interfaces and provide 
one simple modified interface to deals with them.&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
A
 more simple non-software example can be if you want to play a game 
suppose Metal gear Solid on PS3 (Did i tell you that i love that game?).
 You Require PS3, HD TV, Controller etc.&amp;nbsp; So there are so many sub 
system could be involve if you want to play a game on ps3. But actually 
all you are doing in simpler term is playing a game. So facade can give 
you a simple interface with a operation call PlayGame() in this 
example.The Facade object should be a fairly simple advocate or 
facilitator. If the Facade is the only access point for the subsystem, 
it will limit the features and flexibility that “power users” may need.&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
For example we have   &lt;/div&gt;
&lt;table bgcolor=&quot;#fffaef&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;div class=&quot;sourcecode&quot;&gt;
&lt;span style=&quot;color: green;&quot;&gt;
        // Facade pattern -- Structural example      
       &lt;/span&gt;
      &lt;/div&gt;
&lt;/td&gt;        
     &lt;/tr&gt;
&lt;/tbody&gt;&lt;tbody id=&quot;Structure&quot;&gt;
&lt;tr&gt;
     &lt;td&gt;
      &lt;div class=&quot;sourcecode&quot;&gt;
&lt;br /&gt;
       
&lt;div class=&quot;divsource&quot;&gt;

&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; System;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;namespace&lt;/span&gt; DoFactory.GangOfFour.Facade.Structural&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; MainApp startup class for Structural&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; Facade Design Pattern.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;MainApp&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;{&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; Entry point into console application.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Main()&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Facade&lt;/span&gt; facade = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Facade&lt;/span&gt;();&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;facade.MethodA();&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;facade.MethodB();&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: green;&quot;&gt;// Wait for user&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.ReadKey();&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;}&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; The &#39;Subsystem ClassA&#39; class&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;SubSystemOne&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;{&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; MethodOne()&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot; SubSystemOne Method&quot;&lt;/span&gt;);&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;}&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; The &#39;Subsystem ClassB&#39; class&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;SubSystemTwo&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;{&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; MethodTwo()&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot; SubSystemTwo Method&quot;&lt;/span&gt;);&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;}&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; The &#39;Subsystem ClassC&#39; class&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;SubSystemThree&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;{&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; MethodThree()&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot; SubSystemThree Method&quot;&lt;/span&gt;);&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;}&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; The &#39;Subsystem ClassD&#39; class&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;SubSystemFour&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;{&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; MethodFour()&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot; SubSystemFour Method&quot;&lt;/span&gt;);&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;}&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; The &#39;Facade&#39; class&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: grey;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Facade&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;{&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;SubSystemOne&lt;/span&gt; _one;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;SubSystemTwo&lt;/span&gt; _two;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;SubSystemThree&lt;/span&gt; _three;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;SubSystemFour&lt;/span&gt; _four;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; Facade()&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_one = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;SubSystemOne&lt;/span&gt;();&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_two = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;SubSystemTwo&lt;/span&gt;();&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_three = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;SubSystemThree&lt;/span&gt;();&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_four = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;SubSystemFour&lt;/span&gt;();&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; MethodA()&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;\nMethodA() ---- &quot;&lt;/span&gt;);&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_one.MethodOne();&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_two.MethodTwo();&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_four.MethodFour();&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; MethodB()&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;\nMethodB() ---- &quot;&lt;/span&gt;);&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_two.MethodTwo();&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_three.MethodThree();&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;}&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
}&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
   &lt;/tr&gt;
&lt;tr&gt;
    &lt;td bgcolor=&quot;white&quot;&gt;
     &lt;br /&gt;
      &lt;span style=&quot;font-family: arial,helvetica; font-size: x-small;&quot;&gt;Output&lt;/span&gt; 
       &lt;div class=&quot;output&quot;&gt;

        
MethodA() ----&lt;br /&gt;
SubSystemOne Method&lt;br /&gt;
SubSystemTwo Method&lt;br /&gt;
SubSystemFour Method&lt;br /&gt;
&lt;br /&gt;
MethodB() ----&lt;br /&gt;
SubSystemTwo Method&lt;br /&gt;
SubSystemThree Method&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://syednisarbukhari.blogspot.com/feeds/6683162250674339111/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8738129253178686232/6683162250674339111' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/6683162250674339111'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/6683162250674339111'/><link rel='alternate' type='text/html' href='http://syednisarbukhari.blogspot.com/2011/12/c-facade-design-pattern.html' title='C# Facade Design Pattern'/><author><name>Syed Nisar Bukhari</name><uri>http://www.blogger.com/profile/13557733006614710346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHsq903LQfB_RB8a3dDw_BqfpGauwOV2VDH6f-72JrwfY6UpVfa4Z-hfYccTSCrMxSxBZgdFU1QrpuzY38mFY2F6GkyE7i4RWWBWurPn06hy4WDC0E6M2A_uNau_qv1g/s121/m.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8738129253178686232.post-754772708485535120</id><published>2011-12-19T02:00:00.000-08:00</published><updated>2011-12-19T02:01:18.999-08:00</updated><title type='text'>Patterns in Practice..Cohesion And Coupling</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070001&quot;&gt;
&lt;b&gt;Much of software design&lt;/b&gt; 
involves the ongoing question, where should this code go? &lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070002&quot;&gt;
In particular, I would like to achieve three specific things with my code structure:&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070003&quot;&gt;
&lt;ol&gt;
&lt;li&gt;Keep things that have to change together as close together in the code as possible.&lt;/li&gt;
&lt;li&gt;Allow unrelated things in the code to change independently (also known as orthogonality).&lt;/li&gt;
&lt;li&gt;Minimize duplication in the code.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070006&quot;&gt;
To
 achieve these three goals, I need some tools to help me know where new 
code should go and some other tools to help me recognize when I&#39;ve put 
code in the wrong place. &lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070007&quot;&gt;
By
 and large, these goals are closely related to the classic code 
qualities of cohesion and coupling. I achieve these goals by moving 
toward higher cohesion and looser coupling. Of course, first we need to 
understand what these qualities mean and why coupling and cohesion are 
helpful concepts. Then I&#39;d like to discuss some of what I&#39;m going to 
call &quot;design vectors&quot; that help us move toward better structures and 
recognize when we need to move away from bad structures that have crept 
into our code. &lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070008&quot;&gt;
Just
 as a note, I&#39;m the primary developer of an open source inversion of 
control (IOC) tool called StructureMap. I&#39;m going to be using some 
real-life examples from StructureMap to illustrate the design problems 
that these vectors address. In other words, don&#39;t make the same mistakes
 that I made.&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;ArticleTypeTitle&quot; id=&quot;id0070009&quot;&gt;
Decrease Coupling&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070010&quot;&gt;
You
 can&#39;t help but hear the terms &quot;loose coupling&quot; or &quot;tight coupling&quot; in 
almost any discussion on software design. Coupling among classes or 
subsystems is a measure of how interconnected those classes or 
subsystems are. Tight coupling means that related classes have to know 
internal details of each other, changes ripple through the system, and 
the system is potentially harder to understand. &lt;b&gt;Figure 1&lt;/b&gt;
 shows a contrived sample of a business-processing module that is very 
tightly coupled to various other concerns besides the business logic.&lt;/div&gt;
&lt;div class=&quot;figmargin&quot; id=&quot;id013&quot;&gt;
&lt;div class=&quot;MTPS_CollapsibleRegion&quot;&gt;
&lt;div class=&quot;CollapseRegionLink&quot;&gt;
&lt;img class=&quot;LibC_o&quot; src=&quot;http://i.msdn.microsoft.com/Global/Images/clear.gif&quot; style=&quot;border-width: 0px; vertical-align: middle;&quot; /&gt;
&amp;nbsp;Figure 1 Tightly Coupled Code
&lt;/div&gt;
&lt;div class=&quot;MTPS_CollapsibleSection&quot; style=&quot;display: block;&quot;&gt;
&lt;span id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl21_ctl00_ctl00&quot;&gt;
&lt;div class=&quot;libCScode&quot; id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl21_ctl00_ctl00_&quot;&gt;
&lt;div class=&quot;CodeSnippetTitleBar&quot;&gt;
&lt;div class=&quot;CodeDisplayLanguage&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;background-color: #dddddd;&quot;&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl21_ctl00_ctl00_code&quot;&gt;public class BusinessLogicClass {
  public void DoSomething()  {
    // Go get some configuration
    int threshold = 
      int.Parse(ConfigurationManager.AppSettings[&quot;threshold&quot;]);

    string connectionString = 
      ConfigurationManager.AppSettings[&quot;connectionString&quot;];

    string sql = 
      @&quot;select * from things 
        size &amp;gt; &quot;;

    sql += threshold;

    using (SqlConnection connection = 
      new SqlConnection(connectionString)) {

      connection.Open();

      SqlCommand command = new SqlCommand(sql, connection);
      using (SqlDataReader reader = command.ExecuteReader()) {
        while (reader.Read()) {
          string name = reader[&quot;Name&quot;].ToString();
          string destination = reader[&quot;destination&quot;].ToString();

          // do some business logic in here
          doSomeBusinessLogic(name, destination, connection);
        }  
      }
    }
  }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/span&gt;
                                                  
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070011&quot;&gt;
Let&#39;s
 say that what we really care about is the actual business processing, 
but our business logic code is intertwined with data-access concerns and
 configuration settings. So what&#39;s potentially wrong with this style of 
code?&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070012&quot;&gt;
The
 first problem is that the code is somewhat hard to understand because 
of the way the different concerns are intertwined. I&#39;ll discuss this 
further in the next section on cohesion.&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070013&quot;&gt;
The
 second problem is that any changes in data-access strategy, database 
structure, or configuration strategies will ripple through the business 
logic code as well because it&#39;s all in one code file. This business 
logic knows too much about the underlying infrastructure. &lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070014&quot;&gt;
Third,
 we can&#39;t reuse the business logic code independent of the specific 
database structure or without the existence of the AppSettings keys. We 
also can&#39;t reuse the data-access functionality embedded in the 
BusinessLogicClass. That coupling between data access and business logic
 might not be an issue, but what if we want to repurpose this business 
logic for usage against data entered directly into an Excel spreadsheet 
by analysts? What if we want to test or debug the business logic by 
itself? We can&#39;t do any of that because the business logic is tightly 
coupled to the data-access code. The business logic would be a lot 
easier to change if we could isolate it from the other concerns.&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070015&quot;&gt;
To summarize, the goals behind achieving loose coupling between classes and modules are to:&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070016&quot;&gt;
&lt;ol&gt;
&lt;li&gt;Make the code easier to read.&lt;/li&gt;
&lt;li&gt;Make our
 classes easier to consume by other developers by hiding the ugly inner 
workings of our classes behind well-designed APIs.&lt;/li&gt;
&lt;li&gt;Isolate potential changes to a small area of code. &lt;/li&gt;
&lt;li&gt;Reuse classes in completely new contexts.&lt;/li&gt;
&lt;li&gt;&lt;div class=&quot;SidebarContainer&quot; id=&quot;id017&quot;&gt;
&lt;div class=&quot;SidebarHeadline&quot;&gt;
Code Smells&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0170001&quot;&gt;
It&#39;s
 obviously good to know how to do the right things when designing new 
code, but it might be even more important to recognize when your 
existing code or design has developed problems. Like inappropriate 
intimacy, &quot;code smell&quot; (defined by Martin Fowler in the book 
Refactoring: Improving the Design of Existing Code) is a tool that you 
can utilize to spot potential problems in code. &lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0170002&quot;&gt;
A
 code smell is a sign that something may be wrong in your code. It 
doesn&#39;t mean that you need to rip out your existing code and throw it 
away on the spot, but you definitely need to take a closer look at the 
code that gives off the offending &quot;smell.&quot; A code smell can be spotted 
by simple inspection. Learning about code smells is a powerful tool to 
remove little problems in your code and class design before those 
problems become bigger issues.&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0170003&quot;&gt;
Many,
 if not most, of the commonly described code smells are signs of poor 
cohesion or harmful tight coupling. Here are some other examples:&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0170004&quot;&gt;
&lt;b&gt;Divergent Changes&lt;/b&gt;
 A single class that has to be changed in different ways for different 
reasons. This smell is a sign that the class is not cohesive. You might 
refactor this class to extract distinct responsibilities into new 
classes. &lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0170005&quot;&gt;
&lt;b&gt;Feature Envy&lt;/b&gt;
 A method in ClassA seems way too interested in the workings and data 
fields of ClassB. The feature envy from ClassA to ClassB is an 
indication of tight coupling from ClassA to ClassB. The usual fix is to 
try moving the functionality of the interested method in ClassA to 
ClassB, which is already closer to most of the data involved in the 
task.&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0170006&quot;&gt;
&lt;b&gt;Shotgun Surgery&lt;/b&gt;
 A certain type of change in the system repeatedly leads to making lots 
of small changes to a group of classes. Shotgun surgery generally 
implies that a single logical idea or function is spread out over 
multiple classes. Try to fix this by pulling all the parts of the code 
that have to change together into a single cohesive class.&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
                                        &lt;div class=&quot;ArticleTypeTitle&quot; id=&quot;id0070020&quot;&gt;
Increase Cohesion&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070021&quot;&gt;
The
 academic definition of cohesion is that it is a measure of how closely 
related all the responsibilities, data, and methods of a class are to 
each other. I like to think of cohesion as a measure of whether a class 
has a well-defined role within the system. We generally consider high 
cohesion to be a good thing and repeat the words &quot;highly cohesive&quot; like a
 mantra. But why? &lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070022&quot;&gt;
Let&#39;s
 think of coding as having a conversation with the computer. More 
accurately, we&#39;re having several simultaneous conversations with the 
computer. We&#39;re having conversations about how security is carried out, 
how the infrastructure concerns are supposed to behave, and what the 
business rules are. &lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070023&quot;&gt;
When
 you&#39;re at a loud party with a lot of different conversations going on 
at once, it can be difficult to focus on the one conversation you&#39;re 
trying to have. It&#39;s much easier to have a conversation in a quiet 
setting where there&#39;s only one conversation going on. &lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070024&quot;&gt;
An
 easy test for cohesion is to look at a class and decide whether all the
 contents of the class are directly related to and described by the name
 of the class—vague class names, such as InvoiceManager, do not count. 
If the class has responsibilities that don&#39;t relate to its name, those 
responsibilities probably belong to a different class. If you find a 
subset of methods and fields that could easily be grouped separately 
under another class name, then maybe you should extract these methods 
and fields to a new class. &lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070025&quot;&gt;
To
 illustrate, if you find methods and data in your TrainStation, Train, 
and Conductor classes that seem to most accurately fit the theme of the 
TrainSchedule class, move those methods and data into the TrainSchedule.
 One of my favorite sayings about design is applicable here: put code 
where you&#39;d expect to find it. It&#39;s most logical to me that 
functionality involving a train schedule would be in the TrainSchedule 
class.&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070026&quot;&gt;
To
 stretch my earlier conversation analogy, a system consisting of 
cohesive classes and subsystems is like a well-designed online 
discussion group. Each area in the online group is narrowly focused on 
one specific topic so the discussion is easy to follow, and if you&#39;re 
looking for a dialog on a certain subject, there&#39;s only one room you 
have to visit. &lt;/div&gt;
&lt;br /&gt;
                                        &lt;div class=&quot;ArticleTypeTitle&quot; id=&quot;id0070027&quot;&gt;
Eliminate Inappropriate Intimacy&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070028&quot;&gt;
Inappropriate
 intimacy refers to a method in a class that has too much intimate 
knowledge of another class. Inappropriate intimacy is a sign of harmful,
 tight coupling between classes. Let&#39;s say that we have a business logic
 class that calls an instance of class DataServer1 to get the data it 
needs for its business-logic processing. &lt;b&gt;Figure 2&lt;/b&gt; shows
 an example. In this case, the Process method has to know a lot of the 
inner workings of DataServer1 and a bit about the SqlDataReader class.&lt;/div&gt;
&lt;div class=&quot;figmargin&quot; id=&quot;id015&quot;&gt;
&lt;div class=&quot;MTPS_CollapsibleRegion&quot;&gt;
&lt;div class=&quot;CollapseRegionLink&quot;&gt;
&lt;img class=&quot;LibC_o&quot; src=&quot;http://i.msdn.microsoft.com/Global/Images/clear.gif&quot; style=&quot;border-width: 0px; vertical-align: middle;&quot; /&gt;
&amp;nbsp;Figure 2 Inappropriate Intimacy
&lt;/div&gt;
&lt;div class=&quot;MTPS_CollapsibleSection&quot; style=&quot;display: block;&quot;&gt;
&lt;span id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl22_ctl00_ctl00&quot;&gt;
&lt;div class=&quot;libCScode&quot; id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl22_ctl00_ctl00_&quot;&gt;
&lt;div class=&quot;CodeSnippetTitleBar&quot;&gt;
&lt;div class=&quot;CodeDisplayLanguage&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;background-color: #dddddd;&quot;&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl22_ctl00_ctl00_code&quot;&gt;public void Process() {
  string connectionString = getConnectionString();
  SqlConnection connection = new SqlConnection(connectionString);
  DataServer1 server = new DataServer1(connection);

  int daysOld = 5;
  using (SqlDataReader reader = server.GetWorkItemData(daysOld)) {
    while (reader.Read()) {
      string name = reader.GetString(0);
      string location = reader.GetString(1);

      processItem(name, location); 
    }
  }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/span&gt;
                                                  
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070029&quot;&gt;
Now, let&#39;s rewrite the code in &lt;b&gt;Figure 2&lt;/b&gt; to remove the inappropriate intimacy:&lt;/div&gt;
&lt;span id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl06&quot;&gt;
&lt;div class=&quot;libCScode&quot; id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl06_&quot;&gt;
&lt;div class=&quot;CodeSnippetTitleBar&quot;&gt;
&lt;div class=&quot;CodeDisplayLanguage&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;background-color: #dddddd;&quot;&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl06_code&quot;&gt;public void Process() {
  DataServer2 server = new DataServer2();
  foreach (DataItem item in server.GetWorkItemData(5)) {
    processItem(item);
  }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/span&gt;
                                        &lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070036&quot;&gt;
As
 you can see in this version of the code, I&#39;ve encapsulated all the 
SqlConnection and SqlDataReader object manipulation inside the 
DataServer2 class. DataServer2 is also assumed to be taking care of its 
own configuration, so the new Process method doesn&#39;t have to know 
anything about setting up DataServer2. The DataItem objects returned 
from GetWorkItemData are also strongly typed objects.&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070037&quot;&gt;
Now,
 let&#39;s analyze the two versions of Process method against some of the 
goals of loose coupling. First, what about making the code easier to 
read? The first and second versions of Process perform the same basic 
task, but which is easier to read and understand? Personally, I can more
 easily read and understand the business logic processing without wading
 through data-access code.&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070038&quot;&gt;
How
 about making our classes easier to consume? Consumers of DataServer1 
have to know how to create a SqlConnection object, understand the 
structure of the DataReader returned, and iterate through and clean up 
the DataReader. A consumer of DataServer2 only has to call a no-argument
 constructor and then call a single method that returns an array of 
strongly typed objects. DataServer2 is taking care of its own ADO.NET 
connection setup and cleaning up open DataReaders. &lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070039&quot;&gt;
And
 as for isolating potential changes to a small area of code? In the 
first version of the code, almost any change in the way DataServer works
 would impact the Process method. In the second, more encapsulated 
version of DataServer, you could switch the data store to an Oracle 
database or to an XML file without any effect on the Process method. &lt;/div&gt;
&lt;br /&gt;
                                        &lt;div class=&quot;ArticleTypeTitle&quot; id=&quot;id0070040&quot;&gt;
The Law of Demeter&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070041&quot;&gt;
The
 Law of Demeter is a design rule of thumb. The terse definition of the 
law is: only talk to your immediate friends. The Law of Demeter is a 
warning about the potential dangers of code, as in &lt;b&gt;Figure 3&lt;/b&gt;.&lt;/div&gt;
&lt;div class=&quot;figmargin&quot; id=&quot;id019&quot;&gt;
&lt;div class=&quot;MTPS_CollapsibleRegion&quot;&gt;
&lt;div class=&quot;CollapseRegionLink&quot;&gt;
&lt;img class=&quot;LibC_o&quot; src=&quot;http://i.msdn.microsoft.com/Global/Images/clear.gif&quot; style=&quot;border-width: 0px; vertical-align: middle;&quot; /&gt;
&amp;nbsp;Figure 3 Breaking the Law
&lt;/div&gt;
&lt;div class=&quot;MTPS_CollapsibleSection&quot; style=&quot;display: block;&quot;&gt;
&lt;span id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl24_ctl00_ctl00&quot;&gt;
&lt;div class=&quot;libCScode&quot; id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl24_ctl00_ctl00_&quot;&gt;
&lt;div class=&quot;CodeSnippetTitleBar&quot;&gt;
&lt;div class=&quot;CodeDisplayLanguage&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;background-color: #dddddd;&quot;&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl24_ctl00_ctl00_code&quot;&gt;public interface DataService {
  InsuranceClaim[] FindClaims(Customer customer);
}

public class Repository {
  public DataService InnerService { get; set; }
}

public class ClassThatNeedsInsuranceClaim {
  private Repository _repository;

  public ClassThatNeedsInsuranceClaim(Repository repository) {
    _repository = repository;
  }

  public void TallyAllTheOutstandingClaims(Customer customer) {
    // This line of code violates the Law of Demeter
    InsuranceClaim[] claims = 
      _repository.InnerService.FindClaims(customer);
  }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/span&gt;
                                                  
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070042&quot;&gt;
The
 ClassThatNeedsInsuranceClaim class needs to get InsuranceClaim data. It
 has a reference to the Repository class, which itself has a DataService
 object. ClassThatNeedsInsuranceClaim reaches inside Repository to grab 
the inner DataService object, then calls Repository.FindClaims to get 
its data. Note that the call to 
_repository.InnerService.FindClaims(customer) is a clear violation of 
the Law of Demeter because ClassThatNeedsInsuranceClaim is directly 
calling a method on a property of its Repository field. Now please turn 
your attention to &lt;b&gt;Figure 4&lt;/b&gt;, which shows another sample of the same code, but this time it is following the Law of Demeter.&lt;/div&gt;
&lt;div class=&quot;figmargin&quot; id=&quot;id021&quot;&gt;
&lt;div class=&quot;MTPS_CollapsibleRegion&quot;&gt;
&lt;div class=&quot;CollapseRegionLink&quot;&gt;
&lt;img class=&quot;LibC_o&quot; src=&quot;http://i.msdn.microsoft.com/Global/Images/clear.gif&quot; style=&quot;border-width: 0px; vertical-align: middle;&quot; /&gt;
&amp;nbsp;Figure 4 Better Decoupling
&lt;/div&gt;
&lt;div class=&quot;MTPS_CollapsibleSection&quot; style=&quot;display: block;&quot;&gt;
&lt;span id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl25_ctl00_ctl00&quot;&gt;
&lt;div class=&quot;libCScode&quot; id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl25_ctl00_ctl00_&quot;&gt;
&lt;div class=&quot;CodeSnippetTitleBar&quot;&gt;
&lt;div class=&quot;CodeDisplayLanguage&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;background-color: #dddddd;&quot;&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl25_ctl00_ctl00_code&quot;&gt;public class Repository2 {
  private DataService _service;

  public Repository2(DataService service) {
    _service = service;
  }

  public InsuranceClaim[] FindClaims(Customer customer) {
    // we&#39;re simply going to delegate to the inner
    // DataService for now, but who knows what 
    // we want to do in the future?
    return _service.FindClaims(customer);
  }
}

public class ClassThatNeedsInsuranceClaim2 {
  private Repository2 _repository;

  public ClassThatNeedsInsuranceClaim2(
    Repository2 repository) {
    _repository = repository;
  }

  public void TallyAllTheOutstandingClaims(
    Customer customer) {
    // This line of code now follows the Law of Demeter
    InsuranceClaim[] claims = _repository.FindClaims(customer);
  }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/span&gt;
                                                  
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070043&quot;&gt;
What
 did we accomplish? Repository2 is easier to use than Repository because
 you have a direct method to call for the InsuranceClaim information. 
When we were violating the Law of Demeter, the consumers of Repository 
were tightly coupled to the implementation of Repository. With the 
revised code, I have more ability to change the Repository 
implementation to add more caching or swap out the underlying 
DataService with something completely different. &lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070044&quot;&gt;
The
 Law of Demeter is a powerful tool to help you spot potential coupling 
problems, but don&#39;t follow the Law of Demeter blindly. Violating the Law
 of Demeter does add tighter coupling to your system, but in some cases 
you may judge that the potential cost of coupling to a stable element of
 your code is less expensive than writing a lot of delegation code to 
eliminate the Law of Demeter violations. &lt;/div&gt;
&lt;br /&gt;
                                        &lt;div class=&quot;ArticleTypeTitle&quot; id=&quot;id0070045&quot;&gt;
Tell, Don&#39;t Ask&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070046&quot;&gt;
The
 Tell, Don&#39;t Ask design principle urges you to tell objects what to do. 
What you don&#39;t want to do is ask an object about its internal state, 
make some decisions about that state, then tell that object what to do. 
Following the Tell, Don&#39;t Ask style of object interaction is a good way 
to ensure that responsibilities are put in the right places. &lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070047&quot;&gt;
&lt;b&gt;Figure 5&lt;/b&gt;
 illustrates a violation of Tell, Don&#39;t Ask. The code is taking a 
purchase of some sort, checking for the possibility of a discount for 
purchases of more than $10,000, and finally examining the account data 
to decide whether there are sufficient funds. The previous DumbPurchase 
and DumbAccount classes are, well, dumb. The account and purchase 
business rules are both encoded in ClassThatUsesDumbEntities. &lt;/div&gt;
&lt;div class=&quot;figmargin&quot; id=&quot;id023&quot;&gt;
&lt;div class=&quot;MTPS_CollapsibleRegion&quot;&gt;
&lt;div class=&quot;CollapseRegionLink&quot;&gt;
&lt;img class=&quot;LibC_o&quot; src=&quot;http://i.msdn.microsoft.com/Global/Images/clear.gif&quot; style=&quot;border-width: 0px; vertical-align: middle;&quot; /&gt;
&amp;nbsp;Figure 5 Asking Too Much
&lt;/div&gt;
&lt;div class=&quot;MTPS_CollapsibleSection&quot; style=&quot;display: block;&quot;&gt;
&lt;span id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl26_ctl00_ctl00&quot;&gt;
&lt;div class=&quot;libCScode&quot; id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl26_ctl00_ctl00_&quot;&gt;
&lt;div class=&quot;CodeSnippetTitleBar&quot;&gt;
&lt;div class=&quot;CodeDisplayLanguage&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;background-color: #dddddd;&quot;&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl26_ctl00_ctl00_code&quot;&gt;public class DumbPurchase {
  public double SubTotal { get; set; }
  public double Discount { get; set; }
  public double Total { get; set; }
}

public class DumbAccount {
  public double Balance { get; set;}
}

public class ClassThatUsesDumbEntities {
  public void MakePurchase(
    DumbPurchase purchase, DumbAccount account) {
    purchase.Discount = purchase.SubTotal &amp;gt; 10000 ? .10 : 0;
    purchase.Total = 
      purchase.SubTotal*(1 - purchase.Discount);

    if (purchase.Total &amp;lt; account.Balance) {
      account.Balance -= purchase.Total;
    }
    else {
      rejectPurchase(purchase, 
        &quot;You don&#39;t have enough money.&quot;);
    }
  }
} &lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/span&gt;
                                                  
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070048&quot;&gt;
This
 type of code can be problematic in a couple of ways. In a system like 
this, you potentially have duplication because the business rules for an
 entity are scattered in procedural code outside of the entities. You 
might duplicate logic unknowingly because it&#39;s not obvious where the 
previously written business logic would be. &lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070049&quot;&gt;
&lt;b&gt;Figure 6&lt;/b&gt;
 shows the same code, but this time following the Tell, Don&#39;t Ask 
pattern. In this code, I moved the business rules for purchasing and 
accounts into the Purchase and Account classes themselves. When we go to
 make a purchase, we just tell the Account class to deduct the purchase 
from itself. Account and Purchase know about themselves and their 
internal rules. All a consumer of Account has to know is to call the 
Account.Deduct(Purchase, PurchaseMessenger) method.&lt;/div&gt;
&lt;div class=&quot;figmargin&quot; id=&quot;id025&quot;&gt;
&lt;div class=&quot;MTPS_CollapsibleRegion&quot;&gt;
&lt;div class=&quot;CollapseRegionLink&quot;&gt;
&lt;img class=&quot;LibC_o&quot; src=&quot;http://i.msdn.microsoft.com/Global/Images/clear.gif&quot; style=&quot;border-width: 0px; vertical-align: middle;&quot; /&gt;
&amp;nbsp;Figure 6 Telling Your App What to Do
&lt;/div&gt;
&lt;div class=&quot;MTPS_CollapsibleSection&quot; style=&quot;display: block;&quot;&gt;
&lt;span id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl27_ctl00_ctl00&quot;&gt;
&lt;div class=&quot;libCScode&quot; id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl27_ctl00_ctl00_&quot;&gt;
&lt;div class=&quot;CodeSnippetTitleBar&quot;&gt;
&lt;div class=&quot;CodeDisplayLanguage&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;background-color: #dddddd;&quot;&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTContentSelector1_mainContentContainer_ctl27_ctl00_ctl00_code&quot;&gt;public class Purchase {
  private readonly double _subTotal;

  public Purchase(double subTotal) {
    _subTotal = subTotal;
  }

  public double Total {
    get {
      double discount = _subTotal &amp;gt; 10000 ? .10 : 0;
      return _subTotal*(1 - discount);
    }
  }
}

public class Account {
  private double _balance;

  public void Deduct(
    Purchase purchase, PurchaseMessenger messenger) {
    if (purchase.Total &amp;lt; _balance) {
      _balance -= purchase.Total;
    }
    else {
      messenger.RejectPurchase(purchase, this);
    }
  }
}

public class ClassThatObeysTellDontAsk {
  public void MakePurchase(
    Purchase purchase, Account account) {
    PurchaseMessenger messenger = new PurchaseMessenger();
    account.Deduct(purchase, messenger);
  }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/span&gt;
                                                  
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070050&quot;&gt;
The
 Account and Purchase objects are easier to use because you don&#39;t have 
to know quite so much about these classes to execute our business logic.
 We&#39;ve also potentially reduced duplication in the system. The business 
rules for Accounts and Purchases can be effortlessly reused throughout 
the system because those rules are inside the Account and Purchase 
classes instead of being buried inside the code that uses those classes.
 In addition, it should be easier to change the business rules for 
Purchases and Accounts as those rules are found in just one place in the
 system.&lt;/div&gt;
&lt;div class=&quot;ArticleNormalPara&quot; id=&quot;id0070051&quot;&gt;
Closely
 related to Tell, Don&#39;t Ask is the Information Expert pattern. If you 
have a new responsibility for your system, in what class should the new 
responsibility go? The Information Expert pattern asks, who knows the 
information necessary to fulfill this responsibility? In other words, 
your first candidate for any new responsibility is the class that 
already has the data fields affected by that responsibility. In the 
purchasing sample, the Purchase class knows the information about a 
purchase that you would use to determine any possible discount rates, so
 the Purchase class itself is the immediate candidate for calculating 
discount rates. &lt;/div&gt;
&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://syednisarbukhari.blogspot.com/feeds/754772708485535120/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8738129253178686232/754772708485535120' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/754772708485535120'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8738129253178686232/posts/default/754772708485535120'/><link rel='alternate' type='text/html' href='http://syednisarbukhari.blogspot.com/2011/12/patterns-in-practicecohesion-and.html' title='Patterns in Practice..Cohesion And Coupling'/><author><name>Syed Nisar Bukhari</name><uri>http://www.blogger.com/profile/13557733006614710346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='30' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHsq903LQfB_RB8a3dDw_BqfpGauwOV2VDH6f-72JrwfY6UpVfa4Z-hfYccTSCrMxSxBZgdFU1QrpuzY38mFY2F6GkyE7i4RWWBWurPn06hy4WDC0E6M2A_uNau_qv1g/s121/m.jpg'/></author><thr:total>0</thr:total></entry></feed>