Michael Kariv's Web Apps

December 5, 2007

Separating Silverlight issues to a new blog – LightSilver

Filed under: Blogroll — Michael Kariv @ 10:50 am

I was blogging mostly on the SL issues lately.
Hence a new blog. I shall post on SL exclusively there.
This blog will be kept to my more general thoughts.

December 3, 2007

Google AdSense and Silverlight

Filed under: Blogroll — Michael Kariv @ 5:06 pm

I was thinking about Rich Internet Applications (RIA) written in Silverlight. Think about a page with a title and big nice Silverlight control. Think about whole of Outlook implemented as a Silverlight control. It would be a great applciation, wouldn’t it? Now as an author of such applciation, I would definitely want to get paid. I could charge for use, or I could use advsrtising.

AdSense is Google’s adverstising revenue sharing programme. I have no experience with it. To try it first hand I included AdSense module to this blog. But right now as I write this, I rely more of what I read then personal experience.
What I understand is that google’s bot (Metabot) would connect to my pages, analyze its content and then decide what ads to show. It can work great for blogs. It can work nice for average web pages based on HTML or even DHTML. It completely eludes me how will such bot peek into what is happening inside Silverlight control of mine.

Worse thing could happen. Bad guys try to defraud advertisers creating all kind of expoits. They reportedly create automatic clicking systems, or pages consisting entirely of ads etc. Google have to fight back. They also have to automate their decisions. So once i have this empty page with SIlverlight control, I have no idea if Google would not decide it is some kind of new exploit, and ban me for life.

So, what do I do?

Google Adsense help forum seems to have an answer.And the answer seems to be yes. But I am not convinced. I could believe they search XAML file. But what if I generate Silverlight elements programmatically? In my Outlook knockoff application, I’d bring the email and calendar items via JSON calls – how would their bot know that?

December 2, 2007

Silverlight Poor Man’s Unit Test

Filed under: Blogroll — Michael Kariv @ 7:46 pm

Everyone knows Unit Tests are good, and Visual Studio 2008 excells in that, but unfortunately the built in testing projects will not accept Silverlight Assemblies as references. There are some creative ideas circling, from sharing your Silverlight files between SL and non-SL projects to compiling frameworks (e.g. NUnitLite) in SL.

I did neither. I wrote my own SL unit test framework. It looses to standard unit test frameworks on all counts save one. It has just one method of 5 lines of code:

private void Assert(bool condition){TextBlock tb = new TextBlock();tb.SetValue(Canvas.TopProperty, 30 * this.Children.Count);tb.Foreground = new SolidColorBrush((condition) ? Color.FromRgb(30, 255, 30) : Color.FromRgb(255, 0, 0));tb.Text = new System.Diagnostics.StackTrace().GetFrame(1).GetMethod().Name;this.Children.Add(tb);}

Here is how to use.
Create a Silveright project. Don’t touch XAML, it was generated with the root canvas and that is enough. Past the above Assert function inot the genrated cs file. Add any number of test methods, all void and parameterless. Each test method ends with the call to Assert with some condition. True conditions will result in the method name printed in green on the canvas. Erroenous methods will be printed red. That is all to it.

Unusual use of Silverlight in your web page

Filed under: Blogroll — Michael Kariv @ 5:19 am

For someone who is building web 2.0 application, Silverlight presentes an interesting question. Yes, it is a very powerful technology. Yes, I am sure it is superior to Flash/Flex, and far superiour to Ajax/Js/DHTML in terms of ease of developement and coding productivity. Yet Js is 100% omnipresent, and Flash is not far behind. SL numbers are not known to me at this point, but 1.1 being an Alpha, I should assume they are tiny. What does one do?

That, common wisdom goes, depends on the application. If you writing something for a controlled environment – say an intranet applet 10 people would ever use – you can insist on SL.
Else go DHTML or Flash.

One advantage of SL beyond ease of dev – C#, VS2008, all that – is the speed of execution. It is compiled and optimized. JS is interpreted. Techcrunch compares the two as a Ferrary to a bicycle.

So here is my suggestion. Write Javascript. Yet offer user an option to install SL and then use it as an invisible accelerator. You can know in JS if SL is installed. If yes – use it. If no – download your utilities js file.

It will work for everyone. Yet for the brave souls who dear install alpha technology from Microsoft it will work much faster.

Yes, it is coding twice. There are JS to C# converters There are C# to JS converters too, if memory serves me right. So it is not double work.
I assume your application is client-side heavy. It should be if you care for your user experience. Then the user experience will be so much better for early adopters. You’ll be gratified with a core of reliable user base. That base will only grow becaues SL will gradually become 100%.

Silverlight and Printing

Filed under: Blogroll — Michael Kariv @ 5:10 am

I am still hot on Silverlight 1.1. One big limitation I have just found – it does not print. That is if the browser page is printed, the content of the control will be printed too – but as a bitmap, not vector. To understand how big a limitation that is, consider the resolution of a monitor – 72 dpi (dot per int) vs normal lazer or ink-jet printers – 600, sometimes 300 dpi.

One other problem – it shall only print the visible part. Say your control shows a bar chart that is bigger then your page – then you have in-control scroll bars.

By the way at the time of this writing Silverlight 1.1 alpha does not have a built-in scroll bar. I had to find one created in VB for text blocks and rewrite it in C# and extend for canvas)

Back on subject – printing the page would print only the visible part. What a bummer.

A workaround is to send to server, bake up a PDF, send it back, and ask user to print.
Another possiblity would be to create a VML or SVN, depending on what browser you have IE or FireFox, but that is all so much overhead.

There is a thread on Silverlight forums where people vote for including printing capability to the SL control. I voted. Hope it helps.

Blog at WordPress.com.