Monday, February 11, 2013

Visual Studio Productivity Features

These are collection of tips and resources that will enhance productivity in Visual Studios.

Keyboard Shortcuts

Links to Shortcut key how-tos:


Below are a list of frequently used shortcuts with their command name.

Navigation:


  • Window.NextDocumentWindowNav: 
    • Navigate between files and tool windows
    • Ctrl + tab and use arrow keys to select
  • Window.CloseToolWindow:
    • Closes the currently active tool window
    • Shift + Esc
  • Window.CloseDocumentWindow
    • Closes the active tab
    • Ctrl + F4
  • Project.OpenFolderinWindowsExplorer
    • Opens a folder in Windows Explorer
    • Alt + F
  • File.OpenContainingFolder
    • Opens the currenrt file location of the active tab in Windows Explorer
    • Alt + F, F
  • Window.ShowDockMenu
    • Shows the dock options for the current tab
    • Alt + - (alter and underscore)
  • Project.ShowAllFiles
    • Shows all files, including excluded files for the current project. Press the same combination keys again to hide excluded files.
    • Ctrl+P, A
  • View.PropertyPages:
    • Displays the property pages for the currently selected item.
    • Alt + Enter
  • Project.Properties: 
    • Displays the project properties window for the current project 
    • Alt + F7

Text Editing

  • Data.Column
    • Delete the current line where the cursor is on and move the line below up one line. This is a shortcut that I use very often
    • Ctrl + L

Debugging
  • Debug.AttachToProcess
    • A frequetly used feature, specially, in web development to attache to the IIS server
    • Alt + A
  • f11: step into
  • shift f11:step out
  • shift alt f11: step in to a specific property
  • step over properties and operators

Code Snippet 
  • svm: staic void main
  • prop tab tab: auto property
  • class tab tab: class
  • cw: Console.WriteLine();
  • ctrl . :implement method
  • ctrl k s: select and wrap a sectio in class...
Visual Studio
  • Tools.Options
    • To open the options window
    • Alt + O

Open External Applications Thorugh Visual Studio
  • Click here to find out how to open external programs (for instant, SQL Server Management Studio) from Visual studio
Visual Studio Themes

These are some good links to sources of nice themes for visual studio text editors:


http://studiostyl.es/schemes
http://www.hanselman.com/blog/VisualStudioProgrammerThemesGallery.aspx

Use Windows Faster with Less Mouse Movement and Clicks


Using shortcut keys can reduce the use of mouse and increase the speed and efficiency of work.


Opening Applications

Step 1: Create a shortcut for the application (if one doesn't exist) by right-clicking on the program file and choosing the Create Shortcut option
Step 2: Right-click the shortcut and click Properties.
Step 3: Under Shortcut tab, enter the your shortcut in the Shortcut Key box and click applyAll shortcut keys to open an application will follow the combination "CTRL + ALT+your choice of key". 

Operating Application Windows
  • Minimize all the windows: Windows Key + M or use show desktop (Windows Key + D). The shortcut for show desktop is better as pressing it again will show the last active window.
  • Minimize the active window, press alt + spacebar and then press N.
  • Maximize the active window: alt + spacebar and then X.
  • Close an active window: alt + Spacebar and then C
General
  • Copy: Ctrl + C
  • Past: Ctrl + V
  • Cut: Ctrl + X
  • Print: Ctrl + P
  • Save: Ctrl + S
Security
  • Lock the computer: Windows Key + L
Application Specific Shortcuts


Friday, December 21, 2012

Using SignalR in ASP.Net MVC


I assume that you already know what SignalR is and this post is only a step by step guide to start using SignalR in an ASP.Net MVC application. Our  working environment will be:

Visual Studio(VS) 2010
ASP.Net MVC 4
SignalR 1.0
  
Create an ASP.Net MVC Solution

Create a new ASP.Net MVC 4 solution: Open VS and select “File>New>Project” and select “ASP.Net MVC 4 Web Application”. Name the application as “AspDotNetMvc.Integrate.SignalR” and click OK. On the next screen select “Empty” template and click OK. Now, VS will create the following project hierarchy as follows:



Under “Controllers”, create a new controller as follow:

using System.Web.Mvc;

namespace AspDotNetMvc.Integrate.SignalR.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

    }
}

