Jack @ ASP.NET

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries Tagged ‘nbsp’

Visual Studio 2010 Pro Power Tools, It Is Free!

A set of extensions to Visual Studio Professional (and above) which improves developer productivity.

  • Searchable Add Reference Dialog
    The new Add Reference dialog makes it faster and easier for you to find the reference that you are looking for and add it to your VB, C# or F# project.  From the Solution Explorer, simply right click on the References node, select the Add Reference command to see the updated Add Reference Dialog. 
  • Highlight Current Line
    As the resolution of monitors increases, it’s becoming more difficult to find the caret in the code editor.  The highlight current line extension makes it easy to find the caret by highlighting the line that the caret is on in the editor.  You can even configure the default colour by changing the setting for “Current Line (Extension)” and “Current Line Inactive (Extension)” in Tools Options Fonts & Colors. 
  • HTML Copy
    This extension provides support for the HTML Clipboard format when copying code from the editor.  This means that you’ll no longer have to go fix up the formatting of your code when you paste it into a TFS bug form or any other HTML based control. 
  • Triple Click
    It’s never been easier to select a line of code from the mouse by simple triple-clicking anywhere on the line. 
  • Fix Mixed Tabs
    Some developers prefer tabs, others prefer spaces, and nobody likes mixing tabs & spaces.  This extension promotes developer harmony by warning as they are open or save a file that has a mixture of tabs & spaces.  The information bar also provides an easy way to fix the file to suit your preference. 
  • Ctrl + Click Go To Definition
    This extension gives the editor a web browser by adding clickable hyperlinks to symbols in your code as you hold down the Ctrl key.
  • Colorized Parameter Help
    This extension improves consistency with the editor by applying syntax highlighting to the contents of the Parameter Help window for C# &VB. 
  • Move Line Up/Down Commands
    This extension maps the Alt+Up Arrow & Alt+Down Arrow keys such that they will move the current line of code or the selected lines up and down through the editor. 
  • Column Guides
    Since Visual Studio 2002, there has been a not so secret registry key which allowed user to draw a vertical line in the code editor.  This is very useful to remind developers that their full line of code or comments may not fit one a single screen. Thanks to this extension this feature has returned with UI configure it.  Simply place the cursor at the appropriate column and select Add Guideline from the context menu

Building the Http Module with Logging Application Block

Building the Http Module

In order to build an Http module we only need to implement
the IHttpModule interface. The following is a simple
LoggingHttpModule which log details when a web request start
and when web request end:

using System;
using System.Web;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging;
 
namespace HttpModules
{
  public class LoggingHttpModule : IHttpModule
  {
    #region Members
 
    private LogWriter _writer;
 
    #endregion
 
    #region IHttpModule Members
 
    public void Dispose()
    {
      if (_writer != null)
      {
        _writer.Dispose();
      }
    }
 
    public void Init(HttpApplication context)
    {
      CreateLogWriter();
      context.BeginRequest += new EventHandler(context_BeginRequest);
      context.EndRequest += new EventHandler(context_EndRequest);
    }
 
    private void CreateLogWriter()
    {
      ConfigureEnterpriseLibraryContainer();
      _writer = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();
    }
 
    private void ConfigureEnterpriseLibraryContainer()
    {
      var builder = new ConfigurationSourceBuilder();
 
      builder.ConfigureInstrumentation().EnableLogging();
      builder.ConfigureLogging().WithOptions
             .LogToCategoryNamed("General")
               .WithOptions
               .SetAsDefaultCategory()
               .SendTo
               .FlatFile("Log File")
               .FormatWith(new FormatterBuilder()
               .TextFormatterNamed("Textformatter"))
                   .ToFile("file.log");
 
      var configSource = new DictionaryConfigurationSource();
      builder.UpdateConfigurationWithReplace(configSource);
      EnterpriseLibraryContainer.Current =
        EnterpriseLibraryContainer.CreateDefaultContainer(configSource);
    }
 
    void context_BeginRequest(object sender, EventArgs e)
    {
      _writer.Write(new LogEntry
      {
        Message = "BeginRequest"
      });
    }
 
    void context_EndRequest(object sender, EventArgs e)
    {
      _writer.Write(new LogEntry
      {
        Message = "EndRequest"
      });
    }
 
    #endregion
  }
}

Using The Module

In order to use the module all we need to do is to add a reference
to the class library that holds the LoggingHttpModule. Then we need
to register the module in the web.config file in the httpModules 
element like:

<httpModules>
    <add name="LoggingHttpModlue" type="HttpModules.LoggingHttpModule, HttpModules"/>
</httpModules>

That is it. Now the module will be executed whenever a request
start or end.

Silverlight 4 Tools for Visual Studio 2010 and WCF RIA Services is now available for download


Silverlight Tooling Support

Visual Studio 2010 includes rich tooling support for building Silverlight and WPF applications.

It includes a WYSIWYG designer surface that enables you to easily use controls to construct UI – including the ability to take advantage of layout containers, and apply styles and resources:

image

The VS 2010 designer enables you to leverage the rich data binding support within Silverlight and WPF, and easily wire-up bindings on controls.  The Data Sources window within Silverlight projects can be used to reference POCO objects (plain old CLR objects), WCF Services, WCF RIA Services client proxies or SharePoint Lists.


Silverlight 4 Tool Enhancements

Today’s Silverlight 4 Tooling Release for VS 2010 includes a bunch of nice new features.  These include:

Support for Silverlight Out of Browser Applications and Elevated Trust Applications

