Opc.Ua.Configuration.PseudoComServer.CreateProgIdFromUrl C# (CSharp) Method

CreateProgIdFromUrl() public static method

Creates a ProgId from a URI
public static CreateProgIdFromUrl ( ComSpecification specification, string uri ) : string
specification ComSpecification
uri string
return string
        public static string CreateProgIdFromUrl(ComSpecification specification, string uri)
        {           
            if (String.IsNullOrEmpty(uri))
            {
                return null;
            }

            StringBuilder buffer = new StringBuilder();

            switch (specification)
            {
                case ComSpecification.DA:
                {
                    buffer.Append("OpcDa.");
                    break;
                }

                case ComSpecification.AE:
                {
                    buffer.Append("OpcAe.");
                    break;
                }

                case ComSpecification.HDA:
                {
                    buffer.Append("OpcHda.");
                    break;
                }
            }

            bool punctuation = false;

            for (int ii = 0; ii < uri.Length; ii++)
            {
                switch (uri[ii])
                {
                    case '/':
                    case ':':
                    case '?':
                    case '&':
                    case '%':
                    {
                        if (!punctuation)
                        {
                            buffer.Append('.');
                        }

                        punctuation = true;
                        break;
                    }

                    default:
                    {
                        buffer.Append(uri[ii]);
                        punctuation = false;
                        break;
                    }
                }
            }                 
            
            return buffer.ToString();       
        }

Usage Example

コード例 #1
0
        private void ConfigureEndpoint(ConfiguredEndpoint endpoint)
        {
            EndpointComIdentity comIdentity = endpoint.ComIdentity;

            if (comIdentity == null)
            {
                comIdentity = new EndpointComIdentity();
                comIdentity.Specification = ComSpecification.DA;
                endpoint.ComIdentity      = comIdentity;
            }

            string oldProgId = PseudoComServer.CreateProgIdFromUrl(endpoint.ComIdentity.Specification, endpoint.EndpointUrl.ToString());

            endpoint = new ConfiguredServerDlg().ShowDialog(endpoint, m_configuration);

            if (endpoint == null)
            {
                return;
            }

            if (String.IsNullOrEmpty(comIdentity.ProgId) || oldProgId == comIdentity.ProgId)
            {
                comIdentity.ProgId = PseudoComServer.CreateProgIdFromUrl(endpoint.ComIdentity.Specification, endpoint.EndpointUrl.ToString());

                if (comIdentity.Clsid == Guid.Empty)
                {
                    comIdentity.Clsid = Guid.NewGuid();
                }
            }

            m_endpoint      = endpoint;
            EndpointTB.Text = m_endpoint.EndpointUrl.ToString();
        }