コード例 #1
0
        void ShowCraigsListParsedRow(CraigsListResult parsedRow)
        {
            string result = string.Empty;

            // See if sale posting includes picture
            result += (parsedRow.hasPicture) ? "Sale posting includes picture\r\n" : "Sale posting does *NOT* include picture\r\n";

            // Show the date of posting
            result += string.Format("Date of posting is: {0}\r\n", parsedRow.date);

            // Show price of posting
            result += string.Format("Posted price: {0}\r\n", parsedRow.price);

            // Show description
            result += string.Format("Title of posting: {0}\r\n", parsedRow.description);

            // Show hyperlink
            result += string.Format("Link to posting: {0}\r\n", parsedRow.hyperlink);

            // Show location
            result += string.Format("Location of item: {0}\r\n", parsedRow.location);

            // Add a blank line
            result += "\r\n";

            ResultsTextbox.AppendText(result);
        }
コード例 #2
0
        void SaveCraigsListResult(CraigsListResult parsedRow)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(CraigsListResult));
            TextWriter    writer     = new StreamWriter(LOG_FILE_NAME, true);

            serializer.Serialize(writer, parsedRow);
            writer.Close();
        }
コード例 #3
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);
        }