 Thursday, March 29, 2007
In a follow up to this post I made yesterday, it seems some people are annoyed that a Codeplex command line client exists at all... I still can not help but feel some people are missing the point of Codeplex all together... as I see it (and these are only my opinions on the matter) - Codeplex: - Supersedes the aging gotdotnet.
- Demonstrates TFS features
- Scalability for high volumes of users (not necessarily usability, but they're working on that)
- Case study for any large organizations considering deploying it across their organization.
- Provides a place Microsoft can.
- Host open-source projects for life.
- Control and support the environment.
- Keep a single message across their organization - we use TFS for source control from now on.
(At this point it's worth noting I'm a SVN/Trac/CC.Net guy myself... I can't actually justify the expenses of TFS at the moment)For me the reasons to use codeplex over another open source provider are simply: - It's different / new.
- It has a strong Microsoft / .Net focus.
- It's easier to get going for a newbie .Net developer (integrated source control in VS.Net, simple wiki pages baked-in)
- You can play with TFS.
They are reasons, but hardly "compelling" ones ;o) The beta command line client is a good thing, but to counter that "6 months wasted effort" with a call to replace TFS with subversion in Codeplex ... that just seems counter-intuitive to me... suddenly you have a roll-on effect of zero integration between source control and the in-built issue tracking mechanisms... so what, lets replace that with Trac??... and now that comes with it's own wiki... so ditch the existing one... and suddenly Codeplex is nothing more then a shell for managing file releases with some forums. What kind of message would it send to microsoft customers who have invested time and effort into team system... let's be reasonable, it's just not going to happen, so whats the next logical step... improve the tooling to work with the existing source control solution... first step to achieving that... build a decent command line client! So... if you are looking for subversion based hosting why not use well established players who have been supporting open source from the beginning like SourceForge or tigris... don't they still deserve your love now more then ever since Codeplex is on the scene... what better way to vote than with your choice of OSS project hosting? Codeplex is an alternative, not a replacement, for the likes of Sourceforge... perhaps what we need is a OssHostMatrix, much like WikiMatrix that compares feature for feature so you can pick the host that's appropriate to your project on features alone, rather then bitching about what's missing in Codeplex, when it's freely available elsewhere... I'm starting to feel sorry for some of the codeplex guys (like Jonathan Wanagel, who I commend for being vocal about what's going on at codeplex... he seems to pop up on a lot of blogs I read) ... they certainly do seem a little damned if you, damned if you don't at the moment - especially when progress is slowly being made and demonstrated.
If you have to make your own license keys i.e. ABCDE-ABCDE-ABCDE-ABC1Z-A32DE Here's some thoughts/ideas for things you can do to break up the key space a little so people can not easily brute-force your keys by fiddliing just a couple of numbers. - Select a range of numbers and letters that can be directly mapped to 32 values (10 digits and 22 alpha maybe?).
- Know your maths.. creating helper classes for unpacking and packing bytes will help.
- In this example you could carry 125bits (15 bytes and just over a nibble ;o) ... or 13 bytes + CRC16 (or Maybe an Adler16).
- Use lookup tables to translate sequential values into pseudo-random values.
- Break any multi-byte values up into individual bytes, stuff em around your payload of bytes in non-sequential offsets.
- Calculate the CRC for your payload and include it as part of the key's data, verify it when you're decoding.
- You can use structs with a sequential layout and a packing of 1 to define your structure...
- Use Marshal.Copy etc. methods to copy between the struct and a byte array.
- Remap individual bits in the overall payload.
The last one is something that works really well... it's hard to avoid certain digits "sticking" when generating sequential keys no matter what you do... but if you remap the individual bits of a 15 byte array (i.e. using a lookup table containing 120 indexes) you end up with very unique looking keys that have no sequential behaviour to them (especially if you redistribute the bits of the CRC into all the bytes of the key, which in turn are repacked into 5 bit letters).
 Wednesday, March 28, 2007
Cast your mind back... If you recall (maybe you don't) there was some discussion a while back about Codplex, TFS and the fact that it's a bit of a wash for creating an collaborative environment for an open source project... why? Well because of the chasm between developers for the project and those users who wish to collaborate by providing small patches, or working on the bleeding edge (i.e. checking out changes since the last time they build your project from source) Just to recap the big problems were: - No support for patches
- No anonymous check-outs
- No easy way to diff/merge between your version and the latest version on source control (because you could only get the source as a tarball).
In particular I remember Ayendes posts on the subject, which sparked a bit of debate on the whole issue (and even got some feedback from the codeplex developers themselves...) Codeplex's new command line client
Well it looks like one small step has been taken this week, check out this entry on the codeplex blog ... There is now a .Net 2.0 command-line client being developed, which will include support for: - Anonymous checkouts (hurray! dragging down a tar ball every time there were changes... what an arse that is/was)
- Merging
- Patching
I got all excited (well as excited as you can be about a command line client for TFS) and grabbed the beta... really all I cared about was anonymous checkouts... I like my open source medium rare (mmm... nothing like a fresh check-out of castle... release candidates never have any of the fun stuff!) But my hopes were dashed - it appears there's no way to skip the authorisation check as far as I can see, and when supplying my own credentials I didn't have access: c:\dev\tools\codeplex_client> cpc co reflectoraddins:/ c:\dev\resources\reflector _addins\
Username [snd\anonymous_cp]: bittercoder Password for bittercoder: ******** error: TF50309: You do not have sufficient permissions to perform this operation . ---> Attempted to perform an unauthorized operation.
I guess there's a little more waiting to go yet... Still, not to get too disheartended I decided to try it on a project I coordinate for (ye olde Splicer...) and I can certainly confirm it works... considering that the command line tools are less than 200K, this is already a great improvement over the current situtation... (about 250mb to download Team Explorer's iso). c:\dev\tools\codeplex_client> cpc co splicer:/ c:\dev\home\splicer_copy\
A c:\dev\home\splicer_copy A c:\dev\home\splicer_copy\src A c:\dev\home\splicer_copy\src\ASL - Apache Software Foundation License.txt .... and so on ;o)
So as you can see ... it does work... but I have to say it's pretty damn slow (could just be because I'm in New Zealand of course). At any rate... I'll be keeping my eye on it... there may be hope for codeplex yet ;o) ... and on one last note... the gui check-in looks a little like TortoiseSVN don't you think... hopefully the work towards some feature parity there.
 Monday, March 26, 2007
