コード例 #1
0
        private IIndexer GetInstance(IndexerDefinition indexerDefinition)
        {
            var type     = GetImplementation(indexerDefinition);
            var instance = (IIndexer)Activator.CreateInstance(type);

            instance.InstanceDefinition = indexerDefinition;
            return(instance);
        }
コード例 #2
0
        public Indexer Create(Indexer indexer)
        {
            var definition = new IndexerDefinition
            {
                Name           = indexer.Name,
                Enable         = indexer.Enable,
                Implementation = indexer.Implementation,
                Settings       = indexer.Settings.ToJson()
            };

            definition = _indexerRepository.Insert(definition);
            indexer.Id = definition.Id;

            return(indexer);
        }
コード例 #3
0
        private Indexer ToIndexer(IndexerDefinition definition)
        {
            var indexer = new Indexer();

            indexer.Id             = definition.Id;
            indexer.Enable         = definition.Enable;
            indexer.Instance       = GetInstance(definition);
            indexer.Name           = definition.Name;
            indexer.Implementation = definition.Implementation;

            if (indexer.Instance.GetType().GetMethod("ImportSettingsFromJson") != null)
            {
                indexer.Settings = ((dynamic)indexer.Instance).ImportSettingsFromJson(definition.Settings);
            }
            else
            {
                indexer.Settings = NullSetting.Instance;
            }

            return(indexer);
        }
コード例 #4
0
        public bool AtQueryLimit(IndexerDefinition indexer)
        {
            if (indexer.Id > 0 && ((IIndexerSettings)indexer.Settings).BaseSettings.QueryLimit.HasValue)
            {
                var queryCount = _historyService.CountSince(indexer.Id, DateTime.Now.AddHours(-24), new List <HistoryEventType> {
                    HistoryEventType.IndexerQuery, HistoryEventType.IndexerRss
                });
                var queryLimit = ((IIndexerSettings)indexer.Settings).BaseSettings.QueryLimit;

                if (queryCount > queryLimit)
                {
                    _logger.Info("Indexer {0} has exceeded maximum query limit for last 24 hours", indexer.Name);

                    return(true);
                }

                _logger.Debug("Indexer {0} has performed {1} of possible {2} queries in last 24 hours, proceeding", indexer.Name, queryCount, queryLimit);
            }

            return(false);
        }
コード例 #5
0
        public bool AtDownloadLimit(IndexerDefinition indexer)
        {
            if (indexer.Id > 0 && ((IIndexerSettings)indexer.Settings).BaseSettings.GrabLimit.HasValue)
            {
                var grabCount = _historyService.CountSince(indexer.Id, DateTime.Now.AddHours(-24), new List <HistoryEventType> {
                    HistoryEventType.ReleaseGrabbed
                });
                var grabLimit = ((IIndexerSettings)indexer.Settings).BaseSettings.GrabLimit;

                if (grabCount > grabLimit)
                {
                    _logger.Info("Indexer {0} has exceeded maximum grab limit for last 24 hours", indexer.Name);

                    return(true);
                }

                _logger.Debug("Indexer {0} has performed {1} of possible {2} grabs in last 24 hours, proceeding", indexer.Name, grabCount, grabLimit);
            }

            return(false);
        }
コード例 #6
0
 private Type GetImplementation(IndexerDefinition indexerDefinition)
 {
     return(_indexers.Select(c => c.GetType()).SingleOrDefault(c => c.Name.Equals(indexerDefinition.Implementation, StringComparison.InvariantCultureIgnoreCase)));
 }