//====================================================================== // Construction /// <summary> /// Initializes the object with the specifed COM server. /// </summary> internal Browser(OpcCom.Hda.Server server, IOPCHDA_Browser browser, BrowseFilter[] filters, ResultID[] 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 BrowseFilterCollection(validFilters); } }
public virtual void Dispose() { lock (this) { this.m_server = null; OpcCom.Interop.ReleaseServer(this.m_browser); this.m_browser = null; } }
internal Browser(OpcCom.Hda.Server server, IOPCHDA_Browser browser, BrowseFilter[] filters, ResultID[] results) { if (browser == null) { throw new ArgumentNullException("browser"); } this.m_server = server; this.m_browser = browser; if (filters != null) { ArrayList collection = new ArrayList(); for (int i = 0; i < filters.Length; i++) { if (results[i].Succeeded()) { collection.Add(filters[i]); } } this.m_filters = new BrowseFilterCollection(collection); } }
//====================================================================== // IFactory /// <summary> /// Creates a new instance of the server. /// </summary> public override Opc.IServer CreateInstance(Opc.URL url, Opc.ConnectData connectData) { object comServer = Factory.Connect(url, connectData); if (comServer == null) { return(null); } OpcCom.Server server = null; System.Type interfaceType = null; try { // DA if (url.Scheme == Opc.UrlScheme.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 (typeof(OpcRcw.Da.IOPCBrowse).IsInstanceOfType(comServer) && typeof(OpcRcw.Da.IOPCItemIO).IsInstanceOfType(comServer)) { server = new OpcCom.Da.Server(url, comServer); } // DA 2.XX else if (typeof(OpcRcw.Da.IOPCItemProperties).IsInstanceOfType(comServer)) { server = new OpcCom.Da20.Server(url, comServer); } else { interfaceType = typeof(OpcRcw.Da.IOPCItemProperties); throw new NotSupportedException(); } } // AE else if (url.Scheme == Opc.UrlScheme.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 OpcCom.Ae.Server(url, comServer); } // HDA else if (url.Scheme == Opc.UrlScheme.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 OpcCom.Hda.Server(url, comServer); } // DX else if (url.Scheme == Opc.UrlScheme.DX) { // Verify that it is a DX server. if (!typeof(OpcRcw.Dx.IOPCConfiguration).IsInstanceOfType(comServer)) { interfaceType = typeof(OpcRcw.Dx.IOPCConfiguration); throw new NotSupportedException(); } server = new OpcCom.Dx.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) { OpcCom.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) { OpcCom.Interop.ReleaseServer(server); server = null; throw e; } // initialize the wrapper object. if (server != null) { server.Initialize(url, connectData); } return(server); }