Beispiel #1
0
        private void CheckSites()
        {
            try
            {
                foreach (Dictionary <string, string> item in items)
                {
                    if ((item["enabled"] != null && item["enabled"] == "false") || item["enabled"] == null)
                    {
                        continue;
                    }

                    UpdateStatus("Status: Checking " + item["name"] + " at " + item["url"] + ".");
                    WebRequest request = WebRequest.Create(item["url"]);

                    WebResponse response = request.GetResponse();

                    Stream ReceiveStream = response.GetResponseStream();

                    Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

                    StreamReader readStream = new StreamReader(ReceiveStream, encode);

                    string strResponse = readStream.ReadToEnd();
                    if (strResponse == null || strResponse.Length <= 0)
                    {
                        continue;
                    }

                    string regex = item["searchString"];

                    Regex reg = new Regex(regex, RegexOptions.IgnoreCase);

                    bool invertLogic = false;

                    if (item["invertLogic"] != null)
                    {
                        invertLogic = bool.Parse(item["invertLogic"]);
                    }

                    bool isMatch = reg.IsMatch(strResponse);

                    if ((isMatch && !invertLogic) || (!isMatch && invertLogic))
                    {
                        UpdateStatus("Status: Not found at " + item["name"] + ".");
                    }
                    else if ((isMatch && invertLogic) || (!isMatch && !invertLogic))
                    {
                        if (!notified)
                        {
                            LogItem logItem = new LogItem("Wii Found at " + item["name"] + "!!", DateTime.Now, strResponse);
                            logs.Add(logItem);
                            UpdateStatus("Status: Item found at " + item["name"] + ".");
                            UpdateLogView();

                            notified = true;
                            Notify(item["name"], item["url"]);
                            niMain.BalloonTipText  = "Wii is available! The Wii has been found at " + item["name"] + ".";
                            niMain.BalloonTipTitle = "Wii Avilable";
                            niMain.ShowBalloonTip(7000);
                            System.Diagnostics.Process.Start(item["url"]);
                            Stop();
                        }
                    }

                    readStream.Close();

                    response.Close();
                }
                UpdateStatus("Status: Idle");
            }
            catch (WebException ex)
            {
                /// There was a problem in the networking. Just ignore. We'll try again
                /// on the next go round.
                LogItem item = new LogItem(ex.Message, System.DateTime.Now, "");
                logs.Add(item);
                UpdateLogView();
            }
            catch (Exception ex)
            {
                LogItem item = new LogItem(ex.Message, System.DateTime.Now, "");
                logs.Add(item);
                UpdateLogView();
            }
        }
Beispiel #2
0
        public int CompareTo(object obj)
        {
            LogItem input = (LogItem)obj;

            return(input.LogDate.CompareTo(this.LogDate));
        }