public async Task CopyEntitiesAsync(IEntityStore source, IEntityStore dest, CancellationToken cancellationToken = new CancellationToken())
        {
            Logger.LogDebug("CopyEntitiesAsync Starting");
            var sw = Stopwatch.StartNew();
            {
                Logger.LogTrace("Delete all Items");
                await dest.DeleteAllItemsAsync <T>(cancellationToken).ConfigureAwait(false);
            }

            var items = await source.LoadItemsAsync <T>(arg => true, cancellationToken).ConfigureAwait(false);

            var enumerable = items as T[] ?? items.ToArray();

            Logger.LogTrace("Entities Loaded {ItemCount} {EntityType}", enumerable.Length, typeof(T).Name);

            if (enumerable.Any())
            {
                await dest.BulkInsertItemsAsync(enumerable, cancellationToken).ConfigureAwait(false);

                Logger.LogTrace("Items Inserted");
            }

            Logger.LogDebug("CopyEntitiesAsync Finished in {Elapsed} ms ", sw.ElapsedMilliseconds);
        }
Exemple #2
0
        public virtual async Task CopyEntitiesAsync(IEntityStore source, IEntityStore dest, CancellationToken cancellationToken = default(CancellationToken))
        {
            Logger.LogDebug("CopyEntitiesAsync Starting");
            var sw = Stopwatch.StartNew();
            {
                if (!SkipDestinationDeletion)
                {
                    var destItems = await dest.LoadItemsAsync <T>(arg => true, cancellationToken).ConfigureAwait(false);

                    var entities = destItems as T[] ?? destItems.ToArray();

                    if (entities.Any())
                    {
                        Logger.LogTrace("Entities in Destination Loaded {ItemCount} {EntityType} - Must Delete", entities.Length, typeof(T).Name);

                        var tasks = entities.Select(destItem => dest.DeleteItemAsync <T>(destItem.EntityId, cancellationToken));
                        await Task.WhenAll(tasks).ConfigureAwait(false);
                    }
                }
            }

            var items = await source.LoadItemsAsync <T>(arg => true, cancellationToken).ConfigureAwait(false);

            var enumerable = items as T[] ?? items.ToArray();

            Logger.LogTrace("Entities Loaded {ItemCount} {EntityType}", enumerable.Length, typeof(T).Name);

            if (enumerable.Any())
            {
                await dest.BulkInsertItemsAsync(enumerable, cancellationToken).ConfigureAwait(false);

                Logger.LogTrace("Items Inserted");
            }

            Logger.LogDebug("CopyEntitiesAsync Finished in {Elapsed} ms ", sw.ElapsedMilliseconds);
        }