Exemple #1
0
        public Tuple <FeedType, string> DetectFeedType()
        {
            var retrieveResult = RetrieveFeed();

            if (retrieveResult.Item1 != FeedReadResult.Success)
            {
                return(new Tuple <FeedType, string>(FeedType.Unknown, string.Empty));
            }

            return(new Tuple <FeedType, string>(FeedParserBase.DetectFeedType(retrieveResult.Item2), retrieveResult.Item2));
        }
Exemple #2
0
        private FeedReadResult ReadFeed(FeedCenterEntities database, bool forceRead)
        {
            try
            {
                // If not enabled then do nothing
                if (!Enabled)
                {
                    return(FeedReadResult.NotEnabled);
                }

                // Check if we're forcing a read
                if (!forceRead)
                {
                    // Figure out how long since we last checked
                    var timeSpan = DateTime.Now - LastChecked;

                    // Check if we are due to read the feed
                    if (timeSpan.TotalMinutes < CheckInterval)
                    {
                        return(FeedReadResult.NotDue);
                    }
                }

                // We're checking it now so update the time
                LastChecked = DateTime.Now;

                // Read the feed text
                var retrieveResult = RetrieveFeed();

                // Get the information out of the async result
                var result   = retrieveResult.Item1;
                var feedText = retrieveResult.Item2;

                // If we didn't successfully retrieve the feed then stop
                if (result != FeedReadResult.Success)
                {
                    return(result);
                }

                // Create a new RSS parser
                var feedParser = FeedParserBase.CreateFeedParser(this, feedText);

                // Parse the feed
                result = feedParser.ParseFeed(feedText);

                // If we didn't successfully parse the feed then stop
                if (result != FeedReadResult.Success)
                {
                    return(result);
                }

                // Create the removed items list - if an item wasn't seen during this check then remove it
                var removedItems = Items.Where(testItem => testItem.LastFound != LastChecked).ToList();

                // If items were removed the feed was updated
                if (removedItems.Count > 0)
                {
                    LastUpdated = DateTime.Now;
                }

                // Loop over the items to be removed
                foreach (var itemToRemove in removedItems)
                {
                    // Delete the item from the database
                    database.FeedItems.Remove(itemToRemove);

                    // Remove the item from the list
                    Items.Remove(itemToRemove);
                }

                // Process actions on this feed
                ProcessActions();

                return(FeedReadResult.Success);
            }
            catch (InvalidFeedFormatException exception)
            {
                Tracer.WriteException(exception.InnerException);

                return(FeedReadResult.InvalidXml);
            }
            catch (Exception exception)
            {
                Tracer.WriteLine(exception.Message);

                return(FeedReadResult.UnknownError);
            }
        }