Please click this logo to help me get on their beta program:

Xobni outlook add-in for your inbox








7/7/2008

Feedback on my NxtGenUG Fest 08 session - Handling data in F#

Filed under: General — Oliver Sturm @ 3:40 pm - 2 weeks, 5 days ago

It occurred to me today to look at the feedback that a lot of you have left for the session I did at the NxtGenUG Fest 08 event a few weeks ago. Thanks to everybody who did so, it’s always appreciated!

Now, there are a few points I’d like to comment on - feedback as usual was varied, the overall average not too high… but that’s to be expected, especially with a topic like that in the context of the day.

To the 21 people who left an 8 or 9 rating - thanks! There’s not much to say about this since comments were very positive.

The comments on the 7s are a bit more interesting - some of them are still positive, some others are more critical. In order of appearance in the list.

> Second time in a row Oliver has overrun and not covered everything on his agenda, the same happened last year with his WPF session. He needs to work on his timings.

Hm… well, I don’t agree. Perhaps I should post about this in general, because apparently my point of view in this regard isn’t well understood - I get comments about this all the time. In a nutshell, my sessions typically include content that most likely I’m not going to have time to present. The reason it’s in there (in the form of slides and/or samples) is because I found it interesting during the research phase of session preparation and I’m thinking it might be interesting to the people who download my slides and samples after the presentation. It might also come in handy when I deliver the presentation again, with a slightly different target time (this varies a lot from event to event - everything between 55 and 90 minutes for a session slot is quite common). If I remember, I try to explain this in most sessions - I don’t remember whether I did this time or not.

Of course there are also considerations specific to the event in question. For starters, Dave insisted when he talked to me that I submit something entirely new, not something that was previously done elsewhere. Looking at the presentations I saw on the day, I have my doubts whether everybody adhered to that rule, but I did - as a result, this was a first run for the presentation, and these will always be a bit less perfect on timing than subsequent runs, no matter how well prepared somebody is.

Finally, of course, I didn’t run over - I simply adjusted the session content to fit the time frame and left out a few minor bits at the end because time didn’t allow for them. If you don’t like it, my apologies - these bits and bobs are out there in the wide world whether you like it or not. As it is, they are included in the slide deck, and it seems you’re saying I should have left them out. Go figure.

> I think the session would have benefited from getting onto the code samples sooner.
> Whetted our apetites, but didn’t make time to cover the more exciting parts.
> Super fast, but I enjoyed having an introduction to this.
> I thought drilled too quickly into the code examples.

Yeah well… what are you going to do in 60 minutes, when 90% of the audience are on the "F-what?" level to begin with? And as you can see, this is a subject that splits any audience…

> There was no sense of where this language’s niche was.

Fair enough - I can’t tell you though. Still waiting on the MS niche definition committee to finish its work. In the meantime, just listen, get up to speed if it sounds interesting, and make up your own mind.

> In places I felt that the presentation and samples could have been tightened up a bit. Removing a bit of waffle.

Interesting to hear that - I don’t think the majority would agree that there could have been much more in it though.

> Oliver picked an interesting subject, but could really have benefitted from giving a concrete reason for using this language - the benefits of functional languages over imperative perhaps? As it was: interesting but ultimately not useful for everyday coding

I was leaving that part open to your own imagination at this point. I think I did mention areas in which people are currently using F#, and of course general internet content about functional programming will bring up a lot of ideas. Anyway, I think you got the right impression - for the majority of developers, F# is probably not an everyday programming language today, and who knows if it will ever be.

> … I was left wondering why I would choose to use it for data access over c#

I wasn’t saying you would. Some of the techniques I showed were from the functional part of the programming world, but that doesn’t mean you can only use them in F# either. In general the session was supposed to be an introduction to the language and some of the more obscure (from the typical .NET programmer’s point of view) practices, as well as to point out that F# is a .NET language after all and a lot of the standard technology can be used just as easily as it can from C#.

> Interesting stuff… though more of an introduction to F# than handling data!

Yes, that’s what it turned out to be. Or at least it was half and half, I guess… the NxtGenUG guys always ask for bleeding edge technology and their event focus was where the data handling part came from. On second thought, it turned out that the necessary basics took up a bit too much room in this presentation. Will have to ask for a double slot next time, to do a separate introduction and the data handling thing in its whole glory :-)

> I liked the happy go lucky presentation style

Eh? :-)

> … it was too left field for a mainstream session ….

I agree. It wasn’t supposed to be a mainstream session. The way I’ve always understood it, the NxtGenUG Fest isn’t supposed to be a mainstream event.

> personally I dont and neither did anyone around me have any real interest in F#

