Friday, February 13, 2009

Building an application (3) ...

.. exchanging and serializing objects

One the interesting things I ran across while building the Trainer Tool was that I had exchange objects between different parts of the system. I have the excercise and its data in a couple of classes and it's the data that's is used in all parts of the system. I store it in my database (in an XML type field). The HttpHandler requests an excercise object through the web service and uses it to generate an image that is shown on the webpage. And so on. Simply said all the blue arrows in the diagram are used to transport an excercise object.

The excercise object

So all the different components need to have access to the defintion of the excercise object. Well, that's easy. Create a separate project, a class library, and simply set references to that from the other projects. Well, almost. It works for the Web Service and the Web Application, but not for the Silverlight project.

Why not? Well simple enough setting a reference to a project copies the compiled assembly (dll) from that project to the referring project's bin folder. And that just will not work with a Silverlight project. Simply because the it's a different type of dll.

The solution is very simple. Since both the .NET parts and the Silverlight files use the same C# (or VB.NET) code you can use the code in both projects.No, do not copy the class files from the .NET class project to the Silverlight! You will be doing all updates twice. It is quite easy to link the files from the class project. Create a folder to link the files into. And then use the context menu to Add Existing items.

In the following file dialog choose the files you need and then notice the small arrow on the add button. That produces a dropdown menu where the option to link the files is hidden.

Now, you have linked the class files. When you open one of the files through either of the projects you are in essence opening the same physical file. In the project explorer you can see the linked files with the little shortcut style arrow, which hints at that behavior. You get a warning when you try to open a file for the second time (once directly and once linked) and that makes perfect sense.

That was all

Another time some more information on how serialization poses some trickery as well.

Window shopping at Eaton's department store.Image via Wikipedia
Reblog this post [with Zemanta]

Thursday, February 12, 2009

Building an application (2) ...

.. coming full circle

In the first part of this journey I have sketched the outlines of my application. The combination of web pages, web service and Silverlight as I plan to build it.

Jumping hurdles and dodging bullets

While building and debugging I have run into numerous obstacles. Not only did Chrome give me an unexpected headache by not refreshing the Silverlight XAP file in the cache, also Visual Studio behaved weirdly during debugging sessions. At first I couldn't make any of the breakpoints work. Only after using the context menu on the web service and picking 'Debug - Start a new instance' did execution break at the breakpoints. And then after a couple of hours it failed all breakpoints completely. Restart of Visual Studio and browser did not work. A full reboot did the job.

BTW I have logged a bug with Chromium for the caching problem.


My Proof of Concept piece of spaghetti has now come full circle:

  1. I drag and drop some players, balls on the pitch.
  2. Enter some extra info: name of the excercise and some extra text.
  3. Save the data to the data base using the web service.
  4. The asynchronous callback adds some html to the DOM, which is an image that is generated by a special HttpHandler.
  5. The image shows up in the browser.
  6. I have a smile on my face.
Lots of work to do

en: Picture of a girl rubbing her temples.Image via Wikipedia

There is still lots of work to do:

  • a real user interface has to be designed
  • better, I need to sit down and get the complete UX designed
  • have to add the boring user authentication stuff
  • try out the concept on a real web server
  • implement some of the missing graphical pieces, like lines with arrows
  • think of good way of editing the lines
  • undo / redo ?
  • make the database complete
  • add functionality for picking existing excercises, sharing these, copying, editing etc.

Yep, there is lots to do and so little time.

A little bit more tchnical info in Part 3.

Reblog this post [with Zemanta]

Sunday, February 01, 2009

How Microsoft made me leave Google Chrome

.. well, not really

As I wrote in my previous post I am busy building a Silverlight application. This week I did some more work and ran into some very weird behavior.

I was debugging the communication between the Silverlight app and the web service and I ran into very strange errors. I noticed that in my final call in the webservice two string values were assigned to the wrong variables. They were swapped. The variable username held a piece of xml and the variable drawingXml held the username. Looking through my code I could not find the line of code where I made the mistake.

It was getting late already and this is still a POC, so I decided to just swap the place of the parameters in the method definition and investigate further at some other moment.

I stopped the debugger, made the change, inserted a breakpoint and started debugging again. That's when I completely lost any understanding of what was going on.

It was late already as I said and I blamed that and I was too tired to think straight and probably was debugging at the wrong place in the application. I decided it had to be me and had to just let it be. I walked a block with the dog and went to bed

The next day

The problem stuck and I had to investigate further so I started to change my Silverlight application so it would show some debug info in the browser to make things easier to debug.

That's where things started to go even crazier. The Silverlight application didn't show anything. The TextBlock I had added to the XAML wasn't showing up! I tried again and again. But nothing!

Google ChromeImage via Wikipedia

Then I realized that Google Chrome (my default browser) had a problem with caching. The Silverlight application in the browser was an old version of the application. Apparently, Chrome was not refreshing the XAP file!

Googling about I saw some posts about the same problems developers had with Flash. Then I sighed and I knew it was not me.

Google Chrome

So, that was it for me. I had to revert "back" to Firefox for debugging Silverlight applications. A weird feeling having to step away from Google Chrome.

I still remember that I watched the launch live on my laptop. I watched the first part in Firefox and started downloading during the presentation. Installed Chrome and watched the last part in Chrome. I also set it to be my default browser and only occasionally I use Firefox and other browsers. Well, I have to I build websites!

Microsoft made me do it

So, in a way Microsoft made me switch browsers, made me move away from Chrome.

But it's not that dramatic. I only use Firefox now for debugging Silverlight and for day to day browsing I still use Chrome.

Had I been a Flash developer, it would have been Adobe that made me switch from Chrome back to Firefox. But still only for debugging.

Reblog this post [with Zemanta]