SvenHarenburg / TrayKit

A small application to help with often reoccuring tasks.
MIT License
6 stars 2 forks source link

TRAYKIT

TrayKit is a .NET desktop application designed to help with often reocurring tasks. The application runs in the system tray and uses a contextmenu accessible via right clicking to provide commands. The commands itself are provided by plugins which will be loaded by the TrayKit application. You can create the plugins you need by creating a plugin-library and implementing the required interfaces. The process of this is explained further below.

SETTINGS-MANAGEMENT

TrayKit allows it's plugins to publish a list of settings that will be managed by TrayKit itself. This includes saving, loading and editing(Base types only for now) of those settings. I have implemented this so not every plugin has to manage it's own settings including loading and saving them. This would probably trash the application-folder with multiple settings-files and probably create conflicts between plugins. TrayKit stores all the settings in one single json file in the application directory. The settings get loaded when the application starts and saved back to the file when it exists.

Settings-Editor

Example of a plugins settings being displayed for editing by TrayKit.

CREATING PLUGINS

To create a plugin you need to create a new library and implement the interfaces provided by the TrayKit.Base library. To get access to the library you can either download the repository or add the Nuget-package "TrayKit.Base" to the project. I will explain the creation process with the SamplePlugin provided in the TrayKit-solution.

Step 1: Create the plugin-class by implementing "ITrayKitPlugin" and marking the class itself with the "Export"-attribute provided by the MEF-framework:

  [Export(typeof(ITrayKitPlugin))]
  public class SamplePlugin : ITrayKitPlugin
  {
    private const string PluginName = "TrayKit SamplePlugin";
    public List<ITrayKitPluginCommand> Commands { get; }
    public Image Image { get; }

    public string Name { get { return PluginName; } }

    public SamplePlugin()
    {
      Commands = new List<ITrayKitPluginCommand>()
      {
        new HelloWorldCommand(this, Settings) { SortPosition = 0 },
        new TwoPlusTwoCommand(this) { SortPosition = 1 }
      };
      Image = SystemIcons.Asterisk.ToBitmap();
    }
  }

Explanation:

Explanation image

Step 2: Create a command-class by implementing "ITrayKitPluginCommand":

  public class HelloWorldCommand : ITrayKitPluginCommand
  {
    private const string CommandName = "Hello World!";

    public string Name { get { return CommandName; } }
    public ITrayKitPlugin Plugin { get; }
    public int SortPosition { get; set; }
    public Image Image { get; }

    public HelloWorldCommand(ITrayKitPlugin plugin)
    {
      Plugin = plugin;
      Image = SystemIcons.Shield.ToBitmap();
    }

    public void Execute()
    {
      MessageBox.Show("Hello World!");
    }
  }

Explanation:

Explanation image

Step 3(Optional): Using the settings-feature provided by TrayKit. To use the settings-management feature provided by TrayKit(which is explained further up), you need to create a public property on your ITrayKitPlugin-implementation and mark it with the TrayKit.Base.Settings.TrayKitPluginSettingsContainer-Attribute. In the SamplePlugin I created the following property on the Plugin-class:

[Base.Settings.TrayKitPluginSettingsContainer()]
public Settings Settings { get; set; }

By applying the attribute, TrayKit knows that it should look into the marked property and manage settings for the plugin. While looking into the property the application looks for members marked with the TrayKit.Base.Settings.TrayKitPluginSetting-Attribute. By applying the attribute, the properties value will be managed by TrayKit. An implementation could look like this:

public class Settings
  {
    [TrayKitPluginSetting]
    public bool ABoolValue { get; set; }
    [TrayKitPluginSetting]
    public decimal ADecimalValue { get; set; }
    [TrayKitPluginSetting]
    public double ADoubleValue { get; set; }
    [TrayKitPluginSetting]
    public float AFloatValue { get; set; }
    [TrayKitPluginSetting(Description ="This is a setting that stores an integer value.")]
    public int AnIntegerValue { get; set; }
    [TrayKitPluginSetting]
    public string AStringValue { get; set; }    
    [TrayKitPluginSetting]
    public DateTime ADateTimeValue { get; set; }
  }

Notice that the Setting-Attribute provides several properties like "MaxValue" or "MinValue". Not all of these are used by TrayKit yet.

LICENSE

MIT License

Copyright (c) [2016] [Sven Harenburg]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.