示例#1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            StartupIoC.RegisterIoC(_locator);

            // make sure we're able to do work
            _worker = new WorkerRegistrationController(_locator).EnsureWorkerRegistration();
            _jobRepository = _locator.Locate<IJobRepository>();
            _presenter = new WorkloadPresenter(new WorkloadView());

            var poller = new JobPoller(_presenter, _locator, _worker);

            if (_worker.CurrentJob != Guid.Empty)
            {
                // start working on the job
                _presenter.CurrentJob = JobFactory.CreateJob(_jobRepository.GetCurrentJob(_worker.Id), _worker, _locator);
            }

            poller.Start();

            try
            {
                Application.Run((WorkloadView) _presenter.View);
            }
            finally
            {
                poller.Stop();
            }
        }
示例#2
0
        public JobPoller(WorkloadPresenter presenter, ILocator locator, WorkerState worker, int? intervalSeconds = null)
        {
            _interval = intervalSeconds ?? _interval;

            _presenter = presenter;
            _jobRepository = locator.Locate<IJobRepository>();
            _worker = worker;
            _serviceLocator = locator;
        }
示例#3
0
        public static IJob CreateJob(JobDescriptor description, WorkerState worker, ILocator locator)
        {
            var jobType = Type.GetType(description.JobType);
            if (jobType == null)
            {
                throw new TypeAccessException("Could not create a type from " + description.JobType);
            }
            var instance = Activator.CreateInstance(jobType, description, worker.Id, locator) as IJob;

            return instance;
        }
 public WorkerState EnsureWorkerRegistration()
 {
     if (_workerState == null)
     {
         object objLock;
         lock (objLock = new object())
         {
             if (_workerState == null)
             {
                 var worker = _repository.GetWorker(Environment.MachineName);
                 if (worker == null)
                 {
                     worker = _repository.RegisterWorker(Environment.MachineName);
                 }
                 _workerState = worker;
             }
         }
     }
     return _workerState;
 }