Beispiel #1
0
    //0 = Wood
    //1 = Stone
    //2 = Food
    //3 = Water
    public void AddResource(int amount, int resourceIndex, JobActivator optionalJobRemove = default)
    {
        switch (resourceIndex)
        {
        case 0:
            currentWoodAmount += amount;
            woodText.text      = currentWoodAmount.ToString();
            break;

        case 1:
            currentStoneAmount += amount;
            stoneText.text      = currentStoneAmount.ToString();
            break;

        case 2:
            currentFoodAmount += amount;
            foodText.text      = currentFoodAmount.ToString();;
            break;

        case 3:
            currentWaterAmount += amount;
            waterText.text      = currentWaterAmount.ToString();;
            break;
        }

        if (optionalJobRemove)
        {
            allJobs.Remove(optionalJobRemove);
        }
    }
Beispiel #2
0
        public object Perform(JobActivator activator, IJobCancellationToken cancellationToken)
        {
            if (activator == null)
            {
                throw new ArgumentNullException("activator");
            }
            if (cancellationToken == null)
            {
                throw new ArgumentNullException("cancellationToken");
            }

            object instance = null;

            object result = null;

            try
            {
                if (!Method.IsStatic)
                {
                    instance = Activate(activator);
                }

                var deserializedArguments = DeserializeArguments(cancellationToken);
                result = InvokeMethod(instance, deserializedArguments);
            }
            finally
            {
                Dispose(instance);
            }

            return(result);
        }
Beispiel #3
0
 public void GiveNewJob(JobActivator job)
 {
     job.AddNewWorker(gameObject);
     targetObject = job.transform;
     SetTransformTarget(job.transform);
     animator.SetInteger("JobIndex", job.GetJobIndex());
 }
        public void DefaultActivator_ThrowAnException_IfThereIsNoDefaultConstructor()
        {
            var activator = new JobActivator();

            Assert.Throws<MissingMethodException>(
                () => activator.ActivateJob(typeof (CustomConstructor)));
        }
Beispiel #5
0
        public object Perform(JobActivator activator, IJobCancellationToken cancellationToken)
        {
            if (activator == null) throw new ArgumentNullException("activator");
            if (cancellationToken == null) throw new ArgumentNullException("cancellationToken");

            object instance = null;

            object result;
            try
            {
                if (!Method.IsStatic)
                {
                    instance = Activate(activator);
                }

                var deserializedArguments = DeserializeArguments(cancellationToken);
                result = InvokeMethod(instance, deserializedArguments, cancellationToken.ShutdownToken);
            }
            finally
            {
                Dispose(instance);
            }

            return result;
        }
 public BackgroundJobPerformer(
     [NotNull] IJobFilterProvider filterProvider,
     [NotNull] JobActivator activator,
     [CanBeNull] TaskScheduler taskScheduler)
     : this(filterProvider, new CoreBackgroundJobPerformer(activator, taskScheduler))
 {
 }
Beispiel #7
0
        public object Perform(JobActivator activator, IJobCancellationToken cancellationToken)
        {
            if (activator == null)
            {
                throw new ArgumentNullException(nameof(activator));
            }
            if (cancellationToken == null)
            {
                throw new ArgumentNullException(nameof(cancellationToken));
            }

            object instance = null;

            object result;

            try
            {
                if (!Method.IsStatic)
                {
                    instance = Activate(activator);
                }

                var arguments = GetArguments(cancellationToken);
                result = InvokeMethod(instance, arguments, cancellationToken);
            }
            finally
            {
                Dispose(instance);
            }

            return(result);
        }
