Windows Phone 7 Developer Tools Beta Released


Windows Phone 7 Developer Tools Beta have been released.

Tools

Download the Windows Phone Developer tools beta to get started creating Windows Phone 7 applications today. This download includes: Visual Studio 2010 Expression For Windows Phone beta; Windows Phone Emulator beta; Silverlight for Windows Phone beta; Expression Blend for Windows beta; and XNA Game Studio 4.0 beta.

http://www.microsoft.com/downloads/details.aspx?FamilyID=c8496c2a-54d9-4b11-9491-a1bfaf32f2e3&displaylang=en

 

Training

Jump start your development of Windows Phone 7 applications by attending Windows Phone 7 JumpStart. This free virtual live class, comprised of four instructor-led 3 hour sessions, will guide you in developing applications for the Windows Phone 7 platform using Silverlight and XNA. Register today by visiting: https://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032455932&EventCategory=2&culture=en-US&CountryCode=US.

Course sessions:

July 20 – 8am (PDT): Session One: Getting Started with Microsoft Windows Phone and Silverlight
July 20 – 1pm (PDT): Session Two: Programming Game Applications with XNA
July 22 – 8am (PDT): Session Three:  Programming Applications with Silverlight
July 22 – 1pm (PDT): Session Four:  Review and Wrap Up

author: Jonas Stawski | posted @ Thursday, July 15, 2010 11:43 AM | Feedback (0)

Geospatial Article Part 1 on Simple Talk


Part 1 of my Mapping Your Data with Bing Maps and SQL Server 2008 article is now published on Simple-Talk. Go read it and learn how to integrate Bing Maps into your existing or new apps to solve business needs.

Happy Reading!

author: Jonas Stawski | posted @ Wednesday, March 24, 2010 5:13 PM | Feedback (2)

Restart your Elevated Trust, Out-Of-Browser (OOB) Silverlight App


With the release of Silverlight 4 RC you can now close your app programmatically, but unfortunately, you can’t restart it. Why would you want to restart it? Because when the app finds a new update, the update won’t take place until the next restart of the application. In some cases that is ok, but with all the new features of Silverlight 4 for OOB and the support for touch, more and more people are utilizing Silverlight for Kiosk applications, where the application shouldn’t rely on a user to restart it.

Fortunately when you are running on Elevated Trust and OOB you can use the AutomationFactory, which “provides access to the Automation servers.” In Windows that means you get access to COM+, therefore allowing you to do anything COM+ can do. As of this writing, this feature is not available for Mac.

So to restart our app we can use the AutomationFactory to execute a WScript.Shell command by calling the SLLauncher. Unfortunately for us, the SLLauncher requires some arguments that are unknown at runtime and you can see those arguments if you right click on your desktop shortcut – Properties. The big number is a random number that Silverlight generates when the app is first installed and there is no API to retrieve it, so before we can call the SLLauncher command we need to retrieve it by using… yep, you guessed it, the AutomationFactory. Bellow is the code:

image

   1: private string GetSLLauncherCommand()
   2: {
   3:     string desktopPath;
   4:     string SLLauncherCommand = "";
   5:     using (dynamic wShell = AutomationFactory.CreateObject("WScript.Shell"))
   6:     {
   7:         desktopPath = wShell.SpecialFolders("Desktop");
   8:     }
   9:     using (dynamic shell = AutomationFactory.CreateObject("Shell.Application"))
  10:     {
  11:         dynamic folder = shell.NameSpace(desktopPath);
  12:         dynamic items = folder.Items();
  13:         foreach (dynamic item in items)
  14:         {
  15:             if (item.IsLink)
  16:             {
  17:                 string fileName = item.Name.ToLower();
  18:                 if (fileName.Contains("appname"))
  19:                 {
  20:                     dynamic link = item.GetLink();
  21:                     SLLauncherCommand = "\"" + link.Path + "\" " + link.Arguments;
  22:                 }
  23:             }
  24:         }
  25:     }
  26:  
  27:     return SLLauncherCommand;
  28: }

WARNING: note that this code takes into account that the desktop shortcut of the application will always be there. If you can’t count on that then you should check the start menu. Don’t forget to add more robust checking.

