Esempio n. 1
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
                };
            }
        }
Esempio n. 2
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);
            }
        }