Redirected from DekiScript/Tutorials/Writing an extension in C#
1 of 1 found this page helpful

Writing an extension in C#

  • You do not have permissions to view this page - please try logging in.

MindTouch 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 MindTouch extension framework, select Project->Reference and add a reference to the assemblies below.  These binaries can be found within the bin directory of your MindTouch web root (MindTouch VM:  /var/www/dekiwiki/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 MindTouch extensions.  The DreamService attribute is used to specify the Dream service name, description, and unique identifier (SID).  The DekiExtLibrary attribute specifies the MindTouch library name and description.  Both the DreamService and DekiExtLibrary attributes are necessary since a MindTouch library is a specialized Dream service.  The DekiExtFunction attribute marks the HelloWorld method as a MindTouch 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[] { "sid://mindtouch.com/deki/2010/03/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 MindTouch extension!

Testing the Extension

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

2.  Restart MindTouch (VM:  /etc/init.d/dekiwiki 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=sid://mindtouch.com/deki/2010/03/helloworld.  Note: SIDs are not URLs, they are service identifiers. The SID you specify must match the SID specified by the DreamService attribute in the extension.

./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!

Was this page helpful?
Tag page

Files 2

FileVersionSizeModified 
Viewing 5 of 5 comments: view all
this code doesn't work. There is a lot of that around here. When I try it I get the error... "HelloWorld could not be restarted." and looking at the detail I get this...

"unable to initialize service (blueprint not found)"
Posted 13:41, 25 Jul 2009
The code is over a year old. It probably needs some love. Though the sample itself looks correct.
Posted 02:22, 26 Jul 2009
I don't understand what i have to write in class header. I mean, what's
SID = new string[] { "http://services.mindtouch.com/deki/draft/2010/03/helloworld"}
??

'Cause the error reported in #1 still appear.

I putted the dll into C:\var\www\dekiwiki\src\bin\services, because folder /var/www/dekiwiki/bin/services doesn't exists.


response] => URI required:
http://192.168.1.17:8081/deki/site/services/55/start?dream.out.format=php&dream.in.host=192.168.1.221&dream.in.scheme=http&dream.in.origin=192.168.1.221 edited 07:42, 11 Mar 2010
Posted 06:13, 11 Mar 2010
If you ever get a Blueprint Not Found error, it's almost 100% caused by a mismatch between the MindTouch libraries you compiled with and the ones actually running your site. I make a lib folder in the project directory and copy exactly the DLLs in the server's api\bin.
Posted 05:46, 21 Apr 2010
@Shanty: the SID definition is the Service ID. It's a unique identifier tied directly to the service. When you're in the control panel and adding the extension, this is what you type (or paste) in to make the service loader find all the assemblies.

Also if you're using windows, you'll find the dlls in C:\{dekidir}\api\bin where {dekidir} is the path to your deki install.
Posted 05:49, 21 Apr 2010
Viewing 5 of 5 comments: view all
You must login to post a comment.

Copyright © 2011 MindTouch, Inc. Powered by