Saturday, 30 April 2011

I am back with a quote

Bruce Schneier says in his TED talk about security: I tell people "If it's in the news, don't worry about it", 'cause by definition, news is something that almost never happends. It is a great concept, although not completely correct. The switch from one state to another may not happen very often, but you are often worried whether you are in that state or not. But overall I agree and I have to say that it is a great news filter idea: just ignore news that are not about a change in state.

Friday, 22 April 2011

Happy Easter!

I will be going in vacation this Easter, so I won't be around until the 2nd of May. I apologize beforehand for the spam comments that I usually delete as they appear. Have a nice relaxing Easter holiday! Cause when you return to work, all hell has broken loose :)

WPF: Trigger overwrites Setter (duh!)

As usual when I stumble into a problem that I can't solve only to see that it has a simple explanation and that I am not sufficiently informed on the matter, I had some misgivings on blogging about it. But these are the best possible blog entries, the "Oh, I am so stupid!" moments, because other people are sure to make the same mistake and you wouldn't wish for them the same humiliation, would you? Well, I wouldn't :-P

So here it is: I was having a ToggleButton and a ContextMenu in a custom control. I wanted to have the IsChecked property bound in two-way mode with the IsOpen property of the ContextMenu. So I did what most people would do, I created a Setter on the IsChecked property with a Binding on DropDown.IsOpen as a value (DropDown is the property of the control holding the ContextMenu). And it worked, of course. My custom control would inherit from ToggleButton and use the style with the Setter in it.

But now comes the tricky part: I wanted that when a certain condition was met, the button be checked and the menu open. So I added a Trigger to the Style on the condition that I wanted, with a Setter on the IsChecked property to True. And from then on, nothing made any sense. I would click the button and it would not open the menu anymore.

Well, if you think about it, you have a Setter in the Style and then another Setter on the same property in the Trigger. It makes a sort of a sense for them to interfere with each other, but I also know that setting a Binding as value to a DependencyProperty is like using SetBinding on the owner of the property. And I thought it was normal for the IsChecked property to be set to true from the trigger and, in turn, change the value of IsOpen. But it didn't happen. Let it be a lesson to other bozos like myself that this thing does make sense logically (or as wishful thinking), but not in WPF. And here is why:

Let's try to evaluate the values of IsChecked and IsOpen. First case scenario: clicking on the button. That changes the status of IsChecked from true to false and viceversa. Internally, what does happen is WPF finds any bindings associated with the value and refreshes them. In this case, it finds a binding to IsOpen and so the ContextMenu also opens up. Second case scenario: the condition in the ViewModel is met, the trigger is fired and the value of IsChecked is set. It should do the same thing, right? Find the bindings and refresh them. And it does! But in that fateful moment, it sees that the IsChecked property has a setter associated with it, from the trigger in the style, that sets it to True. It does not go further, because the trigger setter overrides the style setter. I personally think this is closer to a bug than a reasonable behavior, but I am biased here :) I mean, you set the value of the property directly in the code IsChecked=true;, and it works, but you set it in the trigger and it overrides the binding?

There are more solutions to this problem. One solution would be to replace the setter value in the trigger with another binding also to the IsOpen property of the ContextMenu, but with a nifty converter. I haven't tried it, because I think that, if it worked, it would add too much weird complexity and even if I love weird, this is a little bit too much for me. Of course, a programmatic solution is also possible, adding handlers for the Open and Close events of the ContextMenu and setting IsChecked, as well as setting IsOpen based on the value sent to the IsChecked property change callback. But I wanted to do something that is as WPFish as possible. Another solution is to set a binding to the IsOpen property, since it is two way, and this is what I did. Unfortunately, the ContextMenu is a variable of the control, so I had to manually set the binding in that property's PropertyChangedCallback. A more elegant solution, I believe, is to have another element present that would have two-way bindings for both IsChecked and IsOpen properties to two of its own properties. Internally, when one changes, the other is synchronized. This leaves both ToggleButton and ContextMenu free to have any setters on IsChecked and IsOpen without interference.

The pattern of using a separate control to link properties from other controls together is called Binding Hub. Here is an article detailing it. I disagree with the naming of properties as I believe for each connection a separate hub should be created with properties that actually make sense :), but the concept is powerful and I like it.

Monday, 18 April 2011

Solution for "This action is only valid for installed products" when trying to double click an Office 2007 document

Short version: open registry, look for file association entry, locate the command subkey and check if, besides the (Default) value, there isn't a command multistring value that looks garbled. Rename or remove it.

Now for the long version. I've had this problem for a long time now: trying to open an Office doc file by double clicking it or selecting "Open" from the context menu or even trying "Open with" and selecting WinWord.exe threw an error that read like this: This action is only valid for installed products. This was strange, as I had Office 2007 installed and I could open Word just fine and open a document from within; it only had problems with the open command.

As I am rarely using Office at home, I didn't deem it necessary to solve the problem, but this morning I've decided that it is a matter of pride to make it work. After all, I have an IT blog and readers look up to me for technical advice. Both of them. So away I go to try to solve the problem.

