March 21st Links: ASP.NET, ASP.NET MVC, AJAX, Visual Studio, Silverlight

Here is the latest in my link-listing series.

If you haven’t already, check out this month’s "Find a Hoster” page on the www.asp.net website to learn about great (and very inexpensive) ASP.NET hosting offers. 

[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

ASP.NET

  • URL Routing in ASP.NET 4: Scott Mitchell has a nice article that talks about the new URL routing features coming to Web Forms applications with ASP.NET 4.  Also check out my previous blog post on this topic.

  • Control of Web Control ClientID Values in ASP.NET 4: Scott Mitchell has a nice article that describes how it is now easy to control the client “id” value emitted by server controls with ASP.NET 4.

  • Web Deployment Made Awesome: Very nice MIX10 talk by Scott Hanselman on the new web deployment features coming with VS 2010, MSDeploy, and .NET 4.  Makes deploying web applications much, much easier.

  • ASP.NET 4’s Browser Capabilities Support: Nice blog post by Stephen Walther that talks about the new browser definition capabilities support coming with ASP.NET 4.

  • Integrating Twitter into an ASP.NET Website: Nice article by Scott Mitchell that demonstrates how to call and integrate Twitter from within your ASP.NET applications.

  • Improving CSS with .LESS: Nice article by Scott Mitchell that describes how to optimize CSS using .LESS – a free, open source library.

ASP.NET MVC

  • Upgrading ASP.NET MVC 1 applications to ASP.NET MVC 2: Eilon Lipton from the ASP.NET team has a nice post that describes how to easily upgrade your ASP.NET MVC 1 applications to ASP.NET MVC 2.  He has an automated tool that makes this easy. Note that automated MVC upgrade support is also built-into VS 2010.  Use the tool in this blog post for updating existing MVC projects using VS 2008.

  • Advanced ASP.NET MVC 2: Nice video talk by Brad Wilson of the ASP.NET MVC team.  In it he describes some of the more advanced features in ASP.NET MVC 2 and how to maximize your productivity with them.

  • Dynamic Select Lists with ASP.NET MVC and jQuery: Michael Ceranski has a nice blog post that describes how to dynamically populate dropdownlists on the client using AJAX.

AJAX

  • Microsoft AJAX Minifier: We recently shipped an updated minifier utility that allows you to shrink/minify both JavaScript and CSS files – which can improve the performance of your web applications.  You can run this either manually as a command-line tool or now automatically integrate it using a Visual Studio build task.  You can download it for free here.

Visual Studio

  • Dependency Graphics: Jason Zander (who runs the VS team) has a nice blog post that covers the new dependency graph support within VS 2010.  This makes it easier to visualize the dependencies within your application.  Also check out this video here.

  • Layer Validation: Jason Zander has a nice blog post that talks about the new layer validation features in VS 2010.  This enables you to enforce cleaner layering within your projects and solutions. 

  • VS 2010 Profiler Blog: The VS 2010 Profiler Team has their own blog and on it you can find a bunch of nice posts from the last few months that talk about a lot of the new features coming with VS 2010’s Profiler support.  Some really nice features coming.

Silverlight

  • Silverlight 4 Training Course: Nice free set of training courses from Microsoft that can help bring you up to speed on all of the new Silverlight 4 features and how to build applications with them.  Updated and current with the recently released Silverlight 4 RC build and tools.

  • Path Based Layout – Part 1 and Part 2: Christian Schormann has a nice blog post about a really cool new feature in Expression Blend 4 and Silverlight 4 called Path Layout. Also check out Andy Beaulieu’s blog post on this.

Hope this helps,

Scott

Getting time from datetime in TSQL

As everyone already knows, to extract the time from a datetime (pre SQL 2008), you have to use the convert function

HOWEVER: beware of using the smalldatetime type, as it trucates the seconds from the value convert returns

Run the following code:

declare @thissmalldatetime smalldatetime,@thisdatetime datetime
select @thissmalldatetime=getdate(),@thisdatetime=getdate()
select convert(nvarchar(8),@thissmalldatetime,14) as [Small Date Time],convert(nvarchar(8),@thisdatetime,14) as [Date Time]
waitfor delay '00:00:01'
select @thissmalldatetime=getdate(),@thisdatetime=getdate()
select convert(nvarchar(8),@thissmalldatetime,14) as [Small Date Time],convert(nvarchar(8),@thisdatetime,14) as [Date Time]

Small Date Time Date Time
--------------- ---------
13:13:00        13:12:40

(1 row(s) affected)

Small Date Time Date Time
--------------- ---------
13:13:00        13:12:41

(1 row(s) affected)

Pluralsight at DevWeek 2010

Pluralsight at DevWeek 2010

Another great year at DevWeek 2010 – can’t believe the show is already coming to a close. DevWeek is always a great event, organized by Nick Payne and team of Bearpark Publishing. Pluralsight had quite the gang out this year including Fritz Onion, Keith Brown, Jon Fancey, Ian Griffiths, Scott Deadrick, Meagon Marshall, and of course me.

DevWeek-Banner Pluralsight-Crew-Booth

Our technical team delivered a long list of breakout sessions on pre/post-conference workshops, which you can read about on Meagon’s blog. I personally did a workshop plus 6 breakout sessions on primarily Azure, Cloud Computing, and REST. I really enjoyed my sessions this year, mostly because the attendees were so engaged and full of questions, especially the ones on REST yesterday. My favorite talk this year was the one on REST + XHTML + MVC.

Demos: for those of you who attended my sessions, you can download my DevWeek 2010 demos.

IMG_1787 Aaron-session-1

On Monday night Nick hosted a speaker’s dinner at a very peculiar and popular London restaurant known for their unique and creative fare (can’t remember the name). Check out the starter bone marrow on toast and look at Jeff Richter ready to dig into his main course. 😉

IMG_1776 IMG_1774 IMG_1783

It was a very unique and entertaining experience to say the least – thanks Nick!  We also enjoyed the London fare you might expect (Indian and Thai) over some very nice Pluralsight dinners.

Pluralsight-Dinner-Indian  IMG_1793

We received a lot of great feedback during the event from attendees all over the UK using Pluralsight On-Demand! Every DevWeek attendee received a free 1-week pass to Pluralsight On-Demand! (look for the white plastic card in your attendee bag) and those who attended my Azure precon received another special gift – you know what to do – make sure you email Meagon if you didn’t catch her at the event.

Our secret? Check out Fritz here playing the siren song of Pluralsight On-Demand! on classical guitar once you hear the tunes, you just can’t help yourself, so beware.

Fritz-Playing-Booth

More photos?  Check out the Pluralsight .NET Training Facebook album for DevWeek 2010. Thanks again to Nick, the crew, and all the attendees for another great year!

Building a Windows Phone 7 Twitter Application using Silverlight

Building a Windows Phone 7 Twitter Application using Silverlight

On Monday I had the opportunity to present the MIX 2010 Day 1 Keynote in Las Vegas (you can watch a video of it here).  In the keynote I announced the release of the Silverlight 4 Release Candidate (we’ll ship the final release of it next month) and the VS 2010 RC tools for Silverlight 4.  I also had the chance to talk for the first time about how Silverlight and XNA can now be used to build Windows Phone 7 applications.

During my talk I did two quick Windows Phone 7 coding demos using Silverlight – a quick “Hello World” application and a “Twitter” data-snacking application.  Both applications were easy to build and only took a few minutes to create on stage.  Below are the steps you can follow yourself to build them on your own machines as well.

[Note: In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

Building a “Hello World” Windows Phone 7 Application

First make sure you’ve installed the Windows Phone Developer Tools CTP – this includes the Visual Studio 2010 Express for Windows Phone development tool (which will be free forever and is the only thing you need to develop and build Windows Phone 7 applications) as well as an add-on to the VS 2010 RC that enables phone development within the full VS 2010 as well.

After you’ve downloaded and installed the Windows Phone Developer Tools CTP, launch the Visual Studio 2010 Express for Windows Phone that it installs or launch the VS 2010 RC (if you have it already installed), and then choose “File”->”New Project.”  Here, you’ll find the usual list of project template types along with a new category: “Silverlight for Windows Phone”. The first CTP offers two application project templates. The first is the “Windows Phone Application” template – this is what we’ll use for this example. The second is the “Windows Phone List Application” template – which provides the basic layout for a master%u2011details phone application:

image

After creating a new project, you’ll get a view of the design surface and markup. Notice that the design surface shows the phone UI, letting you easily see how your application will look while you develop. For those familiar with Visual Studio, you’ll also find the familiar ToolBox, Solution Explorer and Properties pane.

image

For our HelloWorld application, we’ll start out by adding a TextBox and a Button from the Toolbox. Notice that you get the same design experience as you do for Silverlight on the web or desktop. You can easily resize, position and align your controls on the design surface. Changing properties is easy with the Properties pane. We’ll change the name of the TextBox that we added to username and change the page title text to “Hello world.”

image

We’ll then write some code by double%u2011clicking on the button and create an event handler in the code-behind file (MainPage.xaml.cs).

image

We’ll start out by changing the title text of the application. The project template included this title as a TextBlock with the name textBlockListTitle (note that the current name incorrectly includes the word “list”; that will be fixed for the final release.)  As we write code against it we get intellisense showing the members available.  Below we’ll set the Text property of the title TextBlock to “Hello “ + the Text property of the TextBox username:

image

We now have all the code necessary for a Hello World application.  We have two choices when it comes to deploying and running the application. We can either deploy to an actual device itself or use the built%u2011in phone emulator:

image

Because the phone emulator is actually the phone operating system running in a virtual machine, we’ll get the same experience developing in the emulator as on the device. For this sample, we’ll just press F5 to start the application with debugging using the emulator.  Once the phone operating system loads, the emulator will run the new “Hello world” application exactly as it would on the device:

image

Notice that we can change several settings of the emulator experience with the emulator toolbar – which is a floating toolbar on the top right.  This includes the ability to re-size/zoom the emulator and two rotate buttons.  Zoom lets us zoom into even the smallest detail of the application:

image

The orientation buttons allow us easily see what the application looks like in landscape mode (orientation change support is just built into the default template):

image

Note that the emulator can be reused across F5 debug sessions – that means that we don’t have to start the emulator for every deployment. We’ve added a dialog that will help you from accidentally shutting down the emulator if you want to reuse it.  Launching an application on an already running emulator should only take ~3 seconds to deploy and run.

Within our Hello World application we’ll click the “username” textbox to give it focus.  This will cause the software input panel (SIP) to open up automatically.  We can either type a message or – since we are using the emulator – just type in text.  Note that the emulator works with Windows 7 multi-touch so, if you have a touchscreen, you can see how interaction will feel on a device just by pressing the screen.

image

We’ll enter “MIX 10” in the textbox and then click the button – this will cause the title to update to be “Hello MIX 10”:

image

We provide the same Visual Studio experience when developing for the phone as other .NET applications. This means that we can set a breakpoint within the button event handler, press the button again and have it break within the debugger:

image

Building a “Twitter” Windows Phone 7 Application using Silverlight

Rather than just stop with “Hello World” let’s keep going and evolve it to be a basic Twitter client application.

We’ll return to the design surface and add a ListBox, using the snaplines within the designer to fit it to the device screen and make the best use of phone screen real estate.  We’ll also rename the Button “Lookup”:

image

We’ll then return to the Button event handler in Main.xaml.cs, and remove the original “Hello World” line of code and take advantage of the WebClient networking class to asynchronously download a Twitter feed. This takes three lines of code in total: (1) declaring and creating the WebClient, (2) attaching an event handler and then (3) calling the asynchronous DownloadStringAsync method.

In the DownloadStringAsync call, we’ll pass a Twitter Uri plus a query string which pulls the text from the “username” TextBox. This feed will pull down the respective user’s most frequent posts in an XML format. When the call completes, the DownloadStringCompleted event is fired and our generated event handler twitter_DownloadStringCompleted will be called:

The result returned from the Twitter call will come back in an XML based format.  To parse this we’ll use LINQ to XML. LINQ to XML lets us create simple queries for accessing data in an xml feed. To use this library, we’ll first need to add a reference to the assembly (right click on the References folder in the solution explorer and choose “Add Reference):

image

We’ll then add a “using System.Xml.Linq” namespace reference at the top of the code-behind file at the top of Main.xaml.cs file:

image

We’ll then add a simple helper class called TwitterItem to our project. TwitterItem has three string members – UserName, Message and ImageSource:

image

We’ll then implement the twitter_DownloadStringCompleted event handler and use LINQ to XML to parse the returned XML string from Twitter.  What the query is doing is pulling out the three key pieces of information for each Twitter post from the username we passed as the query string. These are the ImageSource for their profile image, the Message of their tweet and their UserName. For each Tweet in the XML, we are creating a new TwitterItem in the IEnumerable<XElement> returned by the Linq query. 

We then assign the generated TwitterItem sequence to the ListBox’s ItemsSource property:

image

We’ll then do one more step to complete the application. In the Main.xaml file, we’ll add an ItemTemplate to the ListBox. For the demo, I used a simple template that uses databinding to show the user’s profile image, their tweet and their username.

<ListBox Height="521" HorizonalAlignment="Left" Margin="0,131,0,0" Name="listBox1" VerticalAlignment="Top" Width="476">
    <ListBox.ItemTemplate>
        <DataTemplate>
           <StackPanel Orientation="Horizontal" Height="132">
              <Image Source="{Binding ImageSource}" Height="73" Width="73" VerticalAlignment="Top" Margin="0,10,8,0"/>
              <StackPanel Width="370">
                 <TextBlock Text="{Binding UserName}" Foreground="#FFC8AB14" FontSize="28" />
                 <TextBlock Text="{Binding Message}" TextWrapping="Wrap" FontSize="24" />
              </StackPanel>
           </StackPanel>
        </DataTemplate>
     </ListBox.ItemTemplate>
</ListBox>

Now, pressing F5 again, we are able to reuse the emulator and re-run the application. Once the application has launched, we can type in a Twitter username and press the  Button to see the results. Try my Twitter user name (scottgu) and you’ll get back a result of TwitterItems in the Listbox:

image

Try using the mouse (or if you have a touchscreen device your finger) to scroll the items in the Listbox – you should find that they move very fast within the emulator.  This is because the emulator is hardware accelerated – and so gives you the same fast performance that you get on the actual phone hardware.

Summary

Silverlight and the VS 2010 Tools for Windows Phone (and the corresponding Expression Blend Tools for Windows Phone) make building Windows Phone applications both really easy and fun. 

At MIX this week a number of great partners (including Netflix, FourSquare, Seesmic, Shazaam, Major League Soccer, Graphic.ly, Associated Press, Jackson Fish and more) showed off some killer application prototypes they’ve built over the last few weeks.  You can watch my full day 1 keynote to see them in action. I think they start to show some of the promise and potential of using Silverlight with Windows Phone 7.  I’ll be doing more blog posts in the weeks and months ahead that cover that more.

Hope this helps,

Scott

CODit Host Integration Server presentation Stockholm

Yesterday Peter Borremans and Sam Vanhoutte were guest speakers at the BizTalk User Group Sweden in Stockholm.
We presented an overview of Microsoft Host Integration Server, a product that allows you to integrate with resources on IBM Mainframes and Midrange systems. The presentation went smoothly and all the demo’s worked 🙂
It was a great pleasure to present this product to the many interested people who attended the presentation.

The slide deck of our presentation can be found here. (change the file extention to ‘pptx’ after downloading)
When the presentation is available online, we will post a link on this blog.

 Peter Borremans

Host Integration Server Smart Multihoming causing delays to connect to a HIS server

Host Integration Server is by default configured to use ‘smart multihoming’. When using smart multihoming, the Host Integration Server (HIS) will send all his available IP addresses to the clients. The SNA client will use the address from the list with addresses received from the server that is closest to its own subnet or IP address.

In some scenarios smart multihoming can cause some problems. What if one of the IP addresses received from the HIS server is not reachable (e.g. an IP address that is used to link to a separate network)? In that case the client will try to connect to one of the other address received from the HIS server. This only happens after a delay (default 45 seconds). After the delay the client will connect to the IP address that connects successfully.

This delay when connecting to the server is not a desired behavior.

How do we fix this?

On the client we can disable smart multihoming. To do this, make sure that this registery key ‘ReadjustMultihomedAddresses’ is set to ‘NO’. If the key does not exist, create it. The location of this registry key should be: ‘HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Snabase\Parameters\SnaTcp’.

If smart multihoming is disabled on our client, the new behavior is as follows: the client will try to connect to a server IP address in the order as the client received them from the server. Again, this causes problems… What if the IP address that is not reachable appears first in the list? We will again see a long delay when connecting to the server. Luckely we can fix this!

Host integration server uses the network bindings to determine in what order to present its IP addresses to the client. You can find the network binding  on the ‘Network Connections’ sceen, ‘Advanced’ menu option, ‘Advanced Settings…’, then ‘Adapters and Bindings’ tab. On that tab page, every network connection is listed and we are able to change the order in which they appear. Adapt the order to your needs (reachable IP’s first!!!). Host Integration Server will use the order specified here to send it’s IP list to the client.

Now that both steps are done (disable smart multihoming AND change the network bindings on the server), the client will no longer experience a delay when connecting to the HIS server.

 

Peter Borremans