Monday, November 11, 2013

What’s new in code Editor in VS 2013

 

VS 2013 has came up with some very handy tools in the code editor. Let’s see some of those in detail.

CodeLens                                                                               

CodeLens allows you to find details about your code without leaving your code editor. This will give you details on top of your class or method as below.

image

In the image above you can see two details on top of the method.

  1. References

This will give you the details on the other methods which reference this method. If you click on the references it will show you the details of the references & you can click on them & go to the actual code.

image

Once you navigate to the reference code & if you want to come back to the code which you were working on, you can use the back button in tools.

image

     2.  Unit Test Status

This shows you the status of the unit tests written for the given method. If you click on that you can see more details. Also you can run the tests with in the popup in the editor rather going to the test classes.

image

Also CodeLens provided you more details.You can configure them in the CodeLens option. It is under

Tools->Options->TextEditor->All Languages->CodeLens

image

Peek Definition                                                                               

Have you ever come across that you are lost in the code, while you going through the code definition & you can’t remember where you were.Then VS 2013’s Peek Definition is the solutions for your problem. It gives you inLine code definition rather moving you between class files.

Short Cut Key : Alt+F12

In my Code sample I wanted to see the logic inside the “GetClassRoomListList()”. So when I click “Alt+F12” it will show me inline popup which shows the actual implementation. Also if we go further down & if we want to come back & see You can use the tools , which is highlighted in the

image

Enhanced Scroll Bar                                                                               

VS 2013 gives options to add remove items to show in your scroll bar. Isn’t in amazing.

Right click on the scroll bar in the editor & then click “Scroll bar Options”

image

Then you will get the scroll bar options window as below.

image

So can see two main categories under it.

  1. Display : You can select what is to be display in the scrollbar.
  2. Behavior : If you select Map mode, it will give you a code visualizer when you going through the scrollbar. So you can see the Code in the Scrollbar itself rather actually scroll & see the code. This is very useful when you have lengthy codes.

image

 

Happy Coding !!!!

Tuesday, November 5, 2013

Check boxes in Kendo Grid

 

You can find the sample code of adding check boxes & handling it’s checked even in Kendo Grid here :

http://jsfiddle.net/sammani/Xg56P/2/

Tuesday, October 29, 2013

Debugging Code in Code Map

 

Code Maps are now integrated with visual studio debugger. So when you debug the code you can see the stack trace in a visual manner.

To Integrate you debugger you can use the following icon in visual studio so it will create the code map for you debugging session. When you start debugging of you code you will see this icon.

image

When you click on the the icon, it will generate the code map for you, & when you stepping through the code parts it will show you visually where you exactly are as below. Arrow will show the current position.

image

You can add comments while you debugging the code for reference. Then if you want you can share your visualized version of you debugger session with the team as below.

image

This helps you to visualize your debugger more effective way.

http://channel9.msdn.com/Series/Visual-Studio-2012-Premium-and-Ultimate-Overview/Visual-Studio-Ultimate-2012Debug-visually-with-Code-Map-debugger-integration

Happy Debugging !!!!!!!!!!

Thursday, October 24, 2013

Change Tfs Workspace Name

 

In case in you have changes your computer name & you want to change the Tfs workspace name follow the following command.

1. Load the Visual Studio developer command prompt.

2. Run the Following Command

tf workspaces /updateUserName:OldUserName /collection:http://Tfs_server:8080

 

you can find more command here.

http://msdn.microsoft.com/en-us/library/cc31bk2e(vs.80).aspx

Tuesday, October 15, 2013

Code Maps In VS 2012

 

Code maps is another attractive visualization tool came with VS 2012 Update 1. it is more similar to the dependency graphs but this has more usability as this has been integrated with visual studio debugger so that the user can use this to visualize their debugging stack trace using this. We will see how we can use this.

Generate a Code Map :

Right click on the method which you want to evaluate & then click on “Show on code map”

 

image

then it will generate a code map as below.

image

Adding Items to Code Map:

when you right click on the “DrawRectangle” in the surface you will get some options to add items to your map as you prefer.

  1. Show Fields this references :- Will show all the global fields or properties which this particular method is referencing. In the code sample which I am using this method using a global variable named rectangle.

image

2. Find All References :- suppose you have a bug in the DrawRectangle(). so you  need to see what are the other methods which referencing this “rectangle” object. you can right click on that “rectangle” property & click on “Find All References”. it will show you all the methods referencing this variable.

