public override bool Init() { if (!mIsInitStarted) { mIsInitStarted = true; MyBaseThing.StatusLevel = 4; MyBaseThing.LastMessage = "Logger Service has started"; MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); MyBaseEngine.RegisterEvent(eEngineEvents.ThingDeleted, OnThingDeleted); cdeP tP = null; if (TheBaseAssets.MyServiceHostInfo.DisableConsole) { TheThing.SetSafePropertyBool(MyBaseThing, "DisableStandardLog", TheBaseAssets.MyServiceHostInfo.DisableConsole); } else { tP = GetProperty("DisableStandardLog", true); } tP.RegisterEvent(eThingEvents.PropertyChanged, sinkDisableChanged); if (TheCommonUtils.CBool(tP.ToString())) { TheBaseAssets.MyServiceHostInfo.DisableConsole = true; } if (TheBaseAssets.MyServiceHostInfo.UseGELFLoggingFormat) { tP = TheThing.SetSafePropertyBool(MyBaseThing, "UseGELF", TheBaseAssets.MyServiceHostInfo.UseGELFLoggingFormat); } else { tP = GetProperty("UseGELF", true); } tP.RegisterEvent(eThingEvents.PropertyChanged, sinkGELF); if (TheCommonUtils.CBool(tP.ToString())) { TheBaseAssets.MyServiceHostInfo.UseGELFLoggingFormat = true; } bool DoLogKPIs = TheCommonUtils.CBool(TheBaseAssets.MySettings.GetSetting("LogKPIs")); if (DoLogKPIs) { TheThing.SetSafePropertyBool(MyBaseThing, "LogKPIs", true); } TheQueuedSenderRegistry.RegisterHealthTimer(sinkTimer); // If not lengthy initialized you can remove cdeRunasync and call this synchronously TheCommonUtils.cdeRunAsync(MyBaseEngine.GetEngineName() + " Init Services", true, (o) => { // Perform any long-running initialization (i.e. network access, file access) here InitServices(); MyBaseEngine.ProcessInitialized(); //Set the status of the Base Engine according to the status of the Things it manages mIsInitCompleted = true; }); } return(false); }
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 override bool DoInit() { base.DoInit(); IsActive = false; TheThing.SetSafePropertyBool(MyBaseThing, "IsStateSensor", true); MyBaseThing.StatusLevel = 4; if (string.IsNullOrEmpty(MyBaseThing.ID)) { MyBaseThing.ID = Guid.NewGuid().ToString(); TheThing.SetSafePropertyString(MyBaseThing, "StateSensorType", "analog"); TheThing.SetSafePropertyString(MyBaseThing, "StateSensorUnit", "units"); TheThing.SetSafePropertyNumber(MyBaseThing, "StateSensorMaxValue", 100); TheThing.SetSafePropertyNumber(MyBaseThing, "StateSensorAverage", 50); TheThing.SetSafePropertyNumber(MyBaseThing, "StateSensorMinValue", 0); TheThing.SetSafePropertyNumber(MyBaseThing, "Interval", 500); } TheThing.SetSafePropertyString(MyBaseThing, "StateSensorIcon", "/P066/Images/iconVThingsRest.png"); GetProperty("FriendlyName", true).RegisterEvent(eThingEvents.PropertyChanged, sinkNameChanged); cdeP tRW = GetProperty("RawValue", true); tRW.RegisterEvent(eThingEvents.PropertyChanged, sinkPrePro); cdeP.SetSafePropertyBool(tRW, "IsStateSensor", true); cdeP.SetSafePropertyString(tRW, "StateSensorType", "analog"); cdeP.SetSafePropertyString(tRW, "StateSensorUnit", "°F"); cdeP.SetSafePropertyNumber(tRW, "StateSensorMaxValue", 100); cdeP.SetSafePropertyNumber(tRW, "StateSensorAverage", 50); cdeP.SetSafePropertyNumber(tRW, "StateSensorMinValue", 0); if (!string.IsNullOrEmpty(TheThing.GetSafePropertyString(MyBaseThing, "RealSensorThing")) && !string.IsNullOrEmpty(TheThing.GetSafePropertyString(MyBaseThing, "RealSensorProperty"))) { EngageMapper(); } GetProperty("IsGlobal", true).RegisterEvent(eThingEvents.PropertyChanged, (p) => { if (TheCommonUtils.CBool(p.ToString())) { TheThingRegistry.RegisterThingGlobally(MyBaseThing); } else { TheThingRegistry.UnregisterThingGlobally(MyBaseThing); } }); GetProperty("Interval", true).RegisterEvent(eThingEvents.PropertyChanged, (p) => { changeInterval(TheCommonUtils.CInt(p.ToString())); }); MyBaseThing.SetPublishThrottle((int)TheThing.GetSafePropertyNumber(MyBaseThing, "Interval")); //TheQueuedSenderRegistry.RegisterHealthTimer(checkMapperHealth); return(true); }
public override bool DoInit() { if (MyBaseThing.StatusLevel != 1) { MyBaseThing.LastMessage = "Tag Ready"; MyBaseThing.StatusLevel = 0; } cdeP Mon = MyBaseThing.GetProperty("DontMonitor", true); Mon.RegisterEvent(eThingEvents.PropertyChanged, sinkPChanged); MyBaseThing.RegisterEvent(eThingEvents.PropertyChanged, sinkUXUpdatedThing); MyBaseThing.RegisterEvent(eThingEvents.ValueChanged, sinkRulesUpdatedThing); return(true); }
/// <summary> /// Initializes the Live Tag /// </summary> /// <returns></returns> public override bool Init() { if (mIsInitCalled) { return(false); } mIsInitCalled = true; TheThing.SetSafePropertyBool(MyBaseThing, "IsLiveTag", true); MyBaseThing.FireEvent("OnInitialized", this, new TSM(MyBaseThing.cdeMID.ToString(), "Was Init"), false); cdeP tThrot = GetProperty("Throttle", true); tThrot.RegisterEvent(eThingEvents.PropertyChanged, sinkThrottleChanged); mIsInitialized = DoInit(); if (string.IsNullOrEmpty(MyBaseThing.ID)) { MyBaseThing.ID = Guid.NewGuid().ToString(); } return(mIsInitialized); }
/// <summary> /// The possible types of WeMo devices that can be detected /// </summary> #endregion public bool Init() { if (mIsInitCalled) { return(false); } mIsInitCalled = true; MyBaseThing.EngineName = eEngineName.NMIService; MyBaseThing.DeviceType = "NMI Editor"; TheThing.SetSafePropertyBool(MyBaseThing, "IsLiveTag", true); MyBaseThing.FireEvent("OnInitialized", this, new TSM(MyBaseThing.cdeMID.ToString(), "Was Init"), false); cdeP tThrot = GetProperty("Throttle", true); tThrot.RegisterEvent(eThingEvents.PropertyChanged, sinkThrottleChanged); mIsInitialized = DoInit(); //we have to follow your design to have mIsINitialzed called at the end. This can lead to problems for live tags if (string.IsNullOrEmpty(MyBaseThing.ID)) { MyBaseThing.ID = Guid.NewGuid().ToString(); } return(mIsInitialized); }
public bool ActivateRules() { if (TheCDEngines.MyThingEngine == null || TheBaseAssets.MyServiceHostInfo.IsCloudService || TheCommonUtils.cdeIsLocked(LockRules) || !mIsInitialized) { return(false); } lock (LockRules) { if (mIsInitialized) { InitRules(); } //List<TheRule> tList = MyRulesStore.MyMirrorCache.GetEntriesByFunc(s => s.IsRuleActive && !s.IsRuleRunning && s.IsRuleWaiting); List <TheThing> tList = TheThingRegistry.GetThingsByFunc("*", s => TheThing.GetSafePropertyString(s, "Parent").Equals(MyBaseThing.ID) && //TheBaseAssets.MyServiceHostInfo.MyDeviceInfo.DeviceID) && TheThing.GetSafePropertyBool(s, "IsRuleActive") && !TheThing.GetSafePropertyBool(s, "IsRuleRunning") && TheThing.GetSafePropertyBool(s, "IsRuleWaiting")); if (tList != null && tList.Count > 0) { foreach (TheThing tThing in tList) { TheRule tRule = tThing.GetObject() as TheRule; if (tRule == null) { continue; } if (string.IsNullOrEmpty(tRule.TriggerProperty)) { tRule.IsIllegal = true; tRule.IsRuleWaiting = false; continue; } if (tRule.TriggerStartTime > DateTimeOffset.Now) { continue; } if (tRule.TriggerEndTime < DateTimeOffset.Now) { RemoveTrigger(tRule, false); continue; } switch (tRule.TriggerObjectType) { case "CDE_ENGINE": TheThing tBase = TheThingRegistry.GetBaseEngineAsThing(tRule.TriggerObject); if (tBase != null) { tBase.RegisterEvent(eEngineEvents.IncomingMessage, sinkRuleIncoming); tRule.IsRuleWaiting = false; tRule.IsRuleRunning = true; tRule.IsTriggerObjectAlive = true; TheSystemMessageLog.WriteLog(4445, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM(eKnownDeviceTypes.TheThingRule, $"Rule {tRule.FriendlyName} started with TriggerType: {tRule.TriggerObjectType}"), false); } break; case "CDE_EVENTFIRED": TheThing tBaseE = TheThingRegistry.GetBaseEngineAsThing(tRule.TriggerObject); if (tBaseE != null) { tBaseE.RegisterEvent(tRule.TriggerProperty, sinkRuleThingEvent); tRule.IsRuleWaiting = false; tRule.IsRuleRunning = true; tRule.IsTriggerObjectAlive = true; TheSystemMessageLog.WriteLog(4445, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM(eKnownDeviceTypes.TheThingRule, $"Rule {tRule.FriendlyName} started with TriggerType: {tRule.TriggerObjectType}"), false); } break; default: TheThing tTriggerThing = TheThingRegistry.GetThingByMID("*", TheCommonUtils.CGuid(tRule.TriggerObject)); if (tTriggerThing != null) { //if (tTriggerThing.GetObject() == null) continue; //TODO: Verify if this can stay removed //if (tTriggerThing.GetProperty("FriendlyName").Value.ToString().Contains("Motion")) continue; cdeP tProp = tTriggerThing.GetProperty(tRule.TriggerProperty, true); if (tProp != null) { tProp.UnregisterEvent(eThingEvents.PropertyChanged, sinkRuleAction); tProp.RegisterEvent(eThingEvents.PropertyChanged, sinkRuleAction); } tRule.IsRuleWaiting = false; tRule.IsRuleRunning = true; tRule.IsTriggerObjectAlive = true; tRule.RuleTrigger(tProp.ToString(), true); TheSystemMessageLog.WriteLog(4445, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM(eKnownDeviceTypes.TheThingRule, $"Rule {tRule.FriendlyName} started with TriggerType: {tRule.TriggerObjectType}"), false); } break; } } } } return(true); }