I've got a little project on at the moment which I chose to use ActiveRecord for... this is for a "legacy" database where there are existing nightly data warehousing scripts written against it... The cost of changing the database structure and tables is potentially quite high (it has run on effects to other systems, potentially effects SLA's when the nightly scripts fail.. and a small project ends up having a big impact)
At any rate, I'm just consuming the existing database as-is... which includes a single character status columns i.e. "A" for active, "P" for pending etc... after poking around with a few solutions I ended up creating an NHibernate custom type... first off, this was surprisingly easy... but it annoyed me a little that I had to create a different custom type for each set of enumerated values, and that this information was no longer declarative, compared to the rest of the ActiveRecord implementation... So I took a few minutes to re-write it as generic solution to the problem today... which at least solves the declarative problem... first off, here's a property with the custom type applied - nothing amazing here, but notice the type is generic... with the type of status field itself qualifying the generic custom type... [Property("dBlrStatus", "App.Model.MappedEnumerationHibernateType`1[[App.Model.Status, App.Model]], App.Model")] public virtual Status Status { get { return _status; } set { _status = value; } } We then declare the mappings on the enumeration itself... public enum Status { [MapToCharacters('A', 'a', '+')] Active, [MapToCharacters('I', 'i', '-')] [Default] InActive } I think this is a good fit for ActiveRecord... If anyone wants the code at some point just leave a comment and I'll package it up and post it... it's pretty elementary stuff, though it might save some time if you wanted to re-implement it yourself...
 Tuesday, March 20, 2007
