Two short points I'd like to make about working with WPF in Visual Studio 2008:
  1. In order to see Binding errors, you need to open the Output window while the app is running, since any binding error is silently dropped, but displayed there. There is also a Binding property called FallbackValue which you can set to "ERRRROOOORRR!!" :)
  2. XML files are seldom unformatted or having weird spaces and extra lines. Yet, there is not context menu for XML editors like the Format in ASP.Net as*x files. However, the option (and many more) is available in the Edit -> Advanced menu.
    • Format entire document: Ctrl+K, Ctrl+D
    • Format selection: Ctrl+K, Ctrl+F
  3. Unfortunately, some of the useful commands are just set up in the Options menu, like what to do with extra lines. So go to Tools -> Options -> Text Editor -> XAML -> Formatting.
    • To set it so that the XML is auto formatted at completion of start/end tag or when pasting code, go to the General option
    • To get rid of extra empty lines, go to the Spacing option and choose either Collapse multiple empty lines in content to a single line or Remove empty lines in content

and has 0 comments
Ok, would I like to make a music video and then all the people watching it on YouTube instead of buying the record? Well... actually yes! If they like the song they will either buy the record or download it from a peer to peer network. And it beats people NOT watching my videos and listening to my songs.

I may not be the perfect example of a musician, since I don't sing, play or dance, but still, what happens on YouTube just doesn't make sense: Most of the cool videos of original songs were deleted! Even those with scenes from movies and such. Are actually the band members surfing the net, fishing for videos of their band and requesting their removal? NO! It's (again) the distribution companies, the record companies, that think this is some sort of way of either
  1. decrease piracy
  2. make some money out of Google
. And , at least for me, this makes me even less likely to apreciate that band and buy their album.

It all reminds me of what happened in my home country of Romania. After the revolution, nobody could be bothered with copyright laws, therefore the streets were littered with people selling pirated CDs. Then the economic stability brought some law enforcement (and widespread Internet) and now you can't find pirated CDs on the street anymore. Do people buy more music albums now?

In the end it is all about the ease of purchase. If you stumble upon a nice CD from a band you love, you will buy it, provided you actually use a CD player anymore. No one goes out of their way to a store specifically for music unless they are collectors. It's so much easier to just watch TV, listen to the radio or watch/listen to their Internet versions. Online stores are not much better. They anally query for all of your personal details in order to buy a crappy thing. It may work for electronics, but not for data!

Probably some day a brilliant idea - like combining IM identities with pay later accounts, or maybe vending machines with USB ports and touchscreens to load any music on your MP3 player for a fixed fee - will work, but until then, people will do what is the easiest thing to do. I mean, if writing music CDs and then distributing them is so damn expensive, why should I pay for it when getting the music online?

Do I feel a little guilty for listening to music and not paying for it? Yeah. But not that much.

It can't be done. Maybe in XAML 2009. In the old one, it just fails. I am using ReSharper and it automatically finds the controls in XAML in the loaded libraries and creates the appropriate namespace. For a library called "My Controls" it adds an "assembly=My Controls" at the end of the clr-namespace and the compilation fails with "Unknown build error".

The only solution I could find for this is to rename the library so that it doesn't have spaces in it. In my case the library was actually another project and I changed the name in the project properties to have underscore rather than space.

What has gone into Siderite and made him rave mad? Is he high? Everybody knows that software patterns are all the rage and the only perfect and delicious way to make software. You can't just go "cowboy style" on software, it's an industry after all.

Well, I am not saying that (although you can probably guess from my impression of my virtual/inner critic that I am a bit partial to the cowboy approach). All I am saying is that once you identify a pattern (and yes, to open another parenthesis, a pattern is identified not learnt) one should never stoop low enough to use it. Some software should do that for him!

One good example is the Iterator Pattern. It sounds so grand, but the software implementation of it is the foreach command. Does anyone actually think while iterrating through a collection that they are using a pattern? As I said before, patterns are identified. You think of what you have been doing, see a pattern, make some software to take care of similar situations, then get on to identifying another pattern.

Well, yes, but you can't entrust everything to a software, Siderite! You will bloat your code, create tools that will do less than you wanted and still end up doing your own efficient code. I know, I've seen it before!

Well, thank you, critic! You have just identified a pattern! And any pattern should be solved. And yes, I agree that software can't do everything for you (yet!) and that sometimes the tools that are designed to help us with a problem become a problem themselves. But instead of having "two problems" you have a bad solution to a previous problem. Fixing the solution would fix everything and the problem domain is now one level of abstraction higher.

Stuff like managed code, linq, TDD, ORMs, log4net... just about every new technology I can think of, they are all solutions to patterns, stuff that introduces new problems on a higher level. What C# programmer cares about pointers anymore? (developers should still be aware of the true nature of pointers, but care less about it).