Beispiel #8
0
        public static (BackgroundJobServer server, IRecurringJobManager recurringJobManager, IBackgroundJobClient backgroundJobClient) StartHangfireServer(
            string serverName,
            string connectionString,
            IApplicationLifetime applicationLifetime,
            IJobFilterProvider jobFilters,
            JobActivator jobActivator,
            IBackgroundJobFactory backgroundJobFactory,
            IBackgroundJobPerformer backgroundJobPerformer,
            IBackgroundJobStateChanger backgroundJobStateChanger,
            IBackgroundProcess[] additionalProcesses
            )
        {
            var options = new BackgroundJobServerOptions
            {
                ServerName = serverName,
                Queues     = new string[] { serverName, "default" }
            };

            return(StartHangfireServer(
                       options,
                       connectionString,
                       applicationLifetime,
                       jobFilters,
                       jobActivator,
                       backgroundJobFactory,
                       backgroundJobPerformer,
                       backgroundJobStateChanger,
                       additionalProcesses
                       ));
        }
        public void GetCurrent_ReturnsPreviouslySetValue()
        {
            var activator = new JobActivator();
            JobActivator.Current = activator;

            Assert.Same(activator, JobActivator.Current);
        }
Beispiel #10
0
        public CoreRuntime(RuntimeConfiguration runtimeConfiguration)
        {
            var jobTypeResolver = new JobTypeResolver(runtimeConfiguration.JobTypeSearchAssemblies);
            var serviceProvider = runtimeConfiguration.ServiceProvider ?? new DefaultServiceProvider();

            this.jobActivator = new JobActivator(jobTypeResolver, serviceProvider);
        }
        public SqlAndAzureServiceBusBackendJobServerConfiguration(IAppEnvironmentProvider appEnvironmentProvider, JobActivator jobActivator, IAutofacDependencyManager dependencyManager, ILogProvider logProvider)
        {
            if (appEnvironmentProvider == null)
            {
                throw new ArgumentNullException(nameof(appEnvironmentProvider));
            }

            if (jobActivator == null)
            {
                throw new ArgumentNullException(nameof(jobActivator));
            }

            if (dependencyManager == null)
            {
                throw new ArgumentNullException(nameof(dependencyManager));
            }

            if (logProvider == null)
            {
                throw new ArgumentNullException(nameof(logProvider));
            }

            _logProvider = logProvider;

            _appEnvironmentProvider = appEnvironmentProvider;
            _jobActivator           = jobActivator;
            _lifetimeScope          = dependencyManager.GetContainer();
        }
Beispiel #12
0
        public object Perform(JobActivator activator, IJobExecutionContext jobExecutionContext)
        {
            if (activator == null)
            {
                throw new ArgumentNullException("activator");
            }
            if (jobExecutionContext == null)
            {
                throw new ArgumentNullException("jobExecutionContext");
            }

            object instance = null;

            object result = null;

            try
            {
                if (!Method.IsStatic)
                {
                    instance = Activate(activator);
                }

                var deserializedArguments = DeserializeArguments(jobExecutionContext);
                result = InvokeMethod(instance, deserializedArguments);
            }
            finally
            {
                Dispose(instance);
            }

            return(result);
        }
Beispiel #13
0
        public Worker(
            [NotNull] IEnumerable <string> queues,
            [NotNull] IBackgroundJobPerformer performer,
            [NotNull] IBackgroundJobStateChanger stateChanger,
            [NotNull] JobActivator activator)
        {
            if (queues == null)
            {
                throw new ArgumentNullException(nameof(queues));
            }
            if (performer == null)
            {
                throw new ArgumentNullException(nameof(performer));
            }
            if (stateChanger == null)
            {
                throw new ArgumentNullException(nameof(stateChanger));
            }
            if (activator == null)
            {
                throw new ArgumentNullException(nameof(activator));
            }

            _queues       = queues.ToArray();
            _performer    = performer;
            _stateChanger = stateChanger;
            _activator    = activator;
            _workerId     = Guid.NewGuid().ToString();
            _profiler     = new SlowLogProfiler(_logger);
        }