Then, under “Views” create a view for our HomeController’s Index action as follow (Here, I created the view without a layout page and with the default Razor engine:

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <div>
        "Hello SignalR"
    </div>
</body>
</html>

Now, run the project and we’ll see the browser with the text “Hello World”. Now our solution will be like below:



Install SignalR

Now, we need to get SignalR from NuGet. For this, go to “Tools>Library Package Manager>Package Manager Console” and type the following and press enter:

Install-Package Microsoft.AspNet.SignalR –pre

NuGet will install SignalR in our solution and the structure will look like below:



Notice that NuGet has added 2 new javascript files. In our folder structure, we can see a new folder called “packages”


And, under Packages, we can see all the dll’s that NuGet downloaded for us:


Here are the references that NuGet added for the needed DLL’s in our project.


Using SignalR: Server Side

Let’s use SignalR to create a tweet application where users can submit a tweet and then it will be broadcasted to all the connected users.  Create a folder called “Hubs” under root, and then create a class in that folder called “Tweet”.

using Microsoft.AspNet.SignalR.Hubs;

namespace AspDotNetMvc.Integrate.SignalR.Hubs
{
    public class Tweet:Hub
    {
        public void SendTweet(string tweetText)
        {
            Clients.All.addTweet(tweetText);
        }
    }
}

This class is called a hub and it derived from the SignalR’s Hub base class. The clients will send new tweets to the SendTweet method in our tweet hub and then it will broadcast it to all the connected clients by calling the “addTweet” javascript method.

Now, add the line “RouteTable.Routes.MapHubs();”  in the “Aplication_Start” method in the Global.asax file. This method will create the mapping to the dynamically created javascript file “~/signalr/hubs” that is discussed in the client side section below.

public class MvcApplication : HttpApplication
{
protected void Application_Start()
{
RouteTable.Routes.MapHubs();
AreaRegistration.RegisterAllAreas();

WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
}

That’s all we have to do on the server side.

Using SignalR: Client Side

To set up the client side, add the following scripts in the html head of the Index view,:

<script src="~/Scripts/jquery-1.6.4.min.js" type="text/javascript"> </script>
<script src="~/Scripts/jquery.signalR-1.0.0-rc1.min.js" type="text/javascript"> </script>
<script type="text/javascript" src="~/signalr/hubs"> </script>

Here, first we add JQuery as SignalR needs it, then we add the javascript for SignalR. Next line with the src attribute “~/signalr/hubs” points to a dynamically created javascrip file on the server by SignalR. Below is our current structure of the solution and you can see that there is no folder at root called “SignalR” and, thus, make sure that we don’t create any folder by the name “SignalR” at the root.



Now, create the user interface for our tweets. Add a textbox and a button to send tweets to the server and a list to add new tweets sent by the server:

<div>    
            <input type="text" id="msg" />
            <input type="button" id="broadcast" value="Send Tweet" />
            <ul id="messages"></ul>
        </div>

Next step is to wire up the client with the server tweet hub. For this, add the following script at the end of the head:

<script type="text/javascript">
$(function() {
           var tweetProxy = $.connection.tweet;

           tweetProxy.client.addTweet = function (message)
           {
                 $('#tweet-list').append('<li>' + message + '</li>');
           };

           $.connection.hub.start().done(
                 function () {
                     $("#send-tweet").click(
                          function() {
                          tweetProxy.server.sendTweet($('#tweet').val());
                      });
                 });
});
</script>

Here, we first create a proxy to talk with the server with the line “$.connection.tweet”. In the next line, we have the “addTweet” javascript function that the server will use to call the browser. In this method, we will simply add the new tweets sent by the server to our tweet list that we created on the html body. The last line, we start the proxy and bind the “Send Tweet” buttons’ click event to send the value in the text box to our tweet hub.  Now, our Index view should look like below with the newly added code highlighted in yellow:

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Index</title>
        <script src="~/Scripts/jquery-1.6.4.min.js" type="text/javascript"> </script>
<script src="~/Scripts/jquery.signalR-1.0.0-rc1.min.js" type="text/javascript"> </script>
        <script type="text/javascript" src="~/signalr/hubs"> </script>
        <script type="text/javascript">
$(function() {
           var tweetProxy = $.connection.tweet;

           tweetProxy.client.addTweet = function (message)
           {
                 $('#tweet-list').append('<li>' + message + '</li>');
           };

           $.connection.hub.start().done(
                 function () {
                     $("#send-tweet").click(
                          function() {
                          tweetProxy.server.sendTweet($('#tweet').val());
                      });
                 });
});
        </script>
    </head>
    <body>
       
        <div>
            "Hello SignalR"
        </div>
       
        <div>    
            <input type="text" id="msg" />
            <input type="button" id="broadcast" value="Send Tweet" />
            <ul id="messages"></ul>
        </div>
    </body>
</html>

That’s all we need to do, now, let’s see our efforts in action. Run the project and open two separate browsers. In each browser, navigate to the local site:


On the left browser, type “Tweet: Left Browser” and press “Send Tweet” and the message will appear in both browsers:


On the right browser, type “Tweet: Right Browser” and press “Send Tweet” and the message will appear in both browsers:

That’s it. You can find this project on GitHub: https://github.com/sujeewa/AspDotNetMvc.Integrate.SignalR.git

Wednesday, December 5, 2012

Good Third Party Libraries

This is a collection of third party libraries that I came across and used in my projects.

Testing


Nunit [Open Source]: Unit test framework
Xinha [Open Source] : Xinha (pronounced like Xena, the Warrior Princess) is a powerful WYSIWYG HTML editor component that works in all current browsers. Also, Xenha has a very good community support and an extensive free plugins.



WatiN [Open Source]: Web user interface automation library.

Web


CLEditor [Open Source]: Not as powerful as Xinha but good enough for basic work. Also, I couldn't find a good image manager plugin for this.

jQuery Masonry [Open Source]: Masonry is a dynamic grid layout plugin for jQuery. Think of it as the flip-side of CSS floats. Whereas floating arranges elements horizontally then vertically, Masonry arranges elements vertically, positioning each element in the next open spot in the grid. The result minimizes vertical gaps between elements of varying height, just like a mason fitting stones in a wall.

MS Office Ribbon ToolbarOffice 2010 Ribbon toolbar that can be used in any website. It is written in HTML, CSS, and JS. Try a demo at http://okgodoit.com/ribbon/

Saturday, December 1, 2012

Good Links to Resources on Software Development

Online research is a regular activity that all software developers perform during day to day development. Sometimes, it takes some time and effort to find a good resource that explains the subject matter well and in a simpler understandable form. Below is a listing of good, in my opinion, resources that I came across during my day to day life as a software engineer. I continually update this post with new resources and also refer it daily to quickly find past resources without having to use a search engine each time. I thought to make this list as a blog post as it might save some time someone else too.

Web
Architecture
C#
Data Layer
Deployment:
Visual Studio:
Testing

Wednesday, October 24, 2012

Can't Delete File/Folder: "The file name you specified is not valid or too long"

Once I got this error message "The file name you specified is not valid or too long" when I tried to delete a folder.  The reason was that this folder has content with very deep folder structure. I googled and tried many methods mentioned by various users without any use. Finally, I found a very smart and simple solution by an anonymous user at "http://www.tomshardware.com/forum/198314-46-deleting-file-path-long". Below is the resolution as  stated by that user:

"One simple method I've used in the past to manage folder trees longer than 
MAX_PATH is to break the trees into chunks. So.. 
Traverse the directory as deep as you can within Explorer or the command 
shell. Then move all the contents below it to the root of the drive (or a 
folder under the root) so you now have a second directory tree. If the new 
tree is still greater than MAX_PATH, repeat until you get a manageable tree. 
What you do with the multiple directory trees is your business, but at least 
they're manageable"

So, basically, I cut and paste the directory structure to the driver root, and then, I was able to delete it.

Monday, August 20, 2012

Windows Error: "System could not allocate the required space in a Registry log"

I recently had this issue on my dad's Acer laptop with Windows XP: "System could not allocate the required space in a Registry log". After googling, I found the fix: "Delete unneeded files from the system partition and then retry the operation." But, there's was an issue: I get the error even before getting on to the login screen. So, I couldn't delete any files and free up any space to get the computer started. 

The next fix I thought was to try the safe mode to get into the computer, so that I could delete some files. Unfortunately, it didn't work either as I got the same error before getting into the files system.

Finally, I removed the hard drive, put it on to an external hard drive enclosure, and plugged into another computer. Then deleted about 500 MB of files and plugged it back into the Acer. The computer started fine without any errors.

Hope this would help someone.