image

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

There are some other options are also available as follows you can use it as per your requirement.

image

Feature: -

1. Legend

You can see the legend by going to the Code Map Toolbar:

image

2. Get details about a method

You can hover your mouse over any node to get more detail also you can double-click any node to see the code associated with it.

image

3. Flags

You can also flag nodes using a variety of colors to indicate some type of action needs to be taken.

image

3. Comments

Also you can add comments to your code map if you want to note something when you analyzing the code for you or your team members future reference.

image

3. Sharing

You can share the code map you have created. There are several sharing options available for you in the code map tool bar.

image

You can find a video on code maps here.

http://channel9.msdn.com/Series/Visual-Studio-2012-Premium-and-Ultimate-Overview/Visual-Studio-Ultimate-2012-Understanding-complex-code-with-Code-Map-ENU

We will discuss how to attach the debugger with the code maps in my next post. Until that…

Happy Visualizing !!!!!!

Sunday, September 15, 2013

Prevent Tab Selection on Condition in jQuery

 

if you want to stop user selecting a tab from the active tab based on a particular  condition or validations you can use the following code to do so.

If you are new to jQuery, you can find more details on jQuery tab in the here. jQueryTab

I have created the simple tab sample in jsfildler.

http://jsfiddle.net/sammani/mgumC/

To handle the tab selection based on conditions is very simple.What you have to do is to call the “beforeActivate” event & return true or false based on the condition. you can find the sample code here.

http://jsfiddle.net/sammani/mgumC/4/

Happy Coding !!!  Thumbs up

Wednesday, August 28, 2013

Web Deploy in Visual Studio 2012

 

Visual Studio 2012 has new feature where you can deploy your web projects to your production or development server in one click. following are the steps to follow.

Step 1:

Right click on the web project & select publish.

image

Step 2:

Then you will get the following window where we have to configure the deployment settings.

image

There are two ways we can create profiles.

  1. Import profile from already created publishsettings file.
  2. Create a new profile.

In here I will explain how to create a new profile.

Step 3:

In the Select or import a publish profile drop-down list, choose <New …>, and enter a name for the profile in the New Profile dialog box.

image

image

 

Step 4:

After that you will get the following window where you have to set up the connection on the deployment.

image

  •  Publish method  

If you select Web Deploy and you are publishing to IIS on your own computer for testing, you must have administrative rights on your computer, and Visual Studio must be running in administrator mode. (To open Visual Studio in administrator mode, right-click the Visual Studio icon in the Windows Start menu and select Run as Administrator.)

If you select Web Deploy and you are publishing to a server on your own network, make sure that the server is set up for the Web Deployment Agent Service (MSDepSvc, also known as Remote Agent service), and that you have administrative rights on the destination server. For information about how to set up the destination server,

If you are deploying to a hosting provider that does not support Web Deploy, you can select FTP instead.

Besides Web Deploy and FTP, another option is to use the File System publish method. This method publishes the web application to a folder that you specify. You can then use your own FTP tool to transfer the files to a hosting provider.

One of the Publish method options is Web Deploy Package. If you want to create a deployment package, then you can copy the package the destination server & then import that package directly to the IIS.

 

  •  Service URL

enter the URL that Web Deploy can use to publish the application.

If you are publishing to a hosting company, the company provides this value. It can be in any of the following formats:

  1. HostingCompanyURL (for example, contoso.com)

  2. https://HostingCompanyURL (for example, https://contoso.com)

  3. https://HostingCompanyURL:8172/msdeploy.axd (for example, https://contoso.com:8172/msdeploy.axd)

If you are publishing to IIS on your own computer for testing, enter localhost or the name of your computer.

If you are publishing to a server on your own network, enter one of the following URLs:

  1. http://ServerName

  2. http://ServerName/msdeployagentservice

If you’re publishing through a firewall, you might need to open port 8172.

 

  • Site/application

enter the name of the IIS web site and application.

  • User Name & Password

enter credentials for an account that has sufficient authority to perform deployment tasks on the destination web server

Then you can validate you settings by clicking on the Validate button in the window.

Step 5:

Next step is to configure the settings tab.

image

  • Configuration.

select the configuration setting which you want to publish in the deployment.

  • File Publish Options