Beispiel #14
0
        public void DefaultActivator_ThrowAnException_IfThereIsNoDefaultConstructor()
        {
            var activator = new JobActivator();

            Assert.Throws <MissingMethodException>(
                () => activator.ActivateJob(typeof(CustomConstructor)));
        }
 internal DefaultJobPerformanceProcess(JobActivator activator, IEnumerable <object> filters)
     : this(activator)
 {
     if (filters != null)
     {
         _getFiltersThunk = jd => filters.Select(f => new JobFilter(f, JobFilterScope.Type, null));
     }
 }
 public DefaultJobPerformanceProcess([NotNull] JobActivator activator)
 {
     if (activator == null)
     {
         throw new ArgumentNullException("activator");
     }
     _activator = activator;
 }
 public SimpleJobActivatorScope([NotNull] JobActivator activator)
 {
     if (activator == null)
     {
         throw new ArgumentNullException(nameof(activator));
     }
     _activator = activator;
 }
 internal DefaultJobPerformanceProcess(JobActivator activator, IEnumerable<object> filters)
     : this(activator)
 {
     if (filters != null)
     {
         _getFiltersThunk = jd => filters.Select(f => new JobFilter(f, JobFilterScope.Type, null));
     }
 }
Beispiel #19
0
        public void DefaultActivator_CanCreateInstanceOfClassWithDefaultConstructor()
        {
            var activator = new JobActivator();

            var instance = activator.ActivateJob(typeof(DefaultConstructor));

            Assert.NotNull(instance);
        }
Beispiel #20
0
        public void GetCurrent_ReturnsPreviouslySetValue()
        {
            var activator = new JobActivator();

            JobActivator.Current = activator;

            Assert.Same(activator, JobActivator.Current);
        }
Beispiel #21
0
        public void DefaultActivator_CanCreateInstanceOfClassWithDefaultConstructor()
        {
            var activator = new JobActivator();

            var instance = activator.ActivateJob(typeof (DefaultConstructor));

            Assert.NotNull(instance);
        }
Beispiel #22
0
 public CoreAsyncBackgroundJobPerformer([NotNull] JobActivator activator)
 {
     if (activator == null)
     {
         throw new ArgumentNullException(nameof(activator));
     }
     _activator = activator;
 }
Beispiel #23
0
        private static JobActivatorScope BeginScope(JobActivator activator)
        {
#if NET45
            return(activator.BeginScope());
#else
            return(activator.BeginScope(null));
#endif
        }
Beispiel #24
0
 private HangfireService(JobActivator activator, string connectionString)
 {
     GlobalConfiguration.Configuration
     .UseActivator(activator)
     .UseSQLiteStorage(connectionString)
     .UseFilter(new AutomaticRetryAttribute {
         Attempts = 0
     });
 }
Beispiel #25
0
 public JobWorkerBuilder(IZeebeClient zeebeClient,
                         Gateway.GatewayClient gatewayClient,
                         ILoggerFactory loggerFactory = null)
 {
     LoggerFactory = loggerFactory;
     Activator     = new JobActivator(gatewayClient);
     Request       = new ActivateJobsRequest();
     JobClient     = zeebeClient;
     ThreadCount   = 1;
 }
Beispiel #26
0
 internal JobWorker(JobWorkerBuilder builder)
 {
     source         = new CancellationTokenSource();
     activator      = new JobActivator(builder.Client);
     activeRequest  = builder.Request;
     maxJobsActive  = activeRequest.MaxJobsToActivate;
     pollInterval   = builder.PollInterval();
     jobClient      = new JobClientWrapper(builder.JobClient);
     jobHandler     = builder.Handler();
     autoCompletion = builder.AutoCompletionEnabled();
 }
