protected override void OnStop() { _timer1.AutoReset = false; _timer1.Enabled = false; SendMailService.WriteErrorLog("Service stopped"); SendMailService.SendEmail(ServiceProperty.Email, "Service Report", $"Service on {Environment.MachineName} has been stopped on {DateTime.Now.ToLongTimeString()}."); }
protected override void OnStart(string[] args) { _timer1.AutoReset = true; _timer1.Enabled = true; SendMailService.WriteErrorLog("Service started"); SendMailService.SendEmail(ServiceProperty.Email, "Service Report", $"Service has been is started on {Environment.MachineName} on {DateTime.Now.ToLongTimeString()}."); }
public string GetRssFeed() { try { WebClient webClient = new WebClient(); string rssData = webClient.DownloadString("https://www.brainyquote.com/link/quotebr.rss"); XDocument xml = XDocument.Parse(rssData); IEnumerable <RssFeed> rssFeedData = (from x in xml.Descendants("item") select new RssFeed { Title = ((string)x.Element("title")), Description = ((string)x.Element("description")) }); string message = string.Empty; foreach (RssFeed item in rssFeedData) { message += $"{item.Description} - {item.Title} \n"; } return(message); } catch (Exception e) { SendMailService.WriteErrorLog(e.Message); return(null); } }
// For Laptop protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus) { if (powerStatus.HasFlag(PowerBroadcastStatus.Suspend)) { SendMailService.WriteErrorLog("System has been shutdown."); SendMailService.SendEmail(ServiceProperty.Email, "Service Report", "Your system has been down on " + DateTime.Now.ToLongTimeString()); } return(true); }
private void ServiceTimer_Tick(object sender, ElapsedEventArgs e) { string msg = GetRssFeed(); if (!string.IsNullOrEmpty(msg)) { SendMailService.SendEmail(ServiceProperty.Email, "Today's Quote", msg); } if (GetCallType != 1) { return; } _timer1.Stop(); System.Threading.Thread.Sleep(1000000); SetTimer(); }
protected override void OnShutdown() { SendMailService.WriteErrorLog("System has been shutdown."); SendMailService.SendEmail(ServiceProperty.Email, "Service Report", $"{Environment.MachineName} went down on {DateTime.Now.ToLongTimeString()}"); }