Exemple #1
0
        /// <summary>
        /// Handles Messages sent from a host sub-engine to its clients
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="pIncoming"></param>
        public override void HandleMessage(ICDEThing sender, object pIncoming)
        {
            TheProcessMessage pMsg = pIncoming as TheProcessMessage;

            if (pMsg == null)
            {
                return;
            }

            string[] cmd = pMsg.Message.TXT.Split(':');
            switch (cmd[0])
            {
            case "CDE_INITIALIZED":
                MyBaseEngine.SetInitialized(pMsg.Message);
                break;

            case "GET_CHARTDATA":
                Type td = typeof(CDMyC3.TheC3ChartsFactory);
                TheChartFactory.PushChartsData(TheCommonUtils.CGuid(pMsg.Message.PLS), pMsg.Message.GetOriginator(), td.AssemblyQualifiedName);
                break;

            default:
                break;
            }
        }
Exemple #2
0
        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);
                }
            });
        }
Exemple #3
0
        string LoadXMLDefinition(string pFile)
        {
            string path = TheCommonUtils.cdeFixupFileName(pFile);

            TheBaseAssets.MySYSLOG.WriteToLog(500, new TSM(MyBaseEngine.GetEngineName(), $"Trying to open Modbus configuration file: {pFile}"));

            ModbusConfiguration config = null;

            try
            {
                config = ModbusConfiguration.ReadFromFile(path);
            }
            catch (IOException)
            {
                return("File not found or parsing failed");
            }

            List <TheThing> tDevList = TheThingRegistry.GetThingsOfEngine(MyBaseThing.EngineName);

            foreach (var dd in config.Devices)
            {
                var tDev = tDevList.Find((t) => t.FriendlyName == dd.Name);
                if (tDev == null || !tDev.HasLiveObject)
                {
                    TheBaseAssets.MySYSLOG.WriteToLog(500, new TSM(MyBaseEngine.GetEngineName(), $"Adding Modbus Device {dd.Name}"));
                    var pm = new ModbusTCPDevice(tDev, this, dd);
                    TheThingRegistry.RegisterThing(pm);
                }
            }

            return("XML Definition loaded correctly.");
        }
 private void sinkStorageStationIsReadyFired(ICDEThing sender, object pReady)
 {
     if (pReady != null)
     {
         if (MySensorStore == null)
         {
             MySensorStore = new TheStorageMirror <TheSensorValue>(TheCDEngines.MyIStorageService);
             if (MyBaseEngine.GetEngineState().IsSimulated || "RAM".Equals(pReady.ToString()))
             {
                 MySensorStore.IsRAMStore        = true;
                 MySensorStore.IsCachePersistent = true;
                 MySensorStore.SetRecordExpiration(10000, null);
             }
             else
             {
                 MySensorStore.IsRAMStore = false;
             }
             if (!MySensorStore.IsRAMStore && MyBaseEngine.GetEngineState().IsService)
             {
                 MySensorStore.CreateStore("Sensor Data: Sensor Data Store", "Data from sensors", null, true, false);
             }
             else
             {
                 MySensorStore.InitializeStore(true, false);
             }
         }
     }
 }
Exemple #5
0
        public override void HandleMessage(ICDEThing sender, object pIncoming)
        {
            if (!(pIncoming is TheProcessMessage pMsg))
            {
                return;
            }
            string[] cmd = pMsg.Message.TXT.Split(':');
            switch (cmd[0])   //string 2 cases
            {
            case "CDE_INITIALIZED":
                MyBaseEngine.SetInitialized(pMsg.Message);
                break;

            //If the Service receives an "INITIALIZE" it fires up all its code and sends INITIALIZED back
            case "CDE_INITIALIZE":
                if (MyBaseEngine.GetEngineState().IsService)
                {
                    if (!MyBaseEngine.GetEngineState().IsEngineReady)
                    {
                        MyBaseEngine.SetEngineReadiness(true, null);
                    }
                }
                MyBaseEngine.ReplyInitialized(pMsg.Message);
                break;

            case "REFRESH_DASH":
                InitServices();
                tDashGuid.Reload(pMsg, false);
                break;
            }
            ProcessServiceMessage(pMsg);
        }
        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);
                    }
                }
            }
        }
        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);
        }
