public List<FlaggedItem> SearchAndFlag(SyndicatedFeed feed)
        {
            feed.LoadFeed();
            List<FlaggedItem> flaggedItems = flagItems(feed);

            return flaggedItems;
        }
 public static SyndicatedFeed GetFeed(string lUrl)
 {
     SyndicatedFeed retVal = new SyndicatedFeed { url = lUrl };
     retVal.LoadFeed();
     return retVal;
 }
        private List<FlaggedItem> flagItems(SyndicatedFeed feed)
        {
            //StringBuilder sb = new StringBuilder();
            //sb.Append("(");
            //foreach (string rule in FlagRules)
            //{
            //    sb.AppendFormat(@"(^|\W){0}($|\W)|", rule);
            //}

            //sb.Remove(sb.Length - 1, 1);

            //sb.Append(")");

            //string reStr = sb.ToString();
            //logger.Debug("Title Search Regex: {0}", reStr);
            //Regex re = new Regex(reStr, RegexOptions.Compiled | RegexOptions.IgnoreCase);
            List<FlaggedItem> flaggedItems = new List<FlaggedItem>();

            Regex itemNumRe = new Regex(@".*\/(?<num>.*?).htm", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            Regex resultRe = new Regex("thanks for flagging", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            Regex urlRe = new Regex("(?<url>http://.*?/)", RegexOptions.IgnoreCase);

            if (!urlRe.IsMatch(feed.Url))
            {
                logger.Error("Error in FeedToFlag.flagItems: Could not parse base URL out of Feed URL: {0}", feed.Url);
                throw new ApplicationException(string.Format("Error in FeedToFlag.flagItems: Could not parse base URL out of Feed URL: {0}", feed.Url));
            }

            string baseUrl = urlRe.Match(feed.Url).Groups["url"].Value;
            string flagFormat = string.Concat(baseUrl, "flag/?flagCode=15&postingID={0}");

            foreach (SyndicatedFeed.Item item in feed.FeedItems)
            {
                if (item.HasBeenRead)
                {
                    //this item has already been processed so move along
                    continue;
                }

                Regex re;

                foreach (string rule in FlagRules)
                {
                    string reStr = string.Format(@"(^|\W){0}($|\W)", rule);
                    re = new Regex(reStr, RegexOptions.IgnoreCase);
                    if (re.IsMatch(item.Title))
                    {
                        FlaggedItem fi = new FlaggedItem
                        {
                            FlaggedRegEx = re.ToString(),
                            Title = item.Title,
                            Url = item.Link
                        };

                        string itemNum = itemNumRe.Match(fi.Url).Groups["num"].Value;
                        string link = string.Format(flagFormat, itemNum);
                        string result = flagItem(link);
                        if (resultRe.IsMatch(result))
                        {
                            flaggedItems.Add(fi);
                            item.HasBeenRead = true;
                        }

                        break;
                    }
                }

            }

            return flaggedItems;
        }