private static void GenerateContactCore(string outputFolder, REF.Scope generatePerContact, Contact contact, string templateFile) { switch (generatePerContact) { case REF.Scope.Letter: GenerateFilled(outputFolder, contact, templateFile); break; case REF.Scope.Envelop: GenerateFilled(outputFolder, contact, REF.envelopFile); break; case REF.Scope.LetterAndEnvelop: GenerateFilled(outputFolder, contact, templateFile); GenerateFilled(outputFolder, contact, REF.envelopFile); break; default: break; } }
public static ExecutionResult GenerateContact(string outputFolder, Contact contact, REF.Scope generatePerContact, string templateFile) { try { GenerateContactCore(outputFolder, generatePerContact, contact, templateFile); CallUpdateStatus("Operation passed and filled templates are generated in the Output folder"); return(ExecutionResult.Successful); } catch (Exception x) { if (!x.Data.Contains("outputFolder")) { x.Data.Add("outputFolder", outputFolder); } if (!x.Data.Contains("generatePerContact")) { x.Data.Add("generatePerContact", generatePerContact); } if (!x.Data.Contains("templateFile")) { x.Data.Add("templateFile", templateFile); } if (!x.Data.Contains("contact.OppName")) { x.Data.Add("contact.OppName", contact.OppName); } XLogger.Error(x); CallUpdateStatus("There was a problem in generating all the contacts files"); return(ExecutionResult.ErrorOccured); } }
private static ExecutionResult GenerateMessages(string templatesFolder, string outputFolder, REF.Scope generatePerContact, List <Contact> contacts) { var successfulContacts = new List <Contact>(); var failedContacts = new List <Contact>(); Contact contact = new Contact(); var templateFile = ""; for (int i = 0; i < contacts.Count; i++) { try { templateFile = ""; contact = contacts[i]; CallUpdateStatus($"Processing contact {i + 1} of {contacts.Count} contacts"); if (!string.IsNullOrEmpty(contact.CDMailerTemplate)) { templateFile = Path.ChangeExtension(Path.Combine(templatesFolder, contact.CDMailerTemplate), ".docx"); } GenerateContactCore(outputFolder, generatePerContact, contact, templateFile); if (!File.Exists(templateFile)) { throw new ApplicationException($"Missing template file: {templateFile}"); } successfulContacts.Add(contact); } catch (Exception x) { if (!x.Data.Contains("outputFolder")) { x.Data.Add("outputFolder", outputFolder); } if (!x.Data.Contains("generatePerContact")) { x.Data.Add("generatePerContact", generatePerContact); } if (!x.Data.Contains("templateFile")) { x.Data.Add("templateFile", templateFile); } if (!x.Data.Contains("contact.OppName")) { x.Data.Add("contact.OppName", contact.OppName); } XLogger.Error(x); failedContacts.Add(contact); } } if (successfulContacts.Count == contacts.Count()) { CallUpdateStatus("Operation passed and filled templates are generated in the Output folder"); return(ExecutionResult.Successful); } else if (failedContacts.Count == contacts.Count()) { CallUpdateStatus("There was a problem in generating all the contacts files"); return(ExecutionResult.ErrorOccured); } else { CallUpdateStatus($"There was a problem generating some of the contact files. Successfully generated {successfulContacts.Count} contact files and failed to generate {failedContacts.Count} files. \nBelow are the failed contacts, make sure they have a valid template assigned:\n\n{String.Join("\n", failedContacts)}"); return(ExecutionResult.PartialPass); } }
public static ExecutionResult DoCustom(string outputFolder, List <Contact> contacts, REF.Scope generatePerContact, string templateFile) { var successfulContacts = new List <Contact>(); var failedContacts = new List <Contact>(); Contact contact = new Contact(); for (int i = 0; i < contacts.Count; i++) { try { contact = contacts[i]; CallUpdateStatus($"Processing contact {i + 1} of {contacts.Count} contacts"); GenerateContactCore(outputFolder, generatePerContact, contact, templateFile); if (!File.Exists(templateFile)) { throw new ApplicationException($"Missing template file: {templateFile}"); } successfulContacts.Add(contact); } catch (Exception x) { if (!x.Data.Contains("outputFolder")) { x.Data.Add("outputFolder", outputFolder); } if (!x.Data.Contains("generatePerContact")) { x.Data.Add("generatePerContact", generatePerContact); } if (!x.Data.Contains("templateFile")) { x.Data.Add("templateFile", templateFile); } if (!x.Data.Contains("contact.OppName")) { x.Data.Add("contact.OppName", contact.OppName); } XLogger.Error(x); failedContacts.Add(contact); } } if (successfulContacts.Count == contacts.Count()) { CallUpdateStatus("Operation passed and filled templates are generated in the Output folder"); return(ExecutionResult.Successful); } else if (failedContacts.Count == contacts.Count()) { CallUpdateStatus("There was a problem in generating all the contacts files"); return(ExecutionResult.ErrorOccured); } else { CallUpdateStatus($"There was a problem generating some of the contact files. Successfully generated {successfulContacts.Count} contact files and failed to generate {failedContacts.Count} files. \nBelow are the failed contacts:\n\n{String.Join("\n", failedContacts)}"); return(ExecutionResult.PartialPass); } }