Beispiel #1
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");
        }
        public ResultData Run(StepStartData data)
        {
            object value = data.Data[VALUE_INPUT];

            OPCTag tag;
            string serverUrl;

            if (chooseTagAtRuntime)
            {
                string tagPath = data.Data[TAG_INPUT] as string;
                serverUrl = data.Data[SERVER_URL_INPUT] as string;
                if (string.IsNullOrEmpty(tagPath))
                {
                    throw new Exception("No tag specified");
                }
                if (string.IsNullOrEmpty(serverUrl))
                {
                    throw new Exception("No server URL specified");
                }
                tag = EntityCache <OPCTag> .GetCache().AllEntities.FirstOrDefault(x => x.Path == tagPath && x.ServerUrl == serverUrl);

                if (tag == null)
                {
                    throw new Exception($"No tag found at '{tagPath}' on server '{serverUrl}'");
                }
            }
            else
            {
                tag = EntityCache <OPCTag> .GetCache().GetById(tagId);

                if (tag == null)
                {
                    throw new Exception($"Tag '{tagId}' not found");
                }
                serverUrl = tag.ServerUrl;
            }

            BaseTagValue tagValue = TagValueUtils.GetTagWithValue(TypeUtilities.FindTypeByFullName(tag.TypeName), value);

            tagValue.Path = tag.Path;

            OPCServerFolderBehaviorData folderExt = EntityCache <OPCServerFolderBehaviorData> .GetCache().AllEntities.FirstOrDefault(s => s.Url == serverUrl);

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

            if (folder == null)
            {
                throw new Exception($"No server folder configured for URL '{serverUrl}'.");
            }

            OPCEngine.SetTagValues(serverUrl, folderExt.AgentId, new BaseTagValue[] { tagValue });

            return(new ResultData(PATH_DONE, new KeyValuePair <string, object>[] { }));
        }