Divis Blog

Just another geeks blog.

Much to do!

clock July 20, 2008 22:21 by author Divi

Since a while I had no time anymore to write some texts for my blog, but because there was just a little break, I thought I could add a short summary of my projects:

That thing that swallowed most of my time during the last weeks was the Microsoft exam 70-536: "Microsoft .NET Framework - Application Development Foundation". After I investigated all my free time in it and couldn't get it at the first try, I had to take my second shot. But the passing of the exam didn't release that much of my time, because all that projects that had been bottled-up had to be done now.

Here're some of them:

Pixelkaempferin - alias Jessika Wollstein

image

A good friend of mine, which wanted to demonstrate her abilities of graphic design. I really enjoyed working on that page, because I could try out some gimmicks. One of them was a the fact that she is now able to configure almost every page by XML and the icons are loaded automatically (matching to the config). Another thing was a diagonal menu, wherefore I just had the idea of an imagemap and some attached mouseover effects.

Spielefinder.Net

image

On a party one evening I talked to my girlfriends brother and asked him about some tools the web is still missing. I wanted to write a new project as a little training, but it needed to be a project which didn't already exist. During our conversation about verious ideas, he got me on the point of a game database. There're many of them, but none allows to filter the games by hardware. So about a week ago I got a page online which was able to filter its database for a specific hardware setup. Over that the client is able to specify a tolerance via some sliders (from the ASP.Net ajax toolkit) for the case they want to upgrade their PCs.

Codeplex - DownloadCounter

And last but not least: I added a new project to Codeplex named "DownloadCounter". At the moment it's just a very simple assembly and a demo project. I started that project, because the boyfriend of my sister asked me if I could put some files online for download and I decided to give him the ability to track how many times these music tracks where downloaded (he's a little hip-hopper) so that he can measure his success (or not :-D). And because I already wrote several download counters, I thought I could write one in .Net which was reusable and put it on Codeplex so that it can be improved over time - so I'm now hoping that some guys will download it and give me some good hints for improving it.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Token not yet valid

clock May 15, 2008 20:50 by author Divi

Some days ago I got the security token project back to the surface (from the deepest part of my repository) to use in in another current project. Unfortunately I got an error message as I started the project for the first time. I didn't know where it came from, so I went through the code step-by-step. Fascinated I recognized that it didn't appear again. I reloaded the page several times, but everything seemed to work fine. Because of this I thought it would have been a cache problem and forgot it.

Some hours later I had deleted my cookies and tried to issue myself a new token - but there the error was again - and again it disappeared during the step-by-step debugging.

Because I couldn't find a specific reason for this I spread several breakpoints all over the code and just hopped from one to the next to narrow the place of the exception. As I finally found the place in the code, I got the following error message:

"The SamlToken is not time valid. The current time "5/14/2008 11:29:21 AM" is outside the Effective "5/14/2008 11:29:59 AM" and Expiration "14.06.2008 11:29:59" time of the token.

image

What happened? First I guessed that there could be a bug in the calculation of the date, until I recognized: The token was valid some seconds AFTER the issuing. But why? Could that be a build in method?

After some research in the internet I found someone who had the same problem. He already had answered the question for himself: "I think I should correct the time of the server" ... right ... there was a time difference of 30 seconds between my PC and the dev-server I used - that has been the reason why the token was not YET valid as I it was issued to me - and this was the reason why I couldn't find it as I went through the code step-by-step, because I needed a longer time to step through than the differnce between both machines.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Capture process output

clock May 3, 2008 22:39 by author Divi

As I recently worked on a private project, where I had to compare several files with each other, I also came across the integrated "Diff" method of SVN. To compare two files, you can call the SVN with the following command:

svn diff -r OLD_REVISION:NEW_REVISION FILE

and you get instantly your output in the diff-format.

 

To call SVN I wanted to start the process from an ASP.Net class in the background and capture the output. Unfortunately I got a problem. The output seemed to be empty all the time.

As I tried the same thing some days later, I suddenly got the desired output. When I came home, I replaced my old code with the new one, but again the output remained silent. Because of this I started to compare both applications (my test app and the app for the file comparison). At first I thought Vista would suppress the output, because the PC on my workplace has XP installed on it, while my private PC has Vista, but this seemed to be the wrong reason, because it also didn't work as I executed the testapp from my "work"-PC on my private one... But that was the moment I recognized it. The difference was the application type: While my project itself was a web application, the test project was a Consolen application.

This is the code I used: 

 

ProcessStartInfo ps = new ProcessStartInfo("svn", "diff -r 4:6 file:///MY_LOCAL_FILE");
ps.UseShellExecute = false;
ps.RedirectStandardOutput = true;

