87 lines
2.8 KiB
C#
87 lines
2.8 KiB
C#
using System;
|
|
using BlubbFish.BosmonMqtt.Models;
|
|
using BlubbFish.BosmonMqtt.Views;
|
|
using BosMon.Data.Processors;
|
|
using BosMon.Exceptions;
|
|
using BosMon.Plugins;
|
|
using BosMon.Prefs;
|
|
|
|
namespace BlubbFish.BosmonMqtt {
|
|
class Plugin {
|
|
private PluginConfiguration pluginconfiguration;
|
|
private Boolean isDisposed = false;
|
|
private Boolean isInitialized = false;
|
|
private ConfigView _configView;
|
|
private MqttEventProcessor _mqtteventprocessor;
|
|
private Boolean isStarted = false;
|
|
private ITelegramEventProcessor _events;
|
|
|
|
internal IBosMonHost PluginHost { get; set; }
|
|
internal IBosMonConfigurationStorage ConfigurationStorage { get; set; }
|
|
|
|
internal void Init() {
|
|
if (this.ConfigurationStorage == null || this.PluginHost == null) {
|
|
throw new BosMonArgumentNullException();
|
|
}
|
|
if (this.isInitialized) {
|
|
throw new BosMonInternalException();
|
|
}
|
|
this.pluginconfiguration = new PluginConfiguration(this.ConfigurationStorage);
|
|
this.isInitialized = true;
|
|
this._configView = new ConfigView(this.pluginconfiguration);
|
|
this._mqtteventprocessor = new MqttEventProcessor(this.pluginconfiguration, this.PluginHost);
|
|
}
|
|
|
|
internal void Start() {
|
|
if (!this.isInitialized) {
|
|
throw new BosMonInternalException("Not initialized");
|
|
}
|
|
try {
|
|
// ... Plugin starten ...
|
|
this.PluginHost.RegisterConfigPage("Plugins", "Mqtt", this._configView);
|
|
//this.PluginHost.RegisterEventProcessor("MqttEventProcessor", this._mqtteventprocessor);
|
|
|
|
this._events = this.PluginHost.GetEventProcessor("TelegramEventProcessor") as ITelegramEventProcessor;
|
|
this._events.TelegramEvent += this._mqtteventprocessor.TelegramEvent;
|
|
|
|
// Es muss unbedingt darauf geachtet werden, dass das Plugin in dieser
|
|
// Methode nicht blockiert, da sonst der Hauptthread von BosMon ebenfalls
|
|
// blockiert wird.
|
|
|
|
this.isStarted = true;
|
|
} catch (Exception) {
|
|
|
|
}
|
|
}
|
|
|
|
internal void Stop() {
|
|
if (!this.isInitialized) {
|
|
throw new BosMonInternalException("Not initialized");
|
|
}
|
|
|
|
try {
|
|
if (this.isStarted) {
|
|
this._configView.Dispose();
|
|
this.PluginHost.UnRegisterConfigPage(this._configView);
|
|
this._events.TelegramEvent -= this._mqtteventprocessor.TelegramEvent;
|
|
this._mqtteventprocessor.Dispose();
|
|
this.isStarted = false;
|
|
}
|
|
} catch (Exception ex) {
|
|
BosMon.Gui.BosMonErrorBox.Show(ex, "Fehler");
|
|
}
|
|
}
|
|
|
|
internal void Dispose(Boolean dispose) {
|
|
if (!this.isDisposed) {
|
|
if (dispose) {
|
|
try {
|
|
//DeInitialize();
|
|
} catch (Exception) { }
|
|
}
|
|
this.isDisposed = true;
|
|
}
|
|
}
|
|
}
|
|
}
|