tag:blogger.com,1999:blog-61660613146838984842024-03-14T14:12:52.229+05:30Software DevelopmentUsing blog posts I will try to share my experience in developing IT solutions. Problems I faced, solutions found, new learnings, OOPS, SOLID Design Principles, Design Patterns,.NET, C#Unknownnoreply@blogger.comBlogger153125tag:blogger.com,1999:blog-6166061314683898484.post-13899892826463618312021-03-09T16:51:00.001+05:302021-03-09T16:51:06.811+05:30NoSQL Database TypesA good artcile on NoSQL Database Types
https://dzone.com/articles/nosql-database-types-1Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-22747253188744878572020-09-19T15:58:00.003+05:302020-09-19T15:58:52.138+05:30How Can Engineers be Future Ready?How Can Engineers be Future Ready? by Tilak Doddapaneni
<a href="https://thehowchannel.publicissapient.com/series/brewing-live/episodes?v=6174869585001">https://thehowchannel.publicissapient.com/series/brewing-live/episodes?v=6174869585001</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-56167958751940425322018-11-17T11:09:00.000+05:302018-11-24T09:53:14.118+05:30How to find App Pool Process ID<p>If you have hosted web applications in IIS (Internet Information Service) web server, then at times you want to know the process ID of the application pool your web app is using.</p>
<p>If you go to TASK Manager and see the process list, it will shows all the app pool’s W3WP processes. So it will be difficult to identify the underlying process ID of app pool which your web application is using.</p>
<p>If you are facing this trouble, don’t worry. Head straight into IIS Manager.</p>
<p>Open IIS Manager (inetmgr), select the server node in the right hand navigation page.</p>
<p>Select the features list in the bottom tab. In the features list click on the Worker Process.</p>
<p>In the Worker Processes list, one of the column is Process ID of the process. Locate your app pool in the list and you will come to know the process ID.</p>
<div tyle="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNAGMjYTcu1tjTqlWDgWdE13G6Eukufc8M1B246KVD0HlK8G320BZ1G0qynrZBE-2GXDp1Rz0w0PzHA9rWzUdMaAvrcVwpg-mCGKtsKmJToA2wH4DWOTiMWPBGXdLxiDVyc7g0CiB04ug/s1600/ProcessID+for+woker+process+in+IIS.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNAGMjYTcu1tjTqlWDgWdE13G6Eukufc8M1B246KVD0HlK8G320BZ1G0qynrZBE-2GXDp1Rz0w0PzHA9rWzUdMaAvrcVwpg-mCGKtsKmJToA2wH4DWOTiMWPBGXdLxiDVyc7g0CiB04ug/s320/ProcessID+for+woker+process+in+IIS.PNG" width="320" height="122" data-original-width="1188" data-original-height="453" /></a></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-56414616752567521772018-10-14T21:09:00.000+05:302018-10-16T21:10:34.003+05:30 what is HTTP HEAD request?<p>Off late REST services have become very popular. People pays lot of attention to HTTP verbs while desiging the REST services. There are different HTTP verbs meant for different kinds of HTTP requests, namely GET, POST, PUT, DELETE, PATCH, HEAD, etc.</p>
<p>In this post let’s discuss perticulalry on HTTP HEAD requests and when to use them.</p>
<h4>What is HTTP HEAD requests?</h4>
<p>With HTTP Head requests (as the name already implying) server will return only the HTTP Headers but not the body.</p>
<h4>When to use HTTP HEAD then?</h4>
<p>Responses for the Http Head request from the servers will be light weight compared to HTTP GET requests, because they don’t contain any body. So you can use HTTP HEAD request / response together to determine whether a heavy payload entity is modified at the server end or not.</p>
<p>One example the server can just return when was a requested resource last modified with the HTTP HEAD response, then client will verify to see if the version of the entity it possess alrerady is latest or not.<p>
<p>If the entity is latest, then client can continue to use the entity it has in its store, else it can issue a HTTP GET request to fetch the heavy payload entity from the server.</p>
<p>In this way using the HTTP HEAD request and responses between client and servers we can design more performant systems by avoiding exchange of heavy payload object when not really required.</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-57153389570254992292018-10-13T20:42:00.000+05:302018-10-16T21:25:26.216+05:30difference between FirstOrDefault () and SingleOrDefault()<p>Recently one of my junior colleague working in .NET asked me about what is the difference between the FirstOrDefault and SingleOrDefault() methods.</p>
<p>Both FirstOrDefault() and SingleOrDefault() are the extension methods on the System.Collections.Generic.IEnumerable<TSource> defined in System.Linq namespace.</p>
<p>The difference is pretty simple</p>
<h4>Enumerable.SingleOrDefault()</h4>
<p>SingleOrDefault() method returns the element which matches the condition. If no element matches the condition, then the method returns the default of value of the source type (default(TSource))</p>
<p>If more than one elements match the condition specified, it throw the Exception (InvalidOperationException)
Enumerable.FirstOrDefault()</p>
<h4>Enumerable.FirstOrDefault()</h4>
<p>The way FirstOrDefault() method works is same as the Enumerable.SingleOrDefault() except that it doesn’t throw an exception if more than one element matches the condition. It just returns the first matching record.</p>
<h4>How to choose between FirstOrDefault () and SingleOrDefault() methods?</h4>
<p>If you know for sure that, there should only be one record present in the collection matching specified condition and presence of more than one record in the collection matching the condition indicates an error, then use the SingleOrDefault() method. So in error conditions, you will rightly get an exception.<p>
<p>If there could be multiple matching records for the specified condition in a collection and just you want the first one, then go ahead and use FirstOrDefault() method.</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-50124499667564220792018-09-23T17:11:00.003+05:302018-09-23T17:24:05.052+05:30How IT deals are negotiated in India <p>Recently I read a book "Bandhan: The Making of a Bank" by Tamal Bandyopadhyay who is known for his works writings on the banking and finance sector in India.</p>
<p>In this book author writes about how Bandhan, now a universal bank become reality after becoming successful a Microfinance company. In the book, the author has written one whole chapter on how the bank negotiated with IT services company in building the IT backbone for the upcoming bank. The book as a whole was really an interesting read especially the chapter # 8, "Building the Backbone".</p>
<p>Author in the chapter has described in detail on how the bank came up with the bidding process, how many companies participated, how companies forged alliance while bidding to come up with competitive bidding and what went on selecting the vendor for the building the IT backbone for one of the latest universal banks in India.</p>
<p>Buy on a copy of "<a href="https://www.amazon.in/Bandhan-Making-Bank-Tamal-Bandyopadhyay/dp/8184004982">Bandhan: The Making of a Bank</a>" from Amazon and give a read. I'm really sure you like the "chapter #8, Building The IT Backbone"
as an IT Professional.</p>
<h4>Book cover letter</h4>
<div style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOUvPlVOxIxSFqlkX19Yptlk4CkmTyIclErjvgYVo3h2oa06pBBey7GVr3_exRvkQkY_mgU6dSYgL34rGuBFSOOfunhxiGIF9gAAGC8W8irX5enkrbld1x7C6R0VM8yo4xg7QxgIl3zbg/s1600/Bandhan+Cover+Letter.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOUvPlVOxIxSFqlkX19Yptlk4CkmTyIclErjvgYVo3h2oa06pBBey7GVr3_exRvkQkY_mgU6dSYgL34rGuBFSOOfunhxiGIF9gAAGC8W8irX5enkrbld1x7C6R0VM8yo4xg7QxgIl3zbg/s400/Bandhan+Cover+Letter.PNG" width="257" height="400" data-original-width="312" data-original-height="486" /></a></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-67212230737619079752018-09-23T16:10:00.000+05:302018-09-23T16:21:29.638+05:30difference between encapsulation and abstraction<p>Abstraction and Encapsulation are the 2 of the 4 building blocks in OOPS. In the previous posts, I have already blogged in a separate post on <a href="http://rangahc.blogspot.com/2013/02/what-is-abstraction-in-oops.html">Abstraction </a>and <a href="http://rangahc.blogspot.com/2018/06/encapsulation-in-oops.html">Encapsulation </a>. In this blog post let's try to understand what is the difference between encapsulation and abstraction.</p>
<p>Encapsulation is all about building the functionality of an entity inside a class hiding the complexity so that users of such classes can use them <b>without worrying about how the stuff has been implemented.</b></p>
<p>Where as abstraction is all about <b>what</b> a class provides to the developers. With abstraction developers only look at <b>what a class provides </b>looking at the interfaces/abstract classes it implements.</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-36558061874901478342018-06-30T14:52:00.000+05:302018-09-22T15:40:52.902+05:30Encapsulation in OOPS<p>Encapsulation is one of the 4 building blocks of OOPS. I have already written about other 3 OOPS concepts namely <a href="http://rangahc.blogspot.com/2013/05/inheritance-in-oops.html">Inheritance</a>, <a href="http://rangahc.blogspot.com/2014/06/difference-between-compile-time-and-runtime-polymorphism.html">Polymorphism </a>and <a href="http://rangahc.blogspot.com/2013/02/what-is-abstraction-in-oops.html">Abstraction</a>. In this blog post, we will discuss Encapsulation is OOPS.</p>
<h4>What is dictionary meaning of Encapsulation</h4>
<p>Encapsulation means "Enclose something in or as if in a capsule" (as per "oxforddictionaries.com" dictionary).</p>
<h4>What is Encapsulation in OOPS</h4>
<p>Having understood the meaning of Encapsulation, in general, let's understand what does it mean in the Object-Oriented programming world.</p>
<p>Image Courtesy: shutterstock</p>
<div style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3Nab1pokMWqs-jQW-qc7ZLPQ6R9_-NEOYxnRyTEZCa07RGMMqz3pH0b0dI-ieTeaSE3ns48HiPp-GD7v2GFgTt34RtT6mHyUNmDTHdXuxF2Ud02iYfKay6qtjpR-OZTGgGuGV7HllxVg/s1600/Capsule.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3Nab1pokMWqs-jQW-qc7ZLPQ6R9_-NEOYxnRyTEZCa07RGMMqz3pH0b0dI-ieTeaSE3ns48HiPp-GD7v2GFgTt34RtT6mHyUNmDTHdXuxF2Ud02iYfKay6qtjpR-OZTGgGuGV7HllxVg/s320/Capsule.PNG" width="320" height="215" data-original-width="395" data-original-height="266" /></a></div>
</br>
<ul>
<li>Wikipedia says Encapsulation in OOPS is data hiding of the data members of the class like properties, fields etc. To implement this definition of data hiding you will make use of <a href="http://rangahc.blogspot.com/2012/12/access-specifier.html">access specifiers</a>.</li>
<li>As per the other definition, Encapsulation is all about bundling the data with the methods which operate on that data.
<p>In other words Encapsulation is about putting together methods/functions and data members all in one place called class so that users of those classes can easily make use of it.</p>
</li>
</ul>
<h4>Why we need Encapsulation</h4>
<p>Having understood what is Encapsulation, now let's turn our attention into what is the advantage of it and what Encapsulation brings to the table in the object-oriented programming world.</p>
<p>With Encapsulation users of the classes need not worry about what how class provides its functionality. Similar to a real-world capsule. As a patient you really no need to know what is inside a capsule, that is something your physician worries about it and prescribe it to you.</p>
<p>As a user of the SmtpClient class in the .NET framework which sends a MailMessage to a recipient address, you don't need to know about how does it actually sends an email. The email sending logic is encapsulated inside the SmtpClient class (by an author of the class i.e., Microsoft)Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-35858576157652028982018-06-03T14:38:00.000+05:302018-06-13T15:46:04.211+05:30increasing salary with number of years of experience<p>Over the last 3 months at least 5 colleagues have asked me questions related to how to keep their salary growing as experience under their belt keep growing. Let's look some of the questions I encountered over lunch breaks, commuting in cabs between home and office and other networking events:</p>
<ul>
<li>My experience is growing but my salary is not growing, any suggestions from your end? </li>
<li>How is the job market now I have 8 years of experience in IT? </li>
<li>Will I get a job when I try to change the company? </li>
<li><p>I'm a lead now with 10 years of experience under my belt, leading team of 6 junior people and my Manager has 40 people under him.</p>
<p>With this prevailing ratio in the software industry, as years rolls and I become more experienced will I get position for my experience?</p>
</li>
</ul>
<p>May be after reading this blog post so far, it might have also ringed similar questions in your mind too. Keep reading further, I will try to answer these questions over next few paragraphs. </p>
<p>I really understand the concerns people have behind these questions because I too had such questions in my mind 2 years back. </p>
<p>Now let me try to my answer to these questions. </p>
<h4>Experience v/s Exposure</h4>
<p>As years goes by, yes you will definitely become more experienced by a mere number of experience. But you need to ask yourself can I do more complex tasks now comparing to 2 to 3 years back? Please understand you need to gain expertise in whatever you do as become more experience any field. </p>
<p>For instance, let's consider Software Developer job. In first 1 - 5 years you are expected to do programming more, later over 6 - 9 years you are expected to take design components, do POCs, etc. And over 10 years & above you are expected to design solutions and provide architecture guidelines etc. Please note here as years of experience goes you need to build different skills set to grow your career and hence the salary. </p>
<p>That is why with more number of experience you need to gain more exposure as well to salary raise. </p>
<h4>Understand value addition</h4>
<p>As years of experience grows you need to add more value to keep getting salary raise. Just because you are there in the company for long years no one keeps giving good salary raise. </p>
<p>For example with 12 years of experience you need to talk comfortably with the leadership team on newer technology developments and how can some of them be adopted in the company to improve operation metrics, KPIs(Key Performance Indicators), reduce costs, etc</p>
<p>Turn the problem upside down. For a moment think you are running a business and would you give salary what you are expecting to person with the same skill set as you.
<h4>Skip level manager should know you by name</h4>
<p>This is not a step but you could use this as a yardstick. You report to manager/lead and then you manager/lead reports to his manager. Your manager boss is your skip level manager. You need to be active and notable in your area of expertise so that your skip level manager knows you by name. </p>
<p>To gain attention with senior management start giving tech talks in your organization, introduce tools which can reduce development efforts. You need to have such an expert level such that your manager should refer you to other people to solve their issues /problems. </p>
<h4>Invest in training</h4>
<p>Especially in IT industry you need to keep upgrading your skill set. There are lot very good training platforms available in the market. Below are few such training platforms online.<p>
<ol>
<li><a href="http://www.pluralsight.com">Pluralsight</a></li>
<li><a href=""http://www.lynda.com">Lynda</a></li>
<li><a href="https://www.coursera.org/">Coursera</a></li>
<li><a href="http://udemy.com">udemy.com</a></li>
</ol>
<p>Spend some bucks, buy subscription and go though courses. It’s like sowing high yield seeds for better crops later in the season. </p>
<h4>Networking</h4>
<ol>
<li>
<p>Be active on <a href="https://www.linkedin.com/">LinkedIn </a>which is a professional networking site. It’s worth spending 2 -3 hours every week. </p>
<p>Follow the people whom you know are getting good salary. See whom they connect to and what they follow on the site. Especially see what new skills they are adding to their resumes of late.</p>
</li>
<li>Subscribe to sites like <a href="http://infoq.com">infoq.com</a>, <a href="http://medium.com">medium.com</a>, <a href="https://msdn.microsoft.com/en-us/magazine/msdn-magazine-issues.aspx">msdn monthly magazine</a> etc for your area of topics.</p>
<p>Read at least 2 -3 article published on these sites every week to get good grasp on what is going on in your area of work. </li>
</ol>
Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-6166061314683898484.post-18748735564497235382018-05-26T18:50:00.000+05:302018-06-08T17:13:29.900+05:30one way to keep developer job interesting all the time<p>Recently one of my close acquaintance said he is experiencing boredom in his developer job because of mundane work and said he has free time sometimes. And he was not at all happy with the situation.</p>
<p>After spending some time researching I sent an email with the below content. My close acquaintance is a C++ developer.</p>
<p>------------------------</p>
<p>Dear,</p>
<p><a href="https://github.com/trending/c++">https://github.com/trending/c++</a></p>
<p>Today you mentioned that your work in not interesting. You can make your developer job interesting if you wish to, by following below:</p>
<ul>
<li>Go through the link at the beginning of the email.</li>
<li>It shows all the interesting projects being built in C++ (Similarly you can see trending projects for other languages as well).</li>
<li>See which projects suits you and sparks interest in you and START contributing to them on github.</li>
</ul>
</br>
<h4>It helps you in two BIG ways:</h4>
<ul>
<li>Firstly, it gives you interesting work.</li>
<li>Second, it will acts a GOOD resume and recruiters will start calling you with job oppurtunities looking @ your contributions on a pubic forum like <a href="https://github.com/">github</a>. </li>
</ul>
<p>------------------------</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-86676352032158695322018-03-17T20:19:00.000+05:302018-03-27T00:51:25.059+05:30remedy to recurring code review comments<p>Recently in one the interview, I was asked: "how would you handle a situation wherein which your junior developer is often making the same coding mistakes and getting same code review comments?".</p>
<p>I without thinking much answered it and I think the interviewer liked it.</p>
<b>The way I answered it.</b>
<p>If a developer is a making same coding mistake often, it’s more likely that he/she doesn’t know why it’s a mistake. Will sit with the colleague and explain him/her why it’s a NOT a best coding practice. After we understand why that is not a GOOD code, then it less likely that we do the same mistake again!!! (at least anytime soon!)</p>
Thanks
Ranga
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-32495956768638456692018-01-01T07:00:00.000+05:302018-01-04T16:54:02.264+05:30what is const keyword in c# language<p>First, let's understand the English dictionary meaning of the "constant" word. Constant means "a situation that does not change", "not changing or varying", etc. Now having understood the meaning of constant, now let's understand about constant in C# language, how to define const in C# and when to use them?, etc</p>
<h4>How to define constants in C#</h4>
<p>Constant in C# language are defined using "const" keyword as in the below example.</p>
<div class="code">
<span class="Modifier">public</span> <span class="Modifier">const</span> <span class="ValueType">double</span> PI = 3.1415926535897931;
</div>
<p>The π (PI) value in Mathematics is a constant and so the PI is defined as a constant in .NET framework class Math.</p>
<h4>Characteritics of constants in C#</h4>
<ol>
<li>
Constant fields value should be assigned value when they are declared. You cannot declare constant fields in one place and assign a value to it another place. If you don't assign a value to a const field during their declaration, you will get a compilation error.
<p class ="error">
A const field requires a value to be provided
</p>
</li>
<li>As obvious as it looks Once constants are defined, you cannot change the value of them. If you try to assign value to them you will get compilation error.</li>
<div class="code">
System.Math.PI = 3.14;
</div>
<p>The above line of code which is trying to set a new value for Math.PI constant will result will produce a compilation error.</p>
<p class ="error">
The left-hand side of an assignment must be a variable, property or indexer
</p>
<li>
<p>Constant fields can be declared with any of the <a href="http://rangahc.blogspot.com/2012/12/access-specifier.html">access specifiers </a>depending upon your need. Thre is no restriction as such.</p>
<p>They can be public, private, protected, etc</p>
</li>
<li>
<p>When you assign a constant value to a variable, such assignment value will be replaced by actual value.</p>
<p>For exmple, let's consider a class.</p>
<div class="code">
<span class="ValueType">double</span> radius = 6.5;<br />
<span class="ValueType">double</span> areaOfCircle = <span style="background-color:yellow">Math.PI</span> * Math.Pow(radius, 2);
</div>
<p>In the above code post compilation the constant variable PI will get replaced with its actual value. So after compilation code will look like below:</p>
<div class="code">
<span class="ValueType">double</span> radius = 6.5;<br />
<span class="ValueType">double</span> areaOfCircle = <span style="background-color:yellow">3.14</span> * Math.Pow(radius, 2);
</div>
</ol>
<h4>Const keyword usage example</h4>
<p>Below C# program defines two classes. Result and ResultHelper. Result class has 3 decimal type constants defined. ResultHelepr class is using the constatnts and determining whether a result is pass/fail.</p>
<div class="code">
<span class="Modifier">public</span> <span class="ReferenceType">class</span> Result<br />
{<br />
<span class="Modifier">public</span> <span class="Modifier">const</span> <span class="ValueType">decimal</span> DistinctionPercentage = 75;<br />
<span class="Modifier">public</span> <span class="Modifier">const</span> <span class="ValueType">decimal</span> FirstClassPercentage = 60;<br />
<span class="Modifier">public</span> <span class="Modifier">const</span> <span class="ValueType">decimal</span> PassPercentage = 35;<br />
<br />
<span class="Modifier">public</span> <span class="ValueType">decimal</span> Percentage { get; set; }<br />
}<br />
<br />
<span class="Modifier">public</span> <span class="Modifier">static</span> <span class="ReferenceType">class</span> ResultsHelper<br />
{<br />
<span class="Modifier">public</span> <span class="Modifier">static</span> <span class="ValueType">void</span> Display(Result result)<br />
{<br />
<span class="Statement">if</span> (result.Percentage >= Result.DistinctionPercentage)<br />
Console.WriteLine(<span class="String">"Pass. Distinction Class!!!."</span>);<br />
<br />
<span class="Statement">else</span> <span class="Statement">if</span> (result.Percentage >= Result.FirstClassPercentage)<br />
Console.WriteLine(<span class="String">"Pass. First Class!!."</span>);<br />
<br />
<span class="Statement">else</span> <span class="Statement">if</span> (result.Percentage >= Result.PassPercentage)<br />
Console.WriteLine(<span class="String">"Pass."</span>);<br />
<span class="Statement">else</span><br />
Console.WriteLine(<span class="String">"Fail."</span>);<br />
}<br />
}
</div>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-6166061314683898484.post-51511889233572989052017-12-31T15:29:00.000+05:302017-12-31T16:49:11.108+05:30readonly fields in C# class<p>C# language has a keyword to mention fields in a class can be readonly. In this tutorial let's discuss readonly keyword and how it can be used to convey class author intention that a field value shouldn't be modified once the class instance is created.</p>
<h4>C# sample demonstrating readonly keyword </h4>
<div class="code">
<span class="Modifier">public</span> <span class="ReferenceType">class</span> Employee<br />
{<br />
<span class="Modifier">private</span> <span class="Modifier">readonly</span> <span class="ReferenceType">string</span> _id;<br />
<span class="Modifier">public</span> <span class="ReferenceType">string</span> _deptId;<br />
<br />
<span class="Modifier">public</span> Employee(<span class="ReferenceType">string</span> id)<br />
{<br />
_id = id;<br />
DeptId = deptId;<br />
}<br />
<br />
<span class="Modifier">public</span> <span class="ReferenceType">string</span> ID<br />
{<br />
get<br />
{<br />
<span class="Statement">return</span> _id;<br />
}<br />
}<br />
<br />
<span class="Modifier">public</span> <span class="ReferenceType">string</span> DeptID<br />
{<br />
get<br />
{<br />
<span class="Statement">return</span> _deptID;<br />
}<br />
set<br />
{<br />
_deptID =value;<br />
}<br />
}<br />
}
</div>
<h4>Notes on above C# program </h4>
<ol>
<li>"_id" has been declared as readonly.</li>
<li>"_id" member has been assigned a value inside the Employee class constructor.</li>
</ol>
<h4>readonly class members and value assignment</h4>
<ol>
<li>With readonly members properties, you can assign value only during initialization and inside the class constructors.</li>
<li>If you try to assign value to members anywhere else, you will get the below error:
<p class="error">A readonly field cannot be assigned to (except in a constructor or a variable initializer)
</p>
</li>
</ol>
<h4>When to define readonly fields in a class</h4>
<p>If a member of a class whose value you(class author) don't want anyone to change post object construction, then consider marking that member as readonly.</p>
<p>By declaring a member as readonly you are indicating to other fellow developers that such member value cannot be changed once the object is created (post constructor call).</p>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-26307202030587973342017-11-28T01:05:00.001+05:302017-11-28T01:30:03.249+05:30stop creating your own delegates, start using Func delegates<p>If you are still defining custom <a href="http://rangahc.blogspot.com/2014/12/why-to-use-delegates.html">delegates</a>, you can stop creating them. In place of them, you can use Action And Func delegates. Sounds cryptic!, don't worry, we will go into detail.</p>
<h4>How we define custom delegates?</h4>
<p>Delegates are function pointers, which are defined like below.</p>
<div class="code">
<span class="Modifier">public</span> <span class="ReferenceType">delegate</span> <span class="ReferenceType">string</span> MessageFormat(<span class="ReferenceType">string</span> text);
</div>
<p>And then you will use the delegate to assign a method returning string by accepting a string argument.</p>
<div class="code">
<span class="Modifier">public</span> <span class="ReferenceType">string</span> BuildText(<span class="ReferenceType">string</span> format){<br />
<br />
<span class="InlineComment">// logic goes here.</span><br />
<br />
}<br />
<br />
<span class="InlineComment">//Later you can assign a method returning string</span><br />
<span class="InlineComment">// to the delegate defined</span><br />
MessageFormat=BuildText;
</div>
<p>So in practice, every time you need a new delegate to match the signature of the target method which returns something. In this way, you end up creating new delegates just to match the target method signatures. Creating custom delegates is no longer necessary in latest C# .NET, you easily use built-in Func Delegates to match the definition of methods returning something; other than void.</p>
<h4>Use Func delegates in place of custom delegates</h4>
<p>As per MSDN Func delegate Encapsulates a method that has one parameter and returns a value of the type specified by the TResult parameter.</p>
<div class="code">
<span class="Modifier">public</span> <span class="ReferenceType">delegate</span> TResult Func<<span class="Statement">in</span> T, <span class="MethodParameter">out</span> TResult>(<br />
T arg<br />
)
</div>
<p>Where T in the input and the TResult in the return type. The Func delegates are overloaded to support varying number of input parameters ranging from one input argument T1 to 16 arguments (T16).<p>
<p>Now using Func delegate we can easily avoid creating a new delegate to match the definition of a method which returns a type by accepting parameters. Going by this we can easily replace MessageFormat custom delegate declaration. The same delegate can be written as below:<p>
<div class="code">
<span class="Modifier">public</span> Func<<span class="ReferenceType">string</span>, <span class="ReferenceType">string</span>> MessageFormat;
</div>
Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-6166061314683898484.post-17439317426597948472017-11-26T07:01:00.000+05:302017-11-27T09:32:21.102+05:30transition to software architect - TIP # 1 - read business case studies <p>Of late I'm thinking a lot more on the subject. How to make a transition from Senior Technical Lead into an Architect role. I must confess transition to an architect role is easy compared to my previous other roles. There are definitely reasons to it, but not delve into that now.</p>
<p>To become an architect you need gain knowledge of various business verticals of an enterprise IT. Ranging from customer acquisitions, sales, marketing, promotions, budget, technology roadmap, hosting, etc and etc.</p>
<p>In the all above business verticles there is an emphasis specific set of IT knowledge.</p>
<h4>Sales lead generation technical domain</h4>
<p>For example, for Customer acquisition you need to be acquainted with lead generation process. Who is the market leader in sales lead generation? Who is the leader in space? It's SalesForce. Going through the salesforce.com business case studies, you will get an idea of how fortunes 500 companies are using Salesforce to enable their respective companies business.</p>
<p><a href="https://www.salesforce.com/in/customers/">Salesforce business case study examples</a></p>
<h4>Content Mangement technical domain</h4>
<p>From sales lead generation if you move to marketing you will companies spent considerable amount money on content management solution. CMS helps companies become expressive about their products on web properties so that potential customers can refer the content.<p>
<p>In this CMS space they are many names. I'm reading more on Sitecore and how using which enterprises are building content to meet their marketing strategies.</p>
<p><a href="https://www.sitecore.net/customers">sitecore CMS solution customer bussines case studies</a></p>
<h4>Enterprise application CLOUD hosting</h4>
<p>When it comes to hosting nowadays it makes lot more sense to consider public CLOUD.Again in the public cloud who is the market leader? It's definitely Amazon AWS with close to 30% market share.</p>
<p>Most fortune 500 companies are using AMAZON AMS nowadays. So reading about AMAZON Cloud AMS business case studies will definitely help you understand how enterprises are building business-critical apps with less budget and in less time.<p>
<p><a href="https://aws.amazon.com/solutions/case-studies/all">https://aws.amazon.com/solutions/case-studies/all</a></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-20413298033623978582017-11-16T22:23:00.001+05:302017-11-17T16:35:18.480+05:30blocking collection in .NET to implement easy concurrent queuing <p>In the last post I talked about using <a href="http://rangahc.blogspot.com/2017/11/concurrent-queuing-in-dotnet.html">ConcurrentQueue to implement thread-safe queuing.</a> In this blog post, you will learn about BlockingCollecton which makes it further easier to implement thread-safe queuing.</p>
<p>While reading items from the queue, we usually use while loop to keep reading messages. Now let's look at such a queuing example with ConcurrentQueue.</p>
<div class="code">
ConcurrentQueue<Message> queue = <span class="Keyword">new</span> ConcurrentQueue<Message>();<br />
<span class="Statement">while</span> (!cancelled)<br />
{<br />
Message item = <span class="Keyword">null</span>;<br />
<span class="Statement">if</span> (queue.TryDequeue(<span class="MethodParameter">out</span> item))<br />
{<br />
<br />
<span class="InlineComment">// Logic to process the item</span><br />
<span class="InlineComment">// goes here.</span><br />
}<br />
<br />
}
</div>
<p>The while loop keeps trying to read the message until its canceled.The thread running the loop will be consuming CPU all the time, even if there are no messages, which is not definitely a good thing.
<p>To reduce CPU overhead with while loop logic to dequeuing the messages, we can take advantage of BlockingCollection introduced in .NET 4.0</p>
<h4>What is BlockingCollection</h4>
<ul>
<li>BlockingCollection is from "System.Collection.Concurrent" namespace.</li>
<li>BlokcingCollection is thread-safe collection.</li>
<li>Use BlockingCollection class GetConsumingEnumerable() method to get the IEnumerable<Message>. You can use foreach loop around GetConsumingEnumerable() method.This for-each loop will iterate in a loop as long as items are present in it. If not GetConsumingEnumerable will get blocked until an item added to it. That is reason its called BlockingCollection.</li>
<li>By default BlockingCollection acts as a ConcurrentQueue i.e., thread-safe, FIFO collection.</li>
<li>Similar to Queue, you can keep adding items to BlockingCollecton from mutiple threads. In another thread you keep removing the items via GetConsumingEnumerable() method.</li>
</ul>
<h4>Code using BlockingCollection</h4>
<div class="code">
BlockingCollection<Message> collection<br />
= <span class="Keyword">new</span> BlockingCollection<Message>();<br />
<br />
<span class="InlineComment">// If not items in blocking collection, </span><br />
<span class="InlineComment">// the call will get blocked here</span><br />
<span class="Statement">foreach</span>(Message message <span class="Statement">in</span> <br />
collection.GetConsumingEnumerable())<br />
{<br />
<br />
}
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-71779985333476818872017-11-14T00:44:00.000+05:302017-11-17T16:35:36.899+05:30concurrent queuing in .NET<p>If you have built a queuing functionality in .NET app, it's most likely that you would have used Queue class from System.Collection.Generic namespace. The Queue collection has EnQueue and DeQueue methods. The Enqueue method adds an item to queue & Dequeue method removes the item from the queue.</p>
<h4>Issues with Queue class from System.Collections.Generic</h4>
<p>However, the Enqueue and Dequeue methods aren't thread-safe. It means in a multi-threaded scenario when one thread sees there is an item in the queue and try to Dequeue it, the item might have been removed by another thread; in such situation, InvalidOperationException will be thrown saying "Queue is empty."</p>
<div class="code">
<span class="Modifier">static</span> <span class="ReferenceType">object</span> syncObject = <span class="Keyword">new</span> <span class="ReferenceType">object</span>();<br />
<span class="Modifier">static</span> <span class="ValueType">void</span> Main(<span class="ReferenceType">string</span>[] args)<br />
{<br />
Queue<Message> queue = <span class="Keyword">new</span> Queue<Message>();<br />
<span class="Statement">while</span> (<span class="Keyword">true</span>)<br />
{<br />
<span class="Statement">if</span> (queue.Count > 0)<br />
{<br />
<span class="Statement">lock</span> (syncObject)<br />
{<br />
<span class="Statement">try</span><br />
{<br />
Message item = queue.Dequeue();<br />
<br />
<span class="InlineComment">// Logic to process the item</span><br />
<span class="InlineComment">// goes here.</span><br />
}<br />
<span class="Statement">catch</span> (InvalidOperationException ex)<br />
{<br />
<br />
}<br />
}<br />
}<br />
}<br />
}
</div>
<h4>Solution using ConcurrentQueue from System.Collections.Concurrent namespace</h4>
<p>To avoid getting such an invalid operation exception on trying to remove a nonexisting item in the queue, you can opt for ConcurrentQueue from the System.Collections.Concurrent namespace. Concurrent Collection were newly added in .NET 4.0 framework.</p>
<p>The ConcurrentQueue class has TryDequeue() method, which will not throw an exception when queue is empty, instead, the method will return false.</p>
<div class="code">
<span class="Modifier">static</span> <span class="ValueType">void</span> Main(<span class="ReferenceType">string</span>[] args)<br />
{<br />
ConcurrentQueue<Message> queue = <span class="Keyword">new</span> ConcurrentQueue<Message>();<br />
<span class="Statement">while</span> (<span class="Keyword">true</span>)<br />
{<br />
Message item = <span class="Keyword">null</span>;<br />
<span class="Statement">if</span> (queue.TryDequeue(<span class="MethodParameter">out</span> item))<br />
{<br />
<br />
<span class="InlineComment">// Logic to process the item</span><br />
<span class="InlineComment">// goes here.</span><br />
}<br />
<br />
}<br />
}
</div>
<h4>Advantage of using ConcurrentQueue over Queue</h4>
<ul>
<li>ConcurrentQueue is from System.Collection.Concurrent, so its thread safe.</li>
<li>ConcurrentQueue has TryDequeue() method which will return false when collection is empty and doesnt throw exception. As you know Exceptions are costlier, hence code with ConcurrentQueue will perform better compared to Queue in multithreaded scenario.</li>
<li>Without the try-catch block around TryDeque() method, the code logic with ConcurrentQueue is simple and easy to read.</li>
</ul>
<h4>Conclusion</h4>
<p>If you are on .NET 4.0, it always better to use ConcurrentQueue compared to Queue. This is because ConcurrenrQueue will perform better in multithread envrionment. Nowadays its quite hard to assume an app which are not multi-threaded, so you can always use ConcurrentQueue going forward.</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-75507293308999594182017-11-10T23:43:00.000+05:302018-06-03T10:16:42.595+05:30how to crack software developer interview in style<p>Junior level professionals in the Software Development industry will be changing their job very often. The interview will be very competitive in well-paying companies. To clear interview you can refer popular blogs based on your skill, refer interview books in the market. </p>
<h4>Issues with conventional ways to prepare for interview</h4>
<P>But the problem with these conventional ways is that, you hardly find any single blog or website to sharpen your skill set. You end up opening multiple tab in a browser for each link available in the <a href="http://google.com">google</a>search. This will lead to confusion on which one to read.</p>
<p>Though interview books are good for interview preparation, they are very narrow in terms of what they cover and more over you will such interviews books only for most widely skills like JAVA, .NET, etc. Also its difficult to find revised books latest frameworks & technologies in market.</p>
<h4>Using stackoverflow to prepare for interview</h4>
<p>I think you can easily clear interview if you went through question and answers on <a href="https://stackoverflow.com">stackoverflow </a>for a given skill.</p>
<p>For example for C# language as of this blog post publish, they are around 125,334 questions. That is very vast universe of questions.</p>
<div style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoSUnq3rBXSBhTwkCENivZdkvy-T2Ffl0PqjBAxcZz679gboBfP51bTSpJI7FGCSVlTl4HaGCQXhd1_WqfSRpGfShyphenhyphen44H9Jx8POXDyeEfuHHoODvTUjYU6biQH0PunWKAce4Jjhxd0yAA/s1600/Stackoverfow+tagged+questions.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoSUnq3rBXSBhTwkCENivZdkvy-T2Ffl0PqjBAxcZz679gboBfP51bTSpJI7FGCSVlTl4HaGCQXhd1_WqfSRpGfShyphenhyphen44H9Jx8POXDyeEfuHHoODvTUjYU6biQH0PunWKAce4Jjhxd0yAA/s1600/Stackoverfow+tagged+questions.PNG" data-original-width="656" data-original-height="156" /></a></div>
<p>Also its easy to find top rated questions and answers. So if you start preparing for top voted questions and answers, over 2 -3 months you can very well sharpen your skill to clear difficult interviews.</p>
<p>
<a href="https://stackoverflow.com/questions/tagged/c%23">Viewing top rated C# questions on stackoverfow.</a>
</p>
<p>
<a href="https://stackoverflow.com/tags/java">Viewing top rated JAVA questions for stackoverfow.</a></p>
<p><a href="https://stackoverflow.com/questions/tagged/algorithm">Viewing top rated algorithm questions on stackoverfow.</a></p>
<p><a href="https://stackoverflow.com/questions/tagged/distributed-computing">Viewing top rated distributed computing questions on stackoverfow.</a></p>
Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-6166061314683898484.post-22413256059766895492017-11-10T09:40:00.000+05:302017-11-10T14:11:21.079+05:30stop creating your own delegates, start using Action delegates<p>If you are still defining custom <a href="http://rangahc.blogspot.com/2014/12/why-to-use-delegates.html">delegates</a>, you can stop creating them. In place of them, you can use Action And Func delegates. Sounds cryptic!, don't worry, we will go into detail.</p>
<h4>How we define custom delegates?</h4>
<p>Delegates are function pointers, which are defined like below.</p>
<div class="code">
<span class="Modifier">public</span> <span class="ReferenceType">delegate</span> <span class="ValueType">void</span> ClickEventHandler (<span class="ReferenceType">object</span> sender, EventArgs args);
</div>
<p>And then you will use the delegate to define an event.</p>
<div class="code">
<span class="Modifier">public</span> <span class="Modifier">event</span> ClickEventHandler Click = <span class="Keyword">null</span>;
</div>
<p>So in practice, every time you need a new delegate to match the signature of the target method. In this way, you end up creating new delegates just to match the target method signatures. Creating custom delegates is no longer necessary in latest C# .NET, you easily use built-in Action Delegates.</p>
<h4>Use Action delegates in place of custom delegates</h4>
<p>The Click event can be defined using an Action delegate like below. Using Action delegate we can almost ALL the time stop worrying about creating new delegates. How cool is that!</p>
<div class="code">
<span class="Modifier">public</span> <span class="Modifier">event</span> Action<<span class="ReferenceType">object</span>, EventArgs> Click = <span class="Keyword">null</span>;
</div>
<p>Now if you are wondering what are these Action Delegates, refer my another blog post on <a href="http://rangahc.blogspot.com/2015/05/generic-delegates-in-csharp.net.html">generic delegates</a>.</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-87455701485711609462017-11-06T09:11:00.000+05:302017-11-06T21:34:46.284+05:30partial class practical use case with web service proxy regeneration<h4>Problem statement</h4>
<p>Recently one of my friends has to regenerate the proxy classes added via Visual Studio Add Service Reference option to an ASMX WEB service. After regeneration of the proxy classes, he started getting "HTTP Error 401 - Unauthorized" error.</p>
<h4>Temporary solution</h4>
<p>He called out for a help. After looking carefully into the proxy file, we found that the manually added code in the reference.cs file was got overwritten with proxy class regeneration.<p>
<p>The error "HTTP Error 401 - Unauthorized" indicated that authentication details are perhaps missing while making a request to web service. But we couldn't find any authentication details passing code in the latest reference.cs file. Later we checked into File History, there was a difference. The authentication related methods were not present in the latest proxy class reference.cs file.</p> After we added the method to include the missing authentication details, the call to web service method started working.</p>
<h5>Auto generated web service proxy with manually edited code</h5>
<p>It overrides the GetWebRequest() method in the same auto generated proxy class.</p>
<div class="code">
<span class="Modifier">protected</span> <span class="Modifier">override</span> WebRequest GetWebRequest(Uri uri)<br />
{<br />
<span class="ReferenceType">string</span> authInfo = <span class="String">"authenticaiton"</span>;<br />
HttpWebRequest request = (HttpWebRequest)<span class="Keyword">base</span>.GetWebRequest(uri);<br />
request.Headers.Add(HttpRequestHeader.Authorization, authInfo);<br />
<br />
<span class="Statement">return</span> request;<br />
}
</div>
<h4>Permanent solution</h4>
<p>Proxy generation happens all the time when the corresponding web service undergoes change. So, the proxy generation was recurring process and whenever proxy generation we would be sitting and fixing the same errors caused by manual changes overwriting issue.</p>
<p>We ought to find out a permanent solution so that all the issues with web service proxy regeneration can be put to rest.</p>
<p>Here <a href="http://rangahc.blogspot.com/2014/01/partial-class-in-csharp.html">partial classes in C#</a> came to our rescue. Added a new partial class and in that partial class, included all the code we were manually adding to proxy class after it got regenerated.</p>
<p>New code looked like below:</p>
<div class="code">
<span class="Namespace">namespace</span> SameNamespaceAsThatOfProxyClass<br />
{<br />
<span class="Modifier">public</span> <span class="Modifier">partial</span> <span class="ReferenceType">class</span> SameClassNameAsThatOfProxyClass<br />
{<br />
<span class="Modifier">protected</span> <span class="Modifier">override</span> WebRequest GetWebRequest(Uri uri)<br />
{<br />
<span class="ReferenceType">string</span> authInfo = = <span class="String">"authenticaiton"</span>; <br />
HttpWebRequest request= (HttpWebRequest)<span class="Keyword">base</span>.GetWebRequest(uri);<br />
request.Headers.Add(HttpRequestHeader.Authorization, authInfo);<br />
<span class="Statement">return</span> request;<br />
}<br />
}<br />
}
</div>
<p>From that point onwards, whenever web reference proxy classes were regenerated, we never faced the problem of manual code being overwritten issue. As the classes were being different, the manually added was never overwritten when the web reference proxy classes regenerated.</p>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-82629177534926183002017-11-05T17:35:00.000+05:302018-09-22T20:02:34.704+05:30viewing c# language ver used in a project<p>Have you ever wondered what is the C# language version used in your C# .NET project. You might have not worried about it because the version of the C# version used depends on the .NET framework version you have used for the project. In this blog post let's see how to view and change the C#
version for the project.</p>
<h4>How to view & change c# language version</h4>
<li>Right click on the .NET project in visual studio and choose Properties.</li>
<li>In the left navigation tree, click on the "Build" tab. And browse to the end of the screen and click on the "Advanced..." button.</li>
<div style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuRMb0vIzrD6bNvZCOKlJ5Y1LFvWBl70jEg1SLFJX0JQMOMGotUnIrUJB6v7dCieSyoctP9N1lmfsXTIsMSdF4YV_SF4YBhKlytHUCFlm2cB01cuxYlbYpvWZbuEL59Bv-jgNqYWF1Ebc/s1600/Changing+C+charp+langauge+version+in+Visual+Studio+Advanced+Build+settings.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuRMb0vIzrD6bNvZCOKlJ5Y1LFvWBl70jEg1SLFJX0JQMOMGotUnIrUJB6v7dCieSyoctP9N1lmfsXTIsMSdF4YV_SF4YBhKlytHUCFlm2cB01cuxYlbYpvWZbuEL59Bv-jgNqYWF1Ebc/s1600/Changing+C+charp+langauge+version+in+Visual+Studio+Advanced+Build+settings.PNG" data-original-width="665" data-original-height="376" /></a></div>
<li>By default Language Version is "default", meaning it uses major C# language version. In the case below as you can see in the image, "default" means "C# 7.0".</li>
<div style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQSFvsH7Wvelb24VUwScUtYJ4K1aJesoYpjtCgxHlcSf-RlNi4xbnsPWlliMhkys2-EmPWt_FTOYid5mOU3tX_wP7ir83oycnCORIFkWgewhYNqsdBpKhxcQPeqw9uSQMdwSPq18c6pmc/s1600/C%2523+language+version+defaulted+to+major+version.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQSFvsH7Wvelb24VUwScUtYJ4K1aJesoYpjtCgxHlcSf-RlNi4xbnsPWlliMhkys2-EmPWt_FTOYid5mOU3tX_wP7ir83oycnCORIFkWgewhYNqsdBpKhxcQPeqw9uSQMdwSPq18c6pmc/s1600/C%2523+language+version+defaulted+to+major+version.png" data-original-width="102" data-original-height="194" /></a></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-49535460075231020862017-11-03T10:31:00.001+05:302017-11-06T16:20:19.950+05:30effect of exceptions on event chain<p>Recently in of the interview question I was asked a question related to event chaining.</p>
<h4>Question</h4>
<p>Let's assume there are 4 different subscribers have subscribed to an <a href="http://rangahc.blogspot.com/2015/01/events-in-csharp-explained-with-example.html">event</a>. Upon event is triggered, all the event subscribers will be called. In one of event handling methods if there an exception happened, what is the impact of that exception in calling the other subscriber's event handling methods.</p>
<h4>Answer</h4>
<p>Let's think for a while.</p>
<p> As event handling method will be called sequentially, if there are any exceptions happened in one of the event handling methods, then the subsequent subscriber's event handling method will not be called.</p>
<p>If the same unhandled exceptions traverse up the call stack, then it might end up in application crash.</p>
<h4> Let's go over an example</h4>
<p>Let' define an event, subscribe to the event and raise the event. Later we will the effect of an exception in one event handling method on other subsequent event subscriber methods.</p>
<div class="code">
<span class="ReferenceType">class</span> Program<br />
{<br />
<span class="InlineComment">// Define an event in the source object</span><br />
<span class="Modifier">public</span> <span class="Modifier">event</span> Action<<span class="ReferenceType">object</span>, EventArgs> MyEvent = <span class="Keyword">null</span>;<br />
<span class="Modifier">static</span> <span class="ValueType">void</span> Main(<span class="ReferenceType">string</span>[] args)<br />
{<br />
<br />
Program program = <span class="Keyword">new</span> Program();<br />
<br />
<span class="InlineComment">// Suscriber 1 </span><br />
program.MyEvent += Program_MyEvent1;<br />
<br />
<span class="InlineComment">// Subscriber 2</span><br />
program.MyEvent += Program_MyEvent2;<br />
<br />
<span class="InlineComment">// Raise event</span><br />
program.MyEvent(<span class="Keyword">new</span> <span class="ReferenceType">object</span>(), <span class="Keyword">new</span> EventArgs());<br />
<br />
Console.ReadLine();<br />
}<br />
<br />
<span class="Modifier">private</span> <span class="Modifier">static</span> <span class="ValueType">void</span> Program_MyEvent1(<span class="ReferenceType">object</span> arg1, EventArgs arg2)<br />
{<br />
<span class="Statement">throw</span> <span class="Keyword">new</span> NotImplementedException();<br />
}<br />
<br />
<span class="Modifier">private</span> <span class="Modifier">static</span> <span class="ValueType">void</span> Program_MyEvent2(<span class="ReferenceType">object</span> arg1, EventArgs arg2)<br />
{<br />
}<br />
}
</div>
<p>In the above sample program, the 2nd subscriber will never get notified because there is an unhandled exception happening in the first subscriber event handling method.</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-64344934240200501332017-11-02T20:06:00.000+05:302017-11-10T14:11:38.686+05:30viewing registry keys used by an application<p>You can easily view registry keys used by an application via tool called Process Monitor from <a href="https://docs.microsoft.com/en-us/sysinternals/">Microsoft Sysinternals</a>.</p>
<p>Launch the <a href="https://docs.microsoft.com/en-us/sysinternals/downloads/procmon">Process Monitor</a>. Click on the Filter menu item in the toolbar.</p>
<div text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPHLRAkkaQx3xtPoICbDYnnk7vrwVupPuYulmacdU6kP-Hqx39kFeJKJ_ljXtr-IHWWRWZZE8nOiRfLpFsCH7gm5o59YDatIRNRocuArBG9TIW9sLpWxOmNPOb48K-aTUYs6Rm4ii-gO4/s1600/Sys+Internals+-+Process+Monitor+-+Filter+toolbar.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPHLRAkkaQx3xtPoICbDYnnk7vrwVupPuYulmacdU6kP-Hqx39kFeJKJ_ljXtr-IHWWRWZZE8nOiRfLpFsCH7gm5o59YDatIRNRocuArBG9TIW9sLpWxOmNPOb48K-aTUYs6Rm4ii-gO4/s1600/Sys+Internals+-+Process+Monitor+-+Filter+toolbar.png" data-original-width="427" data-original-height="95" /></a></div>
</br>
</br>
</br>
</br>
</br>
</br>
<p>Set the filter to match below. Where PID is application Process ID for which you want to see the registry keys.</p>
<div text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHjC0Yi6NQHj5q0IyGVdYdxjLdavn46YSgxtue6tuRwrq0jPjGKjK9I-i4IjZnDB20Pb_Qrs-m9tr3a64MIq8B4XgplSgoObEnvqFM0iPeK2yTzOJ6i9NaQI7-k3KcFv68-V52kVkki1w/s1600/Process+Monitor+to+show+only+Registry+related+events.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHjC0Yi6NQHj5q0IyGVdYdxjLdavn46YSgxtue6tuRwrq0jPjGKjK9I-i4IjZnDB20Pb_Qrs-m9tr3a64MIq8B4XgplSgoObEnvqFM0iPeK2yTzOJ6i9NaQI7-k3KcFv68-V52kVkki1w/s1600/Process+Monitor+to+show+only+Registry+related+events.JPG" data-original-width="519" data-original-height="307" /></a></div>
</br>
</br>
</br>
</br>
</br>
</br></br>
</br>
</br>
</br>
</br>
</br>
</br>
</br>
</br>
</br>
<p>Then Process Monitor will start showing the registry keys accessed by the application, as and when such event happens.</p>
<div style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYGxzx3PSAKdcZxTufx-PLp3zx_hYEh-ZWFefP0ccDY0co7XHVIci7FxPxDObd5K-Bks4jiuzu51vRYn5j6csT1Ih_kpg-lsO_6z21Bx43siD2UZjwMSSubbrdw1-hHGXhz6K9wLqop_Y/s1600/Process+Monitor+showing+Registries+being+used+by+a+application.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYGxzx3PSAKdcZxTufx-PLp3zx_hYEh-ZWFefP0ccDY0co7XHVIci7FxPxDObd5K-Bks4jiuzu51vRYn5j6csT1Ih_kpg-lsO_6z21Bx43siD2UZjwMSSubbrdw1-hHGXhz6K9wLqop_Y/s1600/Process+Monitor+showing+Registries+being+used+by+a+application.JPG" data-original-width="771" data-original-height="215" /></a></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-86546635981881216042017-11-02T15:15:00.002+05:302017-11-05T21:06:10.785+05:30what is defensive programming<p>When writing code usually we will cover ALL positive cases covered because that is what testers will test for. And also depending upon the clarity in requirements you will also code for negative test cases like non admin users should not have access to settlement reports or order reports, etc.</p>
<p>But we need to improve our coding skills beyond just meeting the stated functionality in terms of security, invalid inputs, unexpected errors etc.</p>
<h4>Defensive programming example # 1</h4>
<p>For example if some application is sending you the XML as input and says, XML they send is always going to valid as per the XSD document, then it’s better to check whether given XML is per the shared XSD or not when input is received. If not we should throw an error back to application saying the input XML doesn’t match the XSD definitions.</p>
<p>If you assume input is always be valid, then your application is prone for unexpected error like null reference exceptions or "object reference not set to an instance of an object", etc. Such unexpected errors are time consuming to DEBUG and fix them. So it’s always better to think what can go wrong and write the code to handle such scenarios.</p>
<h4>Defensive programming example # 2</h4>
<p>Let's assume you are going to build a web application to view business critical reports. Probably you show a link to a user from the business heads group to view the list of such reports in a page. When a user click on a report to your app will displays the report in detail. While your app, rendering such detail report, you need to again validate whether the user is having the enough privilege to view the report. If not, you should throw HTTP 403 Forbidden error.</p>
<p>While displaying the detailed report, if you don't check for the required privilege then your business critical information is easily accessible to any other application user as long as they have a valid URL to view such a report.</p>
<p>As a defensive programming practitioner you will add a explicit check before you start processing the request to show the detailed report.</p>
<h4>Conclusion</h4>
<p>This kind of programming which anticipates what can go wrong and writes the logic to handle that errors gracefully is called defensive programming.
You need to become defensive programming practitioner to avoid unexpected errors and security breaches.</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6166061314683898484.post-60461928850151267222017-10-25T15:35:00.000+05:302017-10-30T07:27:29.641+05:30with net-framework-4-6-2 now you can see variabe caused the NullRefereneException<p>Today I was going though below .NET Blog post to know more detail on the framework 4.6.2 features.</p>
<p>Out of many, I found a very useful feature. Now when we encounter NullRefereneException, it’s going to say which variable caused it. This will save a ton of time for sure while fixing object reference not set to an instance of an object.</p>
<a href="https://blogs.msdn.microsoft.com/dotnet/2016/08/02/announcing-net-framework-4-6-2/">https://blogs.msdn.microsoft.com/dotnet/2016/08/02/announcing-net-framework-4-6-2/</a>
<div style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhR0pMSH7b3_2mG6Nd00VijpAAxsSiIyJlUtHB_9oH9u9cEiOhIeEhTuZ6qyXwVRA7i7BpqMiUDMiL3ahc6dvsdKxbtD9uvxnt1ceNlKQMkKG5_1rFNirvUiBq1t_dJ7YoHlKrnRePUIGg/s1600/VisualStudio+displays+the+varibale+caused+the+NullReferenceException.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img title="VisualStudio displays the varibale caused the NullReferenceException" title="VisualStudio displays the varibale caused the NullReferenceException" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhR0pMSH7b3_2mG6Nd00VijpAAxsSiIyJlUtHB_9oH9u9cEiOhIeEhTuZ6qyXwVRA7i7BpqMiUDMiL3ahc6dvsdKxbtD9uvxnt1ceNlKQMkKG5_1rFNirvUiBq1t_dJ7YoHlKrnRePUIGg/s1600/VisualStudio+displays+the+varibale+caused+the+NullReferenceException.png" data-original-width="874" data-original-height="265" /></a></div>Unknownnoreply@blogger.com0India20.593684 78.962880000000041-8.6044825 37.654286000000042 49.791850499999995 120.27147400000004