Beispiel #1
0
        public async Task RunAsync(CancellationToken cancellationToken)
        {
            Status = JobStatus.Downloading;
            OnJobStarted?.Invoke(this, new JobStartedEventArgs(SongHash, SongKey, SongName, LevelAuthorName));
            int downloadTime = NumberGenerator.Next(MinDownloadTime, MaxDownloadTime);
            int extractTime  = NumberGenerator.Next(MinZipTime, MaxZipTime);

            if (UseDelays)
            {
                await Task.Delay(downloadTime);
            }
            if (Paused)
            {
                Console.WriteLine("We're 'Paused'");
            }
            Result.DownloadResult = _finalResult.DownloadResult;
            if ((Result.DownloadResult?.Status ?? DownloadResultStatus.Unknown) == DownloadResultStatus.Success)
            {
                Status = JobStatus.Extracting;
                if (UseDelays)
                {
                    await Task.Delay(extractTime);
                }
                Result.ZipResult = _finalResult.ZipResult;
                SongDirectory    = _finalResult.SongDirectory;
                Status           = JobStatus.Finished;
            }
            Status = JobStatus.Finished;
            OnJobFinished?.Invoke(this, new JobFinishedEventArgs(SongHash, Result.Successful, Result.DownloadResult.Status, Result.ZipResult.ResultStatus, SongDirectory));
        }
Beispiel #2
0
            public Task StartAsync()
            {
                Status = WorkerStatus.WaitingForJob;
                var args = new JobInfoEventArgs(new JobInfoModel());

                OnJobStarted?.Invoke(this, args);
                Status = WorkerStatus.ProcessingJob;
                Task.Delay(10);
                OnJobCompleted?.Invoke(this, args);
                return(Task.Delay(1));
            }
        private void TimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
        {
            _timer.Stop();

            if (_isRunning)
            {
                // Run task
                OnJobStarted?.Invoke();
                RunInternal();
                OnJobFinished?.Invoke();
            }

            if (_isRunning)
            {
                // Restart timer
                _timer.Interval = ExecutionInterval.TotalMilliseconds;
                _timer.Start();
            }
        }