It is subject to change based on input I’ll get, but here is how you can use Extension Manager that is in the BlogEngine build 8474 when you write extension. To utilize manager functionality you first of all need an extension that requires some kind of customization, probably you want users be able to change values set by you as defaults. If so, you can use manager to create default property page for your extension, save default values and let user change them later on. Here is how you save list of default parameters to Extension Manager using BBCode as example:

public BBCode()
{
    Comment.Serving += new EventHandler<ServingEventArgs>(Post_CommentServing);
 
        // create settings object
        ExtensionSettings settings = new ExtensionSettings("BBCode");
        // describe specific rules applied to entering parameters. overrides default wording.
        string help = "Enter values for open and close tags devided ";
        help += "by \" | \" or single value if both tags are the same.";
        settings.SettingsHelp = help;
        // delimiter separating parameter. optional. comma by default.
        settings.ParametersDelimiter = "|".ToCharArray();
        // add default parameters. if more than one delimiter used to split values.
        settings.AddParameter("b", "strong");
        settings.AddParameter("i", "em");
        settings.AddParameter("u", "span style=\"text-decoration:underline\"|span");
        settings.AddParameter("quote", "cite title=\"Quote\"|cite");
        // initial import default settings. to reset blogger will have to
        // remove all parameters through admin tool/extensions/edit settings
        ExtensionManager.ImportSettings(settings);
}

Then you can retrieve and use these parameters, possibly customized by blogger, in your extension:

private void Post_CommentServing(object sender, ServingEventArgs e)
{
    string body = e.Body;
 
        // get settings object from extension manager
        ExtensionSettings settings = new ExtensionSettings("BBCode");
        // use parameters maintained by blogger through admin tool
        // in your extension. parameter values saved as array of strings
        // and can be accessed as values[number] as in example below
        foreach (ExtensionParameter p in settings.Parameters)
        {
            string[] values = p.Value.Split(settings.ParametersDelimiter);
            if (values.Length == 2)
                Parse(ref body, p.Name, values[0], values[1]);
            else
                Parse(ref body, p.Name, values[0]);
        }
    e.Body = body;
}

If you see easier, more obvious and natural way of doing this, please do not hesitate to share your thoughts. We are at the point where it all can be changed for a better relatively painlessly.

Signature

Related posts

Comments

12/12/2007 4:49:55 AM

Hi Ruslan, this is a great addition to the platform!

Things I've thought about:
- Extension should be able to set defaults when activated (may require an interface on the extension?)
- Should be able to specify basic validation (ie: must be an integer, must be a date, must be in range 0-10)
- Allow extension to specify edit field type (ie: drop-down list, checkbox)

Also:
- get a tightly typed object passed back and forward (somehow). Possibly, this should be a standard abstract base class that the extension has to implement and it marshals the data from the typecast class to a common property syntax?
- custom admin pages or controls for where simple fields are to complex (ie: colour picker, image picker, etc)

I've changed my instance of BE as follows:
- the global.asax no longer enumerates the App_Code looking extensions (which I think is correct and I see is in 8474?)
- the extension manager *does* enumerate the App_code and adds extensions that are missing to the extensions list in a disabled state.

Great work..

Dave

12/12/2007 4:52:24 AM

In the Post_CommentServing method you probably want to remove the creation of a new ExtensionSetting each time a comment is served. Why not move it out in a private static field when the first comment is saved, and then use the static field for the subsequent servings?

Mads Kristensen

12/12/2007 5:41:37 AM

Great point Mads, that is what I'm looking for: catching all those mistakes made at stage "first make it work". You right, I’ll adjust code to use static field to hold settings instance, thanks!
Basic validation and strong typing are sound interesting and worth looking into moving forward. I’ll keep it in mind trying not to paint myself in the corner so I can try to add them later. Custom setting pages allowing color pickers etc. are must, this is for sure on my ToDo list.

rtur.net

12/12/2007 9:57:22 AM

Very small things to add.

I would like to have a cleanup function that helps cleanup parameters from extensions no longer installed. Maybe a remove action that would remove the extension and the parameteres would be nice.

