Friday 18 December 2009

IronRuby LinkedIn Group

IronRuby is in RC state and soon we'll all get a possibility to use it in our production environments. I can't predict the exact amount, but I'm absolutely sure it will conquer many developer hearts and build a nice Ruby .NET community.

If you like IronRuby - JOIN LinkedIn community! Let's share our experience in using IronRuby!


Saturday 21 November 2009

Diving into RIA architectures with Flex as an example

Now I have a need to dive into Flex architecture common structure and widely used patterns. Below goes the list of links I've found useful and interesting:

Introduction to RIA architectures

Flex Architecture Fundamentals in 4 parts

Martin Fowler UI patterns

Great benchmark for different ways of Flex to communicate with external services:
(Yes, and SOAP/XML is 4 times slower than Flash-native AMF format)

All of these are really interesting articles that are definitely worth reading even if you don't have same need as I do.

Friday 20 November 2009

Fixing IronRuby error when installing Rake

I was trying to install Rake with IronRuby but was always getting the following error:

>igem install rake
ERROR: While executing gem ... (ArgumentError)

After some Googling I've found the following article:


It's not in English or in Russian so I had to ask Google Translate for help. The article stated that length of name is greater than 255 and that's the problem. I've checked mine:

C:/Program Files/IronRuby 0.9.2/

Obviously it's not longer than 255 characters, so the reason is possibly in spaces. I've reinstalled IronRuby to:

E:/bin/ironruby

And...

PS C:\Users\Ivan Suhinin> igem install rake
Successfully installed rake-0.8.7
1 gem installed
Installing ri documentation for rake-0.8.7...
Installing RDoc documentation for rake-0.8.7...

Yahoo! :) Hope this post will help someone with same problem.

Thursday 19 November 2009

Running IronRuby 0.9.2 with RubyMine 2.0

Latest releases of IronRuby 0.9.2 and RubyMine 2.0 inspired me to make them play together. That's my first experience of running IronRuby in fully featured IDE so I was rather doubtful whether it will work or not.

Here goes step-by-step manual:

1. Download IronRuby 0.9.2 from here and install it.
2. Download RubyMine 2.0 from here and install it. You may need a licence - grab it here.
3. Run RubyMine
4. Click Project Settings or press Ctrl + Alt + S:


5. Navigate to 'Ruby SDK and Gems' left menu option:


6. Click 'Add SDK...' button:


7. Choose ir.exe in your IronRuby 0.9.2 installation folder:


8. That's it! We have IronRuby listed as Ruby SDK in RubyMine:


9. Let's try it in action! Close this window and create a new project:


10. Choose project location and 'Empty project' option - we don't need Rails at the moment:


11. Create a folder named 'src' and add a 'main.rb' file to it:


12. Write this code to editor (and feel the power of RubyMine's IntelliSense):


13. Click the arrow button and choose 'Edit Configurations' option:


14. Add new Ruby configuration:


15. Name configuration and select our 'main.rb' file as executable script:


16. It's damn important to clear 'Ruby Arguments' field. Change this:


to this:


otherwise you'll get the 'can't convert NilClass into String (TypeError)' error:


17. Press OK and run our first program:


18. Here we go, our first IronRuby program running in RubyMine:


Isn't it wonderful? :)

Wednesday 18 November 2009

Use remote desktop connection faster with PowerShell

We have more than ten servers in our production network and all of them are accessible via RDC. The problem is that to connect via RDC you have to specify public IP and not local network nice name like "prod-01" or "prod-db-01". I had not bothered about it till I had a need of connecting some of them several times a day. To solve this problem I wrote a PowerShell script that takes nice name of server and launches RDC with its IP:

$prodServers =
@{
'prod-01' = '1.2.3.2';
'prod-02' = '1.2.3.3';
'prod-03' = '1.2.3.4';

'prod-db-01' = '1.2.3.6';
'prod-db-02' = '1.2.3.8';
}

Set-Alias rdcx 'c:/WINDOWS/system32/mstsc.exe'
function rdc([string]$serverName)
{
$param = ''

if ((![System.String]::IsNullOrEmpty($serverName)) -and ($prodServers.Contains($serverName)))
{
$param += '/v:' + $prodServers[$serverName]
}

rdcx $param
}

It's extremely useful if you have many servers, just believe me :)

Monday 16 November 2009

Use PowerShell to determine MS SQL table used data space

Yet another issue to be solved: we have SQL Expression installed at our branch server and it allows only 4Gb per table. So - what's the solution? Of course, PowerShell!

Right click on database - "Start PowerShell". (Note: I do NOT know how to enter MS SQL mode from normal PowerShell). And now we can have some magic with our database! The following script shows databases that are too heavy and can be cleaned up after some consideration:

ls tables | sort -Property DataSpaceUsed -Descending | ? {$_.DataSpaceUsed -gt 1024} | % {$_.Name + " takes " + [math]::Round($_.DataSpaceUsed / 1024 ) + " Mb"}

Wasn't that just sexy? :) Here goes the step-by-step explanation:

ls tables

Listing all db tables.

sort -Property DataSpaceUsed -Descending

Sorting descending by DataSpaceUsed field - we need to see only the heaviest.


? {$_.DataSpaceUsed -gt 1024}

Taking only tables that take more than 1Mb in data space.

% {$_.Name + " takes " + [math]::Round($_.DataSpaceUsed / 1024 ) + " Mb"}

Making output look nice and actually showing table name.

Friday 13 November 2009

Enlarge your Build System!

http://www.jameskovacs.com/blog/ReleasingPsakeV100PsakeV200.aspx

Rake? NAnt? NO!!!!!!!!!!!

PSake? YES!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

What is it? Ha! Powershell-based build system. DSL for tasks, easily integrated with PS script blocks.

That's only 9th message!

Yeap. This message is only 9th message I have in this year. Compared to 158 messages from last year it seems a bit... small? :)

I should definitely write more.

Delete all MSMQ queues at some PC with PowerShell

We have a small issue at one of our production servers. Once something generated ~10K queues with Guid-like names. Since then they were not deleted as there was a problem: standard MSMQ manager doesn't allow deleting several queues at once.

What to do? Powershell, of course! :) Here goes the script:


[Reflection.Assembly]::LoadWithPartialName("System.Messaging")

[System.Messaging.MessageQueue]::GetPrivateQueuesByMachine("someserver") | % {".\" + $_.QueueName} | % {[System.Messaging.MessageQueue]::Delete($_); }


You may also filter them by name if you do not need to remove them all as I need:


[System.Messaging.MessageQueue]::GetPrivateQueuesByMachine("someserver") | % {".\" + $_.QueueName} | ? {$_ -match "SOME_REGEX_FILTER"} | % {[System.Messaging.MessageQueue]::Delete($_); }

And SOME_REGEX_FILTER is... Yeap, some regex filter :) The -match operator allow us using regular expressions in the Where-Object (alias "?") clause.

Have fun with PowerShell!

Saturday 26 September 2009

What do we need to use IronRuby?

This post is an answer to Jimmy Schementi's Twitter question:
jschementi: Time to start building real #ironruby and #ironpython websites: what content (other than the obvious get/learn/etc) would you like to see?
I'm not going to speak about creating new applications, I'm going to describe a switch of existing ASP.NET application written in C# to IronRuby. Let's have a real-world example. I'm working on a rather huge ASP.NET application dealing with user photos. We use NAnt to build our application, NUnit to test it. Application is layered, we have separate layers for presentation, business logic, data access, etc. We're using ASP.NET 3.5 and have started switching new functionality to ASP.NET MVC 1.

The main question is: what can IronRuby give us? Yes, I'm a HUGE fan of Ruby and I just love it, but my personal usually don't play role in pragmatic reasoning whether to use some technology or not. So let's see what parts can be improved with IronRuby.

1. NAnt - definitely YES, I'm going to smash all barriers and promote usage of Rake. I use it in my home fun project, but fun is not production, fun is not money (at the moment). So what stops me from promoting Rake? Small numbers after it's name: 0.9. No one in company where I work will use something still in Beta status. So that's the first requirement.

2. Testing. According to Patrick Gannon post about Cucumber IronRuby testing could be a real fun. Though, we already use NUnit for testing. Why should we switch to anything else? Or should we use IronRuby with NUnit? To see real advantages we should see comparison of C#/NUnit vs IronRuby/Cucumber. Will it be faster? More readable? Will it increase unit test coverage? That's the second requirement

3. We use MVP for existing ASP.NET 3.5 parts and... guess what we use for ASP.NET MVC? ;) Will we be able to switch our presentation layer to IronRuby? What benefits will it give us? And, moreover, what problems may is cause? My main concern is performance. Ruby itself is a slow language, at least this is true for Ruby 1.8.6, the exact Ruby version IronRuby replicates in .NET. Will it be faster than original Ruby 1.8.6? And what about Ruby 1.9? 2.0? What about our beloved C#? Will IronRuby give us something new and useful in MVC controllers? Models? Views? There are two more requirements: performance benchmarks (vs C# and Ruby) and comparison of business logic layer (for example) in IronRuby vs C# implementation.

Let's sum up the requirements:
1. Final version of IronRuby, ready for production
2. Comparison of C#/NUnit vs IronRuby/Cucumber
3. Performance benchmarks vs C# and Ruby 1.8/1.9
4. Comparison of business layer implementation in IronRuby and C#

That's what will be asked from my pragmatic colleagues in the first place. And what about my own opinion? First of all, I repeat, I'll force them switch to Rake :) That's for sure and I can see real benefits. Testing: I'm satisfied with NUnit and not sure what IronRuby testing will give us. Business logic and presentation layer: I don't think I want to use IronRuby everywhere. Perhaps, it will only be used in presentation layer, for example, or any other area that will benefit from it and will not suffer from performance decrease. But to see where it can be used or can not - I need to see benchmarks and real benefits.


kick it on DotNetKicks.com

Friday 28 August 2009

Resharper doesn't see assemblies from GAC

Just set SetLocal reference property to True. It will copy this library to /bin folder and it will be parsed by Resharper.

Thursday 28 May 2009

Twitquake!

Looks like Twitter is twitquaking right now - it is accessible time to time and has some problems with twitting.

Sad!

Sunday 24 May 2009

Back online!

Here I am :) From today and further on I'm returning to blogging here.

P.S. BTW, I'm now at Twitter and StackOverflow too :)

Monday 19 January 2009

NAnt HowTo #4: How To Create And Use Custom NAnt Task

new class named OK, let's start. What is a NAnt task? Formally, it's a class that extends NAnt.Core.Task class from NAnt.Core.dll assembly located in your NAnt installation folder. As any class it will be placed in an assembly, and this assembly is the way you interact with NAnt. So, let's get it! The following steps describe how to create a simple HelloTask task.

1. Create new project

Create an empty class library project that will compile to .dll file.

2. Create new class derived from NAnt.Core.Task

Create new class named HelloTask and derive from NAnt.Core.Task:

public class HelloTask : Task
{

}

3. Override ExecuteTask method

As NAnt.Core.Task class is abstract VS will suggest you to override the ExecuteTask method - do it. Put the following implementation into it (assume that Person property is already defined ;)):

protected override void ExecuteTask()
{
Project.Log(Level.Info, String.Format("Hello, {0}!", Person));
}
Have a look at Project.Log() call - it will output some message with needed level.

4. Define task name

To define task name, you should apply NAnt.Core.Attributes.TaskNameAttribute attribute to your class:
[TaskName("hello")]
public class HelloTask : Task


5. Define task attributes

To define task attributes, you should define property of appropriate type and mark it with the NAnt.Core.Attributes.TaskAttributeAttribute attribute:

[TaskAttribute("person", Required = true)]
public String Person
{
get;
set;
}
Attribute constructor allows you to specify several options, like whether this attribute is required.

