Errr, some catchy title.... RSS 2.0
 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
 Wednesday, February 14, 2007

For most situations we want the users, not the computers to be the audience of our websites. Therefore, there are situations when we must protect ourselves from automated bots that obtain information from our website, eat the bandwidth or just consume our services (create new email accounts, send text messages to cell phones and so on). The tool for this job is called CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart). If you’re interested how it came into being go to CAPTCHA on Wikipedia.

 

Below is a list of three CAPTCHA solutions that vary from easiest to implement and of course least secure to the safest one (which also involves most work).

 

Hidden input

 

The simplest of the techniques is to embed in the page a HTML input element.

 

<input name="address2" type="text" runat="server" />

 

Next, we make it invisible on a page by applying CSS style (just one of the possibilities). On the submit, we check if the value has been filled. If it has, then that means a bot was going through the page, not the user (as user could not see the textbox). This solution is very easy to implement and should work if the bot is completely automated (there was no recording of what type of fields should be filled in).

 

NoBot from AJAX Control Toolkit

 

One security level higher is the NoBot from ASP.NET AJAX. It is again, a solution that does not need user interaction; therefore it is not very reliable. Also, as it is part of ASP.NET AJAX it will only work in AJAX enabled environment. On the plus side, the user is not bugged by filling out some extra fields.

 

NoBot employs several techniques to prevent bot attacks:

  • Forcing the client's browser to perform a configurable JavaScript calculation and verifying the result as part of the postback. (Ex: the calculation may be a simple numeric one, or may also involve the DOM for added assurance that a browser is involved)
  • Enforcing a configurable delay between when a form is requested and when it can be posted back. (Ex: a human is unlikely to complete a form in less than two seconds)
  • Enforcing a configurable limit to the number of acceptable requests per IP address per unit of time. (Ex: a human is unlikely to submit the same form more than five times in one minute)

 

If you want to see a live demo, go to NoBot Sample from Ajax Control Toolkit

 

CAPTCHA Image Control

 

Safest on the list is CAPTCHA Image Control. Since everyone has used these CAPTCHAs as user it’s best to just show how this solution looks.

 

 

The image displayed is distorted not to allow machine to find out the text on a picture. There are a lot commercial solutions that offer these controls for ASP.NET, however there is also a bunch of them free. I particularly like the one written by Jeff Atwood, author of the brilliant www.codinghorror.com blog. He published this control on CodeProject, it is located here. Go check it out!

 

Note:

 

Last solution is not suitable for blind or visually impaired users. Therefore, sometimes you can find sound CAPTCHAs for these scenarios.

Wednesday, February 14, 2007 4:15:46 PM (GMT Standard Time, UTC+00:00)  #    Comments [3] -
Other
 Friday, February 09, 2007

I stumbled upon an amazing explanation of Web 2.0. Not only it's highly entertaining, but also shows what Web 2.0 is all about. Now, if anybody asks what is Web 2.0 I'll point them towards this clip.

Friday, February 09, 2007 12:07:57 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Other
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 2009
Marcin Waligora
Sign In
All Content © 2009, Marcin Waligora
DasBlog theme 'Business' created by Christoph De Baene (delarou)