コード例 #1
0
ファイル: RavenDB_9626.cs プロジェクト: yitaom2/ravendb
        public void Error_if_script_does_not_contain_any_loadTo_method_and_uses_legacy_replicateTo()
        {
            var config = new SqlEtlConfiguration
            {
                Name = "test",
                ConnectionStringName = "test",
                Transforms           =
                {
                    new Transformation
                    {
                        Name        = "test",
                        Collections ={ "Users"                   },
                        Script      = @"this.Name = 'aaa'; replicateToUsers(this);"
                    }
                },
                SqlTables =
                {
                    new SqlEtlTable {
                        TableName = "Orders", DocumentIdColumn = "Id", InsertOnlyMode = false
                    },
                    new SqlEtlTable {
                        TableName = "OrderLines", DocumentIdColumn = "OrderId", InsertOnlyMode = false
                    },
                }
            };

            config.Initialize(new SqlConnectionString {
                ConnectionString = @"Data Source=localhost\sqlexpress"
            });

            List <string> errors;

            config.Validate(out errors);

            Assert.Equal(2, errors.Count);

            Assert.Equal("No `loadTo<TableName>()` method call found in 'test' script", errors[1]);
            Assert.Equal("Found `replicateTo<TableName>()` method in 'test' script which is not supported. " +
                         "If you are using the SQL replication script from RavenDB 3.x version then please use `loadTo<TableName>()` instead.", errors[0]);
        }
コード例 #2
0
ファイル: EtlLoader.cs プロジェクト: qcjxberin/ravendb
        private IEnumerable <EtlProcess> GetRelevantProcesses <T, TConnectionString>(List <T> configurations, HashSet <string> uniqueNames) where T : EtlConfiguration <TConnectionString> where TConnectionString : ConnectionString
        {
            foreach (var config in configurations)
            {
                SqlEtlConfiguration   sqlConfig   = null;
                RavenEtlConfiguration ravenConfig = null;

                var connectionStringNotFound = false;

                switch (config.EtlType)
                {
                case EtlType.Raven:
                    ravenConfig = config as RavenEtlConfiguration;
                    if (_databaseRecord.RavenConnectionStrings.TryGetValue(config.ConnectionStringName, out var ravenConnection))
                    {
                        ravenConfig.Initialize(ravenConnection);
                    }
                    else
                    {
                        connectionStringNotFound = true;
                    }

                    break;

                case EtlType.Sql:
                    sqlConfig = config as SqlEtlConfiguration;
                    if (_databaseRecord.SqlConnectionStrings.TryGetValue(config.ConnectionStringName, out var sqlConnection))
                    {
                        sqlConfig.Initialize(sqlConnection);
                    }
                    else
                    {
                        connectionStringNotFound = true;
                    }

                    break;

                default:
                    ThrownUnknownEtlConfiguration(config.GetType());
                    break;
                }

                if (connectionStringNotFound)
                {
                    LogConfigurationError(config,
                                          new List <string>
                    {
                        $"Connection string named '{config.ConnectionStringName}' was not found for {config.EtlType} ETL"
                    });

                    continue;
                }

                if (config.Disabled)
                {
                    continue;
                }

                if (ValidateConfiguration(config, uniqueNames) == false)
                {
                    continue;
                }

                var processState  = GetProcessState(config.Transforms, _database, config.Name);
                var whoseTaskIsIt = _database.WhoseTaskIsIt(_databaseRecord.Topology, config, processState);
                if (whoseTaskIsIt != _serverStore.NodeTag)
                {
                    continue;
                }

                foreach (var transform in config.Transforms)
                {
                    if (transform.Disabled)
                    {
                        continue;
                    }

                    EtlProcess process = null;

                    if (sqlConfig != null)
                    {
                        process = new SqlEtl(transform, sqlConfig, _database, _serverStore);
                    }

                    if (ravenConfig != null)
                    {
                        process = new RavenEtl(transform, ravenConfig, _database, _serverStore);
                    }

                    yield return(process);
                }
            }
        }