Blog


January 31, 2012 Why not to buy a HP OfficeJet Pro

Seriously, of all printers I know, the OfficeJet Pro 8500 A909g is the worst ever.

Not only does it refuse to switch to my regional settings (I repeatedly have te change from letter to A4), the print quality sucks and it constantly cancels multipage printjobs without any reason. To make things even worse, the software and driver installers reboot your pc without your consent and device support lasts as long as it is not superceded by a new version of the printer.

No more HP for us.

January 24, 2012 Resize VMWare virtual machine under Windows 7

Pretty often I find myself stuck on a VM with not enough diskspace. Making the thing bigger is not a problem if you have the manuscript laying around.
This is the procedure I succesfully use on VMWare workstation virtual machines containing Windows 7.

  1. Turn off the virtual machine;
  2. Commit/remove all the snapshots or make a Full Clone if you use Link Clones.
  3. Open a Command Prompt and go to:
    C:\Program Files\VMWare\VMWare Server or C:\Program Files\VMware\VMware Workstation
    or for 64-bit
    C:\Program Files (x86)\VMWare\VMWare Server or C:\Program Files (x86)\VMware\VMware WorkstationRun this command to expand the virtual disk:
    vmware-vdiskmanager -x 12GB “My harddisk.vmdk” (in this case, 12 GB will be the new size).
    The file name can contain spaces because of the double quotes.

Note: Because this only expands the disk and not the partition, you’ll need to resize the partition table as well. This can be done with ‘diskpart.exe’, a built-in tool of Windows. VMWare provides a list of tools on their web site: KB1004071

  1. Power on your virtual machine;
  2. Open a Command Prompt and type: diskpart
  3. Type: list volume
    Remember the volume number (#) of your volume!
  4. Type: select volume (the number from step 3)
  5. Type: extend

Finished, no need for a reboot.

Seen on Leon Meijer’s Weblog

Tags:
July 5, 2011 Adding a DataSourceAttribute through CodeDom

Recently I have done quite a few T4 templates that use CodeDom to generate Automated test classes for use with Microsoft Test Manager. One of the problems I encountered was adding a DataSource attribute through CodeDom. This example shows how to do that.

using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using Microsoft.VisualBasic;

namespace AttributeCodeGenDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            //using (CodeDomProvider codeProvider = new VBCodeProvider())
            using (CodeDomProvider codeProvider = new CSharpCodeProvider())
            {
                // Create namespace to hold new class
                CodeNamespace demoCodeNamespace = new CodeNamespace("Troolean.CodeDom.Demo");
                // Create using statements
                demoCodeNamespace.Imports.Add(new CodeNamespaceImport("Microsoft.VisualStudio.TestTools.UnitTesting"));
                demoCodeNamespace.Imports.Add(new CodeNamespaceImport("System"));

                // Create class
                CodeTypeDeclaration fooBarCodeTypeDecl = new CodeTypeDeclaration("FooBar")
                {
                    IsClass = true
                };

                // Add class to namespace
                demoCodeNamespace.Types.Add(fooBarCodeTypeDecl);

                // Decorate class with TestClass attribute
                fooBarCodeTypeDecl.CustomAttributes.Add(new CodeAttributeDeclaration("TestClass"));

                // Create a new method
                CodeMemberMethod executeCodeMember = new CodeMemberMethod()
                {
                    Name = "Execute",
                    Attributes = MemberAttributes.Public | MemberAttributes.Final
                };

                // Add new method to the class
                fooBarCodeTypeDecl.Members.Add(executeCodeMember);

                // Decorate method with TestMethod attribute
                executeCodeMember.CustomAttributes.Add(
                    new CodeAttributeDeclaration("TestMethod"));

                // Create DataSource attribute. Output the constructor that takes 4 parameters of which three are strings and te last one is an enum.
                var dataSourceCodeAttrDecl = new CodeAttributeDeclaration("DataSource",
                    new CodeAttributeArgument(new CodePrimitiveExpression("Microsoft.VisualStudio.TestTools.DataSource.TestCase")),
                    new CodeAttributeArgument(new CodePrimitiveExpression(string.Format("http://tfsserver:8080/tfs/troolean;{0}", "Product1"))),
                    new CodeAttributeArgument(new CodePrimitiveExpression("100")));

                // The last parameter is an enum
                CodeTypeReferenceExpression dataAccessMethodCodeTypeRefExpr = new CodeTypeReferenceExpression("DataAccessMethod");
                dataSourceCodeAttrDecl.Arguments.Add(new CodeAttributeArgument(new CodeFieldReferenceExpression(dataAccessMethodCodeTypeRefExpr, "Sequential")));

                //  Decorate the method with the DataSource attribute
                executeCodeMember.CustomAttributes.Add(dataSourceCodeAttrDecl);

                /*
                namespace Troolean.CodeDom.Demo
                {
                    using Microsoft.VisualStudio.TestTools.UnitTesting;
                    using System;

                    [TestClass()]
                    public partial class FooBar
                    {

                        [TestMethod()]
                        [DataSource("Microsoft.VisualStudio.TestTools.DataSource.TestCase", "http://tfsserver:8080/tfs/troolean;Product1", "100", DataAccessMethod.Sequential)]
                        public void Execute()
                        {
                        }
                    }
                }
                */

                // Generate the code and output to console
                codeProvider.GenerateCodeFromNamespace(
                    demoCodeNamespace,
                    Console.Out,
                    new CodeGeneratorOptions
                    {
                        BlankLinesBetweenMembers = true,
                        BracingStyle = "C"
                    }
                );
            }
        }
    }
}

Tags: ,