-
Notifications
You must be signed in to change notification settings - Fork 12
HelloWorld
Below you see the content of the HelloWorld example. This is a plugin derived from the GlobalcachingApplication.Utils.BasePlugin.Plugin.
public override bool Initialize(ICore core)
This method is called when the plugin needs to initialize. Here you add the actions the plugin can perform, add additional text to the Core.LanguageItems and optionally perform other initialization if needed.
public override PluginType PluginType
Set the plugin type. This mostly determinens were in the menu of the main screen this action will be added.
public override bool Action(string action)
This method is called when the user actives the menu item or by another plugin. Here you check which action to perform and execute it.
LanguageSupport.Instance.GetTranslation(sometext)
Text that is presented to the user should be translated to the active language. The text is translatable by adding it to the Core.LanguageItems. To get the translated text, you call Framework.Utils.LanguageSupport.Instance.GetTranslation()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GlobalcachingApplication.Framework;
using GlobalcachingApplication.Framework.Interfaces;
using GlobalcachingApplication.Utils;
using GlobalcachingApplication.Utils.BasePlugin;
namespace Examples.HelloWorld
{
public class HelloWorld : Plugin
{
public const string ACTION_PERFORM = "Hello World 1";
public const string ACTION_SUBPERFORM1 = "Hello World|Sub action 2";
public const string ACTION_SUBPERFORM2 = "Hello World|Sub action 3";
public const string ACTION_PERFORM_MSG = "Hello World 1!";
public const string ACTION_SUBPERFORM1_MSG = "Hello World 2!";
public const string ACTION_SUBPERFORM2_MSG = "Hello World 3!";
public override bool Initialize(ICore core)
{
AddAction(ACTION_PERFORM);
AddAction(ACTION_SUBPERFORM1);
AddAction(ACTION_SUBPERFORM2);
core.LanguageItems.AddText(ACTION_PERFORM_MSG);
core.LanguageItems.AddText(ACTION_SUBPERFORM1_MSG);
core.LanguageItems.AddText(ACTION_SUBPERFORM2_MSG);
return base.Initialize(core);
}
public override PluginType PluginType
{
get { return PluginType.Action; }
}
public override bool Action(string action)
{
bool result = base.Action(action);
if (result && action == ACTION_PERFORM)
{
System.Windows.Forms.MessageBox.Show(LanguageSupport.Instance.GetTranslation(ACTION_PERFORM_MSG));
}
else if (result && action == ACTION_SUBPERFORM1)
{
System.Windows.Forms.MessageBox.Show(LanguageSupport.Instance.GetTranslation(ACTION_SUBPERFORM1_MSG));
}
else if (result && action == ACTION_SUBPERFORM1)
{
System.Windows.Forms.MessageBox.Show(LanguageSupport.Instance.GetTranslation(ACTION_SUBPERFORM2_MSG));
}
return result;
}
}
}