Out of the other 52 who left feedback, around 48 did though.

> Really not sure

I think the answer is 42. :-)

1/7/2008

Remapping Command keys to Ctrl in VMWare

Filed under: General, Mac — Oliver Sturm @ 5:19 pm - 3 weeks, 4 days ago

On the Mac itself, I have remapped the caps lock key (does anybody actually use that thing these days?) to Command (that’s the key with the weird symbol… ah well, one of the keys with weird symbols <g>) . I had always done the same thing on Windows, where it required registry changes, so I was positively surprised to find that on the Mac it’s just a system preferences option… Microsoft, here’s how you do that kind of thing:

200807011814.jpg

Now, while I’ve found it useful on the Mac to have the Command key easily accessible (although Ctrl is still used in too many places, like terminals and things… gotta find a solution to that), that key is recognized as a Windows key in VMWare. So I changed one of the registry trickery files so that the Windows keys get remapped to Ctrl for use in Windows. Works like a charm. Here’s what the content of that .reg file looks like:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,5B,E0,1d,00,5C,E0,00,00,00,00

Hope it helps somebody!

14/6/2008

Blogging from my new MacBook

Filed under: General, Mac — Oliver Sturm @ 10:59 pm - 1 month, 1 week ago

Would you believe it, I got a MacBook recently. It’s fantastic, there’s no other way to describe it. OS X is amazing, Windows apps seem to run faster in VMWare Fusion than they do on native Windows, and the applications are just… well, can’t find any more superlatives. Holy cow!

I’ll certainly post more about this in the future. I’m not planning on abandoning Windows, or .NET, or anything like that - on the contrary, I want to see what other platforms have to offer these days, be it for competition or compatibility. Mono is supposed to be able to run most Windows Forms apps these days, I hear… now I only need some time :-)

If you haven’t had a look at the Mac since they started building Intel based machines, go do so as soon as you can. You are really missing out.

8/6/2008

TechEd done, NxtGenUG FEST 08 is next

Filed under: General — Oliver Sturm @ 4:16 pm - 1 month, 2 weeks ago

I’m still in Orlando now, but later today I’ll be on a refreshing (?) flight back to the UK. TechEd was very good — lots of people very interested in DX products, we won loads of awards and had a good laugh about the Telerik guys ;-)

Later this week I’ll be in Reading for the NxtGenUG FEST 08 event on June 12th. Hate to state the obvious, but it’s the 2008 incarnation of their yearly FEST event. A day of great speakers and sessions, the usual (well, usual for NxtGenUG standards — if your’e not familiar with it, be prepared to be amazed) assortment of swag, pizza and so on… It costs a bit of money for non-members of NxtGenUG, but it’s still quite a bargain at 49.99, and of course it’s free for members. Sign up is here, and there’s a G(r)eek dinner the night before. Originally it was planned to send Daniel Moth off to the states, but now I hear he can’t make it to the dinner… anyway, if you happen to be in Reading on the night of the 11th, sign up here and join us for the geek dinner!

Right, that’s it — I have some sessions to prepare…

21/5/2008

BA Executive Club? Ridiculous.

Filed under: General — Oliver Sturm @ 6:23 pm - 2 months ago

I’ve had a BA Executive Club account for about 18 months. During that time I must have been on perhaps 15 BA flights - some UK domestic, some within Europe, some to the US. For quite a while I’ve also had a BA-sponsored American Express card, which pays miles into my Executive Club account. I’m not flying on BA all the time, because I find that pretty hard to do - basically I wouldn’t pay extra to fly with a particular airline, and usually it’s hard enough to find flights that go to the right place at the right time anyway. Overall I certainly fly more than most people I know. I’ve collected roughly 30000 miles up to now - is that much? I don’t know.

Today I thought I’d look into something that I’ve never looked into before: see whether it makes sense to upgrade a flight with those miles. I’d tried before to use the online function to do that, but every time I’d been told there was some sort of problem and I should contact my "booking agent". Flight booked online, sometimes even through BA directly, so wtf is that about the booking agent? Why no proper information about what the problem is? Hm…

So I took the time to call them and spend 20 minutes in a phone queue. Of course it was the wrong phone queue - even though I’d taken the number from that online error page, there’s a different, Executive Club specific number I should be using. Okay, got transferred. Other girl, same problem, transferring me elsewhere again. Finally somebody who knows what to do, he looks at my booking and goes "well, that’s not the right kind of ticket". What? Kind of ticket? "Yes, you should have a ‘flexible’ ticket so you can change it later. When booking online, there’s a choice between a cheap and a flexible ticket." Ah, how stupid of me.

