Skip to content

Commit 5def5e0

Browse files
muenchrisChris MuenchMarkusHorstmann
authored
Template improvements (#26)
* new cdeEnergy model used by several plugins * dep5 fixes * missing license * content file fixes for energy and webconnect * Default Sensor improvements; SenderBase UX Improvements * SDK Updates to support VS2022 * Build: use latest msbuild (for vsix 2022) * Build: lock to windows-2022 temporarily (for VSIX) * VSIX projects: remove unused Microsoft.VisualStudio.CoreUtility reference * VSIX project: remove one more Microsoft.VisualStudio.CoreUtility reference * VSIX Template: AppHostWinForms to .Net 4.7.2 * Sensor Template updates; Energy Model Updates * New cdeNMIHelper Library and EnergyModel * Tagged AutoConnect in SensorTemplate correctly * Template optimization using quick aliases * fix for energy contract * missing license info * more licenses * more lic * typos * nmihelper reference missing * cleanup and copyright to 2022 Co-authored-by: Chris Muench <chris.muench@live.com> Co-authored-by: Markus Horstmann <markushorstmann@hotmail.com>
1 parent 580fd1b commit 5def5e0

File tree

19 files changed

+1302
-790
lines changed

19 files changed

+1302
-790
lines changed

.reuse/dep5

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,23 @@ License: MPL-2.0
398398
Files: src/readme.md
399399
Copyright: 2009-2022 TRUMPF Laser GmbH, authors: C-Labs
400400
License: MPL-2.0
401+
402+
Files: src/MessageContracts/034 - EnergyModel/cdeEnergyModel.shproj
403+
Copyright: 2009-2022 TRUMPF Laser GmbH, authors: C-Labs
404+
License: MPL-2.0
405+
406+
Files: src/MessageContracts/034 - EnergyModel/cdeEnergyModel.cs
407+
Copyright: 2009-2022 TRUMPF Laser GmbH, authors: C-Labs
408+
License: MPL-2.0
409+
410+
Files: src/MessageContracts/034 - EnergyModel/cdeEnergyModel.projitems
411+
Copyright: 2009-2022 TRUMPF Laser GmbH, authors: C-Labs
412+
License: MPL-2.0
413+
414+
Files: src/Libraries/324 - NMIHelper/cdeNMIHelper/cdeNMIHelper.projitems
415+
Copyright: 2009-2022 TRUMPF Laser GmbH, authors: C-Labs
416+
License: MPL-2.0
417+
418+
Files: src/Libraries/324 - NMIHelper/cdeNMIHelper/cdeNMIHelper.shproj
419+
Copyright: 2009-2022 TRUMPF Laser GmbH, authors: C-Labs
420+
License: MPL-2.0

src/CDEngineSDKTemplates/CDEngineSDKTemplates.Item.cdeConnectedThingBase/cdeConnectedThingBase.cs

Lines changed: 100 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -2,136 +2,133 @@
22
//
33
// SPDX-License-Identifier: MPL-2.0
44

5-
using System;
5+
using System;
66

77
// TODO: Add reference for C-DEngine.dll
88
// 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;
1411

1512
namespace $rootnamespace$
1613
{
1714
[DeviceType(DeviceType = e$rootnamespace$DeviceTypes.$safeitemrootname$, Description = "This Thing does...", Capabilities = new[] { eThingCaps.ConfigManagement })]
18-
class $safeitemrootname$: TheThingBase
15+
class $safeitemrootname$: TheThingBase
1916
{
2017
// Base object references
2118
protected IBaseEngine MyBaseEngine; // Base engine (service)
2219

23-
// User-interface defintion
24-
protected TheFormInfo MyStatusForm;
25-
protected TheDashPanelInfo MyStatusFormDashPanel;
20+
// User-interface defintion
21+
protected TheFormInfo MyStatusForm;
22+
protected TheDashPanelInfo MyStatusFormDashPanel;
2623

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+
}
3633

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+
}
4340

44-
public $safeitemrootname$(TheThing tBaseThing, ICDEPlugin pPluginBase)
41+
public $safeitemrootname$(TT tBaseThing, ICDEPlugin pPluginBase)
4542
{
46-
MyBaseThing = tBaseThing ?? new TheThing();
47-
MyBaseEngine = pPluginBase.GetBaseEngine();
43+
MyBaseThing = tBaseThing ?? new TT();
44+
MyBaseEngine = pPluginBase.GetBaseEngine();
4845
MyBaseThing.EngineName = MyBaseEngine.GetEngineName();
4946
MyBaseThing.SetIThingObject(this);
5047

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+
}
7451

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+
}
7668

77-
protected virtual void DoEndMe(ICDEThing pEngine, object notused)
78-
{
69+
protected virtual void DoInit()
70+
{
7971

80-
}
72+
}
8173

74+
protected virtual void DoEndMe(ICDEThing pEngine, object notused)
75+
{
8276

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+
}
10678

107-
}
10879

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;
11685

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);
12291

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);
12894

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;
13697
}
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+
}
137134
}

0 commit comments

Comments
 (0)