expand the file publish options in the window then you will get following three options to select.

image

Remove additional files at destination

Will delete the files in the destination folder on deployment.

Precompile during publishing

Precompile or merge assemblies when you package or publish the project. when you click on this option you can click on configure then it will give the following advanced option where you can configure as per your requirement.

image

Exclude files from the App_Data folder

Prevents files in the App_Data folder from being deployed to the destination server

Step 6:

Then click next then you can preview the changes.

Step 7:

Then click on publish so that the site will be published.

Following these steps you can create a web deploy profile. Then next time when you want to publish that project the profile you creates will be loaded you have to just select the profile & click publish , visual studio will take care of the deployment.

image

 

Happy Deploy !!!!!

Sunday, July 14, 2013

Generic Method To get values of an Enum

 

Recently I got a requirement of creating a generic method to pass an Enum Name & get all the Enum Names & Values.

Method will return a collection of following class objects.

public class EnumValueDto  {

      public string Id { get; set; }

      public string Value { get; set; }
  }

private IList<EnumValueDto  > GetEnumValueList<T>()
    {
        IList<EnumValueDto  > enumValueList = new List<EnumValueDto  >();

        
        var values = Enum.GetValues(typeof(T)).Cast<T>();
        var enumerable = values as T[] ?? values.ToArray();


        for (int i = 0; i < enumerable.Count(); i++)
        {
          
            enumValueList.Add(new EnumValueDto  {

Id =((int)Enum.Parse(typeof (T), enumerable.ElementAt(i).ToString())).ToString(),

Value = enumerable.ElementAt(i).ToString() });
      

}

        return enumValueList;
    }

Hope this will be helpful.

Happy Coding !!!!!

Sunday, July 7, 2013

Modeling Applications in VS 2012

Designing Systems with a stable architecture is always challenging. But it is one of the most interesting tasks personally I find as a developer, it is where we can improve both technical knowledge & analytical skills.

VS 2012 has come with some new rich tools for modeling the applications to make sure , it meets the user requirements. This tools can be used to visualize the code to understand its structure, relationships, and behavior in a more effective manner. It provides us the facility of create models in different levels :-

  • Track requirements
  • Track Tasks
  • Test cases
  • bugs

 

Types of Models

 

1. Dependency Graph

This diagrams shows how your code is been organized & it’s dependencies. This is very useful to identify the code base without going through code lines. You can create a dependency graph for the whole solution & then dig in to the small levels of the assemblies as follows.

image

image 

2. Layer Diagram

Layer diagram let us to create logical grouping of the Visual studio solutions items. ( projects, classes). Using the layer diagrams you can group you solutions also can visualize the dependencies between the objects in different layers.

image

You can validate you architecture using layer diagram & generate a report so you can see the failing points. following diagram shows a sample validation report.

image

3. UML Model

Now you can use visual studio to create UML Diagrams so that you can clarify, understand & communicate your code design & user requirements.

  • Class Diagram
  • Use Cases
  • Activity Diagram
  • Sequence Diagram
  • Component Diagrams

 

4.Code-Based sequence Diagram

There are situations where we are assigned to projects which has been developed for several months & we are asked to do some modifications. It is always challenging & time consuming to understand the code & understand he flow of it by going through the code lines. Using visual studio you can generate sequence diagrams of a existing code so that you can easily visualize the flow of the method calls.

image
5. Domain-specific language (DSL)

A domain-specific language is a notation, usually graphical, that is designed to be used for a particular purpose. By contrast, languages such as UML are general-purpose. In a DSL, you can define the types of model element and their relationships, and how they are presented on the screen.

For more Information : http://msdn.microsoft.com/en-us/library/vstudio/ee943825.aspx

 

I will describe about this tools in more detail in my next posts.

Happy Modeling !!!!!

Monday, June 3, 2013

Accessing Service Reference in MVC Controller

When we add a service reference to a MVC application & then try to access it from a controller that type is not accessible in that. To get the service reference accessible in the code follow the following steps when adding the reference.

1. Click on the Advanced Settings Button in the Add Service Reference dialog.

image

2. Unselect the “Reuse types in referenced assemblies” option

image

I QUOTE this from Guy Kolbis' blog:

http://blogs.microsoft.co.il/blogs/kolbis/archive/2008/02/06/breaking-soa-with-wcf.aspx

Reuse types in referenced assemblies” means