I ask the guy if I could theoretically get anything useful for my 30000 miles on my flight to Orlando and it turns out that 25000 miles will buy me an upgrade to World Traveller Plus. Wow! Hallelujah! Just 18 months of careful airline selection and already can I afford 10 additional centimetres of leg room! So he goes, "I’m going to call our sales guys and ask them what the upgrade to a flexible ticket would cost for the trip." Comes back, and it turns out that upgrade costs about 420 quid. I say hey, that’s a bit expensive, isn’t it and he replies "no, and that’s just for one leg of the trip because <weird stuff here> - you can’t get the upgrade on the way back, but for the one leg it’s just 12500 miles".

Phew. That’s it, is it? Pay around 3 times the price for the London-Orlando leg of the trip to get a flexible ticket, and then 12500 miles to upgrade to the next, almost identical, class of travel. Frickin’ unbelievable.

Now, people tell me there’s more to frequent flyer programs - for instance, when you fly enough within one year, you get into a higher class and then you get all sorts of benefits like 150% miles on the mile (What’s the idea with "miles" anyway? The miles I get credited don’t have any similarity to the distance between the start and end of my flight.) and free upgrades to higher classes. Well, BA do 125% and 150% miles, yes. Other benefits available here (or probably not, because you have to be a privileged person with your own login in order to see this). But as far as I can tell they never give me any free upgrades, whatever I do. And most importantly, to be a better Executive Club member than I am today, I need to collect Tier Points. Now wtf are Tier Points suddenly? Check my account - I have ZERO of them. I need another 600 and 4 qualifying flights to get to Silver membership. Hm…

Looking around, I see where to get Tier Points from. Obviously I don’t get them from the kinds of flights I always use, otherwise I’d have some. But there’s a wild list stating that depending on the class and area I fly in there are 20 different fare classes (yes, really!) and all of them collect Tier Points (no further details). For some reason apparently I manage to travel outside these classes all the time - no info on that either.

Now how to figure out what fare class a ticket is in? Oh, easy: look at your boarding card. Yes, that card you get at the airport to carry around for an hour. And yes, the info is on that part of the card that gets ripped off and taken away from you when you board your plane. If you have some form of printed ticket that nobody uses anymore these days, it might also be on there. E-Tickets? Nah, not on there. Well, go figure.

Eat shit, Executive Club.

20/5/2008

F# compiler considered too linear

Filed under: General — Oliver Sturm @ 6:33 pm - 2 months, 1 week ago

In my continuing efforts to make XPO work fully with F#, I found the next problem to deal with: the extremely linear way of thinking of the F# compiler.

Basically, the compiler seems to read each source code file from top to bottom. Generally, things that are defined below the current line can’t be referred to in the current line. Apart from the order of lines in source code files, the order of source code files in the project is equally important, since the compiler handles them in precisely that order. 

Hint for Visual Studio users: While the order of source code files in the project is represented correctly in the Visual Studio Solution Explorer, it can’t be changed from there. Instead, it is necessary to edit the project file and swap source code files around manually. Right-click the project in Visual Studio and select "Unload Project" from the context menu. Right-click the project again and select "Edit <projectname>.fsharpp". When you’re done making your changes, use the context menu a third time to select "Reload Project". You will see that the order of files in Solution Explorer has changed according to the changes you made in the project file.

In some schools of though on programming, this linear view of things might seem quite normal, but in .NET it is not. In main-stream .NET programming, it was widely regarded a great innovation when C# took care of the old problems that C and C++ had in that regard (no more header files!!!). Pascal wasn’t any better, and many other languages - most of them had some sort of "pre-declaration" feature that had to be used when, for instance, a reference to a certain type needed to be created before the type itself was declared. Nothing like that in C# — the compiler looks at all the types and namespaces declared somewhere in my current project and figures things out for me. Great, that’s how it should be.

In all fairness, in F# there’s at least one very obvious reason why the compiler takes that linear approach: type augmentations. They basically mean that depending on the position in code, a class might have a certain member or not. If you’re not familiar with the feature, look at this example:

type MyClass() =
    let answer = 42
	
let mc1 = new MyClass()
	
// At this point Output can't be found on mc1
//mc1.Output()
	
let output x = printfn "%d" x
	
type MyClass with
    member x.Output() = output 52
	
let mc2 = new MyClass()
mc2.Output()
	
// Now Output is part of MyClass, so I can even call
// it on my "old" instance
mc1.Output()

Before I get to my particular use case — just generally speaking, the ordering requirements introduced by linear compiling seem like a great and quite unnecessary hassle in the vast majority of cases. F# has a very strong type inference system, because it is deemed to be unnecessary for the developer to mark all types explicitly in order to implement strong typing. In the same way, the compiler could automatically find types and namespaces in my current project regardless of their location, and it could detect those cases where types change through augmentation.