Process p = new Process();
p.StartInfo = ps;
p.Start();
p.WaitForExit();

string output = p.StandardOutput.ReadToEnd();

 

The string "output" was always empty (not null), while the console application showed the right output:

 

Console:

image

Web application:

image

 

That problem I had to solve, because I didn't want to use a desktop application. So I tried several things. At first I thought there would be problems with the TrustLevel of the application and that the web application was more restrictive, but no matter which changes I made at the security settings, there was no change, until I found a code snippet, which I copied 1:1. It worked in the web application, but when I reduced the copied code to the needed parts by removing the "senseless" stuff, it didn't work again... So I took the code from the internet and removed line-by-line to find out which of the lines made the clue - in this way I found the reason:

The magic property was "RedirectStandardError". As soon as I changed its value to "true", everything worked fine:

image

 

HINT:  

As I started to write this blog entry, I first wanted to use another application than SVN, so I chose "PING" (because it's available everywhere). Interestingly it worked without any problems:

image

So obviously it depends also on the type of the called application, if you have to change the property or if it works also without.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Various 20080406

clock April 6, 2008 15:28 by author Divi

In the last time I haven't had much time to work on my blog or some of my private sites, because at my job we've (fortunately) very much work to do which is sometimes (unfortunately) a little bit short of time.

To not open a larger theme in here, which I'd like to explain much more detailed, but wouldn't have the time to, I decided to just post some things that I found during the daily work of the last weeks:

 

VSO DivxToDVD

Some days ago I was asked to get a very debatable video from the internet on DVD, because a friend of mine has no computer to use the internet himself or at least watch the downloaded video. After some flops of software I tried, I was guided by Google to the page of Softonic, where I found the VSO DivxToDVD Converter 0.5.2.99. It's a pretty cool tool, simple to use and free:

image

As I went to the producers page to check out for some updates, I found out (to my regret) that the nice (and, much more important, free ;-D) Tool became fee required. I think it's a good thing that VSO decided to bring it to the market, because I really like that tool, but I don't want to pay for it as long as I just need it from that rarely. The new name of the tool is ConvertXToDVD and costs about 40€.

(Hint: Softonic still offers the link to the old, free version).

 

SDP Multimedia

As I was searching for the solution of a problem during the last week, I found a webcast which I'd like to watch, but which had no download link. It seemed as if there'd be some very interesting infos inside of it, but because it was to long, I tried to download it on various ways (which didn't actually work) - until I found the stream ripper SDP Multimedia.

image

It's a little bit slow while downloading (or perhaps it has just been the streaming-server :-D), but in any case: It's also free!

You only need to add a stream via the MMS protocoll and instantly the SDP starts downloading it to your harddisc.

 

FileSystemWatcher

At work we're using VisualCron since several months to do our filesystem-based cronjobs. Some days ago I found out that that the .Net framework allready offers a helper class, which can be used to do exactly this thing: System.IO.FileSystemWatcher.

This object allows you to watch filesystem and react on various events (e.g. changes, updates,...). Therefore you only have to instantiate the object, choose the directory to watch, (optionally define a file mask (e.g. to just react on .cs-files)) and to tell the object to start watching:

 

System.IO.FileSystemWatcher fsWatcher = new System.IO.FileSystemWatcher();

fsWatcher.Path = @"C:\fsWatcherTest";
fsWatcher.Created += new System.IO.FileSystemEventHandler(FileCreated);
fsWatcher.WaitForChanged(System.IO.WatcherChangeTypes.Created);

 

With this code, you get the FileSystemWatcher to wait for the creation of exactly one file and call the method FileCreated afterwards. To react on the renaming of this file - and this not once, but several times, I extended the program in the following way:

 

class Program
{
    static void Main(string[] args)
    {
        System.IO.FileSystemWatcher fsWatcher = new System.IO.FileSystemWatcher();

        fsWatcher.Path = @"C:\fsWatcherTest";
        fsWatcher.Created += new System.IO.FileSystemEventHandler(FileCreated);
        fsWatcher.Renamed += new System.IO.RenamedEventHandler(FileRenamed);

        while (true)
        {
            fsWatcher.WaitForChanged(System.IO.WatcherChangeTypes.Created);
            fsWatcher.WaitForChanged(System.IO.WatcherChangeTypes.Renamed);
        }
    }

    static void FileCreated(object sender, System.IO.FileSystemEventArgs e)
    {
        Console.WriteLine(String.Format("File Created: {0}", e.FullPath));
    }

    static void FileRenamed(object sender, System.IO.RenamedEventArgs e)
    {
        Console.WriteLine("---");
        Console.WriteLine("File Renamed:");
        Console.WriteLine(String.Format("Old path: {0}", e.OldFullPath));
        Console.WriteLine(String.Format("Old name: {0}", e.OldName));
        Console.WriteLine(String.Format("New path: {0}", e.FullPath));
        Console.WriteLine(String.Format("New name: {0}", e.Name));
        Console.WriteLine("---");
    }
}

 

After I entered the code I did the following steps

1.) Started the program.

2.) Created a text file in the specified directory.

