Saturday, April 30, 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, April 22, 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.

Tuesday, April 19, 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, April 16, 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, April 14, 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.

Sunday, April 03, 2011

TV Series I've Been Watching - Part 8

Ok, time for a summary of TV shows I have wasted my time with since I've written the last post. As usual, my opinion is king and everybody else's sucks... or so I think the usual disclaimer should have sounded. So, here it the dough:
  • Doctor Who, Torchwood and even The Sarah Jane Adventures - these British shows are a bit ridiculous, but they are meant to be. I continue to watch them. Torchwood is the only one that goes towards the classic team of professionals battling the forces of evil or whatever, so it was bought by the American Starz channel. The other two are goofy and non violent, which is what I actually like about the Who concept.
  • Eureka - nothing has changed, really. There were some stirrings in the storyline, where time travel has changed the future and only some of the people involved are aware of it. I think it's a courageous thing to do in a story, but also a pretty lame cop-out for previous script errors. It's all in the motivation, really.
  • House MD - wife watches it, I mainly just fall asleep at it. It has become almost completely non medical and totally confusing. Did you catch the one minute romantic relationship between Cuddy and House? OMFG, OMFG!.. not
  • Criminal Minds and Criminal Minds - Suspect Behavior - I like Thomas Gibson and I have always felt like he was the one "making" the Criminal Minds show. What better way to test that theory than make a Criminal Minds spin-off, while taking him almost off the original series episodes? The result is a slightly more boring Criminal Minds and a horrible, horrible Suspect Behavior. And the thing is, I like Forest Whitaker and Janeane Garofalo, so I can't for the life of me understand how a spin-off of a show I like starring these two can fail so miserably!
  • Dexter - the show went in a rather boring direction for a while. I mean, you start with a serial killer and you make him a father of three that has a family, all the while trying to make it exciting. Yes, he was almost caught a thousand times and each time the solution was more and more outrageous. Towards the end of season 5 it seemed as Dexter was back on track killing people, but who knows that they will do to him in the sixth season? The latest Dexter book is about cannibals. Yumm!
  • Big Love - this show started as interesting, mostly because it was about a culture I know nothing about: polygamist Mormons, and because it starred Bill Paxton. Towards the end, though, it became so repetitive, with all kinds of moronic twists to keep the viewer interested, that I never got the will to watch it end. The episodes of season 5, last of the series, are waiting for me to watch them.
  • Fringe - Peter and Fauxlivia are having a baby! Yay! Once I stopped bitching about how lame the show is, how ridiculous the science and how bad the scripts are, I actually enjoyed it. The best show to end a hard day or to start a morning when nothing seems to work. It requires no brain power to watch. Actually, having brain power available makes it unwatchable.
  • True Blood - I still enjoy the series, mostly because people are making an effort to act well and keep the script interesting. Also because I started liking it for the vampire/werewolf Louisiana atmosphere mixing the supernatural with the superstupid and the superredneckness and they are still going strong. (yeah, I make up words as I go along)
  • Californication - the original smartness of the character spiced with a little sex turned into a lot of gratuitous sex and not too much smartness, but then it turned both sex and smartness up. (What a turn on!) I can't say if that is good or bad, but I've watched season 5 and I am looking forward to the sixth
  • Secret Diary of a Call Girl - the show ended, but left avenues open for a continuation. Billie Piper playing a prostitute was a guilty pleasure in itself, but the show was actually very enjoyable. The last season was not nearly as good as the ones preceding so I guess it is a good thing the series ended when they did.
  • Entourage - can one keep a show consistent for eight seasons? A lot of people have tried, not many actually succeeded. I enjoy Entourage still, but I feel that the original spunk and friendly youthful energy of the show has dwindled to nothing. Let's see what happens in the eighth and last season.
  • Stargate Universe - used to the other two Stargate shows, I was expecting that the last episodes of Universe be ridiculous, self referential, "screw you, we are done" style, below average quality episodes. But no! They are actually going strong and some of the mid season script and acting is making me angry for the show's cancellation. Whoever heard of great episodes in mid season AND when the show is cancelled? Blasphemy!
  • V - the second season (and probably last) ended up in a Mortal Kombat way: Shao Khan wins, muhahahahaha! It was a no brainer, really, and I won't feel bad whether it continues or not. The things that I found funny was to use some of the actors in the original series. (yes, indeed, there was another V series in 1983. And yes, I was old enough to watch it then and I did watch it and I don't really care if you don't watch anything created before 1990 :-P )
  • Men Of A Certain Age - the show is still smart, funny and tasteful. I keep wondering why is it still on. I can't wait for the second half of the second season
  • Weeds - I have to agree with the wife here: enough is enough. The show isn't even about marijuana anymore! And it gets more and more ridiculous by the episode.
  • The Good Wife - another great Tony and Ridley Scott work, pun not really intended. Characters are consistent, complex, while the story keeps me interested. Just enough human relationships to make it real, but not too much to make it soapy.
  • The Walking Dead - I was expecting a bit more from a zombie series. Apparently it is based on a comic book strip and someone told me it pretty much follows the story there. Well, it doesn't have to! [hint! hint!]
  • Haven - the first season of this supernatural "loosely" based on a Stephen King short story ended in an unexpected twist (which was to be expected). Am I waiting impatiently for the second season? Not really.
  • Rubicon - show was cancelled. I can't remember anything remotely interesting about it.
  • Royal Pains - doctors. That about says it all. This particular brand still has three unwatched episodes waiting for when both me and the wife want to watch it. It doesn't seem likely to happen soon.
  • Lost Girl - waiting for the second season. Does not require brain. Still sexy. Canadian.
  • Nikita - inertia. That's the only reason I keep watching. I have big mass, you see.
  • A Game of Thrones - oh yes! Finally something I want to talk about. Hasn't started yet, but I've read the books and they are great. A feudal fantasy world that is focused on the political machinations in the Seven Kingdoms, with a little magic thrown in to spice things up, but kept nicely in the background. I can hardly wait! It is set to start on the 17th of April
  • No Ordinary Family - about a superhero family, I have not really followed the show and meanwhile it was cancelled. bye bye!
  • Better with You - it started as a funny show to watch with the girls. It seemed as a humorous comparison of the different stages of marriage. But it became the usual background laughter at people's blatant stupidity thing and I am not enjoying it anymore.
  • Shattered - interesting concept, bad execution. Cancelled.
  • Falling Skies - a replacement for V? Aliens attack again and a resistance is formed. Set to start in June.
  • The Cape - Batman's poor little brother is trying his luck in a city that looks more like Robocop's Detroit than Gotham. Show was lame and has been cancelled, too.
  • Outcasts - oh, the humanity! A show with so much promise and so little in the way of proper execution. The premise is that humans fucked up the Earth and in a last ditch effort sent a few colony ships towards a distant planet they named Carpathia. I expected something akin to Sid Meyer's Alpha Centauri (yes, old enough to have played that, too!), but in the end it became the quasi mystical "planetary alien entity" thing, mixed with really bad acting and inconsistent scripting. So it got cancelled. It was British, it was cheap, it has potential. They still screwed it up.
  • Endgame - I am yet to find the time to watch the pilot of this show. Apparently, it is a Canadian show about a chess player that uses his skills to... you guessed it, solve crimes! If it is anything like Numb3rs, I'll watch the hell out of it. Something tells me it won't be quite like that, though.
  • Southpark - still funny as hell and I continue watching it


There are the usual anime shows, too, but I won't list them. The blog entry has gotten long enough.