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);
        }
Exemple #2
0
        internal static void HandleInitialData(string url, OpcInitialData initialData)
        {
            log.Debug("HandleInitialData entered");
            OPCServerFolderBehaviorData folderExt = EntityCache <OPCServerFolderBehaviorData> .GetCache().AllEntities.FirstOrDefault(s => s.Url == url);

            Folder f = folderExt?.GetEntity() as Folder;

            if (f == null)
            {
                throw new Exception("No OPC server found with this URL");
            }

            if (initialData.Nodes != null)
            {
                UpdateTagsInFolder(f.FolderID + ".tagdata", f.FolderID, url, initialData.Nodes);
            }

            string[] eventIds = FolderService.GetFolderEntities <OPCEvent>(f.FolderID).Select(e => e.Id).ToArray();

            foreach (BaseTagValue value in initialData.Values)
            {
                // Record the value separately for each event, because they might update at different rates:
                foreach (string eventId in eventIds)
                {
                    string key = eventId + "|" + value.Path;
                    OPCEngine.mostRecentValues[key] = value;
                }
            }

            log.Debug("HandleInitialData complete");
        }