public bool RegisterRule(TheThingRule pRule) { if (pRule == null || TheBaseAssets.MyServiceHostInfo.IsCloudService) { return(false); } pRule.GetBaseThing().EngineName = MyBaseEngine.GetEngineName(); if (pRule.TriggerCondition == eRuleTrigger.Set) { pRule.ActionValue = null; } pRule.IsRuleRunning = false; pRule.IsRuleWaiting = true; pRule.IsIllegal = false; pRule.IsTriggerObjectAlive = false; pRule.Parent = MyBaseThing.ID; pRule.GetBaseThing().EngineName = MyBaseEngine.GetEngineName(); TheSystemMessageLog.WriteLog(4445, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM(eKnownDeviceTypes.TheThingRule, $"Rule {pRule.FriendlyName} stopped during Register Rule - waiting for startup"), false); TheThing.SetSafePropertyDate(pRule.GetBaseThing(), "LastTriggered", DateTimeOffset.MinValue); TheThing.SetSafePropertyDate(pRule.GetBaseThing(), "LastAction", DateTimeOffset.MinValue); TheThingRegistry.RegisterThing(pRule); return(true); }
void sinkRuleThingEvent(ICDEThing sender, object pIncoming) { if (sender == null) { return; } TheThing tThing = TheThingRegistry.GetThingByProperty("*", Guid.Empty, "TriggerObject", TheThing.GetSafePropertyString(sender, "ID")); if (tThing != null) { TheRule tRule = tThing.GetObject() as TheRule; if (tRule == null || !tRule.IsRuleActive) { return; } if (tRule.TriggerStartTime > DateTimeOffset.Now) { return; } if (tRule.TriggerEndTime < DateTimeOffset.Now) { RemoveTrigger(tRule, false); return; } tRule.FireAction(false); } }
public virtual bool Init() { if (mIsInitCalled) { return(false); } mIsInitCalled = true; if (string.IsNullOrEmpty(MyBaseThing.ID)) { MyBaseThing.ID = Guid.NewGuid().ToString(); this.Gen_Config_StatsUpdateInterval = 5000; } MyBaseThing.Value = "0"; TheThing.SetSafePropertyBool(MyBaseThing, "IsActive", true); MyBaseThing.GetProperty(nameof(Gen_Config_PropertyUpdateInterval), true).RegisterEvent(eThingEvents.PropertyChanged, OnChangeTimer); MyBaseThing.GetProperty(nameof(Gen_Config_NumberOfActiveProperties), true).RegisterEvent(eThingEvents.PropertyChanged, OnChangeTimer); MyBaseThing.StatusLevel = 0; if (TheThing.GetSafePropertyBool(MyBaseThing, "AutoStart")) { OnChangeTimer(null); } mIsInitialized = true; return(true); }
void sinkUpdated(ICDEThing sender, object inObj) { if (TheBaseAssets.MyServiceHostInfo.IsCloudService) { return; } TheThing pThing = sender.GetBaseThing(); if (pThing != null) { TheRule tRule = pThing.GetObject() as TheRule; if (tRule != null) { if (tRule.IsRuleActive) { ActivateRules(); } else { RemoveTrigger(tRule, true); } } } }
public void StartPropertyUpdateLoop() { testThing = new TheThing() { FriendlyName = "MyTestSensor" }; TheThingRegistry.RegisterThing(testThing); Random rand = new Random(); // Used for generating "fake" sensor values cdeP[] props = new cdeP[propertyCount]; // Run the loop on another thread TheCommonUtils.cdeRunAsync("PropertyUpdateLoop", true, (o) => { while (TheBaseAssets.MasterSwitch) { // Set the properties and log props[0] = testThing.SetProperty(properties[0], rand.Next(25, 51)); props[1] = testThing.SetProperty(properties[1], rand.NextDouble()); props[2] = testThing.SetProperty(properties[2], rand.Next(10000, 50000)); LogChanges(false, props); // Wait timeout of 1 second between property updates TheCommonUtils.SleepOneEye(1000, 500); } }); }
void sinkRegisterIsos() { var tEngs = TheThingRegistry.GetBaseEnginesAsThing(false, true); foreach (var t in tEngs) { if (TheThing.GetSafePropertyBool(t, "IsIsolated")) { IBaseEngine tBase = TheThingRegistry.GetBaseEngine(t, true); if (tBase != null && tBase.GetISOLater() != null) { TheThing tT = TheThingRegistry.GetThingByFunc(MyBaseEngine.GetEngineName(), s => s.DeviceType == TheISOlaterKPIs.eDeviceType && TheThing.GetSafePropertyString(s, "ISOLaterName") == t.EngineName); var tKPI = new TheISOlaterKPIs(tT, this, t.EngineName); TheThingRegistry.RegisterThing(tKPI); } } } List <TheThing> tDevList = TheThingRegistry.GetThingsByProperty(MyBaseEngine.GetEngineName(), Guid.Empty, "DeviceType", TheKPIReport.eDeviceType); if (tDevList.Count > 0) { foreach (TheThing tDev in tDevList) { if (tDev.GetObject() == null) { TheKPIReport cs = new TheKPIReport(tDev, this); TheThingRegistry.RegisterThing(cs); } } } }
T CreateOrUpdateService <T>(TheThing tDevice, bool bRegisterThing) where T : TheNetworkServiceBase { T tServer; if (tDevice == null || !tDevice.HasLiveObject) { tServer = (T)Activator.CreateInstance(typeof(T), tDevice, this); if (bRegisterThing) { TheThingRegistry.RegisterThing(tServer); tServer.GetBaseThing().RegisterOnChange("DeviceType", OnServerDeviceTypeChanged); } } else { tServer = tDevice.GetObject() as T; if (tServer != null) { //tServer.InitServer(null); } else { tServer = (T)Activator.CreateInstance(typeof(T), tDevice, this); } } return(tServer); }
public override string ProcessEventData(TheThing thing, object evnt, DateTimeOffset defaultTimestamp) { string error = null; string json = DecodeEventAsString(evnt); if (json == null) { error = "Invalid payload"; } else { MeasurementPayload payload = null; try { payload = TheCommonUtils.DeserializeJSONStringToObject<MeasurementPayload>(json); if (payload == null) { error = "No data in payload"; } else { // TODO Implement deserializer (not customer requirement at this point) } } catch (Exception e) { error = e.ToString(); } } return error; }
public void DeclareSecurePropertyTest() { var testPW = "testpassword123YYY###$$$"; var testThing = new TheThing(); TheThing.SetSafePropertyString(testThing, "Password", testPW); var testPWReadNotEncrypted = TheThing.GetSafePropertyString(testThing, "Password"); Assert.AreSame(testPW, testPWReadNotEncrypted, "Failed to read ununecrypted property"); testThing.DeclareSecureProperty("Password", ePropertyTypes.TString); var testPWReadNotEncryptedObject = testThing.GetProperty("Password").Value; Assert.IsTrue(testPWReadNotEncryptedObject is string, $"Encrypted password is not of type string. Type: {testPWReadNotEncryptedObject.GetType()}"); var testPWReadObjectString = testPWReadNotEncryptedObject as string; Assert.AreNotSame(testPW, testPWReadObjectString, "Password not encrypted after transition from unsecure to secure property"); Assert.IsTrue((testPWReadNotEncryptedObject as string).StartsWith("&^CDESP1^&:"), "Encrypted string does not have expected encryption prefix"); var testPWReadDecryptedString = TheThing.GetSafePropertyString(testThing, "Password"); Assert.AreEqual(testPW, testPWReadDecryptedString, "Password not preserved after transition from unsecure to secure property"); }
public override void DoCreateUX(TheFormInfo tMyForm, ThePropertyBag pChartsBag = null) { base.DoCreateUX(tMyForm); AddSpeedGauge(tMyForm); var tEngage = TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.TileButton, 25012, 2, 0xC0, "Restart KPI", null, new nmiCtrlNumber { ParentFld = TheDefaultSensor.SensorActionArea, TileWidth = 6, NoTE = true }); tEngage.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "reset", (sender, para) => { EngageMapper(); }); var tRemove = TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.TileButton, 25013, 2, 0xC0, "Delete this KPI Report", null, new nmiCtrlNumber { ParentFld = TheDefaultSensor.SensorActionArea, TileWidth = 6, NoTE = true }); tRemove.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "remove", (sender, para) => { TheThing tT = TheThingRegistry.GetThingByID(MyBaseEngine.GetEngineName(), MyBaseThing.ID); if (tT != null) { TheThingRegistry.UnmapPropertyMapper(mRealThingGuid); TheThingRegistry.DeleteThing(tT); } }); }
public virtual bool Init(bool declareInit) { if (mIsInitCalled) { return(false); } mIsInitCalled = true; IsConnected = false; MyBaseThing.StatusLevel = 0; MyBaseThing.LastMessage = "Service is ready"; MyBaseThing.RegisterStatusChanged(sinkUpdateUX); MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); if (string.IsNullOrEmpty(MyBaseThing.ID)) { MyBaseThing.ID = Guid.NewGuid().ToString(); TheThing.SetSafePropertyBool(MyBaseThing, "IsStateSensor", true); TheThing.SetSafePropertyString(MyBaseThing, "StateSensorType", "analog"); TheThing.SetSafePropertyString(MyBaseThing, "StateSensorUnit", "ms"); TheThing.SetSafePropertyNumber(MyBaseThing, "StateSensorMaxValue", 100); TheThing.SetSafePropertyNumber(MyBaseThing, "StateSensorAverage", 50); TheThing.SetSafePropertyNumber(MyBaseThing, "StateSensorMinValue", 0); //TheThing.SetSafePropertyString(MyBaseThing, "StateSensorName", MyBaseThing.FriendlyName); TheRulesFactory.CreateOrUpdateRule(new TheThingRule(Guid.NewGuid(), "NetService:" + MyBaseThing.FriendlyName + " Failed", MyBaseThing, "StatusLevel", eRuleTrigger.Larger, "1", true, true)); } if (declareInit) { mIsInitialized = true; } return(true); }
public override bool DoCreateUX() { TheThing.SetSafePropertyString(MyBaseThing, "StateSensorIcon", "/Images/iconToplogo.png"); var res = base.DoCreateUX(); var ValueFld = TheNMIEngine.GetFieldByFldOrder(base.MyStatusForm, 15); ValueFld.Type = eFieldType.SingleEnded; TheNMIEngine.DeleteFieldsByRange(base.MyStatusForm, 14, 14); TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.DateTime, 14, 0, 0, "###Last Update###", "SourceTimeStamp", new nmiCtrlDateTime() { ParentFld = 10 }); SummaryForm.PropertyBag = new nmiDashboardTile() { Category = "..", Caption = "hhh" }; TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.SingleCheck, 523, 2, 128, "Array 2 Properties", "StoreArrayInProperties", new nmiCtrlDateTime() { ParentFld = 500 }); return(res); }
public override string ProcessEventData(TheThing thing, object evnt, DateTimeOffset defaultTimestamp) { if (!(evnt is EventData)) { return "Invalid Payload"; } if (thing == null) { return "AMQP Converter does not support thing mapping"; } var eventData = evnt as EventData; DateTimeOffset time; if (eventData.Properties.ContainsKey("time")) { time = TheCommonUtils.CDate(eventData.Properties["time"]); } else if (defaultTimestamp == DateTimeOffset.MinValue) { time = eventData.SystemProperties.EnqueuedTimeUtc; } else { time = defaultTimestamp; } foreach (var prop in eventData.Properties) { var tProp = thing.SetProperty(prop.Key, prop.Value, time); //var tProp = thing.GetProperty(prop.Key, true); //tProp.cdeCTIM = time; //tProp.Value = prop.Value; //tProp.cdeE = 0x40; // NMI visible } return null; }
public override bool CreateUX() { if (!mIsUXInitCalled) { mIsUXInitCalled = true; mMyDashboard = TheNMIEngine.AddDashboard(MyBaseThing, new TheDashboardInfo(MyBaseEngine, "###Image Service###") { PropertyBag = new nmiDashboard { Category = "###Services###", Caption = "<i class='fa faIcon fa-5x'></i></br>###Image Service###" } }); var tFlds = TheNMIEngine.CreateEngineForms(MyBaseThing, TheThing.GetSafeThingGuid(MyBaseThing, "MYNAME"), "###My Images###", null, 20, 0x0F, 0xF0, TheNMIEngine.GetNodeForCategory(), "REFFRESHME", false, new eImageTypes(), eImageTypes.Bitmap); TheFormInfo tForm = tFlds["Form"] as TheFormInfo; TheNMIEngine.AddSmartControl(MyBaseThing, tForm, eFieldType.Picture, 5, 0, 0, "###Current Image###", "CurrentImage", new nmiCtrlPicture { FldWidth = 1, TileHeight = 1 }); var tMyForm2 = TheNMIEngine.AddStandardForm(MyBaseThing, "###New Image Uploader###", 6, "ImageUp", null, 0xC0); TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm2["Form"] as TheFormInfo, eFieldType.DropUploader, 3, 2, 0, "###Drop an image-file here###", null, new nmiCtrlDropUploader { TileHeight = 6, ParentFld = 1, NoTE = true, TileWidth = 6, EngineName = MyBaseEngine.GetEngineName(), MaxFileSize = 5000000 }); mIsUXInitialized = true; } return(true); }
public override bool Init() { if (!mIsInitStarted) { mIsInitStarted = true; MyBaseEngine.RegisterEvent(eEngineEvents.ShutdownEvent, OnShutdown); TheThing.SetSafePropertyBool(MyBaseThing, "IsConnected", false); IBaseEngine tBase = TheThingRegistry.GetBaseEngine(TheThing.GetSafePropertyString(MyBaseThing, "ISOLaterName"), true); if (tBase != null) { MyIsolator = tBase.GetISOLater() as Process; if (MyIsolator == null) { MyBaseThing.LastMessage = "Engine not isolated"; MyBaseThing.StatusLevel = 3; mIsInitCompleted = true; return(true); } MyBaseThing.LastMessage = "KPIs monitor ready"; MyBaseThing.StatusLevel = 1; if (TheThing.GetSafePropertyBool(MyBaseThing, "AutoConnect")) { Connect(); } } else { MyBaseThing.LastMessage = "Base Engine cloud not be located"; MyBaseThing.StatusLevel = 3; } mIsInitCompleted = true; } return(true); }
internal static Dictionary <string, object> GetDictionary() { TheThing tn = new TheThing(); ToThingProperties(tn, !TheCommonUtils.CBool(TheBaseAssets.MySettings.GetSetting("EnableKPIs"))); return(tn.GetPBAsDictionary()); }
public TheVTimer(TheThing pThing, IBaseEngine pEngine) : base(pThing) { if (pThing != null) { MyBaseThing = pThing; } else { MyBaseThing = new TheThing(); } cdeP tfirstTrigger = MyBaseThing.DeclareNMIProperty("MsToTrigger", ePropertyTypes.TNumber); tfirstTrigger.RegisterEvent(eThingEvents.PropertySet, sinkLoopChanged); cdeP tLoop = MyBaseThing.DeclareNMIProperty("LoopPeriod", ePropertyTypes.TNumber); tLoop.RegisterEvent(eThingEvents.PropertySet, sinkLoopChanged); cdeP tTrigger = MyBaseThing.DeclareNMIProperty("TriggerTimer", ePropertyTypes.TString); tTrigger.RegisterEvent(eThingEvents.PropertySet, sinkTriggered); MyBaseEngine = pEngine; MyBaseThing.DeviceType = eVThings.eVTimer; MyBaseThing.EngineName = pEngine.GetEngineName(); MyBaseThing.SetIThingObject(this); }
public void TestFooBarRunner() { var writer = new StringWriter(); Console.SetOut(writer); new FooBarRunner(1, 20, 1).ApplyRules( 1. Output("ab").If(TheThing.IsDivisibleBy(2).And(TheThing.IsDivisibleBy(3))), 2. Output("a").If(TheThing.IsDivisibleBy(2)), 3. Output("b").If(TheThing.IsDivisibleBy(3)) ); string result = @"1 a b a 5 ab 7 a b a 11 ab 13 a b a 17 ab 19 a "; Assert.AreEqual(writer.ToString(), result); }
private void sinkLoopChanged(cdeP pProp) { int tTime = TheCommonUtils.CInt(TheThing.GetSafePropertyNumber(this, "MsToTrigger")); //if (tTime > 0) { int tPeriod = TheCommonUtils.CInt(TheThing.GetSafePropertyNumber(this, "LoopPeriod")); if (tPeriod == 0) { tPeriod = -1; } if (tPeriod > 0 && tPeriod < 10) { tPeriod = 10; } MyBaseThing.Value = "0"; if (mTimer != null) { mTimer.Change(tTime, tPeriod); } else { mTimer = new Timer(sinkTriggerTimeout, null, tTime, tPeriod); } IsActive = true; MyBaseThing.StatusLevel = 1; MyBaseThing.LastMessage = $"Timer started at {DateTimeOffset.Now}"; SummaryForm?.SetUXProperty(Guid.Empty, string.Format("Background=green")); } }
public void AddSpeedGauge(TheFormInfo tMyForm, int pFldNumber = 25000, int pParentFld = TheDefaultSensor.SensorGaugeGroup, bool IsHighGood = false) { string Plotband = ""; if (IsHighGood) { Plotband = $"PlotBand=[{{ \"from\": {TheThing.GetSafePropertyNumber(MyBaseThing, "StateSensorMinValue")}, \"to\": {TheThing.GetSafePropertyNumber(MyBaseThing, "StateSensorAverage")}, \"color\": \"#FF000088\" }}, {{ \"from\": {TheThing.GetSafePropertyNumber(MyBaseThing, "StateSensorAverage")}, \"to\": {TheThing.GetSafePropertyNumber(MyBaseThing, "StateSensorMaxValue")}, \"color\": \"#00FF0044\" }}]"; } else { Plotband = $"PlotBand=[{{ \"from\": {TheThing.GetSafePropertyNumber(MyBaseThing, "StateSensorMinValue")}, \"to\": {TheThing.GetSafePropertyNumber(MyBaseThing, "StateSensorAverage")}, \"color\": \"#00FF0088\" }}, {{ \"from\": {TheThing.GetSafePropertyNumber(MyBaseThing, "StateSensorAverage")}, \"to\": {TheThing.GetSafePropertyNumber(MyBaseThing, "StateSensorMaxValue")}, \"color\": \"#FF000044\" }}]"; } GaugeFld = TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.UserControl, pFldNumber, 0, 0, null, "QValue", new ThePropertyBag() { "ControlType=Speed Gauge", "NoTE=true", $"ParentFld={pParentFld}", "TileWidth=6", "TileHeight=3", $"MinValue={TheThing.GetSafePropertyNumber(MyBaseThing,"StateSensorMinValue")}", $"MaxValue={TheThing.GetSafePropertyNumber(MyBaseThing,"StateSensorMaxValue")}", $"SubTitle={TheThing.GetSafePropertyString(MyBaseThing, "StateSensorUnit")}", Plotband, $"SetSeries={{ \"name\": \"{TheThing.GetSafePropertyString(MyBaseThing, "StateSensorValueName")}\",\"data\": [{TheThing.GetSafePropertyNumber(MyBaseThing,"QValue")}],\"tooltip\": {{ \"valueSuffix\": \" {TheThing.GetSafePropertyString(MyBaseThing, "StateSensorUnit")}\"}}}}", $"Value={MyBaseThing.Value}" }); }
void sinkThingWasUpdated(ICDEThing sender, object pPara) { if (TheBaseAssets.MyServiceHostInfo.IsCloudService) { return; //TODO: Allow Cloud Rules } TheThing pThing = sender as TheThing; if (pThing != null && TheThing.GetSafePropertyString(pThing, "DeviceType") == eKnownDeviceTypes.TheThingRule) { TheRule tRule = pThing.GetObject() as TheRule; if (tRule == null) { tRule = new TheRule(pThing, this); tRule.RegisterEvent(eEngineEvents.ThingUpdated, sinkUpdated); RegisterRule(tRule); } { tRule.IsRuleWaiting = true; tRule.IsRuleRunning = false; TheSystemMessageLog.WriteLog(4445, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM(eKnownDeviceTypes.TheThingRule, $"Rule {tRule.FriendlyName} stopped on Rule Update"), false); TheThingRegistry.UpdateThing(tRule, false); } ActivateRules(); } }
public string OpenModBus() { if (MyModMaster != null && tcpClient != null && tcpClient.Connected) { return(null); } string error = null; try { CloseModBus(); tcpClient = new TcpClient(); int port = (int)TheThing.GetSafePropertyNumber(MyBaseThing, "CustomPort"); if (port == 0) { port = 502; //MOdbus default Port TheThing.SetSafePropertyNumber(MyBaseThing, "CustomPort", port); } tcpClient.Connect(IPAddress.Parse(MyBaseThing.Address), port); MyModMaster = ModbusIpMaster.CreateIp(tcpClient); } catch (SocketException e) { error = e.Message; CloseModBus(); } return(error); }
void SendRuleTSM(bool serviceOnly) { string engine = TheCommonUtils.CStr(GetProperty("TSMEngine", false)); string text = TheCommonUtils.CStr(GetProperty("TSMText", false)); string payload = TheCommonUtils.CStr(GetProperty("TSMPayload", false)); //payload = payload.Replace("%DTO%", TheCommonUtils.CStr(DateTimeOffset.Now)); //text = text.Replace("%DTO%", TheCommonUtils.CStr(DateTimeOffset.Now)); ICDEThing triggerThing = TheThingRegistry.GetThingByMID("*", TheCommonUtils.CGuid(TriggerObject)) as ICDEThing; string escPayload = TheCommonUtils.GenerateFinalStr(payload, triggerThing); escPayload = TheCommonUtils.GenerateFinalStr(escPayload, MyBaseThing); string escText = TheCommonUtils.GenerateFinalStr(text, triggerThing); escText = TheCommonUtils.GenerateFinalStr(escText, MyBaseThing); if (!string.IsNullOrEmpty(engine) && !string.IsNullOrEmpty(text)) { TSM customTSM = new TSM(engine, escText, escPayload); if (serviceOnly) { customTSM.SetToServiceOnly(true); } TheCommCore.PublishCentral(customTSM, true); } if (IsRuleLogged) { LogEvent(escPayload); } if (TheThing.GetSafePropertyBool(MyBaseThing, "IsEVTLogged")) { TheLoggerFactory.LogEvent(eLoggerCategory.RuleEvent, TheCommonUtils.GenerateFinalStr(MyBaseThing.FriendlyName, MyBaseThing), eMsgLevel.l4_Message, TheBaseAssets.MyServiceHostInfo.GetPrimaryStationURL(false), escText, escPayload); } }
private void SetCtrlType() { if (CountBar == null) { return; } string tControl = ThePropertyBag.PropBagGetValue(CountBar.PropertyBag, "ControlType", "="); eFieldType tCtrlType = eFieldType.SingleEnded; if (!string.IsNullOrEmpty(tControl) && TheCommonUtils.CInt(tControl) == 0 && tControl.Length > 0) { TheControlType tType = TheNMIEngine.GetControlTypeByType(tControl); if (tType != null) { ThePropertyBag.PropBagUpdateValue(CountBar.PropertyBag, "EngineName", "=", tType.BaseEngineName); } tCtrlType = eFieldType.UserControl; } else { tCtrlType = (eFieldType)TheCommonUtils.CInt(tControl); } CountBar.Type = tCtrlType; CountBar.Flags = TheCommonUtils.CInt(ThePropertyBag.PropBagGetValue(CountBar.PropertyBag, "Flags", "=")); CountBar.PropertyBag = new TheNMIBaseControl { ParentFld = 1 }; CountBar.UpdateUXProperties(Guid.Empty); CountBar.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "click", (sener, para) => { TheThing.SetSafePropertyBool(MyBaseThing, "ClickState", !TheThing.GetSafePropertyBool(MyBaseThing, "ClickState")); }); }
T CreateOrUpdateService <T>(TheThing tDevice, bool bRegisterThing) where T : TheLoggerBase { T tServer; if (tDevice == null || !tDevice.HasLiveObject) { tServer = (T)Activator.CreateInstance(typeof(T), tDevice, this); if (bRegisterThing) { TheThingRegistry.RegisterThing((ICDEThing)tServer); } } else { tServer = tDevice.GetObject() as T; if (tServer != null) { tServer.Connect(null); //Expose a Connect(TheProcessMessage) method on TheThing } else { tServer = (T)Activator.CreateInstance(typeof(T), tDevice, this); } } return(tServer); }
public override bool CreateUX() { if (mIsUXInitCalled) { return(false); } mIsUXInitCalled = true; if (!TheBaseAssets.MyServiceHostInfo.IsCloudService) { MyDash = TheNMIEngine.AddDashboard(MyBaseThing, new TheDashboardInfo(MyBaseEngine, "Messaging") { PropertyBag = new ThePropertyBag() { "Category=Services", "Caption=Messaging", "Thumbnail=FA5:f658" } }); var tFlds = TheNMIEngine.CreateEngineForms(MyBaseThing, TheThing.GetSafeThingGuid(MyBaseThing, "MSGT"), "Messaging Targets", null, 0, 0x0F, 0xF0, TheNMIEngine.GetNodeForCategory(), "REFFRESHME", false, $"{eMessageTypes.EMAIL}", eMessageTypes.EMAIL); //;{eMessageTypes.SMS} not ready - needs carrier servername+port+ssl TheFormInfo tForm = tFlds["Form"] as TheFormInfo; tForm.IsReadOnly = false; tForm.AddButtonText = "Add a new Messaging Target"; (tFlds["Name"] as TheFieldInfo).Header = "Target Name"; (tFlds["DashIcon"] as TheDashPanelInfo).PanelTitle = "Messaging Targets"; TheNMIEngine.AddSmartControl(MyBaseThing, tForm, eFieldType.SingleEnded, 50, 2, 0, "Recipient", "Recipient", null).FldWidth = 3; } mIsUXInitialized = true; return(true); }
public TheLoggerBase(TheThing tBaseThing, ICDEPlugin pPluginBase) { MyBaseThing = tBaseThing ?? new TheThing(); MyBaseEngine = pPluginBase.GetBaseEngine(); MyBaseThing.EngineName = MyBaseEngine.GetEngineName(); MyBaseThing.SetIThingObject(this); }
private void OnDownloadClick(ICDEThing pThing, object pPara) { TheProcessMessage pMSG = pPara as TheProcessMessage; if (pMSG == null || pMSG.Message == null) { return; } string[] cmd = pMSG.Message.PLS.Split(':'); if (cmd.Length > 2) { TheThing tThing = TheThingRegistry.GetThingByMID("*", TheCommonUtils.CGuid(cmd[2]), true); if (tThing == null) { return; } TSM tFilePush = new TSM(eEngineName.ContentService, string.Format("CDE_FILE:{0}.JSON:application/zip", tThing.FriendlyName)) { SID = pMSG.Message.SID, PLS = "bin", PLB = TheCommonUtils.CUTF8String2Array(TheCommonUtils.SerializeObjectToJSONString(tThing)) }; TheCommCore.PublishToOriginator(pMSG.Message, tFilePush); } }
private void UpdateUx(TheThing pThing) { ThePropertyBag.MergeUXBagFromProperties(MySampleControl?.PropertyBag, pThing); SetCtrlType(); TheThingRegistry.UnmapPropertyMapper(MapperGuid); if (!string.IsNullOrEmpty(pThing.Address)) { MapperGuid = TheThingRegistry.PropertyMapper(TheCommonUtils.CGuid(pThing.Address), TheThing.GetSafePropertyString(pThing, "SourceProp"), pThing.cdeMID, "Value", true); if (MapperGuid != Guid.Empty) { pThing.StatusLevel = 1; pThing.LastMessage = "Mapper engaged"; } else { pThing.StatusLevel = 2; pThing.LastMessage = "Mapper failed to engaged"; } } else { pThing.StatusLevel = 0; pThing.LastMessage = "Mapper not engaged"; } }
public bool CreateUX() { if (mIsUXInitCalled) { return(false); } mIsUXInitCalled = true; //NUI Definition for All clients mMyDashboard = TheNMIEngine.AddDashboard(MyBaseThing, new TheDashboardInfo(MyBaseEngine, "<i class='cl-font cl-Logo fa-5x'></i><br>Mesh Receiver") { PropertyBag = new ThePropertyBag() { "Category=Connectors" } }); TheFormInfo tAllCloudConnections = new TheFormInfo(MyBaseEngine) { cdeMID = TheThing.GetSafeThingGuid(MyBaseThing, "MeshR"), defDataSource = string.Format("TheThing;:;0;:;True;:;EngineName={0}", MyBaseEngine.GetEngineName()), FormTitle = "Mesh Receiver Connections", AddButtonText = "Add a Connection" }; TheNMIEngine.AddFormToThingUX(MyBaseThing, tAllCloudConnections, "CMyTable", "Mesh Receivers", 1, 0x0D, 0xC0, TheNMIEngine.GetNodeForCategory(), null, new ThePropertyBag() { "Thumbnail=MicrosoftAzure.png;0.5" }); TheNMIEngine.AddCommonTableColumns(MyBaseThing, tAllCloudConnections, MeshDeviceTypes.GetValues(), MeshDeviceTypes.MeshReceiver, false, true); TheNMIEngine.AddField(tAllCloudConnections, new TheFieldInfo() { FldOrder = 5, cdeA = 0xC0, Flags = 6, Type = eFieldType.SingleCheck, FldWidth = 1, Header = "Auto-Connect", DataItem = "MyPropertyBag.AutoConnect.Value" }); TheNMIEngine.AddField(tAllCloudConnections, new TheFieldInfo() { FldOrder = 6, cdeA = 0xC0, Flags = 0, Type = eFieldType.SingleCheck, FldWidth = 1, Header = "Is Connected", DataItem = "MyPropertyBag.IsConnected.Value", PropertyBag = new nmiCtrlSingleCheck { AreYouSure = "Are you sure you want to connect/disconnect?" } }); TheNMIEngine.AddField(tAllCloudConnections, new TheFieldInfo() { FldOrder = 7, cdeA = 0xC0, Flags = 0, Type = eFieldType.SingleCheck, FldWidth = 1, Header = "Connecting", DataItem = "MyPropertyBag.Connecting.Value" }); TheNMIEngine.AddField(tAllCloudConnections, new TheFieldInfo() { FldOrder = 8, cdeA = 0xC0, Flags = 0, Type = eFieldType.SingleCheck, FldWidth = 1, Header = "Disconnecting", DataItem = "MyPropertyBag.Disconnecting.Value" }); TheNMIEngine.AddField(tAllCloudConnections, new TheFieldInfo() { FldOrder = 50, cdeA = 0xFF, Type = eFieldType.DateTime, FldWidth = 2, Header = "Last Update", DataItem = "MyPropertyBag.LastUpdate.Value" }); TheThingRegistry.UpdateEngineUX(MyBaseEngine.GetEngineName()); TheNMIEngine.AddAboutButton(MyBaseThing, true, "REFRESH_DASH", 0xc0); TheNMIEngine.RegisterEngine(MyBaseEngine); mIsUXInitialized = true; return(true); }