Well as the more observant reader of Alex Jame's Blog might have noticed, I'm talking at the the Architect Camp 2007 this year... which should be...interesting - I haven't done any public speaking for a while now, but Alex James assures me I'll be fine ... be it on his head! ;o) ...
So I'm planning to talk about IoC (Inversion of Control) - one of my little pet loves... Some of the subjects I'm considering include: - Coupling
- How do we couple (Message, data, content etc.)
- Metrics for the architect (Instability vs. Abstractness etc.)
- Dependency Injection
- Constructor dependencies
- Parameter dependencies
- Law of Demeter
- Inversion of Control
- Why bother?
- Added flexibility and opportunity
- Lowering the cost of change
- ServiceLocators
- Inversion of control containers
- What's available (Castle, Spring, StructureMap etc.)
- Autowiring
- Services
- Lifestyle vs Lifecycle
- Configuration
- AOP
- Patterns
- Decorators
- Facilities
- Arrays (simple contributor patterns etc.)
But that's only a small brain dump... we will see what actually gets in there. For anyone who's thinking of attending this event, anything in particular you would like to have covered in a little more depth... or have you had any exposure to IoC at all?
Well first off... where has this month gone??... it's been 2 weeks since I last blogged... I thought it was only a week! At any rate, one of the things I've been working on lately is mocking out COM interfaces (using RhinoMocks of course) ... and I have to admit that my eyes start crossing after a while, at about the point where the mock repositories setup code begins dominating the test case... which happens all too often... here's a smaller example of what I'm talking about: MockRepository repository = new MockRepository();
TaggedValue oneTaggedValue = repository.DynamicMock<TaggedValue>();
Expect.Call(oneTaggedValue.Value = "").Constraints(Is.Equal("ExpectedValue"));
Expect.Call(textAlignTaggedValue.Update()).Return(true);
TaggedValue anotherTaggedValue = repository.DynamicMock<TaggedValue>();
Expect.Call(anotherTaggedValue.Value = "").Constraints(Is.Equal("AnotherExpectedValue"));
Expect.Call(textAlignTaggedValue.Update()).Return(true);
Collection taggedValuesCollection = repository.DynamicMock<Collection>();
Expect.Call(taggedValuesCollection.GetByName("")).Constraints(Is.Equal("OneTaggedValue"))
.Return(oneTaggedValue).Repeat.Any();
Expect.Call(taggedValuesCollection.GetByName("")).Constraints(Is.Equal("AnotherTaggedValue"))
.Return(anotherTaggedValue).Repeat.Any();
Element destinationElement = repository.DynamicMock<Element>();
Expect.Call(destinationElement.TaggedValues).Return(taggedValuesCollection).Repeat.Any();
repository.ReplayAll();
So in this case we have an "Element", which has a collection of "TaggedValues", and we have two tagged values "OneTaggedValue" and "AnotherTaggedValue", and for each we are updating their values, and then invoking "Update()" on them to flush the changes...
To help solidify that, here's an example of what we're expecting to happen to our element (Element, Collection and TaggedValue are all interfaces from a COM interop assembly, in case you were wondering):
Element element; ... TaggedValue oneTaggedValue = (TaggedValue)element.TaggedValues.GetByName("OneTaggedValue");
oneTaggedValue.Value = "ExpectedValue"; oneTaggedValue.Update();
TaggedValue anotherTaggedValue = (TaggedValue)element.TaggedValues.GetByName("AnotherTaggedValue");
anotherTaggedValue.Value = "AnotherExpectedValue"; anotherTaggedValue.Update();
Now normally in this case I take unit tests once I've got "green" and refactor the mocking code out a bit... so in the above case I'd probably end up with something like:
MockRepository repository = new MockRepository();
Collection taggedValuesCollection = repository.DynamicMock<Collection>();
AddTaggedValueSetter(repository, taggedValuesCollection, "OneTaggedValue", "ExpectedValue");
AddTaggedValueSetter(repository, taggedValuesCollection, "AnotherTaggedValue", "AnotherExpectedValue");
Element destinationElement = repository.DynamicMock<Element>();
Expect.Call(destinationElement.TaggedValues).Return(taggedValuesCollection).Repeat.Any();
repository.ReplayAll();
Which works... generally quite well... but lately I've been moving away from that approach and instead have been refactoring the setup code into a fluent interface... which I've found to be a lot easier to maintain and extend (and tends to be a little more re-usable across multiple test fixtures...)
So for example, this is what the setup code for the above mock element is now:
MockRepository repository = new MockRepository();
Element element =
Mock
.Element()
.HasTaggedValue("OneTaggedValue").ExpectSetValue("ExpectedValue")
.HasTaggedValue("AnotherTaggedValue").ExpectSetValue("AnotherExpectedValue")
.Complete(repository);
repository.ReplayAll();
I'm just skimming the surface of what I've been doing, but it might be food for thought for anyone working on similar projects... anyone else doing similar things?
 Tuesday, March 06, 2007
