Global Search / Replace (with Powershell)
Posted By: nicocrm on June 17th, 2009 in Uncategorized
No Gravatar

Had to rename an assembly and was faced with the daunting task of updating a few dozen business rules… I knew I had to do it on the backend as having to click my way through that in App Architect would take a day or more. This is slow but does the trick:

ls -recurse -filter *.xml |% { $text = (get-content $_.FullName) -replace "SourceAssemblyName", "NewAssemblyName"; $text | out-file -encoding utf8 $_.FullName }

Kinda like it better than the old find / grep / sed combo.

There is an alternative that checks if the text was actually modified (otherwise it can append newline to files which sometimes messes things up):

ls -recurse -filter *.xml |% { 
$oldtext = [string]::join([environment]::newline, (get-content $_.FullName));
$text = $oldtext -replace "SourceAssemblyName", "NewAssemblyName"; 
if($text -ne $oldtext) { $text | out-file -encoding utf8 $_.FullName }
}

Finally I stuck this in my powershell profile (do notepad $profile to bring it up). This lets me use the “ReplText” command without having to retype the whole thing out. It takes the list of files from the input pipeline to be flexible:

# Replace text in every file listed on the input.
# $input: list of file objects (from pipeline)
# $pattern: source pattern (regular expression)
# $replacement: replacement (can have backreferences)
#
# Usage: dir -recur -filter *.xml | ReplText SourcePattern DestPattern
function ReplText($pattern, $replacement) {
  process {
    $oldtext = [string]::join([environment]::newline, (get-content $_.FullName))
    $newtext = $oldtext -replace $pattern, $replacement
    if($newtext -ne $oldtext) { $newtext | out-file -encoding utf8 $_.FullName }
  }
} 

Things to try with Windows 7 / Win 2008 R2
Posted By: nicocrm on June 5th, 2009 in Uncategorized
No Gravatar

I installed Windows 7 RC1 last week-end and so far it has much exceeded my expectations. While Vista had a “oh shiny… but nothing works?” feel to it, Windows 7 seems to be finally fulfilling all those promises (or some of them, anyway!). Lots of neat stuff coming out from MS lately, hope they can keep that up. I am almost considering replacing my Linux box with a Windows server (gasp) to get the document libraries to work correctly (Samba is OK for basic use but lacks the more advanced search features).

Beside a much polished UI and a few very nice usability improvements, here are a few things that I find interesting or will need to try on the more technical side:

  • Updated Virtual PC, now with USB support
  • Managed Services Account will allow password-less service accounts
  • VHD boot
  • Powershell 2.0
  • Search connectors
  • Multi touch? Maybe.

I still have not loaded it on my work machine, mind you – am not sure Saleslogix will like it too much.


Easy Business Rules with Extension Methods
Posted By: nicocrm on June 1st, 2009 in Uncategorized
No Gravatar

I just realized that I could use C# extension methods to avoid the whole “open architect, expand the little tree to find my entity, add the business rule definition, select the assembly, select the method from the assembly, save, copy comment from the C# project, save again, build, deploy, pray that the deployment actually worked” process.

I can declare my business rule like this:

public static void CalculateProcessTask(this ITicketActivity ticketActivity)

save as TicketRules.dll, and add this to the code to use it:

using TicketRules;

Another huge benefit is I can now use F12 to navigate to the definition. One less reason to open the Application Architect for – YAY! Sadly there is no way to do something like that for events, or for code snippet properties. But if you add the namespace used for the extension rules to the web.config/system.web/pages/namespaces element (see http://www.west-wind.com/WebLog/posts/2287.aspx for an example) you can use it in snippet actions.

It also opens the door to something that is a bit scary… it looks like those rules could be defined in App_Code (the folder that contains dynamically compiled code for ASP.NET). This would let us edit them without having to recompile… or restart the IIS app… mucho más rápido! But this prevents the code from being unit-tested, and makes it harder to manage, so I am not very likely to use it (business rules typically don’t need to be adjusted very often anyway, once they are unit-tested)