MindTouch Developer Center > Deki > FAQ > Extensions > How do I...Write my first extension in .Net?

How do I...Write my first extension in .Net?

Deki Wiki Extensions provide an easy mechanism for adding dynamic content to your pages.  The following walkthrough explains how to create a simple Hello World extension using C#.

Download source code

Writing an Extension

1.  Open VS.NET and select File->New->Project. From the New Project Dialog Box, choose the Windows Class Library template project and name it HelloWorldExtService.

2.  To access the Deki Wiki extension framework, select Project->Reference and add a reference to the assemblies below.  These binaries can be found within the bin directory of your Deki Wiki web root (Deki Wiki VM:  /var/www/deki-hayes/bin).

  • log4net.dll
  • mindtouch.deki.ext.dll
  • mindtouch.dream.dll
  • SgmlReaderDll.dll

3.  Create a new class containing the code below.  This example creates a new "samples" library with a single "helloworld" function.  Note that HelloWorldExtService derives from DekiExtService, which is the base class of all Deki Wiki extensions.  The DreamService attribute is used to specify the Dream service name, description, and unique identifier (SID).  The DekiExtLibrary attribute specifies the Deki Wiki library name and description.  Both the DreamService and DekiExtLibrary attributes are necessary since a Deki Wiki library is a specialized Dream service.  The DekiExtFunction attribute marks the HelloWorld method as a Deki Wiki library function.

using System;
using MindTouch.Dream;
using MindTouch.Deki;

namespace HelloWorldExtService {

    [DreamService("Hello World Extension Service", 
                  "Copyright (c) 2007 MindTouch, Inc.", 
                  SID = new string[] { "http://services.mindtouch.com/deki/draft/2007/06/helloworld"}
    )]
    [DekiExtLibrary(Namespace = "samples", Description = "Samples Library")]
    public class HelloWorldExtService : DekiExtService {

        [DekiExtFunction(Description = "Hello World function")]
        public string HelloWorld(
        ) {
            return "Hello World!";
        }
    }
}

4.  Compile the project.  You have written your first Deki Wiki extension!

Testing the Extension

1.  Copy the HelloWorldExtService.dll assembly into the bin/services directory of your Deki Wiki web root (Deki Wiki VM:  /var/www/deki-hayes/bin/services).  Deki Wiki will automatically load new extension libraries from this location.

2.  Restart Deki Wiki (Deki Wiki VM:  /etc/init.d/dekihost restart).

3.  Register the service by opening your wiki and selecting Tools->Control Panel->Service Management (administrator access is required).  Add a new Local service and with SID=http://services.mindtouch.com/deki/d.../06/helloworld.  Note that the SID must match the SID specified by the DreamService attribute in the sample code.

./Image1.JPG
Figure 1

 4.  At this point, you are ready to invoke the extension.  Create a new page and add the text below to invoke the "helloworld" function of the "samples" library:

{{samples.helloworld()}} 

Output when the page is saved:

Hello World!

Tag page

Files 1

FileSizeDateAttached by 
HelloWorldExtService.zip
No description
6.17 kB22:21, 20 Sep 2007BrigetteKActions
You must login to post a comment.
Powered by MindTouch Deki v.8.08.2