示例#1
0
        /// <summary>
        /// Asynchronously extracts catalogs/schemas according to the specified <paramref name="tasks"/>.
        /// </summary>
        /// <remarks> Multiple active operations are not supported. Use <see langword="await"/>
        /// to ensure that all asynchronous operations have completed.</remarks>
        /// <param name="connection">Extraction tasks.</param>
        /// <param name="tasks">Connection to use.</param>
        /// <param name="token">The token to cancel asynchronous operation if needed.</param>
        /// <returns>Extracted catalogs.</returns>
        public async Task <SqlExtractionResult> ExtractAsync(SqlConnection connection, IEnumerable <SqlExtractionTask> tasks,
                                                             CancellationToken token = default)
        {
            ArgumentValidator.EnsureArgumentNotNull(connection, nameof(connection));
            ArgumentValidator.EnsureArgumentNotNull(tasks, nameof(tasks));

            if (connection.Driver != this)
            {
                throw new ArgumentException(Strings.ExSpecifiedConnectionDoesNotBelongToThisDriver);
            }

            var taskGroups = tasks
                             .GroupBy(t => t.Catalog)
                             .ToDictionary(g => g.Key, g => g.ToList());

            var result = new SqlExtractionResult();

            foreach (var(catalogName, sqlExtractionTasks) in taskGroups)
            {
                var extractor = await BuildExtractorAsync(connection, token).ConfigureAwait(false);

                if (sqlExtractionTasks.All(t => !t.AllSchemas))
                {
                    // extracting all the schemes we need
                    var schemasToExtract = sqlExtractionTasks.Select(t => t.Schema).ToArray();
                    var catalog          = await extractor.ExtractSchemesAsync(catalogName, schemasToExtract, token).ConfigureAwait(false);

                    CleanSchemas(catalog, schemasToExtract);
                    result.Catalogs.Add(catalog);
                }
                else
                {
                    // Extracting whole catalog
                    var catalog = await extractor.ExtractCatalogAsync(catalogName, token).ConfigureAwait(false);

                    result.Catalogs.Add(catalog);
                }
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// Extracts catalogs/schemas according to the specified <paramref name="tasks"/>.
        /// </summary>
        /// <param name="connection">Extraction tasks.</param>
        /// <param name="tasks">Connection to use.</param>
        /// <returns>Extracted catalogs.</returns>
        public SqlExtractionResult Extract(SqlConnection connection, IEnumerable <SqlExtractionTask> tasks)
        {
            ArgumentValidator.EnsureArgumentNotNull(connection, nameof(connection));
            ArgumentValidator.EnsureArgumentNotNull(tasks, nameof(tasks));

            if (connection.Driver != this)
            {
                throw new ArgumentException(Strings.ExSpecifiedConnectionDoesNotBelongToThisDriver);
            }

            var taskGroups = tasks
                             .GroupBy(t => t.Catalog)
                             .ToDictionary(g => g.Key, g => g.ToList());

            var result = new SqlExtractionResult();

            foreach (var taskGroup in taskGroups)
            {
                var catalogName     = taskGroup.Key;
                var tasksForCatalog = taskGroup.Value;

                if (tasksForCatalog.All(t => !t.AllSchemas))
                {
                    // extracting all the schemes we need
                    var schemasToExtract = tasksForCatalog.Select(t => t.Schema).ToArray();
                    var catalog          = BuildExtractor(connection)
                                           .ExtractSchemes(catalogName, schemasToExtract);
                    CleanSchemas(catalog, schemasToExtract);
                    result.Catalogs.Add(catalog);
                }
                else
                {
                    // Extracting whole catalog
                    var catalog = BuildExtractor(connection).ExtractCatalog(catalogName);
                    result.Catalogs.Add(catalog);
                }
            }

            return(result);
        }