Пример #1
0
        CraigsListResultCollection GetAllPreviousCraigsListResult()
        {
            if (!(File.Exists(LOG_FILE_NAME)))
            {
                return(null);
            }
            XmlSerializer serializer = new XmlSerializer(typeof(CraigsListResultCollection));
            StreamReader  reader     = new StreamReader(LOG_FILE_NAME);
            CraigsListResultCollection previousCraigsListResults = (CraigsListResultCollection)serializer.Deserialize(reader);

            reader.Close();
            return(previousCraigsListResults);
        }
Пример #2
0
        void ParseCraigsListResult(string result)
        {
            ResultsTextbox.Clear();
            List <CraigsListResult>    newResults = new List <CraigsListResult>();
            CraigsListResultCollection previousCraigsListResults = GetAllPreviousCraigsListResult();
            CraigsListResult           latestCraigsListResult    = null;
            //if (null != previousCraigsListResults)
            //{
            //    latestCraigsListResult = previousCraigsListResults.CraigsListResult[0];
            //}

            //ClearPreviousCraigsListResult();

            string rowPattern = "<li class=\"result-row\"";

            string[] rows = Regex.Split(result, rowPattern);

            string spanPattern = "<p class=\"result-info\">";

            foreach (string row in rows)
            {
                if (row.Contains(spanPattern))
                {
                    string temp = "<li " + row.Trim();
                    // if row doesn't end with </li> clear it
                    if (!temp.EndsWith("</li>"))
                    {
                        temp = temp.Substring(0, temp.IndexOf("</li>") + 5);
                    }


                    XmlDocument xml = new XmlDocument();
                    xml.LoadXml(temp);
                    CraigsListResult parsedRow = ParseCraigsListRow(xml);

                    if (parsedRow == latestCraigsListResult)
                    {
                        ResultsTextbox.AppendText("No more new results were found.");
                        break;
                    }

                    int setPrice = 0;
                    try
                    {
                        setPrice = Convert.ToInt32(parsedRow.price);
                    }
                    catch (Exception)
                    {
                        setPrice = -1;
                    }

                    if (maxPrice > setPrice)
                    {
                        ShowCraigsListParsedRow(parsedRow);
                        newResults.Add(parsedRow);
                    }
                }
            }

            //SaveCraigsListResult(previousCraigsListResults);
        }