6. Load assembly with you class in NAnt

To use your new task you should place your assembly somewhere NAnt has access to. Two most appropriate options are in NAnt installation folder and in build execution folder. Though I prefer the last one, the first one may be useful if you use your custom tasks regularly though not changing them often.

As soon as assembly is properly placed, you should load tasks from it in your build file. Use loadtasks attribute to load it:

<loadtasks assembly="Leaves.NAnt.Custom.dll" />

7. Use your task

Just use it in the most obvious way:

<hello person="world" />
The output will be the following:

all:

[loadtasks] Scanning assembly "Leaves.NAnt.Custom" for extensions.
Hello, world!

It works!

8. Summarize

This is what we've got in our task:

using System;
using NAnt.Core;
using NAnt.Core.Attributes;

namespace Leaves.NAnt.Custom
{
[
TaskName("hello")]
public class HelloTask : Task
{
protected override void ExecuteTask()
{
Project.Log(Level.Info, String.Format("Hello, {0}!", Person));
}

[
TaskAttribute("person", Required = true)]
public String Person
{
get;
set;
}
}
}
And build file:

<?xml version="1.0"?>

<project
name="NAnt HowTo 4" default="all" xmlns="http://nant.sf.net/release/0.85-rc2/nant.xsd">
<target
name="all">
<loadtasks
assembly="Leaves.NAnt.Custom.dll" />
<hello
person="world" />
</target>
</project>
kick it on DotNetKicks.com

Friday 16 January 2009

ASP.NET MVC impressions

It's awesome! As a fan of Ruby on Rails I can tell you: ASP.NET MVC is f*cking awesome!

Monday 5 January 2009

NAnt HowTo #3: How To Run NUnit Tests From Your Build File

This post continues my NAnt HowTo series. In previous posts I've covered topics of compiling your project and splitting your build file. Today I want to tell you how to run NAnt unit tests from your NAnt build script.

First of all you may notice that main NAnt distribution has TWO NUnit tasks: nunit and nunit2. First one is designed to work with NUnit 1.0 and second one with NUnit 2.2. This simple moment can warn you that something is not as good as it seems here. And you will be right :) Me personally had a problem running NUnit of some lately version using this nunit2 task. After some googling I've found a solution in Scott Hanselman's blog where he spoke with his friend on same topic. As a result of this conversation Scott recommended using nunit-console.exe instead. I've tried it - it works :) Now changing NUnit version will not break as nunit-console command-line specification is not something to change when switching from 2.x to 2.(x+1).

How can we do this? Simple enough:

<target name="tests.unit.run" description="Run unit tests">
<exec
program="D:/bin/nunit/nunit-console.exe"
workingdir="D:/projects/MyProject/Integration"
commandline="MyProject.Tests.dll /xml:TestResults.xml /nologo"/>
</target>

So, step by step.
  1. We use <exec> task to run an executable. This also means that if our nunit-console.exe executable fails (read: some test fails) it will break our build. Of course, you may use failonerror="false" attribute on your <exec> task but I do not recommend doing so - why would anyone ever need tests if their failure will be ignored?!

  2. We specify path to our nunit-console.exe executable via the program attribute.

  3. We specify working directory (usually it's integration dir where you have all needed assemblies) via the workingdir attribute.

  4. We pass command line parameters via the commandline attribute.
Actually this could be the end of the post but I want to say some words on command line arguments of nunit-console.
  1. First non-keyed (with no preceding /im-a-key: keys) several arguments specify assemblies to run tests from.

  2. Argument after /xml: key is a bit more interesting. It indicates the XML file where test results will be stored. You may not need it at the moment but you'll definitely need this file when you'll be integrating your NAnt build script with CruiseControl.NET or any other integration software.

  3. /nologo key suppresses NUnit copyright information display on each run
You can read more about these command line arguments on the official NUnit website.

That's the end :) Next time I will probably speak on writing NAnt custom tasks. Stay online.


kick it on DotNetKicks.com