public override IDBHelper Create(string dbName, string connectionString) { IDBHelper helper = AssemblyUtil.CreateInstance <IDBHelper> ( "Immas.Database.Oracle.dll", "Immas.Database.Oracle.OracleDbHelper", dbName, connectionString ); return(helper); }
/// <summary> /// Setups the request filter factory. /// </summary> /// <param name="config">The config.</param> /// <param name="requestFilterFactory">The request filter factory.</param> /// <returns></returns> private bool SetupRequestFilterFactory(IServerConfig config, IRequestFilterFactory <TRequestInfo> requestFilterFactory) { //The protocol passed by programming has higher priority, then by config if (requestFilterFactory != null) { this.RequestFilterFactory = requestFilterFactory; } else { //There is a protocol configuration existing if (!string.IsNullOrEmpty(config.Protocol)) { IRequestFilterFactory <TRequestInfo> configuredRequestFilterFactory; try { configuredRequestFilterFactory = AssemblyUtil.CreateInstance <IRequestFilterFactory <TRequestInfo> >(config.Protocol); } catch (Exception e) { if (Logger.IsErrorEnabled) { Logger.Error(string.Format("Invalid configured protocol {0}.", config.Protocol), e); } return(false); } this.RequestFilterFactory = configuredRequestFilterFactory; } } //If there is no defined protocol, use CommandLineProtocol as default if (RequestFilterFactory == null) { if (Logger.IsErrorEnabled) { Logger.Error("Protocol hasn't been set!"); } return(false); } return(true); }
public void OpenForm(string assemblyName, string typeName, string text) { foreach (Form openForm in this.MdiChildren) { if (openForm.GetType().FullName == typeName) { openForm.Activate(); return; } } BaseMdiChildForm form = AssemblyUtil.CreateInstance <BaseMdiChildForm>(assemblyName, typeName); form.AuthCollection = GetAuthCollection(form); form.MdiParent = this; form.Icon = Properties.Resources.program; form.Text = " " + text; form.BringToFront(); form.Show(); }
/// <summary> /// Setups the appServer instance /// </summary> /// <param name="rootConfig">The root config.</param> /// <param name="config">The socket server instance config.</param> /// <param name="socketServerFactory">The socket server factory.</param> /// <param name="requestFilterFactory">The request filter factory.</param> /// <returns></returns> protected virtual bool Setup(IRootConfig rootConfig, IServerConfig config, ISocketServerFactory socketServerFactory, IRequestFilterFactory <TRequestInfo> requestFilterFactory) { if (rootConfig == null) { throw new ArgumentNullException("rootConfig"); } RootConfig = rootConfig; if (!m_ThreadPoolConfigured) { if (!TheadPoolEx.ResetThreadPool(rootConfig.MaxWorkingThreads >= 0 ? rootConfig.MaxWorkingThreads : new Nullable <int>(), rootConfig.MaxCompletionPortThreads >= 0 ? rootConfig.MaxCompletionPortThreads : new Nullable <int>(), rootConfig.MinWorkingThreads >= 0 ? rootConfig.MinWorkingThreads : new Nullable <int>(), rootConfig.MinCompletionPortThreads >= 0 ? rootConfig.MinCompletionPortThreads : new Nullable <int>())) { return(false); } m_ThreadPoolConfigured = true; } if (config == null) { throw new ArgumentNullException("config"); } if (!(config is ServerConfig)) { //Use config plain model directly to avoid extra object casting in runtime var newConfig = new ServerConfig(); config.CopyPropertiesTo(newConfig); config = newConfig; } Config = config; m_SocketServerFactory = socketServerFactory; SetupLogger(); if (!SetupSecurity(config)) { return(false); } if (!SetupListeners(config)) { if (Logger.IsErrorEnabled) { Logger.Error("Invalid config ip/port"); } return(false); } if (!SetupRequestFilterFactory(config, requestFilterFactory)) { return(false); } m_CommandLoaders = new List <ICommandLoader> { new ReflectCommandLoader() }; if (Config.EnableDynamicCommand) { ICommandLoader dynamicCommandLoader; try { dynamicCommandLoader = AssemblyUtil.CreateInstance <ICommandLoader>("SuperSocket.Dlr.DynamicCommandLoader, SuperSocket.Dlr"); } catch (Exception e) { if (Logger.IsErrorEnabled) { Logger.Error("The file SuperSocket.Dlr is required for dynamic command support!", e); } return(false); } m_CommandLoaders.Add(dynamicCommandLoader); } if (!SetupCommands(m_CommandDict)) { return(false); } return(SetupSocketServer()); }
internal void Initialize() { if (_initialized) { return; } Ice.Communicator ic = Communicator(); // // Check for a default directory. We look in this directory for // files mentioned in the configuration. // _defaultDir = ic.GetProperty("IceSSL.DefaultDir") ?? ""; string certStoreLocation = ic.GetProperty("IceSSL.CertStoreLocation") ?? "CurrentUser"; StoreLocation storeLocation; if (certStoreLocation == "CurrentUser") { storeLocation = StoreLocation.CurrentUser; } else if (certStoreLocation == "LocalMachine") { storeLocation = StoreLocation.LocalMachine; } else { _logger.Warning($"Invalid IceSSL.CertStoreLocation value `{certStoreLocation}' adjusted to `CurrentUser'"); storeLocation = StoreLocation.CurrentUser; } _useMachineContext = certStoreLocation == "LocalMachine"; // // Protocols selects which protocols to enable, by default we only enable TLS1.0 // TLS1.1 and TLS1.2 to avoid security issues with SSLv3 // string[]? protocols = ic.GetPropertyAsList("IceSSL.Protocols"); if (protocols != null) { _protocols = ParseProtocols(protocols); } else { _protocols = 0; foreach (int v in Enum.GetValues(typeof(SslProtocols))) { if (v > (int)SslProtocols.Ssl3 && v != (int)SslProtocols.Default) { _protocols |= (SslProtocols)v; } } } // // CheckCertName determines whether we compare the name in a peer's // certificate against its hostname. // _checkCertName = ic.GetPropertyAsInt("IceSSL.CheckCertName") > 0; // // VerifyDepthMax establishes the maximum length of a peer's certificate // chain, including the peer's certificate. A value of 0 means there is // no maximum. // _verifyDepthMax = ic.GetPropertyAsInt("IceSSL.VerifyDepthMax") ?? 3; // // CheckCRL determines whether the certificate revocation list is checked, and how strictly. // _checkCRL = ic.GetPropertyAsInt("IceSSL.CheckCRL") ?? 0; // // Check for a certificate verifier. // string?certVerifierClass = ic.GetProperty("IceSSL.CertVerifier"); if (certVerifierClass != null) { if (_verifier != null) { throw new InvalidOperationException("IceSSL: certificate verifier already installed"); } Type?cls = _facade.FindType(certVerifierClass); if (cls == null) { throw new InvalidConfigurationException( $"IceSSL: unable to load certificate verifier class `{certVerifierClass}'"); } try { _verifier = (ICertificateVerifier?)AssemblyUtil.CreateInstance(cls); } catch (Exception ex) { throw new LoadException( $"IceSSL: unable to instantiate certificate verifier class `{certVerifierClass}", ex); } } // // Check for a password callback. // string?passwordCallbackClass = ic.GetProperty("IceSSL.PasswordCallback"); if (passwordCallbackClass != null) { if (_passwordCallback != null) { throw new InvalidOperationException("IceSSL: password callback already installed"); } Type?cls = _facade.FindType(passwordCallbackClass); if (cls == null) { throw new InvalidConfigurationException( $"IceSSL: unable to load password callback class `{passwordCallbackClass}'"); } try { _passwordCallback = (IPasswordCallback?)AssemblyUtil.CreateInstance(cls); } catch (Exception ex) { throw new LoadException( $"IceSSL: unable to load password callback class {passwordCallbackClass}", ex); } } // // If the user hasn't supplied a certificate collection, we need to examine // the property settings. // if (_certs == null) { // // If IceSSL.CertFile is defined, load a certificate from a file and // add it to the collection. // // TODO: tracing? _certs = new X509Certificate2Collection(); string? certFile = ic.GetProperty("IceSSL.CertFile"); string? passwordStr = ic.GetProperty("IceSSL.Password"); string? findCert = ic.GetProperty("IceSSL.FindCert"); const string findPrefix = "IceSSL.FindCert."; Dictionary <string, string> findCertProps = ic.GetProperties(forPrefix: findPrefix); if (certFile != null) { if (!CheckPath(ref certFile)) { throw new FileNotFoundException($"IceSSL: certificate file not found: `{certFile}'", certFile); } SecureString?password = null; if (passwordStr != null) { password = CreateSecureString(passwordStr); } else if (_passwordCallback != null) { password = _passwordCallback.GetPassword(certFile); } try { X509Certificate2 cert; X509KeyStorageFlags importFlags; if (_useMachineContext) { importFlags = X509KeyStorageFlags.MachineKeySet; } else { importFlags = X509KeyStorageFlags.UserKeySet; } if (password != null) { cert = new X509Certificate2(certFile, password, importFlags); } else { cert = new X509Certificate2(certFile, "", importFlags); } _certs.Add(cert); } catch (CryptographicException ex) { throw new InvalidConfigurationException( $"IceSSL: error while attempting to load certificate from `{certFile}'", ex); } } else if (findCert != null) { string certStore = ic.GetProperty("IceSSL.CertStore") ?? "My"; _certs.AddRange(FindCertificates("IceSSL.FindCert", storeLocation, certStore, findCert)); if (_certs.Count == 0) { throw new InvalidConfigurationException("IceSSL: no certificates found"); } } else if (findCertProps.Count > 0) { // // If IceSSL.FindCert.* properties are defined, add the selected certificates // to the collection. // foreach (KeyValuePair <string, string> entry in findCertProps) { string name = entry.Key; string val = entry.Value; if (val.Length > 0) { string storeSpec = name.Substring(findPrefix.Length); StoreLocation storeLoc = 0; StoreName storeName = 0; string? sname = null; ParseStore(name, storeSpec, ref storeLoc, ref storeName, ref sname); if (sname == null) { sname = storeName.ToString(); } X509Certificate2Collection coll = FindCertificates(name, storeLoc, sname, val); _certs.AddRange(coll); } } if (_certs.Count == 0) { throw new InvalidConfigurationException("IceSSL: no certificates found"); } } } if (_caCerts == null) { string?certAuthFile = ic.GetProperty("IceSSL.CAs"); if (certAuthFile == null) { certAuthFile = ic.GetProperty("IceSSL.CertAuthFile"); } if (certAuthFile != null || (ic.GetPropertyAsInt("IceSSL.UsePlatformCAs") ?? 0) <= 0) { _caCerts = new X509Certificate2Collection(); } if (certAuthFile != null) { if (!CheckPath(ref certAuthFile)) { throw new FileNotFoundException("IceSSL: CA certificate file not found: `{certAuthFile}'", certAuthFile); } try { using FileStream fs = File.OpenRead(certAuthFile); byte[] data = new byte[fs.Length]; fs.Read(data, 0, data.Length); string strbuf = ""; try { strbuf = System.Text.Encoding.UTF8.GetString(data); } catch (Exception) { // Ignore } if (strbuf.Length == data.Length) { int size, startpos, endpos = 0; bool first = true; while (true) { startpos = strbuf.IndexOf("-----BEGIN CERTIFICATE-----", endpos); if (startpos != -1) { endpos = strbuf.IndexOf("-----END CERTIFICATE-----", startpos); size = endpos - startpos + "-----END CERTIFICATE-----".Length; } else if (first) { startpos = 0; endpos = strbuf.Length; size = strbuf.Length; } else { break; } byte[] cert = new byte[size]; Buffer.BlockCopy(data, startpos, cert, 0, size); _caCerts !.Import(cert); first = false; } } else { _caCerts !.Import(data); } } catch (Exception ex) { throw new InvalidConfigurationException( $"IceSSL: error while attempting to load CA certificate from {certAuthFile}", ex); } } } _initialized = true; }