// Applies |process_body| to all bodies but the sun in the tree of celestial // bodies, in topological order. private void ApplyToBodyTree(BodyProcessor process_body) { // Tree traversal (DFS, not that it matters). Stack<CelestialBody> stack = new Stack<CelestialBody>(); foreach (CelestialBody child in Planetarium.fetch.Sun.orbitingBodies) { stack.Push(child); } CelestialBody body; while (stack.Count > 0) { body = stack.Pop(); process_body(body); foreach (CelestialBody child in body.orbitingBodies) { stack.Push(child); } } }
public string alarmEmail(int ttid, string addresses) { if (!CurrentContext.Valid) { return("Please login"); } Defect d = new Defect(ttid); MailMessage mail = new MailMessage(); foreach (string addr in addresses.Split(',')) { mail.To.Add(new MailAddress(addr.Trim())); } mail.From = new MailAddress(CurrentContext.User.EMAIL.Trim()); mail.Subject = string.Format("TT{0} {1}", d.ID, d.SUMMARY); mail.IsBodyHtml = true; string descr = d.DESCR.Replace(Environment.NewLine, "<br/>"); descr = descr.Replace("\n", "<br/>"); descr = BodyProcessor.ResolveLinks(descr); descr = Regex.Replace(descr, "----+", "<hr>"); descr = Regex.Replace(descr, "====+", "<hr>"); string body = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"; body += "<HTML><HEAD><META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\">"; body += "</HEAD><BODY'>" + descr + " </BODY></HTML>"; System.Net.Mime.ContentType mimeType = new System.Net.Mime.ContentType("text/html"); AlternateView alternate = AlternateView.CreateAlternateViewFromString(body, mimeType); mail.AlternateViews.Add(alternate); SmtpClient smtp = new SmtpClient(); Settings sett = Settings.CurrentSettings; smtp.Host = sett.SMTPHOST; smtp.Port = Convert.ToInt32(sett.SMTPPORT); smtp.EnableSsl = Convert.ToBoolean(sett.SMTPENABLESSL);; smtp.Timeout = Convert.ToInt32(sett.SMTPTIMEOUT);; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.UseDefaultCredentials = false; smtp.Credentials = new NetworkCredential(sett.CREDENTIALS1, sett.CREDENTIALS2); string strError = "The email was sent!"; long counter = 0; while (true) { try { counter++; smtp.Send(mail); break; } catch (Exception e) { strError = e.Message; if (!strError.Contains("The operation has timed out.") || counter > 10) { break; } } } return(strError); }