Beispiel #1
0
        // Token: 0x06000005 RID: 5 RVA: 0x000022C8 File Offset: 0x000012C8
        public Guid CLSIDFromProgID(string progID, string host, ConnectData connectData)
        {
            Guid result;

            lock (this)
            {
                NetworkCredential credential = (connectData != null) ? connectData.GetCredential(null, null) : null;
                this.m_server = (IOPCServerList2)Interop.CreateInstance(ServerEnumerator.CLSID, host, credential);
                this.m_host   = host;
                Guid empty;
                try
                {
                    this.m_server.CLSIDFromProgID(progID, out empty);
                }
                catch
                {
                    empty = Guid.Empty;
                }
                finally
                {
                    Interop.ReleaseServer(this.m_server);
                    this.m_server = null;
                }
                result = empty;
            }
            return(result);
        }
        /// <summary>
        /// Looks up the CLSID for the specified prog id on a remote host.
        /// </summary>
        public Guid CLSIDFromProgID(string progID, string host, ConnectData connectData)
        {
            lock (this)
            {
                NetworkCredential credentials = (connectData != null)?connectData.GetCredential(null, null):null;

                // connect to the server.
                m_server = (IOPCServerList2)OpcCom.Interop.CreateInstance(CLSID, host, credentials);
                m_host   = host;

                // lookup prog id.
                Guid clsid;

                try
                {
                    m_server.CLSIDFromProgID(progID, out clsid);
                }
                catch
                {
                    clsid = Guid.Empty;
                }
                finally
                {
                    OpcCom.Interop.ReleaseServer(m_server);
                    m_server = null;
                }

                // return empty guid if prog id not found.
                return(clsid);
            }
        }
        //======================================================================
        // Initialization

        /// <summary>
        /// Connects to the server with the specified URL and credentials.
        /// </summary>
        public virtual void Initialize(URL url, ConnectData connectData)
        {
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            lock (this)
            {
                try
                {
                    m_proxy             = new OpcXml.Da10.Service();
                    m_proxy.Credentials = (connectData != null)?connectData.GetCredential(null, null):null;
                    m_proxy.Url         = url.ToString();
                    m_proxy.Proxy       = (connectData != null)?connectData.GetProxy():new WebProxy();

                    m_proxy.UnsafeAuthenticatedConnectionSharing = true;
                }
                catch (Exception e)
                {
                    string msg = e.Message;
                }

                try
                {
                    GetStatus();
                }
                catch (WebException e)
                {
                    if (e.Status == WebExceptionStatus.ConnectFailure)
                    {
                        throw new ConnectFailedException(e);
                    }

                    throw new AccessDeniedException(e);
                }

                m_url = (URL)url.Clone();
            }
        }
        /// <summary>
        /// Returns a list of servers that support the specified specification on the specified host.
        /// </summary>
        public Opc.Server[] GetAvailableServers(Specification specification, string host, ConnectData connectData)
        {
            lock (this)
            {
                NetworkCredential credentials = (connectData != null)?connectData.GetCredential(null, null):null;

                // connect to the server.
                m_server = (IOPCServerList2)OpcCom.Interop.CreateInstance(CLSID, host, credentials);
                m_host   = host;

                try
                {
                    ArrayList servers = new ArrayList();

                    // convert the interface version to a guid.
                    Guid catid = new Guid(specification.ID);

                    // get list of servers in the specified specification.
                    IOPCEnumGUID enumerator = null;

                    m_server.EnumClassesOfCategories(
                        1,
                        new Guid[] { catid },
                        0,
                        null,
                        out enumerator);

                    // read clsids.
                    Guid[] clsids = ReadClasses(enumerator);

                    // release enumerator object.
                    OpcCom.Interop.ReleaseServer(enumerator);
                    enumerator = null;

                    // fetch class descriptions.
                    foreach (Guid clsid in clsids)
                    {
                        Factory factory = new OpcCom.Factory();

                        try
                        {
                            URL url = CreateUrl(specification, clsid);

                            Opc.Server server = null;

                            if (specification == Specification.COM_DA_30)
                            {
                                server = new Opc.Da.Server(factory, url);
                            }

                            else if (specification == Specification.COM_DA_20)
                            {
                                server = new Opc.Da.Server(factory, url);
                            }

                            else if (specification == Specification.COM_AE_10)
                            {
                                server = new Opc.Ae.Server(factory, url);
                            }

                            else if (specification == Specification.COM_HDA_10)
                            {
                                server = new Opc.Hda.Server(factory, url);
                            }

                            else if (specification == Specification.COM_DX_10)
                            {
                                server = new Opc.Dx.Server(factory, url);
                            }

                            servers.Add(server);
                        }
                        catch (Exception)
                        {
                            // ignore bad clsids.
                        }
                    }

                    return((Opc.Server[])servers.ToArray(typeof(Opc.Server)));
                }
                finally
                {
                    // free the server.
                    OpcCom.Interop.ReleaseServer(m_server);
                    m_server = null;
                }
            }
        }
 public Opc.Server[] GetAvailableServers(Specification specification, string host, ConnectData connectData)
 {
     Opc.Server[] serverArray;
     lock (this)
     {
         NetworkCredential credential = (connectData != null) ? connectData.GetCredential(null, null) : null;
         this.m_server = (IOPCServerList2)Interop.CreateInstance(CLSID, host, credential);
         this.m_host   = host;
         try
         {
             ArrayList    list        = new ArrayList();
             Guid         guid        = new Guid(specification.ID);
             IOPCEnumGUID ppenumClsid = null;
             Guid[]       rgcatidImpl = new Guid[] { guid };
             this.m_server.EnumClassesOfCategories(1, rgcatidImpl, 0, null, out ppenumClsid);
             Guid[] guidArray = this.ReadClasses(ppenumClsid);
             Interop.ReleaseServer(ppenumClsid);
             ppenumClsid = null;
             foreach (Guid guid2 in guidArray)
             {
                 OpcCom.Factory factory = new OpcCom.Factory();
                 try
                 {
                     URL        url    = this.CreateUrl(specification, guid2);
                     Opc.Server server = null;
                     if (specification == Specification.COM_DA_30)
                     {
                         server = new Opc.Da.Server(factory, url);
                     }
                     else if (specification == Specification.COM_DA_20)
                     {
                         server = new Opc.Da.Server(factory, url);
                     }
                     else if (specification == Specification.COM_AE_10)
                     {
                         server = new Opc.Ae.Server(factory, url);
                     }
                     else if (specification == Specification.COM_HDA_10)
                     {
                         server = new Opc.Hda.Server(factory, url);
                     }
                     else if (specification == Specification.COM_DX_10)
                     {
                         server = new Opc.Dx.Server(factory, url);
                     }
                     list.Add(server);
                 }
                 catch (Exception)
                 {
                 }
             }
             serverArray = (Opc.Server[])list.ToArray(typeof(Opc.Server));
         }
         finally
         {
             Interop.ReleaseServer(this.m_server);
             this.m_server = null;
         }
     }
     return(serverArray);
 }
