Sunday, May 20, 2012

MSVS TFS Practical Ruck Guidance

Today I dug a little deeper in some white papers and guidance the ALM rangers are sharing on CodePlex.

One of the topics they cover is the use of the RUCK software development technique.

While I have seen Agile and Scrum so far, I was really interested in this one. Why?

Atm, I am working in a team where this kind of approach might be a lot better then the Agile or Scrum development techniques.
You can find more in detail here.
Because I was so impressed I shared the explanation on RUCK, which in the rugby world means "loose scrum", on YouTube to give you a quick intro on the idea behind the technique.

This video & documentation should give you an idea if this technique might be applicable in your working environment.


Saturday, May 19, 2012

Application Lifecycle Management & Team Foundation Server


Version Control & ALM
As GIS developer I use Team Foundation Server on a daily basis now. 

I used Subversion in the past, but TFS is fairly new to me. 
I've been using both products as version control only and was really interested to figure out how this tool (TFS) can be used as ALM. 
A colleague of mine suggested the use of TFS as ALM this week during a meeting.

Because of that, I decided to quickly figure out the do's and don'ts and get myself up to speed with the product and it's features.

ALM & TFS VIDEOS
Today I followed a 4 hour video course on ALM and TFS. A complete summary of the topics I tackled can be found here.

IRL Application
The video's cover a series of topics that could resolve some difficulties we face at work. I am very interested how this unfolds.

Because I don't have TFS installed at home I will have to wait till Monday to test some features I can quickly implement for personal purposes.

My First Oracle Setup


I have experience with SQL server but I am very new to Oracle Database technologies. So, it was time for me to touch the basics and take a look at some basic features Oracle holds in store for us.

1.Download
First I downloaded and installed the latest version of the oracle database available at http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html
Make sure you remember your password after installation!!

2.Helpfull documentation
I got myself all the necessary documentation at http://docs.oracle.com/cd/E17781_01/index.htm and started with the getting started pdf.

3.Install SQL Developer
As I am not a huge fan of using the command line to configure the database, I installed the SQL developer which allows you to do the same but in a graphical environment. I downloaded it at http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html
To use the database tool, make sure you have the latest Java JDK installed on your computer. You can download it here http://www.oracle.com/technetwork/java/javase/downloads/index.html

4.Database Home Page (pdf ref 1.2)
For me this can be found at C:\oraclexe\app\oracle\product\11.2.0\server\Get_Started. Launch it and it will open in your web browser and give you access to various database administration operations.

5.Create a new User (pdf ref 2.0)
That’s why I installed the SQL developer, to make these things a lot easier then typing inside an old prompt window.
First you have to start by creating a SYSTEM connection. The username should be SYSTEM and password is the one you defined on Oracle Database installation. The name of the connection can be chosen freely.


If all went well you should see a tree view with a lot off tree nodes. Most of them are Chinese still, but there are similarities to SQL server. The treenode Other Users is the one where we define a new user and set up its privileges.



6.UNLOCK HR SAMPLE DATA
There is a HR user inside the Other Users section that should have his account unlocked. This grants you access to the tables tied to that user profile. Modify the properties of that user using the SYSTEM connection and define a new password for that HR user.
The pdf Getting Started guide continued with building an application using the wizard on the Getting Started page but I’ll skip that one. If you are into wizards, feel free to run this sample :)


7.Oracle Database XE

I read the second pfd in line found at http://docs.oracle.com/cd/E17781_01/index.htm and filtered some of the most important things I need to communicate in a descent manner from a .Net environment. At least I have a good first general impression of the Oracle Database XE now and this should be more than enough to get me started.

In the next post I’ll try to connect to the database and pull data from the HR tables using C#.

Thursday, May 10, 2012

Design Patterns - Singleton Pattern

Definition
Ensures a class has only one instance, and provides a global access to it.

Pattern examples
There are a few different approaches on how to implement the singleton pattern. I’ll show some in a C# environment.

Example 1 : “Lazy loading”.
By implementing lazy loading you insure that your class only gets instantiated when it is called upon for the first time and not earlier.

C# Code
/// <summary>
/// Singleton class. Lazy Loading. Instantiation only happens when the class is called upon for the first time.
/// Pitfall : Multithreading might result in ending up with 2 instances of the class. This implementation is not thread safe!

    /// </summary>
    public class MyLazySingleton
    {
        private static MyLazySingleton instance;

        /// <summary>
        /// Public static method that returns an instance of MyLazzySingleton
        /// </summary>
        /// <returns>Unique Instance of MyLazySingleton</returns>
        public static MyLazySingleton Instance()
        {
            //instantiate a new instance of the class if it is null
            if (instance == null)
                instance = new MyLazySingleton();
            return instance;
        }
    }

