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)); }
public void PostResult(AgentInstructions instructions, AgentInstructionsResult r) { DataPair[] results = r.Data; if (results == null) { throw new Exception("Get Initial Data received no response data"); } DataPair result = results.FirstOrDefault(x => x.Name == "initialData"); if (result == null || !(result.OutputValue is OpcInitialData)) { throw new Exception("Get Initial Data did not get the expected data"); } OpcInitialData initialData = result.OutputValue as OpcInitialData; string url = instructions.Data.FirstOrDefault(d => d.Name == "opcServerUrl")?.OutputValue as string; if (string.IsNullOrEmpty(url)) { throw new Exception("No URL found in agent instructions"); } bool?valuesOnly = instructions.Data.FirstOrDefault(d => d.Name == "valuesOnly")?.OutputValue as bool?; if (valuesOnly == false && initialData.Values == null) { throw new Exception("No values found in agent instructions"); } OPCEngine.HandleInitialData(url, initialData); }
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)); } }
public AgentInstructionsResult HandleInstructions(AgentInstructions instruction) { OpcCommunication.RemoveEventGroup( instruction.Data.GetValueByKey <string>("opcServerUrl"), instruction.Data.GetValueByKey <string>("eventId") ); return(new AgentInstructionsResult()); }
public AgentInstructionsResult HandleInstructions(AgentInstructions instruction) { OpcCommunication.SetTagValues( instruction.Data.GetValueByKey <string>("opcServerUrl"), instruction.Data.GetValueByKey <BaseTagValueWrapper>("valuesWrapper") ); return(new AgentInstructionsResult()); }
public AgentInstructionsResult HandleInstructions(AgentInstructions instruction) { OpcCommunication.StartListening( instruction.Data.GetValueByKey <string>("opcServerUrl"), instruction.Id, instruction.Data.GetValueByKey <OpcEventGroup[]>("eventGroups") ); return(new AgentInstructionsResult()); }
public AgentInstructionsResult HandleInstructions(AgentInstructions instruction) { OpcInitialData result = OpcCommunication.GetInitialData( instruction.Data.GetValueByKey <string>("opcServerUrl"), instruction.Data.GetValueByKey <bool>("valuesOnly") ); return(new AgentInstructionsResult { Data = new DataPair[] { new DataPair("initialData", result) } }); }
public static void RemoveEventGroup(string url, string agentId, string eventId) { AgentInstructions instr = new AgentInstructions() { Id = Guid.NewGuid().ToString(), EntityName = "Remove Event Group on " + url, MustBeCompletedBy = DateUtilities.Now(), AgentInstructionHanlderType = "Decisions.OPC.Agent.RemoveEventGroupInstructionHandler", Data = new[] { new DataPair("opcServerUrl", url), new DataPair("eventId", eventId), } }; AgentService.Instance.InstructAgent(new SystemUserContext(), agentId, instr); }
public static void GetInitialData(string url, string agentId, bool valuesOnly) { AgentInstructions instr = new AgentInstructions() { Id = Guid.NewGuid().ToString(), EntityName = "Get Initial Data on " + url, MustBeCompletedBy = DateUtilities.Now(), AgentInstructionHanlderType = "Decisions.OPC.Agent.GetInitialDataInstructionHandler", AgentResultsHandlerType = typeof(GetInitialDataResultHandler).FullName, Data = new[] { new DataPair("opcServerUrl", url), new DataPair("valuesOnly", valuesOnly), } }; AgentService.Instance.InstructAgent(new SystemUserContext(), agentId, instr); }
public static void SetTagValues(string url, string agentId, BaseTagValue[] values) { AgentInstructions instr = new AgentInstructions() { Id = Guid.NewGuid().ToString(), EntityName = "Set Tag Values on " + url, MustBeCompletedBy = DateUtilities.Now(), AgentInstructionHanlderType = "Decisions.OPC.Agent.SetTagValuesInstructionHandler", Data = new[] { new DataPair("opcServerUrl", url), new DataPair("valuesWrapper", new BaseTagValueWrapper { Values = values }), } }; AgentService.Instance.InstructAgent(new SystemUserContext(), agentId, instr); }
public static void StartListening(string url, string agentId, OpcEventGroup[] eventGroups) { AgentInstructions instr = new AgentInstructions() { Id = Guid.NewGuid().ToString(), EntityName = "Start Listening on " + url, MustBeCompletedBy = DateUtilities.Now(), AgentInstructionHanlderType = "Decisions.OPC.Agent.StartListeningInstructionHandler", AgentResultsHandlerType = typeof(StartListeningResultHandler).FullName, Data = new[] { new DataPair("opcServerUrl", url), new DataPair("eventGroups", eventGroups), } }; AgentService.Instance.InstructAgent(new SystemUserContext(), agentId, instr); string ignored; pingInstructionIdPerAgent.TryRemove(url + agentId, out ignored); pingInstructionIdPerAgent.TryAdd(url + agentId, instr.Id); }
public void PostTimeout(AgentInstructions instructions) { }
public void PostStatus(AgentInstructions instructions, DateTime statusDateTime, string statusMessage) { }
public void PostStart(AgentInstructions instructions) { }
public void PostError(AgentInstructions instructions, string errorDetails) { }
public void PostEnd(AgentInstructions instructions) { }
public AgentInstructionsResult HandleInstructions(AgentInstructions instruction) { OpcCommunication.StopListening(instruction.Data.GetValueByKey <string>("opcServerUrl")); return(new AgentInstructionsResult()); }