void imageProcessor_Error_Encountered(string NewMessage, long ParentLogID, string BibID_VID) { if (NewMessage.IndexOf("WARNING: ") == 0) { OnProcess(NewMessage, "Image Processing", BibID_VID, String.Empty, ParentLogID); } else { // Put this in the builder logs OnError(NewMessage, BibID_VID, String.Empty, ParentLogID); // Email a message string email_address = Settings.Email.System_Error_Email; if (String.IsNullOrWhiteSpace(email_address)) { email_address = Settings.Email.System_Email; } if (!String.IsNullOrEmpty(email_address)) { Email_Helper.SendEmail(email_address, "Image Derivation Error : " + BibID_VID, "An error was encountered while creating images for the web from the provided files in the SobekCM Builder service. Processing of this item will be incomplete.\n\n" + NewMessage + "\n\nPlease review this item and correct the issue, most likely by checking the TIFFs and reloading them.", false, Settings.System.System_Name); } // This will indicate a failure returnValue = false; } }
public bool Send(string toaddress, string cc, string bcc, string username, string password, string activateurl, string website_url, string web_design_url, string hosting_url, string help_url, string contact_address) { try { string subject = "User Registration [Web Creation Inc.]"; string templatepath = HttpContext.Current.Server.MapPath("~/Email-Template/UserRegistration.html"); string body = GetBody(templatepath); body = body.Replace("#username", username); body = body.Replace("#password", password); body = body.Replace("#activate_url", activateurl); body = body.Replace("#website_url", website_url); body = body.Replace("#web_design_url", web_design_url); body = body.Replace("#hosting_url", hosting_url); body = body.Replace("#help_url", help_url); body = body.Replace("#contact_address", contact_address); Email_Helper email = new Email_Helper(); System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); mail.To.Add(toaddress); mail.From = new System.Net.Mail.MailAddress(ConfigurationManager.AppSettings.Get("From")); mail.Subject = string.Format(subject); mail.Body = string.Format(body); mail.IsBodyHtml = true; email.SendMail(mail); return(true); } catch { return(false); } }
private static string Text_Send_Email(string Recepient_List, string CcList, string Comments, string User_Name, string SobekCM_Instance_Name, string URL, string URL_Title, string URL_Short_Type, int UserID) { try { StringBuilder messageBuilder = new StringBuilder(); if ((Comments.Length > 0) && (Comments != URL_Title)) { messageBuilder.AppendLine(User_Name + " wanted you to see this " + URL_Short_Type.ToLower() + " on " + SobekCM_Instance_Name + " and included the following comments.\n"); messageBuilder.AppendLine("\"" + Comments.Replace("<", "(").Replace(">", ")").Replace("\"", """) + "\"\n"); } else { messageBuilder.AppendLine(User_Name + " wanted you to see this " + URL_Short_Type.ToLower() + " on " + SobekCM_Instance_Name + ".\n"); } messageBuilder.AppendLine("\tURL:\t" + URL); messageBuilder.AppendLine("\tTitle:\t" + URL_Title); string[] email_recepients = Recepient_List.Split(";,".ToCharArray()); foreach (string thisEmailRecepient in email_recepients) { EmailInfo newEmail = new EmailInfo { Body = messageBuilder.ToString(), isContactUs = false, isHTML = false, Subject = URL_Short_Type + " from " + SobekCM_Instance_Name, RecipientsList = thisEmailRecepient, FromAddress = SobekCM_Instance_Name + " <" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">", UserID = UserID }; if (!String.IsNullOrEmpty(UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay)) { newEmail.FromAddress = UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay + " <" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">"; } if (CcList.Length > 0) { newEmail.RecipientsList = thisEmailRecepient.Trim() + "," + CcList; } string error; if (!Email_Helper.SendEmail(newEmail, out error)) { return(error); } } return(String.Empty); } catch (Exception ee) { return(ee.Message); } }
/// <summary> Checks the text files for a match that appears to be a social security number and /// emails a warning to the privacy email address on a possible match </summary> /// <param name="Resource"> Incoming digital resource object </param> /// <returns> TRUE if processing can continue, FALSE if a critical error occurred which should stop all processing </returns> public override bool DoWork(Incoming_Digital_Resource Resource) { string resourceFolder = Resource.Resource_Folder; string bibID = Resource.BibID; string vid = Resource.VID; // Look for SSN in text string ssn_text_file_name = String.Empty; string ssn_match = String.Empty; try { // Get the list of all text files here string[] text_files = Directory.GetFiles(resourceFolder, "*.txt"); if (text_files.Length > 0) { // Step through each text file foreach (string textFile in text_files) { // If no SSN possibly found, look for one if (ssn_match.Length == 0) { ssn_match = Text_Cleaner.Has_SSN(textFile); if (ssn_match.Length > 0) { ssn_text_file_name = (new FileInfo(textFile)).Name; } } } } } catch { } // Send a database email if there appears to have been a SSN if (ssn_match.Length > 0) { if (!String.IsNullOrEmpty(Settings.Email.Privacy_Email)) { Email_Helper.SendEmail(Settings.Email.Privacy_Email, "Possible Social Security Number Located", "A string which appeared to be a possible social security number was found while bulk loading or post-processing an item.\n\nThe SSN was found in package " + bibID + ":" + vid + " in file '" + ssn_text_file_name + "'.\n\nThe text which may be a SSN is '" + ssn_match + "'.\n\nPlease review this item and remove any private information which should not be on the web server.", false, Settings.System.System_Name); } OnProcess("Possible SSN Located (" + ssn_text_file_name + ")", "Privacy Checking", Resource.BibID + ":" + Resource.VID, Resource.METS_Type_String, Resource.BuilderLogId); } return(true); }
private bool complete_item_submission(SobekCM_Item Item_To_Complete, Custom_Tracer Tracer) { // Set an initial flag criticalErrorEncountered = false; string[] all_files = Directory.GetFiles(digitalResourceDirectory); SortedList <string, List <string> > image_files = new SortedList <string, List <string> >(); SortedList <string, List <string> > download_files = new SortedList <string, List <string> >(); foreach (string thisFile in all_files) { FileInfo thisFileInfo = new FileInfo(thisFile); if ((thisFileInfo.Name.IndexOf("agreement.txt") != 0) && (thisFileInfo.Name.IndexOf("TEMP000001_00001.mets") != 0) && (thisFileInfo.Name.IndexOf("doc.xml") != 0) && (thisFileInfo.Name.IndexOf("marc.xml") != 0)) { // Get information about this files name and extension string extension_upper = thisFileInfo.Extension.ToUpper(); string filename_sans_extension = thisFileInfo.Name.Replace(thisFileInfo.Extension, ""); string name_upper = thisFileInfo.Name.ToUpper(); // Is this a page image? if ((extension_upper == ".JPG") || (extension_upper == ".TIF") || (extension_upper == ".JP2") || (extension_upper == ".JPX")) { // Exclude .QC.jpg files if (name_upper.IndexOf(".QC.JPG") < 0) { // If this is a thumbnail, trim off the THM part on the file name if (name_upper.IndexOf("THM.JPG") > 0) { filename_sans_extension = filename_sans_extension.Substring(0, filename_sans_extension.Length - 3); } // Is this the first image file with this name? if (image_files.ContainsKey(filename_sans_extension.ToLower())) { image_files[filename_sans_extension.ToLower()].Add(thisFileInfo.Name); } else { List <string> newImageGrouping = new List <string> { thisFileInfo.Name }; image_files[filename_sans_extension.ToLower()] = newImageGrouping; } } } else { // If this does not match the exclusion regular expression, than add this if ((!Regex.Match(thisFileInfo.Name, UI_ApplicationCache_Gateway.Settings.Resources.Files_To_Exclude_From_Downloads, RegexOptions.IgnoreCase).Success) && (String.Compare(thisFileInfo.Name, Item_To_Complete.BibID + "_" + Item_To_Complete.VID + ".html", StringComparison.OrdinalIgnoreCase) != 0)) { // Also, exclude files that are .XML and marc.xml, or doc.xml, or have the bibid in the name if ((thisFileInfo.Name.IndexOf("marc.xml", StringComparison.OrdinalIgnoreCase) != 0) && (thisFileInfo.Name.IndexOf("marc.xml", StringComparison.OrdinalIgnoreCase) != 0) && (thisFileInfo.Name.IndexOf(".mets", StringComparison.OrdinalIgnoreCase) < 0) && (thisFileInfo.Name.IndexOf("citation_mets.xml", StringComparison.OrdinalIgnoreCase) < 0) && ((thisFileInfo.Name.IndexOf(".xml", StringComparison.OrdinalIgnoreCase) < 0) || (thisFileInfo.Name.IndexOf(Item_To_Complete.BibID, StringComparison.OrdinalIgnoreCase) < 0))) { // Is this the first image file with this name? if (download_files.ContainsKey(filename_sans_extension.ToLower())) { download_files[filename_sans_extension.ToLower()].Add(thisFileInfo.Name); } else { List <string> newDownloadGrouping = new List <string> { thisFileInfo.Name }; download_files[filename_sans_extension.ToLower()] = newDownloadGrouping; } } } } } } // This package is good to go, so build it, save, etc... try { // Save the METS file to the database and back to the directory Item_To_Complete.Source_Directory = digitalResourceDirectory; // Step through and add each file Item_To_Complete.Divisions.Download_Tree.Clear(); // Add the download files next foreach (string thisFileKey in download_files.Keys) { // Get the list of files List <string> theseFiles = download_files[thisFileKey]; // Add each file foreach (string thisFile in theseFiles) { // Create the new file object and compute a label FileInfo fileInfo = new FileInfo(thisFile); SobekCM_File_Info newFile = new SobekCM_File_Info(fileInfo.Name); string label = fileInfo.Name.Replace(fileInfo.Extension, ""); if (HttpContext.Current.Session["file_" + currentItem.Web.ItemID + "_" + thisFileKey] != null) { string possible_label = HttpContext.Current.Session["file_" + currentItem.Web.ItemID + "_" + thisFileKey].ToString(); if (possible_label.Length > 0) { label = possible_label; } } // Add this file Item_To_Complete.Divisions.Download_Tree.Add_File(newFile, label); } } // Determine the total size of the package before saving string[] all_files_final = Directory.GetFiles(digitalResourceDirectory); double size = all_files_final.Aggregate <string, double>(0, (Current, ThisFile) => Current + (((new FileInfo(ThisFile)).Length) / 1024)); Item_To_Complete.DiskSize_KB = size; // Create the options dictionary used when saving information to the database, or writing MarcXML Dictionary <string, object> options = new Dictionary <string, object>(); if (UI_ApplicationCache_Gateway.Settings.MarcGeneration != null) { options["MarcXML_File_ReaderWriter:MARC Cataloging Source Code"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Cataloging_Source_Code; options["MarcXML_File_ReaderWriter:MARC Location Code"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Location_Code; options["MarcXML_File_ReaderWriter:MARC Reproduction Agency"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Reproduction_Agency; options["MarcXML_File_ReaderWriter:MARC Reproduction Place"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Reproduction_Place; options["MarcXML_File_ReaderWriter:MARC XSLT File"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.XSLT_File; } options["MarcXML_File_ReaderWriter:System Name"] = UI_ApplicationCache_Gateway.Settings.System.System_Name; options["MarcXML_File_ReaderWriter:System Abbreviation"] = UI_ApplicationCache_Gateway.Settings.System.System_Abbreviation; // Save to the database try { SobekCM_Item_Database.Save_Digital_Resource(Item_To_Complete, options); SobekCM_Item_Database.Save_Behaviors(Item_To_Complete, Item_To_Complete.Behaviors.Text_Searchable, false, false); } catch (Exception ee) { StreamWriter writer = new StreamWriter(digitalResourceDirectory + "\\exception.txt", false); writer.WriteLine("ERROR CAUGHT WHILE SAVING DIGITAL RESOURCE"); writer.WriteLine(DateTime.Now.ToString()); writer.WriteLine(); writer.WriteLine(ee.Message); writer.WriteLine(ee.StackTrace); writer.Flush(); writer.Close(); throw; } // Assign the file root and assoc file path Item_To_Complete.Web.File_Root = Item_To_Complete.BibID.Substring(0, 2) + "\\" + Item_To_Complete.BibID.Substring(2, 2) + "\\" + Item_To_Complete.BibID.Substring(4, 2) + "\\" + Item_To_Complete.BibID.Substring(6, 2) + "\\" + Item_To_Complete.BibID.Substring(8, 2); Item_To_Complete.Web.AssocFilePath = Item_To_Complete.Web.File_Root + "\\" + Item_To_Complete.VID + "\\"; //// Create the static html pages //string base_url = RequestSpecificValues.Current_Mode.Base_URL; //try //{ // Static_Pages_Builder staticBuilder = new Static_Pages_Builder(UI_ApplicationCache_Gateway.Settings.Servers.System_Base_URL, UI_ApplicationCache_Gateway.Settings.Servers.Base_Data_Directory, RequestSpecificValues.HTML_Skin.Skin_Code); // if (!Directory.Exists(digitalResourceDirectory + "\\" + UI_ApplicationCache_Gateway.Settings.Resources.Backup_Files_Folder_Name)) // Directory.CreateDirectory(digitalResourceDirectory + "\\" + UI_ApplicationCache_Gateway.Settings.Resources.Backup_Files_Folder_Name); // string filename = digitalResourceDirectory + "\\" + UI_ApplicationCache_Gateway.Settings.Resources.Backup_Files_Folder_Name + "\\" + Item_To_Complete.BibID + "_" + Item_To_Complete.VID + ".html"; // staticBuilder.Create_Item_Citation_HTML(Item_To_Complete, filename, String.Empty); // // Copy the static HTML file to the web server // try // { // if (!Directory.Exists(UI_ApplicationCache_Gateway.Settings.Servers.Static_Pages_Location + currentItem.BibID.Substring(0, 2) + "\\" + currentItem.BibID.Substring(2, 2) + "\\" + currentItem.BibID.Substring(4, 2) + "\\" + currentItem.BibID.Substring(6, 2) + "\\" + currentItem.BibID.Substring(8))) // Directory.CreateDirectory(UI_ApplicationCache_Gateway.Settings.Servers.Static_Pages_Location + currentItem.BibID.Substring(0, 2) + "\\" + currentItem.BibID.Substring(2, 2) + "\\" + currentItem.BibID.Substring(4, 2) + "\\" + currentItem.BibID.Substring(6, 2) + "\\" + currentItem.BibID.Substring(8)); // if (File.Exists(filename)) // File.Copy(filename, UI_ApplicationCache_Gateway.Settings.Servers.Static_Pages_Location + currentItem.BibID.Substring(0, 2) + "\\" + currentItem.BibID.Substring(2, 2) + "\\" + currentItem.BibID.Substring(4, 2) + "\\" + currentItem.BibID.Substring(6, 2) + "\\" + currentItem.BibID.Substring(8) + "\\" + currentItem.BibID + "_" + currentItem.VID + ".html", true); // } // catch (Exception) // { // // This is not critical // } //} //catch (Exception) //{ //} //RequestSpecificValues.Current_Mode.Base_URL = base_url; // Save the rest of the metadata Item_To_Complete.Save_SobekCM_METS(); // Finally, set the currentItem for more processing if there were any files if (((image_files.Count > 0) || (download_files.Count > 0)) && (Item_To_Complete.Web.ItemID > 0)) { SobekCM_Item_Database.Update_Additional_Work_Needed_Flag(Item_To_Complete.Web.ItemID, true); } } catch (Exception ee) { // Set an initial flag criticalErrorEncountered = true; string error_body = "<strong>ERROR ENCOUNTERED DURING ONLINE FILE MANAGEMENT</strong><br /><br /><blockquote>Title: " + Item_To_Complete.Bib_Info.Main_Title.Title + "<br />Permanent Link: <a href=\"" + RequestSpecificValues.Current_Mode.Base_URL + "/" + Item_To_Complete.BibID + "/" + Item_To_Complete.VID + "\">" + RequestSpecificValues.Current_Mode.Base_URL + "/" + Item_To_Complete.BibID + "/" + Item_To_Complete.VID + "</a><br />User: "******"<br /><br /></blockquote>" + ee.ToString().Replace("\n", "<br />"); string error_subject = "Error during file management for '" + Item_To_Complete.Bib_Info.Main_Title.Title + "'"; string email_to = UI_ApplicationCache_Gateway.Settings.Email.System_Error_Email; if (email_to.Length == 0) { email_to = UI_ApplicationCache_Gateway.Settings.Email.System_Email; } Email_Helper.SendEmail(email_to, error_subject, error_body, true, String.Empty); } return(criticalErrorEncountered); }
/// <summary> Sends one email to a user from the system including /// individual usage on items which are linked to the user </summary> /// <param name="UserID"> Primary key for whom to send the email </param> /// <param name="User_Name"> Name of the user to include in the email </param> /// <param name="User_Email"> Email address to use for this email </param> /// <param name="Year"> Year of statistics to highlight in the email </param> /// <param name="Month"> Month of statistics to highlight in the email </param> /// <param name="Number_Of_Items_To_Include"> Number of items to include in this email, in case the user has many, many items linked </param> /// <param name="System_URL"> Base URL to use for links to these items </param> /// <param name="System_Name"> Name of the SobekCM instance </param> /// <param name="FromAddress"> Address from which the email should be sent </param> /// <returns> TRUE if succesful, otherwise FALSE </returns> public static bool Send_Individual_Usage_Email(int UserID, string User_Name, string User_Email, int Year, int Month, int Number_Of_Items_To_Include, string System_URL, string System_Name, string FromAddress) { // If no email body was loaded, use the default if (String.IsNullOrEmpty(emailBody)) { emailBody = DEFAULT_EMAIL_BODY; } try { // Get the item usage stats for this user on this month DataTable usageStats = Engine_Database.Get_User_Linked_Items_Stats(UserID, Month, Year, null); // Only continue if stats were returned if (usageStats != null) { // Use the data view DataView sortedView = new DataView(usageStats) { Sort = "Month_Hits DESC" }; // Keep track for a total row at the bottom int total_total_hits = 0; int total_month_hits = 0; // Build the string here StringBuilder itemStatsBuilder = new StringBuilder(); // Display the stats for each item int item_count = 0; foreach (DataRowView thisRow in sortedView) { if (item_count < Number_Of_Items_To_Include) { string bibid = thisRow["BibID"].ToString(); string vid = thisRow["VID"].ToString(); itemStatsBuilder.AppendLine("<strong><a href=\"" + System_URL + bibid + "/" + vid + "\">" + thisRow["Title"] + "</a></strong><br />"); itemStatsBuilder.AppendLine("<ul>"); itemStatsBuilder.AppendLine(" <li>Permanent Link: <a href=\"" + System_URL + bibid + "/" + vid + "\">" + System_URL + bibid + "/" + vid + "</a></li>"); itemStatsBuilder.AppendLine(" <li>Views"); itemStatsBuilder.AppendLine(" <ul>"); itemStatsBuilder.AppendLine(" <li>" + Month_From_Int(Month) + " " + Year + ": " + thisRow["Month_Hits"] + " views"); itemStatsBuilder.AppendLine(" <li>Total to date ( since " + Convert.ToDateTime(thisRow["CreateDate"]).ToShortDateString() + " ): " + thisRow["Total_Hits"] + " views"); itemStatsBuilder.AppendLine(" </ul>"); itemStatsBuilder.AppendLine(" </li>"); itemStatsBuilder.AppendLine("</ul>"); } // Also, add the values total_total_hits += Convert.ToInt32(thisRow["Total_Hits"]); total_month_hits += Convert.ToInt32(thisRow["Month_Hits"]); item_count++; } // Put some notes if there were more than 10 items if (item_count > Number_Of_Items_To_Include) { itemStatsBuilder.Insert(0, TOO_MANY_ITEMS_MESSAGE.Replace("<%COUNT%>", item_count.ToString())); } string email_body_user = emailBody.Replace("<%TOTAL%>", Number_To_String(total_total_hits)).Replace("<%MONTHLY%>", Number_To_String(total_month_hits)).Replace("<%ITEMS%>", itemStatsBuilder.ToString()).Replace("<%DATE%>", Month_From_Int(Month) + " " + Year).Replace("<%NAME%>", User_Name).Replace("<%SYSURL%>", System_URL).Replace("<%SYSNAME%>", System_Name).Replace("<%YEAR%>", Year.ToString()).Replace("<%MONTH%>", Month.ToString().PadLeft(2, '0')) + "<br /><br /><p>( " + Month_From_Int(Month) + " " + Year + " )</p>"; // Only send the email if there was actually usage this month though if (total_month_hits > 0) { // Send this email EmailInfo newEmail = new EmailInfo { FromAddress = FromAddress, RecipientsList = User_Email, isContactUs = false, isHTML = true, Subject = EMAIL_SUBJECT.Replace("<%DATE%>", Month_From_Int(Month) + " " + Year), Body = email_body_user }; string error; return(Email_Helper.SendEmail(newEmail, out error)); } } // No actual error here, just turns out no items were linked to this user return(true); } catch (Exception) { return(false); } }
private static bool HTML_Send_Email(string Recepient_List, string CcList, string Comments, string User_Name, string SobekCM_Instance_Name, BriefItemInfo Item, string URL, int UserID) { try { StringBuilder messageBuilder = new StringBuilder(); messageBuilder.AppendLine("<span style=\"font-family:Arial, Helvetica, sans-serif;\">"); if (Comments.Length > 0) { messageBuilder.AppendLine(User_Name + " wanted you to see this item on " + SobekCM_Instance_Name + " and included the following comments.<br /><br />\n"); messageBuilder.AppendLine(Comments.Replace("<", "(").Replace(">", ")").Replace("\"", """) + ".<br /><br />\n"); } else { messageBuilder.AppendLine(User_Name + " wanted you to see this item on " + SobekCM_Instance_Name + ".<br /><br />\n"); } messageBuilder.AppendLine("<table cellspacing=\"0px\" cellpadding=\"0px\">\n"); messageBuilder.AppendLine("<tr><td colspan=\"2\" style=\"background: black; color: white; font-family:Arial, Helvetica, sans-serif;\"><b>ITEM INFORMATION</b></td></tr>\n"); // Include the thumbnail, if one exists if (String.IsNullOrEmpty(Item.Behaviors.Main_Thumbnail)) { messageBuilder.AppendLine("<tr>"); } else { messageBuilder.AppendLine("<tr valign=\"top\"><td><a href=\"" + URL + "\"><img src=\"" + Item.Web.Source_URL.Replace("\\", "/") + "/" + Item.Behaviors.Main_Thumbnail + "\" alt=\"BLOCKED THUMBNAIL IMAGE\" border=\"1px\" /></a></td>\n"); } messageBuilder.AppendLine("<td>"); messageBuilder.AppendLine("<table style=\"font-family:Arial, Helvetica, sans-serif; font-size:smaller;\">"); // Step through the citation configuration here CitationSet citationSet = UI_ApplicationCache_Gateway.Configuration.UI.CitationViewer.Get_CitationSet("EMAIL"); foreach (CitationFieldSet fieldsSet in citationSet.FieldSets) { // Check to see if any of the values indicated in this field set exist bool foundExistingData = false; foreach (CitationElement thisField in fieldsSet.Elements) { // Look for a match in the item description BriefItem_DescriptiveTerm briefTerm = Item.Get_Description(thisField.MetadataTerm); // If no match, just continue if ((briefTerm != null) && (briefTerm.Values.Count > 0)) { foundExistingData = true; break; } } // If no data was found to put in this field set, skip it if (!foundExistingData) { continue; } // Step through all the fields in this field set and write them foreach (CitationElement thisField in fieldsSet.Elements) { // Look for a match in the item description BriefItem_DescriptiveTerm briefTerm = Item.Get_Description(thisField.MetadataTerm); // If no match, just continue if ((briefTerm == null) || (briefTerm.Values.Count == 0)) { continue; } // If they can all be listed one after the other do so now if (!thisField.IndividualFields) { List <string> valueArray = new List <string>(); foreach (BriefItem_DescTermValue thisValue in briefTerm.Values) { if (String.IsNullOrEmpty(thisValue.Authority)) { if (String.IsNullOrEmpty(thisValue.Language)) { valueArray.Add(HttpUtility.HtmlEncode(thisValue.Value)); } else { valueArray.Add(HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Language + " )"); } } else { if (String.IsNullOrEmpty(thisValue.Language)) { valueArray.Add(HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Authority + " )"); } else { valueArray.Add(HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Authority + ", " + thisValue.Language + " )"); } } } // Now, add this to the citation HTML Add_Citation_HTML_Rows(thisField.DisplayTerm, valueArray, messageBuilder); } else { // In this case, each individual value gets its own citation html row foreach (BriefItem_DescTermValue thisValue in briefTerm.Values) { // Determine the label string label = thisField.DisplayTerm; if (thisField.OverrideDisplayTerm == CitationElement_OverrideDispayTerm_Enum.subterm) { if (!String.IsNullOrEmpty(thisValue.SubTerm)) { label = thisValue.SubTerm; } } if (String.IsNullOrEmpty(thisValue.Authority)) { if (String.IsNullOrEmpty(thisValue.Language)) { messageBuilder.Append(Single_Citation_HTML_Row(label, HttpUtility.HtmlEncode(thisValue.Value))); } else { messageBuilder.Append(Single_Citation_HTML_Row(label, HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Language + " )")); } } else { if (String.IsNullOrEmpty(thisValue.Language)) { messageBuilder.Append(Single_Citation_HTML_Row(label, HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Authority + " )")); } else { messageBuilder.Append(Single_Citation_HTML_Row(label, HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Authority + ", " + thisValue.Language + " )")); } } } } } } messageBuilder.AppendLine("</table>"); messageBuilder.AppendLine("</td></tr></table>"); messageBuilder.AppendLine("</span>\n"); string[] email_recepients = Recepient_List.Split(";,".ToCharArray()); string subject = Item.Title.Replace(""", "\""); if (Item.Title.Length > 40) { subject = Item.Title.Substring(0, 35).Replace(""", "\"") + "..."; } int error_count = 0; foreach (string thisReceipient in email_recepients) { EmailInfo newEmail = new EmailInfo { Body = messageBuilder.ToString(), isContactUs = false, isHTML = true, Subject = subject, RecipientsList = thisReceipient, FromAddress = SobekCM_Instance_Name + " <" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">", UserID = UserID }; if (!String.IsNullOrEmpty(UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay)) { newEmail.FromAddress = UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay + " <" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">"; } if (CcList.Length > 0) { newEmail.RecipientsList = thisReceipient.Trim() + "," + CcList; } string error; if (!Email_Helper.SendEmail(newEmail, out error)) { error_count++; } } return(error_count <= 0); } catch { return(false); } }
private static bool Text_Send_Email(string Recepient_List, string CcList, string Comments, string User_Name, string SobekCM_Instance_Name, BriefItemInfo Item, string URL, int UserID) { try { StringBuilder messageBuilder = new StringBuilder(); if (Comments.Length > 0) { messageBuilder.Append(User_Name + " wanted you to see this item on " + SobekCM_Instance_Name + " and included the following comments:\n\n"); messageBuilder.Append("\"" + Comments + "\"\n\n"); } else { messageBuilder.Append(User_Name + " wanted you to see this item on " + SobekCM_Instance_Name + ".\n\n"); } messageBuilder.Append("ITEM INFORMATION\n"); messageBuilder.Append("------------------------------------------------------\n"); // Step through the citation configuration here CitationSet citationSet = UI_ApplicationCache_Gateway.Configuration.UI.CitationViewer.Get_CitationSet("EMAIL"); foreach (CitationFieldSet fieldsSet in citationSet.FieldSets) { // Check to see if any of the values indicated in this field set exist bool foundExistingData = false; foreach (CitationElement thisField in fieldsSet.Elements) { // Look for a match in the item description BriefItem_DescriptiveTerm briefTerm = Item.Get_Description(thisField.MetadataTerm); // If no match, just continue if ((briefTerm != null) && (briefTerm.Values.Count > 0)) { foundExistingData = true; break; } } // If no data was found to put in this field set, skip it if (!foundExistingData) { continue; } // Step through all the fields in this field set and write them foreach (CitationElement thisField in fieldsSet.Elements) { // Look for a match in the item description BriefItem_DescriptiveTerm briefTerm = Item.Get_Description(thisField.MetadataTerm); // If no match, just continue if ((briefTerm == null) || (briefTerm.Values.Count == 0)) { continue; } // If they can all be listed one after the other do so now if (!thisField.IndividualFields) { List <string> valueArray = new List <string>(); foreach (BriefItem_DescTermValue thisValue in briefTerm.Values) { if (String.IsNullOrEmpty(thisValue.Authority)) { if (String.IsNullOrEmpty(thisValue.Language)) { valueArray.Add(HttpUtility.HtmlEncode(thisValue.Value)); } else { valueArray.Add(HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Language + " )"); } } else { if (String.IsNullOrEmpty(thisValue.Language)) { valueArray.Add(HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Authority + " )"); } else { valueArray.Add(HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Authority + ", " + thisValue.Language + " )"); } } } // Now, add this to the citation HTML Add_Citation_Text_Rows(thisField.DisplayTerm, valueArray, messageBuilder); } else { // In this case, each individual value gets its own citation html row foreach (BriefItem_DescTermValue thisValue in briefTerm.Values) { // Determine the label string label = thisField.DisplayTerm; if (thisField.OverrideDisplayTerm == CitationElement_OverrideDispayTerm_Enum.subterm) { if (!String.IsNullOrEmpty(thisValue.SubTerm)) { label = thisValue.SubTerm; } } if (String.IsNullOrEmpty(thisValue.Authority)) { if (String.IsNullOrEmpty(thisValue.Language)) { messageBuilder.Append(Single_Citation_Text_Row(label, HttpUtility.HtmlEncode(thisValue.Value))); } else { messageBuilder.Append(Single_Citation_Text_Row(label, HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Language + " )")); } } else { if (String.IsNullOrEmpty(thisValue.Language)) { messageBuilder.Append(Single_Citation_Text_Row(label, HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Authority + " )")); } else { messageBuilder.Append(Single_Citation_Text_Row(label, HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Authority + ", " + thisValue.Language + " )")); } } } } } } string[] email_recepients = Recepient_List.Split(";,".ToCharArray()); string subject = Item.Title.Replace(""", "\""); if (Item.Title.Length > 40) { subject = Item.Title.Substring(0, 35).Replace(""", "\"") + "..."; } int error_count = 0; foreach (string thisReceipient in email_recepients) { EmailInfo newEmail = new EmailInfo { Body = messageBuilder.ToString(), isContactUs = false, isHTML = false, Subject = subject, RecipientsList = thisReceipient, FromAddress = SobekCM_Instance_Name + " <" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">", UserID = UserID }; if (!String.IsNullOrEmpty(UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay)) { newEmail.FromAddress = UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay + " <" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">"; } if (CcList.Length > 0) { newEmail.RecipientsList = thisReceipient.Trim() + "," + CcList; } string error; if (!Email_Helper.SendEmail(newEmail, out error)) { error_count++; } } return(error_count <= 0); } catch { return(false); } }
/// <summary> Constructor for a new instance of the Contact_HtmlSubwriter class </summary> /// <param name="Last_Mode"> URL for the last mode this user was in before selecting contact us</param> /// <param name="UserHistoryRequestInfo"> Some history and user information to include in the final email </param> /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param> public Contact_HtmlSubwriter(string Last_Mode, string UserHistoryRequestInfo, RequestCache RequestSpecificValues) : base(RequestSpecificValues) { // Save the parameters lastMode = Last_Mode; // Set the error message to an empty string to start with errorMsg = String.Empty; // We need the aggregation here Item_Aggregation aggregation; if (!Get_Collection(RequestSpecificValues.Current_Mode, RequestSpecificValues.Tracer, out aggregation)) { aggregation = RequestSpecificValues.Top_Collection; } // Determine the configuration to use for this contact us form configuration = UI_ApplicationCache_Gateway.Configuration.ContactForm; if ((aggregation != null) && (aggregation.ContactForm != null)) { configuration = aggregation.ContactForm; } postBackValues = new Dictionary <string, string>(); foreach (string thisKey in HttpContext.Current.Request.Form.AllKeys) { if (thisKey != "item_action") { string value = HttpContext.Current.Request.Form[thisKey]; if (!String.IsNullOrEmpty(value)) { postBackValues[thisKey] = value; } } } // If this is a post back, send email if (HttpContext.Current.Request.Form["item_action"] == null) { return; } string action = HttpContext.Current.Request.Form["item_action"]; if (action == "email") { // Some values to collect information string subject = "Contact [" + RequestSpecificValues.Current_Mode.Instance_Abbreviation + " Submission]"; string message_from = RequestSpecificValues.Current_Mode.Instance_Abbreviation + "<" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">"; if (!String.IsNullOrEmpty(UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay)) { message_from = UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay + "<" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">"; } int text_area_count = configuration.TextAreaElementCount; StringBuilder emailBuilder = new StringBuilder(); // Make sure all the required fields are completed and build the emails StringBuilder errorBuilder = new StringBuilder(); int control_count = 1; foreach (ContactForm_Configuration_Element thisElement in configuration.FormElements) { if ((thisElement.Element_Type != ContactForm_Configuration_Element_Type_Enum.HiddenValue) && (thisElement.Element_Type != ContactForm_Configuration_Element_Type_Enum.ExplanationText)) { // Determine the name of this control string control_name = String.Empty; if (!String.IsNullOrEmpty(thisElement.Name)) { control_name = thisElement.Name.Replace(" ", "_"); } if (thisElement.Element_Type == ContactForm_Configuration_Element_Type_Enum.Subject) { control_name = "subject"; } if (thisElement.Element_Type == ContactForm_Configuration_Element_Type_Enum.Email) { control_name = "email"; } if (String.IsNullOrEmpty(control_name)) { control_name = "Control" + control_count; } if (!postBackValues.ContainsKey(control_name)) { if (thisElement.Required) { errorBuilder.Append(thisElement.QueryText.Get_Value(RequestSpecificValues.Current_Mode.Language).Replace(":", "") + "<br />"); } } else { if (thisElement.Element_Type == ContactForm_Configuration_Element_Type_Enum.Subject) { subject = postBackValues[control_name] + " [" + RequestSpecificValues.Current_Mode.Instance_Abbreviation + " Submission]"; } else if (thisElement.Element_Type == ContactForm_Configuration_Element_Type_Enum.Email) { string entered_message_from = postBackValues[control_name]; if (!IsValidEmail(entered_message_from)) { errorBuilder.Append(thisElement.QueryText.Get_Value(RequestSpecificValues.Current_Mode.Language).Replace(":", "") + " (INVALID) <br />"); } message_from = RequestSpecificValues.Current_Mode.Instance_Abbreviation + "<" + entered_message_from + ">"; if (!String.IsNullOrEmpty(UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay)) { message_from = UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay + "<" + entered_message_from + ">"; } emailBuilder.Append("Email:\t\t" + entered_message_from + "\n"); } else if (thisElement.Element_Type == ContactForm_Configuration_Element_Type_Enum.TextArea) { if (text_area_count == 1) { emailBuilder.Insert(0, postBackValues[control_name] + "\n\n"); } else { if (emailBuilder.Length > 0) { emailBuilder.Append("\n"); } emailBuilder.Append(thisElement.QueryText.Get_Value(RequestSpecificValues.Current_Mode.Language) + "\n"); emailBuilder.Append(postBackValues[control_name] + "\n\n"); } } else { emailBuilder.Append(control_name.Replace("_", " ") + ":\t\t" + postBackValues[control_name] + "\n"); } } control_count++; } } if (errorBuilder.Length > 0) { errorMsg = errorBuilder.ToString(); return; } // Create the final body string email_body = emailBuilder + "\n\n" + UserHistoryRequestInfo; // Determine the sendee string sendTo = UI_ApplicationCache_Gateway.Settings.Email.System_Email; if ((aggregation != null) && (!String.IsNullOrEmpty(aggregation.Contact_Email))) { sendTo = aggregation.Contact_Email.Replace(";", ","); } int userid = -1; if (RequestSpecificValues.Current_User != null) { userid = RequestSpecificValues.Current_User.UserID; } EmailInfo newEmail = new EmailInfo { Body = email_body, isContactUs = true, isHTML = false, RecipientsList = sendTo, Subject = subject, UserID = userid, FromAddress = message_from }; string error_msg; bool email_error = !Email_Helper.SendEmail(newEmail, out error_msg); // Send back to the home for this collection, sub, or group if (email_error) { HttpContext.Current.Response.Redirect(UI_ApplicationCache_Gateway.Settings.Servers.System_Error_URL, false); HttpContext.Current.ApplicationInstance.CompleteRequest(); } else { // Send back to the home for this collection, sub, or group RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Contact_Sent; UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode); } } }
/// <summary> Add a new aggregation to the system </summary> /// <param name="NewAggregation"> Information for the new aggregation </param> /// <returns> Message indicating success or any errors encountered </returns> public static RestResponseMessage add_new_aggregation(New_Aggregation_Arguments NewAggregation) { // Convert to the integer id for the parent and begin to do checking List <string> errors = new List <string>(); int parentid = -1; if (NewAggregation.ParentCode.Length > 0) { Item_Aggregation_Related_Aggregations parentAggr = Engine_ApplicationCache_Gateway.Codes[NewAggregation.ParentCode]; if (parentAggr != null) { parentid = parentAggr.ID; } else { errors.Add("Parent code is not valid"); } } else { errors.Add("You must select a PARENT for this new aggregation"); } // Validate the code if (NewAggregation.Code.Length > 20) { errors.Add("New aggregation code must be twenty characters long or less"); } else if (NewAggregation.Code.Length == 0) { errors.Add("You must enter a CODE for this item aggregation"); } else if (Engine_ApplicationCache_Gateway.Codes[NewAggregation.Code.ToUpper()] != null) { errors.Add("New code must be unique... <i>" + NewAggregation.Code + "</i> already exists"); } else if (Engine_ApplicationCache_Gateway.Settings.Static.Reserved_Keywords.Contains(NewAggregation.Code.ToLower())) { errors.Add("That code is a system-reserved keyword. Try a different code."); } else { bool alphaNumericTest = NewAggregation.Code.All(C => Char.IsLetterOrDigit(C) || C == '_' || C == '-'); if (!alphaNumericTest) { errors.Add("New aggregation code must be only letters and numbers"); NewAggregation.Code = NewAggregation.Code.Replace("\"", ""); } } // Was there a type and name if (NewAggregation.Type.Length == 0) { errors.Add("You must select a TYPE for this new aggregation"); } if (NewAggregation.Description.Length == 0) { errors.Add("You must enter a DESCRIPTION for this new aggregation"); } if (NewAggregation.Name.Length == 0) { errors.Add("You must enter a NAME for this new aggregation"); } else { if (NewAggregation.ShortName.Length == 0) { NewAggregation.ShortName = NewAggregation.Name; } } // Check for the thematic heading int thematicHeadingId = -1; if (!String.IsNullOrEmpty(NewAggregation.Thematic_Heading)) { // Look for the matching thematic heading foreach (Thematic_Heading thisHeading in Engine_ApplicationCache_Gateway.Thematic_Headings) { if (String.Compare(thisHeading.Text, NewAggregation.Thematic_Heading, StringComparison.InvariantCultureIgnoreCase) == 0) { thematicHeadingId = thisHeading.ID; break; } } // If there was no match, the thematic heading was invalid, unless it was new if (thematicHeadingId < 0) { if ((!NewAggregation.NewThematicHeading.HasValue) || (!NewAggregation.NewThematicHeading.Value)) { errors.Add("Invalid thematic heading indicated"); } else if (errors.Count == 0) { // Add the thematic heading first if ((thematicHeadingId < 0) && (NewAggregation.NewThematicHeading.HasValue) && (NewAggregation.NewThematicHeading.Value)) { thematicHeadingId = Engine_Database.Edit_Thematic_Heading(-1, 10, NewAggregation.Thematic_Heading, null); } } } } if (errors.Count > 0) { // Create the error message StringBuilder actionMessage = new StringBuilder("ERROR: Invalid entry for new item aggregation.<br />"); foreach (string error in errors) { actionMessage.Append("<br />" + error); } return(new RestResponseMessage(ErrorRestTypeEnum.InputError, actionMessage.ToString())); } string language = Web_Language_Enum_Converter.Enum_To_Code(Engine_ApplicationCache_Gateway.Settings.System.Default_UI_Language); // Try to save the new item aggregation if (!Engine_Database.Save_Item_Aggregation(NewAggregation.Code, NewAggregation.Name, NewAggregation.ShortName, NewAggregation.Description, thematicHeadingId, NewAggregation.Type, NewAggregation.Active, NewAggregation.Hidden, NewAggregation.External_Link, parentid, NewAggregation.User, language, null)) { return(new RestResponseMessage(ErrorRestTypeEnum.Exception, "ERROR saving the new item aggregation to the database")); } // Ensure a folder exists for this, otherwise create one try { string folder = Engine_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location + "aggregations\\" + NewAggregation.Code.ToLower(); if (!Directory.Exists(folder)) { // Create this directory and all the subdirectories Directory.CreateDirectory(folder); Directory.CreateDirectory(folder + "/html"); Directory.CreateDirectory(folder + "/images"); Directory.CreateDirectory(folder + "/html/home"); Directory.CreateDirectory(folder + "/html/custom/home"); Directory.CreateDirectory(folder + "/images/buttons"); Directory.CreateDirectory(folder + "/images/banners"); Directory.CreateDirectory(folder + "/uploads"); // Get the parent name string link_to_parent = String.Empty; Item_Aggregation_Related_Aggregations parentAggr = Engine_ApplicationCache_Gateway.Codes.Aggregation_By_ID(parentid); if (parentAggr != null) { if (String.Compare(parentAggr.Code, "all", StringComparison.InvariantCultureIgnoreCase) == 0) { link_to_parent = "<p>← Back to <a href=\"<%BASEURL%>\" alt=\"Return to parent collection\">" + parentAggr.Name + "</a></p>" + Environment.NewLine; } else { link_to_parent = "<p>← Back to <a href=\"<%BASEURL%>" + parentAggr.Code + "\" alt=\"Return to parent collection\">" + parentAggr.Name + "</a></p>" + Environment.NewLine; } } // Create a default home text file StreamWriter writer = new StreamWriter(folder + "/html/home/text.html"); writer.WriteLine(link_to_parent + "<h3>About " + NewAggregation.Name + "</h3>" + Environment.NewLine + "<p>" + NewAggregation.Description + "</p>" + Environment.NewLine + "<p>To edit this, log on as the aggregation admin and hover over this text to edit it.</p>" + Environment.NewLine); writer.Flush(); writer.Close(); // Was a button indicated, and does it exist? if ((!String.IsNullOrEmpty(NewAggregation.ButtonFile)) && (File.Exists(NewAggregation.ButtonFile))) { File.Copy(NewAggregation.ButtonFile, folder + "/images/buttons/coll.gif"); } else { // Copy the default banner and buttons from images if (File.Exists(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design/aggregations/default_button.png")) { File.Copy(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design/aggregations/default_button.png", folder + "/images/buttons/coll.png"); } if (File.Exists(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design/aggregations/default_button.gif")) { File.Copy(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design/aggregations/default_button.gif", folder + "/images/buttons/coll.gif"); } } // Was a banner indicated, and does it exist? string banner_file = String.Empty; if ((!String.IsNullOrEmpty(NewAggregation.BannerFile)) && (File.Exists(NewAggregation.BannerFile))) { banner_file = "images/banners/" + Path.GetFileName(NewAggregation.BannerFile); File.Copy(NewAggregation.BannerFile, folder + "//" + banner_file, true); } else { // Try to create a new custom banner bool custom_banner_created = false; // Create the banner with the name of the collection if (Directory.Exists(Engine_ApplicationCache_Gateway.Settings.Servers.Application_Server_Network + "\\default\\banner_images")) { try { string[] banners = Directory.GetFiles(Engine_ApplicationCache_Gateway.Settings.Servers.Application_Server_Network + "\\default\\banner_images", "*.jpg"); if (banners.Length > 0) { Random randomizer = new Random(); string banner_to_use = banners[randomizer.Next(0, banners.Length - 1)]; Bitmap bitmap = (Bitmap)(Image.FromFile(banner_to_use)); RectangleF rectf = new RectangleF(30, bitmap.Height - 55, bitmap.Width - 40, 40); Graphics g = Graphics.FromImage(bitmap); g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.DrawString(NewAggregation.Name, new Font("Tahoma", 25, FontStyle.Bold), Brushes.Black, rectf); g.Flush(); string new_file = folder + "/images/banners/coll.jpg"; if (!File.Exists(new_file)) { bitmap.Save(new_file, ImageFormat.Jpeg); custom_banner_created = true; banner_file = "images/banners/coll.jpg"; } } } catch (Exception) { // Suppress this Error... } } if ((!custom_banner_created) && (!File.Exists(folder + "/images/banners/coll.jpg"))) { if (File.Exists(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design/aggregations/default_banner.jpg")) { banner_file = "images/banners/coll.jpg"; File.Copy(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design/aggregations/default_banner.jpg", folder + "/images/banners/coll.jpg", true); } } } // Now, try to create the item aggregation and write the configuration file Custom_Tracer tracer = new Custom_Tracer(); Complete_Item_Aggregation itemAggregation = SobekEngineClient.Aggregations.Get_Complete_Aggregation(NewAggregation.Code, true, tracer); if (banner_file.Length > 0) { itemAggregation.Banner_Dictionary.Clear(); itemAggregation.Add_Banner_Image(banner_file, Engine_ApplicationCache_Gateway.Settings.System.Default_UI_Language); } itemAggregation.Write_Configuration_File(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location + itemAggregation.ObjDirectory); // If an email shoudl be sent, do that now if (String.Compare(Engine_ApplicationCache_Gateway.Settings.Email.Send_On_Added_Aggregation, "always", StringComparison.OrdinalIgnoreCase) == 0) { string user = String.Empty; if (!String.IsNullOrEmpty(NewAggregation.User)) { user = NewAggregation.User; } string body = "New aggregation added to this system:\n\n\tCode:\t" + itemAggregation.Code + "\n\tType:\t" + itemAggregation.Type + "\n\tName:\t" + itemAggregation.Name + "\n\tShort:\t" + itemAggregation.ShortName + "\n\tUser:\t" + user + "\n\n" + Engine_ApplicationCache_Gateway.Settings.Servers.Application_Server_URL + "/" + itemAggregation.Code; Email_Helper.SendEmail(Engine_ApplicationCache_Gateway.Settings.Email.System_Email, "New " + itemAggregation.Type + " - " + itemAggregation.ShortName, body, false, Engine_ApplicationCache_Gateway.Settings.System.System_Name); } } } catch { // Reload the list of all codes, to include this new one and the new hierarchy lock (Engine_ApplicationCache_Gateway.Codes) { Engine_Database.Populate_Code_Manager(Engine_ApplicationCache_Gateway.Codes, null); } return(new RestResponseMessage(ErrorRestTypeEnum.Exception, "ERROR completing the new aggregation add")); } // Reload the list of all codes, to include this new one and the new hierarchy lock (Engine_ApplicationCache_Gateway.Codes) { Engine_Database.Populate_Code_Manager(Engine_ApplicationCache_Gateway.Codes, null); } // Clear all aggregation information (and thematic heading info) from the cache as well CachedDataManager.Aggregations.Clear(); return(new RestResponseMessage(ErrorRestTypeEnum.Successful, null)); }
private bool complete_item_submission(SobekCM_Item Item_To_Complete, Custom_Tracer Tracer) { // Set an initial flag criticalErrorEncountered = false; string final_destination = Item_To_Complete.Source_Directory; string[] image_files = Directory.GetFiles(digitalResourceDirectory); // This package is good to go, so build it, save, etc... try { // Step through each file bool error_reading_file_occurred = false; // Add the SourceImage files first bool jpeg_added = false; bool jp2_added = false; foreach (string thisFile in image_files) { // Create the new file object and compute a label FileInfo fileInfo = new FileInfo(thisFile); SobekCM_File_Info newFile = new SobekCM_File_Info(fileInfo.Name); // Copy this file File.Copy(thisFile, final_destination + "\\" + fileInfo.Name, true); currentItem.Divisions.Physical_Tree.Add_File(newFile, "New Page"); // Seperate code for JP2 and JPEG type files string extension = fileInfo.Extension.ToUpper(); if (extension.IndexOf("JP2") >= 0) { if (!error_reading_file_occurred) { if (!newFile.Compute_Jpeg2000_Attributes(currentItem.Source_Directory)) { error_reading_file_occurred = true; } } jp2_added = true; } else if (extension.IndexOf("JPG") >= 0) { if (!error_reading_file_occurred) { if (!newFile.Compute_Jpeg_Attributes(currentItem.Source_Directory)) { error_reading_file_occurred = true; } } jpeg_added = true; } } // Add the JPEG2000 and JPEG-specific viewers //currentItem.Behaviors.Clear_Views(); if (jpeg_added) { // Is a JPEG view already existing? bool jpeg_viewer_already_exists = false; foreach (View_Object thisViewer in currentItem.Behaviors.Views) { if (thisViewer.View_Type == "JPEG") { jpeg_viewer_already_exists = true; break; } } // Add the JPEG view if it did not already exists if (!jpeg_viewer_already_exists) { currentItem.Behaviors.Add_View("JPEG"); } } // If a JPEG2000 file was just added, ensure it exists as a view for this currentItem if (jp2_added) { // Is a JPEG view already existing? bool jpg2000_viewer_already_exists = false; foreach (View_Object thisViewer in currentItem.Behaviors.Views) { if (thisViewer.View_Type == "JPEG2000") { jpg2000_viewer_already_exists = true; break; } } // Add the JPEG2000 view if it did not already exists if (!jpg2000_viewer_already_exists) { currentItem.Behaviors.Add_View("JPEG2000"); } } // Determine the total size of the package before saving string[] all_files_final = Directory.GetFiles(final_destination); double size = all_files_final.Aggregate <string, double>(0, (Current, ThisFile) => Current + (((new FileInfo(ThisFile)).Length) / 1024)); Item_To_Complete.DiskSize_KB = size; // Create the options dictionary used when saving information to the database, or writing MarcXML Dictionary <string, object> options = new Dictionary <string, object>(); if (UI_ApplicationCache_Gateway.Settings.MarcGeneration != null) { options["MarcXML_File_ReaderWriter:MARC Cataloging Source Code"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Cataloging_Source_Code; options["MarcXML_File_ReaderWriter:MARC Location Code"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Location_Code; options["MarcXML_File_ReaderWriter:MARC Reproduction Agency"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Reproduction_Agency; options["MarcXML_File_ReaderWriter:MARC Reproduction Place"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Reproduction_Place; options["MarcXML_File_ReaderWriter:MARC XSLT File"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.XSLT_File; } options["MarcXML_File_ReaderWriter:System Name"] = UI_ApplicationCache_Gateway.Settings.System.System_Name; options["MarcXML_File_ReaderWriter:System Abbreviation"] = UI_ApplicationCache_Gateway.Settings.System.System_Abbreviation; // Save to the database try { SobekCM_Item_Database.Save_Digital_Resource(Item_To_Complete, options); } catch (Exception ee) { StreamWriter writer = new StreamWriter(digitalResourceDirectory + "\\exception.txt", false); writer.WriteLine("ERROR CAUGHT WHILE SAVING DIGITAL RESOURCE"); writer.WriteLine(DateTime.Now.ToString()); writer.WriteLine(); writer.WriteLine(ee.Message); writer.WriteLine(ee.StackTrace); writer.Flush(); writer.Close(); throw; } // Assign the file root and assoc file path Item_To_Complete.Web.File_Root = Item_To_Complete.BibID.Substring(0, 2) + "\\" + Item_To_Complete.BibID.Substring(2, 2) + "\\" + Item_To_Complete.BibID.Substring(4, 2) + "\\" + Item_To_Complete.BibID.Substring(6, 2) + "\\" + Item_To_Complete.BibID.Substring(8, 2); Item_To_Complete.Web.AssocFilePath = Item_To_Complete.Web.File_Root + "\\" + Item_To_Complete.VID + "\\"; // Save the rest of the metadata Item_To_Complete.Save_SobekCM_METS(); // Finally, set the currentItem for more processing if there were any files if ((image_files.Length > 0) && (Item_To_Complete.Web.ItemID > 0)) { SobekCM_Item_Database.Update_Additional_Work_Needed_Flag(Item_To_Complete.Web.ItemID, true); } foreach (string thisFile in image_files) { try { File.Delete(thisFile); } catch (Exception ee) { RequestSpecificValues.Tracer.Add_Trace("Page_Image_Upload_MySobekViewer.Constructor", "Error deleting uploaded file: " + ee.Message); // Do nothing - not a fatal problem } } try { Directory.Delete(digitalResourceDirectory); } catch { // Do nothing - not a fatal problem } // This may be called from QC, so check on that as well string userInProcessDirectory = UI_ApplicationCache_Gateway.Settings.Servers.In_Process_Submission_Location + "\\" + RequestSpecificValues.Current_User.UserName.Replace(".", "").Replace("@", "") + "\\qcwork\\" + Item_To_Complete.METS_Header.ObjectID; if (RequestSpecificValues.Current_User.ShibbID.Trim().Length > 0) { userInProcessDirectory = UI_ApplicationCache_Gateway.Settings.Servers.In_Process_Submission_Location + "\\" + RequestSpecificValues.Current_User.ShibbID + "\\qcwork\\" + Item_To_Complete.METS_Header.ObjectID; } // Make the folder for the RequestSpecificValues.Current_User in process directory if (Directory.Exists(userInProcessDirectory)) { foreach (string thisFile in Directory.GetFiles(userInProcessDirectory)) { try { File.Delete(thisFile); } catch { // Do nothing - not a fatal problem } } } HttpContext.Current.Session[Item_To_Complete.BibID + "_" + Item_To_Complete.VID + " QC Work"] = null; } catch (Exception ee) { // Set an initial flag criticalErrorEncountered = true; string error_body = "<strong>ERROR ENCOUNTERED DURING ONLINE PAGE IMAGE UPLOAD</strong><br /><br /><blockquote>Title: " + Item_To_Complete.Bib_Info.Main_Title.Title + "<br />Permanent Link: <a href=\"" + RequestSpecificValues.Current_Mode.Base_URL + "/" + Item_To_Complete.BibID + "/" + Item_To_Complete.VID + "\">" + RequestSpecificValues.Current_Mode.Base_URL + "/" + Item_To_Complete.BibID + "/" + Item_To_Complete.VID + "</a><br />RequestSpecificValues.Current_User: "******"<br /><br /></blockquote>" + ee.ToString().Replace("\n", "<br />"); string error_subject = "Error during file management for '" + Item_To_Complete.Bib_Info.Main_Title.Title + "'"; string email_to = UI_ApplicationCache_Gateway.Settings.Email.System_Error_Email; if (email_to.Length == 0) { email_to = UI_ApplicationCache_Gateway.Settings.Email.System_Email; } Email_Helper.SendEmail(email_to, error_subject, error_body, true, String.Empty); } return(criticalErrorEncountered); }
private static void Email_Information(string EmailTitle, Exception ObjErr, Custom_Tracer Tracer, bool Redirect) { // Is ther an error email address in the configuration? if (UI_ApplicationCache_Gateway.Settings.Email.System_Error_Email.Length > 0) { try { // Build the error message string err; if (ObjErr != null) { if (ObjErr.InnerException != null) { err = "<b>" + HttpContext.Current.Request.UserHostAddress + "</b><br /><br />" + "Error in!!: " + HttpContext.Current.Items["Original_URL"] + "<br /><br />" + "Error Message: " + ObjErr.Message + "<br /><br />" + "Inner Exception: " + ObjErr.InnerException.Message + "<br /><br />" + "Stack Trace: " + ObjErr.InnerException.StackTrace + "<br /><br />"; } else { err = "<b>" + HttpContext.Current.Request.UserHostAddress + "</b><br /><br />" + "Error in!!: " + HttpContext.Current.Items["Original_URL"] + "<br /><br />" + "Error Message: " + ObjErr.Message + "<br /><br />" + "Stack Trace: " + ObjErr.StackTrace + "<br /><br />"; } if (ObjErr.Message.IndexOf("Timeout expired") >= 0) { EmailTitle = "Database Timeout Expired"; } } else { err = "<b>" + HttpContext.Current.Request.UserHostAddress + "</b><br /><br />"; } // Email the error message if (Tracer != null) { Email_Helper.SendEmail(UI_ApplicationCache_Gateway.Settings.Email.System_Error_Email, EmailTitle, err + "<br /><br />" + Tracer.Text_Trace, true, String.Empty); } else { Email_Helper.SendEmail(UI_ApplicationCache_Gateway.Settings.Email.System_Error_Email, EmailTitle, err, true, String.Empty); } } catch (Exception) { // Failed to send the email.. but not much else to do here really } } try { StreamWriter writer = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\temp\\exceptions.txt", true); writer.WriteLine(); writer.WriteLine("Error Caught in Application_Error event ( " + DateTime.Now.ToString() + ")"); writer.WriteLine("User Host Address: " + HttpContext.Current.Request.UserHostAddress); writer.WriteLine("Requested URL: " + HttpContext.Current.Request.Url); if (ObjErr is SobekCM_Traced_Exception) { SobekCM_Traced_Exception sobekException = (SobekCM_Traced_Exception)ObjErr; writer.WriteLine("Error Message: " + sobekException.InnerException.Message); writer.WriteLine("Stack Trace: " + ObjErr.StackTrace); writer.WriteLine("Error Message:" + sobekException.InnerException.StackTrace); writer.WriteLine(); writer.WriteLine(sobekException.Trace_Route); } else { writer.WriteLine("Error Message: " + ObjErr.Message); writer.WriteLine("Stack Trace: " + ObjErr.StackTrace); } writer.WriteLine(); writer.WriteLine("------------------------------------------------------------------"); writer.Flush(); writer.Close(); } catch (Exception) { // Nothing else to do here.. no other known way to log this error } // Forward to our error message if (Redirect) { HttpContext.Current.Response.Redirect(UI_ApplicationCache_Gateway.Settings.Servers.System_Error_URL, false); HttpContext.Current.ApplicationInstance.CompleteRequest(); } }