The above error message is so looked up that it came up in Google autocomplete, but the circumstances and possible solutions are so varied that it didn't help much. I did find an article that explained how Office actually opens up documents. It said to go in the registry and look in the HKEY_CLASSES_ROOT\Word.Document.12\shell\Open\command subkey. There should be a command line that looks like "C:\Program Files\Microsoft Office\Office12\WINWORD.EXE" /n /dde. The /dde flag is an internal undocumented flag that tells Windows to use the Dynamic Data Exchange server to communicate the command line arguments to Word, via the next key in the registry: HKEY_CLASSES_ROOT\Word.Document.12\shell\Open\ddeexec which looks like: [REM _DDE_Direct][FileOpen("%1")]. So in other words (pun not intended) WinWord should open up with the /n flag, which instructs to start with no document open, then execute the FileOpen command with the file provided. If I had this as the value of the command registry key, it should work.

Ok, opened up the registry editor (if you don't know what that is or how to use it, it is my recommendation to NOT use it. instead ask a friend who knows what to do. You've been warned!), went to where the going is good and found the command subkey. It held a (Default) value that looked like it should and then it held another value named also command, only this one was not a string (REG_SZ), but a multi string (REG_MULTI_SZ), and its value was something like C84DVn-}f(YR]eAR6.jiWORDFiles>L&rfUmW.cG.e%fI4G}jd /n /dde. Do not worry, there is nothing wrong with your monitor, I control the horizontal, vertical and diagonal, it looked just as weird as you see it. At first I thought it was some weird check mechanism, some partial hash or weird encoding method used in that weird REG_MULTI_SZ type, which at the moment I didn't know what it meant. Did I mention it was weird? Well, it turns out that a multi string key is a list of strings, not a single line string, so there was no reason for the weirdness at all. You can see that it was expecting a list of strings because when you modify the key it presents you with a multiline textbox, not a singleline one.

So, thank you for reading thus far, the solution was: remove all the annoying command values (NOT the command subkeys) leaving the (Default) to its normal state. I do not know what garbled the registry, but what happened is that Windows was trying to execute the strange string and, obviously, failed. The obscure error message was basically saying that it didn't find the file or command you were trying to execute and has nothing to do with Office per se.

Of course,you have to repeat the procedure for all the file types that are affected, like RTF, for example.

Saturday, 16 April 2011

Ready for a nice vacation to Greece? My blog is all you need! :) (PhotoSynth)

Who needs time consuming trips to other countries when you can have it all here, on Siderite's blog, embedded in a blog post? Of course, if you would like the real deal (Hmpf!) don't hesitate to contact me. I can guarantee very good prices and the total trustworthiness of the people there. (You will need Silverlight to see this)



You can access the same Photosynth by clicking on this link: Villa in Kyparissi, Greece on Photosynth.

Now, before you start thinking I've gone into tourism marketing, let me explain the technology, what is Photosynth and how to use it.

Photosynth is a Microsoft Research baby and one of the things that they should be terribly proud of, even if not many people have heard of it. I blame this on bad marketing and the stubbornness on using Silverlight only. If you are to read the Wikipedia article, the technology works in two steps. The first step is photo analysis with an algorithm similar to Scale-invariant feature transform for feature extraction. By analyzing subtle differences in the relationships between the features (angle, distance, etc.), the program identifies the 3D position of each feature, as well as the position and angle at which each photograph was taken. This process is known scientifically as Bundle adjustment. You can see it in action if you go to the villa and chose to see the point cloud. The second step is, obviously, navigating the data through the Photosynth viewer.

Now, how does one use it? Surprisingly simple. First take a bunch of photos that overlap themselves. You can use multiple cameras, multiple view angles and times of day, which of course does complicate matters, but the algorithm should be able to run smoothly. Then download the Photosynth software from their site (make sure you have an account there as well) and feed the photos to it. Wait a while (depending on how many photos and their quality) and you are done. I especially liked the option to find the place in the synth on Bing maps and select the angle of one picture in order for it to determine the real location of the objects in the photos. It will also use geographic information embedded in the pictures, if available.

There are, of course, problems. One of the major ones is that it is all done through the Photosynth site. You cannot save it on your HDD and explore it offline. Also, it is not possible to refine the synthing process manually. If your pictures are not good enough, that's it. You will notice, for example, that none of the images rotated to 90 degrees were joined to any others or that there is no correlation between the images of the house outside and those inside. One cannot remove or block pictures in the synth, either. Being all closely connected to the Silverlight viewer also reduces the visibility of the product to the outside world even if, let's face it, I have edited the Photosynth by adding highlights and geographic position and I have navigated it all in the Chrome browser, not Internet Explorer, so if you refuse to install Silverlight to see it, it's a personal problem.

I hope I have opened your eyes to this very nice and free technology and if you are interested in a vacation to the place, just leave me a message on the chat or in a comment. If you have read to this point, you also get a 10% discount, courtesy of yours truly :)

