Microsoft Script Control as a Server Component

The Microsoft Script Control MSScript.ocx is a simple to use component that allows you to host VBScript scripts within your own application. Althought it has been implemented as a control it is very easy to use the underlying script component without involving any UI. However, I’ve recently learnt that things are not as they seem.
 
Using the Script Control as a server component, especially where concurrency is important, is not a good idea. The problem is that the control is written as Appartment threaded, what this really means is that it’s running as a Single Threaded Apartments (STA). So what? Well consider the following:
Clients A and B both invoke the Script Control at time X. The Script Control contains a VB script that takes Y seconds to complete. Client A is fractionally ahead of B and starts the running the VB Script. Now since the Script Control is running on a STA only one thread can be active at any one time. Therefore B is blocked until the control has completed running the script for A. The upshot of this is that the response time for A is (Y-X) whereas for B it is (2Y-X). For N concurrent users this would mean the Nth user would have a response time of (NY-X), obviously bad news.
 
So as nice and easy as the MSScript.ocx is to use, I would recommend staying well away from it where concurrent access is going to be an issue.

Anti Virus and Visual Studio

The projects I work on are typically big. The frustrating thing about this is that when I "build" the project my Anti-virus tool (McAfee) constantly checks everything. It accounts for up to a 1/3 of the build time! So not only do you suffer from getting a virus, you suffer for trying to avoid them. My advice is to turn off "On-Access scan" whilst building. Far from ideal but what choice is there?

struct vs class

I was musing about if I should write a struct or a class today and a collegue pointed out, the obvious, that if I wanted to use it in any form of list or collection then a struct would need to be boxed. So there it is, a very simple way to help decide if you need a class or a struct. Sometimes you can’t see the wood for the trees.
 

DotNetNuke and Stylesheets

My Dad has recently started subscribing to a portal site for his business and was asking about how to style the site correctly. After a cursory look I realised that the site was in fact a DotNetNuke portal. Fine I thought, just write a new skin and off we go. However, in their great wisdom the portal administrator had switched off any ability to add/change skins, so we’re left with the default skin. The problem is that the default skin is churning out a terrible mixture of structure and layout HTML making it almost impossible to style correctly. I’ve really struggled to make them understand why their portal is currently so terrible because of it. This company is one of those companies that give the IT industry a bad name. They pick up a product, which is free, and take money from unsuspecting customers but provide them with a rubbish result because they cannot either understand or be bothered to use the tool properly in the first place. I’m sending them a link to a What is CSS FAQ in the hope they can at least read about CSS.

Extension methods

After watching a Dot Net Rocks TV show about LINQ I’ve become a bit concerned about some of the supporting changes to the underlying compilers. The first of these changes is the ability to create a class on the fly without any strong-typing, at least as far as the compiler is concerned – intellisense still works. I can just about swallow that on the grounds that it should only be used to speed up development in very specific cases…actually I’m not sure I can. But then came Extension Methods. From what I can gather the idea is that you can write a new method that acts upon a specific class and then you can inject or "extend" the class with your new method. So for example I could write:
 void function AppendGoodBye(ref string message){message+=" goodbye"}
 
which would mean I’d call it like:
string message = "I say ";
AppendGoodBye(ref message);
 
With an Extended method (and I’m not 100% on the exact syntax) you write something like:
void function AppendGoodBye(this string message){message+=" goodbye"}
 
you’d then call it like:
string message = "I say ".AppendGoodBye();
 
i.e. you’ve extended the string class.
 
Now at face value that’s all very clever, but I’m worried it’s gonna’ break the OO wide open. If I want to maintain that code where do I go looking for it? Normally I’d be looking in the string class, but where do I look for it now? Seems like a step in the wrong direction to me, I need to read a bit more about this.

Domain Specific Languages vs. UML

I’ve been keeping a sceptical eye on Software Factories and Model Driven Architecture (MDA) for some time so I was very interested to see a Domain Specific Language (DSL) API spring up in the latest drop of Visual Studio. I thought I’d better do some reading around the area to try and understand its goals. During my "travels" around the web I came across the following blog, Jack Greenfield’s Blog. Amongst other things it talks about an on going debate about using UML for MDA (and for Software Factories in general) vs. DSL. Now all the arguments for and against each one are all very interesting and exactly the sort of thing to get real-ale drinking software architectures in a bother, however for me there is one clear advantage for DSL…the average user. I don’t think I’d be burnt at the stake for suggesting that as good as UML is, the majority of people successfully cherry pick UML in order to describe/document their solution, very few would take it through every stage. Again I don’t really want to get into a debate about why people don’t use UML I just want to state that, rightly or wrongly, people don’t believe it is some kind of silver bullet/fits-all language. This brings me to my point (hurray), so far I’ve been talking about people in the software business what hope have we in convincing Joe public to use UML? As much as we like to make our solutions generic it often becomes more complicated for the average user. Did the average user welcome the fact that they could use VBA in Word and Excel? Sure the developers (and hackers) did but did the average user? I’d suggest not. What the user wants is something that talks in the language they understand. So for Word they’d probably want something that talks about text changes, font formatting, picture adjustments, spelling, etc. For Excel formulas, statistics, graphs, etc. Now sure there is some common ground that could be exploited but basically the domains are different. So assuming that I’ve established that the user wants domain specific tools how to best address that? This is where the arguments of DSL vs. UML step in. But wait, if we can’t convince the software development community about UML how on Earth are we going to convince Joe public, surely it will be better to provide specialised DSL for the users problem domain? "But they’d have to learn a new tool/language for every one", I hear you cry. True, partly. This brings me back the cherry picking of UML. Personally I feel UML is too verbose and clumsy to be used "correctly", but what it is great at is conveying ideas and requirements without necessarily concretely specifying them. E.g. I can draw an interaction diagram describing how to spell check and save a Word document, but I wouldn’t feel it necessary to write out a full class specification for a Word document so I could include it in the interaction. I realise this might shock the purists but I’d argue that the real goal of UML is to successfully convey the requirements and to describe the solution. I believe it is successful at this because the concepts of shapes and flow are pretty easy to understand even without formal training. Therefore I believe that providing you implement your DSL using fairly simple concepts but still talk in the context of the domain you can take the reusable parts of UML and still provide the average user with a toolset they can understand.

