Chronos Plugins 5.4.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 if (Helpers.Gui != null)
66 {
67 System.Windows.Forms.MessageBox.Show(Helpers.Gui.MainWindow,"Remote plugin service failed.");
68 }
69 }
73 internal static void StartService()
74 {
75 mHost = new ServiceHost(typeof(RemotePluginService));
76 mHost.AddServiceEndpoint(typeof(IMockPlugin), new NetTcpBinding(), EndpointDef.Endpoint);
77 mHost.Faulted += HostFaultedHandler;
78 mHost.Open();
79 }
80
81 public static void StopService()
82 {
83 try
84 {
85 if (mHost?.State == CommunicationState.Opened)
86 {
87 mHost?.Close();
88 }
89 }
90 catch
91 {
92 // nothing
93 }
94 }
95 }
96}
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.
IWin32Window MainWindow
If you need to set the owner window yourself or want to show message boxes.
Definition: Helpers.cs:37
Static instance for access to utility functions and resources.
Definition: Helpers.cs:78
static IGuiHelper Gui
Utility functions for window handling.
Definition: Helpers.cs:92
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)