The particular case I’m dealing with is that of persistent business class hierarchies. These hierarchies are typically interrelated to the point where one or more networks of classes are formed. As an example, consider modelling a hospital. You’d have a whole bunch of different types of people to store, so you’d have classes for People and Addresses, Employees, which might be Nurses, Doctors and cleaning and housekeeping personnel, Patients with relationships to the Nurses and Doctors, Rooms, Floors and OperatingTheatres which are assigned to Doctors or Teams of Doctors. Visitors, CarParks, the whole Accounting and Booking business… the list is endless. It is quite clear that many of these types have references to many other types, and typically a one-to-many relationship is modelled with a collection property on one end and a simple reference on the other end, so as soon as there’s a relationship there, it will result in two classes interrelating.

Sure, not all classes interrelate, so it might be possible, taking a lot of time and great care, to separate the classes into groups that are hopelessly tangled, but have only unidirectional references outside the group. Of course it might make sense in the example above for almost all classes to have a reference to the Hospital type, since that is important if there’s ever more than one hospital being handled at once. There might be other such "special", high-level objects that make the grouping approach really complicated. In any case the task of sorting the classes into such groups is extremely tedious and the grouping breaks easily, as soon as any class is changed to include or exclude a property that refers to another class. You might wonder why I’m going on about the grouping thing at all — well, read on, that’s what F# wants me to do.

Have I mentioned that persistent business class hierarchies can be large? Apart from having private fields and public members for each and every piece of data that is associated with the various entities, the classes will typically also contain certain parts of business logic functionality. Depending on the architectural approach that is used, validation logic might live in these classes, as well as a lot of the state handling that many entities need. To mention some numbers, a C# project I’ve worked on myself — really just a medium size application — has 75 persistent classes and a total of 11263 lines of code in these classes.

Now, why am I going on about these interrelated networks of classes? Quite simple: because F# requires me to declare all interrelated classes in one block of code! Yes, that’s right. I can’t put some of the classes into other files. I can’t put them in different namespaces. The only valid syntax to declare interrelated classes in F# is this:

type ClassA() =
    let foo = new ClassB()
	
and
 ClassB() =
    let foo = new ClassA()

As you can see, this uses the "and" keyword to concatenate the two type declarations. This doesn’t hold true for classes only, but for all types. One of my first thoughts about this was that it shouldn’t be that much of a problem if my application made use of lots of interfaces and dependency injection throughout to remove the need for direct references from one class to another. But in the end this approach only shifts the problem to the interfaces - at a rough count, that class hierarchy from my old project would require me to declare 75 interfaces with 520 properties and around 300 other members. For those declarations, the problem is still the same, and while the volume may be smaller, it’s still significant. Plus, of course, it requires my application architecture to work in a very specific way, I need to create all those interfaces for no real reason whatsoever, … doesn’t sound like a very good idea.

In the end I don’t think that this problem is entirely particular to my use case. In other class hierarchies, dependencies might typically be somewhat more linear than they are in those hierarchies I’ve described, but interrelations are still rather common. So here are the important points I want to make:

  1. For this particular use case, we need a change that allows us to declare interrelated classes separately. There’s a very similar problem for namespaces - perhaps not quite as severe, but that’s just because there aren’t going to be as many namespaces as there are classes. To solve these issues, I guess a "pre-declaration" feature like I described above could do the job (perhaps as an attribute), but what we really need is … see (2).
  2. The F# compiler should handle all type resolution matters automatically, independent of declaration order, apart from those cases where order is important due to type augmentation. It is my belief that the compiler could detect such "significant-order" cases automatically, so there shouldn’t be a need for any new keywords or decorations to make this work. This intelligent implementation is what I expect from a language compiler in the year 2008, and with the ambitions F# has as a multi-paradigm language, we should expect no less.

19/5/2008

Null values for F# classes

Filed under: General — Oliver Sturm @ 10:34 pm - 2 months, 1 week ago

The next problem I found in my efforts to make XPO work with F# is documented here: Null values for F# classes - basically, I can’t just set a variable that has a reference to another object to null in F#.

The general assumption in F# is that null values are a threat and so the languages discourages their use. I totally see the point and if all I wanted to do was create classes (or perhaps not even those) for use in F# itself, I wouldn’t have a problem with it - but interop is an important thing for F#, as I see it, and all the rest of the .NET world makes elaborate use of null values. Null values are the (rather more dangerous) alternative to F# Options to most .NET developers - exactly the same purpose, just a less elegant implementation.