Exemple #8
0
        void InitServers()
        {
            List <TheThing> tDevList = TheThingRegistry.GetThingsOfEngine(this.MyBaseEngine.GetEngineName());

            if (tDevList.Count > 0)
            {
                foreach (TheThing tDev in tDevList)
                {
                    try
                    {
                        if (!tDev.HasLiveObject)
                        {
                            switch (tDev.DeviceType)
                            {
                            case PrometheusDeviceTypes.PrometheusExporter:
                                var tPS = new ThePrometheusExporter(tDev, this);
                                TheThingRegistry.RegisterThing(tPS);
                                break;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        TheBaseAssets.MySYSLOG.WriteToLog(181001, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM(MyBaseThing.EngineName, $"Error creating exporter instance {tDev?.cdeMID} / {tDev?.FriendlyName}", eMsgLevel.l1_Error, e.ToString()));
                    }
                }
            }

            MyBaseEngine.SetStatusLevel(-1);
        }
Exemple #9
0
        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);
        }
Exemple #10
0
        private void InitServices()
        {
            if (TheBaseAssets.MyServiceHostInfo.IsCloudService)
            {
                return;
            }
            List <TheThing> tDevList = TheThingRegistry.GetThingsOfEngine(MyBaseEngine.GetEngineName());

            if (tDevList.Count > 0)
            {
                foreach (TheThing tDev in tDevList)
                {
                    switch (tDev.DeviceType)
                    {
                    case eWebAppTypes.TheWebApp:
                        TheRelayAppInfo tApp = new TheRelayAppInfo(tDev, null, this);
                        if (string.IsNullOrEmpty(tApp.HomePage))
                        {
                            tApp.HomePage = "/";
                        }
                        if (!tApp.HomePage.StartsWith("/"))
                        {
                            tApp.HomePage = "/" + tApp.HomePage;
                        }
                        tApp.SSID = TheScopeManager.GetScrambledScopeID();
                        TheThingRegistry.RegisterThing(tApp);
                        break;
                    }
                }
            }
        }
Exemple #11
0
        public override bool Init()
        {
            if (mIsInitCalled)
            {
                return(false);
            }
            mIsInitCalled = true;

            ReqBuffer = new TheMirrorCache <TheRequestData>(0);
            string t = TheCommonUtils.CStr(TheBaseAssets.MySettings.GetSetting("WRA_RequestTimeout"));

            if (!string.IsNullOrEmpty(t))
            {
                RequestTimeout = TheCommonUtils.CInt(t);
            }
            if (RequestTimeout < 15)
            {
                RequestTimeout = 15;
            }

            InitServices();

            TheCommCore.MyHttpService.RegisterHttpInterceptorB4("/", InterceptHttpRequest);
            TheScopeManager.RegisterScopeChanged(sinkScopeIDUpdate);
            MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage);

            mIsInitialized = true;
            MyBaseEngine.ProcessInitialized();
            return(true);
        }
        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);
        }
        void  InitServers()
        {
            List <TheThing> tDevList = TheThingRegistry.GetThingsOfEngine(MyBaseThing.EngineName); // TheThingRegistry.GetThingsByProperty("*", Guid.Empty, "DeviceType", eOPCDeviceTypes.OPCServer);

            if (tDevList.Count > 0)
            {
                foreach (TheThing tDev in tDevList)
                {
                    if (!tDev.HasLiveObject)
                    {
                        switch (tDev.DeviceType)
                        {
                        case eOPCDeviceTypes.OPCRemoteServer:
                            TheOPCUARemoteServer tS = new TheOPCUARemoteServer(tDev, this, null);
                            TheThingRegistry.RegisterThing(tS);
                            break;

                        case eOPCDeviceTypes.OPCLiveTag:
                            TheOPCUATagThing tag = new TheOPCUATagThing(tDev, null);
                            TheThingRegistry.RegisterThing(tag);
                            break;

                        case eOPCDeviceTypes.OPCMethod:
                            TheOPCUAMethodThing tMeth = new TheOPCUAMethodThing(tDev, MyBaseEngine.GetEngineName());
                            TheThingRegistry.RegisterThing(tMeth);
                            break;
                        }
                    }
                }
            }
            MyBaseEngine.SetStatusLevel(-1);
        }
