public async Task StartProcessing()
        {
            State = SeedingState.Seeding;
            _cancellationTokenSource = new CancellationTokenSource();
            _processingTask          = _taskFactory.StartNew(() =>
            {
                _log.Info("Seed coordinator is starting");
                if (_seeders.Any() == false)
                {
                    _log.Warn("\tThere are no seeders registered!");
                }
                try
                {
                    // start seeders
                    var seedingTasks = new List <Task>();
                    foreach (var seeder in _seeders)
                    {
                        seedingTasks.Add(seeder.StartSeeding(_cancellationTokenSource.Token));
                    }

                    Task.WaitAll(seedingTasks.ToArray());
                }
                catch (Exception unhandledException)
                {
                    _log.Error($"Unhandled Excpetion in Seeder.  Details: \r\n{unhandledException}");
                }
            });

            await _processingTask;
        }
Exemple #2
0
 public PersonSeederStateModel(SeedingState seedingState)
 {
     // todo: do not like this
     NotStarted = seedingState == SeedingState.Uninitiated;
     Started    = seedingState == SeedingState.Seeding;
     Stopping   = seedingState == SeedingState.Cancelling;
     Stopped    = seedingState == SeedingState.Cancelled ||
                  seedingState == SeedingState.Completed ||
                  seedingState == SeedingState.Errored ||
                  seedingState == SeedingState.Uninitiated;
     Errored = seedingState == SeedingState.Errored;
 }
        public async Task Cancel()
        {
            if (_cancellationTokenSource == null)
            {
                throw new Exception("Unable to cancel seeding because the cancellation token is null");
            }
            _cancellationTokenSource.Cancel();

            await _processingTask.ContinueWith((T) =>
            {
                _log.Info("\tSeeders were successfully cancelled");
                State = SeedingState.Cancelled;
            });
        }