Exemplo n.º 1
0
        public void StopThread()
        {
            DatabaseOptionBase.UnAssignWorkerFromAllAssigned(DatabaseWorker, _mongoConnection);

            DatabaseWorker.Delete(_mongoConnection);

            DatabaseWorker = null;
        }
Exemplo n.º 2
0
        private void SetLastWorkTime()
        {
            if (_lastUpdatedLastWorkTime + _updateLastWorkTimeMinimumInterval > Clock.Now)
            {
                return;
            }

            DatabaseWorker.LastWorkTime = Clock.Now;
            DatabaseWorker.Update(_mongoConnection);
        }
Exemplo n.º 3
0
        private List <DatabaseWorker> GetDeadWorkers()
        {
            DateTime lastAcceptableWorkerTime = Clock.Now - _timeToWaitForWorkers;

            List <DatabaseWorker> deadWorkers = DatabaseWorker.GetDeadWorkers(_connection, lastAcceptableWorkerTime);

            deadWorkers = deadWorkers.Where(worker => _threadHolders.Any(threadHolder => threadHolder.DatabaseWorker.Id == worker.Id) == false).ToList();

            return(deadWorkers);
        }
Exemplo n.º 4
0
        public ThreadHolder(MongoConnection mongoConnection, OptionStatus optionStatus)
        {
            _mongoConnection = mongoConnection;

            DatabaseWorker = new DatabaseWorker();
            DatabaseWorker.Create(_mongoConnection);
            _lastUpdatedLastWorkTime = Clock.Now;

            _optionFinder  = new OptionFinder(_mongoConnection);
            _optionStatus  = optionStatus;
            _optionDecider = new OptionDecider(_mongoConnection, _optionStatus);
        }
Exemplo n.º 5
0
        public List <OptionBase> Find(DatabaseWorker worker)
        {
            List <OptionBase> options = new List <OptionBase>();

            List <DatabaseOptionBase> databaseOptions;

            if (worker == null)
            {
                databaseOptions = _databaseOptionFinder.Find();
            }
            else
            {
                databaseOptions = _databaseOptionFinder.Find(worker);
            }

            List <Type> optionTypes = ReflectionHelper.GetChildTypes(typeof(OptionBase));

            foreach (DatabaseOptionBase databaseOption in databaseOptions)
            {
                string optionName = databaseOption.GetType().Name;

                Type optionType = optionTypes.SingleOrDefault(type => type.Name == optionName);

                if (optionType == null)
                {
                    Log.Write(_connection, $"Unknown option type {optionType}", typeof(OptionFinder), DataLayer.MongoData.Config.LogLevelEnum.OptionError);
                    continue;
                }

                OptionBase option = (OptionBase)Activator.CreateInstance(optionType, _connection, databaseOption);

                options.Add(option);
            }

            return(options);
        }