SiteStatus.Factories.DatabaseMonitorFactory.GetMonitor C# (CSharp) Method

GetMonitor() public method

Gets an implementation of IStatusMonitor that uses appropriate code, and SQL to determine the availability of the database.
public GetMonitor ( Service service ) : IStatusMonitor
service Service A database service to retrieve a status monitor.
return IStatusMonitor
        public override IStatusMonitor GetMonitor(Service service)
        {
            ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[service.Name];

            if (settings != null)
            {
                if (string.Equals("System.Data.SqlClient", settings.ProviderName, StringComparison.CurrentCultureIgnoreCase))
                {
                    return new SqlConnectionMonitor();
                }
                else if (string.Equals("System.Data.OleDb", settings.ProviderName, StringComparison.CurrentCultureIgnoreCase))
                {
                }
                else if (string.Equals("System.Data.Odbc", settings.ProviderName, StringComparison.CurrentCultureIgnoreCase))
                {
                }
                else if (string.Equals("System.Data.OracleClient", settings.ProviderName, StringComparison.CurrentCultureIgnoreCase))
                {
                    return new OracleConnectionMonitor();
                }
            }

            return null;
        }

Usage Example

        public void GetMonitor_All()
        {
            var target = new DatabaseMonitorFactory();
            var sql = new Service()
            {
                Name = "LocalDatabase",
                Type = ServiceType.Database
            };
            var sqlMonitor = target.GetMonitor(sql);
            Assert.IsNotNull(sqlMonitor);
            Assert.IsInstanceOfType(sqlMonitor, typeof(SqlConnectionMonitor));

            var oracle = new Service()
            {
                Name = "OracleDatabase",
                Type = ServiceType.Database
            };
            var oracleMonitor = target.GetMonitor(oracle);
            Assert.IsNotNull(oracleMonitor);
            Assert.IsInstanceOfType(oracleMonitor, typeof(OracleConnectionMonitor));

            var odbc = new Service()
            {
                Name = "OdbcDatabase",
                Type = ServiceType.Database
            };
            var odbcMonitor = target.GetMonitor(odbc);
            Assert.IsNull(odbcMonitor);
        }