<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>.NET Geek&#039;s Blog</title>
	<atom:link href="http://kiransalke.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://kiransalke.wordpress.com</link>
	<description>Some interesting things for .Net Geek&#039;s</description>
	<lastBuildDate>Sat, 24 Jul 2010 12:19:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='kiransalke.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>.NET Geek&#039;s Blog</title>
		<link>http://kiransalke.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://kiransalke.wordpress.com/osd.xml" title=".NET Geek&#039;s Blog" />
	<atom:link rel='hub' href='http://kiransalke.wordpress.com/?pushpress=hub'/>
		<item>
		<title>The Simplicity of Complexity &#8211; The Mandelbrot Set</title>
		<link>http://kiransalke.wordpress.com/2010/07/24/the-simplicity-of-complexity-the-mandelbrot-set/</link>
		<comments>http://kiransalke.wordpress.com/2010/07/24/the-simplicity-of-complexity-the-mandelbrot-set/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 12:19:21 +0000</pubDate>
		<dc:creator>Kiran Salke</dc:creator>
				<category><![CDATA[Others]]></category>

		<guid isPermaLink="false">http://kiransalke.wordpress.com/?p=103</guid>
		<description><![CDATA[The Simplicity of Complexity &#8211; The Mandelbrot Set The MANDELBROT SET is the most complex object in mathematics, its admirers like to say. An eternity would not be enough time to see it all, its disks studded with prickly thorns, its spirals and filaments curling outward and around, bearing bulbous molecules that hang, infinitely variegated, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=103&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>The Simplicity of Complexity &#8211; The Mandelbrot Set</h3>
<p>The MANDELBROT SET is the most complex object in mathematics, its admirers like to say. An eternity would not be enough time to see it all, its disks studded with prickly thorns, its spirals and filaments curling outward and around, bearing bulbous molecules that hang, infinitely variegated, like grapes on God&#8217;s personal vine &#8211; James Gleick in Chaos, Making a New Science.</p>
<p>This project was a brief exploration into the mind-boggling and beautiful world of mathematical complexity, by way of the most famous example of fractal geometry, called the Mandelbrot set. Because of the VisualBots built-in color graphics and user-defined coordinate system features, it is actually quite easy to explore this amazing object.</p>
<p>Above are various windows in the complex plane, rendering the Mandelbrot fractal using the built-in graphics capabilities of the VisualBots simulator.</p>
<h3><strong>Background</strong></h3>
<p>The Mandelbrot set was named after the work of mathematician Benoit Mandelbrot in the 1980&#8242;s, who was one of the early researchers in the field of dynamic complexity. The Mandelbrot set has a fractal-like geometry, which means that it exhibits self-similarity at multiple scales. However, the small-scale details are not identical to the whole, and in fact, the set is infinitely complex, revealing new geometric surprises at ever increasing magnification. Belying this mind-boggling complexity is the extremely simple mathematic process used to produce it.</p>
<p>The Mandelbrot set is a set of complex numbers (remember in algebra &#8211; the points in the 2D complex plane with real and imaginary axes?). Every complex number is either in the set, or outside of it. The set is generated by applying a simple iterative process to each complex number. In mathematical jargon, it is defined by all of the complex numbers C for which the number sequence</p>
<p>is bounded, or does not tend towards infinity.</p>
<p>In other words, to generate the set, take a complex number, multiply it by itself, and add it to the original number; take that result, multiply it by itself, and add it to the original number; and so on. If the resulting numbers generated during the iteration process grows ever and ever larger, then the original complex number C is not in the Mandelbrot set. If the sequence converges, drifts chaotically, or cycles periodically, then C is in the set. Of course in practice we cannot apply the iteration process an infinite number of times to be sure that C is a member of the set. So instead, the process is applied several hundred or several thousand times, and if the sequence remains relatively small during these iterations, then it is assumed that C is probably a member of the set. Fortunately, there is a very useful criteria for detecting divergence &#8211; it can be demonstrated mathematically that if during the iteration process the number sequence exceeds the absolute value of 2, then the sequence will diverge to infinity and the original number C is definitely outside of the set. Many points reach a value that exceeds 2 after only a few iterations.</p>
<p>The typical means of graphically rendering the Mandelbrot fractal is to color points in the complex plane that belong to the set as black, and all other points outside of the set according to how quickly they diverge towards infinity. The speed at which points outside of the set diverge, sometimes referred to as &#8220;escape speed&#8221;, is measured by how many iterations of the number sequence are required until divergence is detected.</p>
<p>It turns out that the Mandelbrot set lives very close to the origin of the complex plane, within a radius of 2. The most interesting regions are found near the boundaries of the set, where the escape speeds are relatively higher than those farther away. Zooming down into these regions exposes a remarkable variation of self-similar structures.</p>
<p>In the Mandelbrot set, nature (or is it mathematics) provides us with a powerful visual counterpart of the musical idea of &#8216;theme and variation&#8217;: the shapes are repeated everywhere, yet each repetition is somewhat different. It would have been impossible to discover this property of iteration if we had been reduced to hand calculation, and I think that no one would have been sufficiently bright or ingenious to &#8216;invent&#8217; this rich and complicated theme and variations. It leaves us no way to become bored, because new things appear all the time, and no way to become lost, because familiar things come back time and time again. Because this constant novelty, this set is not truly fractal by most definitions; we may call it a borderline fractal, a limit fractal that contains many fractals. Compared to actual fractals, its structures are more numerous, its harmonies are richer, and its unexpectedness is more unexpected &#8211; Benoit Mandelbrot.<br />
Above is the highest-elevation view of the Mandelbrot set (the portions colored black). The set does not extend beyond a radius of 2 in the complex plane.</p>
<p>One amazing aspect of the Mandelbrot set that was proved by Hubbard and Douady of the University of Paris, is that it is connected, meaning that there are no islands of points in the set that are isolated from the rest. Many apparently isolated &#8220;molecules&#8221; of the set can be observed at high magnification, but the appearance is deceiving, because each of these are connected to the rest of the set by very thin filaments. Other interesting aspects are that the perimeter of the set has an infinite length, and that its area is unknown.</p>
<h3>VisualBots Implementation</h3>
<p>The algorithm for generating the Mandelbrot fractal is very simple:</p>
<p>1. Cycle through all screen pixels, converting each to its respective complex plane coordinates<br />
2. Determine whether or not the pixels are in the Mandelbrot set<br />
3. If they are in the set, color black, otherwise color based on their escape speed</p>
<p>The following pseudo code renders a specified window in the complex plane:</p>
<p>Set the screen coordinate system to bracket the window of interest<br />
Color the screen background black<br />
maxiter=1000 (setting maxiter to smaller value trades-off resolution for computational speed)<br />
For each screen pixel do the following:<br />
R0 = calculate the real coordinate of pixel<br />
I0 = calculate the imaginary coordinate of pixel<br />
R = R0<br />
I = I0<br />
R2 = R * R<br />
I2 = I * I<br />
iter = 0<br />
While (R2 + I2 &lt; 4) And (iter &lt; maxiter) Do:<br />
I = 2 * R * I + I0<br />
R = R2 &#8211; I2 + R0<br />
R2 = R * R<br />
I2 = I * I<br />
iter = iter + 1<br />
Loop<br />
If iter &lt; maxiter Then<br />
color the pixel according to value of iter<br />
End If<br />
Next screen pixel</p>
<p>To assign color to each screen pixel, we created a single Bot object, gave it a point shape, and set its Footprint property to True. With this combination of settings, the Bot imparts a &#8220;footprint&#8221; of color as it is moved from pixel to pixel. The color of the footprint is calculated using the FillColorPick method of the Bot object, which selects a entry point into the assigned ColorTable based on a variable, in this case, &#8220;iter&#8221;.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kiransalke.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kiransalke.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kiransalke.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kiransalke.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kiransalke.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kiransalke.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kiransalke.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kiransalke.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kiransalke.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kiransalke.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kiransalke.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kiransalke.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kiransalke.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kiransalke.wordpress.com/103/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=103&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kiransalke.wordpress.com/2010/07/24/the-simplicity-of-complexity-the-mandelbrot-set/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9898d57098670c611a10f570a7564007?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkiran33</media:title>
		</media:content>
	</item>
		<item>
		<title>Introducing MVVM &#8211; Model View ViewModel</title>
		<link>http://kiransalke.wordpress.com/2010/07/13/introducing-mvvm-model-view-viewmodel/</link>
		<comments>http://kiransalke.wordpress.com/2010/07/13/introducing-mvvm-model-view-viewmodel/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 10:28:46 +0000</pubDate>
		<dc:creator>Kiran Salke</dc:creator>
				<category><![CDATA[Silverlight & Composite Application Guidance]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[View Model]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://kiransalke.wordpress.com/?p=97</guid>
		<description><![CDATA[What is MVVM? MVVM is the most popular architectural pattern used in Windows Presentation Foundation (WPF) and Silverlight. It is designed to make use of specific functions in WPF/Silverlight to better facilitate the separation of View layer development from the rest of the pattern by removing virtually all “code behind” from View layer, taking advantage [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=97&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2><a href="http://en.wikipedia.org/wiki/Model_View_ViewModel">What is  MVVM?</a></h2>
<p>MVVM is the most popular architectural pattern used in Windows  Presentation Foundation (WPF) and Silverlight.  It is designed to make  use of specific functions in WPF/Silverlight to better facilitate the  separation of View layer development from the rest of the pattern by  removing virtually all “code behind” from View layer, taking advantage  of <a href="http://msdn.microsoft.com/en-us/library/cc189022%28VS.96%29.aspx">Binding  Markup Extension</a> from <a href="http://msdn.microsoft.com/en-us/library/cc189036%28VS.96%29.aspx">XAML</a>.   This separation of roles allows interactive designers to focus on UX  needs rather than programming or business logic, allowing for the layers  of an application to be developed in multiple work streams.</p>
<p>A MVVM solution consist <strong>View</strong> as pure XAML with default  code-behind implementation.  A <strong>View Model</strong> is declared and  initiated somewhere in the XAML with detailed bindings to its properties  and commands.  Left with <strong>Model</strong>s as the data presentation classes  managed by ViewModels.</p>
<p>Now we know that Views should be in pure XAML, and Models are just  classes that represent the real state of data.  Hence, what is actually  in the ViewModel?</p>
<p>To create a ViewModel, we need expose properties and commands required  by a View, notify the binding framework when a property needs to  reflected in the View, and manage the data underneath.</p>
<h3>Exposing Properties and Commands via ViewModel</h3>
<p>A ViewModel is responsible for establishing properties required by View  from a Model.  Say we have a table containing a list of greetings in  different languages.</p>
<ul>
<li>English, Hello</li>
<li>Taiwanese(Hokkien), Li-ho</li>
<li>Mandarin, nǐ hǎo</li>
</ul>
<p>The model will look like this:</p>
<div>
<div id="highlighter_269529">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<h3>
<div><strong><span style="color:#339966;"><code>public</code> <code>class</code> <code>Greeting</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>{</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>public</code> <code>string</code> <code>LanguageName {</code><code>get</code><code>;</code><code>set</code><code>;}</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>public</code> <code>string</code> <code>Dialogue {</code><code>get</code><code>;</code><code>set</code><code>;}</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>}</code></span></strong></div>
</h3>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>A ViewModel that makes this model available to a view will look like  this:</p>
<div>
<h3 id="highlighter_99932">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>
<div><strong><span style="color:#339966;"><code>public</code> <code>class</code> <code>GreetingViewModel :  System.ComponentModel.INotifyPropertyChanged</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>{</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>/// &lt;summary&gt;</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>/// Implement the INotifyPropertyChanged interface  (preferred).</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>/// For  change notification to occur in a binding between a bound client and a  data source.</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>///  &lt;/summary&gt;</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>public</code> <code>event</code> <code>System.ComponentModel.PropertyChangedEventHandler  PropertyChanged;</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>public</code> <code>string</code> <code>LanguageName </code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>{</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>get</code><code>{</code><code>return</code> <code>_model.LanguageName;  }</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>set</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>{</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>_model.LanguageName = value;</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>if</code><code>(PropertyChanged  != </code><code>null</code><code>)</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>PropertyChanged(</code><code>this</code><code>, </code><code>new</code> <code>System.ComponentModel.PropertyChangedEventArgs(</code><code>"LanguageName"</code><code>));</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>}</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>}</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>public</code> <code>string</code> <code>Dialogue </code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>{</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>get</code><code>{</code><code>return</code> <code>_model.Dialogue;}</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>set</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>{</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>_model.Dialogue = value;</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>if</code><code>(PropertyChanged  != </code><code>null</code><code>)</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>PropertyChanged(</code><code>this</code><code>, </code><code>new</code> <code>System.ComponentModel.PropertyChangedEventArgs(</code><code>"Dialogue"</code><code>));</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>}</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>}</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>}</code></span></strong></div>
</div>
</td>
</tr>
</tbody>
</table>
</h3>
</div>
<p>Notice that in the ViewModel we implement <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx">INotifyPropertyChanged</a>?   The aim is to notify the binding framework when a property is updated  via the set method, the property will then be reflected in the View  without extra effort.</p>
<p>Exposing an property in ViewModel seems to be fairly straight forward.   One improvement you might make is to write a method to assist the  notification.  You will find other advance extension that some nice  people have came up on the World Wide Web.</p>
<div>
<div id="highlighter_966218">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<h3>
<div><strong><span style="color:#339966;"><code>/// &lt;summary&gt;</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>///  Implement the INotifyPropertyChanged interface (preferred).</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>/// For  change notification to occur in a binding between a bound client and a  data source.</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>/// &lt;/summary&gt;</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>public</code> <code>event</code> <code>System.ComponentModel.PropertyChangedEventHandler  PropertyChanged;</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>private</code> <code>void</code> <code>NotifyPropertyChanged(</code><code>string</code> <code>propertyName)</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>{</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>if</code> <code>(PropertyChanged  != </code><code>null</code><code>)</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>PropertyChanged(</code><code>this</code><code>, </code><code>new</code> <code>System.ComponentModel.PropertyChangedEventArgs(propertyName));</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>}</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>public</code> <code>string</code> <code>LanguageName</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>{</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>get</code> <code>{ </code><code>return</code> <code>_model.LanguageName;  }</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>set</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>{</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>_model.LanguageName = value;</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>NotifyPropertyChanged(</code><code>"LanguageName"</code><code>);</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>}</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>}</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>public</code> <code>string</code> <code>Dialogue</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>{</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>get</code> <code>{ </code><code>return</code> <code>_model.Dialogue;  }</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>set</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>{</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>_model.Dialogue = value;</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>NotifyPropertyChanged(</code><code>"Dialogue"</code><code>);</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>}</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>}</code></span></strong></div>
</h3>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>Now we have a simple ViewModel, let us look at how we would bind it onto  XAML.</p>
<div>
<div id="highlighter_489281">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<h3>
<div><strong><span style="color:#339966;"><code>&lt;</code><code>UserControl.Resources</code><code>&gt;</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>&lt;</code><code>vm:GreetingViewModel</code> <code>x:Key</code><code>=</code><code>"VM"</code><code>/&gt;</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>&lt;/</code><code>UserControl.Resources</code><code>&gt;</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>&lt;</code><code>Grid</code> <code>x:Name</code><code>=</code><code>"LayoutRoot"</code> <code>Background</code><code>=</code><code>"White"</code> <code>DataContext</code><code>=</code><code>"{StaticResource  VM}"</code><code>&gt; </code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>&lt;</code><code>StackPanel</code><code>&gt;</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>&lt;</code><code>TextBlock</code> <code>FontWeight</code><code>=</code><code>"Bold"</code> <code>Text</code><code>=</code><code>"{Binding Dialogue, Mode=OneWay}"</code><code>/&gt;</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>&lt;</code><code>TextBox</code> <code>Text</code><code>=</code><code>"{Binding  LanguageName, Mode=TwoWay}"</code><code>/&gt;</code></span></strong></div>
<div><strong><span style="color:#339966;"><code> </code><code>&lt;/</code><code>StackPanel</code><code>&gt;</code></span></strong></div>
<div><strong><span style="color:#339966;"><code>&lt;/</code><code>Grid</code><code>&gt;</code></span></strong></div>
</h3>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>For more information on Binding visit <a href="http://msdn.microsoft.com/en-us/library/cc189022%28VS.95%29.aspx">Binding  Markup Extension</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kiransalke.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kiransalke.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kiransalke.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kiransalke.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kiransalke.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kiransalke.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kiransalke.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kiransalke.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kiransalke.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kiransalke.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kiransalke.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kiransalke.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kiransalke.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kiransalke.wordpress.com/97/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=97&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kiransalke.wordpress.com/2010/07/13/introducing-mvvm-model-view-viewmodel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9898d57098670c611a10f570a7564007?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkiran33</media:title>
		</media:content>
	</item>
		<item>
		<title>Stored Procedures</title>
		<link>http://kiransalke.wordpress.com/2010/07/07/stored-procedures/</link>
		<comments>http://kiransalke.wordpress.com/2010/07/07/stored-procedures/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 09:42:13 +0000</pubDate>
		<dc:creator>Kiran Salke</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SP]]></category>
		<category><![CDATA[sproc]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Stored Procedures]]></category>

		<guid isPermaLink="false">http://kiransalke.wordpress.com/?p=93</guid>
		<description><![CDATA[Stores Procedure A stored procedure is a subroutine available to applications accessing a relational database system. Stored procedures (sometimes called a proc, sproc, StoPro, StoredProc, or SP) are actually stored in the database data dictionary. Typical uses for stored procedures include data validation (integrated into the database) or access control mechanisms. Furthermore, stored procedures are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=93&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3><strong>Stores Procedure</strong></h3>
<p>A <strong>stored procedure</strong> is a <a href="http://www.answers.com/topic/subroutine" target="_top">subroutine</a> available to applications accessing a <a href="http://www.answers.com/topic/relational-database" target="_top">relational</a> <a href="http://www.answers.com/topic/database-management-system" target="_top">database  system</a>. Stored procedures (sometimes called a <strong>proc</strong>, <strong>sproc</strong>,  <strong>StoPro</strong>, <strong>StoredProc</strong>, or <strong>SP</strong>) are actually stored in  the database <a href="http://www.answers.com/topic/data-dictionary" target="_top">data  dictionary</a>.</p>
<p>Typical uses for stored procedures include <a href="http://www.answers.com/topic/data-validation" target="_top">data  validation</a> (integrated into the database) or <a href="http://www.answers.com/topic/access-control" target="_top">access  control</a> mechanisms. Furthermore, stored procedures are used to  consolidate and centralize logic that was originally implemented in  applications. Large or complex processing that might require the  execution of several <a href="http://www.answers.com/topic/sql" target="_top">SQL</a> statements is moved into stored procedures, and all applications call  the procedures only.We can use nested stored procedures, by executing  one stored procedure in another. The maximum level of nesting is 32. <sup><a href="http://www.answers.com/topic/stored-procedure#cite_note-0">[1]</a></sup></p>
<p>Stored procedures are similar to <a href="http://www.answers.com/topic/user-defined-function-1" target="_top">user-defined  functions</a> (UDFs). The major difference is that UDFs can be used  like any other expression within SQL statements, whereas stored  procedures must be invoked using the <code>CALL</code> statement <sup><a href="http://www.answers.com/topic/stored-procedure#cite_note-1">[2]</a></sup></p>
<pre>CALL procedure(…)
</pre>
<p>or</p>
<pre>EXECUTE procedure(…)
</pre>
<p>Stored procedures may return <a href="http://www.answers.com/topic/result-set" target="_top">result  sets</a>, <em>i.e.</em> the results of a <code>SELECT</code> statement.  Such result sets can be processed using <a href="http://www.answers.com/topic/cursor-databases" target="_top">cursors</a> by other stored procedures by associating a result set locator, or by  applications. Stored procedures may also contain declared variables for  processing data and cursors that allow it to loop through multiple rows  in a table. The standard Structured Query Language provides <code>IF</code>,  <code>WHILE</code>, <code>LOOP</code>, <code>REPEAT</code>, <code>CASE</code> statements, and more. Stored procedures can receive variables, return  results or modify variables and return them, depending on how and where  the variable is declared.</p>
<h3>Comparison  with dynamic SQL</h3>
<p><strong>Overhead:</strong> Because stored procedure statements are stored  directly in the database, this <em>may</em> remove all or part of the  compilation overhead that is typically required in situations where  software applications send inline (dynamic) SQL queries to a database.  (However, most database systems implement &#8220;statement caches&#8221; and other  mechanisms to avoid repetitive compilation of dynamic SQL statements.)  In addition, pre-compiled SQL statements, while avoiding some overhead,  add to the complexity of creating an optimal execution plan because not  all arguments of the SQL statement are supplied at compile time.  Depending on the specific database implementation and configuration,  mixed performance results will be seen from stored procedures versus  generic queries or user defined functions.</p>
<p><strong>Avoidance of network traffic:</strong> A major  advantage with stored procedures is that they can run directly within  the database engine. In a production system, this typically means that  the procedures run entirely on a specialized database server, which has  direct access to the data being accessed. The benefit here is that  network communication costs can be avoided completely. This becomes  particularly important for complex series of SQL statements.</p>
<p><strong>Encapsulation of business logic:</strong> Stored procedures allow for <a href="http://www.answers.com/topic/business-logic" target="_top">business  logic</a> to be embedded as an API in the database, which can simplify  data management and reduce the need to encode the logic elsewhere in  client programs. This may result in a lesser likelihood of data becoming  corrupted through the use of faulty client programs. Thus, the database  system can ensure data integrity and consistency with the help of  stored procedures.</p>
<p><strong>Delegation of access-rights:</strong> In many systems,  stored-procedures can be granted access rights to the database which the  users who will execute those procedures do not directly have. Thus, the  stored procedure becomes the only way that these users have, to do  whatever the stored procedure does.</p>
<p><strong>Some protection from SQL injection attacks:</strong> Stored procedures  can be used to protect against this attack. The parameters will be  treated as data even if an attacker inserts SQL commands. Also some DBMS  will check the parameter&#8217;s type.</p>
<h3>Comparison  with functions</h3>
<ul>
<li>A function is a subprogram written to perform certain computations  and return a single value.</li>
<li>Functions must return a value (using the <code>RETURN</code> keyword), but for stored procedures this is not compulsory.</li>
<li>Stored procedures can use <code>RETURN</code> keyword but without  any value being passed.</li>
<li>Functions could be used in <code>SELECT</code> statements, provided  they don’t do any data manipulation. However, procedures cannot be  included in <code>SELECT</code> statements.</li>
<li>A function can have only <code>IN</code> parameters, while stored  procedures may have <code>OUT</code> or <code>INOUT</code> parameters.</li>
<li>A stored procedure can return multiple values using the <code>OUT</code> parameter or return no value at all.</li>
</ul>
<h3>Disadvantages</h3>
<p>Stored procedures are &#8220;defined once, used many times.&#8221; If any changes  are necessary, the (one and only one) definition of the stored  procedure must be replaced. Dynamic SQL, of course, allows any SQL query  to be issued at any time. Any change to a stored procedure instantly  impacts every other piece of software, report, etc. (inside or outside  of the DBMS) which directly or indirectly refers to it. It is not always  possible to determine with certainty exactly what those impacts will  be, nor what changes can safely be made without adversely impacting  something else.</p>
<p>For various reasons, many organizations strictly limit who is allowed  to define and issue a query against the database. Programmers and other  users may therefore find themselves having no choice but to implement  inefficient solutions to their problems using what stored procedures are  available to them, whether or not the procedures are appropriate for  this particular ancillary task.</p>
<p>Though not directly related to stored procedures, the movement of  business logic to the DBMS is problematic since it is the layer with the  more complex scalability issues. Furthermore, some modern DBMS systems  (notably from Microsoft SQL Server  2000 onwards) don&#8217;t offer any performance benefits of using stored  procedures against precompiled queries: they are compiled and cached in  the same manner as dynamic SQL.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kiransalke.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kiransalke.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kiransalke.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kiransalke.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kiransalke.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kiransalke.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kiransalke.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kiransalke.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kiransalke.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kiransalke.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kiransalke.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kiransalke.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kiransalke.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kiransalke.wordpress.com/93/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=93&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kiransalke.wordpress.com/2010/07/07/stored-procedures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9898d57098670c611a10f570a7564007?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkiran33</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET Page Life Cycle Events</title>
		<link>http://kiransalke.wordpress.com/2010/07/06/asp-net-page-life-cycle-events/</link>
		<comments>http://kiransalke.wordpress.com/2010/07/06/asp-net-page-life-cycle-events/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 07:49:02 +0000</pubDate>
		<dc:creator>Kiran Salke</dc:creator>
				<category><![CDATA[ASP.NET(C#)]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[Page Life Cycle]]></category>

		<guid isPermaLink="false">http://kiransalke.wordpress.com/?p=89</guid>
		<description><![CDATA[Introduction It is very important to understand ASP.NET page life cycle for many reasons, mainly for understanding where we should place particular methods and when we should set page related properties. Additionally if we are developing custom server controls then clear understanding of page life cycle is very useful to correct initialization of control, setting [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=89&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>It is very  important to understand ASP.NET page life cycle for many reasons, mainly  for understanding where we should place particular methods and when we  should set page related properties. Additionally if we are developing  custom server controls then clear understanding of page life cycle is  very useful to correct initialization of control, setting properties  with view-state data, and control’s code(Control events are subject to  ASP.NET page only)</p>
<p>Page life cycle depends on whether it is  requested for the first time or it is after postback(page request of  itself) and finalize to the web server. When a web page is requested to  web server, it goes through a series of sequence of steps/events (like  initialization, instantiating controls, restoring and maintaining state,  running event handler code, and rendering) before it returned back to  the web browser.</p>
<p>When we use and manipulate page life cycle  events correctly then it becomes a handy and powerful tool for  developing web applications.</p>
<h3>Background</h3>
<p><strong>IIS</strong> : It is default web server  with Microsoft .NET. Internet Information Server helps to deploy web  sites/web application. IIS web server receives request for a web  resource (file), it checks the extension of the file (e.g. .aspx, ascx,  .ashx and .asmx) and then it determines which ISAPI extension should  handle this request and passes this request to proper ISAPI extension</p>
<p><strong>ASPNET_ISAPI.DLL</strong> : IIS loads this DLL and sends the page request to this DLL. This DLL  loads the HTTPRuntime for further processing.</p>
<p><strong>ASPNET_WP.EXE</strong>:  It contains an Application Pool. Each Application Pool can contain any  number of Applications. Application Pool is also called as AppDomain.  When a web page is requested, IIS looks for the application pool under  which the current application is running and forwards the request to the  respective worker process.</p>
<div>
<p><strong>Explanation</strong></div>
<div>General Page Life Cycle Stages Each and every time the browser  sends the request, page instance is created. HTTP runtime invokes  ProcessRequest and starts page execution.</div>
<p><strong>Table showing stage and corresponding Events </strong></p>
<div>
<table style="height:300px;" border="2" cellspacing="1" cellpadding="1" width="570">
<tbody>
<tr>
<td valign="top"><strong>Stage</strong></td>
<td valign="top"><strong>Events/Method </strong></td>
</tr>
<tr>
<td valign="top">Initialization of the page</td>
<td valign="top">Page_Init</td>
</tr>
<tr>
<td valign="top">Loading of the View State</td>
<td valign="top">LoadViewState</td>
</tr>
<tr>
<td valign="top">processing of the Post back data</td>
<td valign="top">LoadPostData</td>
</tr>
<tr>
<td valign="top">Loading of Page</td>
<td valign="top">Page_Load</td>
</tr>
<tr>
<td valign="top">Notification of PostBack</td>
<td valign="top">RaisePostDataChangedEvent</td>
</tr>
<tr>
<td valign="top">Handling of PostBack Event</td>
<td valign="top">RaisePostBackEvent</td>
</tr>
<tr>
<td valign="top">Pre Rendering of Page</td>
<td valign="top">Page_PreRender</td>
</tr>
<tr>
<td valign="top">Saving of view state</td>
<td valign="top">SaveViewState</td>
</tr>
<tr>
<td valign="top">Rendering of Page</td>
<td valign="top">Page_Render</td>
</tr>
<tr>
<td>Unloading of the Page</td>
<td>Page_UnLoad</td>
</tr>
</tbody>
</table>
</div>
<h6>Setting up of the page</h6>
<p>ASP.NET determines that the page request by a user requires to be  parsing and compiling or to render cached copy of the page to be send.  Thus it comes very much before of the beginning of the page life cycle.  After this, it is also checked that request is a normal request,  postback, cross-page postback or callback. The page constructor creates a  tree of controls as soon as the HTTP runtime instantiates the page  class to perform the request</p>
<h3><strong>Events</strong></h3>
<p><strong>PreInit</strong></p>
<p>This event is the beginning of the  page life cycle. Every page controls are initialized and the properties  are set according to aspx source code.</p>
<ul>
<li>Possible to Change or set Master page, Themes</li>
<li>Creates or re-creates dynamic controls.</li>
<li>Reads or sets Profile property values.</li>
</ul>
<p><strong>Init</strong></p>
<p>First, the Init event for the Page  object occurs, then Init event occurs for each control on the Page.  Viewstate information is not available at this stage.</p>
<ul>
<li>Controls have been initialized zed</li>
<li>Theme skins applied if any.</li>
<li>Initialize control properties.</li>
</ul>
<p><strong><br />
InitComplete </strong></p>
<p>This event is used to  processing tasks that require all initialization be complete.</p>
<p><strong>PreLoad </strong></p>
<p>This event is used before Perform any processing that should occur  before Load. Use this event if you need to perform processing on your  page or control before the Load event. Before the Page instance raises  this event, it loads view state for itself and all controls, and then  processes any postback data included with the Request instance.</p>
<p><strong>Load</strong></p>
<p>Set properties in controls and establish database connections</p>
<p><strong>Control  Events</strong></p>
<p>These are control specific events such as – Button Click,  DropDownIndexChanged etc.<br />
<strong><br />
Load Complete</strong></p>
<p>This event is used for performing those tasks which require load has  been completed.</p>
<p><strong>PreRender</strong></p>
<p>In this event page insures that all child controls are created. Page  calls EnsureChildControls for all controls, including itself. Every  controls whose datasource/databind property is set calls for its  databind method.</p>
<p><strong>SaveStateComplete</strong></p>
<p>This event occurs after viewstate encoded and saved for the page and  for all controls.</p>
<p><strong>Render</strong></p>
<p>Every ASP.NET control has render method and the page instance calls  this method to output the control’s markup, after this event any changes  to the page or controls are ignored.</p>
<p><strong>Unload</strong></p>
<p>Unload event used to do cleanup task like closing the database  connections, closing of the open files, completing logging or other  requested tasks. Unload events occurs for each control on page control  tree first and after that page.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kiransalke.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kiransalke.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kiransalke.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kiransalke.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kiransalke.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kiransalke.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kiransalke.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kiransalke.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kiransalke.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kiransalke.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kiransalke.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kiransalke.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kiransalke.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kiransalke.wordpress.com/89/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=89&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kiransalke.wordpress.com/2010/07/06/asp-net-page-life-cycle-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9898d57098670c611a10f570a7564007?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkiran33</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight: Composite Web Apps With Prism</title>
		<link>http://kiransalke.wordpress.com/2010/02/01/silverlight-composite-web-apps-with-prism/</link>
		<comments>http://kiransalke.wordpress.com/2010/02/01/silverlight-composite-web-apps-with-prism/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 16:12:52 +0000</pubDate>
		<dc:creator>Kiran Salke</dc:creator>
				<category><![CDATA[ASP.NET(C#)]]></category>
		<category><![CDATA[Silverlight & Composite Application Guidance]]></category>

		<guid isPermaLink="false">http://kiransalke.wordpress.com/?p=85</guid>
		<description><![CDATA[Silverlight Composite Web Apps With Prism Kiran Salke Code download available from the MSDN Code Gallery Browse the Code Online This article discusses: Silverlight 2 Application composition Dependency injection This article uses the following technologies: Silverlight 2, Prism Contents Why Prism? Introducing Dependency Injection Startup Behavior Modularity UI Composition Event Aggregation Delegate Commands Wrapping Up [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=85&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td valign="top">
<div id="MainContent">
<div>
<div>
<div><strong>Silverlight</strong></div>
<div><strong>Composite Web Apps With Prism</strong></div>
<div>Kiran Salke</div>
<div id="codedownloadtag">Code download available from the  		<a href="http://code.msdn.microsoft.com/mag200907Prism">MSDN Code Gallery</a><br />
<a id="ctl00_MTContentSelector1_mainContentContainer_ctl01" href="http://msdn.microsoft.com/en-us/magazine/dd980903.aspx">Browse the Code Online</a></div>
<table>
<tbody>
<tr valign="top">
<td>This article discusses:</p>
<ul>
<li>Silverlight 2</li>
<li>Application composition</li>
<li>Dependency injection</li>
</ul>
</td>
<td>This article uses the following technologies:<br />
Silverlight 2, Prism</td>
</tr>
</tbody>
</table>
<div>
<div>
<div><!-- ApplyClick with current id --> <img src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Contents</div>
<div><a href="http://msdn.microsoft.com/en-us/magazine/dd943055.aspx#id0420004">Why Prism?</a><br />
<a href="http://msdn.microsoft.com/en-us/magazine/dd943055.aspx#id0420014">Introducing Dependency Injection</a><br />
<a href="http://msdn.microsoft.com/en-us/magazine/dd943055.aspx#id0420066">Startup Behavior</a><br />
<a href="http://msdn.microsoft.com/en-us/magazine/dd943055.aspx#id0420088">Modularity</a><br />
<a href="http://msdn.microsoft.com/en-us/magazine/dd943055.aspx#id0420173">UI Composition</a><br />
<a href="http://msdn.microsoft.com/en-us/magazine/dd943055.aspx#id0420209">Event Aggregation</a><br />
<a href="http://msdn.microsoft.com/en-us/magazine/dd943055.aspx#id0420226">Delegate Commands</a><br />
<a href="http://msdn.microsoft.com/en-us/magazine/dd943055.aspx#id0420239">Wrapping Up</a></div>
</div>
</div>
<div id="id0420001">Your first experience with Silverlight was probably something small: a video player, a simple charting application, or even a menu. These types of applications are simple and straightforward to design, and segmenting them into rigorous layers with separate responsibilities is overkill.</div>
<div id="id0420002">Problems surface, however, when you try to apply a tightly coupled style to large applications. As the number of moving parts grows, the simple style of application development falls apart. Part of the remedy is layering (see my article &#8220;<a href="http://msdn.microsoft.com/en-us/magazine/dd458800.aspx">Model-View-ViewModel In Silverlight 2 Apps</a>&#8220;), but a tightly coupled architecture is just one of a number of problems that need to be solved in large Silverlight projects.</div>
<div id="id0420003">In this article, I show you how to build an application using the composition techniques of the Composite Application Library from the Prism project. The example I develop is a simple editor of database data.</div>
<div id="id0420005">As requirements change and a project matures, it is helpful if you can change parts of the application without having these changes cascade throughout the system. Modularizing an application allows you to build application components separately (and loosely coupled) and to change whole parts of your application without affecting the rest of the code.</div>
<div id="id0420006">Also, you might not want to load all the pieces of your application at once. Imagine a customer management application in which users log on and can then manage their prospect pipeline as well as check e-mail from any of their prospects. If a user checks e-mail several times a day but manages the pipeline only every day or two, why load the code to manage the pipeline until it is needed? It would be great if an application supported on-demand loading of parts of the application, a situation that can be addressed by modularizing the application.</div>
<div id="id0420007">The patterns &amp; practices team at Microsoft created a project called Prism (or CompositeWPF) that is meant to address problems like these for Windows Presentation Foundation (WPF) applications, and Prism has been updated to support Silverlight as well. The Prism package is a mix of framework and guidance for building applications. The framework, called the Component Application Library (CAL), enables the following:</div>
<div id="id0420008">
<ul>
<li>Application modularity: Build applications from partitioned components.</li>
<li>UI composition: Allows loosely coupled components to form user interfaces without discrete knowledge of the rest of the application.</li>
<li>Service location: Separate horizontal services (for example, logging and authentication) from vertical services (business logic) to promote clean layering of an application.</li>
</ul>
</div>
<div id="id0420011">The CAL is written with these same design principles in mind, and for application developers it is a buffet-style framework—take what you need and leave the rest. <strong>Figure 1</strong> shows the basic layout of the CAL in relation to your own application.</div>
<div><img src="http://i.msdn.microsoft.com/dd943055.fig02_L%28en-us%29.gif" alt="" /></p>
<div>Figure 1 <strong>Composite Application Library</strong></div>
</div>
<div id="id0420012">The CAL supports these services to aid you in composing your application from smaller parts. This means the CAL handles which pieces are loaded (and when) as well as providing base functionality. You can decide which of these capabilities help you do your job and which might get in the way.</div>
<div id="id0420013">My example in this article uses as much of the CAL as possible. It is a shell application that uses the CAL to load several modules at run time, place views in regions (as shown in <strong>Figure 2</strong>), and support services. But before we get to that code, you need to understand some basic concepts about dependency injection (also called Inversion of Control, or IoC). Many of the CAL&#8217;s features rely on dependency injection, so understanding the basics will help you develop the architecture of your Silverlight project with Prism.</div>
<div><img src="http://i.msdn.microsoft.com/dd943055.fig03%28en-us%29.gif" alt="" /></p>
<div>Figure 2 <strong>Composite Application Architecture</strong></div>
</div>
<div id="id0420014">Introducing Dependency Injection</div>
<div id="id0420015">In typical development, a project starts with an entry point (an executable, a default.aspx page, and so on). You might develop your application as one giant project, but in most cases some level of modularity exists in that your application loads a number of assemblies that are part of the project. The main assembly knows what assemblies it needs and creates hard references to those pieces. At compile time, the main project knows about all the referenced assemblies, and the user interface consists of static controls. The application is in control of what code it needs and usually knows all the code it might use. This becomes a problem, however, because development takes place inside the main application project. As a monolithic application grows, build time and conflicting changes can slow down development.</div>
<div id="id0420016">Dependency injection aims to reverse this situation by providing instructions that set up dependencies at run time. Instead of the project controlling these dependencies, a piece of code called a container is responsible for injecting them.</div>
<div id="id0420017">But why is this important? For one thing, modularizing your code should make it easier to test. Being able to swap out a project&#8217;s dependencies enables cleaner testing so that only the code to be tested can be the source of a test failing, instead of code somewhere in the nested chain of dependencies. Here&#8217;s a concrete example. Imagine you have a component that other developers use to look up addresses for particular companies. Your component depends on a data access component that retrieves the data for you. When you test your component, you start by testing it against the database, and some of the tests fail. But because the schema and builds of the database are constantly changing, you don&#8217;t know whether your tests are failing because of your own code or the data access code. With your component&#8217;s hard dependency on the data access component, testing the application becomes unreliable and causes churn while you track down failures in your code or in other&#8217;s code.</div>
<div id="id0420018">Your component might look something like this:</div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl05_">
<div></div>
<div dir="ltr">
<pre>public class AddressComponent
{
  DataAccessComponent data = new DataAccessComponent();

  public AddressComponent()
  {
  }

  ...
}
</pre>
</div>
</div>
<div id="id0420029">Instead of a hard-wired component, you could accept an interface that represents your data access, as shown here:</div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl06_">
<div></div>
<div dir="ltr">
<pre>public interface IDataAccess
{
  ...
}

public class AddressComponent
{
  IDataAccess data;

  public AddressComponent(IDataAccess da)
  {
    data = da;
  }

  ...
}
</pre>
</div>
</div>
<div id="id0420046">Ordinarily, an interface is used so you can create a version that allows you to adjust your code. This approach is often called &#8220;mocking.&#8221; Mocking means creating an implementation of the dependency that does not actually represent the real version. Literally, you&#8217;re creating a mock implementation.</div>
<div id="id0420047">This approach is better because the dependency (IDataAccess) can be injected into the project during construction of the object. The implementation of the IDataAccess component will depend on the requirements (testing or real).</div>
<div id="id0420048">That&#8217;s essentially how dependency injection works, but how is the injection handled? The job of the container is to handle creation of the types, which it does by allowing you to register types and then resolving them. For example, assume you have a concrete class that implements the IDataAccess interface. During start up of the application, you can tell the container to register the type. Anywhere else in your application where you need the type, you can ask the container to resolve the type, as shown here:</div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl07_">
<div></div>
<div dir="ltr">
<pre>public void App_Startup()
{
  container.RegisterType&lt;IDataAccess, DbDataAccess&gt;();
}

...

public void GetData()
{
  IDataAccess acc = container.Resolve&lt;IDataAccess&gt;();
}
</pre>
</div>
</div>
<div id="id0420060">Depending on the situation (testing or production), you can swap out the implementation of IDataAccess simply by changing the registration. Additionally, the container can handle construction injection of dependencies. If an object that needs to be created by the container&#8217;s constructor takes an interface that the container can resolve, it resolves the type and passes it to the constructor, as shown in <strong>Figure 3</strong>.</div>
<div id="id046">
<div>
<div><!-- ApplyClick with current id --> <img src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Figure 3 Type Resolution by the Container</div>
<div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl40_ctl00_ctl00_">
<div></div>
<div dir="ltr">
<pre>public class AddressComponent : IAddressComponent
{
  IDataAccess data;

  public AddressComponent(IDataAccess da)
  {
    data = da;
  }
}

...

public void App_Startup()
{
  container.RegisterType&lt;IAddressComponent, AddressComponent&gt;();
  container.RegisterType&lt;IDataAccess, DbDataAccess&gt;();
}

public void GetAddresses()
{
  // When we ask the container to create the AddressComponent,
  // it sees that a constructor takes a IDataAccess object
  // so it automatically resolves that dependency
  IAddressComponent addr = container.Resolve&lt;IAddressComponent&gt;();
}
</pre>
</div>
</div>
</div>
</div>
</div>
<div id="id0420061">Notice that the AddressComponent&#8217;s constructor takes an implementation of IDataAccess. When the constructor creates the AddressComponent class during resolution, it automatically creates the instance of IDataAccess and passes it to the AddressComponent.</div>
<div id="id0420062">When you register types with the container, you also tell the container to deal with the lifetime of the type in special ways. For example, if you are working with a logging component, you might want to treat it as a singleton so that every part of the application that needs logging does not get its own copy (which is the default behavior). To do this, you can supply an implementation of the abstract LifetimeManager class. Several lifetime managers are supported. ContainerControlledLifetimeManager is a singleton per process and PerThreadLifetimeManager is a singleton per thread. For ExternallyControlledLifetimeManager, the container holds a weak reference to the singleton. If the object is released externally, the container creates a new instance, otherwise it returns the live object contained in the weak reference.</div>
<div id="id0420063">You use the LifetimeManager class by specifying it when registering a type. Here&#8217;s an example:</div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl10_">
<div></div>
<div dir="ltr">
<pre>container.RegisterType&lt;IAddressComponent, AddressComponent&gt;(  new ContainerControlledLifetimeManager());
</pre>
</div>
</div>
<div id="id0420065">In the CAL, the IoC container is based on the Unity framework from the patterns &amp; practices group. I&#8217;ll use the Unity container in the following examples, but there are also a number of open source alternatives to the Unity IoC container, such as Ninject, Spring.NET, Castle, and StructureMap. If you are familiar with and already using an IoC container other than Unity, you can supply your own container (although it takes a little more effort).</div>
<div id="id0420066">Startup Behavior</div>
<div id="id0420067">Ordinarily in a Silverlight application, the startup behavior is simply to create the main XAML page&#8217;s class and assign it to the application&#8217;s RootVisual property. In a composite application, this work is still required, but instead of creating the XAML page class, a composite application typically uses a bootstrapping class to handle startup behavior.</div>
<div id="id0420068">To start, you need a new class that derives from the UnityBootstrapper class. This class is in the Microsoft.Practices.Composite.UnityExtensions assembly. The bootstrapper contains overridable methods that handle different parts of startup behavior. Often, you will not override every startup method, only the ones necessary. The two methods you must override are CreateShell and GetModuleCatalog.</div>
<div id="id0420069">The CreateShell method is where the main XAML class is created. This is typically called the shell because it is the visual container for the application&#8217;s components. My example includes a bootstrapper that creates a new instance of the Shell class and assigns it to RootVisual before returning this new Shell class, as shown here:</div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl11_">
<div></div>
<div dir="ltr">
<pre>public class Bootstrapper : UnityBootstrapper
{
  protected override DependencyObject CreateShell()
  {
    Shell theShell = new Shell();
    App.Current.RootVisual = theShell;
    return theShell;
  }

  protected override IModuleCatalog GetModuleCatalog()
  {
    ...
  }
}
</pre>
</div>
</div>
<div id="id0420084">The GetModuleCatalog method, which I&#8217;ll explain in the next section, returns the list of modules to load.</div>
<div id="id0420085">Now that you have a bootstrapper class, you can use it in your Silverlight application&#8217;s startup method. Usually, you create a new instance of the bootstrapper class and call its Run method, as shown in <strong>Figure 4</strong>.</div>
<div id="id048">
<div>
<div><!-- ApplyClick with current id --> <img src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Figure 4 Creating an Instance of the Bootstrapper</div>
<div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl43_ctl00_ctl00_">
<div></div>
<div dir="ltr">
<pre>public partial class App : Application
{

  public App()
  {
    this.Startup += this.Application_Startup;
    this.Exit += this.Application_Exit;
    this.UnhandledException += this.Application_UnhandledException;

    InitializeComponent();
  }

  private void Application_Startup(object sender, StartupEventArgs e)
  {
    Bootstrapper boot = new Bootstrapper();
    boot.Run();
  }

  ...
}
</pre>
</div>
</div>
</div>
</div>
</div>
<div id="id0420086">The bootstrapper is also involved in registering types with the container that different parts of the application require. To accomplish this, you override the ConfigureContainer method of the bootstrapper. This gives you a chance to register any types that are going to be used by the rest of the application. <strong>Figure 5</strong> shows the code.</div>
<div id="id050">
<div>
<div><!-- ApplyClick with current id --> <img src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Figure 5 Registering Types</div>
<div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl44_ctl00_ctl00_">
<div></div>
<div dir="ltr">
<pre>public class Bootstrapper : UnityBootstrapper
{
  protected override void ConfigureContainer()
  {
    Container.RegisterType&lt;IShellProvider, Shell&gt;();
    base.ConfigureContainer();
  }

  protected override DependencyObject CreateShell()
  {
    // Get the provider for the shell
    IShellProvider shellProvider = Container.Resolve&lt;IShellProvider&gt;();

    // Tell the provider to create the shell
    UIElement theShell = shellProvider.CreateShell();

    // Assign the shell to the root visual of our App
    App.Current.RootVisual = theShell;

    // Return the Shell
    return theShell;
  }

  protected override IModuleCatalog GetModuleCatalog()
  {
    ...
  }
}
</pre>
</div>
</div>
</div>
</div>
</div>
<div id="id0420087">Here, the code registers an interface for a class that implements the IShellProvider interface, which is created in our example and is not part of the CAL framework. That way we can use it in our implementation of the CreateShell method. We can resolve the interface and then use it to create an instance of the shell so we can assign it to RootVisual and return it. This methodology may seem like extra work, but as you delve into how the CAL helps you build your application, it becomes clear how this bootstrapper is helping you.</div>
<div id="id0420088">Modularity</div>
<div id="id0420089">In a typical .NET environment, the assembly is the main unit of work. This designation allows developers to work on their code separately from each other. In the CAL, each of these units of work is a module, and for the CAL to use a module, it needs a class that can communicate the module&#8217;s startup behavior. This class also needs to supports the IModule interface. The IModule interface requires a single method called Initialize that allows the module to set itself up to be used in the rest of the application. The example includes a ServerLogger module that contains the logging capabilities for our application. The ServerLoggingModule class supports the IModule interface as shown here:</div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl16_">
<div></div>
<div dir="ltr">
<pre>public class ServerLoggerModule : IModule
{
  public void Initialize()
  {
    ...
  }
}
</pre>
</div>
</div>
<div id="id0420097">The problem is that we don&#8217;t know what we want to initialize in our module. Since it&#8217;s a ServerLogging module, it seems logical that we want to register a type that does logging for us. We want to use the container to register the type so that whoever needs the logging facility can simply use our implementation without knowing the exact type of logging it performs.</div>
<div id="id0420098">We get the container by creating a constructor that takes the IUnityContainer interface. If you remember the discussion of dependency injection, the container uses constructor injection to add types that it knows about. IUnityContainer represents the container in our application, so if we add that constructor, we can then save it and use it in our initialization like so:</div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl17_">
<div></div>
<div dir="ltr">
<pre>public class ServerLoggerModule : IModule
{
  IUnityContainer theContainer;

  public ServerLoggerModule(IUnityContainer container)
  {
    theContainer = container;
  }

  public void Initialize()
  {
    theContainer.RegisterType&lt;ILoggerFacade, ServerBasedLogger&gt;(
      new ContainerControlledLifetimeManager());
  }
}
</pre>
</div>
</div>
<div id="id0420114">Once initialized, this module is responsible for the logging implementation for the application. But how does this module get loaded?</div>
<div id="id0420115">When using the CAL to compose an application, you need to create a ModuleCatalog that contains all the modules for the application. You create this catalog by overriding the bootstrapper&#8217;s GetModuleCatalog call. In Silverlight, you can populate this catalog with code or with XAML.</div>
<div id="id0420116">With code, you create a new instance of the ModuleCatalog class and populate it with the modules. For example, look at this:</div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl18_">
<div></div>
<div dir="ltr">
<pre>protected override IModuleCatalog GetModuleCatalog()
{
  var logModule = new ModuleInfo()
  {
    ModuleName = "ServerLogger",
    ModuleType =       "ServerLogger.ServerLoggerModule, ServerLogger, Version = 1.0.0.0"
  };

  var catalog = new ModuleCatalog();
  catalog.AddModule(logModule);

  return catalog;
}
</pre>
</div>
</div>
<div id="id0420130">Here, I simply add a single module called ServerLogger, the type defined in the ModuleInfo&#8217;s ModuleType property. In addition, you can specify dependencies between modules. Because some modules might depend on others, using dependencies helps the catalog know the order in which to bring in the dependencies. Using the ModuleInfo.DependsOn property, you can specify which named modules are required to load another module.</div>
<div id="id0420131">You can load the catalog directly from a XAML file, as shown here:</div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl19_">
<div></div>
<div dir="ltr">
<pre>protected override IModuleCatalog GetModuleCatalog()
{
  var catalog = ModuleCatalog.CreateFromXaml(new Uri("catalog.xaml",
                                                     UriKind.Relative));
  return catalog;
}
</pre>
</div>
</div>
<div id="id0420138">The XAML file contains the same type information you can create with code. The benefit of using XAML is that you can change it on the fly. (Imagine retrieving the XAML file from a server or from another location based on which user logged on.) An example of a catalog.xaml file is shown in <strong>Figure 6</strong>.</div>
<div id="id052">
<div>
<div><!-- ApplyClick with current id --> <img src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Figure 6 A Sample Catalog.xaml File</div>
<div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl49_ctl00_ctl00_">
<div></div>
<div dir="ltr">
<pre>&lt;m:ModuleCatalog
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:sys="clr-namespace:System;assembly=mscorlib"
  xmlns:m="clr-namespace:Microsoft.Practices.Composite.Modularity;
    assembly=Microsoft.Practices.Composite"&gt;
  &lt;m:ModuleInfoGroup InitializationMode="WhenAvailable"&gt;
    &lt;m:ModuleInfo ModuleName="GameEditor.Client.Data"
        ModuleType="GameEditor.Client.Data.GameEditorDataModule,
          GameEditor.Client.Data, Version=1.0.0.0"/&gt;
    &lt;m:ModuleInfo ModuleName="GameEditor.GameList"
      ModuleType="GameEditor.GameList.GameListModule,
      GameEditor.GameList, Version=1.0.0.0"
      InitializationMode="WhenAvailable"&gt;
      &lt;m:ModuleInfo.DependsOn&gt;
        &lt;sys:String&gt;GameEditor.Client.Data&lt;/sys:String&gt;
      &lt;/m:ModuleInfo.DependsOn&gt;
    &lt;/m:ModuleInfo&gt;
  &lt;/m:ModuleInfoGroup&gt;
&lt;/m:ModuleCatalog&gt;
</pre>
</div>
</div>
</div>
</div>
</div>
<div id="id0420139">In this XAML catalog, the group includes two modules and the second module depends on the first. You could use a specific XAML catalog based on roles or permissions, as you could with code.</div>
<div id="id0420140">Once the catalog is loaded by the bootstrapper, it attempts to create instances of the module classes and allow them to initialize themselves. In the code examples here, the types have to be referenced by the application (therefore, already loaded into memory) for this catalog to work.</div>
<div id="id0420141">This is where this facility becomes indispensible to Silverlight. Although the unit of work is the assembly, you can specify a .xap file that contains the module or modules. To do this, you specify a Ref value in ModuleInfo. The Ref value is a path to the .xap file that contains the module:</div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl22_">
<div></div>
<div dir="ltr">
<pre>protected override IModuleCatalog GetModuleCatalog()
{
  var logModule = new ModuleInfo()
  {
    ModuleName = "ServerLogger",
    ModuleType =
      "ServerLogger.ServerLoggerModule, ServerLogger, Version= 1.0.0.0",
    Ref = "ServerLogger.xap"
  };

  var catalog = new ModuleCatalog();
  catalog.AddModule(logModule);

  return catalog;
}
</pre>
</div>
</div>
<div id="id0420157">When you specify a .xap file, the bootstrapper knows that the assembly is not available and goes out to the server and retrieves the .xap file asynchronously. Once the .xap file is loaded, Prism loads the assembly and creates the module type and initializes the module.</div>
<div id="id0420158">For .xap files that contain multiple modules, you can create a ModuleGroup that contains a set of ModuleInfo objects and set the Ref of the ModuleGroup to load all those modules from a single .xap file:</div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl23_">
<div></div>
<div dir="ltr">
<pre>var modGroup = new ModuleInfoGroup();
modGroup.Ref = "MyMods.xap";
modGroup.Add(logModule);
modGroup.Add(dataModule);
modGroup.Add(viewModule);

var catalog = new ModuleCatalog();
catalog.AddGroup(modGroup);
</pre>
</div>
</div>
<div id="id0420167">For Silverlight applications, this is a way to compose your applications from multiple .xap files, which allows you to version different sections of your composed application separately.</div>
<div id="id0420168">When creating Silverlight modules to be housed in a .xap file, you create a Silverlight Application (not a Silverlight Library). Then you reference all the module projects you want to put in the .xap file. You need to remove the app.xaml and page.xaml files because this .xap file will not be loaded and run like a typical .xap file. The .xap file is just a container (could be a .zip file, it doesn&#8217;t matter). Also, if you are referencing projects that are already referenced in the main project, you can change those references to Copy Local=false in the properties because you don&#8217;t need the assemblies in the .xap file (the main application has already loaded them, so the catalog will not try to load them a second time.)</div>
<div id="id0420169">But loading a huge application with multiple calls across the wire does not seem like it would help performance. That is where the ModuleInfo&#8217;s InitializationMode property comes into play. InitializationMode supports two modes: WhenAvailable, in which the .xap file is loaded asynchronously and then initialized (this is the default behavior), and OnDemand, in which the .xap is loaded when explicitly requested. Since the module catalog does not know the types in the modules until initialization, resolving types that are initialized with OnDemand will fail.</div>
<div id="id0420170">On-demand support for modules and groups allows you to load certain functionality in a large application as needed. Startup time is accelerated, and other required code can be loaded as users interact with an application. This is a great feature to use when you have authorization to separate parts of an application. Users who need only a few parts of the application do not have to download code they&#8217;ll never use.</div>
<div id="id0420171">To load a module on demand, you need access to an IModuleManager interface. Most often, you request this in the constructor of the class that needs to load a module on demand. Then you use IModuleManager to load the module by calling LoadModule, as shown in <strong>Figure 7</strong>.</div>
<div id="id054">
<div>
<div><!-- ApplyClick with current id --> <img src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Figure 7 Calling LoadModule</div>
<div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl52_ctl00_ctl00_">
<div></div>
<div dir="ltr">
<pre>public class GameListViewModel : IGameListViewModel
{
  IModuleManager theModuleManager = null;

  public GameListViewModel(IModuleManager modMgr)
  {
    theModuleManager = modMgr;
  }

  void theModel_LoadGamesComplete(object sender,
                                  LoadEntityCompleteEventArgs&lt;Game&gt; e)
  {
    ...

    // Since we now have games, let's load the detail pane
    theModuleManager.LoadModule("GameEditor.GameDetails");
  }
}
</pre>
</div>
</div>
</div>
</div>
</div>
<div id="id0420172">Modules are simply the unit of modularization in your applications. In Silverlight, treat a module much like you would a library project, but with the extra work of module initialization, you can decouple your modules from the main project.</div>
<div id="id0420173">UI Composition</div>
<div id="id0420174">In a typical Explorer application, the left pane displays a list or tree of information and the right side contains details about the item selected in the left pane. In the CAL, these areas are called regions.</div>
<div id="id0420175">The CAL supports defining regions directly in XAML by using an attached property on the RegionManager class. This property allows you to specify regions in your shell and then indicate what views should be hosted in the region. For example, our shell has two regions, LookupRegion and DetailRegion, as shown here:</div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl26_">
<div></div>
<div dir="ltr">
<pre>&lt;UserControl
  ...
  xmlns:rg=
    "clr-namespace:Microsoft.Practices.Composite.Presentation.Regions;
    assembly=Microsoft.Practices.Composite.Presentation"&gt;
  ...
  &lt;ScrollViewer rg:RegionManager.RegionName="LookupRegion" /&gt;
  &lt;ScrollViewer rg:RegionManager.RegionName="DetailRegion" /&gt;
&lt;/UserControl&gt;
</pre>
</div>
</div>
<div id="id0420185">A RegionName can be applied to the an ItemsControl and its derived controls (for example, ListBox); Selector and its derived controls (for example, TabControl); and ContentControl and its derived controls (for example, ScrollViewer).</div>
<div id="id0420186">Once you define regions, you can direct modules to load their views into the regions by using the IRegionManager interface, as shown here:</div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl27_">
<div></div>
<div dir="ltr">
<pre>public class GameListModule : IModule
{
  IRegionManager regionManager = null;

  public GameListModule(IRegionManager mgr)
  {
    regionManager = mgr;
  }

  public void Initialize()
  {
    // Build the View
    var view = new GameListView();

    // Show it in the region
    regionManager.AddToRegion("LookupRegion", view);
  }
}
</pre>
</div>
</div>
<div id="id0420205">This facility allows you to define regions in your application where views can appear and then have the modules define how to place views into the region, allowing the shell to be completely ignorant of the views.</div>
<div id="id0420206">The behavior of the regions might be different depending on the control type being hosted. The example uses a ScrollViewer so that one and only one view can be added to the region. In contrast, ItemControl regions allow for multiple views. As each view is added, it shows up as a new item in the ItemsControl. That facility makes it easier to build functionality like a dashboard.</div>
<div id="id0420207">If you are using an MVVM pattern to define your views, you can mix the regions and the service location aspects of the container to make your views and view models ignorant of each other and then let the module join them at run time. For example, if I change the GameListModule, I can register views and views models with the container and then join them before applying the view to the region, as shown in <strong>Figure 8</strong>.</div>
<div id="id056">
<div>
<div><!-- ApplyClick with current id --> <img src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Figure 8 Joining Views in a Region</div>
<div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl55_ctl00_ctl00_">
<div></div>
<div dir="ltr">
<pre>public class GameListModule : IModule
{
  IRegionManager regionManager = null;
  IUnityContainer container = null;

  public GameListModule(IUnityContainer con, IRegionManager mgr)
  {
    regionManager = mgr;
    container = con;
  }

  public void Initialize()
  {
    RegisterServices();

    // Build the View
    var view = container.Resolve&lt;IGameListView&gt;();

    // Get an Implemenation of IViewModel
    var viewModel = container.Resolve&lt;IGameListViewModel&gt;();

    // Marry Them
    view.ApplyModel(viewModel);

    // Show it in the region
    regionManager.AddToRegion("LookupRegion", view);
  }

  void RegisterServices()
  {
    container.RegisterType&lt;IGameListView, GameListView&gt;();
    container.RegisterType&lt;IGameListViewModel, GameListViewModel&gt;();
  }
}
</pre>
</div>
</div>
</div>
</div>
</div>
<div id="id0420208">This approach allows you to use UI composition while maintaining the strict separation of MVVM.</div>
<div id="id0420209">Event Aggregation</div>
<div id="id0420210">After you have multiple views in your applications through UI composition, you face a common problem. Even though you have built independent views to support better testing and development, there are often touch points where the views cannot be completely isolated. They are logically coupled because they need to communicate, but you want to keep them as loosely coupled as possible regardless of the logical coupling.</div>
<div id="id0420211">To enable loose coupling and cross-view communication, the CAL supports a service called event aggregation. Event aggregation allows access to different parts of the code to publishers and consumers of global events. Such access provides a straightforward way of communicating without being tightly coupled and is accomplished using the CAL&#8217;s IEventAggregator interface. IEventAggregator allows you to publish and subscribe to events across the different modules of your application.</div>
<div id="id0420212">Before you can communicate, you need a class that derives from EventBase. Typically, you create a simple event that derives from the CompositePresentationEvent&lt;T&gt; class. This generic class allows you to specify the payload of the event you are going to publish. In this case, the GameListViewModel is going to publish an event after a game is selected so that other controls that want to change their context as the user selects a game can subscribe to that event. Our event class looks like the following:</div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl30_">
<div></div>
<div dir="ltr">
<pre>public class GameSelectedEvent : CompositePresentationEvent&lt;Game&gt;
{
}
</pre>
</div>
</div>
<div id="id0420216">Once the event is defined, the event aggregator can publish the event by calling its GetEvent method. This retrieves the singleton event that is going to be aggregated. The first one who calls this method creates the singleton. From the event, you can call the Publish method to create the event. Publishing the event is like firing an event. You do not need to publish the event until it needs to send information. For example, when a game is selected in the GameList, our example publishes the selected game using the new event:</div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl31_">
<div></div>
<div dir="ltr">
<pre>// Fire Selection Changed with Global Event
theEventAggregator.GetEvent&lt;GameSelectedEvent&gt;().Publish(o as Game);
</pre>
</div>
</div>
<div id="id0420219">In other parts of your composed application, you can subscribe to the event to be called after the event is published. The Subscribe method of the event allows you to specify the method to be called when the event is published, an option that allows you to request threading semantics for calling the event (for example, the UI thread is commonly used), and whether to have the aggregator hold a reference to the passed in information so that it is not subject to garbage collection:</div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl32_">
<div></div>
<div dir="ltr">
<pre>// Register for the aggregated event
aggregator.GetEvent&lt;GameSelectedEvent&gt;().Subscribe(SetGame,
                                                  ThreadOption.UIThread,
                                                  false);
</pre>
</div>
</div>
<div id="id0420224">As a subscriber, you can also specify filters that are called only in specific situations. Imagine an event that returns the state of an application and a filter that is called only during certain data states.</div>
<div id="id0420225">The event aggregator allows you to have communication between your modules without causing tight coupling. If you subscribe to an event that is never published or publish an event that is never subscribed, your code will never fail.</div>
<div id="id0420226">Delegate Commands</div>
<div id="id0420227">In Silverlight (unlike WPF), a true commanding infrastructure does not exist. This forces the use of code-behind in views to accomplish tasks that would be accomplished more readily directly in XAML using the commanding infrastructure. Until Silverlight supports this facility, the CAL supports a class that helps solve this problem: the DelegateCommand.</div>
<div id="id0420228">To get started with DelegateCommand, you need to define the DelegateCommand in your ViewModel so you can data-bind to it. In the ViewModel, you would create a new DelegateCommand. The DelegateCommand expects the type of data to be sent to it (often Object if no data is used) and one or two callback methods (or lambda functions). The first of these methods is the action to execute when the command is fired. Optionally, you can specify a second callback to be called to test whether the command can be fired. The idea is to enable the disabling of objects in the UI (buttons, for example) when it is not valid to fire the command. For example, our GameDetailsViewModel contains a command to support saving data:</div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl33_">
<div></div>
<div dir="ltr">
<pre>// Create the DelegateCommand
SaveCommand = new DelegateCommand&lt;object&gt;(c =&gt; Save(), c =&gt; CanSave());
</pre>
</div>
</div>
<div id="id0420231">When SaveCommand is executed, it calls the Save method on our ViewModel. The CanSave method is then called to make sure the command is valid. This allows the DelegateCommand to disable the UI if necessary. As the state of the view changes, you can call the DelegateCommand.RaiseCanExecuteChanged method to force a new inspection of the CanSave method to enable or disable the UI as necessary.</div>
<div id="id0420232">To bind this to XAML, use the Click.Command attached property that is in the Microsoft.Practices.Composite.Presentation.Commands namespace. Then bind the value of the command to be the command you have in your ViewModel, like so:</div>
<div id="ctl00_MTContentSelector1_mainContentContainer_ctl34_">
<div></div>
<div dir="ltr">
<pre>&lt;Button Content="Save"
        cmd:Click.Command="{Binding SaveCommand}"
        Style="{StaticResource ourButton}"
        Grid.Column="1" /&gt;
</pre>
</div>
</div>
<div id="id0420237">Now when the Click event is fired, our command is executed. If you want, you can specify a command parameter to be sent to the command so you can reuse it.</div>
<div id="id0420238">As you might be wondering, the only command that exists in the CAL is the Click event for a button (or any other selector). But the classes you can use to write your own commands are fairly straightforward. The sample code includes a command for SelectionChanged on a ListBox/ComboBox. This command is called the SelectorCommandBehavior and derives from the CommandBehaviorBase&lt;T&gt; class. Looking at the custom command behavior implementation will provide you with a starting place to write your own command behaviors.</div>
<div id="id0420239">Wrapping Up</div>
<div id="id0420240">There are definite pain points when developing large Silverlight applications. By building your applications with loose coupling and modularity, you gain benefits and can be agile in responding to change. The Prism project from Microsoft provides the tools and guidance to allow that agility to come to the surface of your project. While Prism is not a one-size-fits-all approach, the modularity of the CAL means you can use what fits in your specific scenarios and leave the rest.</div>
<div><strong><br />
</strong></div>
</div>
</div>
</div>
</td>
<td valign="top">
<div id="RightContent">
<div id="ctl00_RightSideBox">
<div>
<table>
<tbody>
<tr>
<td valign="top"></td>
<td valign="top"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kiransalke.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kiransalke.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kiransalke.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kiransalke.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kiransalke.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kiransalke.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kiransalke.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kiransalke.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kiransalke.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kiransalke.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kiransalke.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kiransalke.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kiransalke.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kiransalke.wordpress.com/85/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=85&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kiransalke.wordpress.com/2010/02/01/silverlight-composite-web-apps-with-prism/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9898d57098670c611a10f570a7564007?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkiran33</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/dd943055.fig02_L%28en-us%29.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/dd943055.fig03%28en-us%29.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />
	</item>
		<item>
		<title>Get IP Address of iPhone</title>
		<link>http://kiransalke.wordpress.com/2009/12/04/get-ip-address-of-iphone/</link>
		<comments>http://kiransalke.wordpress.com/2009/12/04/get-ip-address-of-iphone/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 14:53:39 +0000</pubDate>
		<dc:creator>Kiran Salke</dc:creator>
				<category><![CDATA[iPhone SDK(Objective C)]]></category>
		<category><![CDATA[IP Address]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective c]]></category>

		<guid isPermaLink="false">http://kiransalke.wordpress.com/?p=80</guid>
		<description><![CDATA[/*  *  IPAdress.h  *  *  */ #define MAXADDRS 32 extern char *if_names[MAXADDRS]; extern char *ip_names[MAXADDRS]; extern char *hw_addrs[MAXADDRS]; extern unsigned long ip_addrs[MAXADDRS]; // Function prototypes void InitAddresses(); void FreeAddresses(); void GetIPAddresses(); void GetHWAddresses(); /*  *  IPAddress.c  *  */ #include &#8220;IPAddress.h&#8221; #include &#60;stdio.h&#62; #include &#60;stdlib.h&#62; #include &#60;string.h&#62; #include &#60;unistd.h&#62; #include &#60;sys/ioctl.h&#62; #include &#60;sys/types.h&#62; #include &#60;sys/socket.h&#62; #include [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=80&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>/*</p>
<p> *  IPAdress.h</p>
<p> *</p>
<p> *</p>
<p> */</p>
<p>#define MAXADDRS	32</p>
<p>extern char *if_names[MAXADDRS];</p>
<p>extern char *ip_names[MAXADDRS];</p>
<p>extern char *hw_addrs[MAXADDRS];</p>
<p>extern unsigned long ip_addrs[MAXADDRS];</p>
<p>// Function prototypes</p>
<p>void InitAddresses();</p>
<p>void FreeAddresses();</p>
<p>void GetIPAddresses();</p>
<p>void GetHWAddresses();</p>
<p>/*</p>
<p> *  IPAddress.c</p>
<p> *</p>
<p> */</p>
<p>#include &#8220;IPAddress.h&#8221;</p>
<p>#include &lt;stdio.h&gt;</p>
<p>#include &lt;stdlib.h&gt;</p>
<p>#include &lt;string.h&gt;</p>
<p>#include &lt;unistd.h&gt;</p>
<p>#include &lt;sys/ioctl.h&gt;</p>
<p>#include &lt;sys/types.h&gt;</p>
<p>#include &lt;sys/socket.h&gt;</p>
<p>#include &lt;netinet/in.h&gt;</p>
<p>#include &lt;netdb.h&gt;</p>
<p>#include &lt;arpa/inet.h&gt;</p>
<p>#include &lt;sys/sockio.h&gt;</p>
<p>#include &lt;net/if.h&gt;</p>
<p>#include &lt;errno.h&gt;</p>
<p>#include &lt;net/if_dl.h&gt;</p>
<p>#include &#8220;IPAddress.h&#8221;</p>
<p>#define	min(a,b)	((a) &lt; (b) ? (a) : (b))</p>
<p>#define	max(a,b)	((a) &gt; (b) ? (a) : (b))</p>
<p>#define BUFFERSIZE	4000</p>
<p>char *if_names[MAXADDRS];</p>
<p>char *ip_names[MAXADDRS];</p>
<p>char *hw_addrs[MAXADDRS];</p>
<p>unsigned long ip_addrs[MAXADDRS];</p>
<p>static int   nextAddr = 0;</p>
<p>void InitAddresses()</p>
<p>{</p>
<p>int i;</p>
<p>for (i=0; i&lt;MAXADDRS; ++i)</p>
<p>{</p>
<p>if_names[i] = ip_names[i] = hw_addrs[i] = NULL;</p>
<p>ip_addrs[i] = 0;</p>
<p>}</p>
<p>}</p>
<p>void FreeAddresses()</p>
<p>{</p>
<p>int i;</p>
<p>for (i=0; i&lt;MAXADDRS; ++i)</p>
<p>{</p>
<p>if (if_names[i] != 0) free(if_names[i]);</p>
<p>if (ip_names[i] != 0) free(ip_names[i]);</p>
<p>if (hw_addrs[i] != 0) free(hw_addrs[i]);</p>
<p>ip_addrs[i] = 0;</p>
<p>}</p>
<p>InitAddresses();</p>
<p>}</p>
<p>void GetIPAddresses()</p>
<p>{</p>
<p>int                 i, len, flags;</p>
<p>char                buffer[BUFFERSIZE], *ptr, lastname[IFNAMSIZ], *cptr;</p>
<p>struct ifconf       ifc;</p>
<p>struct ifreq        *ifr, ifrcopy;</p>
<p>struct sockaddr_in	*sin;</p>
<p>char temp[80];</p>
<p>int sockfd;</p>
<p>for (i=0; i&lt;MAXADDRS; ++i)</p>
<p>{</p>
<p>if_names[i] = ip_names[i] = NULL;</p>
<p>ip_addrs[i] = 0;</p>
<p>}</p>
<p>sockfd = socket(AF_INET, SOCK_DGRAM, 0);</p>
<p>if (sockfd &lt; 0)</p>
<p>{</p>
<p>perror(&#8220;socket failed&#8221;);</p>
<p>return;</p>
<p>}</p>
<p>ifc.ifc_len = BUFFERSIZE;</p>
<p>ifc.ifc_buf = buffer;</p>
<p>if (ioctl(sockfd, SIOCGIFCONF, &amp;ifc) &lt; 0)</p>
<p>{</p>
<p>perror(&#8220;ioctl error&#8221;);</p>
<p>return;</p>
<p>}</p>
<p>lastname[0] = 0;</p>
<p>for (ptr = buffer; ptr &lt; buffer + ifc.ifc_len; )</p>
<p>{</p>
<p>ifr = (struct ifreq *)ptr;</p>
<p>len = max(sizeof(struct sockaddr), ifr-&gt;ifr_addr.sa_len);</p>
<p>ptr += sizeof(ifr-&gt;ifr_name) + len;	// for next one in buffer</p>
<p>if (ifr-&gt;ifr_addr.sa_family != AF_INET)</p>
<p>{</p>
<p>continue;	// ignore if not desired address family</p>
<p>}</p>
<p>if ((cptr = (char *)strchr(ifr-&gt;ifr_name, &#8216;:&#8217;)) != NULL)</p>
<p>{</p>
<p>*cptr = 0;		// replace colon will null</p>
<p>}</p>
<p>if (strncmp(lastname, ifr-&gt;ifr_name, IFNAMSIZ) == 0)</p>
<p>{</p>
<p>continue;	/* already processed this interface */</p>
<p>}</p>
<p>memcpy(lastname, ifr-&gt;ifr_name, IFNAMSIZ);</p>
<p>ifrcopy = *ifr;</p>
<p>ioctl(sockfd, SIOCGIFFLAGS, &amp;ifrcopy);</p>
<p>flags = ifrcopy.ifr_flags;</p>
<p>if ((flags &amp; IFF_UP) == 0)</p>
<p>{</p>
<p>continue;	// ignore if interface not up</p>
<p>}</p>
<p>if_names[nextAddr] = (char *)malloc(strlen(ifr-&gt;ifr_name)+1);</p>
<p>if (if_names[nextAddr] == NULL)</p>
<p>{</p>
<p>return;</p>
<p>}</p>
<p>strcpy(if_names[nextAddr], ifr-&gt;ifr_name);</p>
<p>sin = (struct sockaddr_in *)&amp;ifr-&gt;ifr_addr;</p>
<p>strcpy(temp, inet_ntoa(sin-&gt;sin_addr));</p>
<p>ip_names[nextAddr] = (char *)malloc(strlen(temp)+1);</p>
<p>if (ip_names[nextAddr] == NULL)</p>
<p>{</p>
<p>return;</p>
<p>}</p>
<p>strcpy(ip_names[nextAddr], temp);</p>
<p>ip_addrs[nextAddr] = sin-&gt;sin_addr.s_addr;</p>
<p>++nextAddr;</p>
<p>}</p>
<p>close(sockfd);</p>
<p>}</p>
<p>void GetHWAddresses()</p>
<p>{</p>
<p>struct ifconf ifc;</p>
<p>struct ifreq *ifr;</p>
<p>int i, sockfd;</p>
<p>char buffer[BUFFERSIZE], *cp, *cplim;</p>
<p>char temp[80];</p>
<p>for (i=0; i&lt;MAXADDRS; ++i)</p>
<p>{</p>
<p>hw_addrs[i] = NULL;</p>
<p>}</p>
<p>sockfd = socket(AF_INET, SOCK_DGRAM, 0);</p>
<p>if (sockfd &lt; 0)</p>
<p>{</p>
<p>perror(&#8220;socket failed&#8221;);</p>
<p>return;</p>
<p>}</p>
<p>ifc.ifc_len = BUFFERSIZE;</p>
<p>ifc.ifc_buf = buffer;</p>
<p>if (ioctl(sockfd, SIOCGIFCONF, (char *)&amp;ifc) &lt; 0)</p>
<p>{</p>
<p>perror(&#8220;ioctl error&#8221;);</p>
<p>close(sockfd);</p>
<p>return;</p>
<p>}</p>
<p>ifr = ifc.ifc_req;</p>
<p>cplim = buffer + ifc.ifc_len;</p>
<p>for (cp=buffer; cp &lt; cplim; )</p>
<p>{</p>
<p>ifr = (struct ifreq *)cp;</p>
<p>if (ifr-&gt;ifr_addr.sa_family == AF_LINK)</p>
<p>{</p>
<p>struct sockaddr_dl *sdl = (struct sockaddr_dl *)&amp;ifr-&gt;ifr_addr;</p>
<p>int a,b,c,d,e,f;</p>
<p>int i;</p>
<p>strcpy(temp, (char *)ether_ntoa(LLADDR(sdl)));</p>
<p>sscanf(temp, &#8220;%x:%x:%x:%x:%x:%x&#8221;, &amp;a, &amp;b, &amp;c, &amp;d, &amp;e, &amp;f);</p>
<p>sprintf(temp, &#8220;%02X:%02X:%02X:%02X:%02X:%02X&#8221;,a,b,c,d,e,f);</p>
<p>for (i=0; i&lt;MAXADDRS; ++i)</p>
<p>{</p>
<p>if ((if_names[i] != NULL) &amp;&amp; (strcmp(ifr-&gt;ifr_name, if_names[i]) == 0))</p>
<p>{</p>
<p>if (hw_addrs[i] == NULL)</p>
<p>{</p>
<p>hw_addrs[i] = (char *)malloc(strlen(temp)+1);</p>
<p>strcpy(hw_addrs[i], temp);</p>
<p>break;</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>cp += sizeof(ifr-&gt;ifr_name) + max(sizeof(ifr-&gt;ifr_addr), ifr-&gt;ifr_addr.sa_len);</p>
<p>}</p>
<p>close(sockfd);</p>
<p>}</p>
<p>//Somewhere in your code</p>
<p>- (NSString *)deviceIPAdress {</p>
<p>InitAddresses();</p>
<p>GetIPAddresses();</p>
<p>GetHWAddresses();</p>
<p>return [NSString stringWithFormat:@"%s", ip_names[1]];</p>
<p>}</p>
<p>// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.</p>
<p>- (void)viewDidLoad {</p>
<p>    [super viewDidLoad];</p>
<p><span style="color:#000000;">    </span>ipAddress.text = [self deviceIPAdress];</p>
<p>}</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kiransalke.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kiransalke.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kiransalke.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kiransalke.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kiransalke.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kiransalke.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kiransalke.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kiransalke.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kiransalke.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kiransalke.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kiransalke.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kiransalke.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kiransalke.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kiransalke.wordpress.com/80/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=80&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kiransalke.wordpress.com/2009/12/04/get-ip-address-of-iphone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9898d57098670c611a10f570a7564007?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkiran33</media:title>
		</media:content>
	</item>
		<item>
		<title>Adding Membership tables to your database</title>
		<link>http://kiransalke.wordpress.com/2009/11/18/adding-membership-tables-to-your-database/</link>
		<comments>http://kiransalke.wordpress.com/2009/11/18/adding-membership-tables-to-your-database/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 09:56:16 +0000</pubDate>
		<dc:creator>Kiran Salke</dc:creator>
				<category><![CDATA[ASP.NET(C#)]]></category>

		<guid isPermaLink="false">http://kiransalke.wordpress.com/?p=75</guid>
		<description><![CDATA[ASP.NET Membership When you start creating a new ASP.NET 2.0 site with Visual Studio 2005 or Visual Web Developer Express (VWD) and want to start using it you&#8217;ll notice that a new file in the App_Data folder gets created besides your own database, namely the aspnetdb.mdf file. This extra database holds all the tables and stored [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=75&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>ASP.NET Membership</strong></p>
<p>When you start creating a new ASP.NET 2.0 site with Visual Studio 2005 or Visual Web Developer Express (VWD) and want to start using it you&#8217;ll notice that a new file in the App_Data folder gets created besides your own database, namely the aspnetdb.mdf file. This extra database holds all the tables and stored procedures to let Membership, Roles, Profile etc run smoothly.</p>
<p>However a problem arises when you don&#8217;t want to use that dedicated new database when you want to deploy to your live webserver, certainly not when you use a host that only offers one database and charges you extra for another database. Luckely you can control things more when using the dedicated <a href="http://blog.krisvandermast.com/ct.ashx?id=4839905e-e475-4204-9fb4-b5eebe30335f&amp;url=http%3a%2f%2fmsdn2.microsoft.com%2fen-us%2flibrary%2fms229862%28vs.80%29.aspx" target="_blank">aspnet_regsql tool</a> that ships with the .NET 2.0 framework.</p>
<p>What I&#8217;m about to describe in this article is how to use that tool to generate a SQL script that you can use to run on your other database with a tool like SQL Server Management Studio (SSMS). In this example I&#8217;ll be using the installed <em>Northwind</em> database on my <em>localhost</em> developer machine.</p>
<p>Just start up a new DOS box by going to <strong>Start | Run</strong> and type in <strong>cmd</strong> followed by enter. In Windows Vista you push the blue windows logo button and in the field with the text <em>Start Search</em> you type in cmd followed by ctrl + shift + enter. The reason for that combination is that you must run it under Admin privileges or else the to be generated file doesn&#8217;t get writed to disk.<br />
A new DOS box will appear and you just navigate to the following directory/folder: <strong></strong></p>
<p><strong>Windows\Microsoft.NET\Framework\v2.0.50727\</strong></p>
<p>If you&#8217;re not used to using DOS you can navigate to it by typing this in the DOS box: <strong>cd \windows\Microsoft.net\framework\v2.0.50727 </strong>followed by enter.</p>
<p>Then you type in this line: <strong>aspnet_regsql.exe  -S &lt;server&gt; -U &lt;user&gt; -P &lt;password&gt;  -d &lt;Database&gt; -A all </strong></p>
<p><strong>e.g. </strong><strong>aspnet_regsql.exe  -S localhost -U &lt;user&gt; -P &lt;password&gt; -d Northwind -A all</strong></p>
<p>Any questions about the above process then feel free to post a comment and I will reply.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kiransalke.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kiransalke.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kiransalke.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kiransalke.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kiransalke.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kiransalke.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kiransalke.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kiransalke.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kiransalke.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kiransalke.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kiransalke.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kiransalke.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kiransalke.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kiransalke.wordpress.com/75/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=75&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kiransalke.wordpress.com/2009/11/18/adding-membership-tables-to-your-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9898d57098670c611a10f570a7564007?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkiran33</media:title>
		</media:content>
	</item>
		<item>
		<title>Playing Video Files in iPhone OS</title>
		<link>http://kiransalke.wordpress.com/2009/10/06/playing-video-files-in-iphone-os/</link>
		<comments>http://kiransalke.wordpress.com/2009/10/06/playing-video-files-in-iphone-os/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 10:59:30 +0000</pubDate>
		<dc:creator>Kiran Salke</dc:creator>
				<category><![CDATA[iPhone SDK(Objective C)]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[Video iPhone OS]]></category>

		<guid isPermaLink="false">http://kiransalke.wordpress.com/?p=70</guid>
		<description><![CDATA[Playing Video Files in iPhone OS iPhone OS supports the ability to play back video files directly from your application using the Media Player framework (MediaPlayer.framework). Video playback is supported in full screen mode only and can be used by game developers who want to play cut scene animations or by other developers who want [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=70&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3 style="margin-top:2em;margin-bottom:.5em;font-size:17px;color:#000000;">Playing Video Files in iPhone OS</h3>
<p style="margin-top:0;margin-bottom:10px;font:normal normal normal 12px/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif;">iPhone OS supports the ability to play back video files directly from your application using the Media Player framework (<code style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;">MediaPlayer.framework</code>). Video playback is supported in full screen mode only and can be used by game developers who want to play cut scene animations or by other developers who want to play media files. When you start a video from your application, the media player interface takes over, fading the screen to black and then fading in the video content. You can play a video with or without transport controls; enabling transport controls lets the user pause or adjust the playback of the video. If you do not enable these controls, the video plays until completion or until you explicitly stop it in your code.</p>
<p style="margin-top:0;margin-bottom:10px;font:normal normal normal 12px/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif;">To initiate video playback, you must know the URL of the file you want to play. For files your application provides, this would typically be a pointer to a file in your application’s bundle; however, it can also be a pointer to a file on a remote server or elsewhere in the directory containing your application. You use this URL to instantiate a new instance of the <code style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;">MPMoviePlayerController</code> class. This class presides over the playback of your video file and manages user interactions, such user taps in the transport controls (if shown). To initiate playback, simply call the <code style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;">play</code> method of the controller.</p>
<p style="margin-top:0;margin-bottom:10px;font:normal normal normal 12px/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif;"><span style="margin-top:0;margin-bottom:10px;font:normal normal normal 12px/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif;">Listing 4-4</span> shows a sample method that playbacks the video at the specified URL. The play method is an asynchronous call that returns control to the caller while the movie plays. The movie controller loads the movie in a full-screen view, and animates the movie into place on top of the application’s existing content. When playback is finished, the movie controller sends a notification to the object, which releases the movie controller now that it is no longer needed.</p>
<table style="width:100%;background-color:#f1f5f9;border:1px solid #c9d1d7;" border="0">
<tbody>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">-(void)playMovieAtURL:(NSURL*)theURL</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">{</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">    MPMoviePlayerController* thePlayer = [[MPMoviePlayerController alloc] </pre>
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">    initWithContentURL:theURL];</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row"></td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">    thePlayer.scalingMode = MPMovieScalingModeAspectFill;</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">    thePlayer.userCanShowTransportControls = NO;</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row"></td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">    // Register for the playback finished notification.</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">    [[NSNotificationCenter defaultCenter] addObserver:self</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">                selector:@selector(myMovieFinishedCallback:)</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">                name:MPMoviePlayerPlaybackDidFinishNotification</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">                thePlayer];</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row"></td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">    // Movie playback is asynchronous, so this method returns </pre>
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">      immediately.</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">    [thePlayer play];</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">}</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row"></td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">// When the movie is done, release the controller.</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">-(void)myMovieFinishedCallback:(NSNotification*)aNotification</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">{</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">    MPMoviePlayerController* thePlayer = [aNotification object];</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row"></td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">    [[NSNotificationCenter defaultCenter] removeObserver:self</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">                name:MPMoviePlayerPlaybackDidFinishNotification</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">                thePlayer];</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row"></td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">    // Release the movie instance created in playMovieAtURL:</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">    [thePlayer release];</pre>
</td>
</tr>
<tr>
<td style="padding:6px;" scope="row">
<pre style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;white-space:pre;line-height:14px;margin:-1px 4px -3px 6px;">}</pre>
</td>
</tr>
</tbody>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kiransalke.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kiransalke.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kiransalke.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kiransalke.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kiransalke.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kiransalke.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kiransalke.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kiransalke.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kiransalke.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kiransalke.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kiransalke.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kiransalke.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kiransalke.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kiransalke.wordpress.com/70/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=70&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kiransalke.wordpress.com/2009/10/06/playing-video-files-in-iphone-os/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9898d57098670c611a10f570a7564007?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkiran33</media:title>
		</media:content>
	</item>
		<item>
		<title>How to check or identify which process is listening to port 80 in windows</title>
		<link>http://kiransalke.wordpress.com/2009/08/03/how-to-check-or-identify-which-process-is-listening-to-port-80-in-windows/</link>
		<comments>http://kiransalke.wordpress.com/2009/08/03/how-to-check-or-identify-which-process-is-listening-to-port-80-in-windows/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 14:48:10 +0000</pubDate>
		<dc:creator>Kiran Salke</dc:creator>
				<category><![CDATA[Others]]></category>

		<guid isPermaLink="false">http://kiransalke.wordpress.com/?p=67</guid>
		<description><![CDATA[From yesterday, on my computer I could not start my apache service. From the XAMPP Control Panel Application whenever I start Apache it fails to start. I reinstalled apache several time but it could not help . In fact after installing Apache HTTPD web server or Microsoft IIS Internet Information Services web server, or any [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=67&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>From yesterday, on my computer I could not start my apache service. From the XAMPP Control Panel Application whenever I start Apache it fails to start. I reinstalled apache several time but it could not help . In fact after installing Apache HTTPD web server or Microsoft IIS Internet Information Services web server, or any other application software or service and daemon that requires to open and listen to port 80 (HTTP) or port 443 (HTTPS SSL) it fails. So I consider myself to investigate about the program that is using port 80 or 443.</p>
<p>I am sure that a program is using port 80 or port 443 and restrict apache to use these port as I get following after installing Apache web server using XAMPP.</p>
<p><span style="font-weight:bold;">(OS 10052) Only one usage of each socket address (protocol/network address/port) is normally permitted. : make_sock: could not bind to address 0.0.0.0:80<br />
no listening sockets available, shutting down</span></p>
<p>So, I need to identify the program which is listening to port 80 and kill that process or at least restrict that process to listen to port 80.</p>
<p>To following steps will help you to find the culprit one.</p>
<p>1)Open command prompt. You can do it by clicking your start menu, then select Run, type cmd in the Run box and hit enter.</p>
<p>2)I expect you will see command prompt here unless you have viruses in your computer that restrict to show. In the command prompt type,</p>
<p><strong>&gt;netstat -o -n -a | findstr 0.0:80</strong><br />
in order to determine the process ID which is using port 80.</p>
<p>or type,<br />
<strong>&gt;netstat -o -n -a | findstr 0.0:443</strong><br />
in order to determine the process ID which is listening to port 443.</p>
<p>or type,<br />
<strong>&gt;netstat -aon</strong><br />
in order to list all connection that is listening, established, starting, closing and all other states. As netstat -aon will list all connections so from that you need to manually search for line 0.0.0.0:80 or 0.0.0.0:443 to determine the process ID.</p>
<p>3)Determine the process ID which is listening to port 80 or 443.<br />
A typical output from the above commands are,</p>
<pre style="font-size:12px;color:black;"><strong>E:\Documents and Settings\Arju&gt;netstat -o -n -a | findstr 0.0:80</strong>
 TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       4712

<strong>E:\Documents and Settings\Arju&gt;netstat -o -n -a | findstr 0.0:443</strong>
 TCP    0.0.0.0:443            0.0.0.0:0              LISTENING       4712
 UDP    0.0.0.0:443            *:*                                    316

<strong>E:\Documents and Settings\Arju&gt;netstat -aon</strong>

Active Connections

 Proto  Local Address          Foreign Address        State           PID
 TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       4712
 TCP    0.0.0.0:135            0.0.0.0:0              LISTENING       1324
 TCP    0.0.0.0:443            0.0.0.0:0              LISTENING       4712
 TCP    0.0.0.0:3306           0.0.0.0:0              LISTENING       1920
 TCP    0.0.0.0:5101           0.0.0.0:0              LISTENING       7636
 TCP    0.0.0.0:17536          0.0.0.0:0              LISTENING       316
 TCP    10.65.49.113:1175      118.160.238.122:80     ESTABLISHED     316
 TCP    10.65.49.113:1451      209.85.137.125:5222    ESTABLISHED     1588
 TCP    10.65.49.113:1561      66.102.9.83:80         CLOSE_WAIT      3436
 TCP    10.65.49.113:1623      96.17.159.66:80        CLOSE_WAIT      1964
 TCP    10.65.49.113:2659      216.10.192.112:80      CLOSE_WAIT      5164
 TCP    10.65.49.113:2782      216.10.192.112:80      CLOSE_WAIT      3692
 TCP    10.65.49.113:3084      74.125.87.83:80        ESTABLISHED     2736
 TCP    10.65.49.113:3179      74.125.87.191:80       ESTABLISHED     2736
 TCP    10.65.49.113:3180      74.125.87.83:80        ESTABLISHED     2736
 TCP    10.65.49.113:3185      74.125.87.101:443      ESTABLISHED     5164
 TCP    10.65.49.113:3187      74.125.87.147:80       ESTABLISHED     5164
 TCP    10.65.49.113:3850      68.180.217.28:5050     ESTABLISHED     7636
 TCP    10.65.49.113:3881      68.142.233.181:80      ESTABLISHED     7636
 TCP    10.65.49.113:4837      207.46.125.86:1863     ESTABLISHED     320
 TCP    127.0.0.1:1247         0.0.0.0:0              LISTENING       3692
 TCP    127.0.0.1:1557         0.0.0.0:0              LISTENING       6172
 TCP    127.0.0.1:1557         127.0.0.1:1558         ESTABLISHED     6172
 TCP    127.0.0.1:1558         127.0.0.1:1557         ESTABLISHED     7928
 TCP    127.0.0.1:1672         0.0.0.0:0              LISTENING       1532
 TCP    127.0.0.1:1727         127.0.0.1:1728         ESTABLISHED     7636
 TCP    127.0.0.1:1728         127.0.0.1:1727         ESTABLISHED     7636
 TCP    127.0.0.1:1990         127.0.0.1:1991         ESTABLISHED     5164
 TCP    127.0.0.1:1991         127.0.0.1:1990         ESTABLISHED     5164
 TCP    127.0.0.1:1993         127.0.0.1:1994         ESTABLISHED     5164
 TCP    127.0.0.1:1994         127.0.0.1:1993         ESTABLISHED     5164
 UDP    0.0.0.0:443            *:*                                    316
 UDP    0.0.0.0:17536          *:*                                    316
 UDP    10.65.49.113:123       *:*                                    1364
 UDP    10.65.49.113:1900      *:*                                    1500
 UDP    127.0.0.1:123          *:*                                    1364
 UDP    127.0.0.1:1025         *:*                                    1924
 UDP    127.0.0.1:1171         *:*                                    316
 UDP    127.0.0.1:1716         *:*                                    320
 UDP    127.0.0.1:1730         *:*                                    7636
 UDP    127.0.0.1:1900         *:*                                    1500
 UDP    127.0.0.1:2993         *:*                                    1588
 UDP    127.0.0.1:9877         *:*                                    1924
 UDP    127.0.0.1:9977         *:*                                    1924
 UDP    127.0.0.1:62976        *:*                                    1924</pre>
<p>From the above output we see process ID 4712 is the culprit one which is listening to port 80 and 443 and thus restrict web server to use them.</p>
<p>4)In this step find the process which has the Process ID 4712. You can simply follow <a href="http://arjudba.blogspot.com/2009/07/how-to-know-process-id-or-pid-on.html"> http://arjudba.blogspot.com/2009/07/how-to-know-process-id-or-pid-on.html</a> and bring task manager to display that process ID. From task manager Image Name determine the process name.</p>
<p>So now you can kill that process or still if you want to run that process first run you web server/apache and then run that program. In this way apache first will listen to port 80 and that program will not be able to use as it starts after web server.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kiransalke.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kiransalke.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kiransalke.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kiransalke.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kiransalke.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kiransalke.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kiransalke.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kiransalke.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kiransalke.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kiransalke.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kiransalke.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kiransalke.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kiransalke.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kiransalke.wordpress.com/67/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=67&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kiransalke.wordpress.com/2009/08/03/how-to-check-or-identify-which-process-is-listening-to-port-80-in-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9898d57098670c611a10f570a7564007?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkiran33</media:title>
		</media:content>
	</item>
		<item>
		<title>Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 0</title>
		<link>http://kiransalke.wordpress.com/2009/07/23/sys-webforms-pagerequestmanagerservererrorexception-an-unknown-error-occurred-while-processing-the-request-on-the-server-the-status-code-returned-from-the-server-was-0/</link>
		<comments>http://kiransalke.wordpress.com/2009/07/23/sys-webforms-pagerequestmanagerservererrorexception-an-unknown-error-occurred-while-processing-the-request-on-the-server-the-status-code-returned-from-the-server-was-0/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 09:51:29 +0000</pubDate>
		<dc:creator>Kiran Salke</dc:creator>
				<category><![CDATA[ASP.NET(C#)]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://kiransalke.wordpress.com/?p=64</guid>
		<description><![CDATA[If you get an error: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 0 just add this code: Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);function endRequest(sender, args){ // Check to see if there's an error on this request. if (args.get_error() != undefined) { //$get('Error').style.visibility = "visible"; // Let the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=64&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you get an error:</p>
<p><b>Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 0</b></p>
<p>just add this code:</p>
<pre><span style="color:rgb(0,0,255);"><b>Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);function endRequest(sender, args){	// Check to see if there's an error on this request.	if (args.get_error() != undefined)	{	  //$get('Error').style.visibility = "visible";	  // Let the framework know that the error is handled,	  // so it doesn't throw the JavaScript alert.	  args.set_errorHandled(true);	}}</b></span></pre>
<p><b><br />
</b></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kiransalke.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kiransalke.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kiransalke.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kiransalke.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kiransalke.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kiransalke.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kiransalke.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kiransalke.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kiransalke.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kiransalke.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kiransalke.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kiransalke.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kiransalke.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kiransalke.wordpress.com/64/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kiransalke.wordpress.com&amp;blog=7962335&amp;post=64&amp;subd=kiransalke&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kiransalke.wordpress.com/2009/07/23/sys-webforms-pagerequestmanagerservererrorexception-an-unknown-error-occurred-while-processing-the-request-on-the-server-the-status-code-returned-from-the-server-was-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9898d57098670c611a10f570a7564007?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkiran33</media:title>
		</media:content>
	</item>
	</channel>
</rss>
