-
Notifications
You must be signed in to change notification settings - Fork 5
/
AbstractPlugin.cs
704 lines (594 loc) · 27.2 KB
/
AbstractPlugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
using System;
using System.Collections.Generic;
using System.Threading;
using System.Text;
using HomeSeer.Jui.Views;
using HomeSeer.PluginSdk.Devices;
using HomeSeer.PluginSdk.Devices.Controls;
using HomeSeer.PluginSdk.Events;
using HSCF.Communication.Scs.Communication;
using HSCF.Communication.Scs.Communication.EndPoints.Tcp;
using HSCF.Communication.ScsServices.Client;
// ReSharper disable VirtualMemberNeverOverridden.Global
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
namespace HomeSeer.PluginSdk {
/// <inheritdoc cref="IPlugin"/>
/// <summary>
/// The base implementation of the <see cref="IPlugin"/> interface.
/// <para>
/// It includes default implementations for most of the IPlugin members and wraps others
/// with convenience methods and objects that make it simpler to interface with the HomeSeer system.
///
/// Once the containing plugin application is started, initiate a connection
/// to the HomeSeer system by calling <see cref="Connect(string[])"/>.
/// </para>
/// <para>All plugins (the HSPI class) should derive from this class.</para>
/// </summary>
public abstract class AbstractPlugin : IPlugin, ActionTypeCollection.IActionTypeListener, TriggerTypeCollection.ITriggerTypeListener {
#region Properties
/// <inheritdoc cref="IPlugin.HasSettings" />
/// <remarks>
/// The default implementation should be sufficient for all purposes;
/// returning TRUE if the <see cref="Settings"/> property contains pages
/// or FALSE if it doesn't.
/// <para>
/// Override this and always return TRUE if you plan on adding settings pages to the collection later
/// </para>
/// </remarks>
public virtual bool HasSettings => (Settings?.Count ?? 0) > 0;
/// <inheritdoc cref="IPlugin.Id" />
public abstract string Id { get; }
/// <inheritdoc cref="IPlugin.Name" />
public abstract string Name { get; }
/// <inheritdoc cref="IPlugin.AccessLevel" />
public virtual int AccessLevel { get; } = 1;
/// <inheritdoc cref="IPlugin.SupportsConfigDevice" />
public virtual bool SupportsConfigDevice { get; } = false;
/// <inheritdoc cref="IPlugin.SupportsConfigFeature" />
public virtual bool SupportsConfigFeature { get; } = false;
/// <inheritdoc cref="IPlugin.SupportsConfigDeviceAll" />
public virtual bool SupportsConfigDeviceAll { get; } = false;
/// <inheritdoc cref="IPlugin.TriggerCount" />
public int TriggerCount => TriggerTypes?.Count ?? 0;
/// <inheritdoc cref="IPlugin.ActionCount" />
public int ActionCount => ActionTypes?.Count ?? 0;
/// <summary>
/// Default section name for storing settings in an INI file
/// </summary>
protected const string SettingsSectionName = "Settings";
/// <summary>
/// An instance of the HomeSeer system
/// </summary>
protected IHsController HomeSeerSystem { get; private set; }
/// <summary>
/// The current status of the plugin.
/// <para>
/// Default state is OK
/// </para>
/// </summary>
/// <remarks>
/// This property is often queried by HomeSeer before interfacing with the plugin during normal
/// operation of the system to determine if it should continue making calls or report to the user that
/// the plugin may be inoperable. This is also queried when users navigate to the plugin management page.
/// </remarks>
/// <seealso cref="PluginStatus"/>
protected virtual PluginStatus Status { get; set; } = PluginStatus.Ok();
/// <summary>
/// The name of the settings INI file for the plugin.
/// <para>
/// It is recommended to use [PLUGIN-ID].ini where [PLUGIN-ID] is the ID of this plugin
/// </para>
/// </summary>
protected virtual string SettingsFileName => $"{Id}.ini";
/// <summary>
/// The collection of settings pages for the plugin.
/// See <see cref="SettingsCollection"/> for more information.
/// </summary>
// ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global
protected SettingsCollection Settings { get; set; } = new SettingsCollection();
/// <summary>
/// The collection of action types that this plugin hosts for HomeSeer
/// </summary>
protected ActionTypeCollection ActionTypes { get; set; }
/// <summary>
/// The collection of trigger types that this plugin hosts for HomeSeer
/// </summary>
protected TriggerTypeCollection TriggerTypes { get; set; }
/// <summary>
/// The IP Address that the HomeSeer system is located at
/// </summary>
protected string IpAddress { get; set; } = "127.0.0.1";
/// <summary>
/// Used to enable/disable internal logging to the console
/// <para>
/// When it is TRUE, log messages from the PluginSdk code will be written to the Console
/// </para>
/// </summary>
protected bool LogDebug {
get => _logDebug;
set {
_logDebug = value;
ActionTypes.LogDebug = value;
TriggerTypes.LogDebug = value;
}
}
private const int HomeSeerPort = 10400;
private static IScsServiceClient<IHsController> _client;
private bool _isShutdown;
private bool _logDebug;
//Actions
//Triggers
#endregion
/// <summary>
/// Default constructor that initializes the Action and Trigger type collections
/// </summary>
protected AbstractPlugin() {
ActionTypes = new ActionTypeCollection(this);
TriggerTypes = new TriggerTypeCollection(this);
LogDebug = _logDebug;
}
#region Startup and Shutdown
/// <summary>
/// Attempt to establish a connection to the HomeSeer system
/// <para>
/// This connection will be maintained as long as the program is running
/// or until <see cref="ShutdownIO"/> is called.
/// </para>
/// </summary>
/// <param name="args">Command line arguments included in the execution of the program</param>
// ReSharper disable once ParameterTypeCanBeEnumerable.Global
public void Connect(string[] args) {
foreach (var arg in args) {
var parts = arg.Split('=');
switch (parts[0].ToLower()) {
case "server":
IpAddress = parts[1];
break;
default:
Console.WriteLine("Unknown command-line argument : " + parts[0].ToLower());
break;
}
}
_client = ScsServiceClientBuilder.CreateClient<IHsController>(new ScsTcpEndPoint(IpAddress, HomeSeerPort),
this);
Console.WriteLine("Connecting to HomeSeer...");
Connect(1);
}
private void Connect(int attempts) {
try {
_client.Connect();
try {
HomeSeerSystem = _client.ServiceProxy;
var apiVersion = HomeSeerSystem.APIVersion;
Console.WriteLine("Connected to HomeSeer");
if (LogDebug) {
Console.WriteLine($"Host API Version: {apiVersion}");
}
}
catch (Exception exception) {
if (LogDebug) {
Console.WriteLine(exception);
}
}
}
catch (Exception exception) {
if (LogDebug) {
Console.WriteLine(exception);
}
Console.WriteLine($"Cannot connect attempt {attempts.ToString()}");
if (exception.Message.ToLower().Contains("timeout occured.") && attempts < 6) {
Connect(attempts + 1);
}
else
{
if (_client != null)
{
_client.Dispose();
_client = null;
}
}
return;
}
try {
Console.WriteLine("Waiting for initialization...");
HomeSeerSystem.RegisterPlugin(Id, Name);
do {
Thread.Sleep(10);
} while (_client.CommunicationState == CommunicationStates.Connected && !_isShutdown);
_client.Disconnect();
Console.WriteLine("Disconnected from HomeSeer");
}
catch (Exception exception) {
if (LogDebug) {
Console.WriteLine(exception);
}
throw;
}
}
/// <inheritdoc cref="IPlugin.InitIO"/>
protected abstract void Initialize();
/// <inheritdoc cref="IPlugin.InitIO"/>
/// <summary>
/// Called by HomeSeer to initialize the plugin.
/// <para>Perform all initialization logic in <see cref="Initialize"/></para>
/// </summary>
public bool InitIO() {
try {
if (LogDebug) {
Console.WriteLine("InitIO called by HomeSeer");
}
Initialize();
return true;
}
catch (Exception exception) {
if (LogDebug) {
Console.WriteLine(exception);
}
_isShutdown = true;
throw new Exception("Error on InitIO: " + exception.Message, exception);
}
}
/// <inheritdoc cref="IPlugin.ShutdownIO" />
public void ShutdownIO() {
try {
Console.WriteLine("Disconnecting from HomeSeer...");
OnShutdown();
}
catch (Exception exception) {
if (LogDebug) {
Console.WriteLine(exception);
}
}
_isShutdown = true;
}
/// <summary>
/// Called right before the plugin shuts down.
/// </summary>
protected virtual void OnShutdown() { }
#endregion
#region Settings
/// <inheritdoc cref="IPlugin.GetJuiSettingsPages"/>
public string GetJuiSettingsPages() {
if (LogDebug) {
Console.WriteLine("GetJuiSettingsPages");
}
OnSettingsLoad();
return Settings.ToJsonString();
}
/// <summary>
/// Called right before the data held in <see cref="Settings"/> is serialized and sent to HomeSeer.
/// <para>
/// Use this if you need to process anything when the plugin settings are loaded.
/// Otherwise, it is typically unnecessary to override this. The <see cref="SettingsCollection"/> class
/// automatically takes care of the JSON serialization/deserialization process.
/// </para>
/// </summary>
protected virtual void OnSettingsLoad() { }
/// <inheritdoc cref="IPlugin.SaveJuiSettingsPages"/>
public bool SaveJuiSettingsPages(string jsonString) {
if (LogDebug) {
Console.WriteLine("SaveJuiSettingsPages");
}
try {
var deserializedPages = SettingsCollection.FromJsonString(jsonString).Pages;
foreach (var pageDelta in deserializedPages) {
OnSettingPageSave(pageDelta);
}
return true;
}
catch (KeyNotFoundException exception) {
if (LogDebug) {
Console.WriteLine(exception);
}
throw new KeyNotFoundException("Cannot save settings.",
exception);
}
}
/// <summary>
/// Called when there are changes to settings that need to be processed for a specific page.
/// </summary>
/// <param name="pageDelta">The page with view changes to be processed</param>
/// <exception cref="KeyNotFoundException">
/// Thrown when a view change targets a view that doesn't exist on the page
/// </exception>
protected virtual void OnSettingPageSave(Page pageDelta) {
var page = Settings[pageDelta.Id];
foreach (var settingDelta in pageDelta.Views) {
//process settings changes
if (!page.ContainsViewWithId(settingDelta.Id)) {
throw new KeyNotFoundException($"No view with the ID of {settingDelta.Id} exists on page {page.Id}");
}
if (!OnSettingChange(page.Id, page.GetViewById(settingDelta.Id), settingDelta)) {
continue;
}
page.UpdateViewById(settingDelta);
try {
var newValue = settingDelta.GetStringValue();
if (newValue == null) {
continue;
}
//TODO revise INI setting saving
HomeSeerSystem.SaveINISetting(SettingsSectionName, settingDelta.Id, newValue, SettingsFileName);
}
catch (InvalidOperationException exception) {
Console.WriteLine(exception);
//TODO Process ViewGroup?
}
}
//Make sure the new state is stored
Settings[pageDelta.Id] = page;
}
/// <summary>
/// Called when there is a change to a setting that needs to be processed
/// </summary>
/// <param name="pageId">The ID of the page the view is on</param>
/// <param name="currentView">The state of the setting before the change</param>
/// <param name="changedView">The state of the settings after the change</param>
/// <returns>
/// TRUE if the change should be saved, FALSE if it should not
/// <para>
/// You should throw an exception including a detailed message whenever possible over returning FALSE
/// </para>
/// </returns>
protected abstract bool OnSettingChange(string pageId, AbstractView currentView, AbstractView changedView);
/// <summary>
/// Loads the plugin settings saved to INI to Settings and saves default values if none exist.
/// </summary>
protected void LoadSettingsFromIni() {
if (LogDebug) {
Console.WriteLine("Loading settings from INI");
}
//Get the whole section for settings
var savedSettings = HomeSeerSystem.GetIniSection(SettingsSectionName, SettingsFileName);
//Loop through each settings page
foreach (var settingsPage in Settings) {
//Build a map of settings on the page
var pageValueMap = settingsPage.ToValueMap();
//Loop through each setting
foreach (var settingPair in pageValueMap) {
//If there is a saved value for the setting
// Always true after the first time the plugin starts
if (savedSettings.ContainsKey(settingPair.Key)) {
//Pull the saved value into memory
if (LogDebug) {
Console.WriteLine("Updating view");
}
settingsPage.UpdateViewValueById(settingPair.Key, savedSettings[settingPair.Key]);
//Go to the next setting
continue;
}
//Save the setting if there is no default value already saved
HomeSeerSystem.SaveINISetting(SettingsSectionName,
settingPair.Key,
settingPair.Value,
SettingsFileName);
}
}
}
#endregion
#region Configuration and Status Info
/// <inheritdoc cref="IPlugin.OnStatusCheck" />
public PluginStatus OnStatusCheck() {
BeforeReturnStatus();
return Status ?? PluginStatus.Warning("Current plugin status is unknown (null)");
}
/// <summary>
/// Called immediately before the plugin returns its <see cref="Status"/> to HomeSeer.
/// <para>
/// Use this to analyze the current state of the plugin and update the <see cref="Status"/> accordingly.
/// </para>
/// </summary>
/// <seealso cref="PluginStatus"/>
protected abstract void BeforeReturnStatus();
#endregion
#region Devices
/// <inheritdoc cref="IPlugin.UpdateStatusNow" />
public virtual EPollResponse UpdateStatusNow(int devOrFeatRef) {
return EPollResponse.NotFound;
}
/// <inheritdoc cref="IPlugin.SetIOMulti" />
/// <remarks>
/// The default behavior is to clear the current status text and set the value on the target feature and then
/// let HomeSeer assign the status text based on the configured <see cref="StatusControl"/>s
/// and <see cref="StatusGraphic"/>s
/// </remarks>
public virtual void SetIOMulti(List<ControlEvent> colSend) {
foreach (var controlEvent in colSend) {
HomeSeerSystem.UpdateFeatureValueByRef(controlEvent.TargetRef, controlEvent.ControlValue);
}
}
/// <inheritdoc cref="IPlugin.HasJuiDeviceConfigPage" />
/// <remarks>
/// Default behavior is to show a configuration page for every device when
/// <see cref="SupportsConfigDevice"/> or <see cref="SupportsConfigFeature"/> or <see cref="SupportsConfigDeviceAll"/> is set to true.
/// Adjust this behavior if the plugin only shows a configuration page for some, but not all, devices.
/// </remarks>
public virtual bool HasJuiDeviceConfigPage(int devOrFeatRef) {
return true;
}
/// <inheritdoc cref="IPlugin.GetJuiDeviceConfigPage" />
public virtual string GetJuiDeviceConfigPage(int devOrFeatRef) {
return $"No device config page registered by plugin {Id}";
}
/// <inheritdoc cref="IPlugin.SaveJuiDeviceConfigPage" />
public bool SaveJuiDeviceConfigPage(string pageContent, int devOrFeatRef) {
if (LogDebug) {
Console.WriteLine("SaveJuiDeviceConfigPage");
}
try {
var deserializedPage = Page.FromJsonString(pageContent);
return OnDeviceConfigChange(deserializedPage, devOrFeatRef);
}
catch (KeyNotFoundException exception) {
if (LogDebug) {
Console.WriteLine(exception);
}
throw new KeyNotFoundException("Cannot save device config; no pages exist with that ID.",
exception);
}
}
// ReSharper disable UnusedParameter.Global
/// <summary>
/// Called when there are changes to the device or feature config page that need to be processed and saved
/// </summary>
/// <param name="deviceConfigPage">A JUI page containing only the new state of any changed views</param>
/// <param name="devOrFeatRef">The reference of the device or feature the config page is for</param>
/// <returns>
/// TRUE if the save was successful; FALSE if it was not
/// <para>
/// You should throw an exception including a detailed message whenever possible over returning FALSE
/// </para>
/// </returns>
protected virtual bool OnDeviceConfigChange(Page deviceConfigPage, int devOrFeatRef) {
return true;
}
// ReSharper restore UnusedParameter.Global
#endregion
#region Features
/// <inheritdoc cref="IPlugin.PostBackProc" />
public virtual string PostBackProc(string page, string data, string user, int userRights) {
return "";
}
#endregion
#region Events
/// <inheritdoc cref="IPlugin.HsEvent" />
public virtual void HsEvent(Constants.HSEvent eventType, object[] @params) {
//process events?
}
#region Actions
/// <inheritdoc cref="IPlugin.ActionReferencesDevice" />
public bool ActionReferencesDevice(TrigActInfo actInfo, int dvRef) {
return ActionTypes?.ActionReferencesDeviceOrFeature(dvRef, actInfo) ?? false;
}
/// <inheritdoc cref="IPlugin.ActionBuildUI" />
public string ActionBuildUI(TrigActInfo actInfo) {
return ActionTypes?.OnGetActionUi(actInfo) ?? "Plugin returned malformed data";
}
/// <inheritdoc cref="IPlugin.ActionConfigured" />
public bool ActionConfigured(TrigActInfo actInfo) {
return ActionTypes?.IsActionConfigured(actInfo) ?? true;
}
/// <inheritdoc cref="IPlugin.ActionFormatUI" />
public string ActionFormatUI(TrigActInfo actInfo) {
return ActionTypes?.OnGetActionPrettyString(actInfo) ?? "Plugin returned malformed data";
}
/// <inheritdoc cref="IPlugin.ActionProcessPostUI" />
public EventUpdateReturnData ActionProcessPostUI(Dictionary<string, string> postData, TrigActInfo actInfo) {
return ActionTypes?.OnUpdateActionConfig(postData, actInfo) ??
new EventUpdateReturnData {
DataOut = actInfo.DataIn, Result = "Plugin returned malformed data", TrigActInfo = actInfo
};
}
/// <inheritdoc cref="IPlugin.HandleAction" />
public bool HandleAction(TrigActInfo actInfo) {
return ActionTypes?.HandleAction(actInfo) ?? false;
}
/// <inheritdoc cref="IPlugin.GetActionNameByNumber" />
public string GetActionNameByNumber(int actionNum) {
return ActionTypes?.GetName(actionNum) ?? "Error retrieving action name";
}
#endregion
#region Triggers
/// <inheritdoc cref="IPlugin.TriggerBuildUI" />
public string TriggerBuildUI(TrigActInfo trigInfo) {
return TriggerTypes?.OnGetTriggerUi(trigInfo) ?? "Plugin returned malformed data";
}
/// <inheritdoc cref="IPlugin.TriggerFormatUI" />
public string TriggerFormatUI(TrigActInfo trigInfo) {
return TriggerTypes?.OnGetTriggerPrettyString(trigInfo) ?? "Plugin returned malformed data";
}
/// <inheritdoc cref="IPlugin.TriggerProcessPostUI" />
public EventUpdateReturnData TriggerProcessPostUI(Dictionary<string, string> postData, TrigActInfo trigInfoIn) {
return TriggerTypes?.OnUpdateTriggerConfig(postData, trigInfoIn) ??
new EventUpdateReturnData {
DataOut = trigInfoIn.DataIn, Result = "Plugin returned malformed data",
TrigActInfo = trigInfoIn
};
}
/// <inheritdoc cref="IPlugin.TriggerReferencesDeviceOrFeature" />
public bool TriggerReferencesDeviceOrFeature(TrigActInfo trigInfo, int devOrFeatRef) {
return TriggerTypes?.TriggerReferencesDeviceOrFeature(devOrFeatRef, trigInfo) ?? false;
}
/// <inheritdoc cref="IPlugin.TriggerCanBeCondition" />
public bool TriggerCanBeCondition(int triggerNum) {
return TriggerTypes?.TriggerCanBeCondition(triggerNum) ?? false;
}
/// <inheritdoc cref="IPlugin.GetSubTriggerCount" />
public int GetSubTriggerCount(int triggerNum) {
return TriggerTypes?.GetSubTriggerCount(triggerNum) ?? 0;
}
/// <inheritdoc cref="IPlugin.GetSubTriggerNameByNumber" />
public string GetSubTriggerNameByNumber(int triggerNum, int subTriggerNum) {
return TriggerTypes?.GetSubTriggerName(triggerNum, subTriggerNum) ?? "Plugin returned malformed data";
}
/// <inheritdoc cref="IPlugin.IsTriggerConfigValid" />
public bool IsTriggerConfigValid(TrigActInfo trigInfo) {
return TriggerTypes?.IsTriggerConfigured(trigInfo) ?? true;
}
/// <inheritdoc cref="IPlugin.GetTriggerNameByNumber" />
public string GetTriggerNameByNumber(int triggerNum) {
return TriggerTypes?.GetName(triggerNum) ?? "Plugin returned malformed data";
}
/// <inheritdoc cref="IPlugin.TriggerTrue" />
public bool TriggerTrue(TrigActInfo trigInfo, bool isCondition = false) {
return TriggerTypes?.IsTriggerTrue(trigInfo, isCondition) ?? false;
}
#endregion
#endregion
#region Dynamic Method/Property Calls
/// <inheritdoc cref="IPlugin.PluginFunction" />
public virtual object PluginFunction(string procName, object[] @params) {
try {
var ty = GetType();
var mi = ty.GetMethod(procName);
return mi == null ? null : mi.Invoke(this, @params);
}
catch (Exception exception) {
if (LogDebug) {
Console.WriteLine(exception.Message);
}
}
return null;
}
/// <inheritdoc cref="IPlugin.PluginPropertyGet" />
public virtual object PluginPropertyGet(string propName) {
try {
var ty = GetType();
var mi = ty.GetProperty(propName);
return mi == null ? null : mi.GetValue(this, null);
}
catch (Exception exception) {
if (LogDebug) {
Console.WriteLine(exception.Message);
}
}
return null;
}
/// <inheritdoc cref="IPlugin.PluginPropertySet" />
public virtual void PluginPropertySet(string propName, object value) {
try {
var ty = GetType();
var mi = ty.GetProperty(propName);
if (mi == null) {
var message = new StringBuilder("Property ")
.Append(propName).Append(" does not exist in this plugin.");
if (LogDebug) {
Console.WriteLine(message);
}
}
else {
mi.SetValue(this, value, null);
}
}
catch (Exception exception) {
if (LogDebug) {
Console.WriteLine(exception.Message);
}
}
}
#endregion
/// <inheritdoc cref="IPlugin.SpeakIn" />
public virtual void SpeakIn(int speechDevice, string spokenText, bool wait, string host) {}
}
}