public static String PublishClass(int headerId, String SaveDir = "") { List <int> commentIds = new List <int>(); List <String> fileNames = new List <string>(); String packFileName = ""; using (WebhostEntities db = new WebhostEntities()) { CommentHeader header = db.CommentHeaders.Find(headerId); packFileName = String.Format("{0} {1} comments", header.Section.Block.LongName, header.Section.Course.Name).ToLower(); WebhostEventLog.CommentLog.LogInformation("Publishing {0}", packFileName); packFileName = packFileName.Replace(" ", "_"); packFileName = packFileName.Replace("\"", ""); Regex disalowedChars = new Regex(@"(\.|:|&|#|@|\*|~|\?|<|>|\||\^|( ( )+)|/)"); foreach (Match match in disalowedChars.Matches(packFileName)) { packFileName = packFileName.Replace(match.Value, ""); } foreach (int id in header.StudentComments.Select(c => c.id)) { fileNames.Add((new CommentLetter(id)).Publish(SaveDir)); } } if (SaveDir.Equals("")) { return(MailControler.PackForDownloading(fileNames, packFileName, HttpContext.Current.Server)); } else { return(MailControler.PackForDownloading(fileNames, String.Format("{0}\\{1}.zip", SaveDir, packFileName))); } }
protected void GetAccountsBtn_Click(object sender, EventArgs e) { List <String> files = new List <string>(); List <CSV> csvs = Import.GetNewAccountsCSVs(SelectedIds); csvs[0].Save(Server.MapPath("~/Temp/gmail_users.csv")); csvs[1].Save(Server.MapPath("~/Temp/ad_users.csv")); Response.Redirect(MailControler.PackForDownloading(new List <string>() { "~/Temp/gmail_users.csv", "~/Temp/ad_users.csv" }, "new users", Server)); }
public static String PublishTermByStudent(int termId = -1, List <int> studentIds = null, String SaveDir = "") { using (WebhostEntities db = new WebhostEntities()) { if (db.Terms.Where(t => t.id == termId).Count() <= 0) { termId = Import.GetCurrentOrLastTerm(); } Term term = db.Terms.Where(t => t.id == termId).Single(); String packFileName = term.Name.ToLower() + "_term_comments.zip"; List <String> termCommentFiles = new List <string>(); if (studentIds == null) { studentIds = Import.ActiveStudents(termId); } foreach (int studentId in studentIds) { Student student = db.Students.Where(s => s.ID == studentId).Single(); String studentFileName = String.Format("[{3}] {0}, {1} {2} Comments.zip", student.LastName, student.FirstName, term.Name, student.GraduationYear); WebhostEventLog.CommentLog.LogInformation("Publishing {0}", studentFileName); List <String> studentFiles = new List <String>(); List <int> commentIds = student.StudentComments.Where(com => com.CommentHeader.TermIndex == termId).Select(com => com.id).ToList(); foreach (int id in commentIds) { studentFiles.Add((new CommentLetter(id)).Publish(SaveDir)); } if (SaveDir.Equals("")) { termCommentFiles.Add(MailControler.PackForDownloading(studentFiles, studentFileName, HttpContext.Current.Server)); } else { termCommentFiles.Add(MailControler.PackForDownloading(studentFiles, String.Format("{0}\\{1}", SaveDir, studentFileName))); } } if (SaveDir.Equals("")) { return(MailControler.PackForDownloading(termCommentFiles, packFileName, HttpContext.Current.Server)); } else { return(MailControler.PackForDownloading(termCommentFiles, String.Format("{0}\\{1}", SaveDir, packFileName))); } } }
/// <summary> /// Publish comments via commandline tool. dumps them in C:\Temp /// Defaults to this term, all students. /// </summary> /// <param name="termId"></param> /// <param name="studentIds"></param> public static void CommandLinePublish(int termId = -1, List <int> studentIds = null) { using (WebhostEntities db = new WebhostEntities()) { if (db.Terms.Where(t => t.id == termId).Count() <= 0) { termId = Import.GetCurrentOrLastTerm(); } Term term = db.Terms.Where(t => t.id == termId).Single(); String packFileName = term.Name.ToLower() + "_term_comments"; List <String> termCommentFiles = new List <string>(); if (studentIds == null) { studentIds = Import.ActiveStudents(termId); } foreach (int studentId in studentIds) { Student student = db.Students.Where(s => s.ID == studentId).Single(); String studentFileName = String.Format("{0}, {1} [{3}] {2} Comments", student.LastName, student.FirstName, term.Name, student.GraduationYear); Console.WriteLine("Publishing {0}, {1} [2]", student.LastName, student.FirstName, student.GraduationYear); List <String> studentFiles = new List <string>(); List <StudentComment> commentIds = student.StudentComments.Where(com => com.CommentHeader.TermIndex == termId).ToList(); foreach (StudentComment comment in commentIds) { studentFiles.Add((new CommentLetter(comment.id, true)).Publish(true)); Console.WriteLine("\t[{0}] {1}", comment.CommentHeader.Section.Block.LongName, comment.CommentHeader.Section.Course.Name); } termCommentFiles.Add(MailControler.PackForDownloading(studentFiles, studentFileName)); } MailControler.PackForDownloading(termCommentFiles, packFileName); } }
protected static void ExecuteClassRequest(XMLTree xml, String saveDir) { int termId = Convert.ToInt32(xml.Attributes["termid"]); List <int> studentIds = new List <int>(); List <String> filenames = new List <string>(); foreach (XMLTree studentTree in xml.ChildTrees.Where(tree => tree.TagName.Equals("section")).ToList()) { int headerId = Convert.ToInt32(studentTree.Attributes["headerid"]); filenames.Add(CommentLetter.PublishClass(headerId, saveDir)); } String zipFile = MailControler.PackForDownloading(filenames, String.Format("{0}\\classes_{1}.zip", saveDir, DateTime.Now.Ticks)); MailControler.MailToUser("Comments Published Successfully", String.Format("Click the Link to download the comments you requested:{0}{1}", Environment.NewLine, zipFile.Replace("W:", "https://webhost.dublinschool.org").Replace("\\", "/")), String.Format("{0}@dublinschool.org", xml.Attributes["username"]), xml.Attributes["name"].Replace('_', ' '), "*****@*****.**", "Comment Bot"); }