Thursday, May 26, 2016

Code Contracts in C#

Code contracts introduced in .NET Framework 4.0 is a useful but underutilized feature. It enables a developer to publish various conditions that are necessary within an application.

There is a  concept called Design by contract where you can  define pre-conditions, post-conditions, and invariants on class methods. The basic idea was for a method to define a contract which states conditions that must be true when the method gets called. This is also called as preconditions. The method must also define conditions that must be true when it finishes execution. This is called as postconditions. The method can also define conditions that should remain true while the program is running. This is called as invariants.

.NET 4.5 introduces a new feature in Code Contracts called as abbreviations. Abbreviations are useful in scenarios where some contracts are required repeatedly. So if a method contains multiple contracts, just decorate that method with the ContractAbbreviator attribute, and this enables it to be used within other methods requiring this contract.

Code Contracts in .NET 4.5 and 4.6

 Although you can use the classes in the namespace System.Diagnostics.Contracts available with .NET 4.0, there is no Code Contract ‘tooling’ available in Visual Studio 2013 or in the latest versions of the .NET Framework (.NET 4.5 onwards). You may see the Contract class in .NET 4.5 and above, but the class does not function until you manually install the Code Contract library. The Code Contract library has now been released as an open source framework available on GitHub
You need to download and run the Code Contracts .msi file found at in order for Code Contracts to be available in Visual Studio 2013 and Visual Studio 2015. After the extensions are installed, a new tab appears in the properties of your solution called ‘Code Contracts’. You can specify the properties in this tab to configure Code Contracts in applications created using VS 2013 and VS 2015.

Ref. sites:

Thursday, May 19, 2016

Types of s/w licenses

Hi Guys,

When we work with any application(s), it  may have license, sometimes tools are of freeware with no license. To my knowledge, here are few types of license that are common.
1. Concurrent Licenses - Licenses that can be installed on any number of machines but can be used on a limited number of machines at any given point
2. Developer License -  Software that needs to be licensed by developer and the redistributable components can be deployed to any number of client/servers.
3. Evaluation - Trial license which may come with limited functionality or for a definite period of time
4. Free License - License that is available for free.
5. GNU License – General Public License is a free software license ensuring that the rights are preserved even when the software is copylefted.
6. OEM (Original Equipment Manufacturers) - Software license that accompanies hardware
7. Site License -  Software that is licensed to a site.  The definition of the site can vary by vendor – physical location, city, etc.
8. Volume license or Enterprise Volume License  - A single license can be used on multiple systems depending on the purchased volume.

Tuesday, May 10, 2016

Web applications Vs Web sites

When to use Web applications and Web sites. Courtesy: MSDN
Scenarios in which Web application projects are the preferred choice include the following:
  • You want to be able to use the Edit and Continue feature of the Visual Studio debugger.
  • You want to run unit tests on code that is in the class files that are associated with ASP.NET pages.
  • You want to refer to the classes that are associated with pages and user controls from standalone classes.
  • You want to establish project dependencies between multiple Web projects.
  • You want the compiler to create a single assembly for the entire site.
  • You want control over the assembly name and version number that is generated for the site.
  • You want to use MSBuild or Team Build to compile the project. For example, you might want to add pre-build and post-build steps.
  • You want to avoid putting source code on a production server.
  • You want to use the automated deployment tools that are available in Visual Studio 2010.
Scenarios in which Web site projects are the preferred choice include the following:
  • You want to include both C# and Visual Basic code in a single Web project. (By default, a Web application is compiled based on language settings in the project file. Exceptions can be made, but it is relatively difficult.)
  • You want to open the production site in Visual Studio and update it in real time by using FTP.
  • You do not want to have to explicitly compile the project in order to deploy it.
  • If you do precompile the site, you want the compiler to create multiple assemblies for the site, which can include one assembly per page or user control, or one or more assemblies per folder.
  • You want to be able to update individual files in production by just copying new versions to the production server, or by editing the files directly on the production server.
  • If you precompile the site, you want to be able to update individual ASP.NET Web pages (.aspx files) without having to recompile the entire Web site.
  • You like to keep your source code on the production server because it can serve as an additional backup copy.