Category name:Sourcecode

Get the physical path of a path that uses a subst drive

My previous employer used a tool to attach databases that were located on a substituted path. I needed this conversion logic in another kind of environment and used the almighty google. So I hit an article on Avner Kashtan‘s blog titled Query SUBST information . His code sample proved very usefull but it didn’t support relative paths on the current drive so I altered it a bit. Below is my version and put it here for other people to use and abuse.

using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;

public static class Subst
{
public static string GetRealPath(string path)
{
const string MSG_PATH_INVALID = "The path/file specified does not exist.";
const int BUFFER_LENGTH = 1024;

if (path == null) throw new ArgumentNullException("path");
if (Directory.Exists(path))
{
path = new DirectoryInfo(path).FullName;
}
else if (File.Exists(path))
{
path = new FileInfo(path).FullName;
}
else
{
throw new ArgumentException(MSG_PATH_INVALID, "path");
}

string realPath = path;
StringBuilder pathInformation = new StringBuilder(BUFFER_LENGTH);
string driveLetter = Path.GetPathRoot(realPath).Replace(@"", string.Empty);
QueryDosDevice(driveLetter, pathInformation, BUFFER_LENGTH);

// If drive is substed, the result will be in the format of "??C:RealPath".
// after that strip the ?? prefix and combine the paths.
if (pathInformation.ToString().Contains(@"??"))
{
string realRoot = pathInformation.ToString(4, pathInformation.Length-4);
realPath = realRoot + realPath.Substring(2); // Remove the drive letter
}

return realPath;
}

[DllImport("kernel32.dll")]
static extern uint QueryDosDevice(string lpDeviceName, StringBuilder lpTargetPath, int ucchMax);
}

I tried to use Manoli’s csharp to HTML formatter but it screws up. So no syntax coloring this time.

Subversion troubles "PROPFIND request failed on ‘***’ ‘***’ path not found"

I created a repository at opensvn.csie.org today for the website I created with a friend for the volleybal club. We really needed version control because we are both working on the project at the moment plus that I really don’t like all those *.old *.old2 *.old3 files hanging around 🙂

So I committed the various data of the project to the subversion repository and after that wanted to branch it to identify the site that is currently live. I started the command prompt and use the svn copy action to tag the current development branch.

svn copy
https://*/yumwebsite/trunk
https://*/yumwebsite/branches/v0 -m “Version 0”
After running the command it failed with the following output:

svn: PROPFIND request failed on ‘/yumwebsite/!svn/bc/2/branches’
svn: ‘/yumwebsite/!svn/bc/2/branches’ path not found
My first thought was that the opensvn.csie.org was at fault but quickly I realised that wasn’t the case. So started googling what I was doing from. The problem was that the folder ‘branches’ really did not exist just as the error said. But somehow I blocked that error message in its exact form. So after adding the branches folder the the project root the copy action ran error free. The stupid thing is that I had the same behaviour a while ago. So I decided to post this for my own convenience in case I forget it again.

HttpHandler to format csharp, xml, vb.net, etc.

Today isn’t the best sunday in the Netherlands to enjoy the weather so that left me with the decision to do something usefull (like the household) or do some rainy sunday coding. I obviously choose the latter and that is the reason for this post.

I’m currently busy refining my home buildserver. Build results can be browsed as well as the sourcecode but the code didn’t get formatted. So wouldn’t it be handy if you have a HttpHandler that formats sourcecode like csharp, vb.net, xml (related) and html? So I started googling but could find one! So that left me with some work!

I based the HttpHandler on Manoli’s CSharpFormat class. There are three HttpHandlers available:

  • CSharpFormatHttpHandler
  • HtmlFormatHttpHandler
  • VisualBasicFormatHttpHandler

They resemble Manoli’s formatters if you didn’t noticed already….

You need to add Manoli’s CSharpFormat assembly and my Exyll.Web.HttpHandlers.Code assembly to you bin directory of you website. To make it all work you have to edit the web.config file and add the http handlers as shown in the web.config example Watch out that you don’t give access to your files that need to be secure!!!

After configuring all you need to do is test it! If everything works then you should see something like shown here.

Code formatter shown in action

Download the HttpHandler for csharp, xml and vb.net code formatting.
See an example web.config.

Christmass coding : RGB Plasma

It seems that I wasn’t the only one with some demoscene nostalgia as Frans was first today with his cheesy rotozoomer!

Way to go Frans! 🙂 You can see his christmass coding rotozoomer here.

Well I was more in the mood for a simple plasma. I started with the usual math stuff like how did that cos / sin stuff worked and after that I had more questions like how to have a fps indepandant time correct effect and unsafe code for performance . But I wasn’t really satisfied with the standard XOR’ed circles and decided to use the RGB components and merge them. Below is a screenshot but I seriously suggest you download the archive and see it running.

Most code was written today but some was in the fridge for months. Waiting for a day to finish it and well.. today was the codes lucky day.

Download c# RGB plasma (needs visual studio express to build)

I also included a rotating star field as a bonus ;-).. it was the first effect to see if the crappy gdi based code actually worked. Right click the effect for a context menu to select the framerate. Press F12 for a bitmap save of the effect.

Effect source is included.

MSN like idle behaviour in your application

I posted an article that includes a link to a class file I wrote today that can detect if a user is idle for a certain period and triggers an event.

This is my own quoted text from the article.

I’ve just created a little nice class that helps in building applications that need MSN like behaviour regarding detecting a users idle time. This can be very handy when your application notifies the user for some special event through a non intrusive popup for example. But will the user see this popup when it isn’t behind it’s computer?

This is where this class comes in. When you detect that the user is idle you stack the notification events until the user is active again to show them to your user.

I have seen some implementations that detect a user idle’ness this way but not a single one also includes an event that get’s fired when a user is available again.

Click here to read the IdleTimer to have MSN like behaviour in your application article.

StateMachine in c# and xml, v3 (updated)

Updated:
 – New archive to download (v3)
 – XML updated
 – Code rewrite with delegates and helper methods

I added unittest for a switch in version 1. Leslie had some troubles with building his trafficsign. I now added a trafficsign as a unittest and it outputs the following:

<?xml version="1.0"?>
<Machine Id="Switch" InitialState="On" xmlns="Exyll.StateMachine">
  <SubStates>
    <State Id="On" InitialState="Red">
      <SubStates>
        <State Id="Red">
          <Transitions>
            <Transition EventName="TimeTrigger" Target="Green" Guard="TimerIs4" Action="TimerReset" />
            <Transition EventName="TimeTrigger" Target="Red" Action="TimerIncrement" />
          </Transitions>
        </State>
        <State Id="Yellow">
          <Transitions>
            <Transition EventName="TimeTrigger" Target="Red" Guard="TimerIs2" Action="TimerReset" />
            <Transition EventName="TimeTrigger" Target="Yellow" Action="TimerIncrement" />
          </Transitions>
        </State>
        <State Id="Green">
          <Transitions>
            <Transition EventName="TimeTrigger" Target="Yellow" Guard="TimerIs4" Action="TimerReset" />
            <Transition EventName="TimeTrigger" Target="Green" Action="TimerIncrement" />
          </Transitions>
        </State>
      </SubStates>
      <Transitions>
        <Transition EventName="TurnOff" Target="Off" />
      </Transitions>
    </State>
    <State Id="Off">
      <Transitions>
        <Transition EventName="TurnOn" Target="On" />
      </Transitions>
    </State>
  </SubStates>
  <Events>
    <Event>TimeTrigger</Event>
    <Event>TurnOff</Event>
    <Event>TurnOn</Event>
  </Events>
</Machine>

Download link : StateMachine version 3

StateMachine in c# and xml

Yesterday I browsed through the new articles at codeproject.com. Leslie Sanford StateMachine articles had my attention. He has designed and implemented it in c#. A job done pretty well I think. I took a look at his code that reads an xml definition to deserialize its state design. My thoughts were that it wasn’t really readable and logical so I made a class design that serializes to a "self-describing" xml document.

An example:
<?xml version="1.0"?>
<Machine Id="Switch" InitialState="On" xmlns="Exyll.StateMachine">
  <SubStates>
    <State Id="On">
      <Transitions>
        <Transition EventName="TurnOff" Target="Off" />
      </Transitions>
    </State>
    <State Id="Off">
      <Transitions>
        <Transition EventName="TurnOn" Target="On" />
      </Transitions>
    </State>
  </SubStates>
  <Events>
    <Event>TurnOff</Event>
    <Event>TurnOn</Event>
  </Events>
</Machine>

If you are interested in this class design and the xmlattributes I had to add to achieve this xml format then download StateMachine code.

My WiX experience

Most people use the setup routines supplied with Visual Studio or something like Wise or Installshield to create their setup packages. My current project needed some setup routines and I needed this excuse for sometime to finally see that WiX is all about. Well one thing you don’t get is an easy 1,2,3 click and go experience to create your MSI installers.
The stuff you get are basically some command line tools candle, light, dark and recently tallow. Candle is the compiler to create object files from xml input. Light is the linker that does the magic to create an installer or merge module. Dark can decompile an msi which comes in quite handy when you know that some installer of some program has cool functionality in ther setups and last but not least tallow which can create input xml based on the files on the file system. This is very handy in combination with automated builds.

They are currently busy with Votive which is a very interesting Visual Studio add-on that can create easy setups. One of Votive cool features is that acts like a preprocessor. It can replace placeholders in the WiX xml files. This way you can create templates to easily create setup’s for small applications. However… it really needs the ability to have ‘tallow like’ functionality to automatically add all output files. Just as adding some merge modules within a nice gui would be a blessing. I would really like to see those features added in the future maybe I will add them myself when I can ‘create’ some time.

What do most installers have in common? Generally they have a Welcome screen, an EULA, a destination selection, a full, common or custom selection, progress indication and a result screen. Some applications have the ability to launch the application and/or show the read me when finished. These are quite common for normal desktop applications but when it comes to most applications I work on professionally we need extra functionality. Like to be able to install dependencies as the .net framework, setup a web project, windows services, a database, com+ and/or msmq. Believe it or not but this can all be done with WiX! I got most information to get these thing done is from the excellent WiX Tutorial by Gábor DEÁK JAHN .

What really is cool is the way tallow works. Tallow is a tool to create a wxs xml input file for candle. It scans a directory and imports all files. It is able to add/remove/configure the full range of entities in the COM+
catalog which is still very important because loads of dependencies are still com based and application services are installed in com+. So tallow is my friend as trees are for Bob Ross. The best thing about tallow is that you can merge it into your build engine with for example nAnt. You can create a nAnt task that launches tallow and then let candle compile that output together with a standard template for that specific project type. Then we only need to links all that stuff together and voila there is the msi.

The WiX toolset is very flexible and most things can be customized to suit your needs. One thing I have already learned it that you need to create some good basis WiX templates and use those to create most installer types. I will definitely recommend to use WiX especially within automated build environments.

  • Recent Posts
  • Recent Comments
  • Archives
  • Categories
  • Meta