Visual Studio 2012 Find/Replace With Tagged Expressions

If you ever wanted to do some heavy duty find/replace options in VS 2012, you’ll find yourself needing to use the Regular Expressions option.

One of the most useful things you can do with it is called Tagged Expressions, or backreferences.

Unfortunately, nearly all the online documentation on this is completely wrong.

So I’ll just give a little example.  I’m doing some refactoring, and I have lots of blocks of code that look like this:

Using com As New SqlCommand("SomeCommandNameHere", conn)

and of course each line like this has a different command name.  I want to change the code above to look like this:

Using com As System.Data.IDbCommand = dbProvider.CreateDataCommand()
com.CommandText = "SomeCommandNameHere"

So to achieve this, I use the find/replace below.  You can see that I have to escape a number of characters in the FIND and I’m matching the command name with (.*).  The  () wrap each tagged expression, not { } like all the documentation says.  In the bottom, I just reference the result by saying $1 for the first tagged expression (not \1 like msdn says).

image

Looking for fraud on your credit cards

This is interesting: https://www.billguard.com/power_to_the_people

They will scan your credit card transactions looking for possible fraudulent activity and alert you to it.

BillGuard is a personal finance security service that analyzes millions of consumer billing complaints to find deceptive, erroneous and fraudulent charges on your credit card and debit card bills.

I might give it a try.

MiniProfilerWebFormsEnabler

The StackExchange Mini Profiler is a nice tool to help you see where your pages and queries are spending most of their time. 

It gives you a little jewel in your page that you can click on to see info like:

demo

N+1

While setup is easy, I was going to build a way for it to be enabled/disabled on a per-session basis so that developers could tur n it off and on as needed.  So I decided to make it into a nuget package.

The nuget package is here:

https://nuget.org/packages/MiniProfilerWebformsEnabler

and the source is hosted here:

https://miniprofilerwebforms.codeplex.com/documentation

Adding a reference to this from your web project will cause the StackExchange MiniProfiler to profile for all requests (by default), but only show them to you if you choose to enable it for your session.  To enable display of the values, you simply browse to ~/MiniProfiler/true (or false to turn it back off).

Because the MiniProfiler will cache up to 15 request profiling sessions, this means a developer can notice a page took a long time to load, and after it completes, browse to ~/MiniProfiler/true to see the profile session that contains the info for what caused the slow page processing on the earlier request.

If you don’t want the profiler to always be monitoring, you can disable it with

MiniProfilerHttpModule.AlwaysProfile = false;

in your application startup code.

By default, the application will also always profile local requests.  This can be disabled with:

MiniProfilerHttpModule.AlwaysProfileLocalRequests= false;

Fluent .Net State Machine

I was listening to an episode of DNR featuring Chris Patterson who is behind MassTransit, an open source .net service bus.  I’d recently been working a little with NServiceBus so I was interested to hear his take on the subject.  One of the interesting things to come out of the interview was a quick mention of another of his projects, Automatonymous, which is a .net state machine that operates in a fluent interface.

So for example:

public class BigComplexStateMachine :
StateMachine<BigState>
{
//declare states
public State InProcess { get; set; }
public State Delayed { get; set; }
public State OnHold { get; set; }
public State Delivered { get; set; }
//you get 'complete' and 'initial' for free


//declare events
public Event Ordered { get; set; }
public Event Delay { get; set; }
public Event Hold { get; set; }
public Event<CustomEventData> Deliver { get; set; }



//must NOT have arguments
public BigComplexStateMachine()
{
//inform the statemachine of your states
State(() => InProcess);
State(() => Delayed);
State(() => OnHold);
State(() => Delivered);

//inform the statemachine of your events
Event(() => Ordered);
Event(() => Delay);
Event(() => Hold);
Event(() => Deliver);


//define transitions
Initially(
When(Ordered)
.Then(state=> { /*do cool stuff */ })
.TransitionTo(InProcess)
);

During(InProcess,
When(Deliver) //notice the new param available
.Then((state, @event) => { /* do cool stuff */ })
.TransitionTo(OnHold)
);

//so on and so forth
/*
* During(state, When(event).[StuffIWantToDo].TransitionTo(state));
*/
Anytime(When(Hold) //also support an anytime concept
.Then(state=> { /*cool stuff*/ })
.Complete() //convenience method

);
}
}

Some more info here as well.

Telerik acquires Fiddler

Interesting move here by Telerik to acquire Fiddler.

http://www.fiddler2.com/fiddler/LetterFromEric.asp

http://www.telerik.com/automated-testing-tools/blog/christophereyhorn/12-09-10/here-we-grow-again-telerik-acquires-fiddler-what-s-next.aspx

I’m guessing they will integrate Fiddler into some type of testing framework.  I’ve used Fiddler a lot over the years.  It’s great for looking at the details of network traffic and diagnosing issues to do with HTTP of out of band requests.