« September 2010 | Main | November 2010 »

October 2010

PDC 2010 Day 2

Before the PDC sessions started, there was already an interesting message distributed from Mary Jo Foley from an interview with Bob Muglia: Our strategy with Silverlight has shifted.

The core messages:

Silverlight is the development platform for Windows Phone. Silverlight also has some “sweet spots” in media and line-of-business applications.

HTML is the only true cross-platform solution for everything.

So, HTML 5 gets a really big focus. Microsoft is heavily investing in this technology.

Developer trends in the area of Web development:

  • HTML Interop – across different browsers, platforms…
  • Performance
  • Websites like native applications

If you check several HTML 5 specs, Microsoft plays a major role with the standards body. Interop is an important scenario.

Today I’ve been at a session on performance. Several subsystems of IE have been completely rewritten. JavaScript is now a 1st class citizen with IE. VBScript is still supported via COM interop, but JavaScript is directly integrated and thus marshalling becomes a lot faster. There was a good idea on the JavaScript engine. Having an interpreter has the advantage on the startup, a JavaScript compiler is better on the long-run if a script executes more than once. IE9 has both that run in parallel (usually there’s at least a dual-core CPU in the client systems), and these engines communicate to define who’s taking over.

Microsoft can differentiate by giving a great Windows 7 integration. Similar to features that have been added to WPF with .NET 4, Web applications can be pinned to the taskbar, Jumplists can be defined, and also custom actions such as play/pause buttons can be added to the preview.

IE9 preview 6 can be downloaded from http://www.ietestdrive.com.

What about Silverlight and WPF with such a big focus on HTML 5 and JavaScript? Of course, Silverlight plays a big role with Windows Phone 7. But there’s more! Looking at the sample applications from HTML 5 – these are in the areas of games, graphics demos, fancy animations… What about a DataGrid? Data binding? For LOB applications, HTML is by far not there what Silverlight and WPF has to offer. With Visual Studio LightSwitch a data-driven Silverlight application can be done in a matter of… WPF and Silverlight offers much more productivity compared to HTML, and I’m sure it leads several years ahead.

What other news from PDC?

Mark Russinovich dives deep into Windows Azure and has written his first WPF application:  Windows Azure Storage Explorer.

Part of Windows Azure AppFabric, Access Control Service hosts an STS in the cloud supporting WS-Federation, WS-Trust, OpenId, OAuth… what makes it easy to use FaceBook, Windows Live identifiers for authentication with cloud applications.

WCF gets enhancements with WCF Web APIs – see http://wcf.codeplex.com. First-class support for HTTP/REST

Windows Workflow gets enhancements, where the first bits are shared as well: http://wf.codeplex.com. A state machine is now available, C# expressions, versioning with persistence, enhanced workflow designer with e.g. annotations, new activities, partial trust…

For sure there’s a lot new stuff to explore, and I’m happy to have attended PDC. The next days I’ve to explore the pre-recorded sessions as well as many sessions missed as I cannot split Winking smile

Christian

CN innovation

Follow me on twitter

PDC 2010 Day 1

Last year’s PDC was not about completely new things, but progress, updates to existing technologies. This continues with this year’s PDC. There’s great progress on existing technologies.

Some highlights?

Steve Ballmer’s keynote was on Internet Explorer 9 and Windows Phone 7.

Internet Explorer 9

IE9 has a big focus on standard HTML 5, HTML 5 features with hardware acceleration.

A differentiation of this browser in contrast to the competition is in the integration with Windows 7. Where WPF 4 got improvements for an integration with the Windows 7 taskbar, the same is now possible for Web sites by using IE9 features. This integration is really simple – using metatags to define the items of the jumplist, and a few lines of JavaScript to add custom functionality such as start/stop buttons to the preview.

IE 9 platform preview 6 is available at http://www.ietestdrive.com.

Windows Phone 7

Of course Windows Phone 7 had a big focus at PDC. The phone is different – I’m already using it for a week, it is really different. Metro gives a cool UI experience.

twitter and facebook applications were shown – with great UI features.

And really cool – at least for all attendees - a WP7 LG Optimus 7 was given to every attendee (with the exception of government attendees).

Visual Studio gets a profiler to analyze WP7 applications. This looked like a great way to analyze bottlenecks.

For programming, Charles Petzold’s Windows Phone 7 book is available for download.

