Microsoft Certified Professional Windows Developer

After been spending some tuff days with only reading about user cases and different deployment ways I have finally passed the windows MCPD exam. This is the exam that I think I did learn less from out of the 3 you need to get a MCPD for windows. It was a lot about user cases and testing that I did know most of it already trough my work and universities studies. So I guess the exam was more for people that would like to have paper that they know this things of have not any university degree in computer science.

10 Papers Every Programmer Should Read (At Least Twice)

Found a really interesting blog by Michael Feathers today. His goal is to get every programmer from different background up to minimum knowledge bar. The blog contain link to good papers about best practice and other thing a programmer should know as how programming language works.

Using an enum type with WCF services

I recently started to work with Windows Communication Foundation and one of the first problems I did run into was how to use enum type in WCF.

This is a small example of a data contract and a service contract/interface that makes use of the enum type.

using System;
using System.ServiceModel;
using System.Runtime.Serialization;
 
namespace Test.DataContracts
{
    [DataContract(Namespace = "Testing", Name = "JobResult")]
    public enum JobResult
    {
        [EnumMember]
        Passed = 0,
        [EnumMember]
        Failed = 1,
        [EnumMember]
        Running = 2,
        [EnumMember]
        TestFailure = 3,
        [EnumMember]
        Queued = 4,
        [EnumMember]
        JobNotFound = 5
    }
}

Read more

CSV parsing using OLEDB

For a few days I did run into the problem of importing CSV data with OLEDB. The first thing I tried was creating my own parser, but later I found an easy built in way. I show both methods here.

My own parser is simple based on the split string functionality.

//create the table
DataTable dt = new DataTable("Import");
dt.Columns.Add("col1", typeof(string));
dt.Columns.Add("col2", typeof(string));
dt.Columns.Add("col3", typeof(string));
 
//read the data
using (StreamReader sr = new StreamReader(filepath))
{
    int i = 0;
    while (!sr.EndOfStream)
    {
        //skip the header
        while (i < 1)
        {
            sr.ReadLine();
            i++;
        }
 
        string[] text = sr.ReadLine().Split(',');
        DataRow dr = dt.NewRow();
        dr["col1"] = text[0];
        dr["col2"] = text[1];
        dr["col3"] = text[2];
 
        dt.Rows.Add(dr);
    }
}

The build in CVS parser uses a connection string and a SQL query to handle the CVS data. The connection string is configured according to:
• Provider: Jet OLEDB
• Data source: The directory that contains the CSV file
• Extended properties: ‘text’ means that we are parsing a text, the HDR property can be set to ‘Yes’ (the first row in the CSV files is header information) or ‘No’ (there is no header row), and setting the FMT property set to ‘Delimited’ essentially says that we will be working with a comma separated value file.

public static DataTable ParseCSV(string filePath)
{
    if (!File.Exists(filePath))
    {
        return null;
    }
 
    string fileName = Path.GetFileName(filePath);
    string dirName = Path.GetDirectoryName(filePath);
 
    //connection string 
    string connString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source="" + dirName + "\";" + "Extended Properties="text;HDR=No;FMT=Delimited"";
    string query = "SELECT * FROM " + fileName;
 
    DataTable dt = new DataTable();
    OleDbDataAdapter adapter = new OleDbDataAdapter(query, connString);
 
    try
    { 
        adapter.Fill(dt);
    }
    catch (InvalidOperationException)
    { }
 
    adapter.Dispose();
 
    return dt;
}

How to determine if we are running on 64 or 32 bit?

In my work I need to be able to pick different files depending on if I run in 64 bit or 32 bit system. The first thing I did try was to use the size of IntPtr which is 4 for 32 bit and 8 for 64 bit. But since I was using the visual studio unit test framework it did not work that god. The unit test framework run in a 32 bit process but the application I’m testing is running in 64 bit, so decided to use P/Invoke to call GetNativeSystemInfo.

The structure that you get is according to

