public Ticket(XmlNode node) { Id = int.Parse(node.Attributes["id"].Value); Subject = node.Attributes["subject"].Value; Priority = node.Attributes["priority"].Value; Status = node.Attributes["status"].Value; AssignedTo = (node.Attributes["assignedto"] == null) ? "" : node.Attributes["assignedto"].Value; if (node.SelectNodes("Note")[0].Attributes["date"] != null) { Date = DateTime.Parse(node.SelectNodes("Note")[0].Attributes["date"].Value + " " + node.SelectNodes("Note")[0].Attributes["time"].Value).ToString("dd/MM/yy HH:mm"); } Date = DateTime.Parse(node.SelectNodes("Note")[0].Attributes["datetime"].Value).ToString("dd/MM/yy HH:mm"); try { Username = ADUtils.FindUserInfos(node.SelectNodes("Note")[0].Attributes["username"].Value)[0].UserName; } catch { Username = "******"; } ShowTo = node.Attributes["showto"] == null ? "" : node.Attributes["showto"].Value; try { DisplayName = ADUtils.FindUserInfos(node.SelectNodes("Note")[0].Attributes["username"].Value)[0].DisplayName; } catch { DisplayName = "UNKNOWN"; } FAQ = false; if (node.Attributes["faq"] != null) { FAQ = bool.Parse(node.Attributes["faq"].Value); } ReadBy = node.Attributes["readby"] != null ? node.Attributes["readby"].Value : ""; }
public UserInfo[] getMembers(string UserType) { List <UserInfo> results = new List <UserInfo>(); if (UserType == "Teacher") { results.Add(ADUtils.FindUserInfos(Teacher)[0]); } UserNodes.Reverse(); foreach (UserNode n in UserNodes) { if (n.Method == "Add") { switch (n.Type) { case "User": results.Add(ADUtils.FindUserInfos(n.Value)[0]); break; case "Role": foreach (string s in ADUtils.GetUsersInRole(ADUtils.DirectoryRoot, hapConfig.Current.AD.UPN, n.Value, true)) { results.Add(ADUtils.FindUserInfos(s)[0]); } break; case "OU": results.AddRange(ADUtils.FindUsersIn(n.Value)); break; } } else { switch (n.Type) { case "User": results.RemoveAll(ui => ui.UserName.ToLower() == n.Value.ToLower()); break; case "Role": foreach (string s in ADUtils.GetUsersInRole(ADUtils.DirectoryRoot, hapConfig.Current.AD.UPN, n.Value, true)) { results.RemoveAll(ui => ui.UserName.ToLower() == s.ToLower()); } break; case "OU": foreach (UserInfo i in ADUtils.FindUsersIn(n.Value)) { results.RemoveAll(ui => ui.UserName.ToLower() == i.UserName.ToLower()); } break; } } } UserNodes.Reverse(); return(results.ToArray()); }
public Note(Data.SQL.Note n) { NoteText = HttpUtility.UrlDecode(n.Content.Replace("<![CDATA[", "").Replace("]]>", "").Replace("\n", "<br />"), System.Text.Encoding.Default); Date = n.DateTime; try { User = ADUtils.FindUserInfos(n.Username)[0].DisplayName; } catch { User = "******"; } }
public Ticket(Data.SQL.Ticket tick) { Id = tick.Id; Subject = tick.Title; Priority = tick.Priority; Status = tick.Status; Date = tick.Notes[0].DateTime; try { User = ADUtils.FindUserInfos(tick.Notes[0].Username)[0].DisplayName; } catch { User = "******"; } }
public Note(XmlNode node) { Attachments = new Attachment[] {}; NoteText = HttpUtility.UrlDecode(node.InnerXml.Replace("<![CDATA[", "").Replace("]]>", "").Replace("\n", "<br />"), System.Text.Encoding.Default); if (node.Attributes["date"] != null && node.Attributes["time"] != null) { Date = DateTime.Parse(node.Attributes["date"].Value + " " + node.Attributes["time"].Value).ToString("dd/MM/yy HH:mm"); } else { Date = DateTime.Parse(node.Attributes["datetime"].Value).ToString("dd/MM/yy HH:mm"); } Username = node.Attributes["username"].Value; try { DisplayName = ADUtils.FindUserInfos(node.Attributes["username"].Value)[0].DisplayName; } catch { DisplayName = "UNKNOWN"; } Hide = (node.Attributes["hide"] != null) ? bool.Parse(node.Attributes["hide"].Value) : false; }
public Ticket(Data.SQL.Ticket tick) { Id = tick.Id; Subject = tick.Title; Priority = tick.Priority; Status = tick.Status; AssignedTo = (tick.AssignedTo == null) ? "" : tick.AssignedTo; Date = tick.Notes[0].DateTime.ToString("dd/MM/yy HH:mm"); try { Username = ADUtils.FindUserInfos(tick.Notes[0].Username)[0].UserName; } catch { Username = "******"; } ShowTo = tick.ShowTo == null ? "" : tick.ShowTo; try { DisplayName = ADUtils.FindUserInfos(tick.Notes[0].Username)[0].DisplayName; } catch { DisplayName = "UNKNOWN"; } FAQ = tick.Faq; ReadBy = tick.ReadBy; }
public Note(Data.SQL.Note n) { NoteText = HttpUtility.UrlDecode(n.Content.Replace("<![CDATA[", "").Replace("]]>", "").Replace("\n", "<br />"), System.Text.Encoding.Default); Date = n.DateTime.ToString("dd/MM/yy HH:mm"); Username = n.Username; try { DisplayName = ADUtils.FindUserInfos(n.Username)[0].DisplayName; } catch { DisplayName = "UNKNOWN"; } Hide = n.Hide; Id = n.Id; List <Attachment> attachments = new List <Attachment>(); foreach (Data.SQL.NoteFile nf in n.NoteFiles) { attachments.Add(new Attachment { Name = nf.FileName, CType = nf.ContentType }); } Attachments = attachments.ToArray(); }
public static void GenerateCancel(Booking booking, DateTime date, bool emailadmins) { try { if (string.IsNullOrEmpty(booking.User.Email)) { return; } } catch { return; } hapConfig config = hapConfig.Current; StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); string[] lessons = booking.Lesson.Split(new char[] { ',' }); DateTime startDate = new DateTime(date.Year, date.Month, date.Day, config.BookingSystem.Lessons.Get(lessons[0].Trim()).StartTime.Hour, config.BookingSystem.Lessons.Get(lessons[0].Trim()).StartTime.Minute, 0); DateTime endDate = new DateTime(date.Year, date.Month, date.Day, config.BookingSystem.Lessons.Get(lessons[lessons.Length - 1].Trim()).EndTime.Hour, config.BookingSystem.Lessons.Get(lessons[lessons.Length - 1].Trim()).EndTime.Minute, 0); string location = ""; Resource resource = config.BookingSystem.Resources[booking.Room]; if (resource.Type == ResourceType.Room) { location = booking.Room; } else if (resource.Type == ResourceType.Laptops) { location = booking.LTRoom; } else if (resource.Type == ResourceType.Equipment || resource.Type == ResourceType.Loan) { location = booking.EquipRoom; } string summary = "Cancellation of " + booking.Name + " in " + location; string description = "Cancellation of " + booking.Name + " in " + location + " during " + booking.Lesson + " on " + booking.Date.ToShortDateString() + " (" + DateTime.Now.ToString() + ")"; if (resource.Type == ResourceType.Laptops) { summary += " with the " + booking.Room + " [" + booking.Count + "]"; description += " with the " + booking.Room + " [" + booking.Count + "]"; } sb.AppendLine("BEGIN:VCALENDAR"); sb.AppendLine("VERSION:2.0"); sb.AppendLine("PRODID:-//hap/CalendarAppointment"); sb.AppendLine("CALSCALE:GREGORIAN"); sb.AppendLine("METHOD:CANCEL"); sb.AppendLine("BEGIN:VEVENT"); sb.AppendLine("DTSTART:" + startDate.ToUniversalTime().ToString(DateFormat)); sb.AppendLine("DTEND:" + endDate.ToUniversalTime().ToString(DateFormat)); sb.AppendLine("ORGANIZER:MAILTO:" + booking.User.Email); sb.AppendLine("LOCATION:" + location); sb.AppendLine("UID:" + booking.uid); sb.AppendLine("DTSTAMP:" + DateTime.Now.ToString(DateFormat)); sb.AppendLine("SUMMARY:" + summary); sb.AppendLine("STATUS:CANCELLED"); sb.AppendLine("DESCRIPTION:" + description); sb.AppendLine("END:VEVENT"); sb.AppendLine("END:VCALENDAR"); FileInfo file = new FileInfo(HttpContext.Current.Server.MapPath("~/App_Data/ITBooking.ics")); if (file.Exists) { file.Delete(); } StreamWriter sr = file.CreateText(); sr.Write(sb.ToString()); sr.Flush(); sr.Close(); sr.Dispose(); MailMessage mes = new MailMessage(); IFormatProvider culture = new CultureInfo("en-gb"); mes.Subject = summary; mes.From = mes.Sender = new MailAddress(config.SMTP.FromEmail, config.SMTP.FromUser); mes.ReplyToList.Add(mes.From); foreach (string s in hapConfig.Current.BookingSystem.Resources[booking.Room].Admins.Split(new char[] { ',' })) { if (s != "Inherit") { UserInfo ui = ADUtils.FindUserInfos(s.Trim())[0]; try { if (string.IsNullOrEmpty(ui.Email)) { continue; } } catch { continue; } if (!string.IsNullOrEmpty(ui.Email)) { mes.To.Add(new MailAddress(ui.Email, ui.DisplayName)); } } } mes.Body = description; AlternateView av = AlternateView.CreateAlternateViewFromString(sb.ToString(), new ContentType("text/calendar; method=CANCEL; name=ITBooking.ics")); av.TransferEncoding = TransferEncoding.SevenBit; mes.AlternateViews.Add(av); ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); }; //mes.Attachments.Add(new Attachment(file.FullName, "text/calendar; method=REQUEST; name=ITBooking.ics")); SmtpClient client = new SmtpClient(config.SMTP.Server); if (!string.IsNullOrEmpty(config.SMTP.User)) { client.Credentials = new NetworkCredential(config.SMTP.User, config.SMTP.Password); client.UseDefaultCredentials = false; } client.EnableSsl = config.SMTP.SSL; if (config.SMTP.TLS) { client.TargetName = "STARTTLS/" + config.SMTP.Server; client.DeliveryMethod = SmtpDeliveryMethod.Network; } client.Port = config.SMTP.Port; client.Send(mes); }
public static void Generate(Booking booking, DateTime date, bool emailadmins) { hapConfig config = hapConfig.Current; StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); DateTime startDate = new DateTime(date.Year, date.Month, date.Day, config.BookingSystem.Lessons.Get(booking.Lesson).StartTime.Hour, config.BookingSystem.Lessons.Get(booking.Lesson).StartTime.Minute, 0); DateTime endDate = new DateTime(date.Year, date.Month, date.Day, config.BookingSystem.Lessons.Get(booking.Lesson).EndTime.Hour, config.BookingSystem.Lessons.Get(booking.Lesson).EndTime.Minute, 0); string location = ""; Resource resource = config.BookingSystem.Resources[booking.Room]; Templates t = new Templates(); Template template = t["generaladmin"]; if (t.ContainsKey(resource.Name)) { template = t[resource.Name + "admin"]; } string ltcount = ""; if (resource.Type == ResourceType.Room) { location = booking.Room; } else if (resource.Type == ResourceType.Laptops) { location = booking.LTRoom; ltcount = booking.Count.ToString(); } else if (resource.Type == ResourceType.Equipment) { location = booking.EquipRoom; } string summary = string.Format(template.Subject, booking.Username, booking.User.DisplayName, booking.Room, booking.Name, booking.Date.ToShortDateString(), booking.Day, booking.Lesson, location, ltcount); string description = string.Format(template.Content, booking.Username, booking.User.DisplayName, booking.Room, booking.Name, booking.Date.ToShortDateString(), booking.Day, booking.Lesson, location, ltcount); List <UserInfo> uis = new List <UserInfo>(); sb.AppendLine("BEGIN:VCALENDAR"); sb.AppendLine("VERSION:2.0"); sb.AppendLine("PRODID:-//chsit/CalendarAppointment"); sb.AppendLine("CALSCALE:GREGORIAN"); sb.AppendLine("METHOD:REQUEST"); sb.AppendLine("BEGIN:VEVENT"); sb.AppendLine("DTSTART:" + startDate.ToUniversalTime().ToString(DateFormat)); sb.AppendLine("DTEND:" + endDate.ToUniversalTime().ToString(DateFormat)); sb.AppendLine("ORGANIZER;CN=" + booking.User.DisplayName + ":MAILTO:" + booking.User.Email); sb.AppendLine("ATTENDEE;ROLE=REQ-PARTICIPANT;CN=" + booking.User.DisplayName + ":MAILTO:" + booking.User.Email); foreach (string s in hapConfig.Current.BookingSystem.Resources[booking.Room].Admins.Split(new char[] { ',' })) { UserInfo ui = ADUtils.FindUserInfos(s)[0]; uis.Add(ui); if (!string.IsNullOrEmpty(ui.Email)) { sb.AppendLine("ATTENDEE;ROLE=REQ-PARTICIPANT;CN=" + ui.DisplayName + ":MAILTO:" + ui.Email); } } sb.AppendLine("LOCATION:" + location); sb.AppendLine("UID:" + booking.uid); sb.AppendLine("DTSTAMP:" + DateTime.Now.ToString(DateFormat)); sb.AppendLine("SUMMARY:" + summary); sb.AppendLine("DESCRIPTION:" + description); sb.AppendLine("BEGIN:VALARM"); sb.AppendLine("ACTION:DISPLAY"); sb.AppendLine("DESCRIPTION:" + summary); sb.AppendLine("TRIGGER:-PT5M"); sb.AppendLine("END:VALARM"); sb.AppendLine("END:VEVENT"); sb.AppendLine("END:VCALENDAR"); FileInfo file = new FileInfo(HttpContext.Current.Server.MapPath("~/App_Data/ITBooking.ics")); if (file.Exists) { file.Delete(); } StreamWriter sr = file.CreateText(); sr.Write(sb.ToString()); sr.Flush(); sr.Close(); sr.Dispose(); MailMessage mes = new MailMessage(); IFormatProvider culture = new CultureInfo("en-gb"); mes.Subject = summary; mes.From = mes.Sender = new MailAddress(config.SMTP.FromEmail, config.SMTP.FromUser); mes.ReplyToList.Add(mes.From); foreach (UserInfo u1 in uis.Where(u => !string.IsNullOrEmpty(u.Email))) { mes.To.Add(new MailAddress(u1.Email, u1.DisplayName)); } mes.Body = description; AlternateView av = AlternateView.CreateAlternateViewFromString(sb.ToString(), new ContentType("text/calendar; method=REQUEST; name=ITBooking.ics")); av.TransferEncoding = TransferEncoding.SevenBit; mes.AlternateViews.Add(av); //mes.Attachments.Add(new Attachment(file.FullName, "text/calendar; method=REQUEST; name=ITBooking.ics")); SmtpClient client = new SmtpClient(config.SMTP.Server); if (!string.IsNullOrEmpty(config.SMTP.User)) { client.Credentials = new NetworkCredential(config.SMTP.User, config.SMTP.Password); } client.EnableSsl = config.SMTP.SSL; client.Port = config.SMTP.Port; client.Send(mes); }