Beispiel #6
0
        public static object Connect(URL url, ConnectData connectData)
        {
            string text  = url.Path;
            string text2 = null;
            int    num   = url.Path.LastIndexOf('/');

            if (num >= 0)
            {
                text  = url.Path.Substring(0, num);
                text2 = url.Path.Substring(num + 1);
            }

            Guid guid;

            if (text2 == null)
            {
                guid = new ServerEnumerator().CLSIDFromProgID(text, url.HostName, connectData);
                if (guid == Guid.Empty)
                {
                    try
                    {
                        guid = new Guid(text);
                    }
                    catch
                    {
                        throw new ConnectFailedException(text);
                    }
                }
            }
            else
            {
                try
                {
                    guid = new Guid(text2);
                }
                catch
                {
                    throw new ConnectFailedException(text2);
                }
            }

            NetworkCredential credential = connectData?.GetCredential(null, null);

            if (connectData == null || connectData.LicenseKey == null)
            {
                try
                {
                    return(Interop.CreateInstance(guid, url.HostName, credential));
                }
                catch (Exception e)
                {
                    throw new ConnectFailedException(e);
                }
            }

            try
            {
                return(Interop.CreateInstanceWithLicenseKey(guid, url.HostName, credential, connectData.LicenseKey));
            }
            catch (Exception e2)
            {
                throw new ConnectFailedException(e2);
            }
        }
Beispiel #7
0
        public static object Connect(URL url, ConnectData connectData)
        {
            Guid guid;
            NetworkCredential credential;
            object            obj2;
            string            path = url.Path;
            string            g    = null;
            int index = url.Path.IndexOf('/');

            if (index >= 0)
            {
                path = url.Path.Substring(0, index);
                g    = url.Path.Substring(index + 1);
            }
            if (g == null)
            {
                guid = new ServerEnumerator().CLSIDFromProgID(path, url.HostName, connectData);
                if (!(guid == Guid.Empty))
                {
                    goto Label_007F;
                }
                try
                {
                    guid = new Guid(path);
                    goto Label_007F;
                }
                catch
                {
                    throw new ConnectFailedException(path);
                }
            }
            try
            {
                guid = new Guid(g);
            }
            catch
            {
                throw new ConnectFailedException(g);
            }
Label_007F:
            credential = (connectData != null) ? connectData.GetCredential(null, null) : null;
            if ((connectData == null) || (connectData.LicenseKey == null))
            {
                try
                {
                    return(OpcCom.Interop.CreateInstance(guid, url.HostName, credential));
                }
                catch (Exception exception)
                {
                    throw new ConnectFailedException(exception);
                }
            }
            try
            {
                obj2 = OpcCom.Interop.CreateInstanceWithLicenseKey(guid, url.HostName, credential, connectData.LicenseKey);
            }
            catch (Exception exception2)
            {
                throw new ConnectFailedException(exception2);
            }
            return(obj2);
        }
Beispiel #8
0
 // Token: 0x06000004 RID: 4 RVA: 0x000020E4 File Offset: 0x000010E4
 public Opc.Server[] GetAvailableServers(Specification specification, string host, ConnectData connectData)
 {
     Opc.Server[] result;
     lock (this)
     {
         NetworkCredential credential = (connectData != null) ? connectData.GetCredential(null, null) : null;
         this.m_server = (IOPCServerList2)Interop.CreateInstance(ServerEnumerator.CLSID, host, credential);
         this.m_host   = host;
         try
         {
             ArrayList    arrayList    = new ArrayList();
             Guid         guid         = new Guid(specification.ID);
             IOPCEnumGUID iopcenumGUID = null;
             this.m_server.EnumClassesOfCategories(1, new Guid[]
             {
                 guid
             }, 0, null, out iopcenumGUID);
             Guid[] array = this.ReadClasses(iopcenumGUID);
             Interop.ReleaseServer(iopcenumGUID);
             iopcenumGUID = null;
             foreach (Guid clsid in array)
             {
                 Factory factory = new Factory();
                 try
                 {
                     URL        url   = this.CreateUrl(specification, clsid);
                     Opc.Server value = null;
                     if (specification == Specification.COM_DA_30)
                     {
                         value = new Opc.Da.Server(factory, url);
                     }
                     else if (specification == Specification.COM_DA_20)
                     {
                         value = new Opc.Da.Server(factory, url);
                     }
                     else if (specification == Specification.COM_AE_10)
                     {
                         value = new Opc.Ae.Server(factory, url);
                     }
                     else if (specification == Specification.COM_HDA_10)
                     {
                         value = new Opc.Hda.Server(factory, url);
                     }
                     else if (specification == Specification.COM_DX_10)
                     {
                         value = new Opc.Dx.Server(factory, url);
                     }
                     arrayList.Add(value);
                 }
                 catch (Exception)
                 {
                 }
             }
             result = (Opc.Server[])arrayList.ToArray(typeof(Opc.Server));
         }
         finally
         {
             Interop.ReleaseServer(this.m_server);
             this.m_server = null;
         }
     }
     return(result);
 }