public bool Init() { if (!mIsInitStarted) { mIsInitStarted = true; MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); /// Note: Where this sample is interesting is when one (or both) /// of the following flags are defined on the command line of /// the application host: /// -- CDMyWebToMeshSample_EnableREST=true -- Enable REST Server Support. /// -- CDMyWebToMeshSample_EnableMeshDataQuery -- Whether to send TSM messages out for data query. g_EnableRESTServer = utils.CheckCommandLineFlag("CDMyWebToMeshSample_EnableREST"); g_EnableMeshDataQuery = utils.CheckCommandLineFlag("CDMyWebToMeshSample_EnableMeshDataQuery"); g_EnableMeshDataResponse = utils.CheckCommandLineFlag("CDMyWebToMeshSample_EnableMeshDataResponse"); // Initialize http handler for REST handling. if (g_EnableRESTServer) { RegisterHttpInterceptor(); } MyBaseThing.StatusLevel = 1; MyBaseThing.LastMessage = "Mile Record Holder service has started."; mIsInitCompleted = true; MyBaseEngine.ProcessInitialized(); } return(true); }
public virtual bool Init() { if (mIsInitCalled) { return(false); } mIsInitCalled = true; IsStarted = false; if (string.IsNullOrEmpty(MyBaseThing.ID)) { MyBaseThing.ID = Guid.NewGuid().ToString(); } if (MyBaseThing.GetProperty(nameof(PlaybackSpeedFactor), false) == null) { PlaybackSpeedFactor = 1; } if (MyBaseThing.GetProperty(nameof(InputFileName), false) == null) { InputFileName = "meshsenderdata.log"; } if (MyBaseThing.GetProperty(nameof(ParallelPlaybackCount), false) == null) { ParallelPlaybackCount = 1; } MyBaseThing.RegisterOnChange(nameof(ParallelPlaybackCount), (o) => { if (IsStarted) { StopPlaybackAsync("Changed number of things").ContinueWith(t => StartPlaybackAsync(false)); } }); MyBaseThing.Value = "0"; IsActive = true; MyBaseThing.StatusLevel = 0; if (AutoStart) { TheCommonUtils.cdeRunAsync("DataPLayerAutostart", true, async o => { //if (AutoStartDelay > 0) //{ // await TheCommonUtils.TaskDelayOneEye(AutoStartDelay, 100); //} await StartPlaybackAsync(true); }); } MyBaseThing.RegisterEvent(eEngineEvents.FileReceived, sinkFileReceived); mIsInitialized = true; return(true); }
//List<ScriptSnapshot> MyScriptTableList; //Dictionary<string, Guid> SnapShotGuids; public bool Init() { if (!mIsInitStarted) { mIsInitStarted = true; MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); mIsInitCompleted = true; MyBaseEngine.ProcessInitialized(); MyBaseThing.SetStatus(4, "Waiting for other services before running scripts"); TheBaseEngine.WaitForEnginesStarted(OnEnginesStarted); SetupStorageMirror(); } return(true); }
public bool Init() { if (mIsInitCalled) { return(false); } mIsInitCalled = true; //MyBaseThing.RegisterEvent(eEngineEvents.NewChannelActive, ChannelHasStarted); //MyBaseThing.RegisterEvent(eEngineEvents.ChannelIsUpAgain, ChannelHasStarted); MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); mIsInitialized = true; return(true); }
internal void CheckOnHealthTimer(long tTimerVal) { if (mDisableCollection) { return; } if ((tTimerVal % HealthUpdateCycle) != 0) { return; } if (TheCommonUtils.cdeIsLocked(lockCheckTimer)) { return; } lock (lockCheckTimer) { if (!AreCounterInit) { return; } TheBaseAssets.MySYSLOG.WriteToLog(8005, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("jcHealth", "Enter CheckOnHealthTimer", eMsgLevel.l7_HostDebugMessage)); TheDiagnostics.SetThreadName("C-MyComputer-HealthTimer", true); if (!IsEnergyRegistered) { TheThing tThing = TheThingRegistry.GetBaseEngineAsThing("CDMyEnergy.TheCDMyEnergyEngine"); if (tThing != null) { IsEnergyRegistered = true; tThing.RegisterEvent(eEngineEvents.MessageProcessed, sinkEnergyFound); } } SendHealthInfo(Guid.Empty); if (MyServiceHealthDataStore != null) { TheBaseAssets.MySYSLOG.WriteToLog(8006, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("jcHealth", "Storing HealthInfo", eMsgLevel.l7_HostDebugMessage, MyHealthData.cdeUptime.ToString())); if (!MyServiceHealthDataStore.IsReady) { MyServiceHealthDataStore.InitializeStore(false); TheBaseAssets.MySYSLOG.WriteToLog(8006, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("jcHealth", "Storing HealthInfo- Initializing store", eMsgLevel.l4_Message)); } MyServiceHealthDataStore.AddAnItem(TheThingStore.CloneFromTheThing(MyHealthData, true)); } TheBaseAssets.MySYSLOG.WriteToLog(8006, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("jcHealth", "Leave CheckOnHealthTimer", eMsgLevel.l7_HostDebugMessage)); } }
public bool Init() { if (!mIsInitStarted) { mIsInitStarted = true; MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); // Initialize http interceptor for REST handling. RegisterHttpInterceptor(); MyBaseThing.StatusLevel = 1; MyBaseThing.LastMessage = "Mile Record Holder service has started."; mIsInitCompleted = true; MyBaseEngine.ProcessInitialized(); } return(true); }
public bool Init() { if (!mIsInitStarted) { mIsInitStarted = true; MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); // Additional initialization processing goes here // Initialize handler for /ThingAPI REST handling. RegisterHttpInterceptor(); MyBaseThing.StatusLevel = 1; MyBaseThing.LastMessage = "Hello World service has started."; mIsInitCompleted = true; MyBaseEngine.ProcessInitialized(); } return(true); }
public bool Init() { if (mIsInitCalled) { return(false); } mIsInitCalled = true; MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); if (TheThing.GetSafePropertyString(MyBaseThing, "VisitorCount") == "") { VisitorCount = 0; } MyNodePrintsName = $"NodePrints{TheThing.GetSafeThingGuid(MyBaseThing, "NodePrints")}"; TheBaseEngine.WaitForStorageReadiness(OnStorageReady, true); MyBaseThing.SetPublishThrottle(15000); TheCommCore.RegisterRelayEvents(null, null, sinkNewConnection); if (MyVisitorLog == null) { MyVisitorLog = new TheVisitorLog(MyBaseThing); } TheQueuedSenderRegistry.RegisterHealthTimer(GetSystemInfo); TheCDEngines.MyNMIService.RegisterEvent("NMI_MY_LOCATION", (sender2, para) => { var t = para as TheNMILocationInfo; if (t != null) { var NewEntry = new TheVisitorLogData { cdeN = t.cdeN, latitude = t.Latitude, longitude = t.Longitude, ip = t.ClientInfo?.UserID.ToString(), LastVisit = DateTimeOffset.Now, Description = t.ClientInfo != null && t.ClientInfo.UserID != Guid.Empty ? TheUserManager.GetUserFullName(t.ClientInfo.UserID) : "Unknown user" }; MyVisitorLog.LogVisitor(NewEntry); myGoogleMap?.SetUXProperty(Guid.Empty, $"AddMarker={TheCommonUtils.SerializeObjectToJSONString(NewEntry)}"); } }); TheCommCore.MyHttpService.RegisterHttpInterceptorB4("/cdemeshinfo.aspx", sinkRequestMeshInfo); MyBaseEngine.ProcessInitialized(); MyBaseEngine.SetEngineReadiness(true, null); MyBaseEngine.SetStatusLevel(1); mIsInitialized = true; return(true); }
public bool Init() { if (mIsInitCalled) { return(false); } mIsInitCalled = true; MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); MyBaseEngine.RegisterEvent(eEngineEvents.ThingDeleted, OnDeletedThing); MyBaseEngine.RegisterEvent(eEngineEvents.ThingRegistered, OnThingRegistered); MyBaseEngine.RegisterEvent(eEngineEvents.ShutdownEvent, OnShutdown); TheCommonUtils.cdeRunAsync("Init Mesh Receiver Connections", false, (state) => { // Migrate instances from previous versions List <TheThing> tLegacyDeviceList = TheThingRegistry.GetThingsOfEngine("CDMyCloudServices.cdeMyCloudService"); foreach (var tLegacyDevice in tLegacyDeviceList) { if (!tLegacyDevice.HasLiveObject) { switch (tLegacyDevice.DeviceType) { case "Mesh Receiver": tLegacyDevice.EngineName = MyBaseThing.EngineName; tLegacyDevice.DeviceType = MeshDeviceTypes.MeshReceiver; TheThingRegistry.UpdateThing(tLegacyDevice, false); break; } } } //await System.Threading.Tasks.Task.Delay(30000); InitServers(); mIsInitialized = true; FireEvent(eThingEvents.Initialized, this, true, true); MyBaseEngine.ProcessInitialized(); }, null); return(false); }
public bool Init() { if (!mIsInitStarted) { mIsInitStarted = true; MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); // Additional initialization processing goes here // Registering an Http Interceptor that just returns a hello message. TheCommCore.MyHttpService.RegisterHttpInterceptorB4("/HelloHTTPInterceptor", sinkHelloHttpInterceptor); // Registering an Http Interceptor that returns a dynamic web page. TheCommCore.MyHttpService.RegisterHttpInterceptorB4("/relay.html", sinkRelay); //// Injecting scripts into C-DEngine context. //TheCommCore.MyHttpService.RegisterGlobalScriptInterceptor("/MyStuff.js", (o) => //{ //}); //TheRequestData p = new TheRequestData(); //string strOut = TheCommCore.MyHttpService.CreateHttpHeader(p); //List<string> pGlobalScripts = TheCommCore.MyHttpService.GetGlobalScripts(); //// Providing status info to C-DEngine status page. //// Request to append status details to the /CDESTATUS.ASPX page for ?ALL or ?DIAG //TheCommCore.MyHttpService.RegisterStatusRequest((o) => //{ //}); MyBaseThing.StatusLevel = 1; MyBaseThing.LastMessage = "Hello HTTP Interceptor Service has started."; mIsInitCompleted = true; MyBaseEngine.ProcessInitialized(); } return(true); }
public void RegisterEvent(string pName, Action <ICDEThing, object> pCallBack) { MyBaseThing?.RegisterEvent(pName, pCallBack); }
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); }