Validation is a process that ensures the sanity of data entered, received or processed by a software module, class or class members.  Some examples of validation are length check, range check, Null check, date range, specific character and so on.

Read full Article here: Validation Application Block

Nuget – Visual Studio Package

October 27th, 2012 | Posted by Vidya Vrat in Visual Studio - (0 Comments)
NuGet Package Manager Download URLProblem- Many times during development it become tedious to look for right assemblies to be added to the project’s references. For example, Entity Framework, Enterprise Library blocks, JSON etc.
Due to the nature of application’s dependency on right assemblies; developers spend a good amount of time in searching the right installer URL of the utility packages, or look for assemblies in the machine and then reference those.Solution- NuGet is an open source based developement focused system for implementing packages in the .NET platform based applications. NuGet is designed to simplify the process of bringing/adding Microsoft (Enterprise Blocks etc.) and various third party(Ninjectm JSON etc.) libraries into a .NET application during development.

Once you have installed Nuget, you no longer need to worry about looking for assembly references for various frameworks, blocks etc. for example, JSON, Enterprise Library, Entity Framework etc.

You just need to right-click on the References and click on Manage NuGet Package as shown in the figure below:

This will open a new window, in which you can search your desired package and install it as shown in the figure below:

Now if you will look under thre References, you will notice that assembly references are added through NuGet. NuGet helped you save the time and effrot to add existing assemblies or install and then add in case it was new.

Now, you have got the assemblies your application requires, you can begin with code now to invoke the functionality from added assemblies.

It’s productive isn’t it?
 


EnterpriseLibrary version- 5.0 Download url
Language used in code sample below – C#Logging is a very important feature for many applications and serves the very critical purpose in a software application’s life. Logging enables to look for monitoring data and also document what is happening in-side and out-side of the application; also known as auditing.

Most common places to log such activities, information and data are:
1- Flat files (.log/.txt)
2- Event logs (Windows event viewer) and
3- Database.

In the absence of logging application block, the logging code needs to be repeated in the application at many places. This code will also include .NET library and function calls based on type of place you want to log the information. Hence, logging application block simply de-couples the logging functionality from the application code.

Configuring the Logging Application Block

1- Open your Visual Studio project, if not already available, add an app.config file
2- Open Microsoft Enterprise Library console.
3- In the Blocks menu, choose “Add Logging Settings” option, this will appear as shown here:
 

 

 4- Based on your requirements add listners (File, Event, Database etc.).

 

 

 

 5- Describe “Event Log” target listner


6- Describe “Flat File” trace listner

7- Describe “Message Formatter”

 

 
 


Now save this configuraton by clicking File–> Save option. and choose your added .config file,
this will be modified and will appear as shown here.

 

 

Now you can add the code to enable the Logging from your application into the defined “Target Trace Listners” in our case “Flat File” and “Event Log”.

I have designed a Windows Form application which reads a file, from provided path location, if file is found it loads the cntent into the text box, else in case of an exception “FileNotFoundException” the error info is logged into the Log file (c:\exception.log) and Event Log.

 

 
C# Code will look like this
 
using Microsoft.Practices.EnterpriseLibrary.Logging;
 
private voidbtnReadFile_Click(object sender, EventArgs e)
{
     StreamReader sr = null;
 
     try
      {
          sr = new StreamReader(txtFilePath.Text);
 
          txtFileContent.Text = sr.ReadToEnd();
     }
     catch (FileNotFoundException)
     {
         txtFileContent.Text=“Exception details logged log file  
                                and Event Viewer”;               
 

         LogEntry objLog = new LogEntry();

 

         objLog.Message = “Please provide valid Filename”;

         objLog.Categories.Add(“File Read Error”);
 
         Logger.Write(objLog);               
     }
 
     finally
      {
         if (sr != null)
          {
            sr.Close();
         }
     }    
}
 
 
Now if you open the C:\Exception.log you will see:

 

—————————————-
Timestamp: 10/1/2012 7:35:03 PM

Message: There is no explicit mapping for the categories ‘File Read Error’. The log entry was:
Timestamp: 10/1/2012 7:35:03 PM
Message: Please provide valid Filename
Category: File Read Error
Priority: -1
EventId: 0
Severity: Information
Title:
Machine: VIDYAVRAT-PC
App Domain: LoggingApplicationBlock.vshost.exe
ProcessId: 9164
Process Name: C:\VidyaVrat\Microsoft .NET\Application Code POCs\EnterpriseLibrary-Application Blocks\LoggingApplicationBlock\LoggingApplicationBlock\bin\Debug\LoggingApplicationBlock.vshost.exe
Thread Name:
Win32 ThreadId:13588
Extended Properties:

Category:

Priority: -1

EventId: 6352

Severity: Error

Title:

Machine: VIDYAVRAT-PC

App Domain: LoggingApplicationBlock.vshost.exe

ProcessId: 9164

Process Name: C:\VidyaVrat\Microsoft .NET\Application Code POCs\EnterpriseLibrary-Application Blocks\LoggingApplicationBlock\LoggingApplicationBlock\bin\Debug\LoggingApplicationBlock.vshost.exe

Thread Name:

Win32 ThreadId:13588

Extended Properties:
—————————————-

 

Also, if you open the EventVwr.exe then you will see:
 
 
This concludes that how Logging application block enables you to write small amount of code to do such a critical task of auditing.
 
 
 
 

VS 2010 Multi-Monitor support

December 20th, 2009 | Posted by Vidya Vrat in Visual Studio - (0 Comments)

World is changing and now most of the people has started working with two monitors, it makes them more productive, as people say.

Now if you consider, that you can view Form-Design and Form-code together, would it make you productive? or if you have ever felt sometimes how annoying it is to navigate from one tab to another tab in code editor view to look at code, compare, debug, or even work.

Considering this fact VS 2010 team made these Code/Form-Design windows Floatable, and so whichever code/design window you want to open in another monitor/screen parallely you can select “Float” option on the context menu (right-click that window) and drag it to your 2nd monitor.

If you see in the image here, as you right-click on a window it shows you a new option “Float”


click on the image to see larger view

Float was not an option with VS 2008 or earlier version of Visual Studios.Other options shown in the contect menu in the image above are same as of Visual Studio 2008 and earlier versions.

Microsoft launched WPF Application Framework,its alpha could be downloaded from codeplex site, by following the link below:
WPF Application Framework (WAF)

This application framework will help you create the applications based on layered architecture and the Model-View-ViewModel (aka MVVM, M-V-VM, PresentationModel) patterns.

.NET Framework 3.5 SP1 is a prerequisite for this.

Microsoft has recently launched the development tool support for Windows Cloud Computing – Windows Azure.

Windows Azure Tools for Microsoft Visual Studio; extend Visual Studio to enable the creation, building, debugging, running and packaging of scalable services on Windows Azure.

Windows Azure Tools for Microsoft Visual Studio includes:

*C# and VB Project templates for building Cloud Services
*Integration with the Development Fabric and Development Storage services
*Debugging Cloud Service Roles running in the Development Fabric
*Building and packaging of Cloud Service Packages
*Browsing to the Azure Services Developer Portal
*Role configuration
*SSL Certificate selection

Download here:
Windows Azure Tools for Microsoft Visual Studio