Monday, June 8, 2009

using an XSD.exe generated class

When you have an XSD you can use XSD.EXE to generate a class. This can then be used so that you modify properties that will be mapped and serialized to XML nodes as defined by the XSD.

Some concerns though:
- The cs file generated from the XSD through XSD.EXE would by default use an array for anything with multiple cardinality. This is a major pain, so i'd change that to
List <MultipleStuffType >
.
- You must also add a default empty parameterless constructor to your generated type as the XML serialization might not work otherwise.
- Finally, XmlTypeAttribute(AnonymousType=true) to false on a class that is defined as true by default.

Once that is done, you can nicely poke around on your class instance and when you feel fit, serialize:

static XmlSerializer _serializer = new XmlSerializer(typeof(RootElementType), new Type[] { typeof(RootElementType), typeof(List < MultipleStuffType > ), typeof(MultipleStuffType) });

using (TextWriter writer_ = new StreamWriter(targetFile))
{
_serializer.Serialize(writer_, xmlClassInstanceYouWorkedWith);
writer_.Flush();
writer_.Close();
}


and vica versa:

RootElementType stuff_ = (RootElementType)_serializer.Deserialize(XmlReader.Create(targetFile));

Wednesday, May 27, 2009

configuring BITS

Nice that there is something like BITS for leeching files through HTTP (right, over firewalls..). The downloads proceed as long as the account which started the job is logged on, not too bad.

You need an IIS on the server with a virtual folder to store the files, the client would use the BITS api (better yet, a wrapper ) to transfer the files via a standard HTTP URI.

SharpBITS is yet another wrapper, did not work for me though... (i only use the GUI to manage my jobs).

So far so good, but how about configuring?

There is an innate way to configure the server if you want to upload from the client to the server. This IIS addon allows for tweaking the virtual folder to some extent, but what about the real stuff?

Now Group policies to the rescue!

Just type gpedit.msc on your cmdline and check out Computer Configuration\Administrative Templates\ Network\Background Intelligent Transfer Service.

In case you find nothing there (default for Win XP), download the ADM pack from MS, install it , then right click on the templates node in the group policy editor to add a new template. Make sure to add system.adm so that the BITS policies become available.

If you want to optimize for downloads, this is a good start.

Tuesday, May 26, 2009

creating a unique soapUI testing parameter

There's a good article here on how to assign a changing value to a parameter. This way it's possible to run the test days on end and yet submit the test data under a different name / id to pretend real usage (and allow for tracing on the server end.)

cool stuff!

Monday, May 18, 2009

HTTP MSMQ - the name of the game

Weird enough that i spent a day on this... you can find plenty of (mis)information on how to use MSMQ over HTTP (through a firewall). This link here is one of the better ones..
in fact for me the ONLY way it worked is the following syntax:

FormatName:DIRECT=HTTP://remote.machine.com/MSMQ/PRIVATE$/queuename

so that is, all uppercase, and the queuename all lowercase. All other options either did not even turn up in the output queue on the sender side, or just locked in there. No IP address for me, no no..

So once you got this straight and can now send to a remote machine via the firewall, you will recall that XMLSerializer processes only the public members of your class you will send through...

And then on the remote end read locally as .\private$\queuename for full delight.

Wednesday, March 25, 2009

Moq

Just spotted a flashy new .NET 3.5 supported mocking framework,Moq. I just love how little infrastructure code you need to use it.. just check this.

Also, on the "this" link the author notes "As every mocking framework, except TypeMock which can perform differently, every mocked class can't be sealed and methods that need to be mocked need to be public. If the class is not inheriting from an interface, the method that are being mocked need to be virtual." - which is a sentence i missed to find declared before somehow.. Yet important to know the rules in ballpark we're in.

Which brings us now to the question, which game is that? On this link we can find some real discussion referenced.

Seems like "TDD and the sort may hurt you", or "the lack of TDD-wise thinking may hurt you..."

Not sure how to think about it, probably the context and scope of a project dictates if you want/can afford to follow the religion (and be TDD-compilant -embrace the statement above and desing accordingly-, do not crack stuff open with TypeMock, but adhere to something like Moq or Rhino is meant for).

But it may be that you just have a plain old sort of project, trying to deliver this and that, and TypeMock comes in handy for the production team (not aiming at TDD, shall we always?) to raise the QA bar a bit.

Alas i was too much involved in producing "good enough" software rather than "good" software.. the customer had some dollars to spend, and they merely wanted the acceptance tests to pass.. no time / investment into niche stuff that obviously improves the code, but what does a business forecaster care if the code sucks, it should just work per the requirements..

I wish software development was a trade / skill generally accepted in its own right, it's practicioneers be asked to contribute to their best knowledge.. not under silly constraints of ROI and TCO. Quality is not something you can put in, they say. Well, i think it may be true, since the whole job got to be done right, but still.. there are ways to put in some ingredients which add some quality.

Whether it's TDD or just some "police code" created with TypeMock.. beats me, probably a question of state of mind..