Stores the description of a COM server.
Exemplo n.º 1
0
        /// <summary>
        /// Parses the URL and fetches the information about the server.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <returns>The server description.</returns>
        public ComServerDescription ParseUrl(Uri uri)
        {
            // parse path to find prog id and clsid.
            string progID = uri.LocalPath;
            string clsid  = null;

            while (progID.StartsWith("/"))
            {
                progID = progID.Substring(1);
            }

            int index = progID.IndexOf('/');

            if (index >= 0)
            {
                clsid  = progID.Substring(index+1);
                progID = progID.Substring(0, index);
            }

            // look up prog id if clsid not specified in the uri.
            Guid guid = Guid.Empty;

            if (String.IsNullOrEmpty(clsid))
            {
                // use OpcEnum to lookup the prog id.
                guid = CLSIDFromProgID(progID);

                // check if prog id is actually a clsid string.
                if (guid == Guid.Empty)
                {
                    clsid = progID;
                }
            }

            // convert CLSID to a GUID.
            if (guid == Guid.Empty)
            {
                try
                {
                    guid = new Guid(clsid);
                }
                catch (Exception e)
                {
                    throw ServiceResultException.Create(StatusCodes.BadCommunicationError, e, "COM server URI does not contain a valid CLSID or ProgID.");
                }
            }

            ComServerDescription server = new ComServerDescription();

            server.Url = uri.ToString();
            server.Clsid = guid;
            server.ProgId = progID;
            server.VersionIndependentProgId = server.ProgId;
            server.Description = progID;

			try
			{
				// fetch class details from the enumerator.
				string description  = null;
				string verIndProgID = null;

				m_server.GetClassDetails(
					ref guid, 
					out progID, 
					out description, 
					out verIndProgID);                
				
				// use version independent prog id if available.
				if (!String.IsNullOrEmpty(verIndProgID))
				{
                    progID = verIndProgID;
                }

                server.Url = uri.ToString();
                server.Clsid = guid;
                server.ProgId = progID;
                server.VersionIndependentProgId = verIndProgID;
                server.Description = description;
			}
			catch
			{
                server.Url = uri.ToString();
                server.Clsid = guid;
                server.ProgId = progID;
                server.VersionIndependentProgId = server.ProgId;
                server.Description = guid.ToString();
			}

			// return the server uri.
            return server;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parses the URL and fetches the information about the server.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <returns>The server description.</returns>
        public ComServerDescription ParseUrl(Uri uri)
        {
            // parse path to find prog id and clsid.
            string progID = uri.LocalPath;
            string clsid  = null;

            while (progID.StartsWith("/"))
            {
                progID = progID.Substring(1);
            }

            int index = progID.IndexOf('/');

            if (index >= 0)
            {
                clsid  = progID.Substring(index + 1);
                progID = progID.Substring(0, index);
            }

            // look up prog id if clsid not specified in the uri.
            Guid guid = Guid.Empty;

            if (String.IsNullOrEmpty(clsid))
            {
                // use OpcEnum to lookup the prog id.
                guid = CLSIDFromProgID(progID);

                // check if prog id is actually a clsid string.
                if (guid == Guid.Empty)
                {
                    clsid = progID;
                }
            }

            // convert CLSID to a GUID.
            if (guid == Guid.Empty)
            {
                try
                {
                    guid = new Guid(clsid);
                }
                catch (Exception e)
                {
                    throw ServiceResultException.Create(StatusCodes.BadCommunicationError, e, "COM server URI does not contain a valid CLSID or ProgID.");
                }
            }

            ComServerDescription server = new ComServerDescription();

            server.Url    = uri.ToString();
            server.Clsid  = guid;
            server.ProgId = progID;
            server.VersionIndependentProgId = server.ProgId;
            server.Description = progID;

            try
            {
                // fetch class details from the enumerator.
                string description  = null;
                string verIndProgID = null;

                m_server.GetClassDetails(
                    ref guid,
                    out progID,
                    out description,
                    out verIndProgID);

                // use version independent prog id if available.
                if (!String.IsNullOrEmpty(verIndProgID))
                {
                    progID = verIndProgID;
                }

                server.Url    = uri.ToString();
                server.Clsid  = guid;
                server.ProgId = progID;
                server.VersionIndependentProgId = verIndProgID;
                server.Description = description;
            }
            catch
            {
                server.Url    = uri.ToString();
                server.Clsid  = guid;
                server.ProgId = progID;
                server.VersionIndependentProgId = server.ProgId;
                server.Description = guid.ToString();
            }

            // return the server uri.
            return(server);
        }
Exemplo n.º 3
0
 public Item(Specification specification, ComServerDescription server)
 {
     Specification = specification;
     Server = server;
 }