Showing posts with label silverlight. Show all posts
Showing posts with label silverlight. Show all posts

Silverlight - Testing the untestable

Another limitation of testing Silverlight that me and one of my workmates ran into with mstest and VS2010 is documented below.
OOP especially Polymorphism help us here though.

We try to test a method that takes an ObservableCollection as input parameter.
I would like to leave the discussion about whether a method with a parameter of type "ObservableCollection" is a good idea or not to another day… Smile

This is the method we want to write some tests around

Fast = $$$ How do you make sure to have a fast application?

Speed = $$$
Many articles on the web, books and statistics tell us that “faster = better” and even more important: faster = more revenue.

For Google an increase in page load time from 0.4 second to 0.9 seconds decreased traffic and ad revenues by 20%.
For Amazon every 100 ms increase in load times decreased sales with 1%.

 

Also Google uses site speed in their web search ranking. So make sure to optimize your website for speed as per my other blog post.

Is Web Performance Optimization (WPO) something for you?

A better EBay in Silverlight

Thanks everyone for 2 great user group nights.
Here are my slides and my most important slide, based on Paul Stovell's blog post

Silverlight - 5 easy steps to obfuscate auto-magically on the build server

Disclaimer
Before you start flaming me, I am aware that all business relevant code and IP stuff must be on the server side. Just funny how much bit**** you see in forums and stackoverflow if you search for "Silverlight obfuscation"

Problem

With tools like Reflector, ILSpy (which is a good Reflector replacement BTW, since Reflector is not free anymore) and Silverlight Spy, it is VERY easy to look into Silverlight XAP files and discover some interesting stuff. We cannot completely hide our source code, but we can at least make it harder to disassemble and see.
If you are a serious Silverlight developer, make sure to get a copy of Silverlight Spy. No, I am not related to them, working for them nor affiliated.

 

Silverlight - Prevent users from losing changes by using the browser back button

image

Do you know how to prevent users from losing changes in your Silverlight application, if they click the "back button" or "close browser" button?

How to reduce the size of a Silverlight application?

We are using the WrapPanel from the Silverlight toolkit

Because we don't need the whole toolkit assembly, we copy/paste the source of the WrapPanel and use that.
Instead of the whole full blown assembly

Should be fine with the license: Ms-PL

image
Figure: Size of Silverlight toolkit assemblies

 

Customer Support in Silverlight

Imagine the following

  • You have built the world's best Silverlight twitter client, but every now and then your app crashes
    OR
  • You deployed your great Line Of Business Silverlight application, but you have no idea if people like it or not
    OR
  • Every now and then you get a phone call from your customer: "I cant see the details"

So what do you do?

Instead of having endless support calls, email conversations, tracing in log files, lookups in log-databases etc… use the below Feedback Control

image

 

Silverlight usability – the context menu

My question to you (developers & designers) about the context menu in Silverlight:

Is an application more user friendly, if there are no functions hidden in the context menu?

What do you think?

 

Note
To get a context menu before Silverlight 4 you had to set the Silverlight app to windowless and do some weird hacks (UGLY and performance issues!).
With Silverlight 4 we have a context menu out of the box (MSDN Silverlight Whitepaper).


NB   (Nota bene, the italian note)
There is no out-of-the-box context menu on the iPad.

I really like the UX of the iPad, but there are some inconsistencies left. Read more here from these usability experts (german article)

Google Wave in Silverlight – Online collaboration made easy

Google Wave is pretty cool, and was a big hype in the beginning.
I still use for sharing some notes with others…

Building something similar like Google Wave in Silverlight should be fairly easy

image  
Figure: RichTextBox control in action from MSDN

 

Google Wave = Big Silverlight Richtextbox that gets updates from others

How can we build it with Silverlight?
AND
How do other applications work, like EtherPad?

 

Silverlight – Showing HTML content “inside” Silverlight – without the WebBrowser control

Everyone was VERY excited about the possibility to show HTML content inside Silverlight.
But soon we Silverlight developers realized that it wont work in a inside-browser scenario (if you can call it like that).

image

It’s a NOOB scenario where we need the browser control, just like the browsercontrol in Winforms (aahhh… the good old days, everything was better ;-)
NOOB = Not Out of Browser scenario

 

Silverlight - Reduce your XAP download and increase the start-up performance

How can I reduce the size of my Silverlight application? And make it a better user experience on start-up?

