Dec 2 2007

Presentation at Norwegian .NET user group

Category: TechEd | Presentationfossmo @ 15:46

Last Thursday I held a presentation at NNUG about what I thought was the coolest stuff at TechEd in Barcelona. I promised to publish the presentation and links to the resources I used in the presentation. The talk was about the .NET microframework, Roy Oserhov's presentations at TechEd and System.AddIn framework.

Links to .NET microframework are found here:
http://www.dotnetmicroframework.com/
http://blogs.msdn.com/davbaker/

Links to Roy Oserhove's blog is found here:
http://weblogs.asp.net/rosherove/

And finally links to System.AddIn resources are found here:
http://blogs.msdn.com/clraddins/
http://msdn.microsoft.com/msdnmag/issues/07/02/CLRInsideOut/
http://msdn.microsoft.com/msdnmag/issues/07/03/CLRInsideOut/
http://msdn2.microsoft.com/en-us/arcjournal/bb735304.aspx

My powerpoint slides:
Can be found at the NNUG site: www.nnug.no

Tags:

Be the first to rate this post

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

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 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