Windows Azure

Keynote part 2, Bob Muglia’s focus was on Windows Azure. It was interesting to see that Pixar RenderMan is running on Windows Azure. This makes it possible for smaller studios to create animation by renting CPU power for a specified time. I’m seeing Azure not only important for scale up and scale down scenarios, but also to have access from everywhere, from every device.

Windows Azure gets a lot of improvements:

  • Virtual Machine Role
  • Application Virtualization – transfer application images
  • Extra small instance – of course for a lower price
  • Remote Desktop
  • Full IIS
  • Virtual Network
  • Elevated Privileges
  • Windows Server 2008 R2 Roles
  • Multiple Administrators
  • Marketplace – DataMarket (known as Dallas)

Was the Visual Studio Team Foundation Server too much admin work to consider? Now it’s in the cloud!

Windows Azure AppFabric has been updated with enhancements and new services:

  • Access Control
  • Caching
  • Service Bus
  • Composite Applications

SQLAzure with

  • Reporting
  • Data Sync

 

C# and Visual Basic next

The major focus on the next version of C# and Visual Basic is on asynchronous programming. Based on the Task<T> defined by .NET 4 the language keywords async and await have been added. These keywords make it possible to  that make it possible to write applications asynchronously in a synchronous programming style. This is really cool! I’ll blog some examples on how this can be used soon.

The Async CTP is available for download.

And More

With just two days PDC it’s not possible to have a session on every technology, which doesn’t mean there’s no progress. With PDC also some pre-recorded sessions are available, e.g. on WPF, and information on the future of WPF is here. Enhancements that can be expected with the next version:

  • Hosting of Silverlight content
  • Better AirSpace management with native HWND
  • Binding and change notification for collections from background threads
  • Better integration with UI virtualization
  • Integration of Ribbon
  • more…

Expect more of this content to be covered in my blog.

Christian

CN innovation

Microsoft PDC 2010

This year’s PDC is different. It’s a short one (just two days), located in Redmond, available globally, includes just a few future talks and several deep dives.

The session content is now online. I’m really interested in watching the keynote from Steve Ballmer and Bob Muglia.

This year, Ray Ozzie is missing. Ray stepped down as Microsoft chief software architect just a few days before PDC. Ray focuses in the entertainment space before he retires from Microsoft. There are also some sessions in this area with PDC 2010, e.g. “Things You Need to Know Before Building XNA Games” and “Real-World Analysis and Optimization of XNA Framework Games on Windows Phone 7”.

I’m sure the keynote gives also some entertainment Smile Ray never did such entertaining sessions Winking smile

What’s part of the keynote? News about Windows Azure? News about Windows Phone 7 with an update on copy&paste support? What’s for sure, news about Silverlight. One session on Thursday at 4:30 has the title “Silverlight Session Placeholder” containing this description: “This will be a great Silverlight session, but we can’t disclose any details until after PDC keynotes. Check this abstract after PDC keynote for additional details about this session.”. I’ll attend the Silverlight futures session!

What’s more? Counting the number of sessions this gives more details.

Anders Hejlsberg will give a talk on the future on C# and VB. In summary I’ve counted 5 sessions on language topics including C++ Lambdas, F#, and LINQ.

Internet Explorer 9 and HTML 5 gets a focus with site pinning, JavaScript and IE9, and high-performance HTML 5.

Windows Phone 7 has a focus with 4 sessions as well: WP7 and Azure, WP7 and Silverlight performance, experiences from building apps, XNA and WP7.

Other topics such as memory management, Entity Framework, OData, IntelliTrace, ASP.NET… are covered as well.

However, of course…. the biggest part of the conference is on Windows Azure with at least 12 sessions covering topics such as AppFabric Services, moving major apps to the cloud, Identity & Access, Storage deep dive, Inside Azure, Workflows, and much more. I expect many news on Windows Azure at #pdc10.

I’m travelling to Redmond for PDC, but this year’s PDC is also available globally. The local events can be found here. There’s one event in Vienna in the Village Cinemas. Here you can watch the keynote, get some hotdogs, and watch the film “The Social Network” while I’m at the sessions following the keynote.

Looking forward to #pdc10.

Christian

CN innovation

LINQ Compound From with C# and Visual Basic

The last blog post was about LINQ grouping. Next I’m stepping into compound from. With a LINQ compound from query a list where the elements contain an inner list can be flattened.

