Thursday, May 12, 2011

Great news! Jet Brains, the magicians behind Resharper and Team City, are out on a quest to save us from misery show us the light. dotPeek is their brand new .NET decompiler, still in early build, but live and kicking. I sincerely mourned the Reflector’s untimely “departure” and the timing couldn’t be better! The new tool is free-of-charge, which is against any commercial sense, according to the Red Gate. And I am pretty sure that Jet Brains will figure out some smart licensing, as they did with the awesome Team City (even if it won’t be free in the future, I’d rather pay for dotPeek, than Reflector).
The interface is pretty slick and should look familiar to Resharper users – it even has the same Usage windows! Tabs in the code window is definitely a welcomed addition. There are tons of other features which I didn’t have time to explore yet.
The only thing I am missing so far is the Reflector-style navigation using type names as links. There are few bugs, but remembering Resharper early days I am perfectly OK with it – Jet Brains proved that they can quickly react on user’s feedback. Application size is noticeably bigger, than Reflector but it will be probably eventually optimized down.
Undeniably the best part in this news – we have a choice again.

Saturday, May 07, 2011

How the heck does it work?! MSDN is surprisingly unhelpful on this matter (list of class members with couple of very obvious one-line snippets is a mockery of documentation).
Unfortunately, when configuring the IWorkflowInstanceManagement interface you have to be very precise. Let’s do it step by step, and while we are at that, let’s make the service implementation more WCF-compliant.1. Make your workflow service implement a contract. There won’t be a magic but rather a trick – the workflow service will think that it exposes an interface, name of which you typed in the ServiceContractName of your Receive shapes after {http://tempuri.org} (if you didn’t – do it) and it accidentally matches the interface with the same name in your code (or something similar to that).
In our case let’s name the XAML interface {http://TeddyBearStore.com/Contracts/}ITeddyBearService and our “artificial interface” - TeddyBearStore.Contracts.ITeddyBearService

2. Make WF service look like good old WCF. By default WF service, hosted in IIS is exposed as a magic no-name service: service tag is completely missing and only nameless ServiceBehavior allows some primitive configuration.

Very, very important for the Workflow Control Client – the service name must match exactly the ConfigurationName property (can be found at the top of the XAML file or in the Properties window in the workflow designer window).

4. Add standard endpoint description. They might be accessible by default but I did not bother to test this assumption, so add them in the web.config anyway. This is your last step for the service side.

5. Add client endpoints, one for your service (remember the “artificial” TeddyBearStore.Contracts.ITeddyBearService contract?) and another - for the Workflow Control Client functionality, which is essentially gives you an access to the AppFabricesque goodness. Note that the latter has /wce added to the address because the XAML service will refuse to expose both contracts from the same address.

["free community 30-day trial"] – … isn't our plan. We bought the website sqlserversentral.com a couple of years ago and there was similar concern from the sql professional community then. Since then we've kept the site free, removed most of the ads, upped the quality and multiplied traffic by 3 - there are now more than 850,000 members up from ~200,000 at the time of purchase. We've not ironed out exactly what we'll do with Reflector (because we've not had a chance to interact with the Reflector user community) but we bought it because it is popular and has a passionate user base - we'd be fools to damage either of those things. Simon Galbraith Joint CEO Red Gate Software

As it turned out he spoke the truth: there is no plans for the “Free Community 30-days trial” there is a “14-day Trial” version, it is a big difference, folks. Neither I can deny that sqlserversentral.com is still around – as a marketing tool, collecting emails from subscribers (oh, wait! I remember the site now – it is in my Google excluded searches list, because when you are in a hurry to find an answer, it offers you to register).

Wednesday, May 04, 2011

Don’t optimize your NuGet package libraries until you know exactly what are you doing. I screwed something up eventually, so when I tried to use the awesome “Add Controller” wizard, I’ve got “The term ‘Get-Scaffolder’ is not recognized as the name of a cmdlet…” error.

Tuesday, May 03, 2011

I would be definitely long done should I use my hammer familiar tools for the work, but I would miss all the fun. I am positively in love with MVC3 – the Microsoft team is doing an amazing job! Elegance with which they embrace the latest C# additions makes my cry Bazinga! Let me list some lessons I’ve learned so far on Crazy Project.

MVC3 Scaffolding – not just for Entity Framework

I almost got ready to bitch about MVC team again but discovered a neat expansion (it is fully expandable!) for the MVC 3 Scaffolding – in addition to default EF-centric and empty view templates it can use repositories. All you need to do is navigate to View->Other Windows->Package Manager Console in Visual Studio and type Install-Package MvcScaffolding. It would be nice to have them installed by default - all it does is generate CRUD-compatible Views and Controller and it really needs to know only the underlying entity type. It could cover 99% scenarios out there, including EF one.

MVC validation and Java Script manipulations

Building an interactive (Java Script-backed) form I hit a problem with the built-in validation (generated from Model validation attributes) – I was hiding some fields with Java Script but the validation was still firing for them. Quick search provided a solution: the Form element can be told to exclude fields decorated with certain class from the validation:

$("#myform").validate({
ignore: ".ignore"
})

Which means that no validation should be performed for a field decorated with the class=”ignore” attribute.

Unfortunately this didn’t work for me after I added the code snippet to my document.ready event (I guess, that I just misused the functionality but I don’t know better yet and hope for my audience help). As an immediate measure I had to change a bit the jquery.validate.unobtrusive.min.js file which is included with MVC3 template: right after success: a.proxy(j, d) text I added ,ignore: “.ignore”.

Similarly it should work in a wider scale: when ignore: “:hidden” rule is used instead, all hidden fields will be excluded from validation – the jQuery is smart enough to consider field hidden if it is inside a hidden container, like div tag. Search the jquery.validate.unobtrusive.js file for an unscrambled version of the code to understand better what it does – the resulting function should look like this:

I am new to MVC and jQuery, so I am stepping on the same mines, which my more experienced colleagues know by heart. I had this as my first jQuery exercise, which was returning a JSON list using AJAX get:

And GetItems action, which does the job, accepts only HttpPost verb, while another one by the same name throws back a HttpNotFound result (back to the nature!). The solution is not perfect, as POST is not that difficult to hack (of course I have a security on top of it) but at least it won’t be stumbled upon accidentally.

Shaping workflow service to WCF

The default implementation of the WF4 service, which can be seen in 90% of presentations, uses Service Reference. If you ask me it is a part of Poor Man’s SOA Toolset - an ugly and inflexible technique. Here is an excellent post about how to avoid it – “How to make a WorkflowService implement a contract”. A couple tricks with ChannelFactory and you have a Service Reference-less project!

Workflow correlation

The sad discovery of the day – workflow can not use the same operation twice. Which kind of makes sense and doesn’t at the same time. It is all about correlation – the area where WF4 shares voodoo magic with BizTalk. This particular post helped me to get better understanding the WF4 correlation. At least the sample is not using string-based correlation handler, unlike many others.