3.) Renamed the newly created text file.

This caused the following output:

image

 

Interesting: If I create a new file on Vista via right clicking, I get a new file where the file name (without the extension) is marked, to ease the renaming. As I just said - the file is firste created an renamed later on (as can be seen at the image above). So take care that a file you handle might not have its final name after the creation.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Sitecore Xpress released

clock February 7, 2008 23:13 by author Divi

Today it was the time I waited for. Almost as on christmas I was glad that as I entered the page of "Sitecore Xpress", there was no longer the teaser saying "Coming to a server near you...", but a nice looking download page. For sure I logged in instantly and downloaded it. Small 250MB, which needed less than 10 minutes on their way to my desktop ... the license code on the other hand took his time ... I got it at 4pm - But the waiting was worth it. Now I can finally play around with it on VISTA...

image

The commercial Sitecore (recently called "Sitecore red") had some problems with IIS on Vista ... But I think that will be also fixed on the next version, which I await shortly.

In any way - it's nice to simply ignore the small error message on the beginning (saying the IIS would not run) and just start installing it and - who would have believed - after some minutes - a browser window opened, the page appeared and it simply works. This is how it looks on my screen: 

image

That cheered my heart.

 

But what the hell is Sitecore? Sitecore is a highly developed CMS - the best I've ever seen. You almost have the like on your own desktop, if you're welcomed directly after the login with the following screen:

image

(Yes - that's a screenshot of the current version) ... so just don't wonder if the windows need a little bit longer on the first opening... .Net has to compile the libraries for the first run.

As you can see on the screenshot, the interface looks almost like an Windows-desktop ... and also the "Content Editor" corresponds to the layout of the Windows-Explorer. As a Windows user you shouldn't have any problems to find your way through the system:

image

 

So if you would gladly try that CMS, which is normally for commercial use only and which is also used in enterprise solutions: Download Sitecore Xpress in any case! It's free and you won't ever have the same kind of fun with any other CMS ;-).

 

Links

Sitecore Website

Sitecore Xpress Website (DOWNLOAD)

German Sitecore Solution Partner "netzkern GmbH"

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


CryptographicException

clock January 21, 2008 18:34 by author Divi

Because I hit that error today for the second time (the first time appeared some weeks ago), I thought I just should write it down to not forget it again:

If you get the error messages "Bad Key" or "Invalid handle" in relation to any kind of "System.Security.Cryptography.CryptographicException", you should at first check the write/read-permission of the private-key-file of the certificate - and in the second step, if it contains all required values for our intention (Because you can't do everything with every certificate).

 

My problem: I tried to use an X.509 certificate to sign a Saml-token. Foolishly there were errors on several places, which a catch-block (in combination with a not working logger) hid, so that I needed a lot of time to search for the reason.

Both errors appeared while serializing the token.

 

Two problems and their solution:

Problem 1 - "Invalid handle": This error appeared, if the script couldn't access the private-key file of the certificate. The user "NETWORK SERVICE" needs at least read-permission for this file.

How can I find the private-key file? There's a nice tool collection, created by Microsoft, called the WSE "Web Service Enhancements"... the version, which is, I guess, the current one, is 3.0 - even if most of the results show 2.0, if you search for them with Google.

This collection contains a tool named "WSE X.509 Certificate Tool", with which you can simply select the right values in the two dropdown lists and open a filtered list of all found certificates by hitting the button. As soon as you open a certificate, you can see all information about it. This is the view of one of my test-certificates, which I created myself.

image

At the bottom of the window, you can find a button labeled "View Private Key File Properties". If you click that button, it displays the normal Windows-file dialog for the specified private-key file. In the tab "Security" you can now set the permissions for that file (in our case "NETWORK SERVICE"). As soon as the script is able to read the file, the "invalid handle" message disappears. 

 

Problem 2 - "Bad key": Who is able to read, has an advantage (german saying):

image

As soon as the one input field (Image 1) is replaced with three single input fields (Image 2), the description text on the right changes. It sais: "If the extension is not present, three values will be shown[...]". If I would have read that the first time I tried it, I would have saved much time, because the certificate I bough simply hasn't had the so callend "Subject Key Identifier", which is required for signing the token. As soon as the certificate contains the SKI, you won't get the error message anymore.

 

You can find the WSE tools on the Microsoft-download-page.

 

One last hint I got for you: If you want to check your software against certificates, you can create your own certificates, containing all combinations of rights. There's a nice tool from EldoS which is called "Crypto4™ PKI". It's commercial, but a 30-day trial version can also create nice certificates (for a specific time) ;-).

