Last active
January 4, 2016 17:39
-
-
Save DinisCruz/8655035 to your computer and use it in GitHub Desktop.
Create zip with articles based on title list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var tempFolder = "_articlesMatches".tempDir(false); | |
| var targetZip = tempFolder + "_All.zip"; | |
| try | |
| { | |
| var fastZip = new ICSharpCode.SharpZipLib.Zip.FastZip(); | |
| fastZip.CreateEmptyDirectories = true; | |
| fastZip.CreateZip(targetZip, tempFolder, true, ""); | |
| return targetZip.fileExists(); | |
| } | |
| catch(Exception ex) | |
| { | |
| return ex; | |
| } | |
| return "done"; | |
| //O2Ref:ICSharpCode.SharpZipLib.dll | |
| var file = "https://gist.github.com/DinisCruz/8653339/raw/ce19914729bc232fdbfae2348803abeceb0b4ec8/gistfile1.txt".GET(); | |
| var titles = file.split("\n"); | |
| var tmDatabase = TM_Xml_Database.Current; | |
| var articles = tmDatabase.Cached_GuidanceItems.Values; | |
| var articlePaths = tmDatabase.GuidanceItems_FileMappings; | |
| var articlesMatches = new List<TeamMentor_Article>(); | |
| foreach(var article in articles) | |
| if(titles.contains(article.Metadata.Title)) | |
| { | |
| articlesMatches.add(article); | |
| var articlePath = articlePaths[article.Metadata.Id]; | |
| articlePath.file_Copy(tempFolder); | |
| // break; | |
| } | |
| return tempFolder.files().size(); | |
| return tempFolder; | |
| return articlesMatches.size(); | |
| return titles.contains("Request Smuggling Attack"); | |
| return titles.size(); | |
| return TM_Xml_Database.Current.Path_XmlDatabase; | |
| //using TeamMentor.CoreLib; | |
| //O2Ref:TeamMentor.CoreLib.dll |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var tilesData = "https://gist.github.com/DinisCruz/8653339/raw/ce19914729bc232fdbfae2348803abeceb0b4ec8/gistfile1.txt"; | |
| var email_To = "dcruz@securityinnovation.com"; | |
| var email_Subject = "TM Articles analysis"; | |
| var email_Body = "Please see the attached zip for matches of titles for the server {0} based on the list on {1}".format(); | |
| var tempFolder = "_articlesMatches".tempDir(false); | |
| var targetZip = tempFolder + "_All.zip"; | |
| var tmDatabase = TM_Xml_Database.Current; | |
| var secretData = tmDatabase.UserData.SecretData; | |
| //return targetZip.fileExists(); | |
| //using System.Net.Mail; | |
| //using System.Net; | |
| Action sendEmail = | |
| ()=>{ | |
| var mailMsg = new MailMessage(); | |
| mailMsg.To.Add(new MailAddress(email_To)); | |
| mailMsg.From = new MailAddress(email_To)); | |
| mailMsg.Subject = email_Subject; | |
| mailMsg.Body = email_Body; | |
| mailMsg.Attachments.Add(new Attachment(targetZip)); | |
| var smtpClient = new SmtpClient(secretData.SMTP_Server, 587); | |
| var credentials = new NetworkCredential(secretData.SMTP_UserName, secretData.SMTP_Password); | |
| smtpClient.Credentials = credentials; | |
| smtpClient.Send(mailMsg); | |
| }; | |
| Action zipTargetFolder = | |
| ()=>{ | |
| var fastZip = new ICSharpCode.SharpZipLib.Zip.FastZip(); | |
| fastZip.CreateEmptyDirectories = true; | |
| fastZip.CreateZip(targetZip, tempFolder, true, ""); | |
| }; | |
| return "<a href='https://teammentor-33-ci.azurewebsites.net/_TempFiles/_articlesMatches_All.zip' target='_blank'>Download zip here</a>"; | |
| return "done"; | |
| //O2Ref:ICSharpCode.SharpZipLib.dll | |
| var file = tilesData.GET(); | |
| var titles = file.split("\n"); | |
| var articles = tmDatabase.Cached_GuidanceItems.Values; | |
| var articlePaths = tmDatabase.GuidanceItems_FileMappings; | |
| var articlesMatches = new List<TeamMentor_Article>(); | |
| foreach(var article in articles) | |
| if(titles.contains(article.Metadata.Title)) | |
| { | |
| articlesMatches.add(article); | |
| var articlePath = articlePaths[article.Metadata.Id]; | |
| articlePath.file_Copy(tempFolder); | |
| // break; | |
| } | |
| return tempFolder.files().size(); | |
| return tempFolder; | |
| return articlesMatches.size(); | |
| return titles.contains("Request Smuggling Attack"); | |
| return titles.size(); | |
| return TM_Xml_Database.Current.Path_XmlDatabase; | |
| //using TeamMentor.CoreLib; | |
| //O2Ref:TeamMentor.CoreLib.dll |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var tilesData = "https://gist.github.com/DinisCruz/8653339/raw/ce19914729bc232fdbfae2348803abeceb0b4ec8/gistfile1.txt"; | |
| var email_To = "dcruz@securityinnovation.com"; | |
| var email_Subject = "TM Articles analysis"; | |
| var email_Body = "Please see the attached zip for matches of titles for the server {0} based on the list on {1}".format(); | |
| var tempFolder = "_articlesMatches".tempDir(false); | |
| var targetZip = tempFolder + "_All.zip"; | |
| var tmDatabase = TM_Xml_Database.Current; | |
| var secretData = tmDatabase.UserData.SecretData; | |
| //return targetZip.fileExists(); | |
| //using System.Net.Mail; | |
| //using System.Net; | |
| Action sendEmail = | |
| ()=>{ | |
| var mailMsg = new MailMessage(); | |
| mailMsg.To.Add(new MailAddress(email_To)); | |
| mailMsg.From = new MailAddress(email_To); | |
| mailMsg.Subject = email_Subject; | |
| mailMsg.Body = email_Body; | |
| mailMsg.Attachments.Add(new Attachment(targetZip)); | |
| var smtpClient = new SmtpClient(secretData.SMTP_Server, 587); | |
| var credentials = new NetworkCredential(secretData.SMTP_UserName, secretData.SMTP_Password); | |
| smtpClient.Credentials = credentials; | |
| smtpClient.Send(mailMsg); | |
| }; | |
| Action zipTargetFolder = | |
| ()=>{ | |
| var fastZip = new ICSharpCode.SharpZipLib.Zip.FastZip(); | |
| fastZip.CreateEmptyDirectories = true; | |
| fastZip.CreateZip(targetZip, tempFolder, true, ""); | |
| }; | |
| Action filterByTitleAndCopyToTempFolder = | |
| ()=>{ | |
| var file = tilesData.GET(); | |
| var titles = file.split("\n"); | |
| var articles = tmDatabase.Cached_GuidanceItems.Values; | |
| var articlePaths = tmDatabase.GuidanceItems_FileMappings; | |
| var articlesMatches = new List<TeamMentor_Article>(); | |
| foreach(var article in articles) | |
| if(titles.contains(article.Metadata.Title)) | |
| { | |
| articlesMatches.add(article); | |
| var articlePath = articlePaths[article.Metadata.Id]; | |
| articlePath.file_Copy(tempFolder); | |
| // break; | |
| } | |
| }; | |
| return "done"; | |
| //using TeamMentor.CoreLib; | |
| //O2Ref:TeamMentor.CoreLib.dll | |
| //O2Ref:ICSharpCode.SharpZipLib.dll |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var titlesData = "https://gist.github.com/DinisCruz/8653339/raw/ce19914729bc232fdbfae2348803abeceb0b4ec8/gistfile1.txt"; | |
| var email_To = "dcruz@securityinnovation.com"; | |
| var email_Subject = "TM Articles analysis"; | |
| var email_Body = "Please see the attached zip for matches of titles for based on the list from {0}".format(titlesData); | |
| var tempFolder = "_articlesMatches".tempDir(false); | |
| var targetZip = tempFolder + "_All.zip"; | |
| var tmDatabase = TM_Xml_Database.Current; | |
| var secretData = tmDatabase.UserData.SecretData; | |
| //return targetZip.fileExists(); | |
| //using System.Net.Mail; | |
| //using System.Net; | |
| Action sendEmail = | |
| ()=>{ | |
| var mailMsg = new MailMessage(); | |
| mailMsg.To.Add(new MailAddress(email_To)); | |
| mailMsg.From = new MailAddress(email_To); | |
| mailMsg.Subject = email_Subject; | |
| mailMsg.Body = email_Body; | |
| mailMsg.Attachments.Add(new Attachment(targetZip)); | |
| var smtpClient = new SmtpClient(secretData.SMTP_Server, 587); | |
| var credentials = new NetworkCredential(secretData.SMTP_UserName, secretData.SMTP_Password); | |
| smtpClient.Credentials = credentials; | |
| smtpClient.Send(mailMsg); | |
| }; | |
| Action zipTargetFolder = | |
| ()=>{ | |
| var fastZip = new ICSharpCode.SharpZipLib.Zip.FastZip(); | |
| fastZip.CreateEmptyDirectories = true; | |
| fastZip.CreateZip(targetZip, tempFolder, true, ""); | |
| }; | |
| Action filterByTitleAndCopyToTempFolder = | |
| ()=>{ | |
| var file = titlesData.GET(); | |
| var titles = file.split("\n"); | |
| var articles = tmDatabase.Cached_GuidanceItems.Values; | |
| var articlePaths = tmDatabase.GuidanceItems_FileMappings; | |
| var articlesMatches = new List<TeamMentor_Article>(); | |
| foreach(var article in articles) | |
| if(titles.contains(article.Metadata.Title)) | |
| { | |
| articlesMatches.add(article); | |
| var articlePath = articlePaths[article.Metadata.Id]; | |
| articlePath.file_Copy(tempFolder); | |
| } | |
| }; | |
| filterByTitleAndCopyToTempFolder(); | |
| zipTargetFolder(); | |
| sendEmail(); | |
| return "File with titles that matched {0}, copied to folder {1} should have been send to email {2}".format(titlesData); | |
| //using TeamMentor.CoreLib; | |
| //O2Ref:TeamMentor.CoreLib.dll | |
| //O2Ref:ICSharpCode.SharpZipLib.dll |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var titlesData = "https://gist.github.com/DinisCruz/8653339/raw/ce19914729bc232fdbfae2348803abeceb0b4ec8/gistfile1.txt"; | |
| var email_To = "dcruz@securityinnovation.com"; | |
| var email_Subject = "TM Articles analysis"; | |
| var email_Body = "Please see the attached zip for matches of titles for based on the list from {0}".format(titlesData); | |
| var tempFolder = "_articlesMatches".tempDir(); | |
| var targetZip = tempFolder + "_All.zip"; | |
| var tmDatabase = TM_Xml_Database.Current; | |
| var secretData = tmDatabase.UserData.SecretData; | |
| var articles = tmDatabase.Cached_GuidanceItems.Values; | |
| var articlePaths = tmDatabase.GuidanceItems_FileMappings; | |
| Action sendEmail = | |
| ()=>{ | |
| var mailMsg = new MailMessage(); | |
| mailMsg.To.Add(new MailAddress(email_To)); | |
| mailMsg.From = new MailAddress(email_To); | |
| mailMsg.Subject = email_Subject; | |
| mailMsg.Body = email_Body; | |
| mailMsg.Attachments.Add(new Attachment(targetZip)); | |
| var smtpClient = new SmtpClient(secretData.SMTP_Server, 587); | |
| var credentials = new NetworkCredential(secretData.SMTP_UserName, secretData.SMTP_Password); | |
| smtpClient.Credentials = credentials; | |
| smtpClient.Send(mailMsg); | |
| }; | |
| Action zipTargetFolder = | |
| ()=>{ | |
| var fastZip = new ICSharpCode.SharpZipLib.Zip.FastZip(); | |
| fastZip.CreateEmptyDirectories = true; | |
| fastZip.CreateZip(targetZip, tempFolder, true, ""); | |
| }; | |
| Action filterByTitleAndCopyToTempFolder = | |
| ()=>{ | |
| var file = titlesData.GET(); | |
| var titles = file.split("\n"); | |
| var articlesMatches = new List<TeamMentor_Article>(); | |
| foreach(var article in articles) | |
| if(titles.contains(article.Metadata.Title)) | |
| { | |
| articlesMatches.add(article); | |
| var articlePath = articlePaths[article.Metadata.Id]; | |
| articlePath.file_Copy(tempFolder); | |
| } | |
| }; | |
| try | |
| { | |
| filterByTitleAndCopyToTempFolder(); | |
| zipTargetFolder(); | |
| sendEmail(); | |
| } | |
| catch (Exception ex) | |
| { | |
| return "ERROR: " + ex.str(); | |
| } | |
| return "File with titles that matched {0}, copied to folder {1} should have been send to email {2}".format(titlesData, tempFolder, email_To); | |
| //using System.Net.Mail; | |
| //using System.Net; | |
| //using TeamMentor.CoreLib; | |
| //O2Ref:TeamMentor.CoreLib.dll | |
| //O2Ref:ICSharpCode.SharpZipLib.dll |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment