public ParseUrl ( |
||
uri | The URI. | |
Résultat |
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;
}
/// <summary> /// Gets the available servers. /// </summary> /// <param name="factory">The factory.</param> /// <param name="specification">The specification.</param> private void GetAvailableServers(Opc.Ua.Com.ServerFactory factory, Specification specification) { Uri[] serverUrls = factory.GetAvailableServers(specification); for (int ii = 0; ii < serverUrls.Length; ii++) { ComServerDescription server = factory.ParseUrl(serverUrls[ii]); // don't wrap proxies. if (ConfigUtils.CLSID_UaComDaProxyServer == server.Clsid) { continue; } if (ConfigUtils.CLSID_UaComAeProxyServer == server.Clsid) { continue; } if (ConfigUtils.CLSID_UaComHdaProxyServer == server.Clsid) { continue; } // don't wrap UA psuedo-servers. List <Guid> catids = ConfigUtils.GetImplementedCategories(server.Clsid); bool suppress = false; for (int jj = 0; jj < catids.Count; jj++) { if (catids[jj] == ConfigUtils.CATID_PseudoComServers) { suppress = true; break; } } if (suppress) { continue; } // assume regular COM server. ListViewItem item = new ListViewItem(server.ProgId); item.SubItems.Add(server.Description); item.SubItems.Add(specification.ToString()); item.Tag = new Item(specification, server); ServersLV.Items.Add(item); } }