Exemple #14
0
        void InitServers()
        {
            List <TheThing> tDevList = TheThingRegistry.GetThingsOfEngine(MyBaseThing.EngineName); // TheThingRegistry.GetThingsByProperty("*", Guid.Empty, "DeviceType", eOPCDeviceTypes.OPCServer);

            if (tDevList.Count > 0)
            {
                foreach (TheThing tDev in tDevList)
                {
                    switch (tDev.DeviceType)
                    {
                    case eMessageTypes.EMAIL:
                        TheEmailMessage tS = null;
                        if (!tDev.HasLiveObject)
                        {
                            tS = new TheEmailMessage(tDev, this);
                            TheThingRegistry.RegisterThing(tS);
                        }
                        break;

                    case eMessageTypes.SMS:
                        TheSMSMessage tSMS = null;
                        if (!tDev.HasLiveObject)
                        {
                            tSMS = new TheSMSMessage(tDev, this);
                            TheThingRegistry.RegisterThing(tSMS);
                        }
                        break;
                    }
                }
            }
            MyBaseEngine.SetStatusLevel(-1);
        }
        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);
        }
 /// <summary>
 /// Main call to store values in the StorageService
 /// </summary>
 /// <typeparam name="T">Type of class to be stored</typeparam>
 /// <param name="MyValue">Dictionary of Values of the class to be stored</param>
 /// <param name="pCMD">Command for the store process</param>
 /// <param name="pMagicID">MagicID to be used for back-publish</param>
 /// <param name="pCallBack">If set, and the call came from a local service, the sevices calls back without using the communication system</param>
 public void EdgeDataStore <T>(Dictionary <string, T> MyValue, eSCMD pCMD, string pMagicID, Action <TSM> pCallBack, string pTableName)
 {
     if (TheCDEngines.MyIStorageService != null)
     {
         string serializedXML = TheStorageUtilities.SerializeDataToStore(MyValue, pMagicID, pCMD, typeof(T).Equals(typeof(cdeP)) ? null : pTableName);
         string post          = "CDE_EDGESTORE";
         post += ":";
         if (!string.IsNullOrEmpty(pMagicID) && pCallBack != null)
         {
             MyTimedCallbacks.AddAnItem(new TheTimedCallback()
             {
                 cdeMID = TheCommonUtils.CGuid(pMagicID), MyCallback = pCallBack
             });
             post += pMagicID;
         }
         if (typeof(T).Equals(typeof(cdeP)))
         {
             post += ":" + TheStorageUtilities.GenerateUniqueIDFromType(typeof(TheThing), pTableName);
         }
         TSM tTSM = new TSM(MyBaseEngine.GetEngineName(), post, serializedXML);
         if (TheCDEngines.MyIStorageService.GetBaseEngine().GetEngineState().IsService)
         {
             ProcessStorageServiceCommands(tTSM, pCallBack, true);
         }
         //else //Later for Remote Storage
         //{
         //    tTSM.SetToServiceOnly(true);
         //    TheCommCore.PublishCentral(tTSM);
         //}
     }
 }
        public override bool Init()
        {
            if (TheCDEngines.MyThingEngine == null || mIsInitCalled)
            {
                return(false);
            }
            mIsInitCalled = true;

            if (string.IsNullOrEmpty(MyBaseThing.ID))
            {
                MyBaseThing.ID = Guid.NewGuid().ToString();
            }

            if (TheBaseAssets.MyServiceHostInfo.IsCloudService)
            {
                mIsInitialized = true;
                return(true);
            }

            if (!TheBaseAssets.MyServiceHostInfo.IsCloudService)//TODO: Allow Cloud Rules
            {
                TheCDEngines.MyThingEngine.RegisterEvent(eEngineEvents.ThingUpdated, sinkThingWasUpdated);
                //TheThingRegistry.eventThingUpdated += sinkThingWasUpdated;
                TheCDEngines.MyThingEngine.RegisterEvent(eEngineEvents.ThingRegistered, sinkThingWasRegistered);
                //TheThingRegistry.eventThingRegistered += sinkThingWasRegistered;
                TheCDEngines.MyThingEngine.RegisterEvent(eEngineEvents.ThingInitCalled, sinkActivateRules);
            }
            MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage);
            mIsInitialized = true; // CODE REVIEW Markus: Is the rules engine really ready for consumption at this stage, or should we wait until storage is ready?
                                   //CM: The rules engine is ready but the Event Log might not be fully ready as of this time.
            ActivateRules();
            MyBaseEngine.ProcessInitialized();
            return(true);
        }
        /// <summary>
        /// Requests the capabilities of the Server
        /// </summary>
        /// <param name="pMagicID">MagicID to be used for back-publish</param>
        /// <param name="pCallBack">If set, and the call came from a local service, the sevices calls back without using the communication system</param>
        public void EdgeStorageServerRequestCaps(string pMagicID, Action <TSM> pCallBack)
        {
            if (TheCDEngines.MyIStorageService == null || TheCDEngines.MyIStorageService.GetBaseEngine().GetEngineState().IsService)
            {
                return;
            }
            string serializedXML = TheCommonUtils.SerializeObjectToJSONString(TheCDEngines.MyIStorageService.GetStorageCaps());
            string post          = "CDE_GETEDGECAPS";

            if (pMagicID.Length > 0 && pCallBack != null)
            {
                MyTimedCallbacks.AddAnItem(new TheTimedCallback()
                {
                    cdeMID = TheCommonUtils.CGuid(pMagicID), MyCallback = pCallBack
                });
                post += ":" + pMagicID;
            }
            TSM tTSM = new TSM(MyBaseEngine.GetEngineName(), post, serializedXML);

            if (TheCDEngines.MyIStorageService.GetBaseEngine().GetEngineState().IsService)
            {
                ProcessStorageServiceCommands(tTSM, pCallBack, true);
            }
            //else //Later for Remote Storage
            //{
            //    tTSM.SetToServiceOnly(true);
            //    TheCommCore.PublishCentral(tTSM);
            //}
        }
        public void LogChanges(bool IsConsumer, cdeP[] changedProperties = null)
        {
            string logMessage = "";

            if (IsConsumer)
            {
                List <TheThingStore> history = testThing.GetThingHistory(historyToken, 1, false);
                logMessage = "Aggregated - ";
                foreach (TheThingStore snapShot in history)
                {
                    foreach (string property in properties)
                    {
                        if (snapShot.PB.TryGetValue(property, out var propValue))
                        {
                            logMessage += $"{property}: {propValue} | ";
                        }
                    }
                }
            }
            else
            {
                logMessage = $"{testThing.FriendlyName} - ";
                if (changedProperties != null)
                {
                    foreach (cdeP property in changedProperties)
                    {
                        logMessage += $"{property.Name}: {property.Value} | ";
                    }
                }
            }
            // Log the message to SYSLOG
            TheBaseAssets.MySYSLOG.WriteToLog(
                2020,
                TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM(MyBaseEngine.GetEngineName(), logMessage, IsConsumer ? eMsgLevel.l3_ImportantMessage : eMsgLevel.l4_Message));
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="pBase">The C-DEngine is creating a Host for this engine and hands it to the Plugin Service</param>
 public override void InitEngineAssets(IBaseEngine pBase)
 {
     base.InitEngineAssets(pBase);
     MyBaseEngine.SetFriendlyName("The Rules Engine");
     MyBaseEngine.AddCapability(eThingCaps.RulesEngine);
     MyBaseEngine.SetPluginInfo("The C-Labs Rules engine", 0, null, "toplogo-150.png", "C-Labs", "http://www.c-labs.com", null); //TODO: Describe your plugin - this will later be used in the Plugin-Store
     MyBaseEngine.SetEngineID(new Guid("{843B73BA-028F-4BDF-A102-D1E545204036}"));
 }
Exemple #21
0
 public override void InitEngineAssets(IBaseEngine pBase)
 {
     base.InitEngineAssets(pBase);
     MyBaseEngine.SetFriendlyName("My Messaging Service");
     MyBaseEngine.SetEngineID(new Guid("{7B56E698-59B5-4A11-BFE7-FDB06A912FDC}"));
     MyBaseEngine.SetPluginInfo("Send email and other messages to people, social media and other recipients", 0, null, "FA3:f658", "C-Labs", "http://www.c-labs.com", new List <string>());
     MyBaseEngine.GetEngineState().IsAllowedUnscopedProcessing = true;
 }
        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);
        }