So we first use WScript.Shell to get the user’s desktop path by calling the SpcialFolders method. once we have that, we use the Shell.Application objects to get a hold of the desktop shortcut by iterating over all icons and selecting the apps shortcut (.lnk). Once we find the file we use the GetLinkmethod to be able to retrieve the path and the arguments of the shortcut. Since this operation is very expensive, I recommend saving the command in IsolatedStorage or in memory. The next step is the actual restart and we do so with the following code:

   1: public static void StartAgain(string SLLauncherCommand)
   2: {
   3:     if (!String.IsNullOrEmpty(SLLauncherCommand))
   4:     {
   5:         try
   6:         {
   7:             using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
   8:             {
   9:                 shell.Run(SLLauncherCommand);
  10:             }
  11:  
  12:         }
  13:         catch { } //eat the exception
  14:     }
  15: }

Don’t forget to close your app after calling the StartAgain() method by calling

   1: Application.Current.MainWindow.Close();

Happy Programming!

author: Jonas Stawski | posted @ Friday, March 19, 2010 4:22 PM | Feedback (1)

South Florida Code Camp 2010


This year was another great year for the South Florida Code Camp. Lots of people, sessions, speakers, books, software, food, water, sodas, and a great atmosphere. Both of my Programming Web 101 and 201 sessions went great. I had a small problem with time for my 201 session as I was told by a person I had to end by 10:50, when in reality I had until 11. I apologize to everyone who was at my 201 session for not being able to cover the entire presentation.

You can download both the presentation and the project files from the following links:

Programming Web 101

Programming Web 201

Happy Programming!

author: Jonas Stawski | posted @ Monday, March 01, 2010 11:33 AM | Feedback (3)

Silverlight, WCF, and Cross Domain


Last night I was trying to consume a WCF service using Silverlight and I ran into the Cross Domain problem that a lot of people have already ran into. Here’s the message of the exception:

An error occurred while trying to make a request to URI 'http://localhost:1292/WASService/Service.svc/Service'. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details.

I have already heard about this error and I knew that it could easily be solved by adding clientaccesspolicy.xml and/or crossdomain.xml to the root of the application. You can find a very detail description of when you are attempting to go across domains in this forum: http://forums.silverlight.net/forums/p/24005/86700.aspx (look for sladapter answer). You can also find more info on by reading the Network Security Access Restrictions in Silverlight. The problem I was having is that both of the files were already in the root of the application.

image

I decided to use firebug to see what was going on:

image

and that’s when it hit me. Silverlight is trying to access the xml files on the root of the webserver, not on the root of the application. My files are located on http://localhost:1292/WASService/clientaccesspolicy.xml and http://localhost:1292/WASService/crossdomain.xml. “Easy fix,” I thought, “just change the files to the root.” The problem is that this is hosted using the WebDevServer (Cassini) and there is no root folder. It turns out that Scott Guthrie wrote about running the app as a root with the local web server. So All I had to do was to bring the properties of the project (F4 on the project) and change the Virtual path from “/WASService” to “/”.

image

Now all I had to do was change the service reference on the Silverlight app and I was up and running in no time.

image

Happy programming!

author: Jonas Stawski | posted @ Friday, February 05, 2010 10:07 AM | Feedback (3)

Problem Creating a Localized, Embedded Script


I was following this tutorial and was getting the error: Assembly 'AssemblyName' contains a Web resource with name 'ResourceName', but does not contain an embedded resource with name 'ResourceName'. Everything seemed to be perfect except that I forgot to set the JS file to build as an Embedded Resource:

image

Happy Programming!

author: Jonas Stawski | posted @ Saturday, January 16, 2010 3:42 PM | Feedback (1)

Follow All Microsoft MVPs through Twitter


Scott Dorman created a list where you can follow all Microsoft MVPs through Twitter. Go ahead and follow us. If you’re an MVP and are not in the list you can let @sdorman know.

Happy Twitting!

author: Jonas Stawski | posted @ Tuesday, January 05, 2010 7:09 PM | Feedback (1)

Windows Phone Camp 2009 – Tampa Bay


