//======================================================================
        // Construction

        /// <summary>
        /// Initializes the object with the specifed COM server.
        /// </summary>
        internal Browser(Technosoftware.DaAeHdaClient.Com.Hda.Server server, IOPCHDA_Browser browser, TsCHdaBrowseFilter[] filters, OpcResult[] results)
        {
            if (browser == null)
            {
                throw new ArgumentNullException("browser");
            }

            // save the server object that created the browser.
            m_server = server;

            // save the COM server (released in Dispose()).
            m_browser = browser;

            // save only the filters that were accepted.
            if (filters != null)
            {
                ArrayList validFilters = new ArrayList();

                for (int ii = 0; ii < filters.Length; ii++)
                {
                    if (results[ii].Succeeded())
                    {
                        validFilters.Add(filters[ii]);
                    }
                }

                m_filters = new TsCHdaBrowseFilterCollection(validFilters);
            }
        }
Пример #2
0
        //======================================================================
        // IOpcFactory

        /// <summary>
        /// Creates a new instance of the server.
        /// </summary>
        public override IOpcServer CreateInstance(OpcUrl url, OpcConnectData connectData)
        {
            object comServer = Connect(url, connectData);

            if (comServer == null)
            {
                return(null);
            }

            Server server        = null;
            Type   interfaceType = null;

            try
            {
                if (String.IsNullOrEmpty(url.Scheme))
                {
                    throw new NotSupportedException(String.Format("The URL scheme '{0}' is not supported.", url.Scheme));
                }

                // DA
                else if (url.Scheme == OpcUrlScheme.DA)
                {
                    // Verify that it is a DA server.
                    if (!typeof(OpcRcw.Da.IOPCServer).IsInstanceOfType(comServer))
                    {
                        interfaceType = typeof(OpcRcw.Da.IOPCServer);
                        throw new NotSupportedException();
                    }

                    // DA 3.00
                    if (!ForceDa20Usage && typeof(OpcRcw.Da.IOPCBrowse).IsInstanceOfType(comServer) && typeof(OpcRcw.Da.IOPCItemIO).IsInstanceOfType(comServer))
                    {
                        server = new Technosoftware.DaAeHdaClient.Com.Da.Server(url, comServer);
                    }

                    // DA 2.XX
                    else if (typeof(OpcRcw.Da.IOPCItemProperties).IsInstanceOfType(comServer))
                    {
                        server = new Technosoftware.DaAeHdaClient.Com.Da20.Server(url, comServer);
                    }

                    else
                    {
                        interfaceType = typeof(OpcRcw.Da.IOPCItemProperties);
                        throw new NotSupportedException();
                    }
                }

                // AE
                else if (url.Scheme == OpcUrlScheme.AE)
                {
                    // Verify that it is a AE server.
                    if (!typeof(OpcRcw.Ae.IOPCEventServer).IsInstanceOfType(comServer))
                    {
                        interfaceType = typeof(OpcRcw.Ae.IOPCEventServer);
                        throw new NotSupportedException();
                    }

                    server = new Technosoftware.DaAeHdaClient.Com.Ae.Server(url, comServer);
                }

                // HDA
                else if (url.Scheme == OpcUrlScheme.HDA)
                {
                    // Verify that it is a HDA server.
                    if (!typeof(OpcRcw.Hda.IOPCHDA_Server).IsInstanceOfType(comServer))
                    {
                        interfaceType = typeof(OpcRcw.Hda.IOPCHDA_Server);
                        throw new NotSupportedException();
                    }

                    server = new Technosoftware.DaAeHdaClient.Com.Hda.Server(url, comServer);
                }

                // All other specifications not supported yet.
                else
                {
                    throw new NotSupportedException(String.Format("The URL scheme '{0}' is not supported.", url.Scheme));
                }
            }
            catch (NotSupportedException e)
            {
                Utilities.Interop.ReleaseServer(server);
                server = null;

                if (interfaceType != null)
                {
                    StringBuilder message = new StringBuilder();

                    message.AppendFormat("The COM server does not support the interface ");
                    message.AppendFormat("'{0}'.", interfaceType.FullName);
                    message.Append("\r\n\r\nThis problem could be caused by:\r\n");
                    message.Append("- incorrectly installed proxy/stubs.\r\n");
                    message.Append("- problems with the DCOM security settings.\r\n");
                    message.Append("- a personal firewall (sometimes activated by default).\r\n");

                    throw new NotSupportedException(message.ToString());
                }

                throw e;
            }
            catch (Exception e)
            {
                Utilities.Interop.ReleaseServer(server);
                server = null;

                throw e;
            }

            // initialize the wrapper object.
            if (server != null)
            {
                server.Initialize(url, connectData);
            }

            return(server);
        }