public void UpdateSection(string host, int key)
        {
            logger.Trace("Updating Plex host: {0}, Section: {1}", host, key);
            var url = String.Format("http://{0}/library/sections/{1}/refresh", host, key);

            _httpProvider.DownloadString(url);
        }
        public virtual bool DownloadNzb(string url, string title, bool recentlyAired)
        {
            try
            {
                string cat      = _configProvider.SabTvCategory;
                int    priority = recentlyAired ? (int)_configProvider.SabRecentTvPriority : (int)_configProvider.SabBacklogTvPriority;

                string name    = url.Replace("&", "%26");
                string nzbName = HttpUtility.UrlEncode(title);

                string action = string.Format("mode=addurl&name={0}&priority={1}&pp=3&cat={2}&nzbname={3}&output=json",
                                              name, priority, cat, nzbName);

                string request = GetSabRequest(action);
                logger.Info("Adding report [{0}] to the queue.", title);

                var response = _httpProvider.DownloadString(request);

                logger.Debug("Queue Response: [{0}]", response);

                CheckForError(response);
                return(true);
            }

            catch (WebException ex)
            {
                logger.Error("Error communicating with SAB: " + ex.Message);
            }

            return(false);
        }
Beispiel #3
0
        public virtual string SendCommand(string host, string command, string username, string password)
        {
            var url = String.Format("http://{0}/xbmcCmds/xbmcHttp?command={1}", host, command);

            if (!String.IsNullOrEmpty(username))
            {
                return(_httpProvider.DownloadString(url, username, password));
            }

            return(_httpProvider.DownloadString(url));
        }
        public virtual List <Int32> GetXemSeriesIds(string origin = "tvdb")
        {
            _logger.Trace("Fetching Series IDs from: {0}", origin);

            var url      = String.Format("{0}havemap?origin={1}", XEM_BASE_URL, origin);
            var response = _httpProvider.DownloadString(url);

            CheckForFailureResult(response);

            var result = JsonConvert.DeserializeObject <XemResult <List <Int32> > >(response);

            return(result.Data.ToList());
        }
        public virtual bool UpdateMappings()
        {
            try
            {
                var mappingsJson = _httpProvider.DownloadString(_configProvider.ServiceRootUrl + "/SceneMapping/Active");
                var mappings     = JsonConvert.DeserializeObject <List <SceneMapping> >(mappingsJson);

                Logger.Debug("Deleting all existing Scene Mappings.");
                _database.Delete <SceneMapping>(String.Empty);

                Logger.Debug("Adding Scene Mappings");
                _database.InsertMany(mappings);
            }

            catch (Exception ex)
            {
                Logger.InfoException("Failed to Update Scene Mappings:", ex);
                return(false);
            }
            return(true);
        }
Beispiel #6
0
        public virtual void PingServer(object sender)
        {
            if (!_iisProvider.ServerStarted)
            {
                return;
            }

            try
            {
                ICredentials identity = CredentialCache.DefaultCredentials;
                _httpProvider.DownloadString(_iisProvider.AppUrl, identity); //This should preload the home page, making the first load faster.
                string response = _httpProvider.DownloadString(_iisProvider.AppUrl + "/health", identity);

                if (!response.Contains("OK"))
                {
                    throw new ServerException("Health services responded with an invalid response.");
                }

                if (_pingFailCounter > 0)
                {
                    logger.Info("Application pool has been successfully recovered.");
                }

                _pingFailCounter = 0;
            }
            catch (Exception ex)
            {
                _pingFailCounter++;
                logger.Error("Application pool is not responding. Count: {0} - {1}", _pingFailCounter, ex.Message);
                if (_pingFailCounter >= 10)
                {
                    _pingFailCounter = 0;
                    _iisProvider.RestartServer();
                }
            }
        }
        public List <int> GetDailySeriesIds()
        {
            try
            {
                var dailySeriesIds = _httpProvider.DownloadString(_configProvider.ServiceRootUrl + "/DailySeries/AllIds");

                var seriesIds = JsonConvert.DeserializeObject <List <int> >(dailySeriesIds);

                return(seriesIds);
            }
            catch (Exception ex)
            {
                Logger.WarnException("Failed to get Daily Series", ex);
                return(new List <int>());
            }
        }
        private List <UpdatePackage> GetAvailablePackages()
        {
            var updateList    = new List <UpdatePackage>();
            var updateUrl     = _configProvider.UpdateUrl;
            var rawUpdateList = _httpProvider.DownloadString(updateUrl);
            var matches       = parseRegex.Matches(rawUpdateList);

            foreach (Match match in matches)
            {
                var updatePackage = new UpdatePackage();
                updatePackage.FileName = match.Groups["filename"].Value;
                updatePackage.Url      = updateUrl + updatePackage.FileName;
                updatePackage.Version  = new Version(match.Groups["version"].Value);
                updateList.Add(updatePackage);
            }

            return(updateList);
        }
Beispiel #9
0
        public override ValidationResult Test()
        {
            var releases = _feedFetcher.FetchRss(this);

            if (releases.Any())
            {
                return(new ValidationResult());
            }

            try
            {
                var url = RecentFeed.First();
                var xml = _httpProvider.DownloadString(url);

                NewznabPreProcessor.Process(xml, url);
            }
            catch (ApiKeyException)
            {
                _logger.Warn("Indexer returned result for Newznab RSS URL, API Key appears to be invalid");

                var apiKeyFailure = new ValidationFailure("ApiKey", "Invalid API Key");
                return(new ValidationResult(new List <ValidationFailure> {
                    apiKeyFailure
                }));
            }
            catch (RequestLimitReachedException)
            {
                _logger.Warn("Request limit reached");
            }
            catch (Exception ex)
            {
                _logger.WarnException("Unable to connect to indexer: " + ex.Message, ex);

                var failure = new ValidationFailure("Url", "Unable to connect to indexer, check the log for more details");
                return(new ValidationResult(new List <ValidationFailure> {
                    failure
                }));
            }

            return(new ValidationResult());
        }