Chronos Plugins 5.11.0
This documentation covers the plugin interfaces definitions and an example implementation.
Loading...
Searching...
No Matches
MockPlugin.SampleList.RemotePluginService Class Reference

Example for communication with external programs. More...

Inheritance diagram for MockPlugin.SampleList.RemotePluginService:
Collaboration diagram for MockPlugin.SampleList.RemotePluginService:

Public Member Functions

bool DoSomething (string someParameter)
 Just uses a messagebox to show the external request.

Static Public Member Functions

static void StopService ()

Static Private Member Functions

static void HostFaultedHandler (object sender, EventArgs e)

Private Attributes

System.Windows.Forms.Form mMainWindow

Static Private Attributes

static ServiceHost mHost

Detailed Description

Example for communication with external programs.

This example uses WCF to show how you can trigger actions within the plugin from external programs. See RemoteAccessTester.MessageTesterForm for the client side. Please note that WCF will be discontinued by Microsoft, the server components will not be part of .Net Core in the future. So, while this is a working example for current Chronos releases, you should maybe not base a new project on this method of interprocess communication, but switch to something else like gRPC or an ASP.net WebAPI. Attention: This example service does not use any kind of access control. Do not do this for real applications, as it allows access from unauthorized sources and is a security problem. Access control is not addressed here to put the focus on the core issue: How to make plugin provided functionality available to external software.

Definition at line 22 of file RemoteServiceImplementation.cs.

Member Function Documentation

◆ DoSomething()

bool MockPlugin.SampleList.RemotePluginService.DoSomething ( string someParameter)

Just uses a messagebox to show the external request.

Parameters
someParameter
Returns

Implements MockPlugin.RemoteAccessTester.IMockPlugin.

Definition at line 30 of file RemoteServiceImplementation.cs.

31 {
32 if (mMainWindow == null)
33 {
34 mMainWindow = System.Windows.Forms.Control.FromHandle(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle) as System.Windows.Forms.Form;
35 }
36 // Just a few manipulations of the main window
37 if (mMainWindow != null)
38 {
39 someParameter = someParameter.ToLowerInvariant();
40 switch(someParameter)
41 {
42 case "hide":
43 mMainWindow.Hide();
44 break;
45 case "show":
46 mMainWindow.Show();
47 break;
48 case "min":
49 mMainWindow.WindowState = System.Windows.Forms.FormWindowState.Minimized;
50 break;
51 case "max":
52 mMainWindow.WindowState = System.Windows.Forms.FormWindowState.Maximized;
53 break;
54 }
55 }
56 else
57 {
58 System.Windows.Forms.MessageBox.Show("Could not get main window");
59 }
60 return System.Windows.Forms.MessageBox.Show(
61 $"Plugin does something on remote request: {someParameter}\nSucceeded?",
62 "Remote request to plugin",
63 System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes;
64 }

References mMainWindow.

◆ HostFaultedHandler()

void MockPlugin.SampleList.RemotePluginService.HostFaultedHandler ( object sender,
EventArgs e )
staticprivate

Definition at line 66 of file RemoteServiceImplementation.cs.

67 {
68 System.Diagnostics.Trace.WriteLine("Remote plugin service failed.");
69 }

◆ StopService()

void MockPlugin.SampleList.RemotePluginService.StopService ( )
static

Definition at line 81 of file RemoteServiceImplementation.cs.

82 {
83 try
84 {
85 if (mHost?.State == CommunicationState.Opened)
86 {
87 mHost?.Close();
88 }
89 }
90 catch
91 {
92 // nothing
93 }
94 }

References mHost.

Referenced by MockPlugin.SampleList.MockSampleListWorker.Dispose().

Member Data Documentation

◆ mHost

ServiceHost MockPlugin.SampleList.RemotePluginService.mHost
staticprivate

Definition at line 65 of file RemoteServiceImplementation.cs.

Referenced by StopService().

◆ mMainWindow

System.Windows.Forms.Form MockPlugin.SampleList.RemotePluginService.mMainWindow
private

Definition at line 24 of file RemoteServiceImplementation.cs.

Referenced by DoSomething().


The documentation for this class was generated from the following file: