Errr, some catchy title.... RSS 2.0
 Thursday, June 28, 2007

So, you wrote your first RIA and you want to publish in on the web and start counting those millions of dollars coming in. You deploy your application, type in the link but, nothing happens. Why?

 

 

 

It could be, that your hosting service doesn’t support .xaml files (mine started around a month age). There is a quick workaround for that, simply rename your .xaml files to .xml. You have to update your references accordingly, such as when you create your xaml object via JavaScript. Luckily, if you do that, everything still works (Intellisense) inside Visual Studio so if you do this before deployment, you won’t have any problems.

 

Note: You don’t have to do this for User Controls as they are compiled into the binary file.

 

Let’s assume that you have created your Silverlight project that consists of one Page.xaml file some User Controls, one Default.html page (so typical set up in Visual Studio). Below is a list of files that need to be uploaded to the server:

 

Default.html

Default.html.js

Page.xaml (or Page.xml)

Silverlight.js

 

And the most important one:

ClientBin (the directory in which is the client DLL)

Thursday, June 28, 2007 10:16:01 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Silverlight
 Monday, June 11, 2007

I was writing a short project for myself in Silverlight that involved calling my own web service. Everything was working great in localhost, however when I uploaded it to my website, the application crashed and I had no idea why. After some time spent debugging (not the most pleasant thing in Silverlight I found out, that calling a web service from generated an exception:

 

Request format is unrecognized for URL unexpectedly ending in /MyMethod.

 

After looking at the problem, I realized that HTTP GET and HTTP POST Are Disabled by Default starting from ASP .NET 2.0. A quick fix has solved the problem, paste the following in the web.config and you’re good to go.

 

<system.web>

    <webServices>

        <protocols>

            <add name="HttpGet"/>

            <add name="HttpPost"/>

        </protocols>

    </webServices>

Monday, June 11, 2007 12:55:07 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Silverlight
 Wednesday, June 06, 2007

I moved my blog from www.greatestcoder.com to www.greatestcoder.com/blog/. If you will hit the first page though, you will be automatically redirected to the second page. Here’s how you can do it in the easiest way possible. Create index.html with the following content:

 

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title title="Marcin Waligora" />

    <meta http-equiv="refresh" content="0;url=http://www.greatestcoder.com/blog/" />

</head>

<body>

</body>

</html>

 

The only thing that is interesting here is the meta tag.

 

http-equiv="refresh"

 

This attribuge will tell the server that the page is going to be redirected.

 

content="0;url=http://www.greatestcoder.com/blog

 

Here we have two things into consideration – 0 indicates the amount of time (in seconds) how long the client should wait before being automatically redirected to another page (here idicated by the url tag).

 

On a lot of pages you will see some information, like : “we’re going to redirect you to a different page in 5 seconds. Click here if you don’t wish to wait”.

 

After moving the application I had one problem, all the pictures that I’ve embedded in the posts were using absolute path. So when I moved my application, none of the pictures were displayed. I had to update my previous posts to reflect this change. It would seem logical (if you’re adding your own copy of the image) to the post that it should use relative path instead of absolute. Then, moving a blog to a new location would be a matter of copying all the files.

 

Hey, this sounds like a feature request for das blog guys J.

Wednesday, June 06, 2007 2:27:40 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Html
 Friday, May 04, 2007

There are examples how to set image to the Image object in Silverlight (both in 1.0 and 1.1); however I haven’t found one how to set it to any object that can be filled. The beauty of XAML based applications is that you can put whatever media you want inside objects, so if you want to fill in Ellipse or a Path with an image you can. The easiest way to do it is just declaratively, in XAML:

 

<Rectangle x:Name="mainPic" Width="448" Height="386" Canvas.Left="288">

      <Rectangle.Fill>

            <ImageBrush ImageSource="pic.jpg" />

      </Rectangle.Fill>

</Rectangle>

 

 

This is great for static content, but what if you want to set it programmatically using Downloader object.

 

Below is the solution for 1.0 (I tested in on Feb CTP release)

 

var wpfe;

 

function root_Loaded(sender, args) {

      wpfe = document.getElementById("wpfeControl1");

     

      mainDownloader = wpfe.createObject("Downloader");

      mainDownloader.completed = "javascript:mainDownloadCompleted";

      mainDownloader.DownloadProgressChanged = "javascript:mainDownloadProgressChanged";

     

      mainDownloader.open("GET", "SomePic.JPG", true);

      mainDownloader.send();

     

}    

 

function mainDownloadCompleted(sender, args) {

    sender.findName("mainPic").Fill.ImageSource = sender.Uri;

}

 

 

Apart from setting the downloader, the most important code line is this:

 

    sender.findName("mainPic").Fill.ImageSource = sender.Uri;

 

When the image gets downloaded we set the Rectangle’s ImageBrush to its URL.

 

Now solution for 1.1 in C#:

 

public void Page_Loaded(object o, EventArgs e)

        {

            // Required to initialize variables

            InitializeComponent();

 

            Downloader downloader = new Downloader();

            downloader.Completed += new EventHandler(downloader_Completed);

            downloader.Open("GET", new Uri("SomePic.JPG", UriKind.Relative), true);

            downloader.Send();

        }

 

 

void downloader_Completed(object sender, EventArgs e)

        {

           (mainPic.Fill as ImageBrush).ImageSource = (sender as Downloader).Uri;

        }

 

Once again, the most important code line is this

 

(mainPic.Fill as ImageBrush).ImageSource = (sender as Downloader).Uri;

 

Notice, how much casting we have to do, because C #is a strongly typed language.

 

Hope this helps.

Friday, May 04, 2007 3:15:45 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Silverlight

This is a quick post describing my first impressions with Silverlight 1.1 and Orcas Beta 1.

 

Orcas:

·        Overall: a step forward in a good direction. I really enjoy working with it. Can’t wait for Resharper to come out for it J.

·        I love that I can finally debug JavaScript.

·        Nice and clean separation: When you have Page.html, you also get Paga.html.js. Now, we have code behind for everythingJ.

·        XAML explorer is a lot faster when I compare it to VS 2005.

·        Running Silverlight application launches default browser in the system (in my case Opera). There is no plugin for Opera to make Silverlight working, so I always get the lovely image Get Silverlight. I had to set IE to be my default browser. In VS 2005 IE launched always no matter what was the default browser, I preferred it that way.

·        Ctrl + Right Arrow (and Ctrl + Left Arrow) don’t work! When I checked keyboard shortcuts in 2005 and Orcas they said exactly the same thing: Edit.MoveControlRight. Apparently this doesn’t work in Orcas on my machine. BTW: I had no idea how much I use this feature until it stopped working.

 

 

 

Silverlight:

  • Between 1.0 and 1.1 a HUGE step forward. I mean CLR on MAC, DLR and so on. My head still hurts….
  • It’s amazing I can write C# in my client app. I’ve written an Image Gallery for Silverlight 1.0 (actually when I wrote it, it was still WPF/E) and it wasn’t a joy ride. I didn’t enjoy debugging JavaScript with alert.
  • I’m rewriting it now to learn 1.1 and I’ve noticed that productivity boost is amazing. I truly believe that it will be possible to write simply amazing Rich Internet Applications with this technology.

 

 

Small Tip when building Silverlight applications with Orcas:

 

When you’re adding objects to XAML code that you want to reference in the code behind, make sure you use prefix x before Name property:

 

<Rectangle x:Name="mainPic" Width="448" Height="386" />

 

x of course corresponds to

 

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

 

Without that little x you will get compilation errors. It is a little bit counter intuitive since when you press n you also get a property Name, but this Name corresponds to the default schema

 

 

 

Friday, May 04, 2007 2:41:01 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Orcas | Silverlight
 Friday, April 20, 2007

When you’ve used ASP.NET AJAX’s UpdatePanel you may have come across this error. Its typical message is:

 

Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

 

 

 

 

 

If you get this error, the first thing everyone does is to check whether they have any of the things they were not supposed to be doing:

  • Calling Response.Write()
  • Using response filters or HttpModules
  • Having Server Trace enabled.

 If you check those things and are positive that they are not the case, you’re lost. Well as it turns out, there’s a fourth hidden option:

 

Calling Server.Transfer method.

 

The thing is, when you call Server.Transfer, the server generates HTML for the next page and sends it directly to the client which was expecting some part of the page that was supposed to be returned via AJAX. This generates PageRequestManagerParserErrorException. So, you cannot use Server.Transfer method.

 

Well, actually you can, but it cannot be an asynchronous call.

So if the button is inside the UpdatePanel it will automatically use asynchronous calls. Luckily, there are two ways to force it to make a full postback.

  1. If the button is created statically, then simply register it a as a PostBackTrigger.
  2. If the button is created dynamically, call ScriptManager.RegisterPostBackControl with the necessary button.
Friday, April 20, 2007 1:36:07 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Ajax | ASP.NET AJAX
 Tuesday, March 27, 2007

I was writing a Powershell script today to automate deployment for application we’re currently working on. Part of the requirement was to get latest files from Visual Studio SourceSafe. VSS provides us only with COM wrappers; however I wanted to do that via .NET objects.

 

Luckily googleing the problem has produced some valid resources. Check out VSS Code Samples. From there, download OLE Sample Code Written in Visual Basic .NET and C#. This exe contains a .NET solution with 2 projects: .NET VSS Library written in C# and a VB.NET explorer application that is basically a VSS Explorer that uses the Library under the hood. The problem is this has been written for version 6 of VSS and I had version 8 (the 2005 release).

 

Due to this, the explorer application couldn’t compile, since it relied on some ActiveX that simply wasn’t there anymore. Luckily, the underlying VSS Library still worked. Below is a sample code that I used to do my small task with the VSS Library. The code gets all items (recursively) from the given path.

 

clIVSSLibrary lib = new clIVSSLibrary();

string errorOccured = null;

errorOccured = lib.OpenDB("Martin.Waligora", "somepassword",  "\\192.168.1.75\vss_application");

errorOccured = lib.SetCurrentProject("project");

errorOccured = lib.SetWorkingFolder(@"$/project/DistributionImage", @"C:\VSSTest");

VSSFlags flag = new VSSFlags();

long flags = flag.FlagGetLocalCopyYes() + flag.FlagRecursiveYes()

                        + flag.FlagReplaceLocalReplace() + flag.FlagRights_All();

 

string getPath = null;

errorOccured = lib.GetItem(@"$/project/DistributionImage", ref getPath, (int)flags);

lib.CloseDB();

 

 

After writing the code I’ve added it to my Powershell script. Here’s it:

 

$VssDllPath = 'C:\IVSS_Sample\IVSSDLL\bin\Debug\IVSSLibrary.dll';

"Loading the .NET VSS DLL $VssDllPath"

$ass = [reflection.assembly]::LoadFrom($VssDllPath);

 

"Creating object of type IVSSFunctionLibrary.clIVSSLibrary"

$VssLib = New-Object IVSSFunctionLibrary.clIVSSLibrary;

 

#We create a function to help us with calls to the vss library

function ErrorOccured

{

      if($args[0].Length -gt 1)

      {

            "Error has occured: $args[0]"

      }

}

 

#We insantiated the object, now let's get all data to specified directory

ErrorOccured $VssLib.OpenDB("Martin.Waligora", "fakepass", "\\192.168.1.75\vss_app");

"Starting to copy all the files"

ErrorOccured $VssLib.SetCurrentProject("project");

ErrorOccured $VssLib.SetWorkingFolder("$/project/DistributionImage", $remotePath);

#$flags = 67117199;

$getPath = "";

ErrorOccured $VssLib.GetItem("$/project/DistributionImage", [ref] $getPath, 67117199);

ErrorOccured $VssLib.CloseDB();

"Success, finished copying files to $remotePath";

Tuesday, March 27, 2007 4:02:45 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Powershell
 Monday, March 26, 2007

Last week I've passed 70-229 exam by Microsoft. It was the final one out of 5 exams required. Hence, now I am Microsoft Certified Solution Developer and I can use those logos (MCAD is a subset of MCSD):

 

                                                                 

 

To sum up: Awesome :D .....

Monday, March 26, 2007 4:27:00 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Other
 Thursday, March 22, 2007

I just finished week long second trimester of my Masters course. The module was about Design Patterns. Every day we had lectures in the morning and then labs in the afternoon. During the lectures we went through most of the Gang of Four patterns, they were pretty interesting even though I knew most of the stuff. What I really loved about the course were the labs.

 

Every day we were given some working application and we were supposed to apply some specific pattern to extend the functionality of the application. I always believed, that it’s impossible to learn design patterns just by reading a book, you gotta look at the code and try to incorporate it into it, or just ‘get it’. What was good about the exercises in the lab is the fact that the applications were easy enough to understand their inner workings immediately, but complicated enough to see, that some pattern would help here a lot.

 

Oh yeah, and I was able to refresh my memory of Java and Swing. Win-win situation.

Thursday, March 22, 2007 3:00:34 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Other
 Wednesday, February 28, 2007

I’ve just finished writing a small application for myself. It’s called Application Launcher and yes, it does launch applications…..

 

There were two reasons for writing this small app:

  1. It takes forever to start my system since there are over 10 applications that are invoked at startup. What is ever more annoying all of them start at the same time! This leads to 1-2 minutes after system starts when I cannot use the system since everything is stating up.
  2. I needed a sort of like a Startup utility for my USB key. When I put it in, I want to be able to start my email client, calendar, and RSS reader with least amount of clicks and of course I want to avoid the ‘Startup freeze’.

 

Welcome the application launcher.

 

Features:

  • Launches applications (duh)
  • After each launch there is a configurable delay before the next application launches
  • When closing the application it tries to close all the started applications.
  • When needed it uses relative path (which is great when you’re using USB key)
  • If you want, you can have various configurations of what applications are starting even in one directory, simply rename the application and for each name it will have different configuration.

 

Here is the exe (ApplicationLauncher.zip (74.87 KB)) and the source code (ApplicationLauncher - source.zip (181.58 KB)) of the application. It has been written in .NET v2.0.

 

 

 

Wednesday, February 28, 2007 4:20:15 PM (GMT Standard Time, UTC+00:00)  #    Comments [2] -
Tools | Application Launcher
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Marcin Waligora
Sign In
All Content © 2008, Marcin Waligora
DasBlog theme 'Business' created by Christoph De Baene (delarou)