There is one final issue though, the one about the actual detection of patterns. Using "prediscovered" patterns like from the classic Gang of Four book or anything from Martin Fowler is ok, but only if they actually apply to your situation. That in itself shows you have to have a clear image of your activity and to be able to at least recognize patterns when you see them. Sometimes you do work that is so diverse or so slow that you don't remember enough of what you did in order to see there is a repetitive pattern. Or, worse, you do so much work that you don't have time to actually think about it, which I think is the death of every software developer. Well, what then?

Obviously a log (be it a web one or just a simple notebook or computer tracking system) would help. Writing stuff down makes one remember it better. Feeling the need to write about something and then remembering that you have already done so is a clear sign of a pattern. Now it is up to you to find a solution.

Back to the actual title of the post, I recognize there are situations where no automated piece of code can do anything. It's just too human or too complex a problem. That does mean you should solve it, just not with a computer tool. Maybe it is something you need to remember as a good practice or maybe you need to employ skills that are not technical in nature, but should you find a solution, think about it and keep thinking about it: can it be automated? How about now? Now? Now?

After all, the Romans said errare humanum est, sed perseverare diabolicum. The agile bunch named it DRY. It's the same thing: stop wasting time!

and has 0 comments
HBO has done it again. I am not a great fan of the HBO channel. The movies I see on usually suck ass, the series are cut short, it's a consumer thing. But the HBO produced movies and series are something else. Very often I am amazed of the orginality of a series idea and the quality of the show and then I see it's HBO productions.

Entourage is one of these gems. A show loosely based on Mark Wahlberg's personal experience as a rising actor, it features four childhood friends, one of them quickly becoming a major Hollywood star. Mark Wahlberg is another guy I like without him being a mainstream accepted actor and also an executive producer for Entourage.

Anyway, through all the good and the bad, these four guys stick together. This alone is something to watch the series for, but the acting is very good, too. The whole show shines, yet to tell you the truth, I think that the real stars are Kevin Dillon and Jeremy Piven, who are actually secondary characters.

Again it is proven that great stories are the ones based on reality and you can see that the show has soul, it's not just a winning recipe applied again and again. And even better, I am at the end of the second season and it has not become any worse, so it is not just a one season wonder that quickly collapses after, but something solid. Also an interesting thing is how they have a guest star or two in every episode, playing often themselves, sometimes completely different people.

So watch it!

WPF Unleashed is a 2006 book in the Unleashed series about the new Microsoft paradigm on visual interaction, written by Adam Nathan. Windows Presentation Foundation is now the default Windows graphics framework, overriding Windows Forms, and it is based on XAML, which is used in Windows desktop applications, Silverlight applications, directly in Internet Explorer and even as a document template.

The book is nicely written, covering all the main characteristics of WPF, the functionality, the problems and tips on stuff that is not so clear. It also contains "Digging deeper" sections where some of the works "under the hood" are revealed. The book focuses more on the XAML implementation (the declarative part) rather that the code one, and I was happy to see that the code was written in C#.

All in all I liked the book and I wish I had more time to parse it completely. So far I've read the basic stuff (without the fancy graphics) so the first 10 chapters and I will wait for a moment of respite so I can detail some of the stuff I found in the book and how to implement them.


A while ago I saw the anime Fullmetal Alchemist and I was really starting to like it. An interesting melange of dark horror, funny kid stuff and magic in a very consistent alternate universe. Unfortunately the anime ended, in a somewhat unsatisfactory way.

Enter Brotherhood. This is the "continuation" of the original series to match the progress of the manga. I believe it will quickly tell the story up until the end, then ignore the previous ending and continue in a new way. Unfortunately I already know what is going to happen, having read the manga, and also don't especially like that storyline either. I hope it will not suck like Berserk did. After a brilliant start it just failed utterly.

Anyway, hopefully the anime story arches will be more interesting than those in the manga.

There are two things you need to do. First, set the project as having a neutral language. This is done in Visual Studio 2008 by going to the project's properties, selecting Application, clicking on Assembly information and setting the language. However, it doesn't set an UltimateResourceFallbackLocation. So you have to do it manually, by editing the Properties\AssemblyInfo.cs file and adding
[assembly: NeutralResourcesLanguageAttribute("en-US", UltimateResourceFallbackLocation.Satellite)]


The second thing is rather dumb. I haven't found ANY way to do it from Visual Studio. I just edited the csproj file manually. It needs
<UICulture>en-US</UICulture>
set in (under, actually) every <PropertyGroup> in it.