The first Windows Phone Camp 2009 in Tampa is around the corner. I wouldn’t miss it if I were you. The idea is to be similar to a Code Camp, but for Windows Mobile development. You get 8 sessions one after the other from getting started, to using the GPS, to building games. There will be free lunch and lots of prizes.

The date is December 5th, mark your calendars…

Happy WM Programming!

author: Jonas Stawski | posted @ Monday, November 30, 2009 12:28 PM | Feedback (1)

Powershell Script for Compressing DB Backups


The following Powershell script compresses all the .BAK files using winrar.

   1: cd D:\MSSQL\MSSQL.1\MSSQL\Backup
   2: $dirs = get-childitem|where{$_.PSIsContainer}
   3: foreach ($dir in $dirs) {
   4:     cd $dir
   5:     $files = get-childitem *.bak
   6:     foreach ($file in $files) {
   7:         #Check for null
   8:         if ($file -ne $NULL){
   9:             #write-host $file.Name.Replace(".bak", "")
  10:             & "c:\program files\winrar\rar" a $file.Name.Replace(".bak", "") $file.Name
  11:             remove-item $file
  12:         }
  13:     }
  14:     cd ..
  15: }

Walk through:

1. Change directory to the backup root directory
2. Get all the subdirectories and iterates through each one
3. Get all *.BAK files and iterate through them
4. Use the winrar command line to compress the file
5. remove the .BAK file

Happy Powershelling!

author: Jonas Stawski | posted @ Monday, November 16, 2009 1:43 PM | Feedback (1)

Out of Process Session State and LINQ To SQL Entities


When using ASP.NET you can choose 4 different ways of storing session: In Process, State Server, SQL Server, or Custom. When using In Process the session is stored on the ASP.NET thread of the web server, but when using the State Server or SQL Server the sessions are stored outside the ASP.NET thread. When would you use Out of Process session state? Mostly when you have a web farm and you need to share the same session across all web servers. You might choose to use it even if you have one web server for the simple reason of saving memory on the web server.

When using In Process and you store an object in session, ASP.NET maintains the object in memory and holds a pointer to that object so it can be used on future requests. Based on this explanation you should be able to store almost any object in session, including LINQ to SQL Entities.

The problem arises when you use Out of Process Session State. Whether you use SQL Server or State Server the objects need to be serializable in order to be able to be persisted. The object graph of a LINQ to SQL entity can be very complex and you will need to make every single child entity and type serializable, which can become very cumbersome. I came up with a simple solution that is to serialize all objects when setting them in session and deserialize them when retrieving them from session. In order for this to work you have to make sure that your L2S entities are decorated with the DataContract attribute and the properties are also decorated with the DataMember attribute. If you generate your entities using SqlMetal then you can do so by using the /serialization:Unidirectional parameter or if you use the VS designer by right clicking on the design surface and specify “Uniderectional” in property grid for “Serialization Mode”.

Here are the helper methods:

   1: public static MemoryStream Serialize<T>(T obj)
   2: {
   3:     DataContractSerializer s = new DataContractSerializer(typeof(T));
   4:     MemoryStream ms = new MemoryStream();
   5:     s.WriteObject(ms, obj);
   6:  
   7:     return ms;
   8: }
   9:  
  10: public static T Deserialize<T>(MemoryStream ms)
  11: {
  12:     DataContractSerializer s = new DataContractSerializer(typeof(T));
  13:     ms.Position = 0;
  14:     T retObject = (T)s.ReadObject(ms);
  15:  
  16:     return retObject;
  17: }

A sample on how to use them:

   1: //Store in session
   2: Session["User"] = Serialize(user);
   3:  
   4: //Retrieve from session
   5: User user = Deserialize<User>(Session["User"] as MemoryStream);

Something to be aware of is that by serializing and deserializing a L2S entity you are detaching the entity from the datacontext and hence there will be no lazy loading of child objects nor insertions or updates of that entity. In other words the entity becomes a Plain Old CLR Object (POCO).

Happy Programming!

author: Jonas Stawski | posted @ Friday, November 13, 2009 11:56 AM | Feedback (2)