Chronos Plugins 5.9.0
This documentation covers the plugin interfaces definitions and an example implementation.
Loading...
Searching...
No Matches
RemoteServiceImplementation.cs
Go to the documentation of this file.
1using System;
2using System.ServiceModel;
5// ReSharper disable LocalizableElement
6
8{
20 {
21 private System.Windows.Forms.Form mMainWindow;
27 public bool DoSomething(string someParameter)
28 {
29 if (mMainWindow == null)
30 {
31 mMainWindow = System.Windows.Forms.Control.FromHandle(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle) as System.Windows.Forms.Form;
32 }
33 // Just a few manipulations of the main window
34 if (mMainWindow != null)
35 {
36 someParameter = someParameter.ToLowerInvariant();
37 switch(someParameter)
38 {
39 case "hide":
40 mMainWindow.Hide();
41 break;
42 case "show":
43 mMainWindow.Show();
44 break;
45 case "min":
46 mMainWindow.WindowState = System.Windows.Forms.FormWindowState.Minimized;
47 break;
48 case "max":
49 mMainWindow.WindowState = System.Windows.Forms.FormWindowState.Maximized;
50 break;
51 }
52 }
53 else
54 {
55 System.Windows.Forms.MessageBox.Show("Could not get main window");
56 }
57 return System.Windows.Forms.MessageBox.Show(
58 $"Plugin does something on remote request: {someParameter}\nSucceeded?",
59 "Remote request to plugin",
60 System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes;
61 }
62 private static ServiceHost mHost;
63 private static void HostFaultedHandler(object sender, EventArgs e)
64 {
65 System.Diagnostics.Trace.WriteLine("Remote plugin service failed.");
66 }
70 internal static void StartService()
71 {
72 mHost = new ServiceHost(typeof(RemotePluginService));
73 mHost.AddServiceEndpoint(typeof(IMockPlugin), new NetTcpBinding(), EndpointDef.Endpoint);
74 mHost.Faulted += HostFaultedHandler;
75 mHost.Open();
76 }
77
78 public static void StopService()
79 {
80 try
81 {
82 if (mHost?.State == CommunicationState.Opened)
83 {
84 mHost?.Close();
85 }
86 }
87 catch
88 {
89 // nothing
90 }
91 }
92 }
93}
Classes and interfaces that are meant for plugins. The classes and interfaces below this namespace ar...
Interaction with Chronos crossing the process barrier. A normal Chronos plugin is a class library loa...
The classes in this namespace demonstrate how to interact with the Chronos sample list.
Very basic service, only to show that you can trigger some action from outside and get a response.
To avoid duplicating the endpoint definition in server and client.
Example for communication with external programs.
bool DoSomething(string someParameter)
Just uses a messagebox to show the external request.
static void HostFaultedHandler(object sender, EventArgs e)