just ram

stuff I should remember

vim-ruby-refactoring - Rename Instance Variable

This post is part of a series which documents the vim-ruby-refactoring plugin.

IMPORTANT: As well as installing the vim-ruby-refactoring plugin, you must also install the matchit.vim plugin for this refactoring to work.

Rename Instance Variable

Renames the selected instance variable.

Example

Before refactoring:
RenameInstanceVar_Before
Visually select the instance variable you wish to rename
Hit your **** then type **rriv **You will now see a prompt to enter the new variable name: Rename to: new_name

After refactoring:
RenameInstanceVar_After
The instance variable @name has been renamed to @new_name in both locations within the class.

rriv is the default binding for this refactoring, think Refactor Rename Instance Variable.

vim-ruby-refactoring - Rename Local Variable

This post is part of a series which documents the vim-ruby-refactoring plugin.

IMPORTANT: As well as installing the vim-ruby-refactoring plugin, you must also install the matchit.vim plugin for this refactoring to work.

Rename Local Variable

Renames the selected local variable.

Example

Before refactoring:
RenameVar_Before
Visually select the local variable you wish to rename
Hit your **** then type **rrlv **You will now see a prompt to enter the new variable name: Rename to: is_mac_os

After refactoring:
RenameVar_After
The local variable mac_os has been renamed to is_mac_os in both locations within the method.

rrlv is the default binding for this refactoring, think Refactor Rename Local Variable.

vim-ruby-refactoring - Extract Local Variable

This post is part of a series which documents the vim-ruby-refactoring plugin.

Extract Local Variable

Extracts a visual selection into a local variable.

The refactoring: http://www.refactoring.com/catalog/introduceExplainingVariable.html

Example

Before refactoring:
ExtractVar_Before
Visually select the value you wish to extract
Hit your **** then type **relv **You will now see a prompt to enter the variable name: Variable name: mac_os

After refactoring:
ExtractVar_After
The value platform.upcase.include?(‘MAC’) has been extracted into a local variable mac_os.

relv is the default binding for this refactoring, think Refactor Extract Local Variable.

vim-ruby-refactoring - Extract to Let

This post is part of a series which documents the vim-ruby-refactoring plugin.

Extract to Let

This is an RSpec specific refactoring which will extract an initialisation line and create a let method for you.

Example

Before refactoring:
ExtractLet_Before
Move the cursor on to the line you wish to extract
Hit your **** then type **rel **

After refactoring:
ExtractLet_After
The let method is created above the it block, using the initialisation line - account = Account.new.

rel is the default binding for this refactoring, think Refactor Extract Let.

vim-ruby-refactoring - Extract Constant

This post is part of a series which documents the vim-ruby-refactoring plugin.

Extract Constant

Extracts a selection into a constant which is placed at the top of the current module or class.

The refactoring: http://www.refactoring.com/catalog/replaceMagicNumberWithSymbolicConstant.html

Example

Before refactoring:
ExtractConstant_Before
Visually select the value you wish to extract
Hit your **** then type **rec **You will now see a prompt to enter the constant name: Constant name: Gravitational_Constant

After refactoring:
ExtractConstant_After
The value 9.81 has been extracted into a constant GRAVITATIONAL_CONSTANT which is placed at the top of the module.

rec is the default binding for this refactoring, think Refactor Extract Constant.

vim-ruby-refactoring - Convert Post Conditional

This post is part of a series which documents the vim-ruby-refactoring plugin.

Convert Post Conditional

Converts a post conditional expression to a conditional expression.

Example

Before refactoring:

ConvertPostConditional_Before
Move the cursor onto the line which contains the post conditional expression
Hit your **** then type **rcpc **

After refactoring:

ConvertPostConditional_After
The post conditional expression is split across 3 lines and converted into a standard if expression.

rcpc is the default binding for this refactoring, think Refactor Convert Post Conditional.

vim-ruby-refactoring - Inline Temp

This post is part of a series which documents the vim-ruby-refactoring plugin.

Inline Temp

Replaces a temporary variable with a direct call to the method or formula.

The refactoring: http://www.refactoring.com/catalog/inlineTemp.html

Example

Before refactoring:

InlineTemp_Before
Move the cursor onto the temp variable (in this case base_price)
Hit your **** then type **rit **

After refactoring:

InlineTemp_After
The temp variable base_price has been replace with a direct call to the method and we’ve saved a line of code.

rit is the default binding for this refactoring, think Refactor Inline Temp.

vim-ruby-refactoring - Add Parameter

This post is part of a series which documents the vim-ruby-refactoring plugin.

Add Parameter

Simply adds a parameter (or many separated with commas) to a method.

The refactoring: http://www.refactoring.com/catalog/addParameter.html

Example

Before refactoring:AddParameter_Before
Move your cursor onto the method where you wish to add the parameter
Hit your **** then type **rap **You will now see a prompt to enter the parameter name: Parameter name: **date**

After refactoring:

AddParameter_After
The contact method now has a date parameter added.

rap is the default binding for this refactoring, think Refactor Add Parameter.

