JD2022-TU1/main/tools/framework/JD.Application/Plugin/BasePlugin.cs

44 lines
1.6 KiB
C#

using System;
using JD.Application.Program;
using JD.Core.ProjectManaging;
using JD.Interfaces.Remoting;
using JD.Remoting;
namespace JD.Application.Plugin
{
/// <summary>
/// Base class for plugins.
/// </summary>
public class BasePlugin : Remoting.Plugin
{
public BasePlugin(string name, IConnection connection = null)
: base(name, connection)
{
AllowConnectionToIncompatibleTarget = false;
DispatchOnMainThread = action => TeaBox.ObjectModel.Application.Main.Dispatcher.DispatchAsync(action);
//ReportQueryTimeout = () => MessageService.ShowBalloon(TimeSpan.FromSeconds(10), "No engine response", "Timeout to join the engine expired.", ToolTipIcon.Warning);
ConnectedToIncompatibleTarget += OnConnectedToIncompatibleTarget;
}
/// <summary>
/// Asks the engine for the currently playing wave.
/// </summary>
public void SendGetWave()
{
this.Send(CommandNames.GetTrack);
}
void OnConnectedToIncompatibleTarget(object sender, System.ComponentModel.CancelEventArgs e)
{
Stop();
TeaBox.ObjectModel.Application.Main.Dispatcher.DispatchAsync(() =>
{
MessageService.MessageService.ShowError(
$"{ProgramIdentity.Instance.Name} ({ProjectManager.Instance.GetCurrentProjectId()}) is not compatible with engine ({ProjectId}).",
"Tool incompatibility"
);
}, true);
}
}
}