1. 14:04 9th Jan 2014

    Vote on HN

    Tags: powershellroundhouseCIteamcity

    Calling roundhouse from powershell

    It’s not the first time I struggle to pass parameters containing spaces to an executable from powershell. And since I finally managed to get it right, I will not miss that chance to document it for my future self.

    Pay attention to the back-ticks to escape the double quotes…

    And pay attention to how it checks for the exit code (don’t forget the -PassThru parameter to get the process object out).

    Here is the small powershell wrapper I used for the roundhouse excutable.

     
  2. 09:38 18th Dec 2013

    Vote on HN

    Tags: powershell

    Find the local path from a local UNC network share path with Powershell

    Just making sure that I will know where to find this if I need it again in the future.

    If you have a UNC network share path, such as \Computer1\Shared and you need to know the local folder linked to that when running a script from Computer1, you can achieve that easily in powershell :

    gwmi win32_share | ? {$_.Name -eq "Shared" } | select -expand path
    
     
  3. 12:58 17th Dec 2013

    Vote on HN

    Tags: powershellCImsdeploy

    Deploying to IIS using MSDeploy from powershell with a non-admin user


    In theory, msdeploy is perfect to deploy to IIS, but it was written for cmd, not for powershell. That means that when you call it from a powershell script, things start to fall appart

    I was pretty sure that I would find people who were doing the same thing on github, and indeed, It didn’t take long to find a trusted source: the NugetGallery website deployment script uses msdeploy

    It was helpful, but that was not it… Ready to do the things the right way, I did not want to use an administrator account in my script as MSDeploy seems to want it.

    And apparently there are ways to use a standard user with just the necessary rights.

    The user you create on the machine where you want to deploy, needs to have the ACL rights to the folder of course, and he also needs to have the IIS Manager permission on the application that you want to deploy. You then deploy to the Web Site url (for example, “Default Web Site”) but you give an extra parameter to msdeploy that points to the Web Applilcation this time.

    Summarized, it’s something like this :

    $AppName = "MyApp"
    $Site = "Default Web Site"
    $WebApp= "$Site/$AppName" 
    
    # Here we use the $Site variable, **Not the $WebApp**
    $PublishUrl = "https://WebServer:8172/MSDeploy.axd?site=$($Site)"
    
    $arguments = [string[]]@(
        "-verb:sync",
        "-source:package='$Package'",
        "-dest:auto,computerName='$PublishUrl',userName='$UserName',password='$Password',authtype='Basic'",  
    # This is where you point to the WebApp
        "-setParam:name='IIS Web Application Name',value='$($WebApp)'",
        "-allowUntrusted")
    
    # And this is how you call msdeploy with spaces in the arguments without problems
    Start-Process $msdeploy -ArgumentList $arguments -NoNewWindow -Wait
    

    But somehow that would not work, and the error message was not really helpful. It turns out, as most of the time, that I was doing it wrong (but in that case MSDeploy is really making it easy to shoot yourself in the foot)

    I published the complete powershell wrapper that I use as a gist on github, I hope this helps someone. :)

     
  4. 15:19 16th Dec 2013

    Vote on HN

    Running Nunit tests in Teamcity using wildcards to find dlls

    Quick note for my future self to avoid an hunting for the imaginary problem.

    When using wildcards to run nunit tests in Teamcity, use this :

    **\bin\debug\*Test*.dll    
    

    And not this :

    **\*Test*.dll
    

    The reason being that if we don’t specify the bin folder in the path, it will pick up the dll in the obj folder, and that folder will not contain the referenced dlls, hence it will run the tests twice and fail on the one from the obj folder.

     
  5. 10:55 5th Dec 2012

    Vote on HN

    Using Oracle Text Search

    The author goes from creating the tables, a multicolumn index and queries it.
    I believe there is a better query, but that is still a good and simple start.

     
  6. 14:24 13th Sep 2012

    Vote on HN

    Testing the IDataReader mapping

    I don’t want to enter the discussion if you should or not use a datareader, this is another topic. I will just show how I test the mapping between the reader and my objects easily.

    First of all, I try to isolate the mapping from the rest of the code

    I usually create one class by mapping and pass it the datareader. I use this base class :

    public abstract class DataReaderMapperBase<T> where T:class
    {
          public abstract T Map(IDataReader reader);
    }
    

    A simple example of using this base class :

    public class PersonDataReaderMapper : DataReaderMapperBase<Person>
    {
         public override Person Map(IDataReader reader)
         {
               return new Person 
               {
                      FirstName = reader.GetString("Name"),
                      LastName = reader.GetString("LastName"),
                      ...
               }
         }
    }
    

    But how to test this? there is a simple way of stubbing a datareader using a DataTable and a DataTableReader. But that is still a cumbersome syntax, so I wrapped it in a helper that could take objects and transform them into a DataReader row. I will probably package a little better, but here is the raw draft, with an example of how you use it :

     
  7. 14:09 17th Jul 2012

    Vote on HN

    Notes: 1

    Tags: psakeCITeamCity

    Using psake to run your TeamCity continuous integration build

    Recently I had to setup a CI build in TeamCity.
    I already did this once using msbuild script, and met very quickly walls when I wanted to get into more advanced deployment scripts. So I looked for a different solution and found psake. From the github project :

    psake is a build automation tool written in PowerShell. It avoids the angle-bracket tax associated with executable XML by leveraging the PowerShell syntax in your build scripts. psake has a syntax inspired by rake (aka make in Ruby) and bake (aka make in Boo), but is easier to script because it leverages your existent command-line knowledge.

    DISCLAIMER : Works on my machine!

    The psake build script

    At the top of my default.ps1 I have

    properties {
        $home = $psake.build_script_dir + "/../.."
        $sln_file_server = "$home/Server/Server.sln"
        $sln_file_client = "$home/Client/Client.sln"
        $sln_file_common = "$home/Common/Common.sln"
        $configuration = "Debug"
        $framework = "4.0"
    }
    

    My build script is not at the root of the repository, so I adjust a $home variable myself.

    And here are my tasks :

    task CompileCommon {
      exec { msbuild "$sln_file_common" /p:Configuration=$configuration }
    }
    
    task CompileClient {
      exec { msbuild "$sln_file_client" /p:Configuration=$configuration }
    }
    
    task CompileServer {
      exec { msbuild "$sln_file_server" /p:Configuration=$configuration }
    }
    
    task All -depends Clean, CompileCommon, CompileClient, CompileServer {
    }
    

    Awesome, but the integration with teamcity has some surprises (fortunately relatively simple to overcome). In short, Powershell does not use the exit codes of the programs you launch from it. If msbuild exits with the code 1 (for failure), the powershell process will still exit with the code 0 (success). Unfortunately, this is what teamcity is looking at to tell if the build step passed or failed.

    I ran into this problem and had a hard time making the build fail when the compilation was failing. Here is how I solved it, which is similar to what the wiki says:

    Make TeamCity fail when the compilation fails

    I fixed this in the teamcity build step setup. I have tried multiple things (running the psake.cmd didn’t do it for me), and I ended up with the following configuration (click to see a higher resolution) :

    Some tips

    To reference the paths in my build script, psake has this nice little helper : $psake.build_script_dir
    This variable will have the path to the script that you execute. Whether you execute it from another folder or right from the script folder, it will hold the correct value. That’s what I base the path to the .sln files in the properties section

    $home = $psake.build_script_dir + "/../.."
    

    That’s also how I let psake know where my powershell modules are in the psake.config.ps1 :

    $root = $psake.build_script_dir
    $config.modules=("$root\modules\*.psm1")
    

    Another useful tip is that psake has a built-in function to configure the build environment (access to msbuild.exe of a specific framework for example)

    if you digg into psake.psm1 source code, you will find this function :

    function Configure-BuildEnvironment {
    $framework = $psake.context.peek().config.framework
    if ($framework.Length -ne 3 -and $framework.Length -ne 6) {
        throw ($msgs.error_invalid_framework -f $framework)
    }
    $versionPart = $framework.Substring(0, 3)
    $bitnessPart = $framework.Substring(3)
    $versions = $null
    switch ($versionPart) {
        '1.0' {
            $versions = @('v1.0.3705')
        }
        '1.1' {
            $versions = @('v1.1.4322')
        }
        '2.0' {
            $versions = @('v2.0.50727')
        }
        '3.0' {
            $versions = @('v2.0.50727')
        }
        '3.5' {
            $versions = @('v3.5', 'v2.0.50727')
        }
        '4.0' {
            $versions = @('v4.0.30319')
        }
        default {
            throw ($msgs.error_unknown_framework -f $versionPart, $framework)
        }
    }
    
    $bitness = 'Framework'
    if ($versionPart -ne '1.0' -and $versionPart -ne '1.1') {
        switch ($bitnessPart) {
            'x86' {
                $bitness = 'Framework'
            }
            'x64' {
                $bitness = 'Framework64'
            }
            { [string]::IsNullOrEmpty($_) } {
                $ptrSize = [System.IntPtr]::Size
                switch ($ptrSize) {
                    4 {
                        $bitness = 'Framework'
                    }
                    8 {
                        $bitness = 'Framework64'
                    }
                    default {
                        throw ($msgs.error_unknown_pointersize -f $ptrSize)
                    }
                }
            }
            default {
                throw ($msgs.error_unknown_bitnesspart -f $bitnessPart, $framework)
            }
        }
    }
    $frameworkDirs = $versions | foreach { "$env:windir\Microsoft.NET\$bitness\$_\" }
    
    $frameworkDirs | foreach { Assert (test-path $_ -pathType Container) ($msgs.error_no_framework_install_dir_found -f $_)}
    
    $env:path = ($frameworkDirs -join ";") + ";$env:path"
    # if any error occurs in a PS function then "stop" processing immediately
    # this does not effect any external programs that return a non-zero exit code
    $global:ErrorActionPreference = "Stop"
    }
    

    That function is called automatically by psake before the tasks are run. It looks at psake’s configuration hash to find the $framework property that you can set at the top of the default.ps1 file. You maybe noticed that I do the following :
    properties { … $framework = “4.0” }

    I can then do exec { msbuild … } in my tasks without caring where it is located on my build server. The best is that I can override the properties from the teamcity command line by passing another $framework value as a parameter.

    ./psake.ps1 -properties @{"framework"="3.5"}
    

    Simple and efficient :)

     
  8. 12:59 16th Jul 2012

    Vote on HN

    Notes: 210

    Reblogged from alainmeier

    Some really important shortcuts in SublimeText to improve your productivity.

    The one that is new for me is the last one, very useful indeed!

    • Select all instances: You can select all instances using cmd + ctrl + G (Thanks gryghostvisuals)

    alainmeier:

    I’m a big fan of Sublime Text. As with many Mac programmers, I started on TextMate and then migrated over once Sublime Text 2 was released. When I started, however, there were a lot of things that I didn’t know about ST, so I’ve compiled a list of basic things that are excellent time savers.

     
  9. 13:23 15th Jun 2012

    Vote on HN

    Tags: solrgithub

    Running Solr as a windows service

    Solr is a very powerful search engine built on top of Lucene. If you read this article you are probably familiar with it already, so I will skip the introductions.

    One recurrent issue is that it is not the best fit to run it on a windows server. Or at least, it is not straight forward for everyone apparently.

    I stumbled upon a small project (thanks rupertbates) on github that is making this a piece of cake. I updated it and thought that might help others :

    https://github.com/serbrech/SolrWindowsService

    All you need to do is update the few settings in config file to match your environment :

    <solrService>
    <add key="JavaExecutable" value="C:\Program Files (x86)\Java\jre6\bin\java.exe" />
    <add key="WorkingDirectory" value="C:\Solr\apache-solr-4.0\example" />
    <add key="Solr.Home" value="solr" />
    <add key="CommandLineArgs" value="-Djava.util.logging.config.file=logging.properties" />
    <add key="ShowConsole" value="false" />
    <add key="Port" value="8983" />
    <add key="InstanceName" value="MyProjectName" />
    <add key="ClientSettingsProvider.ServiceUri" value="" />
    </solrService>
    

    After compilation, run Install.bat from the bin folder.

    That’s it. Solr is installed as a service on your windows machine.

    if you just want the executable, here you go.

     
  10. 00:16 14th Jun 2012

    Vote on HN

    Tags: graphneo4jlambdasyntax

    Lambdas input parameter name

    I just saw an example of lanbda using “it” as the lambda input parameter name, and I found it quite nice. I never thought about this, nothing exceptional, just a nice touch in readability :

    collection.Where( it => it.Name == "MyRelationship" );
    

    It stays concise, still keeps a meaning when you read it, and it stays short.

    By the way, this lambda was from an example in the Neo4J Rest interface .net wrapper that popped up in the github "C# Most Watched This Week" rss feed.

    Maybe something I will look into. Graph databases are still a mystery to me.