I haven’t given up on the Hub yet, although I have to say I haven’t received any useful replies from there yet… and the people who do reply are rather those that like to write forum posts than those who really know what they’re talking about ;-) Anyway, perhaps I’ll get lucky with a blog post again - Brian, are you still reading? ;-)

UPDATE: I found the solution to this problem in the release notes for F# 1.9.4: use the Unchecked.defaultof<T> function. I guess that’s the new functionality that was referred to earlier. Great!

18/5/2008

gentoo/Shorewall/DISABLE_IPV6

Filed under: General — Oliver Sturm @ 1:07 pm - 2 months, 1 week ago

Something I just stumbled upon. I was configuring Shorewall 4, and there’s a flag called DISABLE_IPV6 in shorewall.conf. Oh yeah, I thought, that makes sense - I don’t yes IPV6, so I’ll set that to Yes. Did so, and when I ran Shorewall it showed my lots of error messages like this:

FATAL: Module ip6_tables not found.
ip6tables v1.3.8: can't initialize ip6tables table `filter': iptables who? (do you need to insmod?)
Perhaps ip6tables or your kernel needs to be upgraded.

Well, I don’t have ip6_tables compiled, which is just the reason I liked that flag when I saw it. Read the source, and I found that the flag doesn’t mean "don’t use IPV6", but rather it means "use ip6tables to take some special action to disable IPV6". Well.

I searched for the piece of documentation I was missing (because I wasn’t assuming there’d be anything to misinterpret about the meaning of that flag), but I still can’t find anything… apart from this forum post where somebody states "… this is because in a perversely twisted form of logic the configuration file requires you to have IPV6 support to be able to disable it …" Well put.

16/5/2008

Oddities in F#/C# interaction

Filed under: General — Oliver Sturm @ 11:29 pm - 2 months, 1 week ago

I have been working on getting a sample for using XPO from F#. My first sample was easily created back in January this year:

#light
open DevExpress.Xpo
type Person = class
  inherit XPObject as base
  public new(session : Session) = { inherit XPObject(session);
    name = string.Empty
  }
	
  val mutable private name : string
	
  member public x.Name
    with get() = x.name
    and set(v) = x.name <- v
end
	
let person = new Person(XpoDefault.Session)
person.Name <- "Wally"
person.Save()

This works just fine - great. Now I wanted to create a slightly more evolved sample using more of the standard XPO features, and use that to develop some best practices. I also had the idea to create some CodeRush templates similar to those we have for C# and VB.

All this turned out much more complicated than I thought, for a variety of different reasons. The first issue I stumbled upon was that I can’t call our standard helper method SetPropertyValue correctly from F#. It looks like a bug to me, since I did a lot of very similar tests, and only with the precise combination of parameters and return type that this method has does the F# call to it fail. If it’s confirmed to be a bug, it’ll get fixed - but so far I haven’t heard anything, and I want a workable solution now.

I started working on one - see below -, but first I had to decide which type of mutable fields I was going to use for my persistent classes. F# allows class fields to be declared "mutable", which means they can be changed (if this sounds like an ordinary thing to you, I recommend you read up on your functional programming theory <g>). It also allows to declare values as "ref cells", which wraps the actual values in an additional class internally.

Our standard SetPropertyValue method uses a "ref" parameter in its C# implementation. Of course that method isn’t working anyway, so I was considering writing my own helper method for the time being. C# ref parameters are not something F# deals with extremely gracefully in my opinion, the main reasons for which are probably that changeable values are not foremost in peoples’ minds in that language, and there’s support for multiple return values using tuples, so the use cases from ref parameters are much reduced anyway. The only way (afaik - a topic I’m still a little unsure about) that F# ever passes a parameter by reference is if the value I’m using is a ref cell in F#.

The problem with using multiple return values instead of the by-reference type method, whether we’re talking about the standard helper method or a new one, is that it changes the requirements of the syntax at the call site. Optimally, I would like the helper API to be very easy to use. I also want to perform change notification from within the helper method. Using multiple return values, the pattern could look like this:

let setValue oldVal newVal =
    ((oldVal <> newVal), newVal)
let testSetValue1 newVal =
    let mutable testval = 10
    // This is the line I'd need in my property setters
    match (setValue testval newVal) with | true, __n -> testval <- __n | _ -> ()
	
    printfn "testval: %d" testval
	
testSetValue1 10
testSetValue1 42

