Even though there are already a couple of blogposts about bookmarking pages from an asp.net environment using the AJAX scriptmanager, there are not a lot of people that have done deep linking with querystrings and silverlight apps hosted in HTML.
This feature is missing in the current version of silverlight (2.0) and needs to be implemented by hand, if you need to have it. A lot of business App need it, and so does ours.
The solution is an elegant one as well (If I may say so myself): Create a javascript method that gets called when the silverlight app starts, let the javascript method call a method on our silverlight app that's exposed to javascript and let that silverlight method parse the querystring into anything we want it to be!
So here we go:
- Create an HTML host file to host the silverlight app. Make sure the object has an Id. In our case: SilverlightControlApp
66 <div id="silverlightControlHost">
67 <object id="SilverlightControlApp" data="data:application/x-silverlight-2," <!-- Notice the ID -->
68 type="application/x-silverlight-2" width="100%" height="100%">
69 <param name="source" value="ClientBin/MyYetAgainVeryCoolDemoApp.xap"/>
70 <param name="onerror" value="onSilverlightError" />
71 <param name="onload" value="PassTheQueryStringToSilverlight" /> <!-- Notice the Event -->
72 <param name="background" value="white" />
73 <param name="minRuntimeVersion" value="2.0.31005.0" />
74 <param name="autoUpgrade" value="true" />
75 <a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">
76 <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
77 </a>
78 </object>
79 <iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
80 </div>
- Create a javascript file to contain the QueryStringRetrieval. I named it "QueryStringHelper.js".
- paste the following method in there:
2 function PassTheQueryStringToSilverlight(sender, args) {
3 try {
4 silverlightControl = document.getElementById("SilverlightControlApp");
5 silverlightControl.Content.SilverlightApp.SetQueryString(location.search);
6 }
7 catch (e) {
8 alert("An exception occurred in the script. Error name: " + e.name
9 + ". Error message: " + e.message);
10 }
11 }
- Add the javascript reference in the HTML page:
20 <script type="text/javascript" src="Silverlight.js"></script> <!-- Generated by VS -->
21 <script type="text/javascript" src="QueryStringHelper.js" /> <!-- Add this yourself -->
- Add an OnLoad event handler to the Silerlight host object to call the javascript method. Notice the event in the HTML code above.
- Open the App.xaml.cs and create a method to receive the queryString. Use the ScriptableMember to expose the member to be called from Silverlight.
65 [ScriptableMember]
66 public void SetQueryString(string queryString)
67 {
68 // Get the panel from the querystring
69 var parms = QueryStringHelper.ParseQueryString(queryString);
70 if (parms.ContainsKey("panel")) SetPanel(parms["panel"]);
71 }
72
73 private void SetPanel(String panel)
74 {
75 // Navigate to the specified panel
76 if (_availablePanels.Contains(panel)) page.PanelToShow = panel;
77 }
- Register the class as scriptable in the HTML pages by calling HtmlPage.RegisterScriptableObject(String, Object); I've done it from the constructor in the App class in the App.xaml.cs.
20 public App()
21 {
22 HtmlPage.RegisterScriptableObject("SilverlightApp", this);
23
24 Startup += Application_Startup;
25 Exit += Application_Exit;
26 UnhandledException += Application_UnhandledException;
27
28 InitializeComponent();
29 }
- Implement the querystring parsing. I re-used a piece of code from the almighty internet. Just create a class called QueryStringHelper and copy paste the following section code:
2 using System;
3 using System.Collections.Generic;
4 using System.Text.RegularExpressions;
5
6 namespace MyYetAgainVeryCoolDemoApp.Silverlight
7 {
8 public class QueryStringHelper
9 {
10 public static Dictionary<String, String> ParseQueryString(String queryString)
11 {
12 var result = new Dictionary<String, String>();
13
14 // Source = http://increment.cx/wordpress/?p=106
15 var regexPattern = @"\?(?<nv>(?<n>[^=]*)=(?<v>[^&]*)[&]?)*";
16 var regex = new Regex(regexPattern, RegexOptions.ExplicitCapture);
17 var match = regex.Match(queryString);
18
19 for (var currentCapture = 0; currentCapture < match.Groups["nv"].Captures.Count; currentCapture++)
20 {
21 result.Add(match.Groups["n"].Captures[currentCapture].Value.ToLower(),
22 match.Groups["v"].Captures[currentCapture].Value.ToLower());
23 }
24
25 return result;
26 }
27 }
28 }
And now, you'r ready to use query strings in your app!
Cheers mates!
If you have not heard about this you should realy check it out!!!
It's the successor to CAB, Smart Client Software Factory and implements a lot of Paterns and practices!
Download it from here
Stephan
Back to index
Martin fowler is one of the inventors of the Model View Presenter pattern which he let retire a couple of years back. I don't think the rest of the software community will let the pattern retire though!
Mr Fowler suggested to split the pattern up into two very similar flavors of the pattern as you can read here:
So, as it's phased out and there is enough to find about the pattern already (like here and here) I will not write about this pattern.
It seems like every self respecting blogger needs at least one multi-episode blogpost, so this is the start of mine and it's about good design patters and the latest state of it.
While updating and enriching my knowledge about unit testing and automating the daily builds even further, I ran into some exciting new stuff. This made me think about writing a set of blogs that will discuss the whole unit testing matter from the ground up.
In the basic stuff I will only give a brief explanation with links to more elaborate instructions as I don't intend to re-write how to install and setup a daily build. I will give some tips and tricks I know of and maybe you guys can extend these??
After I have covert the basics, I will move into more recent stuff, like the retirement of the MVP pattern, the very new Presenter First methodology Ron Jacobs will be talking about at the various sessions he is giving all over the world and others...
The scope will be WinForms and ASP.NET applications as these will cover most business scenario's. Initially it will be focused on .NET 2.0 and leave WPF, WCF, WWF and cardspaces out of the equation, Maybe in part 17 or something this will be addressed :-)
I will write a Conclusion page right from the start of this multi-episode blogpost, but his is bound to change while I write new posts about these matters. I will try very hard to keep that in sync.
Of course I need an indexing scheme, so here it is:
-
Introduction (This page)
-
Basics of unit testing
-
Basics of setting up unit testing in TFS
-
Basics of Code coverage
-
Design for unit testing
-
Design for code coverage
-
Have I unit tested enough?
-
Overview of design patterns to assist unit testing
-
-
Supervising Controller pattern
-
Passive View pattern
-
Design / development processes that assist unit testing
-
Test Driven Development (TDD)
-
Presenter First design process
-
Hoe this all fits into pragmatic everyday programming
-
Conclusion(s)
But, Lets start at the beginning..... here
A couple of nifty tips-and-tricks for VS2005.
http://msdn2.microsoft.com/en-us/library/bb245788(vs.80).aspx
Some of them I use allready, some of them I knew could be done. Now I know how when I need them or have some time to spare and want to invest it in speeding up my VS2005 usability.
Cheers!
SQL Server CE (previously called SQL Mobile and SQL Everywhere) is a very lightweight SQL server that can run everywhere hance the name "SQL Everywhere". It is targeted to replace the XML data files in a lot of smart client apps.
It's realy, realy, realy great, but the problem is that a lot of tools do not (yet) support the data provider, witch makes it harder to use it. Like active reports. Somehow the provider does not get registered in the GAC as supposed to the documentation states (RC1 documentation). So, it seems I now have to find out where the providers get registered to sort out the problem.
The problem is that the provider resides in the System.Data.SQLClientCE namspace in stead of the System.Data.SQLClient namespace and that namespace is not commonly supported yet by the tools. The namespace is quit old actually, but up until recently it was not interesting to implement (other than om mobile app tooling)
I am contacting DataDynamics about it. Maybe i am not the first and the questing did not make the FAQ or KB yet. (You never know right?)
Maybe i can find another way to connect the ActiveReport to the dataset from the SQL Server CE. There is an option to use unbound fields and at runtime assign values to it. But they are all called Field1, Field2, Field3, etc. I simply refuse to use it. I just won't!
Another option I will look into, is to look for an XSD Dataprovider or somethomg. A dataprovider witch can read the XML schema into a dataset and implements the DataProvider interface so i can consume it from third-party tools.
Some collaegues are going to edmond in januari and one of them proposed to stay at Bill's place. That brought us to the topic of his house and a big discussion followed. So we looked some specs of his house up with google. Here you can find a overview of his little mansion :-)
Realy cool house and a great website to check it out...
For the podcast listeners out there in the Netherlans who have not yet made up there minds about the elections, would like to read the election programs of the political parties and who do not have the time (Is there anyone left due to these exclusions?):
The podcast version of the election programs can be downloaded here. There are also a couple of summary versions of the biggest parties.
Good luck making up yuo're mind and at least go and vote! Be glad you have the right to, so use it!
(Sorry, no spell checking, because im using the website to quickly blog about this)
Patrick had more time, but I actually spoke myself at DotNetRocks. Listen to my stumbling (starts at 1:02:00) as Richard surprised me by handing me the microphone all of a sudden.
It is kind of old news, but did not hear it, so maybe you guys havn't heard it either:
http://www.iunknown.com/articles/2006/10/20/dynamic-languages-microsoft-and-me
(Great domainname b.t.w.)
I think he was on DotNetRocks some time ago, but I'm not going to check witch/wich/who episode. You go look for it if you want to hear more about the RubyCLR for .NET here
I've installed Live writer, ran through the installer, somehow the installer could not find find the settings for the server automatically, so I had to specify it for him. I Replaced the <Hostname> tag with "BloggingAbout.NET" and entered the rest of the standard info like username, password, etc... ok, ok, ok, finish. and it's up!
I am writing this with Live Writer, so if you are reading this, the posting works as well.
The only thing I did not install is the IE Live Writer toolbar. Does anyone know if that is useful? Or is is yet another way to minimize the working area of the screen?
So, lots of text (and possible ways of mistyping stuff) lets see what happens if I do a check on the spelling:
The suggestions: (I corrected them, so you won't see them)
- i -> Replace with I
- LiveWriter -> Replace with a lot of wrong suggestions, so I changed it to Live Writer
- Spellcheck -> A lot of wrong suggestions
- Some other typo's
Conclusion: I think this will work for me! (And for Dennis, Erwyn and you guys out there who do not read the subtitle of my blog. ;-) ok, ok, tidiness is a good thing, that's why I installed Live Writer)
I think I know why the teched moved to Barcelona again :-)
But now i have you're attention:
It's the last day of TechEd and the info keeps on comming! Yesterday i attended a discussion session on CardSpaces. I was realy sceptical about it, but the discussion kept be around the participants moms. (And dads in case of the dodgy sites he visits :-) ). This is, at least in my opinion, a very good thing as we IT geeks allready know what HTTPS means, but the Identity Metadata system (IMS) is realy to give all the mums and dads out there more insight in what they are asked when they get a dialog at amazon.com about SSL.
CardSpaces is the MS implementation of the IMS designed by Kim Cameron (Witch got hired by Microsoft) and there are other open source implementations of it.
As i said: I was sceptical, but after the whiteboard I think it's pretty cool and can have a chance. I will get back to it in more detail, because i have to run now...
Just enough time to blog this great new tool comming in some version of Ocra's (So that you know the timeprojectory :-) )
A session from Steve Lasker
Its a couple of classes on the server and on the client that you can derive you're own class from. The baseclass implements a lot of code to do basic synchronisation between server and client based on a couple of database constraints like mandatory columns (Who you can name youreself, so thay are not bad).
The ADO.NET is one piece of the puzzle; The synchronisation should in the future also include Files, XML, etc, etc. Although i don't know how they are thinking about synchronisation of XML or even worse, just regular files.
There are still a couple of (standard) things not implemented, like:
- How collisions between client and server updates are handled. There are a few build-in but they are the simple onces like "Last one wins" scenarios.
- Cascading changes. No comment on that one, but maybe i run into him later and ask him about that (Or find it on his blog I suppose.)
- Schema changes.
Witch i hate, because you would expect Microsoft to come up with some guidelining and implement that. I mean, they have the experience with outlook, activeSync, right?
The good thing is that the goals are (My interpretation btw):
- to produce a outlook like feeling for the user
- Do something between RDA and merge replication
- Listen to the developers while developing the framework.
Al-and-al i am very excited about this and just wanted to be te first to blog about it :-)
More Posts
Next page »