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); } }
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); } }
public void Simple_Item_XML(HttpResponse Response, List <string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { // Must at least have one URL segment for the BibID if (UrlSegments.Count > 0) { Custom_Tracer tracer = new Custom_Tracer(); try { // Get the BibID and VID string bibid = UrlSegments[0]; string vid = (UrlSegments.Count > 1) ? UrlSegments[1] : "00001"; tracer.Add_Trace("SimpleItemEndpoints.Simple_Item_XML", "Requested citation for " + bibid + ":" + vid); // Get the brief item tracer.Add_Trace("SimpleItemEndpoints.Simple_Item_XML", "Build full brief item"); Tuple <BriefItemInfo, Items.SobekCM_Item_Error> returnTuple = GetBriefItem(bibid, vid, null, tracer); // Was the item null? if ((returnTuple == null) || (returnTuple.Item1 == null)) { // If this was debug mode, then just write the tracer if (IsDebug) { tracer.Add_Trace("SimpleItemEndpoints.Simple_Item_XML", "NULL value returned from getBriefItem method"); Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); // Was an error received though? if ((returnTuple != null) && (returnTuple.Item2 != null)) { Items.SobekCM_Item_Error itemError = returnTuple.Item2; switch (itemError.Type) { case Items.SobekCM_Item_Error_Type_Enum.Invalid_BibID: Response.Output.WriteLine("ERROR: Invalid BibID requested"); break; case Items.SobekCM_Item_Error_Type_Enum.Invalid_VID: Response.Output.WriteLine("ERROR: Invalid VID requested"); Response.Output.WriteLine("First valid VID is " + itemError.FirstValidVid); break; case Items.SobekCM_Item_Error_Type_Enum.System_Error: Response.Output.WriteLine("System ERROR detected while attempting to create the item"); Response.Output.WriteLine(itemError.Message); break; } Response.Output.WriteLine(); } Response.Output.WriteLine(tracer.Text_Trace); } return; } // Get the brief item info BriefItemInfo returnValue = returnTuple.Item1; // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // If this is dark, do nothing if (returnValue.Behaviors.Dark_Flag) { Response.ContentType = "text/plain"; Response.Output.WriteLine("Item is restricted"); Response.StatusCode = 403; return; } // Create and write the basic item info Response.Output.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>"); Response.Output.WriteLine("<item bibid=\"" + returnValue.BibID + "\" vid=\"" + returnValue.VID + "\">"); Response.Output.WriteLine(" <title>" + HttpUtility.HtmlEncode(returnValue.Title) + "</title>"); Response.Output.WriteLine(" <url_item>" + Engine_ApplicationCache_Gateway.Settings.Servers.Application_Server_URL + returnValue.BibID + "/" + returnValue.VID + "/</url_item>"); // Add the thumbnail URL if (!String.IsNullOrEmpty(returnValue.Behaviors.Main_Thumbnail)) { try { Response.Output.WriteLine(" <url_thumbnail>" + Engine_ApplicationCache_Gateway.Settings.Servers.Image_URL + SobekFileSystem.AssociFilePath(returnValue.BibID, returnValue.VID).Replace("\\", "/") + returnValue.Behaviors.Main_Thumbnail.Trim() + "</url_thumbnail>"); } catch (Exception ee) { Response.Output.WriteLine("ERROR WRITING THUMBNAIL"); Response.Output.WriteLine(ee.Message); Response.Output.WriteLine(ee.StackTrace); } } Response.Output.WriteLine(" <metadata>"); // Step through the citation configuration here CitationSet citationSet = Engine_ApplicationCache_Gateway.Configuration.UI.CitationViewer.Get_CitationSet(); foreach (CitationFieldSet fieldsSet in citationSet.FieldSets) { // 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 = returnValue.Get_Description(thisField.MetadataTerm); // If no match, just continue if ((briefTerm == null) || (briefTerm.Values.Count == 0)) { continue; } // Get the clean XML tag for this term string cleaned_metadata_term = HttpUtility.HtmlEncode(thisField.DisplayTerm.Replace(" ", "_").Replace("/", "_").Replace("__", "_").Replace("__", "_")); foreach (BriefItem_DescTermValue term in briefTerm.Values) { Response.Output.WriteLine(" <" + cleaned_metadata_term + ">" + HttpUtility.HtmlEncode(term.Value) + "</" + cleaned_metadata_term + ">"); } } } Response.Output.WriteLine(" </metadata>"); Response.Output.WriteLine("</item>"); } catch (Exception ee) { if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("EXCEPTION CAUGHT!"); Response.Output.WriteLine(); Response.Output.WriteLine(ee.Message); Response.Output.WriteLine(); Response.Output.WriteLine(ee.StackTrace); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Error completing request"); Response.StatusCode = 500; } } }