[StructLayout(LayoutKind.Sequential)]
private struct SystemInfoNative
{
    internal ushort ProcessorArchitecture;
    internal ushort Reserved;
    internal uint PageSize;
    internal IntPtr MinimumApplicationAddress;
    internal IntPtr MaximumApplicationAddress;
    internal IntPtr ActiveProcessorMask;
    internal uint NumberOfProcessors;
    internal uint ProcessorType;
    internal uint AllocationGranularity;
    internal ushort ProcessorLevel;
    internal ushort ProcessorRevision;
}

Out from this you can check the processor architecture.

And the complete source code
Read more

Microsoft .NET Framework – Application Development Foundation

After 2 month of preparation and a weekend that disappeared I have passed my first MCTS exam. It has been an interesting trip with a lot of new knowledge and frustration when the sample questions don’t make sense (But I did pass the exam pass rate criteria with good marginal). I did use the “MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework 2.0 Foundation” book for my preparation and Measureup’s online test questions. The book also contain test question both in the book and one a CD. The questions in the book was really good and helpful both the question on the CD was according to me many times outside of the scope and had no connection to the content in the book or the real exam I did take. Measureup’s questions were the closest ones to the real exam and also the question that I did learn most from.
Read more

Introducing WPF Application Quality Guide v.0.4

WPF Application Quality Guide v0.4 has been released today at the WindowsClient.NET with new topics and updates.

This release includes several new topics and updates:
1. Suggested Roadmap – updated to include new topics
2. Data-Driven Testing – a new article about the data-driven testing practice.
3. Globalization and Localization Testing – updated w/ more details including creating localizable UI layouts in WPF and approaches to localizing WPF applications.
4. Stability and Stress Testing – a new article about stress testing principles, best practices, and useful resources.
5. Accessibility Testing – a new article about accessibility considerations, best practices and key resources.
6. Tools / TestAPI – a brief intro about the newly released TestAPIs.

The full online version can be found here.

Regular expression builder

I was doing some input verification of data to method when it did hit me that it would be nice if I could do it with regular expression since I was only check if the string data was in correct format. Since I’m not an expert in regular expression I needed some type of builder or verification tool. After some searching I found this free tool RegExr that has both an online version and desktop version. The thing that I did like most was the online version that was only a click away. The program doesn’t help you that much building the regular express but it helps a lot for verifying your expressions. It also has a bunch “code snippets” that you can use as building block.
Anyway this little program did save my day to tryout some different expression to find one that did fit my needs.

So I hope that you also will find it useful.
RegExr
RegExr desktop

Fun with UIAutomation and calc

Last night I got a cool idea how to show some basic ideas of UIAutomation. I did decide to-do a UIAutomation example with calc as my test subject. The idea is to give a mathematical expression to the program, which will then use calc to solve the problem and show you the result. The main thing is to show how UIAutomation is working and not to calculate.

The first thing that we need is a method that can find an AutomationElement for us. An AutomationElement is anything that you can see on the screen as buttons and input fields. The method take a root AutomationElement that define where to start to search, a name and a class name for the object that we are looking for. We then create two property conditions based on the name and class name. These two conditions are then combined in an AndCondition. We also have OrCondition and NotCondition to use. The last thing we do is to search for the first AutomationElement that match the condition.

private static AutomationElement GetElement(AutomationElement root, string name, string className)
{
    PropertyCondition condName = new PropertyCondition(AutomationElement.NameProperty, name);
    PropertyCondition condClassName = new PropertyCondition(AutomationElement.ClassNameProperty, className);
    AndCondition cond = new AndCondition(condName, condClassName);
    return root.FindFirst(TreeScope.Descendants, cond);
}

Next method that we need is one that can return a invoke pattern. Invoke pattern is used for example to click on a button. This will be used to be able to click on the different buttons in calc

private static InvokePattern GetInvokePattern(AutomationElement element)
{
    return element.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
}

Read more

.NET Cheat Sheets

When I was surfing around today I found this site that contain a bunch of different cheat sheets for .NET. The one that I find really useful was ‘Visual Studio 2005 Built-in Code Snippets‘. So simple have fun with this findings

« Previous PageNext Page »