public bool LogEvent(TheEventLogData pItem)
        {
            if (pItem == null)
            {
                return(false);
            }
            bool            bRet     = false;
            List <TheThing> tDevList = TheThingRegistry.GetThingsOfEngine(MyBaseThing.EngineName);

            if (tDevList?.Count > 0)
            {
                foreach (TheThing tDev in tDevList)
                {
                    var tTwin = tDev.GetObject() as ICDELoggerEngine;
                    var tRes  = tTwin?.LogEvent(pItem);
                    if (!bRet && tRes == true)
                    {
                        bRet = true;
                    }
                }
            }
            if (PublishEvents) //This allows to have a logger on a different node
            {
                TheCommCore.PublishCentral(new TSM(eEngineName.ContentService, eEngineEvents.NewEventLogEntry, pItem.EventLevel, TheCommonUtils.SerializeObjectToJSONString(pItem)), true);
            }
            return(bRet);
        }
Beispiel #2
0
        private static void SendGlobalThings(Guid targetNodeId)
        {
            // Do not send more often than every 60 seconds
            if (lastGlobalThingSendPerNode.TryGetValue(targetNodeId, out thingSendStatus timeAndPending))
            {
                if (DateTimeOffset.Now.Subtract(timeAndPending.lastSend).TotalSeconds < 59) // && !timeAndPending.Pending)
                {
                    return;
                }
            }
            var globalThings = TheThingRegistry.GetThingsByFunc("*", (t) => TheThing.GetSafePropertyBool(t, "IsRegisteredGlobally") && t.IsOnLocalNode());

            if (globalThings != null)
            {
                TSM tTSM = new TSM(eEngineName.ContentService, "CDE_SYNC_THINGS", TheCommonUtils.SerializeObjectToJSONString(globalThings));
                tTSM.SetToServiceOnly(true);
                if (targetNodeId == Guid.Empty)
                {
                    TheCommCore.PublishCentral(tTSM);
                }
                else
                {
                    TheCommCore.PublishToNode(targetNodeId, tTSM);
                }
                lastGlobalThingSendPerNode[targetNodeId] = new thingSendStatus {
                    lastSend = DateTimeOffset.Now, Pending = false
                };
            }
        }
        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 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);
            }
        }
Beispiel #5
0
        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);
            }
        }
Beispiel #6
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;
                    }
                }
            }
        }
        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);
        }
Beispiel #8
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.");
        }
        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);
        }
Beispiel #10
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);
                }
            });
        }
Beispiel #11
0
        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);
        }
Beispiel #12
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);
        }
Beispiel #13
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)
                {
                    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);
        }
Beispiel #14
0
        private static string AddHTMLHeader()
        {
            string outText = "<html><head>";

            outText += TheBaseAssets.MyServiceHostInfo.GetMeta("");
            if (TheThingRegistry.IsEngineStarted("NMIService.TheNMIHtml5RT", false))
            {
                outText += "<link rel=\"stylesheet\" type=\"text/css\" href=\"css/cdeStyles.min.css\" />";
                outText += "<link rel=\"stylesheet\" type=\"text/css\" href=\"css/MyStyles.min.css\" />";
                outText += "<script src=\"cdeSorttable.js\"></script>";
                outText += "<script src=\"excellentexport.js\"></script>";
                outText += "<script>window.jdenticon_config = { replaceMode: \"observe\" }; </script>";
                outText += "<script src=\"jdenticon-2.2.0.min.js\"></script>";
            }
            else
            {
                outText += "<style>";
                outText += "table.cdeHilite {font-family: 'robotothin','Segoe UI',Arial,sans-serif;margin: 1em;border-collapse: collapse;font-weight: normal;text-decoration: none;}";
                outText += ".cdeLogEntry {padding: .1em;border-bottom-style: solid;border-bottom-width: 1px;}";
                outText += ".cdeClip {overflow: hidden;text-overflow: ellipsis;}";
                outText += ".cdeClip:hover { overflow: visible;text-overflow: initial;}";
                outText += "</style>";
            }
            outText += "<title>" + TheBaseAssets.MyServiceHostInfo.GetPrimaryStationURL(false) + " - System Log</title>";
            outText += "</head><body class=\"cdeLogBody\">\r";
            return(outText);
        }
        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);
                    }
                }
            }
        }
        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 void IncomingMessageEventTest()
        {
            var    contentServiceThing = TheThingRegistry.GetBaseEngineAsThing(eEngineName.ContentService);
            var    contentServiceEng   = contentServiceThing.GetBaseEngine();
            int    numberOfMessages    = 0;
            string txt     = "TEST_TXT";
            string payload = "TestPayload";
            TSM    testMsg = new TSM(eEngineName.ContentService, txt, payload);

            contentServiceEng?.RegisterEvent(eEngineEvents.IncomingMessage, (t, o) =>
            {
                numberOfMessages++;
                if (o is TheProcessMessage msg)
                {
                    Assert.AreEqual(msg.Message.TXT, txt);
                    Assert.AreEqual(msg.Message.PLS, payload);
                    Assert.AreEqual(msg.Message.ENG, contentServiceEng.GetEngineName());
                    testMsg.PLS = "TestPayload2";
                    //Assert.AreNotEqual(msg.Message.PLS, testMsg.PLS); // This fails
                }
                if (t is ICDEThing thing)
                {
                    Assert.AreEqual(thing.GetBaseThing().cdeMID, contentServiceThing.cdeMID);
                }
            });
            TheCommCore.PublishCentral(testMsg, true);
            TheCommonUtils.SleepOneEye(5000, 1000);
            Assert.AreEqual(numberOfMessages, 1);
        }
