예제 #1
0
        public static List <Tuple <string, SystemUnitClassType> > FindAllMtpPictures(CAEXFileType aml)
        {
            // start
            var res = new List <Tuple <string, SystemUnitClassType> >();

            // assumption: all pictures are on the 1st level of a instance hierarchy ..
            foreach (var ih in aml.InstanceHierarchy)
            {
                foreach (var ie in ih.InternalElement)
                {
                    if (ie.RefBaseSystemUnitPath.Trim() == "MTPHMISUCLib/Picture")
                    {
                        res.Add(new Tuple <string, SystemUnitClassType>(ie.Name, ie));
                    }
                }
            }

            // ok
            return(res);
        }
예제 #2
0
        public static void CreateDataSources(
            IMtpDataSourceFactoryOpcUa dataSourceFactory,
            MtpDataSourceOpcUaPreLoadInfo preLoadInfo,
            CAEXFileType aml)
        {
            // access
            if (dataSourceFactory == null || aml == null)
            {
                return;
            }

            // assumption: all instances are on a fixed level of a instance hierarchy ..
            foreach (var ih in aml.InstanceHierarchy)                               // e.g.: ModuleTypePackage
            {
                foreach (var ie in ih.InternalElement)                              // e.g. Class = ModuleTypePackage
                {
                    foreach (var ie2 in ie.InternalElement)                         // e.g. CommunicationSet
                    {
                        foreach (var ie3 in ie2.InternalElement)                    // e.g. InstanceList
                        {
                            if (ie3.RefBaseSystemUnitPath.Trim() == "MTPSUCLib/CommunicationSet/SourceList")
                            {
                                foreach (var server in ie3.InternalElement)     // now on server
                                {
                                    // check if server valid
                                    if (server.RefBaseSystemUnitPath.Trim() !=
                                        "MTPCommunicationSUCLib/ServerAssembly/OPCUAServer")
                                    {
                                        continue;
                                    }
                                    if (!server.Name.HasContent())
                                    {
                                        continue;
                                    }

                                    // get attributes
                                    var ep = FindAttributeValueByName(server.Attribute, "Endpoint");

                                    // mapping??
                                    if (preLoadInfo?.EndpointMapping != null)
                                    {
                                        foreach (var epm in preLoadInfo.EndpointMapping)
                                        {
                                            if (epm?.IsValid == true &&
                                                (server.Name.Trim() == epm.ForName?.Trim() ||
                                                 server.ID.Trim() == epm.ForId?.Trim()))
                                            {
                                                ep = epm.NewEndpoint?.Trim();
                                            }
                                        }
                                    }

                                    // check endpoint
                                    if (!ep.HasContent())
                                    {
                                        continue;
                                    }

                                    // make server
                                    var serv = dataSourceFactory.CreateOrUseUaServer(ep);
                                    if (serv == null)
                                    {
                                        continue;
                                    }

                                    // go into items
                                    foreach (var item in server.ExternalInterface)
                                    {
                                        // check to item
                                        // TODO (MIHO, 2020-08-06): spec/example files seem not to be in a final state
                                        // check for the final role/class names to be used
                                        if (!item.RefBaseClassPath.Trim().Contains("OPCUAItem"))
                                        {
                                            continue;
                                        }

                                        // get attributes
                                        var id = FindAttributeValueByName(item.Attribute, "Identifier");
                                        var ns = FindAttributeValueByName(item.Attribute, "Namespace");
                                        var ac = FindAttributeValueByName(item.Attribute, "Access");

                                        // potential renaming?
                                        if (preLoadInfo?.IdentifierRenaming != null)
                                        {
                                            foreach (var ren in preLoadInfo.IdentifierRenaming)
                                            {
                                                id = ren.DoReplacement(id);
                                            }
                                        }

                                        if (preLoadInfo?.NamespaceRenaming != null)
                                        {
                                            foreach (var ren in preLoadInfo.NamespaceRenaming)
                                            {
                                                ns = ren.DoReplacement(ns);
                                            }
                                        }

                                        // create
                                        // ReSharper disable once UnusedVariable
                                        var it = dataSourceFactory.CreateOrUseItem(serv, id, ns, ac, item.ID);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
        public static Dictionary <string, SystemUnitClassType> FindAllDynamicInstances(CAEXFileType aml)
        {
            // start
            var res = new Dictionary <string, SystemUnitClassType>(StringComparer.InvariantCultureIgnoreCase);

            if (aml == null)
            {
                return(res);
            }

            // assumption: all instances are on a fixed level of a instance hierarchy ..
            foreach (var ih in aml.InstanceHierarchy)                   // e.g.: ModuleTypePackage
            {
                foreach (var ie in ih.InternalElement)                  // e.g. Class = ModuleTypePackage
                {
                    foreach (var ie2 in ie.InternalElement)             // e.g. CommunicationSet
                    {
                        foreach (var ie3 in ie2.InternalElement)        // e.g. InstanceList
                        {
                            if (ie3.RefBaseSystemUnitPath.Trim() == "MTPSUCLib/CommunicationSet/InstanceList")
                            {
                                foreach (var ie4 in ie3.InternalElement)     // now ALWAYS an dynamic instance
                                {
                                    var refID = MtpAmlHelper.FindAttributeValueByName(ie4.Attribute, "RefID");
                                    if (refID != null && refID.Length > 0)
                                    {
                                        res.Add(refID, ie4);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // ok
            return(res);
        }
예제 #4
0
        public static void CreateDataSources(IMtpDataSourceFactoryOpcUa dataSourceFactory, CAEXFileType aml)
        {
            // access
            if (dataSourceFactory == null || aml == null)
            {
                return;
            }

            // assumption: all instances are on a fixed level of a instance hierarchy ..
            foreach (var ih in aml.InstanceHierarchy)                               // e.g.: ModuleTypePackage
            {
                foreach (var ie in ih.InternalElement)                              // e.g. Class = ModuleTypePackage
                {
                    foreach (var ie2 in ie.InternalElement)                         // e.g. CommunicationSet
                    {
                        foreach (var ie3 in ie2.InternalElement)                    // e.g. InstanceList
                        {
                            if (ie3.RefBaseSystemUnitPath.Trim() == "MTPSUCLib/CommunicationSet/SourceList")
                            {
                                foreach (var server in ie3.InternalElement)     // now on server
                                {
                                    // check if server
                                    if (server.RefBaseSystemUnitPath.Trim() !=
                                        "MTPCommunicationSUCLib/ServerAssembly/OPCUAServer")
                                    {
                                        continue;
                                    }

                                    // get attributes
                                    var ep = FindAttributeValueByName(server.Attribute, "Endpoint");
                                    if (ep == null || ep.Trim().Length < 1)
                                    {
                                        continue;
                                    }

                                    // make server
                                    var serv = dataSourceFactory.CreateOrUseUaServer(ep);
                                    if (serv == null)
                                    {
                                        continue;
                                    }

                                    // go into items
                                    foreach (var item in server.ExternalInterface)
                                    {
                                        // check fo item
                                        // TODO (MIHO, 2020-08-06): spec/example files seem not to be in a final state
                                        // check for the final role/class names to be used
                                        if (!item.RefBaseClassPath.Trim().Contains("OPCUAItem"))
                                        {
                                            continue;
                                        }

                                        // get attributes
                                        var id = FindAttributeValueByName(item.Attribute, "Identifier");
                                        var ns = FindAttributeValueByName(item.Attribute, "Namespace");
                                        var ac = FindAttributeValueByName(item.Attribute, "Access");

                                        // create
                                        // ReSharper disable once UnusedVariable
                                        var it = dataSourceFactory.CreateOrUseItem(serv, id, ns, ac, item.ID);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }