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)); } }