Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
 void ShowProgress(int progress)
 {
     ResultsTextbox.AppendText(".");
     if (0 < progress)
     {
         ResultsTextbox.AppendText(progress + "\n\r");
     }
 }
        private async void CalculateButton_Click(object sender, EventArgs e)
        {
            ResultsTextbox.Clear();
            cancelRequested = false;
            int limit = int.Parse(LimitTextBox.Text);

            for (int i = 4; i <= limit; i++)
            {
                if (cancelRequested)
                {
                    break;
                }
                int    temp   = i;
                string result = await Task.Run(() => GetPair(temp));

                ResultsTextbox.AppendText(result);
            }
            ResultsTextbox.AppendText(cancelRequested ? "Cancelled" : "Done");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sends a query to CraigsList.  Assumes that validation for input has already been done.
        /// </summary>
        void GetCraigsListResult(string keyword, string maxPrice)
        {
            // Set up default query
            string query = string.Format("query={0}", keyword);

            // Include asking for maxprice
            if (maxPrice != string.Empty)
            {
                //format = rss &
                query         = string.Format("{0}&max_price={1}", query, maxPrice);
                this.maxPrice = Convert.ToInt32(maxPrice);
                hasMaxPrice   = true;
            }

            string inputURL = string.Format("https://seattle.craigslist.org/search/sss?{0}", query);
            string result   = string.Empty;

            ResultsTextbox.Clear();
            ResultsTextbox.AppendText("Loading");

            worker.DoWork += delegate(Object s, DoWorkEventArgs args)
            {
                result = GetWebPage(inputURL);
            };

            worker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args)
            {
                ShowProgress(args.ProgressPercentage);
            };

            worker.RunWorkerCompleted += delegate(Object s, RunWorkerCompletedEventArgs args)
            {
                if (!isCancelled)
                {
                    ParseCraigsListResult(result);
                }
            };

            worker.RunWorkerAsync();
        }
Ejemplo n.º 5
0
        void ReleaseDesignerOutlets()
        {
            if (BitView != null)
            {
                BitView.Dispose();
                BitView = null;
            }

            if (ClearButton != null)
            {
                ClearButton.Dispose();
                ClearButton = null;
            }

            if (CS_Label != null)
            {
                CS_Label.Dispose();
                CS_Label = null;
            }

            if (Input1Binary != null)
            {
                Input1Binary.Dispose();
                Input1Binary = null;
            }

            if (Input2Binary != null)
            {
                Input2Binary.Dispose();
                Input2Binary = null;
            }

            if (InputLabel1 != null)
            {
                InputLabel1.Dispose();
                InputLabel1 = null;
            }

            if (InputNumber2 != null)
            {
                InputNumber2.Dispose();
                InputNumber2 = null;
            }

            if (InputTextbox1 != null)
            {
                InputTextbox1.Dispose();
                InputTextbox1 = null;
            }

            if (InputTextbox2 != null)
            {
                InputTextbox2.Dispose();
                InputTextbox2 = null;
            }

            if (Results != null)
            {
                Results.Dispose();
                Results = null;
            }

            if (ResultsTextbox != null)
            {
                ResultsTextbox.Dispose();
                ResultsTextbox = null;
            }

            if (SegementedControl != null)
            {
                SegementedControl.Dispose();
                SegementedControl = null;
            }

            if (TypeLabel != null)
            {
                TypeLabel.Dispose();
                TypeLabel = null;
            }
        }
Ejemplo n.º 6
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);
        }
 private void CancelButton_Click(object sender, RoutedEventArgs e)
 {
     worker.CancelAsync();
     isCancelled = true;
     ResultsTextbox.AppendText("Cancelled!");
 }