"Basically it determines whether a WCF client will try to reuse that already exist in referenced assemblies instead of generating new types when a service is added or updated. By default, this option is checked."

 

Happy Coding !!

Sunday, May 26, 2013

Entity Framework Step By Step 3 – Model First

As I have discussed in my previous post we know how to create a Database using Entity Framework Model First framework. In this post we’ll see how to read & write data using EF.

When you create the Database using the designer, entity classes which we can use to access the data will be automatically generated in your solution. Please see the highlighted classes in the screen shot below.

image

  • BloggingModel.Context.cs :- Represents a combination of the Unit-Of-Work and Repository patterns and enables you to query a database and group together changes that will then be written back to the store as a unit.
  • Blog.cs & Post.cs :- Entity classes with properties defined in the database table.
Writing Data

static void WriteData()
      {

          using (var db = new BloggingContext())
          {
              // Create and save a new Blog
              Console.Write("Enter a name for a new Blog: ");
              var name = Console.ReadLine();

              var blog = new Blog { Name = name };
              db.Blogs.Add(blog);
              db.SaveChanges();

              ReadData();
          }
      }

Reading Data

static void ReadData()
{

    using (var db = new BloggingContext())
    {
        var query = from b in db.Blogs
                    orderby b.Name
                    select b;

        foreach (var item in query)
        {
            Console.WriteLine(item.Name);
        }

    }
}

Making Changes To Model

if you want to make any changes to your model the follow the following steps.

  1. Go to the designer & make the changes you want.
  2. Right click on the design surface & select “Generate Database from Model
  3. You may receive warnings about overwriting the existing DDL script and the mapping and storage parts of the model, click Yes for both these warnings
  4. Execute the updated SQL statement.

Sunday, May 12, 2013

Entity Framework Step By Step 2 – Model First

We’ll see how we can user Model First Development workflow of Entity framework with a very simple example in step by step so you can easily understand the concept.

Pre-Requisites

  • 1. You will need to have Visual Studio 2010 or Visual Studio 2012 installed to complete this walkthrough.
  • 2. If you are using Visual Studio 2010, you will also need to have NuGet installed.

Step 1:  Create Application

  • 1. Create New Console Application.
  • 2. Name it as “ModelFirstSample”

Step 2:  Add Entity Model item to project

  • 1. Right click on the project & select add new item.
  • 2. In the new item selection menu select “Data” then select “ADO.net Entity Model”.
  • 3. Name the item as “BloggingModel

image

  • 4. Then in the Entity Data Model Wizard select “"Entity Model” click finish.

image

Step 3:  Create Model

  • Right-click on the design surface and select Properties
  • In the Properties window change the Entity Container Name to BloggingContext
  • Right-click on the design surface and select Add New -> Entity…
  • Enter Blog as the entity name and BlogId as the key name and click OKimage

Step 4:  Add Properties

  • Right click on the entity & select Add New –> Scalar Property –> Add Name

    image

Step 5:  Set Properties of the scalar property added to the entity created

  • Right click on the scalar property you want to edit, them select properties.
  • You can then set the properties listed below as per your requirements in the domain model.

image

Step 6:  Create the “Post” entity

  • Create a entity named “Post” following the same steps with the following properties.

    1.  PostId

2. Title

Step 7:  Create a Relation

  • Right click on the Design surface & select Add New->Association
  • Select the properties of the association as per the requirement.
  • In this example Blog will have many Posts , so the association will have the properties as below.
  • Make Sure “Add foreign key property to the Posts Entity “is checked.

image

Now we have the simple model created as below in the

image

Step 8:  Generate the Database

  • Right click on the design surface and select “Generate Database from Model”

image

  • In “Generate Database Wizard” select new connection
  • Set the connection properties.

image

  • Select OK and you will be asked if you want to create a new database, select Yes
  • Select Next and the Entity Framework Designer will calculate a script to create the database schema
  • Once the script is displayed, click Finish and the script will be added to your project and opened
  • Right-click on the script and select Execute, you will be prompted to specify the database to connect to, specify (localdb)\v11.0 or.\SQLEXPRESS, depending on which version of Visual Studio you are using

Now connect to your database server using “SQL Management Studio” There you can see the new database is created as per the model we specified in the designer.

image

So we are done. In the Next post I will explain how to read & write data & how to handle the model changes.