Chronos Plugins  5.2.0
This documentation covers the plugin interfaces definitions and an example implementation.
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. More...
 

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.

Definition at line 19 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 27 of file RemoteServiceImplementation.cs.

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  }

References MockPlugin.SampleList.RemotePluginService.mMainWindow.

◆ HostFaultedHandler()

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

Definition at line 63 of file RemoteServiceImplementation.cs.

64  {
65  if (Helpers.Gui != null)
66  {
67  System.Windows.Forms.MessageBox.Show(Helpers.Gui.MainWindow,"Remote plugin service failed.");
68  }
69  }
IWin32Window MainWindow
If you need to set the owner window yourself or want to show message boxes.
Definition: Helpers.cs:39
Static instance for access to utility functions and resources.
Definition: Helpers.cs:80
static IGuiHelper Gui
Utility functions for window handling
Definition: Helpers.cs:94

References AxelSemrau.Chronos.Plugin.Helpers.Gui, and AxelSemrau.Chronos.Plugin.IGuiHelper.MainWindow.

◆ StopService()

static 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 MockPlugin.SampleList.RemotePluginService.mHost.

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

Member Data Documentation

◆ mHost

ServiceHost MockPlugin.SampleList.RemotePluginService.mHost
staticprivate

◆ mMainWindow

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

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