Beispiel #18
0
 /// <summary>
 /// Activates a given rule
 /// </summary>
 /// <param name="pRuleID">ID To activate</param>
 /// <param name="pTurnActive">if true, the rule will be activated otherwise deactivated</param>
 /// <returns></returns>
 public static bool ActivateRule(Guid pRuleID, bool pTurnActive)
 {
     InitRR();
     if (MyRulesRegistry != null)
     {
         ICDEThing pRule = TheThingRegistry.GetThingByID(eEngineName.ThingService, pRuleID.ToString());
         if (pRule != null)
         {
             try
             {
                 if (pRule.GetBaseThing().GetObject() is TheThingRule tRule)
                 {
                     tRule.IsRuleActive = pTurnActive;
                     MyRulesRegistry.ActivateRules();
                     return(true);
                 }
             }
             catch
             {
                 //ignored
             }
         }
     }
     return(false);
 }
Beispiel #19
0
        private void UpdateUx()
        {
            ThePropertyBag.MergeUXBagFromProperties(CountBar?.PropertyBag, MyBaseThing);
            SetCtrlType();

            if (TimestampField != null)
            {
                TimestampField?.SetUXProperty(Guid.Empty, $"Visibility={ShowTimestamp}");
                ChangeTimestampField?.SetUXProperty(Guid.Empty, $"Visibility={ShowChangeTimestamp}");
            }

            TheThingRegistry.UnmapPropertyMapper(MapperGuid);
            if (!string.IsNullOrEmpty(MyBaseThing.Address))
            {
                MapperGuid = TheThingRegistry.PropertyMapper(TheCommonUtils.CGuid(MyBaseThing.Address), TheThing.GetSafePropertyString(MyBaseThing, "SourceProp"), MyBaseThing.cdeMID, "Value", true);
                if (MapperGuid != Guid.Empty)
                {
                    MyBaseThing.StatusLevel = 1;
                    MyBaseThing.LastMessage = "Mapper engaged";
                }
                else
                {
                    MyBaseThing.StatusLevel = 2;
                    MyBaseThing.LastMessage = "Mapper failed to engaged";
                }
            }
            else
            {
                MyBaseThing.StatusLevel = 0;
                MyBaseThing.LastMessage = "Mapper not engaged";
            }
        }
        private static IServiceCollection AddCdePubSubServices(this IServiceCollection collection)
        {
            collection.AddSingleton(sp =>
            {
                sp.UseCde();
                var engines = TheThingRegistry.GetBaseEngines(false);
                var engine  = engines.FirstOrDefault(e => e.GetEngineName() == InfrastructureEngine);
                if (engine != null)
                {
                    return(engine.GetBaseThing());
                }

                if (!TheCDEngines.RegisterNewMiniRelay(InfrastructureEngine))
                {
                    throw new InvalidOperationException("Failed to register CDE infrastructure engine");
                }

                engine = TheThingRegistry.GetBaseEngine(InfrastructureEngine, false);
                return(engine.GetBaseThing());
            });

            collection.AddSingleton(sp => new Publisher(Operator.GetLine(sp.GetRequiredService <TheThing>())).ConnectAsync().Result as Publisher)
            .AddSingleton(sp => sp.GetRequiredService <Publisher>() as IPublisher);
            collection.AddSingleton(sp => new Subscriber(Operator.GetLine(sp.GetRequiredService <TheThing>()), sp.GetRequiredService <Publisher>()))
            .AddSingleton(sp => sp.GetRequiredService <Subscriber>() as ISubscriber);

            return(collection);
        }
        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);
        }
Beispiel #22
0
        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);
            }
        }
Beispiel #23
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);
        }