Exemple #23
0
        public override bool CreateUX()
        {
            if (mIsUXInitCalled)
            {
                return(false);
            }
            mIsUXInitCalled = true;
            TheNMIEngine.RegisterEngine(MyBaseEngine);

            mMyDashboard = TheNMIEngine.AddDashboard(MyBaseThing, new TheDashboardInfo(MyBaseEngine, "Prometheus Exporters")
            {
                PropertyBag = new ThePropertyBag()
                {
                    "Category=Diagnostics", "Thumbnail=images/prometheus_logo_grey.png;0.5"
                }
            });

            TheFormInfo tAllCloudConnections = new TheFormInfo(MyBaseEngine)
            {
                cdeMID = TheThing.GetSafeThingGuid(MyBaseThing, "AZC"), defDataSource = string.Format("TheThing;:;0;:;True;:;EngineName={0}", MyBaseEngine.GetEngineName()), FormTitle = "Prometheus Exporters", AddButtonText = "Add a Sender"
            };

            TheNMIEngine.AddFormToThingUX(MyBaseThing, tAllCloudConnections, "CMyTable", "Prometheus Exporters", 1, 0x0D, 0xC0, TheNMIEngine.GetNodeForCategory(), null, new ThePropertyBag()
            {
                "Thumbnail=images/prometheus_logo_grey.png.png;0.5"
            });

            TheNMIEngine.AddCommonTableColumns(MyBaseThing, tAllCloudConnections, PrometheusDeviceTypes.GetValues(), PrometheusDeviceTypes.PrometheusExporter);

            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"
            });
            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);

            mIsUXInitialized = true;
            return(true);
        }
 void sinkTimer(long timer)
 {
     if ((timer % 5) == 0)
     {
         if (TheThing.GetSafePropertyBool(MyBaseThing, "LogKPIs"))
         {
             TheBaseAssets.MySYSLOG.WriteToLog(23099, new TSM(MyBaseEngine.GetEngineName(), TheCDEKPIs.GetKPIs(true), eMsgLevel.l4_Message));
         }
     }
 }
