tag:blogger.com,1999:blog-77127153363360268042024-02-19T13:41:50.425+05:30Xplore with SanathDiscovering Technologies Tools and Techniques with Innovationsanathhttp://www.blogger.com/profile/13451785934486799607noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-7712715336336026804.post-74020134251804970442012-02-11T17:29:00.015+05:302012-02-11T18:39:15.286+05:30Factory Method implementation in C#<div dir="ltr" style="text-align: left;" trbidi="on"><span lang="" style="font-family: Verdana, sans-serif;"> </span><b><span style="font-family: Verdana, sans-serif;">Factory Method<br />
</span></b><br />
<span style="font-family: Verdana, sans-serif;">Factory Method is a widely used mechanism for creating instances of classes in any object oriented programming language. The Factory Method abstracts the Creation of objects from the consumer.It also provides a single place where objects can be created.I supplies the desired objects hiding the complexity of creation for the consumers</span><br />
<b><span style="font-family: Verdana, sans-serif;"></span></b><br />
<b><span style="font-family: Verdana, sans-serif;">Advantages of Factory Method <br />
</span></b><br />
<span style="font-family: Verdana, sans-serif;">1. Hides the Complexity of Creation from the Consumer.</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;">2. Ensures The object creation logic to be in single place</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;">3. Helps customise creation without disturbing the Consumer logic</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;">4.brings in logical Seperation between creation and usage</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;">I have used a simple CarFactory example to demonstrate the same .The Factory manufactures swift cars of 2 types basic and Featured with 3 different colors black,blue and Red.</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<b><span style="font-family: Verdana, sans-serif;">Steps for implementing the Factory Method</span></b><br />
<b><span style="font-family: Verdana, sans-serif;"> </span></b><br />
<span style="font-family: Verdana, sans-serif;">1.Create an abstract class Swift Car with an attribute color and a method CaliculatePrice as the price differs for different models</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_vwJqSRx__TPPm6s9eGoL7Rti8Sh7WCEhVwzA3cpP2MBjifkHMeZheXw6AsA0L6EecnlVFvZrAXpoL2J_84GnElO5xXJta2yssxPGKJ6XIl9QMw5vU7P08UA-rhBNclCCaCVat6yXYw/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_vwJqSRx__TPPm6s9eGoL7Rti8Sh7WCEhVwzA3cpP2MBjifkHMeZheXw6AsA0L6EecnlVFvZrAXpoL2J_84GnElO5xXJta2yssxPGKJ6XIl9QMw5vU7P08UA-rhBNclCCaCVat6yXYw/s1600/1.png" /></span></a></div><span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;">2. Create 2 derived classes For Basic Swift Car and Featured Swift Car</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXtCUVzIgtoSxI2anLBBQkw0Sn9ETQsKHCc0NdoNXgXKpeuRQ-jJDg1RCl4MSMuN1TjKa1lONhTUdqz21oCU3m72TWHiCZ__OnTovROZlk55QOgdSDPuXXGxmGxN8LEJGPZ8UnFiWOHA/s1600/2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXtCUVzIgtoSxI2anLBBQkw0Sn9ETQsKHCc0NdoNXgXKpeuRQ-jJDg1RCl4MSMuN1TjKa1lONhTUdqz21oCU3m72TWHiCZ__OnTovROZlk55QOgdSDPuXXGxmGxN8LEJGPZ8UnFiWOHA/s1600/2.png" /></span></a><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4K9gj3yQD6fyCOJpYRWs3Z3bOuxYWTI7ADbSnz951izG4Gvq-y6lRrmDO6OgSquqoq1-2bosxehU_0n4HqCqU76IkhxR7LwdgLUOoU7LWy_xWJL3dahY4pY2EDM2hYE4fQgfZgyjrTg/s1600/3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4K9gj3yQD6fyCOJpYRWs3Z3bOuxYWTI7ADbSnz951izG4Gvq-y6lRrmDO6OgSquqoq1-2bosxehU_0n4HqCqU76IkhxR7LwdgLUOoU7LWy_xWJL3dahY4pY2EDM2hYE4fQgfZgyjrTg/s1600/3.png" /></span></a><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;">3. Define Enumerations which describe the Car types and Car Colors </span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZWUcbt6fRaiIg_7iv4-VezlO9IJo3e5WfoL8IGVxD6gJ3j80GcYOBLZFpy44Y15pqwRMeBrmT2OOAqq_fMjc7n8nLmCu92Eei52wZbV-bgNI4SKCMHM-33ozKkZlQk_VmEcfXqzUUTg/s1600/4.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZWUcbt6fRaiIg_7iv4-VezlO9IJo3e5WfoL8IGVxD6gJ3j80GcYOBLZFpy44Y15pqwRMeBrmT2OOAqq_fMjc7n8nLmCu92Eei52wZbV-bgNI4SKCMHM-33ozKkZlQk_VmEcfXqzUUTg/s1600/4.png" /></span></a><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><br />
<span style="font-family: Verdana, sans-serif;">4. Create a Static Class with a Static Method which Returns the Car of Desired Type</span><br />
<strong><span style="font-family: Verdana, sans-serif;">Note: </span></strong><br />
<span style="font-family: Verdana, sans-serif;">it is very important to keep the abstract base class Swift car as a Return Type.</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj18fNNqizsO2TTjKfnXeh8sdW7gbZPu47ht12rC5rGpfC6pFlQYreiN-ZExOeP9Fjc7eeqz9G96fYC5pkE6oBiTCKSEvvdcqf8NW9Hamf-9Yx6xYZCuec4hlKqz4c7TjzpVkvA0562LA/s1600/5.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj18fNNqizsO2TTjKfnXeh8sdW7gbZPu47ht12rC5rGpfC6pFlQYreiN-ZExOeP9Fjc7eeqz9G96fYC5pkE6oBiTCKSEvvdcqf8NW9Hamf-9Yx6xYZCuec4hlKqz4c7TjzpVkvA0562LA/s1600/5.png" /></span></a><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;">5. Design a Client to Consume the Car from the Swift Car Factory.</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE_h4N1oTE9I5Aye4QU57ERUGYvAnarUc6h0myMSzx3BqHloKsrJGVbUCAc2lURGkfGM6ePhgpEMswwybKBTPHvUqO_-hr05aUi4_L69Ok_ipjtygI7t23qbEo2w_YE3Neg3Nn2Un22g/s1600/6.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE_h4N1oTE9I5Aye4QU57ERUGYvAnarUc6h0myMSzx3BqHloKsrJGVbUCAc2lURGkfGM6ePhgpEMswwybKBTPHvUqO_-hr05aUi4_L69Ok_ipjtygI7t23qbEo2w_YE3Neg3Nn2Un22g/s1600/6.png" /></span></a></div><span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;">Finally it can be observed that creation logic is unknown to the client and Since the factory takes care of the creation .the Factory logic can be further customised or changed easily.</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;"> </span></div>sanathhttp://www.blogger.com/profile/13451785934486799607noreply@blogger.com0tag:blogger.com,1999:blog-7712715336336026804.post-60875053090229790572012-01-24T22:00:00.001+05:302012-01-24T22:00:58.411+05:30Reading and Updating WCF Configuration file<div dir="ltr" style="text-align: left;" trbidi="on"><span style="font-family: inherit;">It had been very long since I had blogged. I had a peculiar requirement where I needed to parse the configuration of a WCF Service. that is the <System.ServiceModel> tag in the configuration file.</span><br />
<span style="font-family: inherit;">I finally came to know that there was a dedicated namespace System.ServiceModel.Configuration,</span><br />
<span style="font-family: inherit;">Following is code that helps read and update the configuration file</span><br />
<br />
<span style="font-family: inherit;"> <span style="background-color: transparent; color: blue; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">using system.ServiceModel;</span></span><br />
<span style="background-color: transparent; color: blue; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"><span style="font-family: inherit;"> <span style="background-color: transparent; color: blue; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">using system.ServiceModel.Configuration;</span></span></span><br />
<br />
<span style="font-family: inherit;"><span id="internal-source-marker_0.3615221887885146" style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Configuration</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> c = </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">ConfigurationManager</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">.OpenExeConfiguration(</span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">ConfigurationUserLevel</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">.None);</span></span><br />
<br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"><span style="font-family: inherit;">//Read the Service Model Tag</span></span><br />
<span style="font-family: inherit;"><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">ServiceModelSectionGroup</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> SvCGroup = System.ServiceModel.Configuration.</span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">ServiceModelSectionGroup</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">.GetSectionGroup(c);</span></span><br />
<br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"><span style="font-family: inherit;">//get the count of the number of Services and the service Model</span></span><br />
<span style="font-family: inherit;"><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Console</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">.WriteLine(</span><span style="background-color: transparent; color: #a31515; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">"Number of Services: "</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> + SvCGroup.Services.Services.Count);</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Console</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">.WriteLine(</span><span style="background-color: transparent; color: #a31515; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">"Number of ServiceBehaviours: "</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> + SvCGroup.Behaviors.ServiceBehaviors.Count);</span></span><br />
<span style="font-family: inherit;">//iterate through the services in the config file</span><br />
<span style="background-color: transparent; color: blue; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><span style="font-family: inherit;"><span style="background-color: transparent; color: blue; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">foreach</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> (</span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">ServiceElement</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> ele </span><span style="background-color: transparent; color: blue; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">in</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> SvCGroup.Services.Services)</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> {</span></span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><span style="font-family: inherit;"> //Name of the Service<br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Console</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">.WriteLine(</span><span style="background-color: transparent; color: #a31515; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">"Service Name -"</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> + ele.Name);</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span></span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"><span style="font-family: inherit;"> //The Host Tag</span></span><br />
<span style="font-family: inherit;"><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">HostElement</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> hele = ele.Host;</span></span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><span style="font-family: inherit;"> </span><br />
<span style="font-family: inherit;"> //iterate through the list of base addresses<br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: blue; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">foreach</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> (</span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">BaseAddressElement</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> belement </span><span style="background-color: transparent; color: blue; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">in</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> hele.BaseAddresses)</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> {</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Console</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">.WriteLine(</span><span style="background-color: transparent; color: #a31515; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">" Base Address -"</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> + belement.BaseAddress);</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> }</span></span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><span style="font-family: inherit;"> </span><br />
<span style="font-family: inherit;"> //get the endpoint details<br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: blue; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">foreach</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> (</span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">ServiceEndpointElement</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> sep </span><span style="background-color: transparent; color: blue; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">in</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> ele.Endpoints)</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> {</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Console</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">.WriteLine(</span><span style="background-color: transparent; color: #a31515; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">"------Endpoint -----------"</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">);</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Console</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">.WriteLine(</span><span style="background-color: transparent; color: #a31515; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">"Address -"</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> + sep.Address.ToString());</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Console</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">.WriteLine(</span><span style="background-color: transparent; color: #a31515; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">"Binding -"</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> + sep.Binding.ToString());</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Console</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">.WriteLine(</span><span style="background-color: transparent; color: #a31515; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">"Contract -"</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> + sep.Contract);</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Console</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">.WriteLine(</span><span style="background-color: transparent; color: #a31515; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">"Changing Contract to IService2"</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">);</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> sep.Contract = </span><span style="background-color: transparent; color: #a31515; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">"IService2"</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">;</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Console</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">.WriteLine(</span><span style="background-color: transparent; color: #a31515; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">"DNS -: "</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> + sep.Identity.Dns.Value);</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Console</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">.WriteLine();</span><br />
<br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> }</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> }</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span> // get the list of ServiceBehaviour elements<br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: blue; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">foreach</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> (</span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">ServiceBehaviorElement</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> behavelement </span><span style="background-color: transparent; color: blue; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">in</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> SvCGroup.Behaviors.ServiceBehaviors)</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> {</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> Console</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">.WriteLine(</span><span style="background-color: transparent; color: #a31515; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">"-------------ServiceBehaviour--------------"</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">);</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: blue; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">foreach</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> (</span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">BehaviorExtensionElement</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> extele </span><span style="background-color: transparent; color: blue; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">in</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> behavelement)</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> {</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span> </span><br />
<span style="font-family: inherit;"> //get the service metadata element<br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: blue; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">if</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> (extele </span><span style="background-color: transparent; color: blue; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">is</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">ServiceMetadataPublishingElement</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">)</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> {</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Console</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">.WriteLine(</span><span style="background-color: transparent; color: #a31515; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">"---------------------------MetaData Behaviour------------------"</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">);</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">ServiceMetadataPublishingElement</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> behaviour1 = extele </span><span style="background-color: transparent; color: blue; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">as</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">ServiceMetadataPublishingElement</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">;</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Console</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">.WriteLine(</span><span style="background-color: transparent; color: #a31515; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">"Behaviour Name: "</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> + behaviour1.ConfigurationElementName);</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Console</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">.WriteLine(</span><span style="background-color: transparent; color: #a31515; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">"Property HttpGetEnabled: "</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> + behaviour1.HttpGetEnabled);</span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> }</span></span><br />
<span style="font-family: inherit;">}</span><br />
<br />
<span style="font-family: inherit;">you can also set back the properties and call the configuration.Save(); to change the config file</span><br />
<span style="font-family: inherit;"><span id="internal-source-marker_0.3615221887885146" style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> c.SaveAs(</span><span style="background-color: transparent; color: #a31515; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">"ConsoleApplication1.exe.config"</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">, </span><span style="background-color: transparent; color: #2b91af; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">ConfigurationSaveMode</span><span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">.Modified);</span></span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"><span style="font-family: inherit;"> this saves on the modified parts of the configuration class. how ever 2 other overloads are provided.</span></span><br />
<br />
<br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Consolas; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"><span style="font-family: inherit;"> </span></span><br />
<br />
</div>sanathhttp://www.blogger.com/profile/13451785934486799607noreply@blogger.com0tag:blogger.com,1999:blog-7712715336336026804.post-62099605213854778552011-11-27T13:19:00.000+05:302011-11-27T13:19:35.954+05:30Extending ClientBase to Create a WCF Service Proxy<div dir="ltr" style="text-align: left;" trbidi="on"><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="margin: 0cm 0cm 10pt;"><span style="line-height: 115%;"><span style="font-family: Verdana, sans-serif;">I was trying to explore different ways of creating a proxy to use the service. I knew 3 ways to doing it<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="margin: 0cm 0cm 10pt;"><span style="line-height: 115%;"><span style="font-family: Verdana, sans-serif;">1.using <b style="mso-bidi-font-weight: normal;">SVCUtil.exe<o:p></o:p></b></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="margin: 0cm 0cm 10pt;"><span style="line-height: 115%;"><span style="font-family: Verdana, sans-serif;">2.using<b style="mso-bidi-font-weight: normal;"> Add Service Reference</b> <o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="margin: 0cm 0cm 10pt;"><span style="line-height: 115%;"><span style="font-family: Verdana, sans-serif;">3.using <b style="mso-bidi-font-weight: normal;">ChannelFactory<T></b> and <b style="mso-bidi-font-weight: normal;">DuplexChannelFactory<T></b> classes <br />
As and when I explored that we could also create a proxy by using a wonderful class <b style="mso-bidi-font-weight: normal;">ClientBase<T></b> <o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="margin: 0cm 0cm 10pt;"><span style="line-height: 115%;"><span style="font-family: Verdana, sans-serif;">Here are the steps I followed to create a Proxy using <b style="mso-bidi-font-weight: normal;">ClientBase<T></b><o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="margin: 0cm 0cm 10pt;"><span style="line-height: 115%;"><span style="font-family: Verdana, sans-serif;">1.Created a Sample service and Hosted in IIS <o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="margin: 0cm 0cm 10pt;"><span style="line-height: 115%;"><span style="font-family: Verdana, sans-serif;">2.Copy the Service Interface to Client Code<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="margin: 0cm 0cm 10pt;"><span style="line-height: 115%;"><span style="font-family: Verdana, sans-serif;">3.Extend the <b style="mso-bidi-font-weight: normal;">ClientBase<T></b><o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="margin: 0cm 0cm 10pt;"><span style="line-height: 115%;"><span style="font-family: Verdana, sans-serif;">4. Create the proxy in the client and use<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="margin: 0cm 0cm 10pt;"><br />
</div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="margin: 0cm 0cm 10pt;"><span style="line-height: 115%;"><span style="font-family: Verdana, sans-serif;">1.The Service Interface is as follows<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;">[<span style="color: #2b91af;">ServiceContract</span>]<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">public</span> <span style="color: blue;">interface</span> <span style="color: #2b91af;">IService1</span><o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><br />
</div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span>[<span style="color: #2b91af;">OperationContract</span>]<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">string</span> GetData(<span style="color: blue;">int</span> value);<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><br />
</div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><br />
</div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">// TODO: Add your service operations here</span><o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><br />
</div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><br />
</div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="margin: 0cm 0cm 10pt;"><span style="line-height: 115%;"><span style="font-family: Verdana, sans-serif;">The Implementation is as follows<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Service1</span> : <span style="color: #2b91af;">IService1</span><o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">public</span> <span style="color: blue;">string</span> GetData(<span style="color: blue;">int</span> value)<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">return</span> <span style="color: blue;">string</span>.Format(<span style="color: #a31515;">"You entered: {0}"</span>, value);<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><br />
</div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><br />
</div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><br />
</div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Verdana, sans-serif;">2. I copied the Service interface<span style="mso-spacerun: yes;"> </span>to the Client Code <o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Verdana, sans-serif;">3. Extended the <b style="mso-bidi-font-weight: normal;">ClientBase<T></b> as Follow<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">class</span> <span style="color: #2b91af;">ServiceClient</span>:<span style="color: #2b91af;">ClientBase</span><<span style="color: #2b91af;">IService1</span>>,<span style="color: #2b91af;">IService1</span><o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><br />
</div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">public</span> ServiceClient(<span style="color: #2b91af;">BasicHttpBinding</span> binding, <span style="color: #2b91af;">EndpointAddress</span> address<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span>):<span style="color: blue;">base</span>(binding,address)<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><br />
</div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">protected</span> <span style="color: blue;">override</span> <span style="color: #2b91af;">IService1</span><span style="mso-spacerun: yes;"> </span>CreateChannel()<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;">{<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span><span style="mso-tab-count: 1;"> </span><span style="mso-spacerun: yes;"> </span><span style="color: blue;">return</span> <span style="color: blue;">base</span>.CreateChannel();<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;">}<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Verdana, sans-serif;"><span style="color: blue; font-family: Consolas;">public</span><span style="font-family: Consolas;"> <span style="color: blue;">string</span><span style="mso-spacerun: yes;"> </span>GetData(<span style="color: blue;">int</span> value)<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;">{<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span><span style="mso-tab-count: 1;"> </span><span style="color: blue;">return</span> <span style="color: blue;">base</span>.Channel.GetData(value);<span style="mso-spacerun: yes;"> </span><o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;">}<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;">}<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;">}<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><br />
</div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="margin: 0cm 0cm 10pt;"><br />
</div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="margin: 0cm 0cm 10pt;"><span style="line-height: 115%;"><span style="font-family: Verdana, sans-serif;">4.We can Invoke the custom handcoded proxy as follows<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Verdana, sans-serif;"><span style="color: blue; font-family: Consolas;">class</span><span style="font-family: Consolas;"> <span style="color: #2b91af;">Program</span><o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">static</span> <span style="color: blue;">void</span> Main(<span style="color: blue;">string</span>[] args)<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">ServiceClient</span> client = <span style="color: blue;">new</span> <span style="color: #2b91af;">ServiceClient</span>(<span style="color: blue;">new</span> <span style="color: #2b91af;">BasicHttpBinding</span>(<span style="color: #2b91af;">BasicHttpSecurityMode</span>.None), <span style="color: blue;">new</span> <span style="color: #2b91af;">EndpointAddress</span>(<span style="color: #a31515;">"http://mycomputer:61468/Service1.svc"</span>)); <o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">Console</span>.WriteLine(client.GetData(10));<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">Console</span>.ReadLine();<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-family: Verdana, sans-serif;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="margin: 0cm 0cm 10pt;"><br />
</div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="margin: 0cm 0cm 10pt;"><br />
</div><span style="font-family: Verdana, sans-serif;"> </span><div class="MsoNormal" style="margin: 0cm 0cm 10pt;"><br />
</div><span style="font-family: Verdana, sans-serif;"> </span></div>sanathhttp://www.blogger.com/profile/13451785934486799607noreply@blogger.com4tag:blogger.com,1999:blog-7712715336336026804.post-2325713893557247542011-11-05T18:51:00.000+05:302011-11-05T18:53:00.624+05:30using Microsoft Message Queuing and System.Messaging<div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">Microsoft has provided a wonderful Queuing framework .It is known as Microsoft message Queuing .This can used for data storage during failure at the same time send message between two processes in the same machine or 2 different machine</span><br />
<div class="MsoNormal"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span></div><div class="MsoNormal"><b><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">In case of 2 processes in a local machine we use Private Queue</span></b></div><div class="MsoNormal"><b><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">In case of 2 processes in 2 remote machines we use public Queues</span></b></div><div class="MsoNormal"><b><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span></b></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">The message Queue Installation is available in <b>Add remove Windows Components Message Queuing</b></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">After installing the same .you will able to create an use Message Queues</span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">The Queues can be created by following the steps</span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span></div><div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">1.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span>Start <b>CompMgmt.msc</b></span></div><div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">2.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span>You get <b>MessageQueing</b> Sub menu</span></div><div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">3.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span>You can Select <b>Private</b> and <b>Public</b> Queues and Select New</span></div><div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">4.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span>Enter the <b>Queue Name</b></span></div><div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">5.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span>Select <b>Transactional</b> and <b>Non-Transactional</b> </span></div><div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span></div><div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">6.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span>The public queue name format is <b>machine-name\public$\Queue-Name</b></span></div><div class="MsoListParagraphCxSpLast" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">7.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span>The private queue name format is <b>machine-name\private$\Queue-Name</b></span></div><div class="MsoListParagraphCxSpLast" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><b><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span></b></div><div class="MsoNormal" style="margin-left: 18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">I have written an article in this blog that demonstrates a <b>QueueServer</b> and a <b>QueueClient</b>.</span></div><div class="MsoNormal" style="margin-left: 18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">The <b>Queue Server</b> pushes the message to a private Queue with name test Queue</span></div><div class="MsoNormal" style="margin-left: 18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">The <b>Queue Client</b> Recieves the message and displays it on the console</span></div><div class="MsoNormal" style="margin-left: 18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span></div><div class="MsoNormal" style="margin-left: 18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">The Queue stores the messages that is <b>Enqueued</b> and <b>Dequeued</b> in the first in first out order</span></div><div class="MsoNormal" style="margin-left: 18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span></div><div class="MsoNormal" style="margin-left: 18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">Messages contain 3 important parts which I have used </span></div><div class="MsoNormal" style="margin-left: 18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><b>Label</b> –unique id for the message</span></div><div class="MsoNormal" style="margin-left: 18.0pt;"><b><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span></b></div><div class="MsoNormal" style="margin-left: 18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><b>Formatter</b> – the way in which message is stored it may be binary,text,xml or custom .</span></div><div class="MsoNormal" style="margin-left: 18.0pt;"><b><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span></b></div><div class="MsoNormal" style="margin-left: 18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><b>Body</b> – The field which stores the message .</span></div><div class="MsoNormal" style="margin-left: 18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">The message can be retrieved by the client in <b>Synchronous</b> and <b>Asynchronous</b> fashion</span></div><div class="MsoNormal" style="margin-left: 18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">I have used asynchronous mechanism to retrieve the messages in the message queue client side</span></div><div class="MsoNormal" style="margin-left: 18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">Following is the example </span></div><div class="MsoNormal" style="margin-left: 18.0pt;"><b><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span></b></div><div class="MsoNormal" style="margin-left: 18.0pt;"><b><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">Queue Server<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-left: 18.0pt;"><b><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span></b></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: blue; font-size: 9.5pt;">using</span><span style="font-size: 9.5pt;"> System;<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: blue; font-size: 9.5pt;">using</span><span style="font-size: 9.5pt;"> System.Collections.Generic;<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: blue; font-size: 9.5pt;">using</span><span style="font-size: 9.5pt;"> System.Linq;<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: blue; font-size: 9.5pt;">using</span><span style="font-size: 9.5pt;"> System.Text;<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: blue; font-size: 9.5pt;">using</span><span style="font-size: 9.5pt;"> System.Messaging;<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: blue; font-size: 9.5pt;">namespace</span><span style="font-size: 9.5pt;"> MessageQueueServer<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">{<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">Program</span><o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> {<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> Main(<span style="color: blue;">string</span>[] args)<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> {<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: green;">//create a Queue if it doesnot exists</span><o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: blue;">if</span> (!<span style="color: #2b91af;">MessageQueue</span>.Exists(<span style="color: #a31515;">@"mycomputer\private$\testQueue"</span>))<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> {<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: green;">//create a message queue</span><o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: #2b91af;">MessageQueue</span>.Create(<span style="color: #a31515;">@"mycomputer\private$\testQueue"</span>); <o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> }<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: green;">//instance representing the Queue</span><o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: #2b91af;">MessageQueue</span> Queue = <span style="color: blue;">new</span> <span style="color: #2b91af;">MessageQueue</span>(<span style="color: #a31515;">@"mycomputer\private$\testQueue"</span>);<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: blue;">int</span> messagecount = <span style="color: blue;">int</span>.MaxValue;<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: blue;">int</span> messageindex = 0;<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: blue;">while</span> (messageindex < messagecount)<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> {<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: green;">//create messages</span><o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: #2b91af;">Message</span> QueMessage = <span style="color: blue;">new</span> <span style="color: #2b91af;">Message</span>();<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: green;">//unique id for the message</span><o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> QueMessage.Label = messageindex.ToString();<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: green;">//can be any information</span><o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> QueMessage.Body =<span style="color: #a31515;">"m"</span>+ messageindex;<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> QueMessage.Formatter = <span style="color: blue;">new</span> <span style="color: #2b91af;">BinaryMessageFormatter</span>(); <o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: green;">//send the message to the Queue</span><o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"pushing message no "</span> + messageindex + <span style="color: #a31515;">"to "</span> + Queue.QueueName); <o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> Queue.Send(QueMessage);<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> messageindex++; <o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> }<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: #2b91af;">Console</span>.ReadLine(); <o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> }<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> }<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">}<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-left: 18.0pt;"><b><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">The code above pushes the messages to the Queue<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-left: 18.0pt;"><b><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span></b></div><div class="MsoNormal" style="margin-left: 18.0pt;"><b><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">Queue Client<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-left: 18.0pt;"><b><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span></b></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: blue; font-size: 9.5pt;">using</span><span style="font-size: 9.5pt;"> System;<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: blue; font-size: 9.5pt;">using</span><span style="font-size: 9.5pt;"> System.Collections.Generic;<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: blue; font-size: 9.5pt;">using</span><span style="font-size: 9.5pt;"> System.Linq;<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: blue; font-size: 9.5pt;">using</span><span style="font-size: 9.5pt;"> System.Text;<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: blue; font-size: 9.5pt;">using</span><span style="font-size: 9.5pt;"> System.Messaging;<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: blue; font-size: 9.5pt;">namespace</span><span style="font-size: 9.5pt;"> MessageQueueClient<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">{<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">Program</span><o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> {<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: blue;">static</span> <span style="color: #2b91af;">MessageQueue</span> queue;<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> Main(<span style="color: blue;">string</span>[] args)<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> {<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: green;">//access the queue</span><o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> queue = <span style="color: blue;">new</span> <span style="color: #2b91af;">MessageQueue</span>(<span style="color: #a31515;">@"mycomputer\private$\testQueue"</span>);<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> queue.ReceiveCompleted += <span style="color: blue;">new</span> <span style="color: #2b91af;">ReceiveCompletedEventHandler</span>(queue_ReceiveCompleted);<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: green;">//start recieving the message</span><o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> queue.BeginReceive();<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: #2b91af;">Console</span>.ReadLine(); <o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> }<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> queue_ReceiveCompleted(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">ReceiveCompletedEventArgs</span> e)<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> {<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: green;">//recieve the message from the Queue and close it until one message is processed</span><o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: #2b91af;">Message</span> message = queue.EndReceive (e.AsyncResult);<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"Message recieved with id:"</span> + e.Message.Label);<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: green;">//format the message to retrieve the data</span><o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> e.Message.Formatter = <span style="color: blue;">new</span> <span style="color: #2b91af;">BinaryMessageFormatter</span>();<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"Content in the Queue:"</span> + e.Message.Body);<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"--------------------------------"</span>);<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span style="color: green;">//open the queue for recieving</span><o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> queue.BeginReceive(); <o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> }<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> }<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-size: 9.5pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">}<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-left: 18.0pt; tab-stops: 329.25pt;"><b><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">The code above is a Queue Client and receives the messages from the Queue Server </span></b></div><div class="MsoNormal" style="margin-left: 18.0pt; tab-stops: 329.25pt;"><b><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <o:p></o:p></span></b></div><div class="MsoNormal" style="margin-left: 18.0pt; tab-stops: 329.25pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">Run the Queue Server and then the Queue Client and enjoy the example.</span></div><div class="MsoNormal" style="margin-left: 18.0pt;"><br />
</div><div class="MsoNormal" style="margin-left: 18.0pt;"><br />
</div><div class="MsoNormal" style="margin-left: 18.0pt;"><br />
</div><div class="MsoNormal" style="margin-left: 18.0pt;"><br />
</div><div class="MsoNormal" style="margin-left: 18.0pt;"><br />
</div><div class="MsoNormal" style="margin-left: 18.0pt;"><br />
</div><div class="MsoNormal" style="margin-left: 18.0pt;"><br />
</div><div class="MsoNormal" style="margin-left: 18.0pt;"><br />
</div></div>sanathhttp://www.blogger.com/profile/13451785934486799607noreply@blogger.com0tag:blogger.com,1999:blog-7712715336336026804.post-30964731648349078152011-10-30T15:39:00.000+05:302011-10-30T15:47:27.277+05:30Copying large collections without iteration<div dir="ltr" style="text-align: left;" trbidi="on">I had go through an interesting situation where I had to copy items from one collection to another.The problem was that the collection was very large and iterating through it was not a very good option . I solved the problem using the snippet below<br />
<div class="MsoNormal">This example is just a representation of the problem. In My situation the stack had 100 thousand integers int .I had to copy it to a ordered list of integers</div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System;<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Collections.Generic;<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Collections;<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">namespace</span><span style="font-family: Consolas; font-size: 9.5pt;"> testCollection<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">Program</span><o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> Main(<span style="color: blue;">string</span>[] args)<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//Stack of integers</span><o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Stack</span><<span style="color: blue;">int</span>> stackCollection = <span style="color: blue;">new</span> <span style="color: #2b91af;">Stack</span><<span style="color: blue;">int</span>>();<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> stackCollection.Push(1);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> stackCollection.Push(2);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> stackCollection.Push(3);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> stackCollection.Push(4);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> stackCollection.Push(5);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//copying the items of stack into the ordered list</span><o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">List</span><<span style="color: blue;">int</span>> listCollection = <span style="color: blue;">new</span> <span style="color: #2b91af;">List</span><<span style="color: blue;">int</span>>(stackCollection);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Console</span>.WriteLine(listCollection.Count); <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span class="Apple-style-span" style="font-family: Consolas; font-size: 13px;"> }</span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"> }<br />
}</div></div>sanathhttp://www.blogger.com/profile/13451785934486799607noreply@blogger.com0tag:blogger.com,1999:blog-7712715336336026804.post-60678935309224582992011-10-30T14:49:00.000+05:302011-10-30T15:44:35.713+05:30Iterating through collections without For and Foreach using IEnumerable and IEnumerator<div dir="ltr" style="text-align: left;" trbidi="on"><br />
<div class="MsoNormal"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">We were using a number of collections holding same type of data. Someone asked me if there is a way to handle these collections in a common way. In other words how do we iterate through different kinds of collection using a common function .I told them we could achieve the same using a function with <b>IEnumerable<T> . </b>I demonstrated the same using 3 collections Generic <b>Stack, Queue, and Ordered List. </b></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">Following is the code snippet that demonstrates the same</span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System;<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Collections.Generic;<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Collections;<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">namespace</span><span style="font-family: Consolas; font-size: 9.5pt;"> testCollection<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">Program</span><o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> Main(<span style="color: blue;">string</span>[] args)<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//Stack of integers</span><o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Stack</span><<span style="color: blue;">int</span>> stackCollection = <span style="color: blue;">new</span> <span style="color: #2b91af;">Stack</span><<span style="color: blue;">int</span>>();<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> stackCollection.Push(1);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> stackCollection.Push(2);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> stackCollection.Push(3);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> stackCollection.Push(4);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> stackCollection.Push(5);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//Queue of Integers</span><o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Queue</span><<span style="color: blue;">int</span>> queueCollection = <span style="color: blue;">new</span> <span style="color: #2b91af;">Queue</span><<span style="color: blue;">int</span>>();<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> queueCollection.Enqueue(1);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> queueCollection.Enqueue(2);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> queueCollection.Enqueue(3);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> queueCollection.Enqueue(4);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> queueCollection.Enqueue(5);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//ordered list of integers</span><o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">List</span><<span style="color: blue;">int</span>> listCollection = <span style="color: blue;">new</span> <span style="color: #2b91af;">List</span><<span style="color: blue;">int</span>>();<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> listCollection.Add(1);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> listCollection.Add(2);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> listCollection.Add(3);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> listCollection.Add(4);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> listCollection.Add(5);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//iterates through the stack of items in last in first out manner</span><o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> GetItems(stackCollection);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//iterates through the queue in a fist in first out manner</span><o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> GetItems(queueCollection);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//Iterates through an ordered list of integers</span><o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> GetItems(listCollection);<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Console</span>.ReadLine(); <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary></span><o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">///</span><span style="color: green;"> generic iteration logic for a collection</span><o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary ></span><o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param name="collection"></span><span style="color: green;"> is decided at runtime and instance of a class implementing ienumerable</span><span style="color: grey;"></param></span><o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">void</span> GetItems(<span style="color: #2b91af;">IEnumerable</span><<span style="color: blue;">int</span>> collection)<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//gets the enumerator </span><o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">IEnumerator</span><<span style="color: blue;">int</span>> enumerator = collection.GetEnumerator();<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">while</span> (enumerator.MoveNext ())<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//gets the items from the collection</span><o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Console</span>.WriteLine(enumerator.Current); <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div></div>sanathhttp://www.blogger.com/profile/13451785934486799607noreply@blogger.com0tag:blogger.com,1999:blog-7712715336336026804.post-39042341768342545082011-10-20T20:33:00.000+05:302011-10-30T15:57:43.770+05:30Instrumenting code using #if DEBUG #endif Block<div dir="ltr" style="text-align: left;" trbidi="on"><br />
<div class="MsoNormal">Its usually very difficult to debug a software with large amount of code. People generally writelogs, write traces while debugging code and often forget to remove these .this will result in undesirable messages in production code. </div><div class="MsoNormal">A bad way of instrumenting code is shown below</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas;">static</span><span style="font-family: Consolas;"> <span style="color: blue;">void</span> calleeFunc()<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> <span style="color: blue;">try</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> <span style="color: #2b91af;">Trace</span>.WriteLine(<span style="color: #a31515;">"in callee func"</span>);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"in callee func"</span>);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> <span style="color: blue;">int</span> i = 1;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> <span style="color: blue;">int</span> j = 0;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> <span style="color: blue;">int</span> k = i / j;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> <span style="color: blue;">catch</span> (<span style="color: #2b91af;">Exception</span> ex)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> <span style="color: blue;">throw</span> ;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal">The problem with this snippet is that it displays unnecessary messages when compiled in Release mode.This can also lead to security vulnerabilities</div><div class="MsoNormal">A way to solve the problem is the use of conditional compilation directives provided by c# compiler.</div><div class="MsoNormal">The #if DEBUG end if block enables the trace message and console messages in debug mode and strips it of in release mode</div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> calleeFunc()<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> <span style="color: blue;">try</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas;">#if</span><span style="font-family: Consolas;"> DEBUG<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: grey; font-family: Consolas;"> Trace.WriteLine("in callee func");</span><span style="font-family: Consolas;"><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: grey; font-family: Consolas;"> Console.WriteLine("in callee func");</span><span style="font-family: Consolas;"><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas;">#endif</span><span style="font-family: Consolas;"><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> <span style="color: blue;">int</span> i = 1;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> <span style="color: blue;">int</span> j = 0;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> <span style="color: blue;">int</span> k = i / j;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> <span style="color: blue;">catch</span> (<span style="color: #2b91af;">Exception</span> ex)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> <span style="color: blue;">throw</span> ;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas;">The use of the #if debug #endif block helps eliminate unnecessary debug messages in production(Release Mode code) This way you can stop spending large amount of time in removing code used for understanding or tracing.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div></div>sanathhttp://www.blogger.com/profile/13451785934486799607noreply@blogger.com0tag:blogger.com,1999:blog-7712715336336026804.post-23677709223451056452011-10-19T18:11:00.000+05:302011-10-19T18:15:22.479+05:30Re-throwing exceptions Throw Vs Throw ex<div dir="ltr" style="text-align: left;" trbidi="on"><br />
<div class="MsoNormal"><span style="font-family: Arial, sans-serif;">Most of us use exception handling very frequently .we generally use try catch finally for handling exceptions.We are often mislead due to bad rethrow of exceptions.<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: Arial, sans-serif;">The following snippet shows a bad rethrow <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">namespace</span><span style="font-family: Consolas; font-size: 9.5pt;"> ExceptionTest<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">Program</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> Main(<span style="color: blue;">string</span>[] args)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">try</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> callerFunc();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">catch</span> (<span style="color: #2b91af;">Exception</span> ex)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Console</span>.WriteLine(ex.StackTrace);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Console</span>.ReadLine(); <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> callerFunc( )<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">try</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> calleeFunc();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">catch</span> (<span style="color: #2b91af;">Exception</span> ex)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">throw</span> ex;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> calleeFunc()<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">try</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">int</span> i = 1;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">int</span> j = 0;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">int</span> k = i / j;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">catch</span> (<span style="color: #2b91af;">Exception</span> ex)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">throw</span> ex ;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">The result of this code is shown below<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY1ZmrA-q91zbGgYGskdxDLEWwTTRb6aFuyyHZlKgaWZavLi-NVShATMK1fn2V0iBk0bN-upKS8kEV06suIpNmcAVMrF65EUnj1vpJ-9PETKvExsNOiFr74qs3X5q0Jk5EiljeUZoc9Q/s1600/throwex.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="131" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY1ZmrA-q91zbGgYGskdxDLEWwTTRb6aFuyyHZlKgaWZavLi-NVShATMK1fn2V0iBk0bN-upKS8kEV06suIpNmcAVMrF65EUnj1vpJ-9PETKvExsNOiFr74qs3X5q0Jk5EiljeUZoc9Q/s640/throwex.png" width="640" /></a></div><span class="Apple-style-span" style="font-family: Consolas; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">The information here is totally misleading as it only gives a partial idea of the total stacktrace of the program. The stacktrace is not preserved.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">The Solution is to never use Throw ex, instead use only Throw. The following code preserves the stacktrace of the code.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">namespace</span><span style="font-family: Consolas; font-size: 9.5pt;"> ExceptionTest<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">Program</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> Main(<span style="color: blue;">string</span>[] args)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">try</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> callerFunc();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">catch</span> (<span style="color: #2b91af;">Exception</span> ex)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Console</span>.WriteLine(ex.StackTrace);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Console</span>.ReadLine(); <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> callerFunc( )<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">try</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> calleeFunc();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">catch</span> (<span style="color: #2b91af;">Exception</span> ex)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">throw</span>;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> calleeFunc()<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">try</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">int</span> i = 1;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">int</span> j = 0;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">int</span> k = i / j;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">catch</span> (<span style="color: #2b91af;">Exception</span> ex)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">throw</span> ;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">The output of this code preserves the stackTrace totally to get the exact location of the exception.<o:p></o:p></span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEja0tByF-Z7bK7o7WUIQsEmkhcGYdRUtaY7g5THiBbxrsx1AuydnaaEHUfYAPU1T_8p6FGUs7T2eNd4mX60OXBl24ktWWLu3r3Z45bllaMt8yaSyNYOC8Em6eh6rsfvhBUp8UarUPf59g/s1600/throw.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEja0tByF-Z7bK7o7WUIQsEmkhcGYdRUtaY7g5THiBbxrsx1AuydnaaEHUfYAPU1T_8p6FGUs7T2eNd4mX60OXBl24ktWWLu3r3Z45bllaMt8yaSyNYOC8Em6eh6rsfvhBUp8UarUPf59g/s1600/throw.png" /></a></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div></div>sanathhttp://www.blogger.com/profile/13451785934486799607noreply@blogger.com0tag:blogger.com,1999:blog-7712715336336026804.post-60259766905150607952011-10-08T21:10:00.000+05:302011-10-08T21:30:39.609+05:30Implementing a publisher and subscriber with Action Delegate with and without parameters<div dir="ltr" style="text-align: left;" trbidi="on"><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Consolas; font-size: 13px;">I usually used to declare a delegate and event as separate declarations to build a publisher and subscriber mechanism. I found an alternate mechanism to accomplish the same</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">The concept that came to my help was Action Delegate.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> I followed the steps below<o:p></o:p></span></div><div class="MsoListParagraphCxSpFirst" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 33.75pt; margin-right: 0cm; margin-top: 0cm; mso-add-space: auto; mso-layout-grid-align: none; mso-list: l0 level1 lfo1; text-autospace: none; text-indent: -18.0pt;"><b><span style="font-family: Consolas; font-size: 9.5pt;">1.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span><span style="font-family: Consolas; font-size: 9.5pt;">Create 2 classes publisher and Subscriber<o:p></o:p></span></b></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 33.75pt; margin-right: 0cm; margin-top: 0cm; mso-add-space: auto; mso-layout-grid-align: none; mso-list: l0 level1 lfo1; text-autospace: none; text-indent: -18.0pt;"><b><span style="font-family: Consolas; font-size: 9.5pt;">2.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span><span style="font-family: Consolas; font-size: 9.5pt;">Declare the Action Delegate in the Publisher class<o:p></o:p></span></b></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 33.75pt; margin-right: 0cm; margin-top: 0cm; mso-add-space: auto; mso-layout-grid-align: none; mso-list: l0 level1 lfo1; text-autospace: none; text-indent: -18.0pt;"><b><span style="font-family: Consolas; font-size: 9.5pt;">3.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span><span style="font-family: Consolas; font-size: 9.5pt;">Hook the action Delegate to the event handler in Subscriber<o:p></o:p></span></b></div><div class="MsoListParagraphCxSpLast" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 33.75pt; margin-right: 0cm; margin-top: 0cm; mso-add-space: auto; mso-layout-grid-align: none; mso-list: l0 level1 lfo1; text-autospace: none; text-indent: -18.0pt;"><b><span style="font-family: Consolas; font-size: 9.5pt;">4.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span><span style="font-family: Consolas; font-size: 9.5pt;">Raise the event in any of the publisher functions<o:p></o:p></span></b></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">The example below demonstrates the use of Action delegate with no parameters and Parameterised Action delegates<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Publisher</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary></span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">///</span><span style="color: green;"> Action delegate without parameter</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary></span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">public</span> <span style="color: #2b91af;">Action</span> Completed;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary></span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">///</span><span style="color: green;"> Parameterised Action Delegate</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary></span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">public</span> <span style="color: #2b91af;">Action</span><<span style="color: blue;">int</span>, <span style="color: blue;">string</span>, <span style="color: blue;">string</span>> ParameterizedCompleted;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">public</span> <span style="color: blue;">void</span> PublishParameterisedAction()<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">string</span> str1 = <span style="color: #a31515;">"Hello"</span>;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">string</span> str2 = <span style="color: #a31515;">"World"</span>;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">StringBuilder</span> builder = <span style="color: blue;">new</span> <span style="color: #2b91af;">StringBuilder</span>();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> builder.Append(str1);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> builder.Append(str2);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">int</span> length = builder.Length;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//Raise an event with parameters</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> ParameterizedCompleted(length, str1, str2);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">public</span> <span style="color: blue;">void</span> PublishAction()<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">string</span> str1 = <span style="color: #a31515;">"Hello"</span>;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">string</span> str2 = <span style="color: #a31515;">"World"</span>;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">StringBuilder</span> builder = <span style="color: blue;">new</span> <span style="color: #2b91af;">StringBuilder</span>();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> builder.Append(str1);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> builder.Append(str2);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">int</span> length = builder.Length;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//Raise an event without parameters</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> Completed();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">Subscriber</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> Main(<span style="color: blue;">string</span>[] args)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> <span style="color: #2b91af;">Publisher</span> publisher = <span style="color: blue;">new</span> <span style="color: #2b91af;">Publisher</span>();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> publisher.Completed += <span style="color: blue;">new</span> <span style="color: #2b91af;">Action</span>(handleCompleted);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> publisher.ParameterizedCompleted += <span style="color: blue;">new</span> <span style="color: #2b91af;">Action</span><<span style="color: blue;">int</span>, <span style="color: blue;">string</span>, <span style="color: blue;">string</span>>(handleTemplateCompleted);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> publisher.PublishAction ();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> publisher.PublishParameterisedAction ();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> <span style="color: #2b91af;">Console</span>.ReadLine(); <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> handleTemplateCompleted(<span style="color: blue;">int</span> length,<span style="color: blue;">string</span> str1 ,<span style="color: blue;">string</span> str2)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> <span style="color: #2b91af;">Console</span>.Write(<span style="color: #a31515;">"Result from TemplateCompletedAction"</span> + length + str1 + str2); <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> handleCompleted()<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"notification recieved"</span>);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 8pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal"><br />
</div></div>sanathhttp://www.blogger.com/profile/13451785934486799607noreply@blogger.com0tag:blogger.com,1999:blog-7712715336336026804.post-44896835499174087392011-10-02T14:09:00.000+05:302011-10-02T14:13:52.800+05:30Use of MSMQ Binding provided by WCF.For Centralized Reliable logging Mechanism.<div dir="ltr" style="text-align: left;" trbidi="on"><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><b>Msmq Binding</b> is used to communicate to the Service using Microsoft Message Queuing. I have used this binding for transferring log messages. This way we can build a centralised logging system.</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;">For this I followed the steps mentioned below</span><br />
<br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <b> 1. Installed Microsoft Message Queuing</b></span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><b> 2. Create a message Queue with Transaction Enabled</b></span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><b> 3. Create a Service</b></span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <b>[ServiceContract]</b></span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> public interface ILogService</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> {</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> [<span class="Apple-style-span" style="color: purple;"><b>OperationContract</b></span>(IsOneWay =true )]</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> void Log(string Message);</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> } </span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <b>Note:</b><b>if we use NetMsmqBinding we have to mark all operations with in the service contract as OneWay.</b></span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><b><br />
</b></span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><b> 4.Define the implementation</b></span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;">public class MathService:ILogService</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> {</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> public void Log(string message)</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> {</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> File.AppendAllText(@"C:\logFolder\AppMessages.txt", message + Environment.NewLine);</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> </span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> }</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> }</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <b>5.Host the Service I have used Self Hosting.</b></span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <span class="Apple-style-span" style="color: #38761d;"> //Address of the message Queue in the machine -</span></span><br />
<span class="Apple-style-span" style="color: #38761d; font-family: Verdana, sans-serif;"> // use public with active directory installation</span><br />
<span class="Apple-style-span" style="color: #38761d; font-family: Verdana, sans-serif;"> // in case of Active directory integration . other machines can also access</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> // the Queue</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> Uri uri = new Uri(@"net.msmq:\\mycomputer\private\testQueue");</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> </span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> //Create Msmq binding with impersonate</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> // you may need need to do some thing more if you desire security</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> NetMsmqBinding messageQueueBinding = new NetMsmqBinding(NetMsmqSecurityMode .None);</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> ServiceHost host = new ServiceHost(typeof(ILogService), uri);</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> host.AddServiceEndpoint(typeof(ILogService), messageQueueBinding,uri .AbsoluteUri );</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> //host the WCF Service</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> host.Open();</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><b><br />
</b></span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><b>6.Design a Logging Client Application I have used Simple Console Application to demonstrate the same.</b></span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;">class Program</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> {</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> static void Main(string[] args)</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> {</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <b>Uri </b>uri = new <b>Uri </b>("net.msmq:\\mycomputer\private\testQueue");</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <b>EndpointAddress</b> address = new <b>EndpointAddress </b>(uri.AbsoluteUri );</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <b>NetMsmqBinding</b> binding =new <b>NetMsmqBinding</b> (NetMsmqSecurityMode.None );</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <b>ChannelFactory <ILogService></b> SerChannel = new <b>ChannelFactory<ILogService></b> (binding ,address );</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> </span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <b>ILogService </b>client = SerChannel.<b>CreateChannel </b>();</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> <b>client</b>.<b>Log </b>(" This is a log message");</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> Console.ReadLine ();</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> }</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> }</span><br />
<br />
</div>sanathhttp://www.blogger.com/profile/13451785934486799607noreply@blogger.com0tag:blogger.com,1999:blog-7712715336336026804.post-8898315738698046482011-09-24T13:36:00.000+05:302011-09-24T13:36:49.659+05:30Creating a network drive with Net use Command in Windows 7.<div dir="ltr" style="text-align: left;" trbidi="on"><br />
<div class="MsoNormal"><span class="Apple-style-span" style="font-size: 19px; line-height: 21px;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br />
</span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-size: 19px; line-height: 21px;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">In this article I would discuss the problem with respect to creating a network drive<span> </span>for a share in Windows 7 by using the <b>NET USE </b>Command . The problem was that when<span> </span>I<span> </span>tried to create a network drive in Windows Xp<span> </span>using net use . The command<span> </span>worked absolutely fine .It also showed me a network drive in the Windows Explorer.</span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-size: 19px; line-height: 21px;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br />
</span></span></div><div class="MsoNormal"><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">But with Windows 7 the command completed successfully but surprisingly the drive was not visible in Windows Explorer. Let me show<span> </span>you the steps which I followed <o:p></o:p></span></span></div><div class="MsoNormal"><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span> </span>I used an Administrator command prompt and<span> </span>typed the following command<o:p></o:p></span></span></div><div class="MsoNormal"><b><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span> </span>NET USE Z: \\mycomputer\sharetest<o:p></o:p></span></span></b></div><div class="MsoNormal"><b><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> </span></span></span></b></div><div class="MsoNormal"><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">The command<span> </span>completed<span> </span>successfully<span> </span>but there wasn’t<span> </span>a network drive visible in the Windows Explorer.<o:p></o:p></span></span></div><div class="MsoNormal"><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">I<span> </span>searched<span> </span>a number forums <span> </span>and tried several workarrounds and finally got a crude method to get out of it. Many of forums pointed to UAC settings of Windows 7.<o:p></o:p></span></span></div><div class="MsoNormal"><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br />
</span></span></div><div class="MsoNormal"><b><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Note:<span> </span>The solution provided below can have side effects on the working of Windows and also may lead to security<span> </span>implications .The author is not<span> </span>responsible. You would always do it at your own risk.<o:p></o:p></span></span></b></div><div class="MsoNormal"><b><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br />
</span></span></b></div><div class="MsoNormal"><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Following<span> </span>are the steps followed to solve the problem.</span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: 14.0pt; line-height: 115%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span><br />
</span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: 14.0pt; line-height: 115%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span>1.<span style="font: 7.0pt "Times New Roman";"> </span></span></span><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;">Goto<span> </span><b>Start </b>--></span><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"> run Type <b>msconfig </b>and press <b>enter </b>you get the tabbed screen shown below</span></span></div><!--[if !supportLists]--><br />
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br />
</span></span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAoB-9e_VL2TWOs4OiC3Vb6ucfkFBQ-KKCEsu4D4382aVPdGXweSd06A-OIv43hT0VoSW63QN7zLCK-XrUIti5SHHpiR4lwZva3IPDd1M_nsW4DdZv2DipAEdwtIPFDyTPEB1Dq4nlhw/s1600/msconfig.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><img border="0" height="211" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAoB-9e_VL2TWOs4OiC3Vb6ucfkFBQ-KKCEsu4D4382aVPdGXweSd06A-OIv43hT0VoSW63QN7zLCK-XrUIti5SHHpiR4lwZva3IPDd1M_nsW4DdZv2DipAEdwtIPFDyTPEB1Dq4nlhw/s320/msconfig.png" width="320" /></span></a></div><div class="MsoListParagraphCxSpLast"><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><!--[if gte vml 1]><v:shapetype
id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t"
path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <v:stroke joinstyle="miter"/> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0"/> <v:f eqn="sum @0 1 0"/> <v:f eqn="sum 0 0 @1"/> <v:f eqn="prod @2 1 2"/> <v:f eqn="prod @3 21600 pixelWidth"/> <v:f eqn="prod @3 21600 pixelHeight"/> <v:f eqn="sum @0 0 1"/> <v:f eqn="prod @6 1 2"/> <v:f eqn="prod @7 21600 pixelWidth"/> <v:f eqn="sum @8 21600 0"/> <v:f eqn="prod @7 21600 pixelHeight"/> <v:f eqn="sum @10 21600 0"/> </v:formulas> <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/> <o:lock v:ext="edit" aspectratio="t"/> </v:shapetype><v:shape id="Picture_x0020_2" o:spid="_x0000_i1027" type="#_x0000_t75"
alt="msconfig.png" style='width:430.5pt;height:285pt;visibility:visible;
mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\Sanath\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png"
o:title="msconfig"/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></span></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: 14.0pt; line-height: 115%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span>2.<span style="font: 7.0pt "Times New Roman";"> </span></span></span><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;">Goto <b>Tools </b>tab-> Select</span><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"> <b>Change UAC settings <span> </span></b>and then click on <b>Launch</b>. You would get the screen shown below</span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"><br />
</span></span></div><!--[if !supportLists]--><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQwokEyTsE96MEpUkoPst44H6PSuQLxKcLnKJTjmffiGuSNTr4cdoxx8TeW4LHCVjYyMZ0sc7uyFc0fuOUeJMCSmjUnItdn1KVmcMXnYrK3XVxxgmvA1bkNCT0cVEDzyLn4m1CqXxzKQ/s1600/UAC1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><img border="0" height="233" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQwokEyTsE96MEpUkoPst44H6PSuQLxKcLnKJTjmffiGuSNTr4cdoxx8TeW4LHCVjYyMZ0sc7uyFc0fuOUeJMCSmjUnItdn1KVmcMXnYrK3XVxxgmvA1bkNCT0cVEDzyLn4m1CqXxzKQ/s320/UAC1.jpg" width="320" /></span></a></div><div class="MsoListParagraphCxSpMiddle"><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><!--[if gte vml 1]><v:shape
id="Picture_x0020_3" o:spid="_x0000_i1026" type="#_x0000_t75" alt="UAC1.jpg"
style='width:366.75pt;height:267.75pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\Sanath\AppData\Local\Temp\msohtmlclip1\01\clip_image003.jpg"
o:title="UAC1"/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></span></span></div><div class="MsoListParagraphCxSpMiddle"><br />
</div><div class="MsoListParagraphCxSpMiddle"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: 14.0pt; line-height: 115%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span>3.<span style="font: 7.0pt "Times New Roman";"> </span></span></span><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;">Bring down the slider to <b>Never notify</b>.</span></span></div><div class="MsoListParagraphCxSpMiddle"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"><br />
</span></span></div><!--[if !supportLists]--><br />
<div class="separator" style="clear: both; text-align: center;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; margin-left: 1em; margin-right: 1em;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR_GiR44gt1eXwgx1jnsOu0dMQ7kuCLgPdzhnr_tpTtVGsbxNiwf6tOqZ5YLuilJ8HDQPM-4vr7cPIh-ME6tQwvVOJ3p6mRttqJIfm5z6Ez5RkKlv0PJKfD5xF_BSUp3yRrAxqOSYckQ/s1600/Uac2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="249" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR_GiR44gt1eXwgx1jnsOu0dMQ7kuCLgPdzhnr_tpTtVGsbxNiwf6tOqZ5YLuilJ8HDQPM-4vr7cPIh-ME6tQwvVOJ3p6mRttqJIfm5z6Ez5RkKlv0PJKfD5xF_BSUp3yRrAxqOSYckQ/s320/Uac2.jpg" width="320" /></a></span></div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: 14.0pt; line-height: 115%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span>4.<span style="font: 7.0pt "Times New Roman";"> </span></span></span><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;">Click on <b>Ok</b></span></span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: 14.0pt; line-height: 115%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span>5.<span style="font: 7.0pt "Times New Roman";"> </span></span></span><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"><b>Restart<span> </span></b>your Computer</span></span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: 14.0pt; line-height: 115%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span>6.<span style="font: 7.0pt "Times New Roman";"> </span></span></span><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;">Run the command<span> </span>prompt as Administrator<span> </span>and the command<b><span> </span></b></span></span></div><!--[if !supportLists]--><br />
<div class="MsoListParagraphCxSpMiddle"><b><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> NET USE Z: <span> </span><span style="text-decoration: none; text-underline: none;">\\mycomputer\sharetest</span>.</span></span></b></div><div class="MsoListParagraphCxSpMiddle"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: 14.0pt; line-height: 115%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-language: EN-IN; mso-no-proof: yes;"><span>7.<span style="font: 7.0pt "Times New Roman";"> </span></span></span><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;">Finally you can see the network drive visible in Windows Explorer</span></span></div><div class="MsoListParagraphCxSpMiddle"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"><br />
</span></span></div><!--[if !supportLists]--><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSrgrX5JyPkKsPfi4gug7dw3s_8ZxaB8j1Iq8l8DkXao_iNY9bmjSQw6qu-fB5oqVTdtmJCpMQDTSdulhOs9XgtibRJH6RsAmJSVwl5udKbBsXxzdtoNkazUmgC5GtE8YZL3reRNHksg/s1600/networkdrive1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><img border="0" height="256" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSrgrX5JyPkKsPfi4gug7dw3s_8ZxaB8j1Iq8l8DkXao_iNY9bmjSQw6qu-fB5oqVTdtmJCpMQDTSdulhOs9XgtibRJH6RsAmJSVwl5udKbBsXxzdtoNkazUmgC5GtE8YZL3reRNHksg/s400/networkdrive1.jpg" width="400" /></span></a></div><div class="MsoNormal"><span style="font-size: 14.0pt; line-height: 115%; mso-fareast-language: EN-IN; mso-no-proof: yes;"><!--[if gte vml 1]><v:shape id="Picture_x0020_1"
o:spid="_x0000_i1025" type="#_x0000_t75" style='width:381pt;height:223.5pt;
visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\Sanath\AppData\Local\Temp\msohtmlclip1\01\clip_image006.png"
o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]--></span><span style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div></div>sanathhttp://www.blogger.com/profile/13451785934486799607noreply@blogger.comBengaluru, Karnataka, India12.9715987 77.59456269999998312.7518902 77.342821199999989 13.191307199999999 77.846304199999977tag:blogger.com,1999:blog-7712715336336026804.post-31099205258150386262011-09-18T18:07:00.000+05:302011-09-18T18:10:04.797+05:30Handling Cross Thread operations in Windows Forms<div dir="ltr" style="text-align: left;" trbidi="on"><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;">There are many scenerios in day to day development activities and if you are working with thread you always encounter a problem for cross thread operation.In other words you are not able to update properties of a control from some other thread . Here I have tried to depict a simple scenario of updating a progressbar as a problem.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;">The Code written below show a problem of cross thread operation.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;">In the code below I have a created a separate thread and implemented a event mechanism to update the progress bar value from a thread that doesnot own the progressbar.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"><span style="color: blue;">using</span> System;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"><span style="color: blue;">using</span> System.Collections.Generic;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"><span style="color: blue;">using</span> System.ComponentModel;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"><span style="color: blue;">using</span> System.Drawing;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"><span style="color: blue;">using</span> System.Windows.Forms;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"><span style="color: blue;">using</span> System.Collections;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"><span style="color: blue;">using</span> System.Threading;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"><span style="color: blue;">namespace</span> CrossThreadOperation<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;">{<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: blue;">public</span> <span style="color: blue;">partial</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Form1</span> : <span style="color: #2b91af;">Form</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary></span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: grey;">///</span><span style="color: green;"> delegate for callback implementation</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary></span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param name="value"></span><span style="color: green;">data from the calling thread</span><span style="color: grey;"></param></span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: blue;">public</span> <span style="color: blue;">delegate</span> <span style="color: blue;">void</span> <span style="color: #2b91af;">CompletedDelegate</span>(<span style="color: blue;">int</span> value);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary></span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: grey;">///</span><span style="color: green;"> event used for notification by the thread</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary></span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: blue;">public</span> <span style="color: blue;">event</span> <span style="color: #2b91af;">CompletedDelegate</span> Completed;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: blue;">public</span> Form1()<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> InitializeComponent();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: green;">// hooking the callback function</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: blue;">this</span>.Completed += <span style="color: blue;">new</span> <span style="color: #2b91af;">CompletedDelegate</span>(Form1_Completed);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: blue;">void</span> Form1_Completed(<span style="color: blue;">int</span> value)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> progressBar1.Value = value ;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: blue;">private</span> <span style="color: blue;">void</span> button1_Click(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: #2b91af;">Thread</span> workerThread = <span style="color: blue;">new</span> <span style="color: #2b91af;">Thread</span>(DoSomeWork);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> workerThread.Start(); <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: blue;">private</span> <span style="color: blue;">void</span> DoSomeWork()<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: #2b91af;">ArrayList</span> arr = <span style="color: blue;">new</span> <span style="color: #2b91af;">ArrayList</span>();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: blue;">for</span> (<span style="color: blue;">int</span> index = 65; index < 95; index++)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> arr.Add(index);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> Completed(100); <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;">}<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;">When I try to run this code in Debug mode I get an exception as shown below<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhR5femEVjnMhJGt5gqe14vk-XzFS-7fYBX2JndYV6LljbFRBpUtT7chW3wp3GklwzJP00tgjVtCO1EbNR-j0aAvzneZ4oY_IuK2_CduUaQXbRfaCPLkVpZBmgsXFAGXW1tn6_wzZFYJA/s1600/crossthreadoperation.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhR5femEVjnMhJGt5gqe14vk-XzFS-7fYBX2JndYV6LljbFRBpUtT7chW3wp3GklwzJP00tgjVtCO1EbNR-j0aAvzneZ4oY_IuK2_CduUaQXbRfaCPLkVpZBmgsXFAGXW1tn6_wzZFYJA/s1600/crossthreadoperation.jpg" /></span></a></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="color: blue; font-family: Verdana, sans-serif; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"><span style="color: blue;"> </span>To overcome the problem we have to follow the steps mentioned below<o:p></o:p></span></div><div class="MsoListParagraphCxSpFirst" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 27.0pt; margin-right: 0cm; margin-top: 0cm; mso-add-space: auto; mso-layout-grid-align: none; mso-list: l0 level1 lfo1; text-autospace: none; text-indent: -18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;">1.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span>Create a delegate with the same signature as the function that updates a control<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 27.0pt; margin-right: 0cm; margin-top: 0cm; mso-add-space: auto; mso-layout-grid-align: none; mso-list: l0 level1 lfo1; text-autospace: none; text-indent: -18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;">2.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span>Create a function that updates the control.<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 27.0pt; margin-right: 0cm; margin-top: 0cm; mso-add-space: auto; mso-layout-grid-align: none; mso-list: l0 level1 lfo1; text-autospace: none; text-indent: -18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;">3.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span>Instantiated the delegate with the function which updates the control<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 27.0pt; margin-right: 0cm; margin-top: 0cm; mso-add-space: auto; mso-layout-grid-align: none; mso-list: l0 level1 lfo1; text-autospace: none; text-indent: -18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;">4.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span>Check whether the control is updated by the main thread or a separate thread by checking the Invoke Required property of the control. Here the separate thread requests the main thread to update the property of the control.<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 27.0pt; margin-right: 0cm; margin-top: 0cm; mso-add-space: auto; mso-layout-grid-align: none; mso-list: l0 level1 lfo1; text-autospace: none; text-indent: -18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;">5.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span>If the control is being updated from a separate thread then update the control from the delegate<o:p></o:p></span></div><div class="MsoListParagraphCxSpLast" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 27.0pt; margin-right: 0cm; margin-top: 0cm; mso-add-space: auto; mso-layout-grid-align: none; mso-list: l0 level1 lfo1; text-autospace: none; text-indent: -18.0pt;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;">6.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span>If the control is being updated directly from the main thread then directly update the property of the control.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary></span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: grey;">///</span><span style="color: green;"> delegate for setting the progressBar</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary></span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param name="value"></param></span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: blue;">public</span> <span style="color: blue;">delegate</span> <span style="color: blue;">void</span> <span style="color: #2b91af;">SetProgessBarDelegate</span>(<span style="color: blue;">int</span> value);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: blue;">void</span> Form1_Completed(<span style="color: blue;">int</span> value)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: green;">// progressBar1.Value = value ;</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> UpdateProgress(value ); <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: blue;">private</span> <span style="color: blue;">void</span> DoSomeWork()<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: #2b91af;">ArrayList</span> arr = <span style="color: blue;">new</span> <span style="color: #2b91af;">ArrayList</span>();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: blue;">for</span> (<span style="color: blue;">int</span> index = 65; index < 95; index++)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> arr.Add(index);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> Completed(100); <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary></span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: grey;">///</span><span style="color: green;"> function to avoid the exception due to Cross-Thread Operation</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary></span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param name="value"></param></span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: blue;">public</span> <span style="color: blue;">void</span> UpdateProgress(<span style="color: blue;">int</span> value)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: green;">//intantiate the delegate for thread safe action of </span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: green;">// of updating the progressbar</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: #2b91af;">SetProgessBarDelegate</span> setProgess = <span style="color: blue;">new</span> <span style="color: #2b91af;">SetProgessBarDelegate</span>(UpdateProgress);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: green;">//if the value is not updated from the main Thread.</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: blue;">if</span> (progressBar1.InvokeRequired)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: green;">//you can check the thread id using a message box here to verify it yourself</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: green;">//here the worker thread requests the main thread</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: green;">// to increment the progress bar</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> progressBar1.Invoke(setProgess , <span style="color: blue;">new</span> <span style="color: blue;">object</span>[] { value }); <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: blue;">else</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <span style="color: green;">//The main thread increments the progressbar </span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> progressBar1.Value =value ; <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"> <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNUStXf32j1aDDwl_YM_bi_IrjFcfJZdWwKnSCN0O4rM0DTDv8Mu4eaSF40jQa8aA4gbEmDmHubY-FXvuAVLgBsV73YIVMiufkUsOkhh_RfovP2gaaJS2UyBOhICPwVcFxmSAH7lwC8g/s1600/progressbarIncrement.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"><img border="0" height="265" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNUStXf32j1aDDwl_YM_bi_IrjFcfJZdWwKnSCN0O4rM0DTDv8Mu4eaSF40jQa8aA4gbEmDmHubY-FXvuAVLgBsV73YIVMiufkUsOkhh_RfovP2gaaJS2UyBOhICPwVcFxmSAH7lwC8g/s320/progressbarIncrement.jpg" width="320" /></span></a></div><div class="separator" style="clear: both; text-align: center;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"><br />
</span></div><div class="separator" style="clear: both; text-align: center;"></div><div class="MsoNormal"><span style="line-height: 115%;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;">Finally we observe that the progress bar increments smoothly</span><span class="Apple-style-span" style="font-size: x-small;"><o:p></o:p></span></span></div><br />
<div class="MsoNormal"><span style="font-size: 8pt; line-height: 115%;"></span><span style="font-size: 8pt; line-height: 115%;"><o:p></o:p></span></div></div>sanathhttp://www.blogger.com/profile/13451785934486799607noreply@blogger.comtag:blogger.com,1999:blog-7712715336336026804.post-23308041267171094202011-09-10T00:24:00.000+05:302011-09-10T01:02:01.083+05:30Deploying a JAVA application with Wix Tool Set<div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">As I was trying to build a installer for java application using Wix that could detect JRE Installation and install only if JRE was present. I stumbled across a number of forums and blogs.Finally I found a good solution. The key steps involved were </span><br />
<b><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> 1.Setting the working directory for a java application in the start menu shortcut properties</span></b><br />
<div class="MsoNormal"></div><b><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> 2. Check the registry for existence of specific JRE versions .</span></b><br />
<b><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br />
</span></b><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">The highlighted Grey text in the mark up shown below emphasises the same</span><br />
<div class="MsoNormal"><span lang="EN-US" style="color: blue; font-family: 'Courier New', Courier, monospace; font-size: 10pt;"><br />
</span></div><div class="MsoNormal"><span lang="EN-US" style="color: blue; font-family: 'Courier New', Courier, monospace; font-size: 10pt;"><br />
</span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"><?</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">xml</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">version</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">1.0</span>"<span style="color: blue;"> </span><span style="color: red;">encoding</span><span style="color: blue;">=</span>"<span style="color: blue;">UTF-8</span>"<span style="color: blue;">?><o:p></o:p></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"><</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Wix</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">xmlns</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">http://schemas.microsoft.com/wix/2006/wi</span>"<span style="color: blue;">><o:p></o:p></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Product</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">07f0003f-4290-4f4c-9442-c2d203f64b4f</span>"<span style="color: blue;"> </span><span style="color: red;">Name</span><span style="color: blue;">=</span>"<span style="color: blue;">TestJar</span> "<span style="color: blue;"> </span><span style="color: red;">Language</span><span style="color: blue;">=</span>"<span style="color: blue;">1033</span>"<span style="color: blue;"> </span><span style="color: red;">Version</span><span style="color: blue;">=</span>"<span style="color: blue;">1.0.0.0</span>"<span style="color: blue;"> </span><span style="color: red;">Manufacturer</span><span style="color: blue;">=</span>"<span style="color: blue;">abc</span>"<span style="color: blue;"> </span><span style="color: red;">UpgradeCode</span><span style="color: blue;">=</span>"<span style="color: blue;">00e83a73-37c7-4ec0-88f4-9612dcb05a0d</span>"<span style="color: blue;">><o:p></o:p></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Package</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">InstallerVersion</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">200</span>"<span style="color: blue;"> </span><span style="color: red;">Compressed</span><span style="color: blue;">=</span>"<span style="color: blue;">yes</span>"<span style="color: blue;"> /></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Media</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">1</span>"<span style="color: blue;"> </span><span style="color: red;">Cabinet</span><span style="color: blue;">=</span>"<span style="color: blue;">media1.cab</span>"<span style="color: blue;"> </span><span style="color: red;">EmbedCab</span><span style="color: blue;">=</span>"<span style="color: blue;">yes</span>"<span style="color: blue;"> /></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Directory</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">TARGETDIR</span>"<span style="color: blue;"> </span><span style="color: red;">Name</span><span style="color: blue;">=</span>"<span style="color: blue;">SourceDir</span>"<span style="color: blue;">><o:p></o:p></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Directory</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">ProgramFilesFolder</span>"<span style="color: blue;"> </span><span style="color: red;">Name</span><span style="color: blue;">=</span>"<span style="color: blue;">ProgramFilesFolder</span>"<span style="color: blue;">><o:p></o:p></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Directory</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">INSTALLLOCATION</span>"<span style="color: blue;"> </span><span style="color: red;">Name</span><span style="color: blue;">=</span>"<span style="color: blue;">TestJar</span>"<span style="color: blue;">></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Component</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">component1</span>"<span style="color: blue;"> </span><span style="color: red;">Guid</span><span style="color: blue;">=</span>"<span style="color: blue;">323CBA27-E825-4b15-B297-ABBEA9B686DA</span>"<span style="color: blue;">></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">File</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">'<span style="color: blue;">Test.jar</span>'<span style="color: blue;"> </span><span style="color: red;">Name</span><span style="color: blue;">=</span>'<span style="color: blue;">Test.jar</span>'<span style="color: blue;"> </span><span style="color: red;">DiskId</span><span style="color: blue;">=</span>'<span style="color: blue;">1</span>'</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Source</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">E:\JavaProj\Bin\Test.jar</span>"<span style="color: blue;"> </span><span style="color: red;">Vital</span><span style="color: blue;">=</span>'<span style="color: blue;">yes</span>'<span style="color: blue;">/></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">File</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">'<span style="color: blue;">Start.bat</span>'<span style="color: blue;"> </span><span style="color: red;">Name</span><span style="color: blue;">=</span>'<span style="color: blue;">Start.bat</span>'<span style="color: blue;"> </span><span style="color: red;">DiskId</span><span style="color: blue;">=</span>'<span style="color: blue;">1</span>'<o:p></o:p></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Source</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">E:\JavaProj\Bin\Start.bat</span>"<span style="color: blue;"> </span><span style="color: red;">Vital</span><span style="color: blue;">=</span>'<span style="color: blue;">yes</span>'<span style="color: blue;">/><o:p></o:p></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> </</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Component</span><span lang="EN-US" style="color: blue; font-size: 10pt;">><o:p></o:p></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"></</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Directory</span><span lang="EN-US" style="color: blue; font-size: 10pt;">></span> </span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Directory</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">StartMenuFolder</span>"<span style="color: blue;"> ><o:p></o:p></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Directory</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> =</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">ProgramMenuFolder</span>"<span style="color: blue;">><o:p></o:p></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Directory</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">TestJar</span>"<span style="color: blue;"> </span><span style="color: red;">Name</span><span style="color: blue;"> =</span>"<span style="color: blue;">TestJar</span>"<span style="color: blue;">><o:p></o:p></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Component</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> =</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">component3</span>"<span style="color: blue;"> </span><span style="color: red;">Guid</span><span style="color: blue;"> =</span>"<span style="color: blue;">92B0EDF4-664E-4707-AD32-066DD3993A57</span>"<span style="color: blue;"> ></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Registry</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Root</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">HKCU</span>"<span style="color: blue;"> </span><span style="color: red;">Key</span><span style="color: blue;"> =</span>"<span style="color: blue;">Software\[Manufacturer]\[ProductName]</span>"<span style="color: blue;"> </span><span style="color: red;">Value</span><span style="color: blue;"> =</span>"<span style="color: blue;">[INSTALLLOCATION]</span>"<span style="color: blue;"> </span><span style="color: red;">Type</span><span style="color: blue;"> =</span>"<span style="color: blue;">string</span>"<span style="color: blue;"> </span><span style="color: red;">KeyPath</span><span style="color: blue;"> =</span>"<span style="color: blue;">yes</span>"<span style="color: blue;"> /><o:p></o:p></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Shortcut</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">MyTestShortCutA</span>"<span style="color: blue;"> </span><span style="color: red;">Directory</span><span style="color: blue;"> =</span>"<span style="color: blue;">TestJar</span> "<span style="color: blue;"> </span><span style="color: red;">Name</span><span style="color: blue;">=</span>"<span style="color: blue;">testjar</span> "<span style="color: blue;"> </span><span style="color: red;">Icon</span><span style="color: blue;"> =</span>"<span style="color: blue;">icon1</span>"<span style="color: blue;"> </span><span style="color: red;">Show</span><span style="color: blue;">=</span>"<span style="color: blue;">normal</span>"<b><i><span style="color: blue;"> </span><span class="Apple-style-span" style="background-color: #eeeeee;"><span style="color: red;">WorkingDirectory</span><span style="color: blue;">=</span>"<span style="color: blue;">INSTALLLOCATION</span>"</span></i></b><span style="color: blue;"><b><i> </i></b> </span><span style="color: red;">Target</span><span style="color: blue;"> =</span>"<span style="color: blue;">[!start.bat]</span>"<span style="color: blue;">><o:p></o:p></span></span></span><br />
<span lang="EN-US" style="font-size: 10pt;"><span style="color: blue; font-family: 'Courier New', Courier, monospace;"><br />
</span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Icon</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">icon1</span>"<span style="color: blue;"> </span><span style="color: red;">SourceFile</span><span style="color: blue;">=</span>"<span style="color: blue;">E:\JavaProj\Bin\images\User1.ico</span>"<span style="color: blue;"> /><o:p></o:p></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> </</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Shortcut</span><span lang="EN-US" style="color: blue; font-size: 10pt;">><o:p></o:p></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> </</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Component</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> ><o:p></o:p></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> </</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Directory</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> ><o:p></o:p></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> </</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Directory</span><span lang="EN-US" style="color: blue; font-size: 10pt;">></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> </</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Directory</span><span lang="EN-US" style="color: blue; font-size: 10pt;">></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> </</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Directory</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> ><o:p></o:p></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> </</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Directory</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> ><o:p></o:p></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <span class="Apple-style-span" style="background-color: #cccccc;"> <b><i> </i></b><b><i><</i></b></span></span><b><i style="background-color: #cccccc;"><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Property</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">JAVA_CURRENT_VERSION</span>"<span style="color: blue;">><o:p></o:p></span></span></i></b></span></div><div class="MsoNormal"><b><i style="background-color: #cccccc;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">RegistrySearch</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">JRE_KEY</span>"<span style="color: blue;"> </span><span style="color: red;">Root</span><span style="color: blue;">=</span>"<span style="color: blue;">HKLM</span>"<span style="color: blue;"> </span><span style="color: red;">Key</span><span style="color: blue;">=</span>"<span style="color: blue;">SOFTWARE\JavaSoft\Java Runtime Environment</span>"<span style="color: blue;"> </span><span style="color: red;">Name</span><span style="color: blue;">=</span>"<span style="color: blue;">EVersion</span>"<span style="color: blue;"> </span><span style="color: red;">Type</span><span style="color: blue;">=</span>"<span style="color: blue;">raw</span>"<span style="color: blue;"> </span><span style="color: blue;"> /><o:p></o:p></span></span></span></i></b></div><div class="MsoNormal"><b><i style="background-color: #cccccc;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> </</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Property</span><span lang="EN-US" style="color: blue; font-size: 10pt;">><o:p></o:p></span></span></i></b></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><b><i style="background-color: #cccccc;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Condition</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Message</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">Java not installed Please install JRE 1.6 or later.</span>"<span style="color: blue;">><![CDATA[</span><span style="color: grey;">(Installed OR JAVA_CURRENT_VERSION) AND JAVA_CURRENT_VERSION >= "1.6"</span><span style="color: blue;">]]></</span><span style="color: #a31515;">Condition</span><span style="color: blue;">></span></span></i></b><span class="Apple-style-span" style="color: blue; font-size: 13px;"><b><i> </i></b> </span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Feature</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">'<span style="color: blue;">Complete</span>'<span style="color: blue;"> </span><span style="color: red;">Level</span><span style="color: blue;">=</span>'<span style="color: blue;">1</span>'<span style="color: blue;"> </span><span style="color: red;">ConfigurableDirectory</span><span style="color: blue;"> =</span>'<span style="color: blue;">INSTALLLOCATION</span>'<span style="color: blue;">></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">ComponentRef</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">'<span style="color: blue;">component1</span>'<span style="color: blue;"> /><o:p></o:p></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">ComponentRef</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">'<span style="color: blue;">component3</span>'<span style="color: blue;"> /><o:p></o:p></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> </</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Feature</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> ><o:p></o:p></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Property</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">WIXUI_INSTALLDIR</span>"<span style="color: blue;"> </span><span style="color: red;">Value</span><span style="color: blue;">=</span>"<span style="color: blue;">INSTALLLOCATION</span>"<span style="color: blue;"> ></</span><span style="color: #a31515;">Property</span><span style="color: blue;">></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">WixVariable</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">WixUIBannerBmp</span>"<span style="color: blue;"> </span><span style="color: red;">Value</span><span style="color: blue;">=</span>"<span style="color: blue;">E:\JavaProj\Bin\images\Test.bmp</span>"<span style="color: blue;"> /><o:p></o:p></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">WixVariable</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">WixUIDialogBmp</span>"<span style="color: blue;"> </span><span style="color: red;">Value</span><span style="color: blue;">=</span>"<span style="color: blue;">E:\JavaProj\Bin\images\blank.bmp</span>"<span style="color: blue;"> /><o:p></o:p></span></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> <</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">UIRef</span><span lang="EN-US" style="color: blue; font-size: 10pt;"> </span><span lang="EN-US" style="color: red; font-size: 10pt;">Id</span><span lang="EN-US" style="color: blue; font-size: 10pt;">=</span><span lang="EN-US" style="font-size: 10pt;">"<span style="color: blue;">WixUI_InstallDir</span>"<span style="color: blue;"> /></span></span> </span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"> </</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Product</span><span lang="EN-US" style="color: blue; font-size: 10pt;">><o:p></o:p></span></span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span lang="EN-US" style="color: blue; font-size: 10pt;"></</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Wix</span><span lang="EN-US" style="color: blue; font-size: 10pt;">><o:p></o:p></span></span><br />
<span lang="EN-US" style="color: blue; font-family: 'Courier New', Courier, monospace; font-size: 10pt;"><br />
</span><br />
<span lang="EN-US" style="font-family: 'Courier New', Courier, monospace;"><b>Note:</b><u>Registry search keys may change depending on different JRE Versions.</u></span></div><div class="MsoNormal"><br />
</div></div>sanathhttp://www.blogger.com/profile/13451785934486799607noreply@blogger.comtag:blogger.com,1999:blog-7712715336336026804.post-69401542403141107352011-08-31T20:52:00.000+05:302011-09-05T16:47:58.847+05:30Security Features in .net 4.0<div dir="ltr" style="text-align: left;" trbidi="on"><br />
<div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="font-family: Verdana; font-size: 10pt;">The .net Framework 4 brings in new meaning to security .Its very handy .Here the Framework classify the code into 3 Types<o:p></o:p></span></div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 10pt;">SecurityCritical</span></b><span style="font-family: Verdana; font-size: 10pt;">: This code can only be accessed by fully trusted callers<o:p></o:p></span></div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 10pt;">SecuritySafeCritical</span></b><span style="font-family: Verdana; font-size: 10pt;">: this code can access by partially trusted Callers<o:p></o:p></span></div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 10pt;">SecurityTransparent</span></b><span style="font-family: Verdana; font-size: 10pt;">: This code is not trusted or the code with lowest privilege<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="font-family: Verdana; font-size: 10pt;">Each of these could be demonstrated with an example <o:p></o:p></span></div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 10pt;">Scenario 1: </span></b><span style="font-family: Verdana; font-size: 10pt;">Security Transparent Code Accessing Security Critical Code<b style="mso-bidi-font-weight: normal;"><o:p></o:p></b></span></div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 10pt;">Scenario 2: </span></b><span style="font-family: Verdana; font-size: 10pt;">Security Critical Code Accessing Security Critical Code<b style="mso-bidi-font-weight: normal;"><o:p></o:p></b></span></div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 10pt;">Scenario 3: </span></b><span style="font-family: Verdana; font-size: 10pt;">How to allow some methods to be accessible by Security Transparent Code<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 10pt;">Scenario 1: Security Transparent Code Accessing Security Critical Code<o:p></o:p></span></b></div><div class="MsoNormal"><span style="font-family: Verdana; font-size: 10pt;">Caller Code in one Assembly<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Security;<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> CalleeLibrary ;<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">[ <span style="color: blue;">assembly</span>:<span style="color: #2b91af;">SecurityTransparent</span> ]<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">namespace</span><span style="font-family: Consolas; font-size: 9.5pt;"> Caller<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">Program</span><o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> <st1:place w:st="on">Main</st1:place>(<span style="color: blue;">string</span>[] args)<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Callee</span> callee = <span style="color: blue;">new</span> <span style="color: #2b91af;">Callee</span> (<span style="color: #a31515;">"Tom"</span>);<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> callee.GetDetails() ; <o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 10pt;">Callee Code in Second Assembly</span><o:p></o:p></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System;<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Security;<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">[<span style="color: blue;">assembly</span>: <span style="color: #2b91af;">SecurityCritical</span>] <o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">namespace</span><span style="font-family: Consolas; font-size: 9.5pt;"> CalleeLibrary<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Callee</span><o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">private</span> <span style="color: blue;">string</span> Name;<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">public</span> Callee(<span style="color: blue;">string</span> name)<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> Name = name;<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">public</span> <span style="color: blue;">void</span> GetDetails()<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"Name passed From Caller:"</span> + Name); <o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="font-family: Verdana; font-size: 10pt;">The Reason here is that a SecurityTransparent Assembly cannot Access the Security CriticalCode<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 10pt;">Scenario 2: Security Critical Code Accessing Security Critical Code<o:p></o:p></span></b></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="font-family: Verdana; font-size: 10pt;">Mark the Calling Assembly with SecurityCritical to set it right<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Callee Library code<o:p></o:p></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Security;<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> CalleeLibrary ;<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">[ <span style="color: blue;">assembly</span>:<span style="color: #2b91af;">SecurityCritical</span> ]<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">namespace</span><span style="font-family: Consolas; font-size: 9.5pt;"> Caller<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">Program</span><o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> <st1:place w:st="on">Main</st1:place>(<span style="color: blue;">string</span>[] args)<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Callee</span> callee = <span style="color: blue;">new</span> <span style="color: #2b91af;">Callee</span> (<span style="color: #a31515;">"Tom"</span>);<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> callee.GetDetails() ; <o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal"><span style="font-family: Verdana; font-size: 10pt;">As result of which you code starts running.<o:p></o:p></span></div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 10pt;">Scenerio3: How to Allow some methods to be accessible by Security Transparent Code<o:p></o:p></span></b></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Security;<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> CalleeLibrary ;<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">[ <span style="color: blue;">assembly</span>:<span style="color: #2b91af;">SecurityTransparent</span> ]<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">namespace</span><span style="font-family: Consolas; font-size: 9.5pt;"> Caller<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">Program</span><o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> <st1:place w:st="on">Main</st1:place>(<span style="color: blue;">string</span>[] args)<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Callee</span> callee = <span style="color: blue;">new</span> <span style="color: #2b91af;">Callee</span> (<span style="color: #a31515;">"Tom"</span>);<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> callee.GetDetails() ; <o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Verdana; font-size: 10pt;">Mark the Callee Assembly with</span><span style="font-family: Verdana; font-size: 10pt;"> <b style="mso-bidi-font-weight: normal;">AllowPartiallyTrustedCallers</b> and mark the code which are to be accessed by SecurityTransparent code with <b style="mso-bidi-font-weight: normal;">SecuritySafeCritical </b>Attribute<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Verdana; font-size: 10pt;">Following table represents the observations thatvwhere the observation which were made When Assembly <b style="mso-bidi-font-weight: normal;">A1 and A2</b> where applied the following attributes A1 refers to the caller Assembly and A2 refers to the <b style="mso-bidi-font-weight: normal;">Callee</b> Assembly<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><table border="0" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; margin-left: -27.0pt; mso-padding-alt: 0in 0in 0in 0in; mso-table-layout-alt: fixed;"><tbody>
<tr style="height: 12.65pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;"> <td style="border: solid windowtext 1.0pt; height: 12.65pt; padding: 0in 5.4pt 0in 5.4pt; width: 131.4pt;" valign="top" width="175"><div align="center" class="MsoNormal" style="text-align: center;"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 9pt;">A1 -rows/A2 -columns<o:p></o:p></span></b></div></td> <td style="border-left: none; border: solid windowtext 1.0pt; height: 12.65pt; padding: 0in 5.4pt 0in 5.4pt; width: 90.7pt;" valign="top" width="121"><div align="center" class="MsoNormal" style="text-align: center;"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 9pt;">SecurityCritical<o:p></o:p></span></b></div></td> <td style="border-left: none; border: solid windowtext 1.0pt; height: 12.65pt; padding: 0in 5.4pt 0in 5.4pt; width: 125.5pt;" valign="top" width="167"><div align="center" class="MsoNormal" style="text-align: center;"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 9pt;">SecurityTransparent<o:p></o:p></span></b></div></td> <td style="border-left: none; border: solid windowtext 1.0pt; height: 12.65pt; padding: 0in 5.4pt 0in 5.4pt; width: 121.25pt;" valign="top" width="162"><div align="center" class="MsoNormal" style="text-align: center;"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 9pt;">SecuritySafeCritical<o:p></o:p></span></b></div></td> </tr>
<tr style="height: 12.65pt; mso-yfti-irow: 1;"> <td style="border-top: none; border: solid windowtext 1.0pt; height: 12.65pt; padding: 0in 5.4pt 0in 5.4pt; width: 131.4pt;" valign="top" width="175"><div align="center" class="MsoNormal" style="text-align: center;"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 9pt;">SecurityCritical<o:p></o:p></span></b></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 12.65pt; padding: 0in 5.4pt 0in 5.4pt; width: 90.7pt;" valign="top" width="121"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 9pt;">yes<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 12.65pt; padding: 0in 5.4pt 0in 5.4pt; width: 125.5pt;" valign="top" width="167"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 9pt;">yes<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 12.65pt; padding: 0in 5.4pt 0in 5.4pt; width: 121.25pt;" valign="top" width="162"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 9pt;">yes<o:p></o:p></span></div></td> </tr>
<tr style="height: 13.85pt; mso-yfti-irow: 2;"> <td style="border-top: none; border: solid windowtext 1.0pt; height: 13.85pt; padding: 0in 5.4pt 0in 5.4pt; width: 131.4pt;" valign="top" width="175"><div align="center" class="MsoNormal" style="text-align: center;"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 9pt;">SecurityTransparent<o:p></o:p></span></b></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.85pt; padding: 0in 5.4pt 0in 5.4pt; width: 90.7pt;" valign="top" width="121"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 9pt;">no<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.85pt; padding: 0in 5.4pt 0in 5.4pt; width: 125.5pt;" valign="top" width="167"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 9pt;">yes<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.85pt; padding: 0in 5.4pt 0in 5.4pt; width: 121.25pt;" valign="top" width="162"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 9pt;">no<o:p></o:p></span></div></td> </tr>
<tr style="height: 13.85pt; mso-yfti-irow: 3; mso-yfti-lastrow: yes;"> <td style="border-top: none; border: solid windowtext 1.0pt; height: 13.85pt; padding: 0in 5.4pt 0in 5.4pt; width: 131.4pt;" valign="top" width="175"><div align="center" class="MsoNormal" style="text-align: center;"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 9pt;">SecuritySafeCritical<o:p></o:p></span></b></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.85pt; padding: 0in 5.4pt 0in 5.4pt; width: 90.7pt;" valign="top" width="121"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 9pt;">yes<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.85pt; padding: 0in 5.4pt 0in 5.4pt; width: 125.5pt;" valign="top" width="167"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 9pt;">yes<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.85pt; padding: 0in 5.4pt 0in 5.4pt; width: 121.25pt;" valign="top" width="162"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 9pt;">yes<o:p></o:p></span></div></td> </tr>
</tbody></table><div align="center" class="MsoNormal" style="text-align: center;"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="font-family: Verdana; font-size: 10pt;">The table below gives an Idea about the scope of the security Attributes with respect to the language constructs<o:p></o:p></span></div><div align="center" class="MsoNormal" style="text-align: center;"><br />
</div><table border="0" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; margin-left: -34.15pt; mso-padding-alt: 0in 0in 0in 0in; mso-table-layout-alt: fixed;"><tbody>
<tr style="height: 17.7pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;"> <td style="border: solid windowtext 1.0pt; height: 17.7pt; padding: 0in 5.4pt 0in 5.4pt; width: 147.55pt;" valign="top" width="197"><div align="center" class="MsoNormal" style="text-align: center;"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 8pt;">Attribute<o:p></o:p></span></b></div></td> <td style="border-left: none; border: solid windowtext 1.0pt; height: 17.7pt; padding: 0in 5.4pt 0in 5.4pt; width: 91.4pt;" valign="top" width="122"><div align="center" class="MsoNormal" style="text-align: center;"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 8pt;">Namespace/Assembly<o:p></o:p></span></b></div></td> <td style="border-left: none; border: solid windowtext 1.0pt; height: 17.7pt; padding: 0in 5.4pt 0in 5.4pt; width: 38.45pt;" valign="top" width="51"><div align="center" class="MsoNormal" style="text-align: center;"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 8pt;">Class<o:p></o:p></span></b></div></td> <td style="border-left: none; border: solid windowtext 1.0pt; height: 17.7pt; padding: 0in 5.4pt 0in 5.4pt; width: 115.25pt;" valign="top" width="154"><div align="center" class="MsoNormal" style="text-align: center;"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 8pt;">Method/Constructor<o:p></o:p></span></b></div></td> <td style="border-left: none; border: solid windowtext 1.0pt; height: 17.7pt; padding: 0in 5.4pt 0in 5.4pt; width: 55.6pt;" valign="top" width="74"><div align="center" class="MsoNormal" style="text-align: center;"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 8pt;">Property<o:p></o:p></span></b></div></td> <td style="border-left: none; border: solid windowtext 1.0pt; height: 17.7pt; padding: 0in 5.4pt 0in 5.4pt; width: 53.4pt;" valign="top" width="71"><div align="center" class="MsoNormal" style="text-align: center;"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 8pt;">Member<o:p></o:p></span></b></div></td> </tr>
<tr style="height: 17.7pt; mso-yfti-irow: 1;"> <td style="border-top: none; border: solid windowtext 1.0pt; height: 17.7pt; padding: 0in 5.4pt 0in 5.4pt; width: 147.55pt;" valign="top" width="197"><div align="center" class="MsoNormal" style="text-align: center;"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 8pt;">SecurityCritical<o:p></o:p></span></b></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 17.7pt; padding: 0in 5.4pt 0in 5.4pt; width: 91.4pt;" valign="top" width="122"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">yes<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 17.7pt; padding: 0in 5.4pt 0in 5.4pt; width: 38.45pt;" valign="top" width="51"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">yes<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 17.7pt; padding: 0in 5.4pt 0in 5.4pt; width: 115.25pt;" valign="top" width="154"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">yes<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 17.7pt; padding: 0in 5.4pt 0in 5.4pt; width: 55.6pt;" valign="top" width="74"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">No<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 17.7pt; padding: 0in 5.4pt 0in 5.4pt; width: 53.4pt;" valign="top" width="71"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">yes<o:p></o:p></span></div></td> </tr>
<tr style="height: 19.4pt; mso-yfti-irow: 2;"> <td style="border-top: none; border: solid windowtext 1.0pt; height: 19.4pt; padding: 0in 5.4pt 0in 5.4pt; width: 147.55pt;" valign="top" width="197"><div align="center" class="MsoNormal" style="text-align: center;"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 8pt;">Security Transparent<o:p></o:p></span></b></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 19.4pt; padding: 0in 5.4pt 0in 5.4pt; width: 91.4pt;" valign="top" width="122"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">yes<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 19.4pt; padding: 0in 5.4pt 0in 5.4pt; width: 38.45pt;" valign="top" width="51"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">yes<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 19.4pt; padding: 0in 5.4pt 0in 5.4pt; width: 115.25pt;" valign="top" width="154"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">no<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 19.4pt; padding: 0in 5.4pt 0in 5.4pt; width: 55.6pt;" valign="top" width="74"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">No<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 19.4pt; padding: 0in 5.4pt 0in 5.4pt; width: 53.4pt;" valign="top" width="71"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">no<o:p></o:p></span></div></td> </tr>
<tr style="height: 19.4pt; mso-yfti-irow: 3;"> <td style="border-bottom: none; border-left: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; border-top: none; height: 19.4pt; padding: 0in 5.4pt 0in 5.4pt; width: 147.55pt;" valign="top" width="197"><div align="center" class="MsoNormal" style="text-align: center;"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 8pt;">SecuritySafeCritical<o:p></o:p></span></b></div></td> <td style="border-right: solid windowtext 1.0pt; border: none; height: 19.4pt; padding: 0in 5.4pt 0in 5.4pt; width: 91.4pt;" valign="top" width="122"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">no<o:p></o:p></span></div></td> <td style="border-right: solid windowtext 1.0pt; border: none; height: 19.4pt; padding: 0in 5.4pt 0in 5.4pt; width: 38.45pt;" valign="top" width="51"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">yes<o:p></o:p></span></div></td> <td style="border-right: solid windowtext 1.0pt; border: none; height: 19.4pt; padding: 0in 5.4pt 0in 5.4pt; width: 115.25pt;" valign="top" width="154"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">yes<o:p></o:p></span></div></td> <td style="border-right: solid windowtext 1.0pt; border: none; height: 19.4pt; padding: 0in 5.4pt 0in 5.4pt; width: 55.6pt;" valign="top" width="74"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">no<o:p></o:p></span></div></td> <td style="border-right: solid windowtext 1.0pt; border: none; height: 19.4pt; padding: 0in 5.4pt 0in 5.4pt; width: 53.4pt;" valign="top" width="71"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">Yes<o:p></o:p></span></div></td> </tr>
<tr style="height: 19.4pt; mso-yfti-irow: 4; mso-yfti-lastrow: yes;"> <td style="border-top: none; border: solid windowtext 1.0pt; height: 19.4pt; padding: 0in 5.4pt 0in 5.4pt; width: 147.55pt;" valign="top" width="197"><div align="center" class="MsoNormal" style="text-align: center;"><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 8pt;">AllowPartiallyTrustedCallers</span></b><b style="mso-bidi-font-weight: normal;"><span style="font-family: Verdana; font-size: 8pt;"><o:p></o:p></span></b></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 19.4pt; padding: 0in 5.4pt 0in 5.4pt; width: 91.4pt;" valign="top" width="122"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">yes<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 19.4pt; padding: 0in 5.4pt 0in 5.4pt; width: 38.45pt;" valign="top" width="51"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">no<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 19.4pt; padding: 0in 5.4pt 0in 5.4pt; width: 115.25pt;" valign="top" width="154"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">no<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 19.4pt; padding: 0in 5.4pt 0in 5.4pt; width: 55.6pt;" valign="top" width="74"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">no<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 19.4pt; padding: 0in 5.4pt 0in 5.4pt; width: 53.4pt;" valign="top" width="71"><div align="center" class="MsoNormal" style="text-align: center;"><span style="font-family: Verdana; font-size: 8pt;">no<o:p></o:p></span></div></td> </tr>
</tbody></table><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div></div>sanathhttp://www.blogger.com/profile/13451785934486799607noreply@blogger.com0