You can open up a Silverlight application’s project properties window and click the “Enable Running Application Out of Browser” checkbox to enable you to install an offline, out of browser, version of your Silverlight 4 application.  You can then customize a number of “out of browser” settings of your application within Visual Studio:

image

Notice above how you can now indicate that you want to run with elevated trust, with hardware graphics acceleration, as well as customize things like the Window style of the application (allowing you to build a nice polished window style for consumer applications).

Support for Implicit Styles and “Go to Value Definition” Support:

Silverlight 4 now allows you to define “implicit styles” for your applications.  This allows you to style controls by type (for example: have a default look for all buttons) and avoid you having to explicitly reference styles from each control. 

In addition to honoring implicit styles on the designer-surface, VS 2010 also now allows you to right click on any control (or on one of it properties) and choose the “Go to Value Definition…” context menu to jump to the XAML where the style is defined, and from there you can easily navigate onward to any referenced resources.  This makes it much easier to figure out questions like “why is my button red?”:

Box Selection with Visual Studio 2010

Box selection is a feature that has been in Visual Studio for awhile (although not many people knew about it).  It allows you to select a rectangular region of text within the code editor by holding down the Alt key while selecting the text region with the mouse.  With VS 2008 you could then copy or delete the selected text.

VS 2010 now enables several more capabilities with box selection including:

  • Text Insertion: Typing with box selection now allows you to insert new text into every selected line
  • Paste/Replace: You can now paste the contents of one box selection into another and have the content flow correctly
  • Zero-Length Boxes: You can now make a vertical selection zero characters wide to create a multi-line insert point for new or copied text

These capabilities can be very useful in a variety of scenarios.  Some example scenarios: change access modifiers (private->public), adding comments to multiple lines, setting fields, or grouping multiple statements together.

A cool Visual Studio 2010 feature

Upgrade or Uninstall of Office 2007 might cause VS 2008 Web designer to hang

On machines with a 64-bit OS, uninstall of Office 2007 will break the VS 2008 web designer.  You will find that the VS designer won’t be able to load, and any attempts to switch to Design View will hang the product.  Note that 32-bit machines are not affected and neither are other VS releases.

The root cause of this problem is that Office 2007 and the VS 2008 web designer both share a component, 32-bit MSXML5.  When Office 2007 uninstalls or gets upgraded, MSXML5 is removed yet Visual Studio still needs it.

If you are affected by this issue, there are workarounds where you may not have to completely reinstall Visual Studio.  However, the steps are different depending on how Office 2007 got removed (uninstall vs. upgrade to Office 2010) and also if you have VWD Express or a full product.

Workaround if you manually uninstalled Office 2007 (i.e. Add/Remove Programs) AND have a non-Express version of VS 2008:

  1. Go to Add/Remove Programs
  2. Uninstall “Microsoft Visual Studio Web Authoring Component
  3. Reinstall “Microsoft Visual Studio Web Authoring Component” -
    • You will need the VS install media: the product DVD or mount an ISO image
    • Go to WCU\WebDesignerCore folder and run WebDesignerCore.exe.
    • Setup does not have UI, so please simply wait about 5 minutes or watch msiexec activity in the Task Manager.
    • Verify that Microsoft Visual Studio Web Authoring Component reappears in Add/Remove Programs.
    • WebDesignerCore.exe installs RTM version.
  4. If your VS 2008 has been updated to SP1, you have to reinstall SP1 to update the Web Authoring Component you installed in Step 3.

Workaround if you manually uninstalled Office 2007 (i.e. Add/Remove Programs) AND have Visual Web Developer Express 2008:

  1. Go to Add/Remove Programs  
  2. Uninstall “Microsoft Visual Studio Web Authoring Component
  3. Reinstall Visual Web Developer Express 2008/SP1
    (SP1 for Express is not a separate install thus the need to reinstall the entire product)

Visual Stusio 2010: Quickly Closing Documents

Before (VS 2008)

image

After (VS 2010)

image

The majority of feedback around this change was positive, but, as with most UI changes, there has been a vocal group that preferred the older placement.  When asked what they liked about the old placement, 99% of the time the response was, “I liked the ability to quickly close tabs by repeatedly clicking on the ‘X’ without moving my mouse.” 

I’ll admit it: I used that feature quite a bit to quickly close tabs.  That is, until I found out that there are better and more efficient ways to clean up the Tab Well.  Once I discovered these, I never looked back.  So, for this “Tips and Tricks” article, I wanted to share some of those ways to quickly close documents. 

 

image#1: Window->Close All Documents

Under the Window menu is a handy command: Close All Documents.  Clicking this will prompt you to save your work and will then close all documents that are currently open.  Yes, this does affect more than just the documents in the Tab Well – floating documents are also closed.  If you don’t want to take your hands off the keyboard, simply press Alt+ W, L, to invoke the command (You can also assign it a keyboard shortcut under Tools->Options->Environment->Keyboard).

 #2: Ctrl+F4

Another handy shortcut is Ctrl+F4 which, on most machines, is bound to the command Window.CloseDocumentWindow.  Pressing this keyboard combination will close the current document window that has focus.  Therefore, if you want to quickly get rid of a number of items in your tab well, just keep pressing Ctrl+F4 and eventually they’ll be gone. 

#3: Right-Click->Close All But This

If you want to close all but one open file, simply right-click on the tab and select Close All But This.  This will close all open documents (floating included) except the tab you’ve right-clicked on. 

#4: Middle Click

For those that prefer to use the mouse instead of the keyboard, there’s still a quick way to close tabs: the middle click.  This shortcut actually works in a number of other applicatios as well.  Simply place your mouse on the tab well and middle click to close the tab.  You can keep your mouse in the first spot and click away.