Nov 29 2007

System.AddIn

Category: C# | TechEdfossmo @ 17:13

At TechEd some weeks ago, I went to a presentation about System.AddIn. It's a new cool addin framework for .NET. It's shipped with the .NET 3.5 framework. Making addIns and using them is much easier with this framework. To demonstrate how easy creating addins is, I will create a simple addin.

Here we go:

For this project I'm using Visual Studio 2008 Express. In the Express version, advanced build configuration is turned off by default. Lets turn it on:

In VS2008 Express choose Tools -> Options and then Show all settings.

SS-11.28.2007-12.54.05AM

Then choose Projects and solutions -> General -> Show advanced build configuration.

SS-11.28.2007-12.59.03AM

Now advanced build configuration is turned on and you can choose debug and release from the dropdown menu. Set it to debug.

SS-11.28.2007-01.03.16AM

I am going to create a console application. I'll name it TestAddIn.

In the Main method, I add the following line:

string addInPath = Environment.CurrentDirectory;

This line tells the application where to look for the addins.

Then I add references to this namespaces:

System.AddIn and System.AddIn.Contract

These two references have to be added to all the projects in this solution.

Next, I updates my addIns in store so the application is aware of the addins:

AddInStore.Update(addInPath);

To discover the addIns, add this line of code:

Collection<AddInToken> tokens = AddInStore.FindAddIns(typeof(MyTextHostView), addInPath);

The class MyTextHostView does not exist yet, so I have to create it. I add a new class library, and call it Host.View and add the following code:

public abstract class MyTextHostView
{
    public abstract string ViewText(string inputText);
}
 

SS-11.28.2007-05.21.51PM

Back in the main method, add:

foreach (AddInToken addinsToken in tokens)
{
     MyTextHostViewtextInstance =
        addinsToken.Activate<MyTextHostView>(AddInSecurityLevel.Internet);
     Console.WriteLine(textInstance.ViewText("My input text"));
}

The addin views define the base class for the add-ins. It is the way the addin receives the calls from the host. I create a class library called AddIn.Views and add this code:

[AddInBase]
public class MyTextAddinView
{
    public abstract string ViewText(string inputText);
}

SS-11.27.2007-12.55.59AM

Set the output path to ..\build\AddInViews.

SS-11.28.2007-05.30.33PM

Then it's time to create the first addin.

A new class library is required; AddIn.First. Add this code:

[AddIn("First addIn", Version="1.0.0.0")]
public class First:MyTextAddinView
{
    public override string ViewText(string inputText)
    {
        return "Addin 1: " + inputText;
    }
}


Set the output path to ..\build\AddIns\First\

Add a reference to the AddIn.View project, and make sure you set Copy Local = False.

SS-11.28.2007-05.52.55PM 

The interface between the host and the addIns, is expressed by a contract.

Create a class library called Contracts and add this code:

[AddInContract]
public interface IMyTextContract : IContract
{
    string ViewText(string name);
}

SS-11.27.2007-12.51.35PM

Set the output path to ..\build\Contracts\

An other class library is needed. Create a library called Host.Adapters. You know the drill; add the following code:

[HostAdapter]
public class MyTextContractToHostViewAdapter : MyTextHostView
{
    private IMyTextContract _contract;
    private ContractHandle _handle;

    public MyTextContractToHostViewAdapter(IMyTextContract contract)
    {
        this._contract = contract;
        _handle = new ContractHandle(contract);
    }

    public override string ViewText(string inputText)
    {
        return this._contract.ViewText(inputText);
    }

}

SS-11.28.2007-12.16.24AM

Add a reference to the Host.View project and Contracts project, and make sure you set Copy Local = False.

I also need a adapter on the addInside. Create a class library called AddIn.Adapter and add the code:

[AddInAdapter]
public class SimpleAddInViewToContractAdapter : ContractBase, IMyTextContract
{
    private MyTextAddinView _view;

    public SimpleAddInViewToContractAdapter(MyTextAddinView view)
    {
        this._view = view;
    }

    public string ViewText(string inputText)
    {
        return this._view.ViewText(inputText);
    }
}

SS-11.28.2007-06.06.03PM

Add a reference to the AddIn.View project and Contracts project, and make sure you set Copy Local = False.

Then it's time to test the project. Press F5, and run it.

SS-11.28.2007-06.11.30PM

I will write more in detail about this cool framework later.


Download project:

TestAddIn1.rar (19.56 KB)

Tags:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Nov 14 2007

Paper prototyping

Category: Prototyping | Scrumfossmo @ 07:32

Last night I went to a meeting at a agile user group in Trondheim. It was the first meeting and it went really well. One of my co-workers presented hands-on experience with Scrum, taken from the project I'm currently working on. Many of the attendance had experienced the same problems we struggled with. The conclusion of the talk, was that the biggest problem is communication. Communication between stakeholders and developers, but also communication between developers. In future projects I'm going to focus even more on the communication between the project participants.

kables

In one of the other talks, "paper" prototyping, was shown. I really liked the idea. This is how they did it: First they gathered the stakeholders and some of the developers. Then they used a white-board and drew all the screens in the application on it. A digital camera was used to take a photo of every screen they had drawn. They then imported the photos into PowerPoint and linked  the buttons and other interactive GUI elements together. This way they could click thru the application and "try" it out before the coding and graphical design started. Doing prototyping like this, makes it easy to change the screens and all the project participants easily sees how the application should work. This eliminates a lot of unnecessary discussions between team members. I will definitely try this out in the next project.

Tags:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Nov 6 2007

I'm at TechEd, Barcelona

Category: TechEdfossmo @ 17:39
This two first days of TechEd have been great. Lot of good sessions, and many great speakers.
You can find some photos I have taken at TechEd here.

Tags:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5