Exemplo n.º 1
0
 /// <summary>
 /// Retrieves list of quotes from specified xml file
 /// </summary>
 /// <param name="xmlPath">path of xml file to read from</param>
 public IList<IList<IIMDbQuote>> ReadQuotes(
     string xmlPath)
 {
     try
     {
         List<IList<IIMDbQuote>> quotes = new List<IList<IIMDbQuote>>();
         if (System.IO.File.Exists(xmlPath))
         {
             System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
             doc.Load(xmlPath);
             System.Xml.XmlNodeList quoteBlockList = doc.SelectNodes("/Quotes/QuoteBlock");
             if (quoteBlockList != null)
                 foreach (System.Xml.XmlNode quoteBlockNode in quoteBlockList)
                 {
                     List<IIMDbQuote> quoteBlock = new List<IIMDbQuote>();
                     foreach (System.Xml.XmlNode quoteNode in quoteBlockNode.ChildNodes)
                     {
                         if (quoteNode["Character"] != null
                             && quoteNode["Character"].InnerText != null
                             && quoteNode["Character"].InnerText.Trim() != ""
                             && quoteNode["QuoteText"] != null
                             && quoteNode["QuoteText"].InnerText != null
                             && quoteNode["QuoteText"].InnerText.Trim() != "")
                         {
                             IMDbQuote quote = new IMDbQuote();
                             quote.Character = quoteNode["Character"].InnerText;
                             quote.Text = quoteNode["QuoteText"].InnerText;
                             quoteBlock.Add(quote);
                         }
                     }
                     if (quoteBlock.Count > 0)
                         quotes.Add(quoteBlock);
                 }
         }
         return quotes;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        private void GetQuotes(ref IMDbMovie movie, string quotesURL)
        {
            // get quotes html
            string html = ToolBox.WebUtils.GetSiteContents(quotesURL);  //Old Code: JCUtils.WebUtils.GET(quotesURL);

            // Grab quotes
            Match match1 = GetRegExMatch(html, _quoteBlockPattern);
            while (match1 != null && match1.Length > 0)
            {
                string quoteBlockHTML = GetMatchValue(match1, "QuoteBlock", false);
                if (quoteBlockHTML.Trim() != "")
                {
                    List<IIMDbQuote> quoteBlock = new List<IIMDbQuote>();
                    Match match2 = GetRegExMatch(quoteBlockHTML, _quotePattern);
                    while (match2 != null && match2.Length > 0)
                    {
                        IMDbQuote quote = new IMDbQuote();
                        quote.Character = GetMatchValue(match2, "Character", true);
                        quote.Text = GetMatchValue(match2, "Quote", true);
                        quoteBlock.Add(quote);
                        match2 = match2.NextMatch();
                    }
                    if (quoteBlock.Count > 0)
                        movie.Quotes.Add(quoteBlock);
                }
                match1 = match1.NextMatch();
            }
        }