Rhino ETL Sample

Here is a quick sample that shows how to get rhino etl working.
It moves data from one database into another without any of the complex transforms.

Rhino.Etl.Cmd -c:database.config -f:CopyUser.boo -p CopyUser

=== database.config === Need to replace the [ with the expected angle brackets.

[configuration]
[connectionStrings]
[add name=”source” connectionString=”Data Source=DATABASE_SERVER1;Initial Catalog=databaseName;User=username;Password=password;” providerName=”System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ /]
[add name=”target” connectionString=”Data Source=DATABASE_SERVER2;Initial Catalog=databaseName2;User=username;Password=password;” providerName=”System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ /]
[/connectionStrings]

[/configuration]

=== CopyUser.boo === Need to replace [TAB] with tabs

process CopyUser:
[TAB]input “source”, Command = “SELECT strUserID, strParamGroup, strName, strValue from tblParameter where strUserID = ‘FRED'”
[TAB]output “target”, Command = “””
INSERT INTO tblParameter (strUserID, strParamGroup, strName, strValue)
VALUES (‘JOE’, @strParamGroup, @strName, @strValue)
“””

Remember that boo is a tab sensitive.

Minimal adding pages to sharepoint

The following is the boo source to a utility that can be used to add pages to a SharePoint site.
No feature required!

=== addpage.boo ===
import Microsoft.SharePoint
import System.IO

def addPage(_site as string, _web as string, _page as string, _url as string):
    site = SPSite(_site)
    web = site.OpenWeb(_web)
    folder = web.GetFolder(“”)
    folder.Files.Add(_url, File.OpenRead(_page), true)
    
addPage(argv[0], argv[1], argv[2], argv[3])    

Pure Boo WCF problem

I have been trying to create a pure WCF service that exposes metadata.
Learning WCF implies that MexHttpBinding exists as a class that can be used like HttpBinding.

Unfortuantely I get HTTP 405 errors!

The following host:

namespace IndigoService

import System
import System.ServiceModel
import System.ServiceModel.Description

host = ServiceHost(typeof(IndigoService.HelloIndigoService), Uri(“http://localhost:8000/HelloIndigo”))

mexBehaviour = ServiceMetadataBehavior()
mexBehaviour.HttpGetEnabled = true
host.Description.Behaviors.Add(mexBehaviour)

host.AddServiceEndpoint(typeof(IndigoService.IHelloIndigoService), BasicHttpBinding(), “HelloIndigoService”);
host.AddServiceEndpoint(typeof(System.ServiceModel.Description.IMetadataExchange), BasicHttpBinding(), “mex”);

host.Open();
print “Press any key to terminate”
Console.ReadKey()

Running the service and calling:

C:devboowcf>svcutil /o:serviceproxy.cs /config:app.config http://localhost:8000/HelloIndigo/mex

Produces the following errors:

Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.30]
Copyright (c) Microsoft Corporation.  All rights reserved.

Attempting to download metadata from ‘http://localhost:8000/HelloIndigo/mex’ usi
ng WS-Metadata Exchange or DISCO.
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.30]
Copyright (c) Microsoft Corporation.  All rights reserved.

Error: Cannot obtain Metadata from http://localhost:8000/HelloIndigo/mex

If this is a Windows (R) Communication Foundation service to which you have acce
ss, please check that you have enabled metadata publishing at the specified addr
ess.  For help enabling metadata publishing, please refer to the MSDN documentat
ion at http://go.microsoft.com/fwlink/?LinkId=65455.

WS-Metadata Exchange Error
    URI: http://localhost:8000/HelloIndigo/mex

    Metadata contains a reference that cannot be resolved: ‘http://localhost:800
0/HelloIndigo/mex’.

    Content Type application/soap+xml; charset=utf-8 was not supported by servic
e http://localhost:8000/HelloIndigo/mex.  The client and service bindings may be
 mismatched.

    The remote server returned an error: (415) Cannot process the message becaus
e the content type ‘application/soap+xml; charset=utf-8’ was not the expected ty
pe ‘text/xml; charset=utf-8’..

HTTP GET Error
    URI: http://localhost:8000/HelloIndigo/mex

    There was an error downloading ‘http://localhost:8000/HelloIndigo/mex’.

    The request failed with the error message:

<s:Envelope xmlns:s=”http://schemas.xmlsoap.org/soap/envelope/”><s:Body><s:Fault
><faultcode xmlns:a=”http://schemas.microsoft.com/ws/2005/05/addressing/none”>a:
ActionNotSupported</faultcode><faultstring xml:lang=”en-GB”>The message with Act
ion ” cannot be processed at the receiver, due to a ContractFilter mismatch at
the EndpointDispatcher. This may be because of either a contract mismatch (misma
tched Actions between sender and receiver) or a binding/security mismatch betwee
n the sender and the receiver.  Check that sender and receiver have the same con
tract and the same binding (including security requirements, e.g. Message, Trans
port, None).</faultstring></s:Fault></s:Body></s:Envelope>
–.

If you would like more help, type “svcutil /?”

It appears that mex must be enabled in a config file – you can’t do it in code!

wcf demo in Boo

This is the promised simple wcf demo in boo.

It is based upon the examples in Learning WCF by Michelle Leroux Bustemante.

### Contract.boo ###
namespace IndigoService

import System.ServiceModel

[ServiceContract(Namespace:”http://foo/bar&#8221;)]
interface IHelloIndigoService:
    [OperationContract]
    def SayHello() as string:
        pass

### Service.boo ###
namespace IndigoService

#import System.ServiceModel
   
class HelloIndigoService(IHelloIndigoService):
    def SayHello() as string:
        return “Hello Indigo”

### Host.boo ###
namespace IndigoService

import System.ServiceModel
import System

host = ServiceHost(typeof(IndigoService.HelloIndigoService), Uri(“http://localhost:8000/HelloIndigo&#8221;))
host.AddServiceEndpoint(typeof(IndigoService.IHelloIndigoService), BasicHttpBinding(), “HelloIndigoService”);
host.Open();
print “Press any key to terminate”
Console.ReadKey()

### Client.boo ###
namespace IndigoService

import System
import System.ServiceModel

try:
    ep = EndpointAddress(“http://localhost:8000/HelloIndigo/HelloIndigoService&#8221;)
    proxy as IHelloIndigoService
    proxy = (ChannelFactory [of IHelloIndigoService]).CreateChannel(BasicHttpBinding(),ep)
    Console.WriteLine(proxy.SayHello())
    Console.ReadKey()
except e:
    print “Problem with server – probably not there”
    # print e

### default.build ###
<?xml version=”1.0″ ?>

<project name=”wcfdemo” default=”build”>
<property name=”boo.dir” value=”C:/boo/bin” />
    <target name=”build” depends=”wcfserver,wcfclient” />
    <target name=”wcfserver”>
        <loadtasks assembly=”${boo.dir}/Boo.NAnt.Tasks.dll” />
                 <booc output=”wcfserver.exe” target=”exe”>
            <references>
                <include name=”C:/Program Files/Reference Assemblies/Microsoft/Framework/v3.0/*.dll” />
            </references>
            <sources>
                <include name=”Service.boo” />
                <include name=”Host.boo” />
                <include name=”Contract.boo” />               
            </sources>
        </booc>
    </target>
    <target name=”wcfclient”>
        <loadtasks assembly=”${boo.dir}/Boo.NAnt.Tasks.dll” />
                 <booc output=”wcfclient.exe” target=”exe”>
            <references>
                <include name=”C:/Program Files/Reference Assemblies/Microsoft/Framework/v3.0/*.dll” />
            </references>
            <sources>
                <include name=”Client.boo” />
                <include name=”Contract.boo” />               
            </sources>
        </booc>
    </target>
</project>

Improved wpf demo

Here is an improved version of the wpf demo.  The older posts build script still applies.

I need to attribute this site for giving me hints to go in the right direction.

import System

import System.Windows

import System.Windows.Controls

import System.Windows.Navigation

  

class Exer1(NavigationWindow):

            para as TextBlock

            button as Button

           

            def constructor():

                        para = TextBlock(Text:”Hello World!!!”, FontSize:36)

                        para.VerticalAlignment = VerticalAlignment.Center

                        para.HorizontalAlignment =HorizontalAlignment.Center  

                        # create a button


//<![CDATA[

//]]>
                        button = Button(Content:”Click Me”, Height:30, Width:100)

                        # display the textblock when the button is clicked

                        button.Click += NavButtonClick

                        # display the button first

                        Navigate(button)

                       

            protected def NavButtonClick(sender as object, e as RoutedEventArgs):

                        Navigate(para)

                                   

                       

[STAThread]

def Main():

            app = Application()        

            Exer1().Show()

            app.Run()

Boo compiler warning

The latest Boo release is 0.8.1

Boo build 0.8.1.2865 appears to be broken.

Code that works fine under 0.8.0.2730 fails to compile.

Apparently the latest source from subversion works fine.

Some of my samples were blowing up with unknown key errors, mostlty when assigning events.

Boo Compiler Options

There are lots of options for building Boo.

I got fed up having to look up the options so I have them all here.

Usage is: booc [options] file1 …
Options:
 -c:CULTURE           Sets the UI culture to be CULTURE
 -debug[+|-]          Generate debugging information (default: +)
 -define:S1[,Sn]      Defines symbols S1..Sn with optional values (=val) (-d:)
 -delaysign           Delays assembly signing
 -ducky               Turns on duck typing by default
 -checked[+|-]        Turns on or off checked operations (default: +)
 -embedres:FILE[,ID]  Embeds FILE with the optional ID
 -lib:DIRS            Adds the comma-separated DIRS to the assembly search path
 -noconfig            Does not load the standard configuration
 -nostdlib            Does not reference any of the default libraries
 -nologo              Does not display the compiler logo
 -p:PIPELINE          Sets the pipeline to PIPELINE
 -o:FILE              Sets the output file name to FILE
 -keyfile:FILE        The strongname key file used to strongname the assembly
 -keycontainer:NAME   The key pair container used to strongname the assembly
 -reference:ASS       References the specified assembly (-r:ASS)
 -srcdir:DIR          Adds DIR as a directory where sources can be found
 -target:TYPE         Sets the target type (exe, library or winexe)
 -resource:FILE[,ID]  Embeds FILE as a resource
 -pkg:P1[,Pn]         References packages P1..Pn (on supported platforms)
 -utf8                Source file(s) are in utf8 format
 -v, -vv, -vvv        Sets verbosity level from warnings to very detailed
 -wsa                 Enables white-space-agnostic build

Direct compile line:

booc -t:library bender.boo

booc wpfdemo.boo -r:PresentationCore.dll -r:PresentationFramework.dll -r:WindowsBase.dll

Note you can supply multiple boo source files to split the project.

Nant build script:

<?xml version=”1.0″ ?>
<project name=”wpfdemo” default=”build”>
<property name=”boo.dir” value=”C:/boo/bin” />
    <target name=”build” depends=”wpfdemo” />
    <target name=”wpfdemo”>
        <loadtasks assembly=”${boo.dir}/Boo.NAnt.Tasks.dll” />
                 <booc output=”wpfdemo.exe” target=”winexe”>
            <references>
                <include name=”C:/Program Files/Reference Assemblies/Microsoft/Framework/v3.0/*.dll” />
            </references>
            <sources>
                <include name=”wpfdemo.boo” />
            </sources>
        </booc>
    </target>
</project>

You can also use msbuild:

<Project DefaultTargets=”Build” xmlns=”http://schemas.microsoft.com/developer/msbuild/2003″&gt;
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <RootNamespace>Bake.Example</RootNamespace>
    <AssemblyName>Bake.Example</AssemblyName>
    <Configuration Condition=” ‘$(Configuration)’ == ” “>Debug</Configuration>
    <Platform Condition=” ‘$(Platform)’ == ” “>AnyCPU</Platform>
    <ProjectGuid>{707667FA-CDCB-4756-9EF0-96DB18A53DCD}</ProjectGuid>
    <NoStdLib>False</NoStdLib>
    <Ducky>False</Ducky>
  </PropertyGroup>
  <PropertyGroup Condition=” ‘$(Configuration)’ == ‘Debug’ “>
    <BaseIntermediateOutputPath>obj</BaseIntermediateOutputPath>
    <IntermediateOutputPath>objDebug</IntermediateOutputPath>
    <OutputPath>….bin</OutputPath>
    <Optimize>False</Optimize>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>Full</DebugType>
  </PropertyGroup>
  <PropertyGroup Condition=” ‘$(Configuration)’ == ‘Release’ “>
    <BaseIntermediateOutputPath>obj</BaseIntermediateOutputPath>
    <IntermediateOutputPath>objRelease</IntermediateOutputPath>
    <OutputPath>….bin</OutputPath>
    <Optimize>True</Optimize>
    <DefineConstants>TRACE</DefineConstants>
    <DebugSymbols>false</DebugSymbols>
    <DebugType>None</DebugType>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include=”Program.boo” />
  </ItemGroup>
  <ItemGroup>
    <Content Include=”example.boobs” />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include=”..bake.engineBake.Engine.booproj”>
      <Project>{B86E7336-0498-486D-A199-FC19ED9740AF}</Project>
      <Name>Bake.Engine</Name>
    </ProjectReference>
  </ItemGroup>
  <Import Project=”$(BooBinPath)Boo.Microsoft.Build.targets” />
</Project>

Bake:

import Bake.IO.Extensions

Task(“default”, [“test”])

Task(“compile”, [“codeGen”]) do:
    print “> do compile stuff”

Task(“dataLoad”, [“codeGen”]) do:
    print “> do dataLoad stuff”

Task(“codeGen”) do:
    print “> do codeGen stuff”

Task(“test”, [“compile”, “dataLoad”]) do:
    print “> do test stuff”
    print Configuration.test

Boo build system

Here is a build system that is pure Boo.

It was called BooBS and may be transitioning to Bake.

This reminds me of a build tool that I built once in Python.
It would do the packaging and deployment details but left the compilation to want (the delphi port of nant).
There are big advantages of having the build tool in a scripting language.  This makes fixes much easier and quicker – which you really need if you are trying to get an emergency build out.

Having an automated build tool seriously improves the quality of a build – it reduces the bar on releases so you don’t need a hideous checklist.  I found the need for it when I forgot to release half of the dll’s for a project once.

These days I would recommend creating an automated installer as part of the build.  This seriously reduces the mistakes that the instalation engineer makes.

Boo and WPF

Here is an example of Boo and WPF.
I am not claiming that it is origonal since it was cribbed from someone elses site.
However this version is not broken and does have a build script.

The following is wpdemo.boo:

namespace Boo.WinFx
import System
import System.Windows
import System.Windows.Controls
import System.Windows.Navigation

[STAThread]
def Main():
    # create a window host
    win = NavigationWindow()   
    # create a textblock
    para = TextBlock(Text:”Hello World!!!”, FontSize:36)
    para.VerticalAlignment = VerticalAlignment.Center
    para.HorizontalAlignment =HorizontalAlignment.Center   
    # create a button
    button = Button(Content:”Click Me”, Height:30, Width:100)
    # display the textblock when the button is clicked
    button.Click += { win.Navigate(para) }
    # display the button first
    win.Navigate(button)
    # create an application host
    app = Application()
    # show the window
    win.Show()
    # fire the application
    app.Run()

The following is default.build:

<?xml version=”1.0″ ?>

<project name=”wpfdemo” default=”build”>
<property name=”boo.dir” value=”C:/boo/bin” />
    <target name=”build” depends=”wpfdemo” />
    <target name=”wpfdemo”>
        <loadtasks assembly=”${boo.dir}/Boo.NAnt.Tasks.dll” />
                 <booc output=”wpfdemo.exe” target=”winexe”>
            <references>
                <include name=”C:/Program Files/Reference Assemblies/Microsoft/Framework/v3.0/*.dll” />
            </references>
            <sources>
                <include name=”wpfdemo.boo” />
            </sources>
        </booc>
    </target>
</project>

Boo and WF

This is based upon an example that has been floating around the blogs.
I have removed the Python accent from it (hint you don’t need to use self in a Boo class):

The following is wf.boo

import System.Workflow.Activities
import System.Workflow.Runtime
import System
class MyWorkflow(SequentialWorkflowActivity):
_codeActivity as CodeActivity
def constructor():
super()
_codeActivity = CodeActivity()
_codeActivity.ExecuteCode += SayHello
_codeActivity.Name = “Hello”
Activities.Add(_codeActivity)
def SayHello(sender, args):
print “Hello”

def Started(sender as object, args as EventArgs):
print “Startedn”
def Completed(sender as object, args as EventArgs):
print “Completed”

tf = MyWorkflow()
rt = WorkflowRuntime()
rt.WorkflowStarted += Started
rt.WorkflowCompleted += Completed
type = tf.GetType()
instance = rt.CreateWorkflow(type)
instance.Start()
Console.ReadKey()

The following is default.build:

<?xml version=”1.0″ ?>

<project name=”wpfdemo” default=”build”>
<property name=”boo.dir” value=”C:/boo/bin” />
<target name=”build” depends=”wpfdemo” />
    <target name=”wpfdemo”>
        <loadtasks assembly=”${boo.dir}/Boo.NAnt.Tasks.dll” />
            <booc output=”wf.exe” target=”exe”>
                <sources>
                    <include name=”wf.boo” />
                </sources>
            </booc>
    </target>
</project>