Esempio n. 1
0
        /// <summary>
        /// Sends back to the originator
        /// </summary>
        /// <param name="sourceMessage">Original Message to reply to</param>
        /// <param name="TargetMessage">New message to be sent to originator</param>
        /// <param name="IncludeLocalNode">if true the message will be sent to localhost</param>
        /// <returns></returns>
        public bool SendToOriginator(TSM sourceMessage, TSM TargetMessage, bool IncludeLocalNode)
        {
            if (sourceMessage == null || TargetMessage == null)
            {
                return(false);
            }
            TargetMessage.SID = sourceMessage.SID;
            Guid tOrg = sourceMessage.GetOriginator();

            if (tOrg == Guid.Empty)
            {
                return(false);
            }
            TargetMessage.GRO = sourceMessage.ORG;
            Guid tOriginatorThing = sourceMessage.GetOriginatorThing();

            if (tOriginatorThing != Guid.Empty)
            {
                TargetMessage.OWN = tOriginatorThing.ToString();
            }
            if (IncludeLocalNode)
            {
                TheBaseAssets.LocalHostQSender.SendQueued(TheBaseAssets.MyScopeManager.AddScopeID("CDE_SYSTEMWIDE;" + FNI, null, ref sourceMessage.SID, true, false), TargetMessage, false, TheBaseAssets.MyServiceHostInfo.MyDeviceInfo.DeviceID, "CDE_SYSTEMWIDE", RS, null); //GRSI: rare
            }
            return(MyQSender.SendQueued(TheBaseAssets.MyScopeManager.AddScopeID("CDE_SYSTEMWIDE;" + tOrg, null, ref sourceMessage.SID, true, false), TargetMessage, false, tOrg, "CDE_SYSTEMWIDE", RS, null));                                                                  //GRSI: rare
        }
Esempio n. 2
0
 /// <summary>
 /// Synchronously checks if a node is the current owner for a source.
 /// </summary>
 /// <param name="sourceORG"></param>
 /// <param name="ownerORG"></param>
 /// <returns></returns>
 internal bool?CheckOwner(string sourceORG, string ownerORG)
 {
     if (_nodeOwners.TryGetValue(TSM.GetOriginator(sourceORG), out var nodeInfo))
     {
         if (TSM.GetOriginator(nodeInfo.OwnerORG) == TSM.GetOriginator(ownerORG))
         {
             return(true);
         }
         return(false);
     }
     return(null);
 }
Esempio n. 3
0
 /// <summary>
 /// Call this Method to tell the C-DEngine and "EngineInitialized" registrars that the service has been successfully initialized
 /// The Event is fired synchronous and fires BEFORE the EngineState.IsInitialized is set to true. This allows event recceivers to check if the Engine has been initialized before
 /// </summary>
 /// <param name="pMessage"></param>
 public void SetInitialized(TSM pMessage)
 {
     if (EngineState.ServiceNode == Guid.Empty || EngineState.IsInitializing)
     {
         EngineState.ServiceNode = pMessage?.GetOriginator() ?? TheBaseAssets.MyServiceHostInfo.MyDeviceInfo.DeviceID;
     }
     ResetInitialization();
     //if (MyBaseThing != null)
     //    MyBaseThing.GetBaseThing().FireEvent(eEngineEvents.EngineInitialized, MyBaseThing, null, false);
     //EngineState.IsInitialized = true;
     SetEngineReadiness(true, null);
 }
Esempio n. 4
0
        public void SendCPUInfo(TSM message)
        {
            Guid originator = message.GetOriginator();

            if (originator == Guid.Empty)
            {
                SendCPUInfo(originator);
            }
            else
            {
                GetCPUInfo(TheBaseAssets.MyServiceHostInfo.GetPrimaryStationURL(false));
                TSM tMsg = new TSM(MyEngineName, "CPUINFO", TheCommonUtils.SerializeObjectToJSONString <TheCPUInfo>(MyCPUInfoData));
                tMsg.SetNoDuplicates(true);
                TheCommCore.PublishToOriginator(message, tMsg, true);
                TheBaseAssets.MySYSLOG.WriteToLog(8003, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : tMsg);
            }
        }
Esempio n. 5
0
        public void SendHealthInfo(TSM message)
        {
            Guid originator = message.GetOriginator();

            if (originator == Guid.Empty)
            {
                SendHealthInfo(originator);
            }
            else
            {
                GetISMHealthData();
                TSM tMsg = new TSM(MyEngineName, "ISMHEALTH", TheCommonUtils.SerializeObjectToJSONString <TheServiceHealthData>(MyHealthData));
                tMsg.SetNoDuplicates(true);
                TheCommCore.PublishToOriginator(message, tMsg, true);
                eventNewHealthData?.Invoke(MyHealthData);
                TheBaseAssets.MySYSLOG.WriteToLog(8004, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : tMsg);
            }
        }
Esempio n. 6
0
            /// <summary>
            /// Registers an owner for a given source
            /// </summary>
            /// <param name="correlationToken"></param>
            /// <param name="sourceORG"></param>
            /// <param name="ownerORG"></param>
            /// <param name="bIsTargeted"></param>
            /// <returns>true if the owner has changed or was newly registered</returns>
            internal bool RegisterOwnerCandidate(string correlationToken, string sourceORG, string ownerORG, bool bIsTargeted)
            {
                string previousOwnerORG = null;
                var    newOwnerInfo     = _nodeOwners.AddOrUpdate(TSM.GetOriginator(sourceORG), new NodeOwnerInfo {
                    OwnerORG = ownerORG, SourceORG = sourceORG, WasTarget = bIsTargeted, TimeObserved = DateTimeOffset.Now
                }, (s, nodeInfo) =>
                {
                    if (bIsTargeted || !nodeInfo.WasTarget || nodeInfo.TimeObserved < DateTimeOffset.Now - new TimeSpan(0, 5, 0))
                    {
                        previousOwnerORG      = nodeInfo.OwnerORG;
                        nodeInfo.OwnerORG     = ownerORG;
                        nodeInfo.WasTarget    = bIsTargeted;
                        nodeInfo.TimeObserved = DateTimeOffset.Now;
                    }
                    return(nodeInfo);
                });

                _pendingAcks.RemoveNoCare(correlationToken);
                return(TSM.GetOriginator(newOwnerInfo.OwnerORG) != TSM.GetOriginator(previousOwnerORG));
            }