There are several things wrong with this. First, the line I need to use in each property setter is rather complicated. I’d integrate it in a template, but there are people who don’t use templates, and anyway it just looks wrong to reproduce that sort of thing in every single property. Second, the naming of the helper function is really no longer correct - it doesn’t actually set the value of the property anymore, it just finds out whether setting the value is required at all. Of course if that’s all I want to do, I should change the function’s name and I don’t need multiple return values after all… the real problem is that the actual setting of the value happens in the property setter code. And that brings me to third: if I was to integrate change notification in the helper function, this would now happen before the property change actually takes place (and that’s still assuming that it takes place at all, which is not under the control of the helper function anymore).

So all this looked bad to me and I decided to go with the by-reference type helper function after all. This works only if the value I’m actually setting from inside the helper function is a ref cell. In C#, it’s possible to take any given variable and pass a reference to it into a method that requires such a reference. Not so in F#, apparently. Unless a value is declared to be a ref cell, it can’t be used in this way. Declaring as a ref cell in turn means that there’s an extra wrapper class created for the value - quite a bit of unnecessary overhead it seems, particularly when dealing with large numbers of fields such as there are typically in persistent classes. But since ref cells are the only way to make the F# compiler pass something by reference, there’s no way around that. I did some additional tests with temporary ref cells and other things, but this only made the overhead worse, not better. So I decided to accept things as they are and move on.

One other thing I should mention about ref cells: they require special syntax when used in code, basically they need to be dereferenced in order to access the actual value. So instead of writing "foo" to access the value foo, I now have to write "!foo" (yeah, looks like "not foo", but it’s not, if you know what I mean <g>). Quite inconvenient as well, if you write a lot of business logic in your class and prefer to use the private field directly. Probably better to use the public properties where possible, then you don’t have that problem.

My next step was to try and pull the helper functions which can’t be called in their original C# implementation into F# as a workaround. That looked pretty simple to begin with - our C# implementation is actually quite a bit more complex because we have to jump through some hoops to get the equality comparison right (that’s the reason for having the conflicting overloads I mentioned earlier). I created a base class that I was going to use for further objects:

type FSharpBaseClass =
    inherit XPObject as base
    public new(session: Session) = { inherit XPObject(session) }
    member public x.SetPropertyValueFS propertyName oldVal newVal =
        let needsSetting = !oldVal <> newVal
        if needsSetting then
             oldVal := newVal
        x.OnChanged(propertyName, !oldVal, newVal)
        needsSetting

And lo and behold, here’s the next inexplicable F# issue: I can’t call the OnChanged method! Again, no idea why that is - I did a bunch of tests with very similar setups and all of these work. OnChanged can’t be called though, I get a compiler error: Error 5 A protected member is called or a base variable is being used. This is currently only allowed in the direct implementation of members since they could escape their object scope.

Of course there’s not a single page that Google can find about this problem, that would have been boring. Ah well. That’s it for today in any case. To be continued.

28/4/2008

WPF styles and default behavior

Filed under: General — Oliver Sturm @ 5:59 pm - 2 months, 4 weeks ago

After my recent presentation at the VBUG conference, somebody sent me this question: "I have code to style a button and several triggers to change the button’s background color. For some reason, the trigger for the IsPressed property doesn’t seem to work. Why?" Here’s the style code that was being used (this actually includes some changes I made to the original, but never mind that):

<Style TargetType="{x:Type Button}">
  <Setter Property="Background" Value="Red"/>
  <Style.Triggers>
    <Trigger Property="IsMouseOver" Value="True">
      <Setter Property="Background" Value="Green"/>
    </Trigger>
    <Trigger Property="IsPressed" Value="True">
      <Setter Property="FontWeight" Value="Bold"/>
      <Setter Property="Width" Value="200" />
      <Setter Property="Background" Value="Lime" />
    </Trigger>
  </Style.Triggers>
</Style>

With a few buttons on a form and this style code installed in App.xaml, you can easily see that he’s right - the IsMouseOver property change triggers a change of the background color to green, but IsPressed seems to do its job only partly, since it misses setting the Background property to Lime. In the original example, the change to the background color in that trigger was actually the only thing that was supposed to happen, so it looked like nothing was happening at all. With my changes, it seems obvious that the trigger is observed correctly, but the Background property change doesn’t seem to be executed.

The reason for this behavior is simple: there are standard templates in place that format the buttons in the way we’re normally used to seeing a button formatted. On Vista that means setting the background color to a certain gradient, displaying a rounded rectangle, and having certain animations in place that are executed when the button is focused, the mouse moves over it or it is clicked. This standard behavior is also implemented as control templates using triggers, and so interests collide - the triggers in the sample code actually do set the background color to Green or Lime, only the standard trigger quickly starts doing something else. As a result, the IsMouseOver trigger sets the color to Green only for a short while before the standard animation sets in, and in the IsPressed case the color is actually never seen.