Silverlight - Browser interaction

Reminder to myself

  • Silverlight - How to use managed code to manipulate HTML DOM?
    • How to interact with the DOM of the hosting page from Silverlight?
  • Silverlight – How to call a JavaScript from Silverlight
    • How to open a new browser window in code?
    • What about "htmlWindow.invoke" print from Silverlight?
  • Browser – How to call a Silverlight function?
    • How to tell the Silverlight control to show next customer details from the HTML page?

All this is part of the Html bridge API of Silverlight, that allows talking to the browser
http://msdn.microsoft.com/en-us/library/cc645076(VS.95).aspx

 

Silverlight – The UI thread belongs to the browser!

To myself: Remember the following

Silverlight is “normally” hosted in the browser.
So, the single UI Thread should belong to the browser.

You can either learn that from different blogs, presentations or you learn it the hard way, like myself.

---------

No debugging in Silverlight 4 with VS2010?

If you get this nice error message, you are probably lost, because there is no hints on WHY!!!???

clip_image002

Microsoft Visual Studio
---------------------------
Unable to start debugging. The Silverlight Developer Runtime is not installed. Please install a matching version.

 

Check your registry!!

When you create a Silverlight project, VS looks for the HKLM,SOFTWARE\Microsoft\Silverlight\Components\Debugging reg key to make sure you have the dev runtime. 
And when you debug, Silverlight looks for the HKLM\Software\Microsoft\.NETFramework\DbgpackShimPath reg key.

Thanks Amy!! Check out her blog about Silverlight and web dev

 

So your registry should have those keys and pointing to

 

On 64bit machines check

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Silverlight\Components\Debugging

image

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework

image

Both these keys should point to the same version (see my examples for Silverlight RTM)

Unable to open project in Expression Blend (since you are using VS2010 with .NET 4)

If you get the following problem in Expression Blend 3.0.1927.0: “Unsupported project”

image
Figure: Error messages in Expression Blend

 

Add the following pieces manually to your project file (.proj)

<PropertyGroup Condition="'$(MSBuildToolsVersion)' == '3.5'">
  <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>

and (not sure if that is actually needed…)

<ExpressionBlendVersion>3.0.1927.0</ExpressionBlendVersion>

 

image
Figure: Applied changes to the .proj file

 

Reason: Expression Blend is not .NET 4 aware, so it needs this switch at the top of the project file

"Real time" communication – client/server

How would you implement an online chat application?
Which technology would you use?

--------

We are building something similar and have the following requirements

  1. People on the web should be able to use it
  2. No download of an application
  3. Broadcasting messages to all user (server to clients)
  4. Everyone should be able to use it
    1. People behind firewalls, proxies, NATs, …
    2. People with 1 of the current browsers
  5. Lightweight solution needed

 

We tested and verified different technology options like:

  • HTML+ Reverse AJAX
  • Silverlight 2: Duplex WCF over HTTP (Long polling HTTP connection under the hood or Comet-style)
  • Silverlight 4: Duplex WCF over TCP (is using net.tcp, socket connection under the hood)
  • Silverlight raw Sockets (maybe even using SocketsLight)
  • Silverlight UDP
  • HTML 5 web sockets

The signs for HTML 5 web sockets are not so good, even though the promise for the socket implementation sounds interesting!
But it seems that HTML 5 is not going to be ready before ~201X, X > 2 and not sure what that X is…
More here
http://blogs.techrepublic.com.com/programming-and-development/?p=718
http://www.webmonkey.com/blog/HTML_5_Won_t_Be_Ready_Until_2022DOT_Yes__2022DOT

 

We finally are using "Silverlight with Duplex WCF over TCP
And falling back to "Silverlight with Duplex WCF over HTTP” when we have a firewall or proxy in the middle that causes connection problems.

The main reason for going in that direction was:

  • Ease of development and productivity in coding with Silverlight and WCF
  • Developing against one API (WCF) and doing an easy fallback behind the scenes (10 lines of code!)
  • Performance is awesome by using TCP (see Tomasz post about that)
  • Testing Silverlight means testing 1 environment against testing different browsers, operating systems, JavaScript versions, OS versions, browser versions,....

 

PS
There is a new HTTP polling duplex mode added in Silverlight 4 RC, called “MultipleMessagesPerPoll”, makes this technology even more interesting

