public void PostResult(AgentInstructions instructions, AgentInstructionsResult r)
        {
            string url = instructions.Data.GetValueByKey <string>("opcServerUrl");

            if (string.IsNullOrEmpty(url))
            {
                return;
            }
            Folder configFolder = EntityCache <OPCServerFolderBehaviorData> .GetCache().AllEntities.FirstOrDefault(s => s.Url == url)?.GetEntity() as Folder;

            if (configFolder == null)
            {
                return;
            }

            DateTime now           = DateTime.UtcNow;
            bool     refreshFolder = true;
            DateTime?lastTime;

            if (OPCEngine.lastPingTimePerInstruction.TryGetValue(instructions.Id, out lastTime) && lastTime != null)
            {
                refreshFolder = (lastTime.Value.AddSeconds(OPCEngine.LATE_PING_VALUE - 1) < now);
            }
            OPCEngine.lastPingTimePerInstruction.AddOrUpdate(instructions.Id, now, (s, dt) => now);

            if (refreshFolder)
            {
                ClientEventsService.SendEvent(FolderMessage.FolderChangeEventId, new FolderChangedMessage(configFolder.FolderID));
            }
        }
Пример #2
0
        public static void StopListening(string url, string agentId)
        {
            AgentInstructions instr = new AgentInstructions()
            {
                Id                          = Guid.NewGuid().ToString(),
                EntityName                  = "Stop Listening on " + url,
                MustBeCompletedBy           = DateUtilities.Now(),
                AgentInstructionHanlderType = "Decisions.OPC.Agent.StopListeningInstructionHandler",
                Data                        = new[]
                {
                    new DataPair("opcServerUrl", url),
                }
            };

            AgentService.Instance.InstructAgent(new SystemUserContext(), agentId, instr);

            string ignored; // Forget this instruction & refresh folder, so IsListening will immediately switch to false:

            pingInstructionIdPerAgent.TryRemove(url + agentId, out ignored);

            Folder configFolder = EntityCache <OPCServerFolderBehaviorData> .GetCache().AllEntities.FirstOrDefault(s => s.Url == url)?.GetEntity() as Folder;

            if (configFolder == null)
            {
                return;
            }
            ClientEventsService.SendEvent(FolderMessage.FolderChangeEventId, new FolderChangedMessage(configFolder.FolderID));
        }