Windows service based on plugin architecture - c#

I am building a windows service based on plugin architecture and I run into some problem.
The problem is I want plugin to fire event on the main application. Here is some code.
These are delegates
namespace eTreasury.SchedulerInterface
{
public enum Severity
{
Message,
Warning,
Error
}
public delegate void ErrorHandler(string message, Severity errorSeverity);
public delegate void CompletedHandler(string message);
public delegate void ProgressReportHandler(string message, int percentCompleted);
}
This is interface
public interface IPluginInterface : IDisposable
{
string Identifier{ get; }
void Run();
void Dispose();
event ErrorHandler OnError;
event CompletedHandler OnCompleted;
event ProgressReportHandler OnProgress;
}
This is base class I want all plugins to inherit from
public abstract class BasePlugin : MarshalByRefObject, IPluginInterface
{
protected string _identifier;
public string Identifier
{
get { return _identifier; }
}
public abstract void Run();
protected void ReportError(string message, Severity errorSeverity)
{
if (OnError != null)
OnError(message, errorSeverity);
}
protected void ReportProgress(string message, int percentCompleted)
{
if (OnProgress != null)
OnProgress(message, percentCompleted);
}
protected void ReportProgress(string message)
{
ReportProgress(message, 0);
}
protected void ReportCompleted(string message)
{
if (OnCompleted != null)
OnCompleted(message);
}
public void Dispose()
{
OnError = null;
OnCompleted = null;
OnProgress = null;
_identifier = null;
}
public event ErrorHandler OnError;
public event CompletedHandler OnCompleted;
public event ProgressReportHandler OnProgress;
}
This is plugin
public class CurrencyRatesPlugin : BasePlugin
{
public CurrencyRatesPlugin()
{
_identifier = "CurrencyRatesPlugin";
}
public override void Run()
{
try
{
ReportProgress("bla", 0);
}
catch (Exception e)
{
ReportError("bla");
}
}
}
And this is my windows service code
public partial class CurrencyRatesPluginService : ServiceBase
{
AppDomain appDomain;
IPluginInterface pluginInterface;
System.Timers.Timer Timer = null;
public CurrencyRatesPluginService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
try
{
this.appDomain = CreateAppDomain();
this.pluginInterface = (IPluginInterface)appDomain.CreateInstanceFrom("C:\\eTreasuryScheduler\\Plugins\\eTreasury.CurrencyRatesPlugin.dll", "eTreasury.Plugins.CurrencyRatesPlugin.CurrencyRatesPlugin").Unwrap();
PluginSection section = (PluginSection)ConfigurationManager.GetSection("PluginSectionGroup/PluginSection");
if (section == null)
{
EventLogManager.LogError("bla");
}
else
{
Timer = new System.Timers.Timer();
Timer.Enabled = false;
Timer.Interval = section.PluginItems[0].Interval;
Timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
Timer.Start();
}
}
catch(Exception ex)
{
EventLogManager.LogError(String.Format("{0}...{1}", ex.Message, ex.InnerException == null ? string.Empty : ex.InnerException.Message));
}
}
protected override void OnStop()
{
Timer.Stop();
this.pluginInterface.Dispose();
AppDomain.Unload(this.appDomain);
}
void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
Process();
}
void Process()
{
try
{
this.pluginInterface.OnProgress += ProcessProgressReportHandler;
this.pluginInterface.OnCompleted += ProcessCompletedHandler;
pluginInterface.Run();
this.pluginInterface.OnProgress -= ProcessProgressReportHandler;
this.pluginInterface.OnCompleted -= ProcessCompletedHandler;
}
catch (Exception ex)
{
EventLogManager.LogError(String.Format("{0}...{1}", ex.Message, ex.InnerException == null ? string.Empty : ex.InnerException.Message));
}
}
private void ProcessProgressReportHandler(string message, int percentCompleted)
{
EventLogManager.LogInformation(message);
}
private void ProcessCompletedHandler(string message)
{
EventLogManager.LogInformation(message);
}
AppDomain CreateAppDomain()
{
...
}
}
And everythig is working fine except the events.
The error occurs here
this.pluginInterface.OnProgress += ProcessProgressReportHandler;
And the error message is
Exception has been thrown by the target of an invocation....Could not load file or assembly 'eTreasury.SchedulerService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