To solve this problem I used Blend to get hold of the standard control template for a button. I opened my test solution in Blend, selected one of my buttons and used the context menu entry Edit Control Parts (Template) | Edit a Copy… to have a block of code for the base template inserted into my XAML file. Note that this block is inserted into the Window class XAML file by default. In many cases this is actually the sensible solution, but in the sample application I had my styles defined in App.xaml, so I had to move the block across to that file. If you do this, be aware that there’s also an XML namespace Microsoft_Windows_Themes inserted by Blend, which you have to move together with the code in order to make things work.

Now, if you have a close look at this code that has been created by Blend, you will see that there are three "events" called RenderDefaulted, RenderMouseOver and RenderPressed configured to call various elements of the ButtonBase class, which are pulled in using the TemplateBinding syntax extension. In addition, there are some triggers that are also involved with changing the button’s appearance in response to various events.

For this example, I chose to remove all those elements to break things down to an extremely basic button that doesn’t react visually anymore (apart from my own triggers) to mouse moves or clicks. In reality this might not always be the right thing to do - this article is just meant as a starting point for readers to figure out what they need to do in their own use cases. Anyway, after my modifications, this is what I was left with:

<ControlTemplate x:Key="buttonTemplate" TargetType="{x:Type ButtonBase}">
  <Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome"
     SnapsToDevicePixels="True"
     Background="{TemplateBinding Background}"
     BorderBrush="{TemplateBinding BorderBrush}">
    <ContentPresenter
       HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
       Margin="{TemplateBinding Padding}"
       VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
       SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
       Content="{TemplateBinding Content}"
       ContentTemplate="{TemplateBinding ContentTemplate}"
       RecognizesAccessKey="True"/>
  </Microsoft_Windows_Themes:ButtonChrome>
</ControlTemplate>

Blend had automatically inserted a Template attribute for this control template into XAML, to make the particular button, which I had called the context menu on, work with this template. So I just had to run the application and there it was - two buttons still working in the same way as ever, and a third one without any of the animations and perfect green and lime colors depending on mouse state. Great!

You can download the source code for my test application here: WPFControlTemplating.zip (9016 bytes)

27/4/2008

Impressions from the VBUG conference

Filed under: General — Oliver Sturm @ 1:59 pm - 3 months ago

VBUG did their Spring 2008 Conference last week. In the beginning, Andy was tired , Chris was enthusiastic and Tim was … … also there. Dave was hungry and then he couldn’t get in . When he finally made it, he was the only one in Rich’s session and had to be revived . Not quite Dave’s event - he was scared of his computer and ended up starting his own presentation early .

Mark , Gary and Rich sang , and everybody danced

In the end it was all as it should be.

Great event, guys!

DX takes all the awards plus Product of the Year

Filed under: General — Oliver Sturm @ 11:55 am - 3 months ago

Developer Express have won each of the 8 (eight!!) categories we entered for this year’s asp.netPRO Magazine Reader’s Choice Awards. Wow!

The categories we entered were Best Add-in, Best Charting and Graphics Tool, Best Component Set, Best Grid, Best Navigation Suite, Best Online Editor, Best Printing/Reporting Tool and Best Scheduling/Calendar Tool. Our overall package DXperience was also named Product of the Year.

Look here for more info, the official thank-you to everybody and a few words from Julian.

25/4/2008

Locked myself out of Vista? Help! - Solved

Filed under: General — Oliver Sturm @ 12:28 pm - 3 months ago

It appears I’ve managed to do a pretty stupid thing - personally I rather feel like Windows let me do a stupid thing, but that’s probably a matter of perspective ;-)

Anyway, I was trying out some things with UAC, looking at the way different elevation prompts are displayed depending on whether or not the current user is an Administrators member or not, and so on. Previously I was working in what appears to be the default configuration, which my user account being a member of the local Administrators group and the Administrator account disabled and without password.

I activated the Administrator account and gave it a password. Then I removed my own account from the Administrators group and added Power Users instead. I played around with this setup and then decided to go back where I came from - only I made a mistake, I disabled the Administrator account first, before assigning the Administrators group back to my own account.

As a result, I can’t currently find a way to get Administrator privileges on my system! I can’t log in as Administrator because the account is disabled. For the same reason I can’t use the "runas" command to run any admin tools. And elevation offers only my own account (pretty weird that - why does it offer to elevate into my own account if I’m not an Administrators member at all?), which allows me, after entering my password, to bring up Computer Management - but I still can’t make changes to any account settings, obviously.

What do I do? I can see that I wasn’t thinking enough before making those changes, but I’m still having a hard time believing that I managed to lock myself out completely, i.e. the only solution is a restore from backup. Any ideas, please?

 