What that does is create a language folder in the bin directory when compiled with a localizable resource file. Using the locBaml utility in the Windows SDK you can turn a resources.dll in the language folder into a CSV, then back into a dll like this:
LocBaml /parse ProjectName.g.en-US.resources /out:en-US.csv
LocBaml /generate ProjectName.resources.dll /trans:fr-CA.csv /cul:fr-CA
.

You will not find locBaml in the Windows SDK folder except maybe as a sample project. The sample project can be downloaded here. Don't forget to compile it!

Some other useful links:
WPF Localization
Localizing WPF Applications using Locbaml
LocBaml + MsBuild + ClickOnce Deployment

Rick Strahl presents an easier and better alternative by using normal resx files! I don't want to copy (too much) from his post, so just read it:
Resx and BAML Resources in WPF

and has 0 comments
I was just installing a new system, with all the necessary tools of the trade (Visual Studio(s), Sql Server, etc) and after I've installed VS2005 I noticed that there was no entry for the Business Intelligence Studio. I've tried all kinds of "solutions" on the net, varying from using some complicated command line to running vs_setup (exe or msi) or even reinstalling everything (which I refused to do).

In the end the problem was simple enough: Visual Studio installed some SQL Express version and the SQL Server 2005 setup thought I already had Business Intelligence Studio installed, so it never did reinstall it. The solution is to run this command line:
setup.exe UPGRADE=1 SKUUPGRADE=1
on the SQL 2005 installation kit.

Warning:
  • the parameters MUST be upper case, otherwise it will not work
  • it may be that only one of those parameters is actually necessary, but I have tried them both, anyway
.

and has 0 comments
I have seen this used in a couple of places, the most prominent being LInQ. You run a method and then you chain another method to it and so on and so on. It's a nice improvement in readability and a good alternative to static methods.

The clearest example I can give you is on Wikipedia. Check it out. It's actually very easy to use and implement.

Tomorrow I start work on a WPF application that is supposed to be as modular as possible. Since I know almost nothing about WPF or modular applications, I started researching a little bit how it should be done. Basically I found only two ways I cared to expand my research on: Prism (patterns & practices Composite Application Guidance for WPF and Silverlight) and MEF (Managed Extensibility Framework).

Unfortunately I've only had time to do some Prism, although MEF seems to be the way to go. First of all it is a general framework, not limited to WPF/Silverlight and secondly it is used in the new Visual Studio 2010 release. What is amazing is that both frameworks come as freely available opensource.

Ok, back on Prism. The concepts are simple enough, although it takes a while to "get" the way to work with them. Basically you start with:
  • a Bootstrapper class - it initializes the Shell and the Catalog
  • a Shell - a visual frame where all the modules will be shown
  • a Module Catalog - a class that determines which modules will be loaded
  • an Inversion of Control Container - class that will determine, through Reflection usually, how to initialize the classes and what parameters they receive
  • a RegionManager - class that will connect views with Regions, empty placeholders where views are supposed to be shown
  • an EventAggregator - a class that is used to publish events or subscribe to events without referencing the objects that need to do that


Easy right? I don't even need to say more. But just in case you don't have a four digit IQ, better watch this four part video walkthrough:
Creating a modular application using Prism V2 - part 1
Creating a modular application using Prism V2 - part 2
Creating a modular application using Prism V2 - part 3
Creating a modular application using Prism V2 - part 4.

I did try to take the WPF Hands on Labs project and mold it with Prism and it partially worked. The problem I had was with the navigation controls. These work as a web application, where you call the XAML and it has to be a file somewhere, and you have events for the calling and returning from those "pages". I could find no way to encapsulate them so I could build no modules out of them and the whole thing collapsed.