The default **** in vim is the ‘\’ key but you can remap this to any key you like.

Using vim to write ruby code? Check out this excellent refactoring plugin

I’ve written a series of posts documenting the excellent vim plugin vim-ruby-refactoring. As you may have guessed from the name, its a Ruby refactoring plugin for vim.

  1. Add Parameter

  2. Inline Temp

  3. Convert Post Conditional

  4. Extract Constant

  5. Extract to Let

  6. Extract Local Variable

  7. Rename Local Variable

  8. Rename Instance Variable

  9. Extract Method

IMPORTANT: When installing the vim-ruby-refactoring plugin, make sure you also install the matchit.vim plugin otherwise some of these refactoring’s will not work.

How the new Host feature works in nServiceBus

The latest Alpha version of nServiceBus uses the TopShelf project as part of its new hosting feature. This new Host feature makes it super easy to setup a console/windows service for your clients/servers. So here’s how I think it works and what you can do with it…

Get nServiceBus

First you’ll need to get the latest build which includes the new Host feature either:

Either way take a look at the FullDuplex/RequestResponse sample project which consists of a Client, Server and Messages project:

image

Run the sample

Note: To get the Server to run successfully in my demo solution I had to change the app.config slightly by replacing the UnicastBusConfig setting with:

Ok simply hit F5 to run the sample and two console windows should appear one for the Client and one for the Server:

image

So everything is running ok our Client can send messages to the Server and receive a response. But what’s just happened?

Multiple startup projects

First the solution is set to start both the Client and the Server projects. This is set in the solution property pages you can view this setting by right clicking on the solution and selecting Set St_a_rtUp Projects…

image

As you can see the solution is set to start multiple projects namely the Client and the Server.

Now the Server and Client projects are both Class Library’s so how come they are running as console apps when we F5 (debug) the solution?

Debug settings

If we take a look at the Debug settings for the Client (Right click the Client project and select P_r_operties, then Debug from the tab):

image

Notice the Start Action is set to Start e_x_ternal program NServiceBus.Host.exe from the Client projects debug\bin directory. When we hit F5 to debug the application visual studio runs this exe and that’s how we get the console windows.

Reference NServiceBus.Host.exe

NServiceBus.Host.exe ends up in the debug\bin because its referenced by the project for example in the Client:

image

But how does it know where to get its configuration?

Configuration

NServiceBus.Host.exe scans its current directory for any dlls. For each dll it finds it searches for a class which implements the interface IConfigureThisEndpoint. If the search is successful the Host knows to use the app.config for this dll so in the case of the Client – Client.dll.config is used to configure nServiceBus.

Client

If we take a look at the Client project we’ll find the class EndpointConfig which implements the IConfigureThisEndpoint. This is simply a marker interface which has no actual implementation. Notice there are other interfaces used to configure the client which do require implementations:

public class EndpointConfig:IConfigureThisEndpoint,
As.aClient,
ISpecify.ToUseXmlSerialization,
ISpecify.XmlSerializationNamespace,
IWantCustomInitialization,
ISpecify.ToRun { public string Namespace { get { return “[http://www.UdiDahan.com”;](http://www.UdiDahan.com”;) } }

public void Init(Configure configure)
{
configure.RijndaelEncryptionService();
}
}

Of particular interest, the interface used to configure the dll as a client (As.aClient) and another to specify which code to actually run (ISpecify.ToRun). The ClientEndPoint class contains the code which is runs when the Host starts and stops.

Note there are lots more interfaces which can be used to specify configuration options:

image

Server

The Server project works in pretty much the same way as the Client it has an EndpointConfig class:

public class EndpointConfig:IConfigureThisEndpoint,
As.aServer,
ISpecify.ToUseXmlSerialization,

ISpecify.XmlSerializationNamespace,
IWantCustomInitialization
{
public string Namespace
{
get { return “http://www.UdiDahan.com”; }
}

public void Init(Configure configure)
{
configure.RijndaelEncryptionService();
}
}

Here the interfaces are used to configure the dll as a server (As.aServer) and IWantCustomInitialization which allows you to specify additional configuration via the Init method. The Server project also contains the RequestDataMessageHandler class which the bus knows to use when a RequestDataMessage arrives.

All this makes it very easy to create Client and Server applications for nServiceBus which are a doddle to debug in visual studio.

But wait there’s more…

Run from console

You can run the Client or Server from outside Visual Studio from the command line. Open a command prompt, cd to the relevant bin folder and type:

NServiceBus.Host.exe

image

Install as a Windows Service

We can install the Server as a Windows Service no extra code or configuration required! Open a command prompt, cd to the relevant bin folder and type:

NServiceBus.Host.exe /install

image

You’ll then be prompted to supply some authentication details for the service:

image

Enter some relevant user details and hit ok and your service will be installed and ready to start:

image

Uninstall service

Finally you can also uninstall the service:

NServiceBus.Host.exe /uninstall

image

Note: The service will not disappear from this Services management console until you reboot your machine, this is standard for a windows service.

That’s as much as I have puzzled out for now, if I’ve made and glaring errors please let me know.

kick it on DotNetKicks.com