• Note: All development at this stage is subject to break due to namespace changes, object renames, and other factors that may occur with beta software.
  • Toolbar Note: No interface yet exists for creating toolbars; this is in active development.
  • Commands Note: Command is a property for menus, but this is not yet solidified.

Prerequisites: Please download the Nucleo framework, available at: www.codeplex.com/nucleo.

When creating a module, create a class that inherits from Bible.Modules.ModuleBase. ModuleBase has a lot of the methods that you will use throughout the lifecycle. The example for this page will be a Prayer module, which has a repository object that contains the prayer requests, and invokes a command (discussed later).

public class PrayerManager : ModuleBase
{
private PrayerRequestRepository _repository = null;
private readonly string PrayerFile = ServicesCentral.GetFolderPathForFile(ServicesCentral.FolderType.Content, "prayers.xml");

public PrayerRequestRepository Repository
{
get
{
if (_repository == null)
_repository = PrayerRequestRepository.GetInstance();
return _repository;
}
}

public override void Show()
{
Commands.ModuleCommands.CreatePrayers.Execute();
base.Show();
}
}

The second part to this is a command object. A command implements the ICommand interface defined in Nucleo.Windows.Commands (Nucleo.Windows assembly). This interface defines a CanExecute and Execute methods to determine whether the command can run. The command looks like as below:

public class CreatePrayersCommand : Nucleo.Windows.Commands.ICommand
{
#region " Methods "

public bool CanExecute()
{
return true;
}

public void Execute()
{
string windowName = NameGenerator.GetRootObjectName<Prayer.PrayerManager>();

if (!ServicesCentral.Application.DocumentWindows.Contains(windowName))
{
DocumentWindow window = new DocumentWindow(windowName, "Prayers", null);
window.UIInterface = Activator.CreateInstance("Bible.Windows", "Bible.Windows.Controls.QuotesManagerWindow").Unwrap();
ServicesCentral.Application.DocumentWindows.Add(window);
return window;
}
else
return ServicesCentral.Application.DocumentWindowswindowName;
}

#endregion
}

This command returns true, because in this instance, the interface object (a document) can always be instantiated. For more information about the object module, please read this article: http://aspalliance.com/1419. I've been finding that it is becoming somewhat inefficient, and I am contemplating an alternative way to do things, so the API may change. But the concept is very similar; if the window doesn't exist, it is created; otherwise, the current window representing this module is shown.

When creating a module, a plugin class is needed that will instantiate all of the underlying objects that you will use. This object is an interface named Bible.Plugins.IBiblePlugin, which is defined in the Bible.Business assembly. This plugin defines a series of methods, most of which you may not use. That is fine, leave the method call blank. This object loads menus, tool windows, and all, as well as performing any serializing/deserializing and saving that is needed. It is important to inherit from this interface so that the dynamic inspection system for your module can be correctly recognized and loaded.

public class PrayerPlugin : IBiblePlugin
{
private string _windowName = NameGenerator.GetRootObjectName<PrayerManager>();

public void LoadMenus()
{
ServicesCentral.Application.Menus.Add(new MenuItem(_windowName + "Menu", "Prayer Requests", Commands.ModuleCommands.CreatePrayers, ServicesCentral.Application.Menus["Tools"]));
}

public void LoadMiscellaneous() { }

public void LoadModule()
{
ServicesCentral.ModuleService.RegisterModule<PrayerManager>();
}

public void LoadToolWindows() { }

public void UnloadDocumentWindows()
{
if (ServicesCentral.Application.DocumentWindows.Contains(_windowName))
ServicesCentral.Application.DocumentWindows.Remove(_windowName);
}

public void UnloadMenus()
{
ValuePath path = new ValuePath();
path.AddValues(new string[] { "Tools", _windowName + "Menu" });

if (ServicesCentral.Application.Menus.Contains(path))
ServicesCentral.Application.Menus.Remove(path);
}

public void UnloadMiscellaneous() { }

public void UnloadModule()
{
ServicesCentral.ModuleService.UnregisterModule<PrayerManager>();
}

public void UnloadToolWindows() { }
}

Note that whatever feature is not initially loaded should be left blank. When creating your architecture, please choose an object-oriented one, as that is the theme that fits into the application. If you can, use test-driven development as well (all of that is not required). For your user interfaces, please use user controls for each interface.

The final compiled module should be put in the AddOns folder under Bible.NET, in a folder that contains the name of the module. For the content related to the module, this should be in the Content/<module name> folder.

Last edited Oct 21, 2007 at 3:01 AM by bmains, version 2

Comments

No comments yet.