So, for a quick walkthrough on using Prism with WPF.
Creating the core:
  1. create a new WPF application project
  2. reference the Prism libraries
  3. create the Bootstrapper class by inheriting UnityBottstrapper that will determine the Shell (a WPF window class) and set it as the application MainWindow, as well as create the type of ModuleCatalog (either take a default one or inherit one from IModuleCatalog) you want
  4. create the layout of the Shell and add region names to the controls you want to host the loaded modules (example <ContentControl Grid.Row="0" Margin="2" Regions:RegionManager.RegionName="SearchRegion"/>
.

Creating a module:
  1. create a new library project
  2. add a class that inherits IModule
  3. the constructor of the IModule can have different parameters, like an IRegionManager, an IUnityContainer, an IEventAggregator and any other types that have been registered in the container (I know it hasn't been initialized in the core, the catalog takes care of that). The IoC container will make sure the parameters are instantiated and passed to the module
  4. register views with regions and any additional types with the IoC container in the Initialize method of the module
  5. create view classes - WPF controls that have nothing except the graphical layout. Any value displayed, any command bound, any color and any style are bound to the default DataContext. The views will receive a view model class as a constructor parameter which they will set as their DataContext
  6. create the view model classes - they also can have any types in the contructor as long as they are registered with the IoC container, stuff like the eventAggregator or a data service or other class that provides the data in the view model.
  7. provide all the information needed in the view as public properties in the view model so that they can be bound
  8. subscribe or publish events with the event aggregator


As you can see, most of the work is done by the modules, as it should be. They are both communicating and displaying data using the event aggregator and the binding mechanisms of WPF. There are some differences between how WPF and Silverlight approach some issues. The Prism library brings some classes to complement the subset of functionality in Silverlight that are not needed in WPF. However, one can still use those for WPF applications, making a transition from WPF to Silverlight or a mixed project more easily maintained.

The video walkthrough (as well as my own text summary) are based on the rather new Model-View-ViewModel pattern, which many people call a flavour of MVC. It was created specifically for WPF/Silverlight in order to separate behaviour from user interface.

Expect more on this as soon as I unravel it myself.

and has 0 comments

A while ago I was writing about the novel Infected, a sci-fi thriller written by Scott Sigler. In it, an automated alien probe was using biological reconstruction to create a portal for unspeakable (and not described) evil that awaited on the other side. Alien probes being as they are, the operation failed, but not permanently, since the probe remained undiscovered and ready to plan more mayhem.

Enter Contagious, Sigler's latest book, also freely available in weekly installments on his personal blog in both MP3 and PDF versions. Is the guy too nice or what? Today the final episode was released and I can finally comment on the book.

It is clearly a better book than Infected. Not by too much, but definitely more intense. It's like Aliens to the Alien film, only for Infected :) The probe is logically doing all kind of stupid stuff, including duplicating part of his functionality in the brain of a little girl. I mean, we humans have enough trouble as it is with girls, be them small or grown up, albeit the alien probe had no idea I suppose. The US centric approach was kept, there are more explosions, lots of killing, contagious yet centralised alien organisms... in other words, a decent sequel. The only thing I couldn't really get is the father-son relationship between Perry and Dew. Couldn't believe that for a moment, although it may be my fault.

All in all I read all chapters with pleasure, anxiously waiting for the next episode. It would make a nice manga :) I can only thank mr. Sigler for allowing me to read his book without feeling like a thief getting it through a file sharing service.

So, is humanity doomed in this one? Well, yeah... I mean, we still have girls... and besides, I can't possible spoil the ending now, can I? Rest assured that there will be a third book and our favourite aliens may still get rid of the human infestation and bring the love of God on our planet. Hmm, why did I say that? My tongue feels funny, too.

This is only a bookmark. If you want to know how to do this, read this link from Microsoft: Walkthrough: Using ASP.NET Routing in a Web Forms Application.

Well, you might laugh out loud when you read this, but it is an achievement for me. I wanted to update a table (table A) which had a connection to another table (table B) through a many to many table (table A2B). I had changed A2B to link A to a new table C. I wanted to reflect that change in my Entity Model.

So the first step was to right click on the model and do an "Update Model from Database". Then went through all the steps and clicked Finish. Now entity A has both a collection of Bs and a collection of Cs. I wanted to delete the B collection but, to my chagrin, no delete option was available.

The epiphany came when I managed to select the graphical link from entity A to entity B. The link has the delete option! Which, I have to admit, does make sense. So whenever you want to remove an association between entities... well, select the association and delete it, not the entity properties.

and has 0 comments
I was trying to do something that is usually a drag: create a query with variable parameters. Something like Google search, where each query has a number of words and you want to search for each of them. How can one do this with Linq? More than that, Linq to Entities, which is pretty much making my life hell nowadays.

The idea would be to start with a IQueryable object and keep adding queries to it. This isn't so bad when you want to do an AND operation between your individual query strings.
var dc=new MyEntities();
var content=dc.Content;
foreach (var filter in filters) content=content.Where(c=>c.Text.Contains(s));


But what if you want to do an OR operation? Then you would want to be able to add stuff to the lambda inside a singe Where method. I won't get into the details, rather give you a link. I am not an expert on this myself, so it would be pointless. The more important thing is that you can do this a lot easier by using a library called LinqKit, which adds some very useful extension methods for Linq, enabling you to dynamically create queries, lambdas, etc.

There are other 'lighter' versions of this method on the Internet, unfortunately most of them are usable only with Linq to SQL, not the Entity Framework. For example I've read an interesting blog entry about this, tried the code, and got an ugly error: "The LINQ expression node type 'Invoke' is not supported in LINQ to Entities". LinqKit also did this in its earlier versions, but the Albahari brothers fixed it. So, as far as I can see, I recommend this library for real life linq composition.