Exemple #25
0
 public override void InitEngineAssets(IBaseEngine pBase)
 {
     base.InitEngineAssets(pBase);
     MyBaseEngine.SetFriendlyName("Image Service");
     MyBaseEngine.GetEngineState().IsAcceptingFilePush = true;
     MyBaseEngine.SetEngineID(new Guid("{795370F8-EF3A-4F1F-BBE0-F16053329B90}"));
     MyBaseEngine.SetPluginInfo("This service allows you to manage images", 0, null, "toplogo-150.png", "C-Labs", "http://www.c-labs.com", new List <string>()
     {
     });
 }
        /// <summary>
        /// If this is a service the SimplexProc event will be called when the C-DEngine receives a new event sent by a subscriber to this service
        /// </summary>
        /// <param name="pMsg">The Message to be Processed</param>
        private void ProcessServiceMessage(TheProcessMessage pMsg)
        {
            string[] cmd = pMsg.Message.TXT.Split(':');
            switch (cmd[0]) //string 2 cases
            {
            case "WEBRELAY_RESPONSE":
                TheRequestData tState = TheCommonUtils.DeserializeJSONStringToObject <TheRequestData>(pMsg.Message.PLS);
                if (pMsg.Message.PLB != null && pMsg.Message.PLB.Length > 0)
                {
                    tState.ResponseBuffer = pMsg.Message.PLB;
                }
                tState.RequestUri = new Uri(tState.RequestUriString);
                //tState.SessionState = new TheSessionState() { SScopeID = pMsg.SID };
                sinkResults(tState);
                break;

            case "WEBRELAY_REQUEST":
                TheRequestData tData = TheCommonUtils.DeserializeJSONStringToObject <TheRequestData>(pMsg.Message.PLS);
                if (tData != null)
                {
                    tData.RequestUri = new Uri(tData.RequestUriString);
                    //tData.SessionState = new TheSessionState() { SScopeID = pMsg.SID };
                    if (pMsg.Message.PLB != null && pMsg.Message.PLB.Length > 0)
                    {
                        tData.PostData = pMsg.Message.PLB;
                    }
                    tData.CookieObject = pMsg.Message;
                    ReadHttpPage(tData, tData.SessionState.ARApp, null, sinkProcessResponse);
                    //InterceptHttpRequest(tData,tData.SessionState.ARApp);
                }
                break;

            case "WEBRELAY_REQUESTWRA":
                TSM             tTSM    = new TSM();
                List <TheThing> webApps = TheThingRegistry.GetThingsOfEngine(MyBaseEngine.GetEngineName());
                foreach (TheThing tApp in webApps)
                {
                    if (tApp.Address.Equals(pMsg.Message.PLS))
                    {
                        tTSM.PLS = $"/CDEWRA{tApp.cdeMID}" + TheThing.GetSafePropertyString(tApp, "HomePage");
                        break;
                    }
                }
                if (!string.IsNullOrEmpty(tTSM.PLS))
                {
                    string[]    org          = pMsg.Message.ORG.Split(':');
                    TheThing    senderThing  = TheThingRegistry.GetThingByMID(TheCommonUtils.CGuid(org[1]), true);
                    IBaseEngine senderEngine = TheThingRegistry.GetBaseEngine(senderThing, true);
                    tTSM.ENG = senderEngine.GetEngineName();
                    tTSM.TXT = "RESPONSEWRA";
                    TheCommCore.PublishToOriginator(pMsg.Message, tTSM, true);
                }
                break;
            }
        }
 public override void InitEngineAssets(IBaseEngine pBase)
 {
     base.InitEngineAssets(pBase);
     MyBaseEngine.SetFriendlyName("Computer Management");
     MyBaseEngine.SetEngineID(new Guid("{8FB08B63-1A2D-4DF6-8DC8-BADB12500F94}"));
     MyBaseEngine.GetEngineState().IsAcceptingFilePush = true;
     // MyBaseEngine.RegisterJSEngine(null);
     MyBaseEngine.AddCapability(eThingCaps.ComputerHealth);
     MyBaseEngine.AddCapability(eThingCaps.HardwareAccess);
     MyBaseEngine.AddCapability(eThingCaps.DoNotIsolate);
     MyBaseEngine.SetPluginInfo("Monitors the health of all your Nodes", 0, null, "FA3:f108", "C-Labs and its licensors", "http://www.c-labs.com", new List <string>());
 }
        private void sinkProcessResponse(TheRequestData pRequest)
        {
            if (pRequest.StatusCode >= 400 && pRequest.ResponseBuffer == null && !string.IsNullOrEmpty(pRequest.ErrorDescription))
            {
                pRequest.ResponseBuffer = TheCommonUtils.CUTF8String2Array(pRequest.ErrorDescription);
            }
            if (pRequest.ResponseBuffer == null && string.IsNullOrEmpty(pRequest.ResponseBufferStr))
            {
                pRequest.ResponseBuffer = TheCommonUtils.CUTF8String2Array("EMPTY");
            }
            if (pRequest.ResponseMimeType.StartsWith("text/html") || pRequest.ResponseMimeType.Contains("javascript"))  //OK
            {
                pRequest.ResponseBufferStr = TheCommonUtils.CArray2UTF8String(pRequest.ResponseBuffer);
            }
            string tReqUri = pRequest.RequestUri.Host;

            if (pRequest.RequestUri.Port != 80)
            {
                tReqUri += ":" + pRequest.RequestUri.Port;
            }
            if (!string.IsNullOrEmpty(pRequest.ResponseBufferStr) && (pRequest.ResponseMimeType.StartsWith("text/html") || pRequest.ResponseMimeType.Contains("javascript")) && pRequest.ResponseBufferStr.IndexOf(tReqUri, StringComparison.CurrentCultureIgnoreCase) >= 0)
            {
                if (pRequest.SessionState.ARApp != Guid.Empty)
                {
                    TheRelayAppInfo tMyApp = TheThingRegistry.GetThingObjectByMID(MyBaseEngine.GetEngineName(), pRequest.SessionState.ARApp) as TheRelayAppInfo; //MyRelayApps.MyMirrorCache.GetEntryByFunc(s => s.cdeMID.Equals(pRequest.SessionState.ARApp));
                    if (tMyApp != null)
                    {
                        Uri tCloudUri = new Uri(pRequest.RequestUriString);
                        //pRequest.ResponseBufferStr = pRequest.ResponseBufferStr.Replace(pRequest.RequestUri.Host + ":" + pRequest.RequestUri.Port, new Uri(tMyApp.CloudUrl).Host + ":" + new Uri(tMyApp.CloudUrl).Port);
                        pRequest.ResponseBufferStr = pRequest.ResponseBufferStr.Replace(pRequest.RequestUri.Scheme + "://" + tReqUri, tCloudUri.Scheme + "://" + tCloudUri.Host + ":" + tCloudUri.Port);
                        pRequest.ResponseBuffer    = TheCommonUtils.CUTF8String2Array(pRequest.ResponseBufferStr);
                    }
                }
            }
            TheBaseAssets.MySYSLOG.WriteToLog(400, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM(MyBaseEngine.GetEngineName(), string.Format("Response Bytes:{1} For Page:{0} Sent", pRequest.cdeRealPage, pRequest.ResponseBuffer != null ? pRequest.ResponseBuffer.Length : 0), eMsgLevel.l3_ImportantMessage));
            if (pRequest.ResponseBuffer != null)
            {
                //TheCommonUtils.SleepOneEye(5000, 100);
                TSM message3 = new TSM(MyBaseEngine.GetEngineName(), "WEBRELAY_RESPONSE")
                {
                    PLB = pRequest.ResponseBuffer
                };
                pRequest.ResponseBuffer    = null;
                pRequest.ResponseBufferStr = null;
                pRequest.RequestUriString  = pRequest.RequestUri.ToString();
                TSM tMSG = pRequest.CookieObject as TSM;
                pRequest.CookieObject = null;
                pRequest.PostData     = null;
                message3.PLS          = TheCommonUtils.SerializeObjectToJSONString(pRequest);
                TheCommCore.PublishToOriginator(tMSG, message3);
            }
        }