Visual Studio 2005 and Remote Desktop

For some strange reason Visual Studio runs really poorly in a Remote Desktop session. I guess it’s something to do with not being the main interactive desktop? Anyway one way around this problem is to use the lesser known /Console flag when starting up the Remote Desktop client…mstsc.exe /console
 
This enables you to access the interactive console and VS2005 works again. Of course its also useful for grabbing the current users console but not great if you’re trying to share the machine. Still you’re unlikely to be wanting to share VS2005 between many users, it’s not exactly shy when it comes to resources.
 

Remote Debugging using Visual Studio 2003

I got into one of those situations when I need to debug a bit of software of a server but I couldn’t install Visual Studio. So for the first time I stepped into the world of remote debugging. It was actually fairly painless, although I did cheat and went the not-recommend route of adding, ahem, myself to the local administrators group.
The basic steps are…
  1. Install remote components (not full blown Visual Studio), found in the install root of VS. A bit annoying you have to install anything but the client was ok with this
  2. Add your interactive user into the remote servers "debug users" group (and possibly the administrators account or discover the permission necessary to access a running process)
  3. On the remote server run; msvcmon -tcpip -anyuser Note that you can specify the correct user but if you’re not too concerned about security then this is a simple short-cut. Also read what it says, it will stop listening after a period of time (15 mins by default) 
  4. In Visual Studio open the process dialog and type in the name of the server
  5. Attach to the process and off you go

Apparently you can start the remote process off from Visual Studio too, but for some reason it wouldn’t let me specify the location. Since I was using Remote Desktop to control the program on the server it wasn’t a problem.

Wake Up On Lan

Recently I’ve wanted to remotely start up machines, either because a machine the other end of VPN is down or I can’t be bothered to walk upstairs and turn on a desktop file server whilst using a laptop! What started off as a simple process seemed to have a number of gotcha’s that I thought I’d record.
 
The basic premise is that if your machine has a network card that support Wake Up On Lan (WOL) then if you enable this setting you can…wake the machine up via the network. There seem to be various ways of doing this but I chose the "Magic Number" approach using a utility called MC-WOL.EXE.
 
The basic steps in using this little program are:
  1. You first need to discover the MAC address of the network card in question. To do this I ran a command window on the target machine and entered "IPCONFIG /ALL". Note down the address of the card, it’s not the IP address but a series of hex numbers normally "-" separated.
  2. Ensure the machine’s BIOS is configured to accept WOL. This usually requires rebooting your machine and going into the "setup" for the BIOS. Locate your network settings and ensure that WOL is enabled. Note that on some systems you can have conflicting settings. So Wake Up from Hibernation settings often conflict, see you BIOS/Motherboard settings for more details.
  3. Switch your machine off and run MC-WOL from another machine.

This should work, however there are a number of gotcha’s.

  1. Firewalls. I only use this via a LAN or VPN so I’ve not had this problem but for sensible reasons a firewall can get in the way of your call. This is good news since you don’t want people on the internet starting your machines up.
  2. "Soft" and "Hard" shutdowns. This was the first time I’d come across this concept. You can shut a machine down in two different ways. For example, pressing Shutdown in Windows produces a Soft shutdown and the machine can normally be woken up. Hold the power button and switching the machine off results in a Hard shutdown and it won’t wake up. This is annoying since the reason you want to wake a machine might be because someone’s turned it off or ’cause of power cut, et al.
  3. Operating System settings. The BIOS changes aren’t always enough. Sometimes you have to go into Hardware Manager, select the network card and look at its settings. My cards have "Use Magic Number" or "Enable WOL". As you see there doesn’t seem to be a standard so look for something that sounds like Wake Up…not great instructions but there you go.

Testing for Safari when you don’t have OSX

Developing using Microsoft technologies can make it expensive to test your site for other browsers and platforms. IE, Firefox and Opera can ease (or maybe that’s make things harder) to test your site. However, the big bugbear is OSXs Safari. Well until the OSX86 project managers to make it legal to run OSX on any PC I think it boils down to…
  1. Buy a Mac – nice if you afford it
  2. Use a screen shot service – pain to use if your site has any kind of dynamic changes, lets face it they’re a pain to use full stop
  3. Use another KDE based browser

Option 3 is the one I’m currently recommending. Safari is based upon the KDE browser engine, so why not use another browser that uses the same fundamental rendering engine, e.g. Konqueror. Well, the first problem is if you’re running Windows there currently isn’t a version for good ole’ Windows. The answer is turn to Linux, well sort of. My advice is to get hold of the VMWare player with a downloaded image of your favourite flavour of Linux, mine is Ubuntu (if only for the name). Install Konqueror and off you go, Safari like browsing without OSX. It’s not a 100% guarantee, but you’ll iron out the most obvious problems.