|
2 | 2 | //
|
3 | 3 | // SPDX-License-Identifier: MPL-2.0
|
4 | 4 |
|
5 |
| -using System; |
| 5 | +using System; |
6 | 6 |
|
7 | 7 | // TODO: Add reference for C-DEngine.dll
|
8 | 8 | // TODO: Make sure plugin file name starts with either CDMy or C-DMy
|
9 |
| -using nsCDEngine.BaseClasses; |
10 |
| -using nsCDEngine.Engines; |
11 |
| -using nsCDEngine.Engines.NMIService; |
12 |
| -using nsCDEngine.Engines.ThingService; |
13 |
| -using nsCDEngine.ViewModels; |
| 9 | +using NMI = nsCDEngine.Engines.NMIService.TheNMIEngine; |
| 10 | +using TT = nsCDEngine.Engines.ThingService.TheThing; |
14 | 11 |
|
15 | 12 | namespace $rootnamespace$
|
16 | 13 | {
|
17 | 14 | [DeviceType(DeviceType = e$rootnamespace$DeviceTypes.$safeitemrootname$, Description = "This Thing does...", Capabilities = new[] { eThingCaps.ConfigManagement })]
|
18 |
| - class $safeitemrootname$: TheThingBase |
| 15 | +class $safeitemrootname$: TheThingBase |
19 | 16 | {
|
20 | 17 | // Base object references
|
21 | 18 | protected IBaseEngine MyBaseEngine; // Base engine (service)
|
22 | 19 |
|
23 |
| - // User-interface defintion |
24 |
| - protected TheFormInfo MyStatusForm; |
25 |
| - protected TheDashPanelInfo MyStatusFormDashPanel; |
| 20 | +// User-interface defintion |
| 21 | +protected TheFormInfo MyStatusForm; |
| 22 | +protected TheDashPanelInfo MyStatusFormDashPanel; |
26 | 23 |
|
27 |
| - // |
28 |
| - // C-DEngine properties are wrapped inside C# properties. |
29 |
| - // This is a recommended practice. |
30 |
| - // Also recommended, the use of the 'GetSafe...' and 'SetSafe...' methods. |
31 |
| - public bool IsConnected |
32 |
| - { |
33 |
| - get { return TheThing.MemberGetSafePropertyBool(MyBaseThing); } |
34 |
| - set { TheThing.MemberSetSafePropertyBool(MyBaseThing, value); } |
35 |
| - } |
| 24 | +// |
| 25 | +// C-DEngine properties are wrapped inside C# properties. |
| 26 | +// This is a recommended practice. |
| 27 | +// Also recommended, the use of the 'GetSafe...' and 'SetSafe...' methods. |
| 28 | +public bool IsConnected |
| 29 | +{ |
| 30 | + get { return TT.MemberGetSafePropertyBool(MyBaseThing); } |
| 31 | + set { TT.MemberSetSafePropertyBool(MyBaseThing, value); } |
| 32 | +} |
36 | 33 |
|
37 |
| - [ConfigProperty] |
38 |
| - public bool AutoConnect |
39 |
| - { |
40 |
| - get { return TheThing.MemberGetSafePropertyBool(MyBaseThing); } |
41 |
| - set { TheThing.MemberSetSafePropertyBool(MyBaseThing, value); } |
42 |
| - } |
| 34 | +[ConfigProperty] |
| 35 | +public bool AutoConnect |
| 36 | +{ |
| 37 | + get { return TT.MemberGetSafePropertyBool(MyBaseThing); } |
| 38 | + set { TT.MemberSetSafePropertyBool(MyBaseThing, value); } |
| 39 | +} |
43 | 40 |
|
44 |
| - public $safeitemrootname$(TheThing tBaseThing, ICDEPlugin pPluginBase) |
| 41 | +public $safeitemrootname$(TT tBaseThing, ICDEPlugin pPluginBase) |
45 | 42 | {
|
46 |
| - MyBaseThing = tBaseThing ?? new TheThing(); |
47 |
| - MyBaseEngine = pPluginBase.GetBaseEngine(); |
| 43 | + MyBaseThing = tBaseThing ?? new TT(); |
| 44 | +MyBaseEngine = pPluginBase.GetBaseEngine(); |
48 | 45 | MyBaseThing.EngineName = MyBaseEngine.GetEngineName();
|
49 | 46 | MyBaseThing.SetIThingObject(this);
|
50 | 47 |
|
51 |
| - // TODO: Add your DeviceType to the plug-in's e$rootnamespace$DeviceTypes class |
52 |
| - MyBaseThing.DeviceType = e$rootnamespace$DeviceTypes.$safeitemrootname$; |
53 |
| - } |
54 |
| - |
55 |
| - public override bool Init() |
56 |
| - { |
57 |
| - if (!mIsInitCalled) |
58 |
| - { |
59 |
| - mIsInitCalled = true; |
60 |
| - IsConnected = false; |
61 |
| - SetMessage("Thing Ready", DateTimeOffset.Now); |
62 |
| - MyBaseThing.StatusLevel = 0; |
63 |
| - MyBaseEngine.RegisterEvent(eEngineEvents.ShutdownEvent, DoEndMe); |
64 |
| - DoInit(); |
65 |
| - if (AutoConnect) |
66 |
| - Connect(null); |
67 |
| - mIsInitialized = true; |
68 |
| - } |
69 |
| - return true; |
70 |
| - } |
71 |
| - |
72 |
| - protected virtual void DoInit() |
73 |
| - { |
| 48 | +// TODO: Add your DeviceType to the plug-in's e$rootnamespace$DeviceTypes class |
| 49 | +MyBaseThing.DeviceType = e$rootnamespace$DeviceTypes.$safeitemrootname$; |
| 50 | +} |
74 | 51 |
|
75 |
| - } |
| 52 | +public override bool Init() |
| 53 | +{ |
| 54 | + if (!mIsInitCalled) |
| 55 | + { |
| 56 | + mIsInitCalled = true; |
| 57 | + IsConnected = false; |
| 58 | + SetMessage("Thing Ready", DateTimeOffset.Now); |
| 59 | + MyBaseThing.StatusLevel = 0; |
| 60 | + MyBaseEngine.RegisterEvent(eEngineEvents.ShutdownEvent, DoEndMe); |
| 61 | + DoInit(); |
| 62 | + if (AutoConnect) |
| 63 | + Connect(null); |
| 64 | + mIsInitialized = true; |
| 65 | + } |
| 66 | + return true; |
| 67 | +} |
76 | 68 |
|
77 |
| - protected virtual void DoEndMe(ICDEThing pEngine, object notused) |
78 |
| - { |
| 69 | +protected virtual void DoInit() |
| 70 | +{ |
79 | 71 |
|
80 |
| - } |
| 72 | +} |
81 | 73 |
|
| 74 | +protected virtual void DoEndMe(ICDEThing pEngine, object notused) |
| 75 | +{ |
82 | 76 |
|
83 |
| - public override bool CreateUX() |
84 |
| - { |
85 |
| - if (!mIsUXInitCalled) |
86 |
| - { |
87 |
| - mIsUXInitCalled = true; |
88 |
| - |
89 |
| - var tHead = TheNMIEngine.AddStandardForm(MyBaseThing, MyBaseThing.FriendlyName); |
90 |
| - MyStatusForm = tHead["Form"] as TheFormInfo; // TheNMIEngine.AddForm(new TheFormInfo(MyBaseThing) { FormTitle = MyBaseThing.DeviceType, DefaultView = eDefaultView.Form, PropertyBag = new ThePropertyBag { "MaxTileWidth=6" } }); |
91 |
| - MyStatusFormDashPanel = tHead["DashIcon"] as TheDashPanelInfo; |
92 |
| - var tBlock = TheNMIEngine.AddStatusBlock(MyBaseThing, MyStatusForm, 2); |
93 |
| - tBlock["Group"].SetParent(1); |
94 |
| - |
95 |
| - tBlock = TheNMIEngine.AddConnectivityBlock(MyBaseThing, MyStatusForm, 120, sinkConnect); |
96 |
| - tBlock["Group"].SetParent(1); |
97 |
| - |
98 |
| - DoCreateUX(tHead["Form"] as TheFormInfo); |
99 |
| - mIsUXInitialized = true; |
100 |
| - } |
101 |
| - return true; |
102 |
| - } |
103 |
| - |
104 |
| - protected virtual void DoCreateUX(TheFormInfo pForm) |
105 |
| - { |
| 77 | +} |
106 | 78 |
|
107 |
| - } |
108 | 79 |
|
109 |
| - void sinkConnect(TheProcessMessage pMsg, bool DoConnect) |
110 |
| - { |
111 |
| - if (DoConnect) |
112 |
| - Connect(pMsg); |
113 |
| - else |
114 |
| - Disconnect(pMsg); |
115 |
| - } |
| 80 | +public override bool CreateUX() |
| 81 | +{ |
| 82 | + if (!mIsUXInitCalled) |
| 83 | + { |
| 84 | + mIsUXInitCalled = true; |
116 | 85 |
|
117 |
| - public virtual void Connect(TheProcessMessage pMsg) |
118 |
| - { |
119 |
| - SetMessage("Thing Connected", DateTimeOffset.Now); |
120 |
| - MyBaseThing.StatusLevel = 1; |
121 |
| - } |
| 86 | + var tHead = NMI.AddStandardForm(MyBaseThing, MyBaseThing.FriendlyName); |
| 87 | + MyStatusForm = tHead["Form"] as TheFormInfo; // TheNMIEngine.AddForm(new TheFormInfo(MyBaseThing) { FormTitle = MyBaseThing.DeviceType, DefaultView = eDefaultView.Form, PropertyBag = new ThePropertyBag { "MaxTileWidth=6" } }); |
| 88 | + MyStatusFormDashPanel = tHead["DashIcon"] as TheDashPanelInfo; |
| 89 | + var tBlock = NMI.AddStatusBlock(MyBaseThing, MyStatusForm, 2); |
| 90 | + tBlock["Group"].SetParent(1); |
122 | 91 |
|
123 |
| - public virtual void Disconnect(TheProcessMessage pMsg) |
124 |
| - { |
125 |
| - SetMessage("Thing Disconnected", DateTimeOffset.Now); |
126 |
| - MyBaseThing.StatusLevel = 0; |
127 |
| - } |
| 92 | + tBlock = NMI.AddConnectivityBlock(MyBaseThing, MyStatusForm, 120, sinkConnect); |
| 93 | + tBlock["Group"].SetParent(1); |
128 | 94 |
|
129 |
| - public override bool Delete() |
130 |
| - { |
131 |
| - DoEndMe(this, null); |
132 |
| - //TODO: Remove any residuals in the cache folder like StorageMirrors |
133 |
| - //i.e. MyStorageMirror.RemoveStore(); |
134 |
| - return true; |
135 |
| - } |
| 95 | + DoCreateUX(tHead["Form"] as TheFormInfo); |
| 96 | + mIsUXInitialized = true; |
136 | 97 | }
|
| 98 | + return true; |
| 99 | +} |
| 100 | + |
| 101 | +protected virtual void DoCreateUX(TheFormInfo pForm) |
| 102 | +{ |
| 103 | + |
| 104 | +} |
| 105 | + |
| 106 | +void sinkConnect(TheProcessMessage pMsg, bool DoConnect) |
| 107 | +{ |
| 108 | + if (DoConnect) |
| 109 | + Connect(pMsg); |
| 110 | + else |
| 111 | + Disconnect(pMsg); |
| 112 | +} |
| 113 | + |
| 114 | +public virtual void Connect(TheProcessMessage pMsg) |
| 115 | +{ |
| 116 | + SetMessage("Thing Connected", DateTimeOffset.Now); |
| 117 | + MyBaseThing.StatusLevel = 1; |
| 118 | +} |
| 119 | + |
| 120 | +public virtual void Disconnect(TheProcessMessage pMsg) |
| 121 | +{ |
| 122 | + SetMessage("Thing Disconnected", DateTimeOffset.Now); |
| 123 | + MyBaseThing.StatusLevel = 0; |
| 124 | +} |
| 125 | + |
| 126 | +public override bool Delete() |
| 127 | +{ |
| 128 | + DoEndMe(this, null); |
| 129 | + //TODO: Remove any residuals in the cache folder like StorageMirrors |
| 130 | + //i.e. MyStorageMirror.RemoveStore(); |
| 131 | + return true; |
| 132 | +} |
| 133 | +} |
137 | 134 | }
|
0 commit comments