One of the cool new features of MSBuild 4.0 is the extensible task factory. Writing your own task factory will allow you to write inline tasks in Perl, Python, or in this case… Windows PowerShell.

Blog post MSBuild Task Factories: guest starring Windows Powershell.

Sample task factory on MSDN Code Gallery MSBuild Windows PowerShell Task Factory.

{ 0 comments }

Microsoft MVP Summit 2010

by Doug Finke on February 16, 2010

in MVP Summit 2010, Microsoft, PowerShell

There are some 1,300 technical experts from around the world here to participate  in the summit. I am sitting in the Hyatt in downtown Bellevue Washington drinking a tall drip from Tully’s. Today there are several welcome keynotes and community sessions.

I have seen a few book authors, CodePlex contributors and others  I follow in  the twittersphere.

Tomorrow starts the all day presentations at the Microsoft campus for each specific technology. I am looking forward to meeting the PowerShell team and other PowerShell MVPs in person. I won’t be able to blog much, NDAs are in effect.

{ 0 comments }

Kent Beck tweeted:  screencast of a simple example of a fluent api driven by tests from @jitterted http://bit.ly/cSqtJE.

Using VS 2010 RC, C# and .NET 4.0

Ted Young gives a nice introduction into building fluent APIs using Java. He returns an instance of a DateBuilder to manage the dates. The .NET example copies this and uses extension methods.

I used VS 2010’s generate stub tooling for creating methods and classes while following Ted using IntelliJ IDEA in his video.

   1: using System;

   2:  

   3: namespace ConsoleApplication1

   4: {

   5:     class Program

   6:     {

   7:         static void Main(string[] args)

   8:         {

   9:             var somedate = new DateTime(2010, 1, 10);

  10:             var otherDate = new DateTime(2010, 1, 31);

  11:  

  12:             System.Diagnostics.Debug.Assert(somedate.IsBefore(otherDate));

  13:             System.Diagnostics.Debug.Assert(otherDate.IsBefore(somedate) == false);

  14:  

  15:             System.Diagnostics.Debug.Assert(Dates.Is(otherDate).OnOrAfter(somedate));

  16:             System.Diagnostics.Debug.Assert(Dates.Is(somedate).OnOrAfter(otherDate) == false);

  17:  

  18:             System.Diagnostics.Debug.Assert(Dates.Is(somedate).OnOrBefore(otherDate));

  19:             System.Diagnostics.Debug.Assert(Dates.Is(otherDate).OnOrBefore(somedate) == false);

  20:  

  21:             System.Diagnostics.Debug.Assert(Dates.Is(otherDate).On(otherDate));

  22:             System.Diagnostics.Debug.Assert(Dates.Is(otherDate).On(somedate) == false);

  23:  

  24:             

  25:  

  26:         }

  27:     }

  28:  

  29:     public static class Dates

  30:     {

  31:         public static bool IsBefore(this DateTime firstDateTime, DateTime otherDate)

  32:         {

  33:             return (firstDateTime <= otherDate) ? true : false;

  34:         }

  35:  

  36:         public static bool IsAfter(this DateTime firstDateTime, DateTime otherDate)

  37:         {

  38:             return (firstDateTime >= otherDate) ? true : false;

  39:         }

  40:  

  41:         public static DatesBuilder Is(DateTime firstDateTime)

  42:         {

  43:             return new DatesBuilder(firstDateTime);

  44:         }

  45:  

  46:         public class DatesBuilder

  47:         {

  48:             private DateTime _firstDateTime;

  49:  

  50:             public DatesBuilder(DateTime firstDateTime)

  51:             {

  52:                 this._firstDateTime = firstDateTime;

  53:             }

  54:  

  55:             public bool OnOrAfter(DateTime otherDate)

  56:             {

  57:                 return !_firstDateTime.IsBefore(otherDate);

  58:             }

  59:  

  60:             public bool OnOrBefore(DateTime otherDate)

  61:             {

  62:                 return !_firstDateTime.IsAfter(otherDate);

  63:             }

  64:  

  65:             public bool On(DateTime otherDate)

  66:             {

  67:                 return _firstDateTime.Equals(otherDate);

  68:             }

  69:         }

  70:     }

  71: }

{ 2 comments }

Dave Thompson posts Consuming data from Codename “Dallas”. He outlines how to retrieve data using C# and VB. Plus he provides links to overviews and Channel 9 resources.

Microsoft® Codename "Dallas" is a new service allowing developers and information workers to easily discover, purchase, and manage premium data subscriptions in the Windows Azure platform.

PowerShell Version

You can grab the PowerShell scripts below. The scripts download the data from a Dallas Url, transform the results to PowerShell objects and then pipes the results to Out-DataGrid for previewing and filtering.

Transformed Dallas Data from Info USA Service/Business Analytics

PowerShell Version 2 ships with a cmdlet Out-DataGrid. After pulling down the business analytics and transforming them, you simply pipe the results to Out-DataGrid and get the following.

image

Get-DallasInfo PowerShell Function

All it takes is a few lines of PowerShell to get the above preview. You’ll need to get an account key and unique userId from Microsoft Dallas. The Url below points to one the subscriptions you sign up for. Plus it can take parameters. The request used here gets business analytics for the US.

$accountKey = "your account key"
$uniqueUserId = "your unique user id"            

. .\Get-DallasInfo.ps1            

$url = "https://api.sqlazureservices.com/InfoUsaService.svc/businessAnalytics/us?$format=raw"            

Get-DallasInfo $url $accountKey $uniqueUserId | Out-GridView            

Get-DallasInfo

This function does the bulk of the work making the request, grabbing the response and converting the results to PowerShell objects.

Function Get-DallasInfo {
    param (
        $url,
        $accountKey,
        $uniqueUserId
    )            

    $Error.Clear()            

    $request = [System.Net.WebRequest]::Create($url)
    $request.Headers.Add('$accountKey', $accountKey)
    $request.Headers.Add('$uniqueUserID', $uniqueUserId)            

    try {
        $response = $request.GetResponse()            

        $dataStream = $response.GetResponseStream()
        $reader = New-Object System.IO.StreamReader($dataStream)
        $feed = [xml]$reader.ReadToEnd()            

        $reader.close()
        $dataStream.close()
        $response.close()            

        # transform the Dallas data into PowerShell objects
        $records = $feed |
            select -ExpandProperty feed |
            select -ExpandProperty entry |
            select -ExpandProperty content |
            select -ExpandProperty properties             

        $propertyNames = $records[0] |
            Get-Member -MemberType property |
            Select -ExpandProperty name            

        foreach($record in $records) {
            $p=@{}
            foreach($propertyName in $propertyNames) {
                $p.$propertyName = $record.$propertyName.'#text'
            }
            New-Object PSObject -Property $p
        }            

    } catch {
        $Error
    }
}

Grab the PowerShell Scripts

{ 3 comments }

Auto-scaling in Azure with PowerShell Cmdlets

by Doug Finke on February 7, 2010

in Azure, PowerShell

This post Auto-scaling in Azure shows a proof of concept for auto-scaling an Azure Solution and the different options that you have for implementing a similar solution.

At the end, the author provides a PowerShell example using the Windows Azure Service Management CmdLets

Add-PSSnapin AzureManagementToolsSnapIn            

Get-HostedService $serviceName -Certificate $cert -SubscriptionId $subId |
Get-Deployment -Slot Production |
Set-DeploymentConfiguration `
  {$_.RolesConfiguration[$roleName].InstancesCount+=1}
            

{ 0 comments }

Gesture Cube

by Doug Finke on February 7, 2010

in Gesture Cube, Microsoft Surface

A portable Microsoft Surface? No need to touch – just give it a wave!

{ 0 comments }

There clearly needs to be a successor to Java

by Doug Finke on February 7, 2010

in Groovy, Java, Scala

Will Groovy++ spell the end of Scala?

As much as we all "try to be friends", the successor to Java (and there clearly needs to be one) "battle" continues

via blue train software

Groovy++ adds to Groovy static typing with very little in terms of trade off (meta programming)

  • Allowing mixing of static and dynamic code in the same application.
  • Same speed as Java – sometimes faster, sometimes slower depending on how the problem is expressed.
  • Groovy++ is really Java ++ and is thus a natural and easy path for the millions of Java programmers.
  • Groovy not being controlled by the boffins at Snoracle hopefully means innovation in the platform can happen much faster and address real developer needs.

Others in the community counter that Scala is ~50 times faster than Groovy++.

{ 2 comments }

Rockford Lhotka has a three part series here discussing the benefits and usage of the SQL Server Modeling technologies in the context of his CSLA .NET framework. It is a framework for building the business logic layer in your applications.

He demonstrates modeling, a DSL (domain specific language), code savings, reduced testing burden, and consistency of the user experience.

{ 0 comments }

PowerShell New-PSCustomObject

by Doug Finke on January 24, 2010

in New-Object, PSObject, PowerShell

Karl Prosser posts a PowerShell script quick and dirty new custom object as a way to create PowerShell objects on the fly. I’ve come across the need for this and posted an approach PowerShell Function Factory after reading up on Managing Records in Python.

Yet Another Approach To Building Custom Objects

This function peels off two items at a time placing them in $key and $value, $list gets the remainder (it has two fewer items now). Then key/value pair is added to the $Properties hash table. The while loop continues until $list is empty.

After the $Properties hash table is built up, a new PSObject is returned with those properties created and populated by using the –Property parameter on New-Object.

Function New-PSCustomObject ($list) {
    $Properties = @{}            

    while($list) {
        $key, $value, $list = $list
        $Properties.$key = $value
    }            

    New-Object PSObject -Property $Properties
}            

Function ql {$args}            

New-PSCustomObject ( ql Name "John Doe" Age 10 Height (6*12) )

Result

image

Still rolling this around in my head. Love to hear other approaches. Plus, this may show up in PowerShell Version 3.

UPDATE

Thanks to Nivot Ink for a terser approach.

while($key, $value, $list = $list) {
    $Properties.$key = $value
}                        

{ 5 comments }

WCF WebHttp Services in .NET 4

by Doug Finke on January 24, 2010

in .NET 4.0, WCF, WebHttp

Introducing WCF WebHttp Services in .NET 4

Have your used WCF 3.5 or the WCF REST Starter Kit to build non-SOAP services?

WCF WebHttp Services is the vehicle that brings these technologies forward to .NET 4.

New to WCF or have only used WCF for building SOAP-based services, this series of blog posts will bring you up to speed quickly.z

{ 1 comment }