Debugging windows services

I’ve written a post before about how I debug windows service (i.e. run them from within Visual Studio without having to use “Attach to process”). I’ve come up with a new easier approach.

Continue Reading





The persistence layer in SharpMessaging

I’m working on a messaging system in .NET. It’s purpose is to allow you to use reliable (and transactional) messaging inside your application without the need of an external server. This post is about the persistence layer (i.e. file storage). It can handle somewhere between 100 000 and 300 000 messages per second depending on the configuration.

Continue Reading



Griffin Framework homepage

Griffin Framework just got a new homepage.

It’s still basic, but will continue to grow. I’ll also commit it in the “homepage” branch at github. Feel free to add improvements to it.



Simple command line parser

I have tried 3-4 different nuget packages for command line parsing. Didn’t figure out how to use them properly. Here is a small command line parser.

Usage example

Here is how I use it.

internal class Program
{
    private static void Main(string[] args)
    {
        var parser = new SimpleCommandLineParser();
        parser.Parse(args);

        if (parser.Arguments.ContainsKey("server"))
        {
            var server = new LoadTestServer();
            server.Start(int.Parse(parser.Arguments["server"][0]));
            Console.WriteLine("Server started");
        }
        else if (parser.Arguments.ContainsKey("client"))
        {
            var client = new LoadTestClient(parser.Arguments["client"][0]);
            client.Start();
            Console.WriteLine("All enqueued");
        }
        else
        {
            Console.WriteLine("SharpMessaging.BenchmarkApp");
            Console.WriteLine(" - Check the app.config for additional configuration options");
            Console.WriteLine();
            Console.WriteLine("SharpMessaging.BenchmarkApp -server [port]");
            Console.WriteLine("SharpMessaging.BenchmarkApp -client [host:port]");
            return;
        }

        Console.WriteLine("Press ENTER to quit");
        Console.ReadLine();
    }
}

Code

And the actual code:

public class SimpleCommandLineParser
{
    public SimpleCommandLineParser()
    {
        Arguments = new Dictionary<string, string[]>();
    }

    public IDictionary<string, string[]> Arguments { get; private set; }

    public void Parse(string[] args)
    {
        var currentName = "";
        var values = new List<string>();
        foreach (var arg in args)
        {
            if (arg.StartsWith("-"))
            {
                if (currentName != "")
                    Arguments[currentName] = values.ToArray();

                values.Clear();
                currentName = arg.Substring(1);
            }
            else if (currentName == "")
                Arguments[arg] = new string[0];
            else
                values.Add(arg);
        }

        if (currentName != "")
            Arguments[currentName] = values.ToArray();
    }

    public bool Contains(string name)
    {
        return Arguments.ContainsKey(name);
    }
}

Features

The great thing is that .NET have already done an initial parse for you. You can for instance use quotes in it to get everything in the same argument:

someApplication "this is argv[0]"

My parser parses the following:

someApp -server 8344 arg2

as

Console.WriteLine(parser.Arguments["server"][0]); //8334
Console.WriteLine(parser.Arguments["server"][1]); //arg2

While this:

someApp server verbose

can be checked as:

Console.WriteLine(parser.Arguments.ContainsKey["server"]);
Console.WriteLine(parser.Arguments.ContainsKey["verbose"]);

i.e. strings that are specified before the first dash argument (“-arg”) will be considered to be an argument by itself.



Pages:1234567...16