Currently rated 3.5 by 2 people

  • Currently 3.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Adding MessageInspectors

clock January 17, 2008 01:46 by author Divi

After some time ago noone could explain to me at tutorials.de how to log incoming and outgoing messages in WCF, I thought I should tell share my knowledge about that with you:

WCF offers a configuration for MessageLogging by default. These are the so called "Diagnostics" and absolutely sufficient if you're really just trying to log something. The related article about that you can find at the MSDN.

Unfortunately the logging can't be configured as detailed as I needed it at that time. My task was to store the sent message related to an object, to check wheter the preprocessing wrapper does its job.

After some searching I found the way of the "Extensions". And that works as follows:

You can set the endpoint in the configuration and attach an Endpoint-Behavior::

<endpoint address="ADDRESS" binding="basicHttpBinding" behaviorConfiguration="AttachClientInspector" contract="CONTRACT" />

Therefore a "Behavior" named "AttachClientInspector" needs to be created (Of course you can chose the name yourself). This one would look somewhat look like this:

<endpointBehaviors>
  <behavior name="AttachClientInspector">
    <ClientInspector />
  </behavior>
</endpointBehaviors>

If you're using Visual Studio 2005, just don't wonder why the "ClientInspector"-Tag is beeing marked with the description "...invalid child element". That's just because the VS2005 doesn't recognize the Extension itself. And that's the next step you have to do. The config section "System.ServiceModel" allows subsections named "Bindings", "Behaviors" and "Extensions". Here you can add your "BehaviorExtension":

<behaviorExtensions>
  <add name="ClientInspector " type="CLASSNAME, ASSEMBLYNAME, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>

Of course the CLASSNAME has to point on a specific class, which is qualified for inspecting the message. To make sure that the class is accepted for this, you have to derive it from "System.ServiceModel.Configuration.BehaviorExtensionElement" AND implement "System.ServiceModel.Description.IEndpointBehavior". You have to derive from BehaviorExtensionElement, to use the class as an extension for the behavior. It requires the allocation of BehaviorType, where you can just return the current class via typeof and the method CreateBehavior, where you just have to return an instance of the current class.

public override Type BehaviorType
{
    get { return typeof(CLASSNAME); }
}

protected override object CreateBehavior()
{
    return new CLASSNAME();
}

On the other hand IEndpointBehavior provides the methods which are called, when the extension is executed at runtime. The interesting method for us should be: "ApplyClientBehavior". This method has a parameter "clientRuntime" of the same-named type. Here you can now attach the inspector as follows:

clientRuntime.MessageInspectors.Add(new CUSTOMINSPECTOR());

So... that's the key thing, to call our inspector as soon as the Endpoint is beeing used. Now there's only missing the implementation of the inspector itself. Therefore you have to create a class named CUSTOMINSPECTOR (the uppercase words are just placeholders to demonstrate the relations) and derive it from the type "System.ServiceModel.Dispatcher.IClientMessageInspector". This interface adds two methods. AfterReceiveReply and BeforeSendRequest. The second one awaits a return value of the type "object"... simply write "return null;" into this method and everything works fine.

If you now hit the compile button, everything should build without any problems. Now we have to add the implementation of the inspector. Therefore both methods have parameters of the type "System.ServiceModel.Channels.Message". In these parameters there's the real message contained.

If you're now trying to use that object, I guess it won't last a long time until you're getting stressed up, because the message-object is getting invalid, as soon as you read any information out of it. Cool, isn't it? ;-)

But you can solve that problem also very easily, because the message-objects contain a method called "CreateBufferedCopy". By calling that method you can create a "buffered copy" of the current message-object:

MessageBuffer bufferedMessage = request.CreateBufferedCopy(request.ToString().Length);

(Here's the message-object "request". In the "AfterReceiveReply" the object is called "reply".)

 

You can modify the "buffered copy" as often as you want and create a message object again after your analysis has finished:

 

request = bufferedMessage.CreateMessage();

(And as already told - again: The parameter of the reply-method is "reply". The object which is filled here, has to be the same as passed to the current method.)

 

All you have to know about it is - you've got several ways to analyze the content of the message:

1.) You can create a XPathNavigator with the method "CreateNavigator" out of the "bufferedMessage", with which you can analyze the xml itself. Over that you can access the content at any part of the XPathNavigator via its property "InnerXML". This one contains the content of the current node as a plaintext-string.

2.) You can also, as already said before, use ToString on the request object, which will return the content of the message (The envelope).

I wish a lot of fun with that and hope I could help you!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5