Opc.Ua.WindowsCertificateStore.Parse C# (CSharp) Method

Parse() private method

Parses the a string representing the store location.
private Parse ( string location ) : void
location string
return void
        private void Parse(string location)
        {
	        if (location == null) throw new ArgumentNullException("location");

	        location = location.Trim();

            if (String.IsNullOrEmpty(location))
            {
                throw ServiceResultException.Create(
                    StatusCodes.BadUnexpectedError,
                    "Store Location cannot be a empty string.");
            }

	        string hostName = null;
	        WindowsStoreType storeType = WindowsStoreType.LocalMachine;
	        string serviceNameOrUserSid = null;

	        int index = 0;

	        // extract host name.
	        if (location.StartsWith("\\\\", StringComparison.Ordinal))
	        {
		        hostName = location;

		        index = location.IndexOf('\\', 2);

		        if (index > 0)
		        {
			        hostName = hostName.Substring(2, index-2);
			        location = location.Substring(index+1);
		        }
	        }

	        // extract store type.
	        index = location.IndexOf('\\');

	        if (index == -1)
            {
                throw ServiceResultException.Create(
                    StatusCodes.BadUnexpectedError,
                    "Location does not specify a store name. Location={0}",
                    location);
	        }

	        string storeTypeName = location.Substring(0, index);

	        if (storeTypeName == "LocalMachine")
	        {
		        storeType = WindowsStoreType.LocalMachine;
	        }
	        else if (storeTypeName == "CurrentUser")
	        {
		        storeType = WindowsStoreType.CurrentUser;
	        }
	        else if (storeTypeName == "Service")
	        {
		        storeType = WindowsStoreType.Service;
	        }
	        else if (storeTypeName == "User")
	        {
		        storeType = WindowsStoreType.User;
	        }
	        else
            {
                throw ServiceResultException.Create(
                    StatusCodes.BadUnexpectedError,
                    "Location does not specify a valid store type. Location={0}",
                    location);
	        }
        		
	        location = location.Substring(index+1);

	        if (storeType == WindowsStoreType.Service || storeType == WindowsStoreType.User)
	        {
		        index = location.IndexOf('\\');

		        if (index == -1)
                {
                    throw ServiceResultException.Create(
                        StatusCodes.BadUnexpectedError,
                        "Location does not specify a store name. Location={0}",
                        location);
		        }

		        serviceNameOrUserSid = location.Substring(0, index);			
		        location = location.Substring(index+1);
	        }

	        m_hostName = hostName;
	        m_storeType = storeType;
	        m_serviceNameOrUserSid = serviceNameOrUserSid;
	        m_symbolicName = location;
	        m_displayName = GetStoreDisplayName(m_storeType, m_serviceNameOrUserSid, m_symbolicName);

            if (String.IsNullOrEmpty(m_symbolicName))
            {
                throw ServiceResultException.Create(
                    StatusCodes.BadUnexpectedError,
                    "Location does not specify a store name. Location={0}",
                    location);
            }
        }