Back to Volta

Today I took the afternoon to take another look at Windows Live Labs Volta.

The idea of deferring the application partitioning to the last minute may be good for some types of projects but translating “X” (IL in this case) into JavaScript was something I’ve been wanting since the ASP + VB6 days!

I always thought that writing code in general and data validation code in particular for the server and then for the client was a tedious and error prone task.

At those days I had to write validation code in VB6 for the server and then rewrite it again in JavaScript for the client. Besides being tedious, it is an error prone task because you had two places to maintain the code as validation logic evolved.

Today I decided to test this with some legacy code I have here. I was thinking on getting some document number validation code I have here, but I stumbled across a function that translates currency amounts into their textual equivalents. Not sure how to say this in English, but the idea is to translate “1,234.56” into “Um mil, duzentos e trinta e quarto Reais e cinquenta e seis centavos”. That is “One thousand, two hundred and thirty four Reais and fifty six cents” in Portuguese.

I got this code originally written in Clipper from a magazine back in 1993.

Sometime later I rewrote it in Access Basic 2.0. A couple of years later ported it to Access 97’s VBA and at last VB 6. I have not touched it since 2000.

I ran the project through Visual Studio 2008 VB project Converter, made a couple of tweaks (really!), and added the project to my Volta test solution configured to run in Debug mode and voila! It worked like a breeze!

The important part is that I converted the project to a normal VB Class Library. Not a Volta Class Library. That implicates that I could theoretically use any any library that does not have dependencies on anything not supported by Volta and have it flow as JavaScript to the client side.

That must be what Erik Meijer means when he says "Volta stretches the .NET platform to cover the Cloud.”!!

It is important to notice however, that when you run the code in Debug mode, you are really running the IL version of it. I’m not yet sure how the magic works. Give me time!

As soon I tried to run it in Release mode, the page started complaining about unsupported features such as the Decimal constructor that accepts a Double or somewhere in the VB string helper functions trying to get a CultureInfo.

This is comprehensible since the technology is in its very early stages.

I tried equivalent BCL types and members without using the Visual Basic helper functions, and they worked so as soon as I find more time, I’ll try to fix it. I could simply try to isolate the helper functions giving me trouble and fix those pieces of code, but I’m more inclined to rewrite it in C# since it is not too much code and I have not been programming seriously in VB since 2005.

Anyway I’ll decide the route another time.

Stay tuned!

Programming FSRM quotas

Introduction

Recently I was evaluating the options I had for implementing disk quotas on a backend system running on a major Internet Service Provider in Brazil.

Windows offers quota management up to some degree since NTFS 5 (Windows 2000) with user/volume quotas. Those were not appropriate for our scenario since we needed to set quotas on a per directory basis and this was not supported natively by Windows until the arrival of Windows Server 2003 R2.

R2 brings us a new feature called File Server Resource Manager a.k.a. FSRM. It is exposed for the system administrator as an MMC 3.0 snap-in.

Unfortunately, as of today Microsoft does not officially support any way for programming against FSRM quotas.  I said “officially support” because if the snap-in can do it, probably we can too! So after some research I found two DLLs called srm.dll and srmlib.dll that happens to do the stuff we want. Srm.dll exposes FSRM functionality through COM and srmlib.dll is a managed code wrapper around srm.dll.

Let’s take a look at some sample code:

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.Storage;

using System.IO;

using System.Runtime.InteropServices;

 

namespace Fsrm {

    class Program {

        static void Main(string[] args) {

            string directoryName = @"c:FsrmTests";

 

            // Creates a directory for testing if necessary

            if (!Directory.Exists(directoryName)) {

                Directory.CreateDirectory(directoryName);

            }

           

            ISrmQuotaManager quotaManager = new SrmQuotaManagerClass();

            ISrmQuota quota = null;

            try {

                // Try to get quota info

                quota = quotaManager.GetQuota(directoryName);

                quota.QuotaLimit *= 2;

            }

            catch (COMException ex) {

                unchecked {

                    if (ex.ErrorCode == (int)0x80045301) {

                        // Quota doesn’t exist for this directory. Create it.

                        Console.WriteLine("No quota defined for ‘{0}’. Creating quota.", directoryName);

                        quota = quotaManager.CreateQuota(directoryName);

                        quota.QuotaLimit = 1024 * 1024;

                    }

                    else {

                        Console.WriteLine(ex);

                        return;

                    }

                }

            }

 

            // Update quota info

            quota.Commit();

 

            // Add new file to the diretory to see QuotaUsed getting updated

            File.WriteAllText(directoryName + @"" + Path.GetRandomFileName() + ".txt", "Testing FSRM directory quotas");

            Console.WriteLine("New file added. Quota doubledrn{0} of {1} used.", quota.QuotaUsed, quota.QuotaLimit);

        }

    }

}

 

This sample doubles the size of the directory’s quota and puts a file in it every time it is run.

There are a bunch of other classes and methods available. Have fun!

This thing still has some bugs

It looks like my plans on becoming a multi-billionaire referring links to Amazon have failed. 😛

Today I tried to include another book on my list, but the site simply started to generate wrong URLs.

Another bug that bothers me is the fact from time to time the lists don’t render correctly:

Let’s hope these bugs are fixed as soon as possible.