Update: I found a solution on this very helpful page: http://www.jimmah.com/vista/Administration/locked_out_of_admin.aspx I feel quite lucky that the no. 1 option actually worked for me and I didn’t have to use any of the other two - but at least there seems to be hope even if the situation is worse than mine turned out to be. In case you need that article and the above link should have stopped working, I have a local copy of it that I might be prepared to pass on in that event. Thanks to everybody who helped!

Not using the Secure Desktop?

Filed under: General — Oliver Sturm @ 10:18 am - 3 months ago

Using Local Security Policy settings (specifically the one called "User Account Control: Switch to the secure desktop when prompting for elevation"), I can modify Vista’s behaviour when showing elevation prompts, so that the elevation dialog is simply shown as a normal window on the current desktop. I like this behaviour much better, but I’m wondering if there’s any security related reason why the so-called secure desktop is actually more secure. If you know, please tell me!

23/4/2008

32 bit Explorer on Vista 64

Filed under: General — Oliver Sturm @ 12:49 pm - 3 months ago

There’s a pretty big problem with shell extensions when you try to run 64 bit Windows - they either come in 64 or 32 bit varieties, and each "group" of extensions will only be loaded into a corresponding host application. In other words, Windows Explorer runs as a 64 bit executable by default and it only loads shell extensions for 64 bit. Many alternative file manager tools only come in 32 bit versions so far, and they will only load 32 bit extensions.

Some extensions come in both 32 bit and 64 bit versions, and it should be possible to install them both. I’ve seen some extensions do this automatically and then it works fine - but some other vendors distribute both versions of their products with exactly the same file naming, so you can only install either one of them.

The whole thing seems a bit stupid to me… I wonder if it wouldn’t be possible to create a 64 bit shell extension that includes the 32 bit extensions in the 64 shell. Yes, I know I can’t load the extensions directly, but I could run a separate 32 bit executable that loads them and passes over all relevant information to the 64 extension - and the other way round of course. This could work both ways actually, also enabling 64 bit extensions to be available in 32 bit hosts. Of course that’s quite a bit of information that has to be transferred very carefully, mapped correctly and so on… just the sort the thing that Microsoft could have done in Windows, probably not the sort of thing I’m going to take on myself over the next weekend.

Now, for most applications I’ve been able to use Explorer for 64 bit extensions and Altap Salamander, which I use anyway, for the 32 bit ones. But I encountered a worse kind of problem the other day, when I was trying to Anapod (brilliant iPod tool, btw - can’t begin to describe how much better than iTunes it is). Anapod comes only in a 32 bit version so far. It installed just fine and then it ran the tray application and connected to my iPod. Great. Problem was, the context menu entry I normally used to bring up Anapod Explorer and access the contents of my iPod wasn’t working - some weird error message.

After a little while, I figured out what was going on. Normally, Anapod installs a top level shell extension, which displays an icon for the iPod in the main "Computer" window in Explorer. Said context menu entry simply goes and brings up an Explorer window in the right location. Because the extension that was installed was 32 bit, my 64 bit Explorer couldn’t open a window in that location. Hm. Of course there was also no other way to get to that location from the 64 bit Explorer.

I thought for a bit and then remembered that there’s a 32 bit version of Explorer also installed on the system. By default the path to it is C:\Windows\SysWOW64\explorer.exe. I tried running it, but I still couldn’t access the Anapod shell extension. After a while I found that Task Manager listed the second running Explorer instance as 64 bit - why? I don’t really know. The funny thing is that if you watch Task Manager closely while running that version of Explorer, you’ll see that for a very short time it actually shows the "*32* marker, but then this goes away and it’s 64 bit again. I don’t have an idea why that happens - I’ve only been using 64 bit Windows for a few weeks and I don’t know anything at all about its execution model.

The solution I finally found (my apologies - I don’t remember where I found it and I didn’t store a bookmark) involves a way to run a 32 bit Explorer instance on 64 bit Windows, but it’s certainly not intuitive. To make it work, you need to create a shortcut to Explorer (I’m actually still using the SysWOW64 one, but I believe the standard one should work equally well) somewhere and then change it’s properties. Set the Target of the shortcut to this: C:\Windows\SysWOW64\explorer.exe /separate, ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}. Great, isn’t it? Again, I don’t really understand this at all, just passing it on ;-)

This solution works just fine with Anapod. I still can’t use the context menu entry to bring up the Explorer window, but with the tray tool running and the iPod connected, I just open a 32 bit instance of Explorer and browse into the iPod from there.

Next Page »

Powered by WordPress
© Copyright 2005-2008 Oliver Sturm