private void TimerElapsed(object sender, ElapsedEventArgs e)
        {
            HtmlWeb web = new HtmlWeb();
            try
            {
                var doc = web.Load("http://szforum/viewforum.php?f=31");
                var posts = doc.DocumentNode.SelectNodes("//ul[@class='topiclist topics']")[1];
                var postCount = posts.SelectNodes("li").Count;

                if (postCount != currentPostCount)
                {
                    currentPostCount = postCount;
                    if (EventHapped != null)
                    {
                        var eventArgs = new EventHappenedEventArgs { Message = "New Post of gym club!" };
                        EventHapped(this, eventArgs);
                    }
                }
            }
            catch (Exception ex)
            {
                if (EventHapped != null)
                {
                    EventHapped(this, new EventHappenedEventArgs { Message = ex.Message });
                }
            }
        }
        public void SendNotification(object sender, EventHappenedEventArgs eventArgs)
        {
            if (_emailAddr.Count == 0)
            {
                Console.WriteLine("No register");
                return;
            }

            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("*****@*****.**", "Kun Zhu");

            foreach (var address in _emailAddr)
            {
                msg.To.Add(address);
            }

            msg.Body = eventArgs.Message;

            msg.Subject = eventArgs.Message;
            DevPublicSmtpClient smtpClient = new DevPublicSmtpClient();
            
            try
            {
                smtpClient.Send(msg);
                Console.WriteLine("Succeed:" + string.Join(",", _emailAddr.ToArray()));
            }
            catch (Exception e)
            {
                //TODO: handle exception.
                string s = e.Message;
                Console.WriteLine(s + ":" + string.Join(",", _emailAddr.ToArray()));
            }
        }
예제 #3
0
 static void Listener_EventHapped(object sender, EventHappenedEventArgs eventArgs)
 {
     Console.WriteLine(eventArgs.Message);
 }