예제 #1
0
        public void PrepareInitializationCommands()
        {
            _commandQueue.Add(_tickModuleInitializeCommand);
            _commandQueue.Add(_loggerModuleInitializeCommand);
            _commandQueue.Add(_playerModuleInitializeCommand);
            _commandQueue.Add(_renderModuleInitializeCommand);

            _commandQueue.OnComplete += HandleAllCommandsComplete;
        }
예제 #2
0
        private void GetHtml(Link link)
        {
            try
            {
                _logger.Log(LogType.Info, $"Started to gather data from {link.GetClassName()} with Id: {link.Id}");
                var htmlData = _dataGatherer.Gather(link);
                _logger.Log(LogType.Info, $"Finished to gather data from {link.GetClassName()} with Id: {link.Id}");

                using (var transaction = _htmlDataRepository.GetTransaction())
                {
                    _htmlDataRepository.Insert(htmlData, transaction);
                    _logger.Log(LogType.Info, $"Inserted new {htmlData.GetClassName()} to database");

                    _linkRepository.Delete(link);
                    _logger.Log(LogType.Info, $"Removed {link.GetClassName()} with Id: {link.Id}");

                    _commandQueue.Add(new ExtractDataCommand()
                    {
                        Id = Guid.NewGuid().ToString()
                    });
                    _logger.Log(LogType.Info, $"Created new {typeof(ExtractDataCommand).Name} 1x1");
                }
            }
            catch (Exception e)
            {
                using (var transaction = _linkRepository.GetTransaction())
                {
                    link.Status = Status.Failed;
                    _linkRepository.Update(link, transaction);
                    _logger.Log(LogType.Error, $"Failed to gather data from {link.GetClassName()} with Id: {link.Id}|{e.Message}");
                }
                throw;
            }
        }
        public void AddGatherDataCommands(int numberOfLinks, ITransaction transaction)
        {
            var linksPerCommand = 10;   // configuration

            for (int i = 0; i < numberOfLinks / linksPerCommand; i++)
            {
                _commandQueue.Add(new GatherDataCommand(linksPerCommand)
                {
                    Id = Guid.NewGuid().ToString()
                }, transaction);
            }

            _commandQueue.Add(new GatherDataCommand(numberOfLinks % linksPerCommand)
            {
                Id = Guid.NewGuid().ToString()
            }, transaction);

            _logger.Log(LogType.Info, $"Created new {typeof(GatherDataCommand).Name}s: {numberOfLinks / linksPerCommand}x{linksPerCommand} and 1x{numberOfLinks % linksPerCommand}");
        }
 private void AddDefaultCommands()
 {
     _commandQueue.Add(new GetLinksCommand(OfferType.Olx));
     _commandQueue.Add(new GetLinksCommand(OfferType.OtoDom));
 }