Beispiel #27
0
 internal JobWorker(Gateway.GatewayClient client, ActivateJobsRequest request, TimeSpan pollInterval,
                    IJobClient jobClient, JobHandler jobHandler)
 {
     this.source        = new CancellationTokenSource();
     this.client        = client;
     this.activator     = new JobActivator(client);
     this.activeRequest = request;
     this.maxJobsActive = request.MaxJobsToActivate;
     this.pollInterval  = pollInterval;
     this.jobClient     = jobClient;
     this.jobHandler    = jobHandler;
 }
        public static void Main()
        {
            JobActivator = new JobActivator();
            var config = new JobHostConfiguration {
                JobActivator = JobActivator
            };

            config.UseTimers();

            var host = new JobHost(config);

            host.RunAndBlock();
        }
Beispiel #29
0
 internal JobWorker(JobWorkerBuilder builder)
 {
     this.jobWorkerBuilder        = builder;
     this.source                  = new CancellationTokenSource();
     this.logger                  = builder.LoggerFactory?.CreateLogger <JobWorker>();
     this.jobHandler              = jobWorkerBuilder.Handler();
     this.autoCompletion          = builder.AutoCompletionEnabled();
     this.pollInterval            = jobWorkerBuilder.PollInterval();
     this.activateJobsRequest     = jobWorkerBuilder.Request;
     jobActivator                 = jobWorkerBuilder.Activator;
     this.maxJobsActive           = jobWorkerBuilder.Request.MaxJobsToActivate;
     this.thresholdJobsActivation = maxJobsActive * 0.6;
 }
        public JobSchedulerInMemoryBackendConfiguration(JobActivator jobActivator, IAutofacDependencyManager dependencyManager)
        {
            if (jobActivator == null)
            {
                throw new ArgumentNullException(nameof(jobActivator));
            }

            _jobActivator = jobActivator;

            if (dependencyManager == null)
            {
                throw new ArgumentNullException(nameof(dependencyManager));
            }

            _container = dependencyManager.GetContainer();
        }
Beispiel #31
0
        public CoreBackgroundJobPerformer(
            [NotNull] JobActivator activator,
            [NotNull] IJobFilterProvider filterProvider)
        {
            if (activator == null)
            {
                throw new ArgumentNullException("activator");
            }
            if (filterProvider == null)
            {
                throw new ArgumentNullException("filterProvider");
            }

            _activator      = activator;
            _filterProvider = filterProvider;
        }
Beispiel #32
0
        public void WhenICallTheActivateMethodWithTheTypeArgument(string type)
        {
            try
            {
                Type jobType = null;

                if (type == "TestJob") jobType = typeof (TestJob);
                else if (type == "CustomConstructorJob") jobType = typeof (CustomConstructorJob);

                var activator = new JobActivator();
                _jobInstance = activator.ActivateJob(jobType);
            }
            catch (Exception ex)
            {
                _exception = ex;
            }
        }
Beispiel #33
0
    private void AssignSpecificJob(JobActivator job)
    {
        int allocatedJobs = job.GetCurrentWorkers();

        for (int i = 0; i < allCitizens.Count; i++)
        {
            if (allocatedJobs >= job.GetMaxJobWorkers())
            {
                return;
            }
            if (!allCitizens[i].GetComponent <Citizen>().HasActiveJob())
            {
                allocatedJobs++;
                allCitizens[i].GetComponent <Citizen>().GiveNewJob(job);
            }
        }
    }
