Пример #1
0
        public void BuildWorker(IBackgroundWorker worker)
        {
            int?period;
            var workerType = worker.GetType();

            if (worker is AsyncPeriodicBackgroundWorkerBase || worker is PeriodicBackgroundWorkerBase)
            {
                if (typeof(TWorker) != worker.GetType())
                {
                    throw new ArgumentException($"{nameof(worker)} type is different from the generic type");
                }

                var timer = (AbpTimer)worker.GetType().GetProperty("Timer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(worker);
                period = timer?.Period;
            }
            else
            {
                return;
            }

            if (period == null)
            {
                return;
            }

            JobDetail = JobBuilder
                        .Create <QuartzPeriodicBackgroundWorkerAdapter <TWorker> >()
                        .WithIdentity(workerType.FullName)
                        .Build();
            Trigger = TriggerBuilder.Create()
                      .WithIdentity(workerType.FullName)
                      .WithSimpleSchedule(builder => builder.WithInterval(TimeSpan.FromMilliseconds(period.Value)).RepeatForever())
                      .Build();
        }
Пример #2
0
    public void Add(IBackgroundWorker worker)
    {
        if (worker is IHangfireBackgroundWorker hangfireBackgroundWorker)
        {
            if (hangfireBackgroundWorker.RecurringJobId.IsNullOrWhiteSpace())
            {
                RecurringJob.AddOrUpdate(() => hangfireBackgroundWorker.DoWorkAsync(),
                                         hangfireBackgroundWorker.CronExpression);
            }
            else
            {
                RecurringJob.AddOrUpdate(hangfireBackgroundWorker.RecurringJobId, () => hangfireBackgroundWorker.DoWorkAsync(),
                                         hangfireBackgroundWorker.CronExpression);
            }
        }
        else
        {
            int?period;

            if (worker is AsyncPeriodicBackgroundWorkerBase or PeriodicBackgroundWorkerBase)
            {
                var timer = (AbpTimer)worker.GetType()
                            .GetProperty("Timer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(worker);
                period = timer?.Period;
            }
Пример #3
0
        protected virtual async Task ReScheduleJobAsync(IBackgroundWorker worker)
        {
            if (worker is IQuartzBackgroundWorker quartzWork)
            {
                Check.NotNull(quartzWork.Trigger, nameof(quartzWork.Trigger));
                Check.NotNull(quartzWork.JobDetail, nameof(quartzWork.JobDetail));

                if (quartzWork.ScheduleJob != null)
                {
                    await quartzWork.ScheduleJob.Invoke(_scheduler);
                }
                else
                {
                    await DefaultScheduleJobAsync(quartzWork);
                }
            }
            else
            {
                var adapterType = typeof(QuartzPeriodicBackgroundWorkerAdapter <>).MakeGenericType(worker.GetType());

                var workerAdapter = Activator.CreateInstance(adapterType) as IQuartzBackgroundWorkerAdapter;

                workerAdapter?.BuildWorker(worker);

                if (workerAdapter?.Trigger != null)
                {
                    await DefaultScheduleJobAsync(workerAdapter);
                }
            }
        }
 public ContactSyncBackgroundService(IOptions <Shared.Configuration.Queue> queues, IBackgroundWorker backgroundWorker, IServiceProvider provider)
 {
     this.queue            = queues.Value.Contact;
     this.backgroundWorker = backgroundWorker;
     this.provider         = provider;
     this.contactBook      = this.provider.GetService <IContactBook>();
 }
Пример #5
0
        private void Awake()
        {
            m_progressIndicator = Dependencies.Progress;
            m_job = Dependencies.Job;

            m_mapCameras = new List <MapCamera>();
        }
Пример #6
0
        public void Should_be_able_to_have_multiple_workers_using_one_queue()
        {
            var container = BuildContainer();
            var backgroundWorkerFactory = container.Resolve<BackgroundWorker.Factory>();

            int WorkerCount = Environment.ProcessorCount*2;
            IBackgroundWorker[] workers = new IBackgroundWorker[WorkerCount];

            var workQueue = container.Resolve<IPendingWorkCollection<IScheduledTask>>();

            for (int i = 0; i < WorkerCount; i++) {
                workers[i] = backgroundWorkerFactory(workQueue, ApartmentState.MTA);
                workers[i].Start();
            }

            // schedule some work
            for (int i = 0; i < 50; i++) {
                workQueue.SendAction(() => { Thread.Sleep(50); }, null, CancellationToken.None);
            }

            // wait until work is done
            workQueue.Wait(CancellationToken.None);

            // dispose of workers
            for (int i = 0; i < WorkerCount; i++) {
                workers[i].Dispose();
            }
        }
Пример #7
0
 public void Add(IBackgroundWorker worker)
 {
     if (worker is IHangfireBackgroundWorker hangfireBackgroundWorker)
     {
         RecurringJob.AddOrUpdate(() => hangfireBackgroundWorker.ExecuteAsync(), hangfireBackgroundWorker.CronExpression);
     }
 }
 private static Result ForEachNewTransaction(
     this IBackgroundWorker backgroundWorker,
     Func <WineMsDbContext, WineMsGeneralLedgerJournalTransactionBatch[]> loadData,
     Func <WineMsGeneralLedgerJournalTransactionBatch, Result> func) =>
 WineMsDbContextFunctions
 .WrapInDbContext(loadData)
 .ForEachNewTransaction(backgroundWorker, func);
Пример #9
0
        public IBackgroundWorker GetBackendReference(string backendName)
        {
            IBackgroundWorker backendClient =
                ServiceProxy.Create <IBackgroundWorker>(new Uri($"{m_appName}/{backendName}"), new ServicePartitionKey(1));

            return(backendClient);
        }
Пример #10
0
        public CopyWorker(IFileSystem fileSystem, IFileHelper fileHelper, IContext uiContext, IBackgroundWorker backgroundWorker, IUniqueCharsGenerator charsGenerator)
        {
            if (fileSystem == null)
            {
                throw new ArgumentNullException("fileSystem");
            }
            if (fileHelper == null)
            {
                throw new ArgumentNullException("fileHelper");
            }
            if (uiContext == null)
            {
                throw new ArgumentNullException("uiContext");
            }
            if (backgroundWorker == null)
            {
                throw new ArgumentNullException("backgroundWorker");
            }
            if (charsGenerator == null)
            {
                throw new ArgumentNullException("charsGenerator");
            }

            _fileSystem       = fileSystem;
            _fileHelper       = fileHelper;
            _uiContext        = uiContext;
            _backgroundWorker = backgroundWorker;
            _charsGenerator   = charsGenerator;
        }
Пример #11
0
 public ProgramReloadHandler(
     IBackgroundWorker backgroundWorker,
     IBlockCollectionManager blockCollectionManager)
 {
     _backgroundWorker       = backgroundWorker;
     _blockCollectionManager = blockCollectionManager;
 }
Пример #12
0
 public WorkCompletedContext(
     IBackgroundWorker sender,
     RunWorkerCompletedEventArgs args)
 {
     Sender = sender;
     Args   = args;
 }
Пример #13
0
 private static Result ForEachNewTransaction(
     this IBackgroundWorker backgroundWorker,
     Func <WineMsDbContext, WineMsOrderTransactionDocument[]> loadData,
     Func <WineMsOrderTransactionDocument, Result> func) =>
 WineMsDbContextFunctions
 .WrapInDbContext(loadData)
 .ForEachNewTransaction(backgroundWorker, func);
Пример #14
0
        public void Add(IBackgroundWorker worker)
        {
            var timer = worker.GetType()
                        .GetProperty("Timer", BindingFlags.NonPublic | BindingFlags.Instance)?
                        .GetValue(worker);

            if (timer == null)
            {
                return;
            }

            var period = timer.GetType()
                         .GetProperty("Period", BindingFlags.Public | BindingFlags.Instance)?
                         .GetValue(timer)?
                         .To <int>();

            if (!period.HasValue)
            {
                return;
            }

            var adapterType   = typeof(HangfireBackgroundWorkerAdapter <>).MakeGenericType(worker.GetType());
            var workerAdapter = ServiceProvider.GetRequiredService(adapterType) as IHangfireBackgroundWorkerAdapter;

            RecurringJob.AddOrUpdate(
                recurringJobId: worker.GetType().FullName,
                methodCall: () => workerAdapter.ExecuteAsync(),
                cronExpression: CronGenerator.FormMilliseconds(period.Value));
        }
Пример #15
0
        public void Add(IBackgroundWorker worker)
        {
            if (worker is IHangfireBackgroundWorker hangfireBackgroundWorker)
            {
                RecurringJob.AddOrUpdate(() => hangfireBackgroundWorker.ExecuteAsync(),
                                         hangfireBackgroundWorker.CronExpression);
            }
            else
            {
                int?period;

                if (worker is AsyncPeriodicBackgroundWorkerBase || worker is PeriodicBackgroundWorkerBase)
                {
                    var timer = (AbpTimer)worker.GetType()
                                .GetProperty("Timer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(worker);
                    period = timer?.Period;
                }
                else
                {
                    return;
                }

                if (period == null)
                {
                    return;
                }

                var adapterType   = typeof(HangfirePeriodicBackgroundWorkerAdapter <>).MakeGenericType(worker.GetType());
                var workerAdapter = Activator.CreateInstance(adapterType) as IHangfireBackgroundWorker;

                RecurringJob.AddOrUpdate(() => workerAdapter.ExecuteAsync(), GetCron(period.Value));
            }
        }
Пример #16
0
    public Task AddAsync(IBackgroundWorker worker)
    {
        if (worker is IHangfireBackgroundWorker hangfireBackgroundWorker)
        {
            var unProxyWorker = ProxyHelper.UnProxy(hangfireBackgroundWorker);
            if (hangfireBackgroundWorker.RecurringJobId.IsNullOrWhiteSpace())
            {
                RecurringJob.AddOrUpdate(() => ((IHangfireBackgroundWorker)unProxyWorker).DoWorkAsync(), hangfireBackgroundWorker.CronExpression);
            }
            else
            {
                RecurringJob.AddOrUpdate(hangfireBackgroundWorker.RecurringJobId, () => ((IHangfireBackgroundWorker)unProxyWorker).DoWorkAsync(),
                                         hangfireBackgroundWorker.CronExpression);
            }
        }
        else
        {
            int?period;

            if (worker is AsyncPeriodicBackgroundWorkerBase or PeriodicBackgroundWorkerBase)
            {
                var timer = worker.GetType()
                            .GetProperty("Timer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(worker);

                if (worker is AsyncPeriodicBackgroundWorkerBase)
                {
                    period = ((AbpAsyncTimer)timer)?.Period;
                }
                else
                {
                    period = ((AbpTimer)timer)?.Period;
                }
            }
Пример #17
0
 public RentsHistory(int daysCount, UnitOfWork session, IBackgroundWorker backgroundWorker, IExceptionProcesser exceptionProcesser)
 {
     if (formatsIndexes == null)
     {
         formatsIndexes = new Dictionary <MovieItemFormat, int>();
         for (int i = 0; i < formats.Length; ++i)
         {
             formatsIndexes.Add(formats[i], i);
         }
     }
     if (statusesIndexes == null)
     {
         statusesIndexes = new Dictionary <MovieItemStatus, int>();
         for (int i = 0; i < statuses.Length; ++i)
         {
             statusesIndexes.Add(statuses[i], i);
         }
     }
     addedItemsCountGenerators = new RandomGenerator[formats.Length];
     this.exceptionProcesser   = exceptionProcesser;
     this.session                  = session;
     this.daysCount                = daysCount;
     this.backgroundWorker         = backgroundWorker;
     this.backgroundWorker.DoWork += new DoWorkEventHandler(Generate);
     this.backgroundWorker.RunWorkerAsync(System.Threading.Thread.CurrentThread.CurrentUICulture);
 }
 public void Dispose()
 {
     _interval = 0;
     _backgroundWorkerActive = false;
     _worker.Stop();
     _worker = null;
 }
Пример #19
0
 public MatchService(AlexandriaContext alexandriaContext, IBackgroundWorker backgroundWorker, ICacheBreaker cacheBreaker, TournamentUtils tournamentUtils, IOptions <Alexandria.Games.SuperSmashBros.Configuration.Queue> superSmashBrosQueues)
 {
     this.alexandriaContext    = alexandriaContext;
     this.cacheBreaker         = cacheBreaker;
     this.tournamentUtils      = tournamentUtils;
     this.backgroundWorker     = backgroundWorker;
     this.superSmashBrosQueues = superSmashBrosQueues.Value;
 }
Пример #20
0
 public void Add(IBackgroundWorker worker)
 {
     _backgroundWorkers.Append(worker);
     if (IsRunning)
     {
         worker.Start();
     }
 }
Пример #21
0
 public static Result Execute(IBackgroundWorker backgroundWorker) =>
 backgroundWorker
 .ForEachNewTransactionEvolutionContext(
     context => context.ListNewWineMsCreditNoteTransactions(),
     wineMsTransactionDocument =>
     EvolutionCreditNoteTransactionFunctions
     .ProcessTransaction((WineMsCreditNoteTransactionDocument)wineMsTransactionDocument)
     .OnSuccess(
         document => { document.CompletePosting(IntegrationDocumentTypes.CreditNote); }));
        public TransactionalCommandRunner(IBackgroundWorker backgroundWorker, ThreadSafeQueue <ICommand> queue)
        {
            _commandQueue      = queue;
            _bgWorker          = backgroundWorker;
            _undoStack         = new Stack <ICommand>();
            _workReportCreator = new WorkReportGenerator();

            _cancelRequested = false;
        }
Пример #23
0
 public MemoryCache(IRepository repository, IBackgroundWorker backgroundWorker, ILogger <MemoryCache> logger, VoguediOptions options)
 {
     this.repository       = repository;
     this.backgroundWorker = backgroundWorker;
     this.logger           = logger;
     expiration            = options.AggregateRootExpiration;
     backgroundWorkerKey   = $"{nameof(MemoryCache)}_{SnowflakeId.Default().NewId()}";
     cacheItemMapping      = new ConcurrentDictionary <string, AggregateRootCacheItem>();
 }
Пример #24
0
        private void Awake()
        {
            m_debugMaterial = new Material(Shader.Find("GUI/Text Shader"));

            m_progressIndicator = Dependencies.Progress;
            m_job = Dependencies.Job;

            m_mapCameras = new List <MapCamera>();
        }
 public static Result Execute(IBackgroundWorker backgroundWorker) =>
 backgroundWorker
 .ForEachNewTransactionEvolutionContext(
     context => context.ListNewWineMsGeneralLedgerJournalTransactions(),
     journalTransactionBatch =>
     EvolutionGeneralLedgerJournalTransactionFunctions
     .ProcessTransaction(journalTransactionBatch)
     .OnSuccess(
         transactionBatch => { transactionBatch.CompletePosting(IntegrationDocumentTypes.Journal); }));
        public void Add(IBackgroundWorker worker)
        {
            _backgroundJobs.Add(worker);

            if (IsRunning)
            {
                worker.Start();
            }
        }
        public void Add(IBackgroundWorker worker)
        {
            this._backgroundJobs.Add(worker);

            if (this.IsRunning)
            {
                worker.Start();
            }
        }
Пример #28
0
    public virtual async Task AddAsync(IBackgroundWorker worker)
    {
        _backgroundWorkers.Add(worker);

        if (IsRunning)
        {
            await worker.StartAsync();
        }
    }
        public TransactionalCommandRunner(IBackgroundWorker backgroundWorker, ThreadSafeQueue<ICommand> queue)
        {
            _commandQueue = queue;
            _bgWorker = backgroundWorker;
            _undoStack = new Stack<ICommand>();
            _workReportCreator = new WorkReportGenerator();

            _cancelRequested = false;
        }
Пример #30
0
    public virtual async Task AddAsync(IBackgroundWorker worker, CancellationToken cancellationToken = default)
    {
        _backgroundWorkers.Add(worker);

        if (IsRunning)
        {
            await worker.StartAsync(cancellationToken);
        }
    }
Пример #31
0
        public void Add(IBackgroundWorker worker)
        {
            if (worker is IQuartzBackgroundWorker quartzWork)
            {
                Check.NotNull(quartzWork.Trigger, nameof(quartzWork.Trigger));
                Check.NotNull(quartzWork.JobDetail, nameof(quartzWork.JobDetail));

                AsyncHelper.RunSync(() => _scheduler.ScheduleJob(quartzWork.JobDetail, quartzWork.Trigger));
            }
        }
        public void ReportProgress_InvokeFunctionWhileWorkerReportsProgressIsFalse_ThrowsInvalidOperationException()
        {
            // arrange
            IBackgroundWorker worker = InitializeWorker();

            TestDelegate testDelegate = () => worker.ReportProgress(It.IsAny <int>());

            // act, assert
            Assert.That(testDelegate, Throws.Exception.TypeOf <InvalidOperationException>());
        }
Пример #33
0
 public EventCommitter(ICommittingEventQueueFactory queueFactory, ICache cache, IBackgroundWorker backgroundWorker, ILogger <EventCommitter> logger, VoguediOptions options)
 {
     this.queueFactory     = queueFactory;
     this.cache            = cache;
     this.backgroundWorker = backgroundWorker;
     this.logger           = logger;
     expiration            = options.MemoryQueueExpiration;
     backgroundWorkerKey   = $"{nameof(EventCommitter)}_{SnowflakeId.Default().NewId()}";
     queueMapping          = new ConcurrentDictionary <string, ICommittingEventQueue>();
 }
Пример #34
0
        public PlaybackService(IBackgroundWorker backgroundWorker)
        {
            Guard.NotNull(backgroundWorker, "backgroundWorker");

            this._backgroundWorker = backgroundWorker;
            this._backgroundWorker.DoWork += this.BackgroundWorker_DoWork;
            this._backgroundWorker.RunWorkerCompleted += this.BackgroundWorker_RunWorkerCompleted;

            this._assembly = Assembly.GetExecutingAssembly();
            this._currentPlayerState = PlayerState.NotInitialized;
            this._words = new List<string>();
        }
        public RandomizerWorker(IFileService fileService, ITraverseService traverseService, IContext uiContext, IBackgroundWorker backgroundWorker)
        {
            if (fileService == null) throw new ArgumentNullException("fileService");
            if (traverseService == null) throw new ArgumentNullException("traverseService");
            if (uiContext == null) throw new ArgumentNullException("uiContext");
            if (backgroundWorker == null) throw new ArgumentNullException("backgroundWorker");

            _fileService = fileService;
            _traverseService = traverseService;
            _uiContext = uiContext;
            _backgroundWorker = backgroundWorker;
        }
Пример #36
0
        public CopyWorker(IFileSystem fileSystem, IFileHelper fileHelper, IContext uiContext, IBackgroundWorker backgroundWorker, IUniqueCharsGenerator charsGenerator)
        {
            if (fileSystem == null) throw new ArgumentNullException("fileSystem");
            if (fileHelper == null) throw new ArgumentNullException("fileHelper");
            if (uiContext == null) throw new ArgumentNullException("uiContext");
            if (backgroundWorker == null) throw new ArgumentNullException("backgroundWorker");
            if (charsGenerator == null) throw new ArgumentNullException("charsGenerator");

            _fileSystem = fileSystem;
            _fileHelper = fileHelper;
            _uiContext = uiContext;
            _backgroundWorker = backgroundWorker;
            _charsGenerator = charsGenerator;
        }
Пример #37
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);
            bgWorker = app.ServiceLocator.Get<IBackgroundWorker>();
            logger = SmeedeeApp.Instance.ServiceLocator.Get<ILog>();

            flipper = FindViewById<RealViewSwitcher>(Resource.Id.WidgetContainerFlipper);
            flipper.ScreenChanged += HandleScreenChanged;

            _bottomRefreshButton = FindViewById<Button>(Resource.Id.WidgetContainerBtnBottomRefresh);
            _bottomRefreshButton.Click += delegate { RefreshCurrentWidget(); };

            AddWidgetsToFlipper();

            foreach (var widget in _widgets)
            {
                widget.DescriptionChanged += WidgetDescriptionChanged;
            }
        }
Пример #38
0
 public FakeImageService(IBackgroundWorker worker)
 {
     this.worker = worker;
     this.bytes = imageToByteArray(defaultImage);
 }
 public FakeLatestCommitsService()
 {
     bgWorker = app.ServiceLocator.Get<IBackgroundWorker>();
 }
Пример #40
0
 public LatestCommitsService()
 {
     downloader = app.ServiceLocator.Get<IFetchHttp>();
     bgWorker = app.ServiceLocator.Get<IBackgroundWorker>();
 }
 public WorkerTester(IBackgroundWorker worker)
 {
     this.worker = worker;
 }
 public FakeTopCommittersService()
 {
     bgWorker = app.ServiceLocator.Get<IBackgroundWorker>();
 }
Пример #43
0
 public ImageService(IBackgroundWorker worker)
 {
     this.worker = worker;
 }
 public FakeLatestCommitsService()
 {
     bgWorker = SmeedeeApp.Instance.ServiceLocator.Get<IBackgroundWorker>();
 }
 public FakeBuildStatusService(IBackgroundWorker bgWorker)
 {
     this.bgWorker = bgWorker;
     Builds = DefaultBuilds;
 }
Пример #46
0
 public ValidationService()
 {
     http = SmeedeeApp.Instance.ServiceLocator.Get<IFetchHttp>();
     bgWorker = SmeedeeApp.Instance.ServiceLocator.Get<IBackgroundWorker>();
 }
 public FakeWorkingDaysLeftService()
 {
     bgWorker = app.ServiceLocator.Get<IBackgroundWorker>();
 }
Пример #48
0
 public BuildStatusService()
 {
     downloader = SmeedeeApp.Instance.ServiceLocator.Get<IFetchHttp>();
     bgWorker = SmeedeeApp.Instance.ServiceLocator.Get<IBackgroundWorker>();
 }
Пример #49
0
 public TopCommittersService()
 {
     bgWorker = app.ServiceLocator.Get<IBackgroundWorker>();
     http = app.ServiceLocator.Get<IFetchHttp>();
 }