How to create a Karaoke machine in Silverlight

(Scroll to the bottom for the nice UI)

clip_image002
Figure: Karaoke machine UI done by a Developer :-)

Goal

  1. We have 2 textboxes for artist and title
  2. On click of “Start fun” button we call a web service to get the lyrics of the requested song
  3. After that we scroll the lyrics in the textbox below

See how easy that is, with Silverlight!!!

System overview

clip_image002[4]
Figure: Silverlight application calls the local web server, which calls the Lyrics web server

It’s that complicated, because cross domain access is blocked in Silverlight and the Lyrics web service doesn’t have a clientaccesspolicy.xml file

 

Prerequisites

“Silverlight SDK Toolkit”

Download “Silverlight SDK Toolkit” from MSDN
http://www.microsoft.com/downloads/details.aspx?FamilyId=c22d6a7b-546f-4407-8ef6-d60c8ee221ed&displaylang=en

Create a new Silverlight Application project

clip_image004
Figure: Create a Silverlight project

clip_image006
Figure: Yes, Add a ASP.NET web project

Create a reference to the external Lyrics web service

  1. Right click on “SilverlightApplication.Web”
    clip_image008
  2. Click on “Add Web Reference”
  3. Use this URL to reference the web service
    http://lyricwiki.org/server.php?wsdl
  4. Click on Add Reference to finish
    clip_image010

Create the web service proxy that calls the external Lyrics web service

  1. Right click on “SilverlightApplication.Web”
  2. Add New item
    clip_image012
  3. Choose “Web Service”
  4. Name it “LyricService”
  5. Enter a new method called GetSong
[WebMethod]
public org.lyricwiki.LyricsResult GetSong(string artist, string title)
{
    org.lyricwiki.LyricWiki lyricWiki = new org.lyricwiki.LyricWiki();
    return lyricWiki.getSong(artist, title);
}

Build your solution!

Create a reference to the web application proxy service



Create the layout (page.xaml)

<UserControl x:Class="SilverlightApplication.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300">
    <StackPanel>
        <TextBlock  Text="Artist"></TextBlock>
        <TextBox x:Name="textBoxArtist" Width="200" Margin="5" Height="50"></TextBox>
        <TextBlock  x:Name="Artist" Text="Title"></TextBlock>
        <TextBox x:Name="textBoxTitle" Width="200" Margin="5" Height="50"></TextBox>
        <Button x:Name="buttonStart" Content="Start fun!" Margin="10" Width="100" Height="50" Click="buttonStart_Click"></Button>
        <TextBlock x:Name="textBlockResult" FontSize="20"  Text="nothing so far" Margin="10" Height="30" Width="700"></TextBlock>
    </StackPanel>
</UserControl>
Figure: XAML for the ugly Karaoke player

Code! Finally :-)


Use a timer to tick every 100 milliseconds and scroll through the lyrics

DispatcherTimer timer = new DispatcherTimer();  
timer.Interval = new TimeSpan(0, 0, 0, 0, 100);  
timer.Tick += new EventHandler(timer_Tick);

On each timer tick, we scroll the text


private void ScrollText()
{
// Scroll 1 caret to the left, I know thats not nice :-) but easy!
textBlockResult.Text = textBlockResult.Text.Substring(1) + textBlockResult.Text.Substring(0, 1);
}

Create the event handler on song completed call

    //No code, tooo easy

Create the timer and start it after song completed call

    //No code, tooo easy

 

 

Remember: Everything is async in Silverlight



Advanced Tasks


1. Add a slider for the speed of the text

clip_image018


Figure: Slider for adjusting the speed of the text scrolling


2. Make your Silverlight application look pretty

clip_image020


3. Make the text show only 1 line full, the other lines with low opacity

Google for: Silverlight Opacity


4. Scroll the text line by line (instead by characters)

Search for the first Newline in the text and split the text there


5. Make the application go in full screen after start

Have a look at http://www.silverlightshow.net/tips/Tip-How-to-enter-full-screen-mode.aspx


6. If no title entered, let the user choose from a list of songs by the artist

clip_image022


7. Make the song scroll like Star wars

See http://franksworld.com/blog/archive/2009/05/01/11451.aspx

clip_image024


8. Embed a youtube video next to the text of that song

See http://code.google.com/apis/youtube/overview.html for details on calling the youtube webservice

Latest Posts

Popular Posts