Beispiel #34
0
        public static (BackgroundJobServer server, IRecurringJobManager recurringJobManager, IBackgroundJobClient backgroundJobClient) StartHangfireServer(
            BackgroundJobServerOptions options,
            string connectionString,
            IApplicationLifetime applicationLifetime,
            IJobFilterProvider jobFilters,
            JobActivator jobActivator,
            IBackgroundJobFactory backgroundJobFactory,
            IBackgroundJobPerformer backgroundJobPerformer,
            IBackgroundJobStateChanger backgroundJobStateChanger,
            IBackgroundProcess[] additionalProcesses
            )
        {
            JobStorage storage;

            if (string.IsNullOrWhiteSpace(connectionString))
            {
                storage = new MemoryStorage();
            }
            else if (ConnectionStringHelper.IsSQLite(connectionString))
            {
                storage = new SQLiteStorage(connectionString);
            }
            else
            {
                storage = new SqlServerStorage(connectionString);
            }

            var server = new BackgroundJobServer(options, storage, additionalProcesses,
                                                 options.FilterProvider ?? jobFilters,
                                                 options.Activator ?? jobActivator,
                                                 backgroundJobFactory,
                                                 backgroundJobPerformer,
                                                 backgroundJobStateChanger);

            applicationLifetime.ApplicationStopping.Register(() => server.SendStop());
            applicationLifetime.ApplicationStopped.Register(() => server.Dispose());

            var recurringJobManager = new RecurringJobManager(storage, backgroundJobFactory);

            var backgroundJobClient = new BackgroundJobClient(storage, backgroundJobFactory, backgroundJobStateChanger);

            return(server, recurringJobManager, backgroundJobClient);
        }
Beispiel #35
0
        private object Activate(JobActivator activator)
        {
            try
            {
                var instance = activator.ActivateJob(Type);

                if (instance == null)
                {
                    throw new InvalidOperationException($"JobActivator returned NULL instance of the '{Type}' type.");
                }

                return instance;
            }
            catch (Exception ex)
            {
                throw new JobPerformanceException(
                    "An exception occurred during job activation.",
                    ex);
            }
        }
Beispiel #36
0
        private object Activate(JobActivator activator)
        {
            try
            {
                var instance = activator.ActivateJob(Type);

                if (instance == null)
                {
                    throw new InvalidOperationException($"JobActivator returned NULL instance of the '{Type}' type.");
                }

                return(instance);
            }
            catch (Exception ex)
            {
                throw new JobPerformanceException(
                          "An exception occurred during job activation.",
                          ex);
            }
        }
        internal SharedWorkerContext(
            string serverId,
            string[] queues,
            JobStorage storage,
            IJobPerformanceProcess performanceProcess,
            JobActivator activator,
            IStateMachineFactory stateMachineFactory)
        {
            if (serverId == null)
            {
                throw new ArgumentNullException("serverId");
            }
            if (queues == null)
            {
                throw new ArgumentNullException("queues");
            }
            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }
            if (performanceProcess == null)
            {
                throw new ArgumentNullException("performanceProcess");
            }
            if (activator == null)
            {
                throw new ArgumentNullException("activator");
            }
            if (stateMachineFactory == null)
            {
                throw new ArgumentNullException("stateMachineFactory");
            }

            ServerId            = serverId;
            Queues              = queues;
            Storage             = storage;
            PerformanceProcess  = performanceProcess;
            Activator           = activator;
            StateMachineFactory = stateMachineFactory;
        }
        internal SharedWorkerContext(
            string serverId,
            string[] queues,
            JobStorage storage,
            IJobPerformanceProcess performanceProcess,
            JobActivator activator,
            IStateMachineFactory stateMachineFactory)
        {
            if (serverId == null) throw new ArgumentNullException("serverId");
            if (queues == null) throw new ArgumentNullException("queues");
            if (storage == null) throw new ArgumentNullException("storage");
            if (performanceProcess == null) throw new ArgumentNullException("performanceProcess");
            if (activator == null) throw new ArgumentNullException("activator");
            if (stateMachineFactory == null) throw new ArgumentNullException("stateMachineFactory");

            ServerId = serverId;
            Queues = queues;
            Storage = storage;
            PerformanceProcess = performanceProcess;
            Activator = activator;
            StateMachineFactory = stateMachineFactory;
        }
 public DefaultJobPerformanceProcess([NotNull] JobActivator activator)
 {
     if (activator == null) throw new ArgumentNullException("activator");
     _activator = activator;
 }
 public CoreBackgroundJobPerformer([NotNull] JobActivator activator)
 {
     if (activator == null) throw new ArgumentNullException("activator");
     _activator = activator;
 }