public override bool OnStartJob(IJobParameters jobParameters)
        {
            int position = jobParameters.Extras.GetInt(FibonacciPositionKey, DEFAULT_VALUE);

            LogMessage($"Starting FibonacciCalculatorJob::OnStartJob. Job tag {jobParameters.Tag}.");

            // Look for the Fibonacci number on a thread - don't bog down the main thread.
            Task.Run(() => GetFibonacciNumberAt(position)).
            ContinueWith(task =>
            {
                // Record the result, so that it will show up in the Main activity.
                IJobHistoryStorage storage = FJDTestApplication.JobHistoryStorage;
                string msg = $"The fibonnaci number at {position} is {task.Result}";
                storage.RecordResult(jobParameters, msg);

                // Have to call JobFinished when the thread is done. This lets the FJD know that
                // the work is done.
                JobFinished(jobParameters, false);
                LogMessage(
                    $"Finished FibonacciCalculatorJob::OnStartJob/Job tag {jobParameters.Tag}. {msg}");
            }, TaskScheduler.FromCurrentSynchronizationContext());

            LogMessage("Leaving FibonacciCalculatorJob::OnStartJob.");


            return(false); // No more work to do, so return false.
        }
        public void SetUp()
        {
            _job = new Job(new JobInfo(), new ConversionProfile(), new JobTranslations(), new Accounts());
            _job.OutputFilenameTemplate = "MayNotStartWithTempfolder.pdf";
            _job.OutputFiles.Add("NotEmpty.pdf");
            _storedHistory = new List <HistoricJob>();

            _jobHistoryStorage = Substitute.For <IJobHistoryStorage>();
            for (var i = 0; i < _capacity; i++)
            {
                _storedHistory.Add(new HistoricJob(_job));
            }
            _jobHistoryStorage.Load().Returns(_storedHistory);

            var settingsProvider = Substitute.For <ISettingsProvider>();

            _settings = new PdfCreatorSettings(null);
            _settings.ApplicationSettings.JobHistory.Enabled  = true;
            _settings.ApplicationSettings.JobHistory.Capacity = _capacity;
            settingsProvider.Settings.Returns(_settings);

            _tempFolderProvider = Substitute.For <ITempFolderProvider>();
            _tempFolderProvider.TempFolder.Returns(TempFolder);

            _file = Substitute.For <IFile>();
            _file.Exists(Arg.Any <string>()).Returns(true);

            _jobHistoryManager = new JobHistoryManager(settingsProvider, _jobHistoryStorage, _tempFolderProvider, _file);
        }
示例#3
0
 public JobHistoryManager(ISettingsProvider settingsProvider, IJobHistoryStorage jobHistroryStorage,
                          ITempFolderProvider tempFolderProvider, IFile file, IHashUtil hashUtil)
 {
     History             = new List <HistoricJob>();
     _settingsProvider   = settingsProvider;
     _jobHistoryStorage  = jobHistroryStorage;
     _tempFolderProvider = tempFolderProvider;
     _file     = file;
     _hashUtil = hashUtil;
     _settingsProvider.SettingsChanged += (sender, args) => UpdateCapacity();
 }
 public JobHistoryActiveRecord(ISettingsProvider settingsProvider, IJobHistoryStorage jobHistoryStorage,
                               ITempFolderProvider tempFolderProvider, IFile file, IHashUtil hashUtil, IGpoSettings gpoSettings)
 {
     History             = new List <HistoricJob>();
     _settingsProvider   = settingsProvider;
     _jobHistoryStorage  = jobHistoryStorage;
     _tempFolderProvider = tempFolderProvider;
     _file        = file;
     _hashUtil    = hashUtil;
     _gpoSettings = gpoSettings;
     _settingsProvider.SettingsChanged += (sender, args) => UpdateCapacity();
 }
示例#5
0
        public void SetUp()
        {
            _job = new Job(new JobInfo(), new ConversionProfile(), new JobTranslations(), new Accounts());
            _job.OutputFilenameTemplate = "MayNotStartWithTempfolder.pdf";
            _job.OutputFiles.Add("NotEmpty.pdf");
            _storedHistoryFullCapacity = new List <HistoricJob>();

            _jobHistoryStorage         = Substitute.For <IJobHistoryStorage>();
            _storedHistoryFullCapacity = new List <HistoricJob>();
            var hjPdf         = new HistoricFile(@"X:\Foldername\PeeDeeEff.pdf", "PeeDeeEff.pdf", @"X:\Foldername\", "ABC123");
            var historicFiles = new List <HistoricFile> {
                hjPdf
            };

            for (int i = 0; i < _capacity; i++)
            {
                _storedHistoryFullCapacity.Add(new HistoricJob(historicFiles, OutputFormat.Pdf, DateTime.Now, new Metadata(), 23, false));
            }
            _jobHistoryStorage.Load().Returns(_storedHistoryFullCapacity);

            var settingsProvider = Substitute.For <ISettingsProvider>();

            _settings = new PdfCreatorSettings(null);
            _settings.ApplicationSettings.JobHistory.Enabled  = true;
            _settings.ApplicationSettings.JobHistory.Capacity = _capacity;
            settingsProvider.Settings.Returns(_settings);

            _tempFolderProvider = Substitute.For <ITempFolderProvider>();
            _tempFolderProvider.TempFolder.Returns(TempFolder);

            _file = Substitute.For <IFile>();
            _file.Exists(Arg.Any <string>()).Returns(true);

            _hashUtil = Substitute.For <IHashUtil>();

            _jobHistoryManager = new JobHistoryManager(settingsProvider, _jobHistoryStorage, _tempFolderProvider, _file, _hashUtil);
        }