Exemple #29
0
        /// <summary>
        /// Initializes the internal NMI Engine
        /// </summary>
        /// <param name="pBase">The C-DEngine is creating a Host for this engine and hands it to the Plugin Service</param>
        public override void InitEngineAssets(IBaseEngine pBase)
        {
            base.InitEngineAssets(pBase);
            MyBaseEngine.SetEngineName(eEngineName.NMIService);        //Can be any arbitrary name - recommended is the class name
            MyBaseEngine.SetFriendlyName("The NMI Model Service");
            MyBaseEngine.AddCapability(eThingCaps.Internal);
            MyBaseEngine.SetPluginInfo("This service manages the NMI Model of the C-DEngine", 0, null, "toplogo-150.png", "C-Labs", "http://www.c-labs.com", null); //TODO: Describe your plugin - this will later be used in the Plugin-Store

            MyBaseEngine.GetEngineState().IsAllowedUnscopedProcessing = TheBaseAssets.MyServiceHostInfo.IsCloudService;
            MyBaseEngine.GetEngineState().IsAcceptingFilePush         = true;
            MyBaseEngine.SetEngineID(new Guid("{4D6E5FE7-338E-4B3E-B98D-0FFFEB62FE63}"));
            MyBaseEngine.SetVersion(TheBaseAssets.BuildVersion);
        }
        /// <summary>
        /// Initializes The Thing Engine
        /// </summary>
        /// <returns></returns>
        public override bool Init()
        {
            if (mIsInitCalled)
            {
                return(false);
            }
            mIsInitCalled = true;

            MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage);        //Event when C-DEngine has new Telegram for this service as a subscriber (Client Side)
            MyBaseEngine.SetInitialized(null);
            mIsInitialized = true;
            return(true);
        }