Have you ever wanted to be able to do something like this in C#? string propertyName = GetName(MyClass.MyProperty);Well I have, in fact I've wanted the ability to do this since Version 1 of the .Net Framework, and now with C# 3.0 we finally can! First off, check out the original blog post here - Symbols in C# 3.0 by Jafar Husain - it's a clever (and once I thought about, plainly obvious) use of extension methods and expression trees.
public static class SymbolExtensions
{
public static string GetPropertySymbol<T,R>(this T obj, Expression<Func<T, R>> expr)
{
return ((System.Linq.Expressions.MemberExpression) (((System.Linq.Expressions.LambdaExpression)(expr)).Body)).Member.Name;
}
}
Usage requires a lambda, but that's not to painful, here's example usage:
MyClass o;
//...
string propertyName = this.GetPropertySymbol(o => o.MyProperty)
The beauty of this is that refactoring is entirely painless, you don't need to spend time reviewing all the optional string replacements that resharper may have found in case you haven't mirrored a property or method name change correctly... it also looks like it could offer some nice usability improvements to some unit testing scenarios (nothing worse then unit tests that don't seamlessly refactor with your code). I wonder what other ideas are floating around for expression trees at the moment (outside of the obvious querying concepts) ?
 Saturday, March 03, 2007
Dumping eventsI'm often surprised (or is it dismayed) when questions pop up in news groups surrounding things like event orders for winforms or webforms applications... this isn't rocket science... we're given all the tools to make this easy to figure out! Lets do a winforms 2.0 app as an example... first off, the earliest point at which can easily get involved is the constructor... lets have a look:
public partial class Form1 : Form
{
public Form1()
{
AttachToAllEvents();
InitializeComponent();
}
So I'm going to attach to all the events before the forms components are initialized... now lets have a look at the " AttachToAllEvents" method.
private void AttachToAllEvents()
{
Type type = GetType();
foreach (EventInfo info in type.GetEvents())
{
string eventName = info.Name;
EventHandlerWrapper wrapper = new EventHandlerWrapper(new EventHandler(
delegate
{
Console.WriteLine("{0}: EventName: {1}, IsVisible: {2}, IsHandleCreated: {3}, HasChildren: {4}, IsDisposed: {5}",
DateTime.Now, eventName, this.Visible, this.IsHandleCreated, this.HasChildren,
this.IsDisposed);
}));
wrapper.Attach(this, info);
}
}
Only magic there is we're using a class called " EventHandlerWrapper" - what's that... well, it's used to create a strongly typed delegate for attaching to an event. The reason we need this at all is because EventInfo.AddEventHandler(...) is fussy about the kind of delegate you supply, so if you pass in an " EventHandler" for a " CancelEventHandler" event, it'll throw an exception complaining about it's inability to cast between them... there might be an easier way to do this, but I haven't come across it so far.
public class EventHandlerWrapper
{
private EventHandler _handler;
private static readonly MethodInfo _methodInfo;
static EventHandlerWrapper()
{
_methodInfo = typeof(EventHandlerWrapper).GetMethod("InvokeHandler", BindingFlags.NonPublic | BindingFlags.Instance);
}
public EventHandlerWrapper(EventHandler handler)
{
if (handler == null) throw new ArgumentNullException("handler");
_handler = handler;
}
public void Attach(object target, EventInfo info)
{
Delegate wrappedHandler = Delegate.CreateDelegate(info.EventHandlerType, this, _methodInfo);
info.AddEventHandler(target, wrappedHandler);
}
private void InvokeHandler(object sender, EventArgs args)
{
_handler(sender, args);
}
}
With a little brain power I'm sure I could've done this without the separate wrapper class, but this is probably a little easier to read at any rate. Results..?So.. onto the results - once we run the code and see exactly what order events are happening in, we can then make a pretty table that may not render in most browsers because I cut 'n pasted it from Excel 2007 ;o)
| EventName |
IsVisible |
IsHandleCreated |
HasChildren |
IsDisposed |
| Resize |
False |
False |
False |
False |
| SizeChanged |
False |
False |
False |
False |
| ClientSizeChanged |
False |
False |
False |
False |
| ClientSizeChanged |
False |
False |
False |
False |
| ControlAdded |
False |
False |
True |
False |
| ControlAdded |
False |
False |
True |
False |
| StyleChanged |
False |
False |
True |
False |
| TextChanged |
False |
False |
True |
False |
| Move |
False |
True |
True |
False |
| LocationChanged |
False |
True |
True |
False |
| HandleCreated |
False |
True |
True |
False |
| Invalidated |
False |
True |
True |
False |
| StyleChanged |
False |
True |
True |
False |
| ChangeUICues |
True |
True |
True |
False |
| Invalidated |
True |
True |
True |
False |
| BindingContextChanged |
True |
True |
True |
False |
| Load |
True |
True |
True |
False |
| Layout |
True |
True |
True |
False |
| VisibleChanged |
True |
True |
True |
False |
| Activated |
True |
True |
True |
False |
| Shown |
True |
True |
True |
False |
| Paint |
True |
True |
True |
False |
| Paint |
True |
True |
True |
False |
| Paint |
True |
True |
True |
False |
| MouseCaptureChanged |
True |
True |
True |
False |
| Closing |
True |
True |
True |
False |
| FormClosing |
True |
True |
True |
False |
| Closed |
True |
True |
True |
False |
| FormClosed |
True |
True |
True |
False |
| Deactivate |
True |
True |
True |
False |
| HandleDestroyed |
True |
True |
True |
False |
| Disposed |
False |
False |
False |
False |
The main thing to keep in mind when doing something like this is to avoid making assumptions - we may not be the first or last to attach to the events (depending on the complexity of the form) - and events can trigger other events... which could explain the ordering of some of this data i.e. changes in visibility and handle creation... if anything we are viewing the order of consequences, as opposed to the true order in which the events are invoked (to get that we'd need to override all the OnXXXX methods of the form class... which would be a good job for dynamic proxy :)
 Thursday, March 01, 2007
I've been using tortoise SVN for a couple of years now... but I'd never seen this dialog before when renaming files with similar name patterns... probably old news to some people, but it pleased me no end, very helpful!  It's these kinds of features that I like about an explorer based SCM client... I find IDE integrated source control just bugs me now days (like Team System which I use for codeplex).
 Wednesday, February 28, 2007
In the last post about WiX shortcuts
I detailed how to make an unisntall link... it was actually slightly
wrong ;o) ... well at least if your product Id wasn't surrounded with
braces... so here's the offending line fixed for product Guid's that
aren't surrounded with braces (which is generally what you should be
using in a WiX file)
<CustomAction Id="SetUninstallArgs" Property="UNINSTALLARGS" Value="/x {$(var.PRODUCTGUID)}" />
As you were...
© Copyright 2009 Alex Henderson
Theme design by Bryan Bell
newtelligence dasBlog 1.9.6264.0  | Page rendered at Tuesday, January 06, 2009 12:49:02 PM (New Zealand Daylight Time, UTC+13:00)
|
Search
FeedCount
Tags...
|