Ejemplo n.º 1
0
        private bool PrepareSqlReplicationConfig(SqlReplicationConfig cfg, string sqlReplicationConfigDocumentKey, SqlReplicationStatistics replicationStats, SqlReplicationConnections <SqlReplicationConnections.PredefinedSqlConnectionWithConfigurationOrigin> sqlReplicationConnections, bool writeToLog = true, bool validateSqlReplicationName = true)
        {
            if (validateSqlReplicationName && string.IsNullOrWhiteSpace(cfg.Name))
            {
                if (writeToLog)
                {
                    Log.Warn("Could not find name for sql replication document {0}, ignoring", sqlReplicationConfigDocumentKey);
                }
                replicationStats.LastAlert = new Alert
                {
                    AlertLevel = AlertLevel.Error,
                    CreatedAt  = DateTime.UtcNow,
                    Title      = "Could not start replication",
                    Message    = string.Format("Could not find name for sql replication document {0}, ignoring", sqlReplicationConfigDocumentKey)
                };
                return(false);
            }
            if (string.IsNullOrWhiteSpace(cfg.PredefinedConnectionStringSettingName) == false)
            {
                var matchingConnection = sqlReplicationConnections.PredefinedConnections.FirstOrDefault(x => string.Compare(x.Name, cfg.PredefinedConnectionStringSettingName, StringComparison.InvariantCultureIgnoreCase) == 0);
                if (matchingConnection != null)
                {
                    cfg.ConnectionString = matchingConnection.ConnectionString;
                    cfg.FactoryName      = matchingConnection.FactoryName;
                }
                else
                {
                    if (writeToLog)
                    {
                        Log.Warn("Could not find predefined connection string named '{0}' for sql replication config: {1}, ignoring sql replication setting.",
                                 cfg.PredefinedConnectionStringSettingName,
                                 sqlReplicationConfigDocumentKey);
                    }
                    replicationStats.LastAlert = new Alert
                    {
                        AlertLevel = AlertLevel.Error,
                        CreatedAt  = DateTime.UtcNow,
                        Title      = "Could not start replication",
                        Message    = string.Format("Could not find predefined connection string named '{0}' for sql replication config: {1}, ignoring sql replication setting.",
                                                   cfg.PredefinedConnectionStringSettingName,
                                                   sqlReplicationConfigDocumentKey)
                    };
                    return(false);
                }
            }
            else if (string.IsNullOrWhiteSpace(cfg.ConnectionStringName) == false)
            {
                var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings[cfg.ConnectionStringName];
                if (connectionString == null)
                {
                    if (writeToLog)
                    {
                        Log.Warn("Could not find connection string named '{0}' for sql replication config: {1}, ignoring sql replication setting.",
                                 cfg.ConnectionStringName, sqlReplicationConfigDocumentKey);
                    }

                    replicationStats.LastAlert = new Alert
                    {
                        AlertLevel = AlertLevel.Error,
                        CreatedAt  = DateTime.UtcNow,
                        Title      = "Could not start replication",
                        Message    = string.Format("Could not find connection string named '{0}' for sql replication config: {1}, ignoring sql replication setting.",
                                                   cfg.ConnectionStringName,
                                                   sqlReplicationConfigDocumentKey)
                    };
                    return(false);
                }
                cfg.ConnectionString = connectionString.ConnectionString;
            }
            else if (string.IsNullOrWhiteSpace(cfg.ConnectionStringSettingName) == false)
            {
                var setting = Database.Configuration.Settings[cfg.ConnectionStringSettingName];
                if (string.IsNullOrWhiteSpace(setting))
                {
                    if (writeToLog)
                    {
                        Log.Warn("Could not find setting named '{0}' for sql replication config: {1}, ignoring sql replication setting.",
                                 cfg.ConnectionStringSettingName,
                                 sqlReplicationConfigDocumentKey);
                    }
                    replicationStats.LastAlert = new Alert
                    {
                        AlertLevel = AlertLevel.Error,
                        CreatedAt  = DateTime.UtcNow,
                        Title      = "Could not start replication",
                        Message    = string.Format("Could not find setting named '{0}' for sql replication config: {1}, ignoring sql replication setting.",
                                                   cfg.ConnectionStringSettingName,
                                                   sqlReplicationConfigDocumentKey)
                    };
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
		private bool PrepareSqlReplicationConfig(SqlReplicationConfig cfg, string sqlReplicationConfigDocumentKey, SqlReplicationStatistics replicationStats, SqlReplicationConnections sqlReplicationConnections, bool writeToLog = true, bool validateSqlReplicationName = true)
		{
			if (validateSqlReplicationName && string.IsNullOrWhiteSpace(cfg.Name))
			{
				if (writeToLog)
					Log.Warn("Could not find name for sql replication document {0}, ignoring", sqlReplicationConfigDocumentKey);
				replicationStats.LastAlert = new Alert
				{
					AlertLevel = AlertLevel.Error,
					CreatedAt = DateTime.UtcNow,
					Title = "Could not start replication",
					Message = string.Format("Could not find name for sql replication document {0}, ignoring", sqlReplicationConfigDocumentKey)
				};
				return false;
			}
			if (string.IsNullOrWhiteSpace(cfg.PredefinedConnectionStringSettingName) == false)
			{
				var matchingConnection = sqlReplicationConnections.PredefinedConnections.FirstOrDefault(x => string.Compare(x.Name, cfg.PredefinedConnectionStringSettingName, StringComparison.InvariantCultureIgnoreCase) == 0);
				if (matchingConnection != null)
				{
					cfg.ConnectionString = matchingConnection.ConnectionString;
					cfg.FactoryName = matchingConnection.FactoryName;
				}
				else
				{
					if (writeToLog)
						Log.Warn("Could not find predefined connection string named '{0}' for sql replication config: {1}, ignoring sql replication setting.",
							cfg.PredefinedConnectionStringSettingName,
							sqlReplicationConfigDocumentKey);
					replicationStats.LastAlert = new Alert
					{
						AlertLevel = AlertLevel.Error,
						CreatedAt = DateTime.UtcNow,
						Title = "Could not start replication",
						Message = string.Format("Could not find predefined connection string named '{0}' for sql replication config: {1}, ignoring sql replication setting.",
							cfg.PredefinedConnectionStringSettingName,
							sqlReplicationConfigDocumentKey)
					};
					return false;
				}
			}
			else if (string.IsNullOrWhiteSpace(cfg.ConnectionStringName) == false)
			{
				var connectionString = ConfigurationManager.ConnectionStrings[cfg.ConnectionStringName];
				if (connectionString == null)
				{
					if (writeToLog)
						Log.Warn("Could not find connection string named '{0}' for sql replication config: {1}, ignoring sql replication setting.",
							cfg.ConnectionStringName, sqlReplicationConfigDocumentKey);

					replicationStats.LastAlert = new Alert
					{
						AlertLevel = AlertLevel.Error,
						CreatedAt = DateTime.UtcNow,
						Title = "Could not start replication",
						Message = string.Format("Could not find connection string named '{0}' for sql replication config: {1}, ignoring sql replication setting.",
							cfg.ConnectionStringName,
							sqlReplicationConfigDocumentKey)
					};
					return false;
				}
				cfg.ConnectionString = connectionString.ConnectionString;
			}
			else if (string.IsNullOrWhiteSpace(cfg.ConnectionStringSettingName) == false)
			{
				var setting = Database.Configuration.Settings[cfg.ConnectionStringSettingName];
				if (string.IsNullOrWhiteSpace(setting))
				{
					if (writeToLog)
						Log.Warn("Could not find setting named '{0}' for sql replication config: {1}, ignoring sql replication setting.",
			cfg.ConnectionStringSettingName,
			sqlReplicationConfigDocumentKey);
					replicationStats.LastAlert = new Alert
					{
						AlertLevel = AlertLevel.Error,
						CreatedAt = DateTime.UtcNow,
						Title = "Could not start replication",
						Message = string.Format("Could not find setting named '{0}' for sql replication config: {1}, ignoring sql replication setting.",
							cfg.ConnectionStringSettingName,
							sqlReplicationConfigDocumentKey)
					};
					return false;
				}
			}
			return true;
		}