Update: Here is a bit of interesting news, the release of a Photosynth application for iPhone. I personally distrust Apple products, but even Microsoft seems intent of getting a piece of those.

Thursday, 14 April 2011

I am a Microsoft Certified Professional Developer

MCPD Certified Developer
Now what else could I have been? I have been doing this damn job for at least 6 years, depending on what you call programming and what not, and even in the worst moments of depression and disappointment I still can't imagine myself doing anything else.

The point is that I have taken the 70-518 exam: Designing and Developing Windows Applications Using Microsoft .NET Framework 4 with 950 points of 1000. The same old story: pointless questions with some ridiculous answers and focus on technologies that nobody has really heard about like Microsoft Sync Framework or using DTOs or planning testing strategies (you only have to know how they are named, though).

Even worse, after getting almost all the questions and answers from the web in the form of a helpful .vce file, I started researching them on MSDN. I really wanted to know exactly what each question meant and why were those the correct answers. I really expected to find tons of documentation from Microsoft about all of this, but no! Not only did I not find what I was looking for most of the time, but when I did it was either obsolete information, meaning there were from 2007 or having specific message on the pages that the information is no longer valid, or formatted in a weird and unfriendly way that was not conducive to any type of training or learning.

Go ahead, try finding documentation on Microsoft Sync Framework, a Hands on Lab or anything that can be read from top to bottom and give you the ability to use that technology. Nada! There is no book for the MCPD exam, not even one that is going to be published in the future. Sure, I can download anything, install it, try it out, google for error messages and fix things up when they don't work, but I would have done that anyway!

I leave this whole experience behind with a vague sense of disappointment. I've learned a lot about WCF and I am going to read Julie Lerman's Entity Framework book now, but none of these four exams did really push me to learn anything new or (something that I feel I deserved from Microsoft) to find the best ways of doing things. It is all a jumbled, bureaucratic mess.

The Crippled God, by Steven Erikson

book coverSomehow I have managed to read the tenth and final book in Steven Erikson's Malazan Book of the Fallen series: The Crippled God. Almost a year ago I was saying "I doubt the tenth book will be able to satisfyingly end the story." and I have to agree with myself :)

The book continues where Dust of Dreams ended, but introduces even more characters, all amassing towards a grand finale. But is it grand? And is it, or should it be, a finale? I dare say no, but first a little bit about the content of the book.

The adjunct Tavore does for the entire book things that not even the characters understand. More than that, they follow her, all the time acknowledging that they don't know why. While this may work for short periods of time, it gets annoying and breaks one of the tenets of book writing: allow the reader to sympathize with the characters. How can you, if you don't understand what they are doing? Combine that with Erikson's style of beginning chapters without disclosing who the characters are and having to wait for a few paragraphs before using any names, and you get a book that is hard to enjoy without giving it all your attention. And when you do, people start sobbing and having "raw feelings" and understanding a world of pain from a single word and what not.

To summarize, I believe Erikson finally succumbed to the writer curse of trying to force the reader to think like him. In the end, the pleasure of understanding the situation explain by the author and filling in the blanks with your own imagination is replaced with a vast blank instead.

Then there are the tactical situations. After a rather interesting campaign in Letheras in Dust of Dreams we get a long pointless march that makes no sense whatsoever, problems created for no reason and bad solutions for them. The enemy, the Forkrul Assail, are nothing more than glorified Nazis, running around and spreading their own brand of justice, but having small and clichéd thoughts and not much in the way of actual power. They draw extra power from the heart of the Crippled God in order to boost their grand Akhrast Korvalain magic, but when it is time to unleash it, it pretty much duds, making the reader wonder what the hell happened. Also the military strategy makes no sense whatsoever, down to the individual battles. That could have slipped if Erikson wouldn't have slipped of how Tavore is the greatest strategist of all time. I won't bore you with the details, let's just say that there is much more sobbing than thinking in this book.

And now to return to the grand finale. Not only did I not understand much of it (maybe I am too dumb, who knows?) but it fizzled in comparison to most of the previous books. The battle was not that grandiose, the scheming something only a god would understand, the characters rather bland, the sobbing (did I mention it?), even the Malazan marine was boring in this book. I did enjoy it, but it all felt rushed and soulless. A lot less than I have imagined the ending of this great series to be.

The last qualm I have is with another writer trap: the desire to finish up in a clean way. It has to end with Apsalar in her village and the two meddling Shadow gods like the first book began. It had to end a lot of the pieces of stories sprinkled throughout the books. It had to save people that suffered and have couples reunited. This could have worked for a romantic comedy with werewolves, for example, but not for a series of books that never wasted time on finding boring beginnings and useless endings for its many threads.

The ending of the book betrayed the eight preceding books and some of Ian Cameron's. Perhaps the many voices of the characters always whispering in Steven Erikson's ears for twenty years have finally driven him mad. Or maybe he just got bored.