Pitfall
This piece of code is not ideal in a multithreading environment. Two instances can still be instantiated at the same time if both separate threads run over this code check:
//instantiate a new instance of the class if it is null
            if (instance == null)

Meaning, for both threads this check will be true and they will both instantiate an instance of that class, which is exactly what we want to prevent using the singleton pattern. Outside a multithreading environment this code works just fine. 

Example 2 : “Eagerly Creation”.

If the load is done at the start of the application or you are sure the class will get used for sure within your application, use eagerly creation of your singleton class. This is a thread safe implementation.

C# Code
/// <summary>
/// Singleton class. Eagerly Creation. Use this type of singleton if the load is done on startup or you are sure the singleton will be used
    /// at least once in your program. This implementation is thread safe!
    /// </summary>
    class MyEagerSingleton
    {
        /// <summary>
        /// Declare and instantiate immediatly
        /// </summary>
        private static MyLazySingleton instance = new MyLazySingleton();

        /// <summary>
        /// Public static method that returns an instance of MyEagerSingleton
        /// </summary>
        /// <returns>Unique Instance of MyEagerSingleton</returns>
        public static MyLazySingleton Instance()
        {
            return instance;
        }

Tuesday, April 24, 2012

MSVS Setup Autodesk Autocad 2012 Autoloader

After explaining how to create bundles and use the new Autoloader feature within Autodesk 2012 products to load plugins I show you how to create an msi of your bundle within Visual Studio. An msi is a very easy way to get things done correctly. Enjoy!!!


Download the full msi project.

Autodesk Autocad Autoloader

Introduction

With the launch of Autocad 2012 there is a new way to install custom made plug-ins build in MSVS. They refer to them as bundles or packages who are read by Autocad on startup. The Autoloader doesn't change anything to previous solutions who install plug-ins, but is an additional and new way of Autodesk to easily install all your plug-ins without too much hassle.


1.New C# Example Autoloader Project
Start a new C#.net project and name it to your heart's desire. (This example could easily be translated to VB.net). Make sure you create a class library project.

2.Add Autocad references
Add references to the acdbmgd and the acmgd dll. (These files are located inside your Autocad installation folder) Make sure you change the properties of the dll's inside MSVS and set it to Copy Local = False.

3.Set Autocad as startup while debugging

MSVS Full version
In the properties of your project make sure you debug using Autocad as an external program. This option is only available in the full version of MSVS. In the express version you'll need a work-around to accomplish the same behavior.

MSVS Express Edition
Add the following to your project xml file to launch Autocad from within MSVS C# Express.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
    <StartAction>Program</StartAction>
    <StartProgram>C:\Program Files\Autodesk\AutoCAD 2012\acad.exe</StartProgram>
  </PropertyGroup>
</Project>


4.Class Code
 Rename Class1.cs and name it Commands and place following code inside the class. Make sure you reference the acdbmgd assembly found in the autocad installation folder!

using Autodesk.AutoCAD.Runtime;
using System.Windows;

namespace AutoLoaderExample
{
    public class Commands
    {
        [CommandMethod("AutoLoaderExample")]
        public void AutoLoaderExample()
        {
            MessageBox.Show("AutoLoader Example");
        }
    }
}


Now that we have set up visual studio build your solution and we head over to the Autoloader bundle and its contents.

5.Availability Autoloader bundle

The first thing to point out is that it's possible to install the plug-in for all users and to install it for only a particular user.
·         For all user access to your plug-in we will place the plug-in in our installation folder under the map ApplicationPlugins. (Most likely this will be the Program Files/Autodesk/ ApplicationPlugins/ folder)
·         To install the plugin for a particular user place the plug-in inside the [AppDataFolder]/Autodesk/ ApplicationPlugins.


6.Autoloader map and file structure

It is important to understand that the autoloader looks for folders of a particular format. The folder has to look like this => AutoLoader.bundle, where the .bundle behind any given name is very important to the Autoloader to identify your bundle. The AutoLoader folder can be renamed to anything you like as long as it's followed by the .bundle.
 Because of the .bundle format we won't talk about plug-ins anymore if we talk about any .bundle under the ApplicationPlugins folder. I'll refer to them as bundles or packages.
Now we know that your bundle can be placed on 2 different locations on your hard drive let's look at the content of a one.

7.Autoloader contents

There are 2 files a bundle should always have inside, and it's the PackageContents.xml file which contains all necessary information for the autoloader on how to load your plug-in inside Autocad. And the second file is the assembly that contains all your Autocad commands. Or in case of multiple assembly files you could place them inside a separate folder. In my projects I try to separate my assemblies and resources within their own respective folder to make things more manageable.
In this example I'll place my bundle inside the "available to all Autocad users".


Inside the AutoLoader.bunde I place my example assembly , produced by Visual Studio on Build, and an PackageContents.xml file.


8.Assembly Location MS Visual Studio Example

For those who are new to how MSVS works when you have build the project you created earlier you can find the .dll inside the bin folder of your project. The default projects folder of MSVS can be found under Documents/ Visual Studio 2010/ and the picture should give you an idea how to find your assembly file.


9.PackageContent.xml definition

Place the following code inside the xml file you created earlier. If you placed yours inside a folder, make sure you adjust the attribute ModuleName to match the correct path.


<?xml version="1.0" encoding="utf-8" ?>
<ApplicationPackage SchemaVersion="1.0" Name=" AutoLoaderExample " AppVersion="1.0">
  <Components>
    <ComponentEntry AppName="AutoLoader"
             ModuleName="AutoLoaderExample.dll"
          AppDescription="AutoLoader Example" />
  </Components>
</ApplicationPackage>

Let's take a look at the contents of the xml file first. I've kept it very simple and only the bare minimum got placed inside the file to ensure the plug-in is loaded when Autocad is launched.
If you wish to define the file in depth, I advise you to take a look at the section provided inside AutoDesk Help which explains in detail how to apply certain element and attributes inside the xml file. As far as I know there isn't a schema definition that can help you with your xml definition so you'll have to do it with the information inside the Help file.
If I am not mistaking it also explains how to attach CUI files who then get loaded in the Plug-in ribbon section of Autocad 2012 products. If I find myself some time I'll tackle this one and post how it's done.

10.Finally launch Autocad!!
The assembly file should be loaded on startup and you should be able to execute the "ALExample" command. Hope it works out well!!

autoloader bundle example download

autoloader c# project download

More information can be found in the Help of Autocad (keyword:PackageContents.xml)

Monday, April 23, 2012

Comparer Project Part 1


Introduction
I started working as CAD-GIS engineer on 2nd of March, and ever since I haven't been posting anything new.

Recent activity
As I try to build a recap on what I have done so far I thought I’d share what’s been realized so far. Although I won’t be sharing the whole project here, I’ll be posting some portions and insights on how I dealt with the given assignment.
Let’s start by explaining what I had to accomplish.

My first small project
Too save you from a long story … In short …
I had to compare the contents of 2 AutoDesk Autocad DWG drawings on a few layers. Two technical drawers started on the same drawing and had to classify some objects on those layers. Because both can classify them differently, I had to compare the differences once they end their classification.
They had to be able to see and localize the differences and fix them in an appropriate manner afterwards.
That’s the project in a nutshell J

Architecture
My goal was to build a Data Access Layer that has the potential to be used in other projects as well. I also integrated some classes I wrote 1-2 years ago to make the application much more stable and flexible. I did the best I could to build a Model-View-ViewModel environment.
Let’s start by sharing a picture of the architecture I used within the project. 


Database Assembly DAL
The Data Access Layer is only the start of what should become a wrapper around the Autocad Libraries. The wrapper allows you to decouple layers and gives you the possibility to Unit-Test your project with sample data without the necessity of having a Autodesk product at hand to test the decoupled layers.
Although this method seems tedious at first, it should result in a gain of speed when developing new applications. 

Objective DAL
Basically you're building a library that gives you access to clean and tested code which reduces bugs and errors in future development.
At the moment, I am only working inside a Map environment, but if adjusted slightly, this setup should allow you to extend the framework to support programming towards other CAD Autodesk products build on AutoDesk AutoCad and expose their API.





Looking at this picture, it is quite obvious that using other products, build on AutoDesk Autocad's basic module, will end up using a AutoDesk Autocad Drawing as well.

Object oriented programming and libraries
Because we program in an object oriented environment it's an ideal opportunity to exploit this and build a reusable library. Although this is a first step to build something flexible and reusable, the path towards a good library won't be without it's pitfalls and setbacks. 

What might be reusable and valid code for your library in one project, might become unusable in certain particular situations. I'll try to prevent that as much as possible but I still have a long way to go to become a better object oriented programmer to exclude that from happening completely. Using the correct methods and pattern to build robust and flexible libraries will be a big challenge.

If you talk about objected oriented design, libraries and flexible code, we can't exclude the use of interfaces. That's why I'll be using those throughout this project because they are very powerful and give you the possibility to program flexible environments.


What's next?
In a next post I'll be explaining what I've done with the DAL and I'll create an example in C# demonstrating what the methods inside the classes do.