public Callback(OpcCom.Server server) { this.m_server = server; }
public override IServer CreateInstance(URL url, ConnectData connectData) { object o = Connect(url, connectData); if (o == null) { return(null); } OpcCom.Server server = null; System.Type type = null; try { if (url.Scheme == "opcda") { if (!typeof(IOPCServer).IsInstanceOfType(o)) { type = typeof(IOPCServer); throw new NotSupportedException(); } if (!typeof(IOPCBrowse).IsInstanceOfType(o) || !typeof(IOPCItemIO).IsInstanceOfType(o)) { if (!typeof(IOPCItemProperties).IsInstanceOfType(o)) { type = typeof(IOPCItemProperties); throw new NotSupportedException(); } server = new OpcCom.Da20.Server(url, o); } else { server = new OpcCom.Da.Server(url, o); } } else if (url.Scheme == "opcae") { if (!typeof(IOPCEventServer).IsInstanceOfType(o)) { type = typeof(IOPCEventServer); throw new NotSupportedException(); } server = new OpcCom.Ae.Server(url, o); } else if (url.Scheme == "opchda") { if (!typeof(IOPCHDA_Server).IsInstanceOfType(o)) { type = typeof(IOPCHDA_Server); throw new NotSupportedException(); } server = new OpcCom.Hda.Server(url, o); } else { if (!(url.Scheme == "opcdx")) { throw new NotSupportedException(string.Format("The URL scheme '{0}' is not supported.", url.Scheme)); } if (!typeof(IOPCConfiguration).IsInstanceOfType(o)) { type = typeof(IOPCConfiguration); throw new NotSupportedException(); } server = new OpcCom.Dx.Server(url, o); } } catch (NotSupportedException exception) { OpcCom.Interop.ReleaseServer(server); server = null; if (type != null) { StringBuilder builder = new StringBuilder(); builder.AppendFormat("The COM server does not support the interface ", new object[0]); builder.AppendFormat("'{0}'.", type.FullName); builder.Append("\r\n\r\nThis problem could be caused by:\r\n"); builder.Append("- incorrectly installed proxy/stubs.\r\n"); builder.Append("- problems with the DCOM security settings.\r\n"); builder.Append("- a personal firewall (sometimes activated by default).\r\n"); throw new NotSupportedException(builder.ToString()); } throw exception; } catch (Exception exception2) { OpcCom.Interop.ReleaseServer(server); server = null; throw exception2; } if (server != null) { server.Initialize(url, connectData); } return(server); }
//====================================================================== // 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); }