Beispiel #24
0
        void InitServices()
        {
            var tThing = TheThingRegistry.GetThingByProperty(MyBaseThing.EngineName, Guid.Empty, "DeviceType", eTheDemoScreensTypes.DemoIFrame);
            var t      = new DemoIFrame(tThing, this);

            var tThing2 = TheThingRegistry.GetThingByProperty(MyBaseThing.EngineName, Guid.Empty, "DeviceType", eTheDemoScreensTypes.DemoStandardForm);
            var t2      = new DemoStandardForm(tThing2, this);

            var tThing3 = TheThingRegistry.GetThingByProperty(MyBaseThing.EngineName, Guid.Empty, "DeviceType", eTheDemoScreensTypes.DemoControls);
            var t3      = new DemoControls(tThing3, this);

            var tThing4 = TheThingRegistry.GetThingByProperty(MyBaseThing.EngineName, Guid.Empty, "DeviceType", eTheDemoScreensTypes.DemoWizard);
            var t4      = new DemoWizard(tThing4, this);

            var tThing5 = TheThingRegistry.GetThingByProperty(MyBaseThing.EngineName, Guid.Empty, "DeviceType", eTheDemoScreensTypes.AudioWizard);
            var t5      = new AudioRuleWizard(tThing5, this);

            var tThing9 = TheThingRegistry.GetThingByProperty(MyBaseThing.EngineName, Guid.Empty, "DeviceType", eTheDemoScreensTypes.MeshPicker);
            var t9      = new TheMeshPicker(tThing9, this);

            var tThing10 = TheThingRegistry.GetThingByProperty(MyBaseThing.EngineName, Guid.Empty, "DeviceType", eTheDemoScreensTypes.TestAutomationWizard);
            var t10      = new TestAutoWizard(tThing10, this);

            MyBaseEngine.SetStatusLevel(1);
        }
Beispiel #25
0
        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";
            }
        }
        IEnumerable <JSonOpcArrayElement> GetJSONArray(TheThingStore thingEvent)
        {
            // TODO Replace with linkid some identifier that represents the activated instance/customer, and make this more efficient (avoid or cache thing registry lookup)
            string linkid;
            var    tThing = TheThingRegistry.GetThingByMID("*", TheCommonUtils.CGuid(thingEvent.cdeMID), true);

            if (tThing != null && !String.IsNullOrEmpty(tThing.FriendlyName))
            {
                linkid = tThing.FriendlyName;
            }
            else
            {
                if (thingEvent.PB.ContainsKey("Address"))
                {
                    linkid = TheCommonUtils.CStr(thingEvent.PB["Address"]);
                }
                else
                {
                    if (tThing != null)
                    {
                        linkid = tThing.Address;
                    }
                    else
                    {
                        linkid = TheCommonUtils.cdeGuidToString(thingEvent.cdeMID);
                    }
                }
            }

            var jsonArray = new List <JSonOpcArrayElement>();

            jsonArray.AddRange(thingEvent.PB.Select(propKV => GetJSONArrayElement(linkid, propKV.Key, thingEvent.cdeCTIM, propKV.Value)));
            return(jsonArray.OrderBy(ev => ev.sourcetimestamp));
        }
        public MainWindow()
        {
            InitializeComponent();

            // Start the CDEngine communication channels
            StartCDEngineHost();

            TheBaseEngine.WaitForEnginesStartedAsync().ContinueWith(t =>
            {
                try
                {
                    // Express our interest in the EngineName used for the chat, so that a subscription to the cloud is established even though the engine has not matching plug-in on this node
                    TheCDEngines.RegisterNewMiniRelay(strChatEngine);

                    // Intercept any messages sent to the chat engine
                    var chatEngine = TheThingRegistry.GetBaseEngine(strChatEngine);
                    chatEngine.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage);

                    // Intercept any messages sent to the ContentService (we will use that as the originating thing, and acknowledge messages will come back to it)
                    TheThingRegistry.GetBaseEngineAsThing(eEngineName.ThingService).RegisterEvent(eThingEvents.IncomingMessage, HandleMessage);
                }
                catch
                {
                }
            });
        }
        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);
        }
Beispiel #29
0
 TheThing GetOpcThing()
 {
     if (_opcThing == null)
     {
         _opcThing = TheThingRegistry.GetThingByMID(OpcThingAddress.EngineName, OpcThingAddress.ThingMID);
     }
     return(_opcThing);
 }
Beispiel #30
0
 public TheDemoBase(TheThing tBaseThing, ICDEPlugin pPluginBase)
 {
     MyBaseThing            = tBaseThing ?? new TheThing();
     MyBaseEngine           = pPluginBase.GetBaseEngine();
     MyBaseThing.EngineName = MyBaseEngine.GetEngineName();
     MyBaseThing.SetIThingObject(this);
     TheThingRegistry.RegisterThing(this);
 }