I`ve added IHost interface and Initialize methods in plugin interface. When loading plugin in host application I call Initialize method of that plugin and pass Host to it. After this I have ability to call host methods from plugin.

Related

websocket-sharp - OnMessage callback is not running in the main thread

I have a WPF (.NET Framework 4.6) application that uses websocket-sharp (version 3.0.0) to create a websocket server.
I have a WebsocketServer and using EventHandler to tranfer event to MainWindow.xaml.cs but it not working. The MainWindow.xaml.cs listened to a RaiseOnScanDevice event but not any event invoked here.
I think this issue is relative to different thread. I try using Dispatcher.Invoke but it still not working.
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() =>
{
RaiseOnScanDevice(this, new EventArgs());
}));
I found an issue (https://github.com/sta/websocket-sharp/issues/350) but the answers do not resolve my issue.
Please help me a solution for this issue.
WebsocketServer.cs file
public class WebsocketServer : WebSocketBehavior
{
private static readonly Lazy<WebsocketServer> lazyInstance = new Lazy<WebsocketServer>(() => new WebsocketServer());
public static WebsocketServer Instance
{
get
{
return lazyInstance.Value;
}
}
private const string TAG = "WebsocketServer";
private const string HOST_IP_ADDRESS = "127.0.0.2"; // localhost
private const int PORT = 38001;
public WebSocketServer socket;
private PacketHandler packetHandler = new PacketHandler();
public event EventHandler<EventArgs> RaiseOnScanDevice = new EventHandler<EventArgs>((a, e) => { });
public WebsocketServer()
{
Initialize();
}
public void Initialize()
{
socket = new WebSocketServer(IPAddress.Parse(HOST_IP_ADDRESS), PORT);
socket.AddWebSocketService<WebsocketServer>("/");
StartServer();
}
public void StartServer()
{
socket.Start();
}
public void StopServer()
{
socket.Stop();
}
protected override Task OnOpen()
{
return base.OnOpen();
}
protected override Task OnClose(CloseEventArgs e)
{
return base.OnClose(e);
}
protected override Task OnError(ErrorEventArgs e)
{
return base.OnError(e);
}
protected override Task OnMessage(MessageEventArgs e)
{
System.IO.StreamReader reader = new System.IO.StreamReader(e.Data);
string message = reader.ReadToEnd();
//Converting the event back to 'eventName' and 'JsonPayload'
PacketModel packet = packetHandler.OpenPacket(message);
HandleMessageFromClient(packet);
return base.OnMessage(e);
}
private void HandleMessageFromClient(PacketModel packet) {
var eventName = packet.EventName;
var data = packet.Data;
if (eventName == null || eventName.Equals(""))
{
return;
}
switch (eventName)
{
case SocketEvent.Hello:
Send("OK");
break;
case SocketEvent.ScanDevice:
ScanDevice();
break;
default:
break;
}
}
private void ScanDevice()
{
try
{
RaiseOnScanDevice(this, new EventArgs());
// or dispatch to Main Thread
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() =>
{
RaiseOnScanDevice(this, new EventArgs());
}));
}
catch (Exception exception)
{
Console.WriteLine(exception);
}
}
}
MainWindow.xaml.cs file
public partial class MainWindow : Window
{
public WebsocketServer WebsocketConnection
{
get { return WebsocketServer.Instance; }
}
public MainWindow()
{
InitializeComponent();
WebsocketConnection.RaiseOnScanDevice += SocketConnection_RaiseOnScanDevice;
}
private void SocketConnection_RaiseOnScanDevice(object sender, EventArgs e)
{
Console.WriteLine("SocketConnection_RaiseOnScanDevice");
}
The queue of messages is a good idea but you may want to use a lock to guard access to it. Most likely it won't be an issue but if you don't, you leave yourself open to the possibility of an error if the coroutine is reading from the queue as the websocket is writing to it. For example you could do something like this:
var queueLock = new object();
var queue = new Queue<MyMessageType>();
// use this to read from the queue
MyMessageType GetNextMessage()
{
lock (queueLock) {
if (queue.Count > 0) return queue.Dequeue();
else return null;
}
}
// use this to write to the queue
void QueueMessage(MyMessageType msg)
{
lock(queueLock) {
queue.Enqueue(msg);
}
}

EventHandler bubbling up

I want to bubble up a message through classes. I used events and did this:
public class TopLevel{
public event EventHandler<string> Message;
public MiddleLevel mid;
public TopLevel()
{
mid.Message += (s, e) => { Message(s, e) };
}
}
public class MiddleLevel{
public event EventHandler<string> Message;
public BottomLevel bottom;
public MiddleLevel()
{
bottom.Message += (s, e) => { Message(s, e) };
}
}
public class BootomLevel{
public event EventHandler<string> Message;
public void DoSomething()
{
Message?.Invoke(this, "I did it.");
}
}
public class Handler{
public void HandleEvent(TopLevel top)
{
top.Message += PrintMessage;
}
public void PrintMessage(object sender, string message)
{
Console.WrteLine(message);
}
}
Also tried changing constructor to lambda expressions like this:
public class TopLevel{
public event EventHandler<string> Message;
public MiddleLevel mid;
public TopLevel()
{
mid.Message += (s, e) => { Message?.Invoke(s, e); };
}
}
public class MiddleLevel{
public event EventHandler<string> Message;
public BottomLevel bottom;
public MiddleLevel()
{
bottom.Message += (s, e) => { Message?.Invoke(s, e); };
}
}
public class BootomLevel{
public event EventHandler<string> Message;
public void DoSomething()
{
Message?.Invoke(this, "I did it.");
}
}
public class Handler{
public void HandleEvent(TopLevel top)
{
top.Message += PrintMessage;
}
public void PrintMessage(object sender, string message)
{
Console.WrteLine(message);
}
}
Codes above doesn't print any message. Even if I handle event in MiddleLevel class, I still get no message. I assume it is because message call is made in constructor (Even though linq quarries update themselves)? If I handle event in Handle class straight from BottomLevel class, it obviously - works. But I need to bubble the message up, I can't think of any other way to to this, because of how classes are constructed. Is it even possible to do what I have in mind with a standard Eventhandler class? If so than how? Should I just make an event class myself as in one of the sites i refered?
I refered to these sites:
What is the preferred way to bubble events?
https://www.carlosble.com/2016/04/event-bubbling-in-c/
Updated answer:
If you want 'Handler' to be triggered you will have to make sure that 'BottomLevel' falls within the hierarchy of the 'TopLevel' class being passed to the handler, this can be done via dependency injection (DI).
If 'BottomLevel' instantiates it's own classes (no DI) then it will not know about 'Handler', so handler will never be triggered.
If you comment out the DI setup and un-comment the 'BottomLevel' instantiation you can see the different behaviors.
class Program
{
static void Main(string[] args)
{
//setup the classes (dependency injection)
TopLevel topLevel = new TopLevel();
MiddleLevel middleLevel = new MiddleLevel(topLevel);
BottomLevel bottomLevel = new BottomLevel(middleLevel);
//set up the handler
Handler h = new Handler(topLevel);
//using this will not link to 'Handler' as there is no relation between this bottom and top
//BottomLevel bottomLevel = new BottomLevel();
//trigger the bottom class
bottomLevel.TriggerBottom();
//or
bottomLevel.DoSomething(null, "call from main");
Console.ReadLine();
}
}
public class Handler
{
TopLevel _topLevel;
public Handler(TopLevel topLevel)
{
if (topLevel != null)
_topLevel = topLevel;
_topLevel.Message += _topLevel_Message;
}
private void _topLevel_Message(object sender, string e)
{
Console.WriteLine($"handler triggered : {e}");
}
}
public class TopLevel
{
public event EventHandler<string> Message;
public TopLevel()
{ }
public void TriggerTop()
{
Message?.Invoke(this, "origin top");
}
public void DoSomething(object sender, string e)
{
Console.WriteLine($"Do something at top : {e}");
Message?.Invoke(this, e);
}
}
public class MiddleLevel
{
TopLevel _TopLevel;
public event EventHandler<string> Message;
public MiddleLevel(TopLevel topLevel) : this()
{
_TopLevel = topLevel;
}
public MiddleLevel()
{
if (_TopLevel == null)
_TopLevel = new TopLevel();
//subscribe this message to bottom message event method
Message += (s, e) => { _TopLevel.DoSomething(s, e); };
}
public void TriggerMiddle()
{
Message?.Invoke(this, "origin middle");
}
public void DoSomething(object sender, string e)
{
Console.WriteLine($"do something in middle : {e}");
//invoke the event(s)
Message?.Invoke(sender, e);
}
}
public class BottomLevel
{
MiddleLevel _MidLevel;
public event EventHandler<string> Message;
public BottomLevel(MiddleLevel midLevel) : this()
{
_MidLevel = midLevel;
}
public BottomLevel()
{
if (_MidLevel == null)
_MidLevel = new MiddleLevel();
////here you assign it
Message += (s, e) => { _MidLevel.DoSomething(s, e); };
}
public void TriggerBottom()
{
DoSomething(this, "origin bottom");
}
public void DoSomething(object sender, string e)
{
Console.WriteLine($"do something at bottom : {e}");
Message?.Invoke(sender, e);
}
}

Publish and subscribe events in silverlight

I am trying to understand a piece of code in a legacy silverlight application.In this code as you can see user can publish an event and subscribe to that event.
while publishing event
Messenger.Publish<ErrorInformationData>(MessageConstant.ShowMessageTechnicalError,
new ErrorInformationData(ServiceOperationName.ClaimsService_GetClaim, ServiceOperationOccurence.DataServiceUI));
then subscribing to that event
Messenger.Subscribe<ErrorInformationData>(
this,
MessageConstant.ShowMessageTechnicalError,
(result) =>
{
Messenger.Publish(MessageConstant.ShowMessage,
new MessageData
{
Title = "Common$TechnicalError",
MessageText = "Common$TechnicalErrorDetail",
TextParameters = new object[] { result.OperationErrorCode.ToString() },
MessageType = MessageData.MessageTypes.OK,
OKAction = () =>
{
HtmlPage.Window.Navigate(new Uri("", UriKind.Relative));
},
MessageLevel = MessageData.MessageLevels.Error
}
);
}
);
Question is why do I need to use this framework where instead I can simply invoke a method.Also can anyone point to any documentation/tutorial regarding this communication.
Thanks #Nikosi for pointer, after more investigation I have found what's going on under the hood.
So there is a IMessanger interface which contains signature of publish,subscribe and unsubscribe method.
public interface IMessanger : IDisposable
{
void Subscribe(IReceiver receiver, int messageId);
void Publish<TEventArgs>(object sender, TEventArgs e, int messageId)
where TEventArgs : EventArgs;
void Unsubscribe(IReceiver receiver, int messageId);
}
Now we define a class Messanger which implements the interface.
public sealed class Messanger : IMessanger
{
private readonly Dictionary<int, List<IReceiver>> messageIdToReceiver;
public Messanger()
{
this.messageIdToReceiver = new Dictionary<int, List<IReceiver>>();
}
public void Subscribe(IReceiver receiver, int messageId)
{
List<IReceiver> receivers;
if (this.messageIdToReceiver.TryGetValue(messageId, out receivers))
{
receivers.Add(receiver);
}
else
{
this.messageIdToReceiver.Add(messageId, new List<IReceiver>() { receiver });
}
}
public void Publish<TEventArgs>(object sender, TEventArgs e, int messageId)
where TEventArgs : EventArgs
{
List<IReceiver> receivers;
if (this.messageIdToReceiver.TryGetValue(messageId, out receivers))
{
foreach (IReceiver receiver in receivers)
{
IReceiver<TEventArgs> receiverToReceive = receiver as IReceiver<TEventArgs>;
if (receiverToReceive != null)
{
receiverToReceive.Receive(sender, e, messageId);
}
}
}
}
public void Unsubscribe(IReceiver receiver, int messageId)
{
List<IReceiver> receivers;
if (this.messageIdToReceiver.TryGetValue(messageId, out receivers))
{
if (receivers.Count > 1)
{
receivers.Remove(receiver);
}
else if(receivers.Count == 1)
{
this.messageIdToReceiver.Remove(messageId);
}
}
}
public void Dispose()
{
this.messageIdToReceiver.Clear();
}
}
public interface IReceiver<TEventArgs> : IReceiver
where TEventArgs : EventArgs
{
void Receive(object sender, TEventArgs e, int messageId);
}
public interface IReceiver : IDisposable
{
}
Now we can see the usage of the above,Defined two classes one is publishing the event and other one is receiving the event.
public class PresenterA : IReceiver<EventArgs>, IDisposable
{
readonly IMessanger messanger;
public PresenterA(IMessanger messanger)
{
this.messanger = messanger;
this.messanger.Subscribe(this, (int)PubSubMsg.AppInstl);
}
public void Receive(object sender, EventArgs e, int messageId)
{
if ((PubSubMsg)messageId == PubSubMsg.AppInstl)
{
//Now that you received the message, update the UI, etc...
}
}
public void Dispose()
{
this.messanger.Unsubscribe(this, (int)PubSubMsg.AppInstl);
}
}
public class PresenterB
{
readonly IMessanger messanger;
public PresenterB(IMessanger messanger)
{
this.messanger = messanger;
}
public void btnApplicationRemove(object sender, EventArgs e)
{
//Do what you need to do and then publish the message
this.messanger.Publish<EventArgs>(this, e, (int)PubSubMsg.AppInstl);
}
}
public enum PubSubMsg
{
AppInstl = 1
}

Update a form in parallel with an installation script?

I currently have an installation "framework" that does specific things. What I need now to do is be able to call my form in parallel with my script. Something like this:
InstallationForm f = new InstallationForm();
Application.Run(f);
InstallSoftware(f);
private static void InstallSoftware(InstallationForm f) {
f.WriteToTextbox("Starting installation...");
Utils.Execute(#"C:\temp\setup.msi", #"-s C:\temp\instructions.xml");
...
f.WriteToTextbox("Installation finished");
The current way I can do this is by adding the Form.Shown handler in InstallSoftware, but that seems really messy. Is there anyway I can do this better?
Your code will not work, because Application.Run(f) returns not until the form was closed.
You may use a simplified Model/View/Controller pattern. Create an InstallationFormController class that has several events, e.g. for textual notifications to be written to your textbox. The InstallationForm registers on these events in it's OnLoad() method and then calls InstallationFormController.Initialize(). That method starts your installation (on a worker thread/task). That installation callback method fires several text events.
InstallationForm f = new InstallationForm(new InstallationFormController());
Application.Run(f);
internal class InstallationFormController
{
public event EventHandler<DataEventArgsT<string>> NotificationTextChanged;
public InstallationFormController()
{
}
public void Initialize()
{
Task.Factory.StartNew(DoInstallation);
}
private void DoInstallation()
{
...
OnNotificationTextChanged(new DataEventArgsT<string>("Installation finished"));
}
private void OnNotificationTextChanged(DataEventArgsT<string> e)
{
if(NotificationTextChanged != null)
NotificationTextChanged(this, e);
}
}
public class DataEventArgsT<T> : EventArgs
{
...
public T Data { get; set; }
}
internal class InstallationForm : Form
{
private readonly InstallationFormController _controller;
public InstallationForm()
{
InitializeComponent();
}
public InstallationForm(InstallationFormController controller) : this()
{
if(controller == null)
throw new ArgumentNullException("controller")
_controller = controller;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
_controller.NotificationTextChanged += Controller_NotificationTextChanged;
_controller.Initialize();
}
protected virtual void Controller_NotificationTextChanged(object sender, DataEventArgsT<string> e)
{
if(this.InvokeRequired)
{ // call this method on UI thread!!!
var callback = new EventHandler<DataEventArgsT<string>>(Controller_NotificationTextChanged);
this.Invoke(callback, new object[] {sender, e});
}
else
{
_myTextBox.Text = e.Data;
}
}
...
}

C# Plugin using MarshalByRefObject creating multiple copies

I am putting together a plugin framework with these requirements:
load/unload plugins at will
call methods in loaded plugins
raise callback events from plugin to the owner
To do this I am creating a new AppDomain, and loading the Plugin assemblies into this.
The implementation I have so far is working to a degree, but I believe I am creating an instance of the plugin in the local appDomain and also the new AppDomain.
When I load first, I get duplicate callback messages. When I load/unload multiple times I get multiple callback messages being added to the list. This indicates to me that I am loading up the plugin assembly not only remotely but also locally, and thus my "unload" mechanism is not operating as I would like. I would be grateful if anyone can tell me where I am going wrong.
I also understand I need to take the "life time" of the plugin into account but not sure where to implement this.
Thanks.
(1) I have a plugin interface
public interface IPlugin
{
string Name();
string Version();
string RunProcess();
// custom event handler to be implemented, event arguments defined in child class
event EventHandler<PluginEventArgs> CallbackEvent;
//event EventHandler<EventArgs> CallbackEvent;
void OnProcessStart(PluginEventArgs data);
void OnProcessEnd(PluginEventArgs data);
}
(2) custom event args
[Serializable]
public class PluginEventArgs : EventArgs
{
public string ResultMessage;
public string executingDomain;
public PluginEventArgs(string resultMessage = "")
{
// default empty values allows us to send back default event response
this.ResultMessage = resultMessage;
this.executingDomain = AppDomain.CurrentDomain.FriendlyName;
}
}
(3) example plugin class implementation
[Serializable]
public class Plugin_1 : IPlugin
{
System.Timers.Timer counter;
int TimerInterval;
string PluginName = "My plugin";
public string Name()
{
return "CMD";
}
public bool Start()
{
OnStart(new PluginEventArgs());
RunProcess();
return true;
}
// OnTimer event, process start raised, sleep to simulate doing some work, then process end raised
public void OnCounterElapsed(Object sender, EventArgs e)
{
OnProcessStart(new PluginEventArgs());
OnProcessEnd(new PluginEventArgs());
Stop();
}
public bool Stop()
{
// simulate waiting for process to finish whatever its doing....
if (counter != null)
{
counter.Stop();
OnStop(new PluginEventArgs());
}
return true;
}
public string RunProcess()
{
TimerInterval = 2000;
if (counter == null){
counter = new System.Timers.Timer(TimerInterval);
}
else {
counter.Stop();
counter.Interval = TimerInterval;
}
counter.Elapsed += OnCounterElapsed;
counter.Start();
return "";
}
public event EventHandler<PluginEventArgs> CallbackEvent;
void OnCallback(PluginEventArgs e)
{
if (CallbackEvent != null)
{
CallbackEvent(this, e);
}
}
public void OnProcessStart(PluginEventArgs Data)
{
OnCallback(new PluginEventArgs(Data.executingDomain + " - " + PluginName + " started"));
}
public void OnProcessEnd(PluginEventArgs Data)
{
OnCallback(new PluginEventArgs(Data.executingDomain + " - " + PluginName + " ended"));
}
(4) I have a plugin manager that loads/unloads
public bool LoadPlugin()
{
try
{
Domain_Command = AppDomain.CreateDomain("Second_domain");
command_loader = (ProxyLoader)Domain_Command.CreateInstanceAndUnwrap("PluginMgr", "PluginMgr.Method");
Plugins.AddPlugin(command_loader.LoadAndExecute("APluginName", Plugins.ProxyLoader_RaiseCallbackEvent), SomePluginType, false);
return true;
}
catch (Exception ex)
{
string message = ex.Message;
return false;
}
}
(5) my "ProxyLoader" to load the plugin into separate AppDomain
public class ProxyLoader : MarshalByRefObject
{
public AssemblyInstanceInfo LoadAndExecute(string assemblyName, EventHandler<PluginContract.PluginEventArgs> proxyLoader_RaiseCallbackEvent)
{
AssemblyInstanceInfo AInfo = new AssemblyInstanceInfo();
//nb: this AppDomain.CurrentDomain is in its own context / different from the caller app domain?
Assembly pluginAssembly = AppDomain.CurrentDomain.Load(assemblyName);
foreach (Type type in pluginAssembly.GetTypes())
{
if (type.GetInterface("IPlugin") != null)
{
object instance = Activator.CreateInstance(type, null, null);
AInfo.ObjectInstance = instance;
string s = ((PluginContract.IPlugin)instance).RunProcess(); // main procedure
AInfo.ASM = pluginAssembly;
((PluginContract.IPlugin)instance).CallbackEvent += proxyLoader_RaiseCallbackEvent;
((PluginContract.IPlugin)instance).Start();
instance = null;
}
}
return AInfo;
}
}
(6) I have a callback this plugs into
public event EventHandler<PluginContract.PluginEventArgs> Callback;
void OnCallback(PluginContract.PluginEventArgs e)
{
if (Callback != null)
{
Callback(this, e);
}
}
(7) called by (referenced in ProxyLoader when load the assembly)
public void ProxyLoader_RaiseCallbackEvent(object source, PluginContract.PluginEventArgs e)
{
OnCallback(new PluginContract.PluginEventArgs(str));
}

Categories

Resources