public override 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 Prometheus Exporters", false, (state) => { try { InitServers(); } catch (Exception e) { TheBaseAssets.MySYSLOG.WriteToLog(181001, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM(MyBaseThing.EngineName, "Error initializing instances", eMsgLevel.l1_Error, e.ToString())); } mIsInitialized = true; FireEvent(eThingEvents.Initialized, this, true, true); MyBaseEngine.ProcessInitialized(); }, null); return(false); }
public override bool Init() { if (!mIsInitCalled) { mIsInitCalled = true; MyBaseThing.StatusLevel = 4; SetMessage("Service has started", DateTimeOffset.Now); MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); MyBaseEngine.RegisterEvent(eEngineEvents.ThingDeleted, OnThingDeleted); // 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 that must finish before other plug-ins or the C-DEngine can use the plug-in InitServices(); // Declare the thing initialized mIsInitialized = true; // For future IsInit() calls FireEvent(eThingEvents.Initialized, this, true, true); // Notify the C-DEngine and other plug-ins that the thing is initialized MyBaseEngine.ProcessInitialized(); //Set the status of the Base Engine according to the status of the Things it manages }); } return(false); }
public override bool Init() { if (mIsInitCalled) { return(false); } mIsInitCalled = true; MyBaseThing.StatusLevel = 4; MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); MyBaseEngine.RegisterEvent(eEngineEvents.ThingRegistered, sinkRegistered); MyBaseEngine.RegisterEvent(eEngineEvents.ThingDeleted, sinkRegistered); if (EnableTracing) { Opc.Ua.Utils.SetTraceOutput(Utils.TraceOutput.FileOnly); Opc.Ua.Utils.SetTraceLog("opcclient.log", false); } else { Opc.Ua.Utils.SetTraceOutput(Utils.TraceOutput.Off); } if (EnableTracingToLog) { Opc.Ua.Utils.Tracing.TraceEventHandler += OnOpcLibraryTrace; } TheCommonUtils.cdeRunAsync("Init OPC Servers", true, (a) => { InitServers(); mIsInitialized = true; FireEvent(eThingEvents.Initialized, this, true, true); MyBaseEngine.ProcessInitialized(); }); return(false); }
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 override bool Init() { if (mIsInitCalled) { return(false); } mIsInitCalled = true; MyBaseEngine.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); base.Init(); mIsInitialized = InitBase("Mesh Receiver", MeshDeviceTypes.MeshReceiver); MyBaseThing.StatusLevel = IsConnected ? 1 : 0; return(mIsInitialized); }
public override bool Init() { if (!mIsInitCalled) { mIsInitCalled = true; MyBaseThing.StatusLevel = 4; MyBaseThing.LastMessage = "Service has started"; MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); MyBaseEngine.RegisterEvent(eEngineEvents.ThingDeleted, OnThingDeleted); MyBaseThing.RegisterEvent(eEngineEvents.FileReceived, sinkFileReceived); InitServices(); MyBaseEngine.ProcessInitialized(); //Set the status of the Base Engine according to the status of the Things it manages mIsInitialized = true; } return(false); }
public override bool Init() { if (mIsInitCalled) { return(false); } mIsInitCalled = true; MyBaseThing.StatusLevel = 4; MyBaseThing.LastMessage = "Plugin has started"; MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); MyBaseEngine.RegisterEvent(eEngineEvents.ThingDeleted, (t, o) => OnThingDeleted(t, o)); MyBaseEngine.RegisterEvent(eEngineEvents.ThingRegistered, sinkRegistered); MyBaseThing.RegisterEvent("FileReceived", sinkFileReceived); // Create any properties and set them to default values on first run only bool bFirstRun = MyBaseThing.ID == null; // Using the ID property to detect first run - any other property would work as well if you don't need/want an ID property // Tip: If you want to reset all properties to their defaults just set the ID property to null SetPropertyIfNotExist("FriendlyName", "Modbus Plugin", bFirstRun); //Declare the Property and optionally Initalize (change null with initialization) if (bFirstRun) { MyBaseThing.ID = Guid.NewGuid().ToString(); } TheCommonUtils.cdeRunAsync(MyBaseEngine.GetEngineName() + " Init Services", true, (o) => { // Perform any long-running initialization (i.e. network access, file access) here InitServices(); // Only then declare the service as initizlied if (MyBaseThing.StatusLevel == 4) { MyBaseThing.StatusLevel = 1; } FireEvent(eThingEvents.Initialized, this, true, true); MyBaseEngine.ProcessInitialized(); // If not lengthy initialized you can remove cdeRunasync and call this synchronously }); mIsInitialized = true; return(IsInit()); }
public override bool Init() { if (mIsInitCalled) { return(false); } mIsInitCalled = true; MyBaseThing.RegisterStatusChanged(sinkStatChanged); MyBaseThing.StatusLevel = 4; MyBaseThing.Value = "0"; MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); MyBaseEngine.RegisterEvent(eEngineEvents.ThingDeleted, OnThingDeleted); MyBaseEngine.RegisterEvent(eEngineEvents.ThingRegistered, OnThingRegisterd); if (!TheBaseAssets.MyServiceHostInfo.IsCloudService && !TheThing.GetSafePropertyBool(MyBaseThing, "RanBefore")) { TheThing.SetSafePropertyBool(MyBaseThing, "RanBefore", true); string tAutoPing = TheBaseAssets.MySettings.GetSetting("AutoPing"); if (!string.IsNullOrEmpty(tAutoPing)) { TheThing tThing = new TheThing(); tThing.EngineName = MyBaseEngine.GetEngineName(); tThing.DeviceType = eNetworkServiceTypes.PingService; tThing.Address = tAutoPing; tThing.FriendlyName = tAutoPing; TheThing.SetSafePropertyBool(tThing, "AllowRTT", true); TheThing.SetSafePropertyBool(tThing, "AutoConnect", true); TheThingRegistry.RegisterThing(tThing); } } if (MyBaseEngine.GetEngineState().IsService) { TheCommonUtils.cdeRunAsync("Init Networkers", true, (o) => { InitNetworkServices(); mIsInitialized = true; FireEvent(eThingEvents.Initialized, this, true, true); MyBaseEngine.ProcessInitialized(); }); } return(false); }