Typed values would be nice, with the classical text, boolean, numbers, eventually radio bouton, check box list and also a multiline field would be nice. because I guess that editing some fields will be painfull with only one field.

I would also like to see the web site of the extension author. that way I would be able to go to that web site directly from the extension manager and check if there is a new version. Without that I will have to find the adress elsewhere and would take more time.

jonx

12/12/2007 2:49:13 PM

Being an extension writer... not real happy with the burden this puts on the users. _I'M_ still confused about what I'd have to put in the name and value fields to make my Quicker links work.

So I guess I'd prefer a way to make the 'edit' button load MY page (or custom control) and not yours. That way I can have my own UI AND integrate into your system.

ck

12/12/2007 11:50:19 PM

I agree with ck - it would be more convenient if the extension brings his own control for customizing the configuration.

Christoph

12/13/2007 2:20:38 AM

This is a default control, that's why I'm trying to make it very basic. Extension will be able to bring its own control with it, it is a natural next step and this is what I meant when mentioned "custom settings page". As for quick/quicker links, they could easily use one field for word been hypertext and another for anchor to use. But I see where confusion coming from, I will make labels overridable, so instead of "Name" and "Value" extension author can use "Word to replace" and "Link" or whatever make sense. Very good catch. When its all settled, I'll add section to wiki with many examples on how to use it.

rtur.net

12/13/2007 4:15:22 AM

I think, I'll put some extra effort into custom pages and push it for 1.3 release. This is how it is going to work:
1. You should be able to drop your custom admin page to specified folder and manager will point "edit" button to it.
2. You should be able to add line to common config file and manager will use it to point to your custom page wherever it happens to be.
3. You can use customizable default page without creating your own admin UI.
4. My weekend is ruined. Are you happy now? Smile

rtur.net

12/14/2007 1:44:16 AM

I've been playing with this quite a lot over the last couple of days and it is a fantastic job - thanks! It is probably the most used admin page on my test sites.

With regard to pushing custom admin control/page into 1.3 - have you considered a basic interface that has a single method CustomAdminPage() that returns type information only. You could use that to update your settings and I wouldn't have to edit files, drop pages in different folders....If I don't implement the interface it doesn't matter because the existing code works sweet.

Right, I'm off to Lapland so my daughter can visit Santa - that would be my weekend ruined Smile

Dave

12/14/2007 2:22:40 AM

That is an excellent idea Dave, I could've probably also use attribute in similar way as it is done for extensions themselves to get a list of custom admin pages regardless of file location/configuration through reflection. The reason I stay away from interfaces is because I'm trying to be as less restrictive as possible and let extension authors to be as independent and autonomous as it can be. But sometimes interface can be the easiest and most elegant way of doing just that. I'll think about it and try some to see whichever works best.
Thanks for your support - really appreciate it!

rtur.net

1/31/2008 2:12:34 PM

Any chance you can post an example on how to insert information into the settings table? I tried this but it didn't want to work for me...

ExtensionSettings updatedSettings = null;
updatedSettings = ExtensionManager.GetSettings("MyExtension");
updatedSettings.AddValue("Column1", "My Column 1 text");
updatedSettings.AddValue("Column2", "My Column 2 text");
ExtensionManager.SaveSettings("MyExtension", updatedSettings);

Suggestions?

Chris

2/1/2008 1:46:06 AM

Any chance you can post an example on how to insert information into the settings table? I tried this but it didn't want to work for me..

Your example should work, unless "MyExtension" is not a valid extension name. Try to check if updatedSettings is not null after you set it by GetSettings method, it should have Column1 and Column2. You may be missing initialization (you need to create parameters first). Also, you might try AddValues that has several overloads, but most likely problem is with "MyExtension" been not set. Let me know if it helped or just send me your extension if you run into dead end.

settings.AddParameter("Column1");
settings.AddParameter("Column2");

rtur.net

Add comment


 

  Country flag

biuquoteimg
Loading



<<  July 2008  >>
SuMoTuWeThFrSa
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789
Enhanced with Snapshots

Subscribe to Rtur.net