Like the previous sample, I’m using the Racer type with the query. The properties Cars and Years can be used with a compound from.

public class Racer { public string FirstName { get; set; } public string LastName { get; set; } public int Wins { get; set; } public string Country { get; set; } public int Starts { get; set; } public int PolePositions { get; set; } public string[] Cars { get; set; } public int[] Years { get; set; } //...

This time the goal of the query is to find racers based on the car which is a collection by itself. With the list of F1 champions that is returned from Formula1.GetChampions(), every champion can be a champion with multiple cars. For example, Juan Manuel Fangio won the F1 world championship with Alfa Romeo, Maserati, Mercedes, and Ferrari.

Getting into the cars from racers can be done with a compound from. The first from is to iterate the racers, and the second one the cars from each racer.

string car = "Ferrari"; var q = from r in Formula1.GetChampions() from c in r.Cars where c == car select r;

Such a compound from is changed to invoke the SelectMany method. The where and select clauses are changed to invoke the Where and Select methods.

string car = "Ferrari"; var q = Formula1.GetChampions() .SelectMany(r => r.Cars, (r1, c1) => new {Racer = r1, Car = c1}) .Where(rc => rc.Car == car) .Select(rc => rc.Racer);

The SelectMany method has several overloads. With the LINQ Query statement after the compound from both the outer collection (the racers) and the inner collection (the cars) is accessed with following clauses. So the SelectMany overload must return racers and cars. This is possible with the overload IEnumerable<TResult> SelectMany<TSource, TCollection, TResult>(this IEnumerable<TSource>, Func<TSource, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>).

The first parameter this IEnumerable<TSource> defines an extension method, in the sample for IEnumerable<Racer>. This is returned from Formula1.GetChampions.

The second parameter Func<TSource, IEnumerable<TCollection>> is used to flatten the inner collection. This parameter specifies a delegate where the return type is IEnumerable<TCollection>. The source is a Racer, and the return by returning the country is IEnumerable<string>. So this parameter is resolved to Func<Racer, IEnumerable<string>>. The lambda expression receives a racer with the parameter r and returns a list of cars.

The third parameter Func<TSource, TCollection, TResult> defines what should be returned from the SelectMany method. The return of the method is IEnumerable<TResult>. With the sample, this resolves to Func<Racer, string, TResult>. The first parameter is the racer and the second parameter the car. This lambda expression returns an anonymous type that contains a Racer and a Car property.

The Where method uses the Car property of the anonymous type for filtering, and the Select method uses the Racer property to return all racers where the filter applies.

Instead of iterating the query directly next I’m defining a variable of type Func<string, IEnumerable<Racer>> to assign a lambda expression that contains the query. This lambda expression that’s referenced from the delegate can be invoked by passing a car as parameter. This way it’s easy to invoke methods such as Union or Intersect.

Func<string, IEnumerable<Racer>> racerByCar = car => from r in Formula1.GetChampions() from c in r.Cars where c == car select r; foreach (var r in racerByCar("Ferrari").Intersect(racerByCar("McLaren"))) { Console.WriteLine(r); }

The Visual Basic version of the above looks like this:

Dim racerByCar = Function(car As String) Return From r In Formula1.GetChampions() From c In r.Cars Where c = car Select r End Function For Each r In racerByCar("Ferrari").Intersect(racerByCar("McLaren")) Console.WriteLine(r) Next

If you would like to know the results of all F1 champions that have won the championship both with Ferrari and McLaren: Niki Lauda.

More LINQ posts:

More about LINQ with C# in my book Professional C# 4 with .NET 4, and with the language of your choice in my LINQ programming workshop. There’s also more about LINQ in the upcoming BASTA! On Tour in Munich.

Christian

CN innovation

Follow me on twitter

LINQ Grouping with C# and Visual Basic

Most of the times I’m doing my code samples with C# and XAML. Of course, some samples are in C++/CLI and F#. If a customer demands I’m also doing Visual Basic. This is when it comes to translate C# to Visual Basic.

In this blog post I’m showing LINQ queries with grouping.

First, let’s start with C#. As usual I’ve a list of Formula 1 world champions that are described by a simple Racer class.

public class Racer { public string FirstName { get; set; } public string LastName { get; set; } public int Wins { get; set; } public string Country { get; set; } public int Starts { get; set; } public int PolePositions { get; set; } //...

The collection I’m working on are all Formula 1 champions since 1950 that is returned from Formula1.GetChampions().

To group the list of racers based on the country to get the number of champions of each country. This is a simple group by statement as shown.

var q = from r in Formula1.GetChampions() group r by r.Country into g orderby g.Count() descending, g.Key select new { Country = g.Key, Count = g.Count() };

The group by clause gets translated from the compiler to the GroupBy method. GroupBy gets a key-selector as argument of type Func<T, TKey>. In the sample this is Func<Racer, string> as grouping the collection by the country which is of type string. GroupBy returns IEnumerable<IGrouping<TKey, T>> what is IEnumerable<IGrouping<string, Racer>> with the sample.

The result from the grouping is ordered based on the number of elements within a group by using the Count extension method. If the count is the same, it is ordered by the key which is the country.

The result that is returned is an anonymous type with the properties Country and Count.

As the sample is now, the Count method is invoked two times. This can be changed by creating a variable within the LINQ query using the let clause.

var q = from r in Formula1.GetChampions() group r by r.Country into g let count = g.Count() orderby count descending, g.Key select new { Country = g.Key, Count = count };

Adding the racers to the result of each country is done in the next version by adding a Racers property to the anonymous type that is returned from the query. The Racers property is filled by a LINQ query that accesses the group.

var q = from r in Formula1.GetChampions() group r by r.Country into g let count = g.Count() orderby count descending, g.Key select new { Country = g.Key, Count = count, Racers = from r1 in g select r1.FirstName + " " + r1.LastName };

To reduce the result of the query to the first five groups the extension method Take is used to just return the first five.

var q = (from r in Formula1.GetChampions() group r by r.Country into g let count = g.Count() orderby count descending, g.Key select new { Country = g.Key, Count = count, Racers = from r1 in g select r1.FirstName + " " + r1.LastName }).Take(5);

Doing the same query by using extension methods instead of the LINQ Query syntax looks as shown next. The method that follows the GroupBy method can use the IEnumerable<IGrouping<string, Racer>> type that is returned.

The let clause from the LINQ query is converted to a Select method. The let clause was used to define a variable that could be used in the following LINQ clauses. The same is true by returning an anonymous type that contains the Count property from the Select method. For using the group as well with the methods that follow the Select method, the anonymous type contains the group as well.

var q = Formula1.GetChampions() .GroupBy(r => r.Country) .Select(g => new { Count = g.Count(), Group = g }) .OrderByDescending(x => x.Count) .ThenBy(x => x.Group.Key) .Select(x => new { Country = x.Group.Key, Count = x.Count, Racers = x.Group.Select(r => r.FirstName + " " + r.LastName) }) .Take(5);

Doing the same query with Visual Basic, the query looks very similar to the C# LINQ query. What’s different is that with Visual Basic Take is also defined with the LINQ query clauses.

Dim q = From r In Formula1.GetChampions() Group By country = r.Country Into Group Let count = Group.Count() Order By count Descending, country Take 5 Select Count = count, Country = country, Racers = From r In Group Order By r.LastName Select r.FirstName + " " + r.LastName

What’s also different with Visual Basic is that it’s not necessary to define a variable with the Group By clause to add the group to it, instead Group can be used. If multiple groups are used within one query, a variable can be assigned with into:

Dim q = From r In Formula1.GetChampions() Group By country = r.Country Into g = Group Let count = g.Count() Order By count Descending, country Take 5 Select Count = count, Country = country, Racers = From r In g Order By r.LastName Select r.FirstName + " " + r.LastName

If you are curious about the result of the query, here it is:

10 UK Jenson Button Jim Clark Lewis Hamilton Mike Hawthorn Graham Hill Damon Hill James Hunt Nigel Mansell Jackie Stewart John Surtees 3 Brazil Emerson Fittipaldi Nelson Piquet Ayrton Senna 3 Finland Mika Hakkinen Kimi Räikkönen Keke Rosberg 2 Australia Jack Brabham Alan Jones 2 Austria Niki Lauda Jochen Rindt

More about LINQ with C# in my book Professional C# 4 with .NET 4, and with the language of your choice in my LINQ programming workshop. There’s also more about LINQ in the upcoming BASTA! On Tour in Munich.

Christian

CN innovation