protected void SendButton_Click(object sender, System.EventArgs e) { // SHOW THE PREVIEW if (Page.IsValid) { // GENERATE MESSAGE AND SEND MESSAGE MailMergeTemplate mergeTemplate = GetMailMergeTemplate(); IList <MailMergeRecipient> recipients = GetAllRecipients(); mergeTemplate.Send(recipients, true); if (_RestockNotifyList != null) { if (RemoveNotificationSubscriptionsFlag.Value == "1") { _RestockNotifyList.DeleteAll(); } else { foreach (RestockNotify notification in _RestockNotifyList) { notification.LastSentDate = LocaleHelper.LocalNow; } _RestockNotifyList.Save(); } } // PROVIDE NOTIFICATION ComposePanel.Visible = false; PreviewPanel.Visible = false; ConfirmationPanel.Visible = true; SmtpErrorPanel.Visible = false; ConfirmationMessage.Text = string.Format(ConfirmationMessage.Text, recipients.Count); } }
/// <summary> /// Reads the values from the form and popupates a /// MailMergeTemplate instance /// </summary> /// <returns>A MailMergeTemplate instance populated with /// the values on the form</returns> private MailMergeTemplate GetMailMergeTemplate() { MailMergeTemplate mergeTemplate = new MailMergeTemplate(); mergeTemplate.CCList = CCAddress.Text; mergeTemplate.BCCList = BCCAddress.Text; mergeTemplate.FromAddress = FromAddress.Text; mergeTemplate.Subject = Subject.Text; mergeTemplate.IsHTML = (MailFormat.SelectedIndex == 0); mergeTemplate.Body = Message.Text; // POPULATE SHARED PARAMETERS mergeTemplate.Parameters["store"] = AbleContext.Current.Store; // RETURN GENERATED MESSAGE return(mergeTemplate); }
protected void PreviewButton_Click(object sender, EventArgs e) { // SHOW THE PREVIEW if (Page.IsValid) { // GENERATE MESSAGE MailMergeTemplate mergeTemplate = GetMailMergeTemplate(); mergeTemplate.Parameters["store"] = AbleContext.Current.Store; // GET RECIPIENT IList <MailMergeRecipient> recipients = GetAllRecipients(); // GET A PREVIEW MESSAGE MailMessage message; try { message = mergeTemplate.GenerateMessage(recipients[0]); } catch (Exception ex) { EmailTemplateErrorLabel.Text = String.Format(EmailTemplateErrorLabel.Text, mergeTemplate.Subject, ex.Message); EmailTemplateErrorLabel.Visible = true; return; } // DISPLAY THE MESSAGE CONTENT if (message.IsBodyHtml) { PreviewMessage.Text = message.Body; } else { PreviewMessage.Text = "<PRE>" + Server.HtmlEncode(message.Body) + "</PRE>"; } // SWAP THE PANELS ComposePanel.Visible = false; PreviewPanel.Visible = true; PreviewHelpText.Text = string.Format(PreviewHelpText.Text, recipients.Count); ConfirmationPanel.Visible = false; SmtpErrorPanel.Visible = false; // SET Flag for notification subscriptinos removal RemoveNotificationSubscriptionsFlag.Value = RemoveNotificationSubscriptions.Checked ? "1" : "0"; } }
protected void SendButton_Click(object sender, System.EventArgs e) { // SHOW THE PREVIEW if (Page.IsValid) { // GENERATE MESSAGE AND SEND MESSAGE MailMergeTemplate mergeTemplate = GetMailMergeTemplate(); IList <MailMergeRecipient> recipients = GetAllRecipients(); mergeTemplate.Send(recipients, true); if (_EmailList != null) { _EmailList.LastSendDate = LocaleHelper.LocalNow; _EmailList.Save(); } // PROVIDE NOTIFICATION ComposePanel.Visible = false; PreviewPanel.Visible = false; ConfirmationPanel.Visible = true; SmtpErrorPanel.Visible = false; ConfirmationMessage.Text = string.Format(ConfirmationMessage.Text, recipients.Count); Session["SendMail_IdList"] = null; } }
private async Task <string> CheckMailMergeTemplates() { StringBuilder content = new StringBuilder(); await _comparerSource.InitializeConnection(_iWriteToOutput, content); string operation = string.Format(Properties.OperationNames.CheckingMailMergeTemplatesFormat2, Connection1.Name, Connection2.Name); content.AppendLine(_iWriteToOutput.WriteToOutputStartOperation(null, operation)); Task <List <MailMergeTemplate> > task1 = _comparerSource.GetMailMergeTemplate1Async(); Task <List <MailMergeTemplate> > task2 = _comparerSource.GetMailMergeTemplate2Async(); List <MailMergeTemplate> list1 = await task1; content.AppendLine(_iWriteToOutput.WriteToOutput(null, "Mail Merge Templates in {0}: {1}", Connection1.Name, list1.Count())); List <MailMergeTemplate> list2 = await task2; content.AppendLine(_iWriteToOutput.WriteToOutput(null, "Mail Merge Templates in {0}: {1}", Connection2.Name, list2.Count())); if (list1.Count == 0 && list2.Count == 0) { _iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.ThereIsNothingToCompare); _iWriteToOutput.WriteToOutputEndOperation(null, operation); return(null); } FormatTextTableHandler tableOnlyExistsIn1 = new FormatTextTableHandler(); tableOnlyExistsIn1.SetHeader("AssociatedEntity", "Name", "Language", "File Name", "Mail Merge Type", "Viewable By", "Owner", "Id"); FormatTextTableHandler tableOnlyExistsIn2 = new FormatTextTableHandler(); tableOnlyExistsIn2.SetHeader("AssociatedEntity", "Name", "Language", "File Name", "Mail Merge Type", "Viewable By", "Owner", "Id"); Dictionary <Tuple <string, string, string, string>, List <string> > dictDifference = new Dictionary <Tuple <string, string, string, string>, List <string> >(); foreach (MailMergeTemplate template1 in list1) { { MailMergeTemplate template2 = list2.FirstOrDefault(template => template.Id == template1.Id); if (template2 != null) { continue; } } string name1 = template1.Name; string entityName1 = template1.TemplateTypeCode; int language1 = template1.LanguageCode.Value; string filename = template1.FileName; string reportType = template1.FormattedValues.ContainsKey(MailMergeTemplate.Schema.Attributes.mailmergetype) ? template1.FormattedValues[MailMergeTemplate.Schema.Attributes.mailmergetype] : string.Empty; Microsoft.Xrm.Sdk.EntityReference ownerRef = template1.OwnerId; string owner = string.Empty; if (ownerRef != null) { owner = ownerRef.Name; } string ispersonal = template1.FormattedValues.ContainsKey(MailMergeTemplate.Schema.Attributes.ispersonal) ? template1.FormattedValues[MailMergeTemplate.Schema.Attributes.ispersonal] : string.Empty; tableOnlyExistsIn1.AddLine(entityName1, name1, LanguageLocale.GetLocaleName(language1), filename, reportType, ispersonal, owner, template1.Id.ToString()); this.ImageBuilder.AddComponentSolution1((int)ComponentType.MailMergeTemplate, template1.Id); } foreach (MailMergeTemplate template2 in list2) { { MailMergeTemplate template1 = list1.FirstOrDefault(template => template.Id == template2.Id); if (template1 != null) { continue; } } string name2 = template2.Name; string entityName2 = template2.TemplateTypeCode; int language2 = template2.LanguageCode.Value; string filename = template2.FileName; string templateType = template2.FormattedValues.ContainsKey(MailMergeTemplate.Schema.Attributes.mailmergetype) ? template2.FormattedValues[MailMergeTemplate.Schema.Attributes.mailmergetype] : string.Empty; Microsoft.Xrm.Sdk.EntityReference ownerRef = template2.OwnerId; string owner = string.Empty; if (ownerRef != null) { owner = ownerRef.Name; } string ispersonal = template2.FormattedValues.ContainsKey(MailMergeTemplate.Schema.Attributes.ispersonal) ? template2.FormattedValues[MailMergeTemplate.Schema.Attributes.ispersonal] : string.Empty; tableOnlyExistsIn2.AddLine(entityName2, name2, LanguageLocale.GetLocaleName(language2), filename, templateType, ispersonal, owner, template2.Id.ToString()); this.ImageBuilder.AddComponentSolution2((int)ComponentType.MailMergeTemplate, template2.Id); } foreach (MailMergeTemplate template1 in list1) { MailMergeTemplate template2 = list2.FirstOrDefault(template => template.Id == template1.Id); if (template2 == null) { continue; } FormatTextTableHandler tabDiff = new FormatTextTableHandler(); tabDiff.SetHeader("Attribute", "Organization", "Value"); foreach (string fieldName in _fieldsToCompareMailMergeTemplateOrdinal) { if (ContentCoparerHelper.IsEntityDifferentInField(template1, template2, fieldName)) { string str1 = EntityDescriptionHandler.GetAttributeString(template1, fieldName, Connection1); string str2 = EntityDescriptionHandler.GetAttributeString(template2, fieldName, Connection2); tabDiff.AddLine(fieldName, Connection1.Name, str1); tabDiff.AddLine(fieldName, Connection2.Name, str2); } } foreach (string fieldName in _fieldsToCompareMailMergeTemplateXml) { string xml1 = template1.GetAttributeValue <string>(fieldName) ?? string.Empty; string xml2 = template2.GetAttributeValue <string>(fieldName) ?? string.Empty; if (!ContentCoparerHelper.CompareXML(xml1, xml2).IsEqual) { string reason = string.Empty; ContentCopareResult compare = ContentCoparerHelper.CompareXML(xml1.ToLower(), xml2.ToLower(), true); if (!compare.IsEqual) { reason = "InCase"; } else { reason = compare.GetCompareDescription(); } tabDiff.AddLine(fieldName, string.Empty, string.Format(Properties.OrganizationComparerStrings.FieldDifferenceReasonFormat3, Connection1.Name, Connection2.Name, reason)); } } if (tabDiff.Count > 0) { string name1 = template1.Name; string entityName1 = template1.TemplateTypeCode; int language1 = template1.LanguageCode.Value; var diff = tabDiff.GetFormatedLines(false); this.ImageBuilder.AddComponentDifferent((int)ComponentType.MailMergeTemplate, template1.Id, template2.Id, string.Join(Environment.NewLine, diff)); dictDifference.Add(Tuple.Create(entityName1, name1, LanguageLocale.GetLocaleName(language1), template1.Id.ToString()), diff); } } if (tableOnlyExistsIn1.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("Mail Merge Templates ONLY EXISTS in {0}: {1}", Connection1.Name, tableOnlyExistsIn1.Count); tableOnlyExistsIn1.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd())); } if (tableOnlyExistsIn2.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("Mail Merge Templates ONLY EXISTS in {0}: {1}", Connection2.Name, tableOnlyExistsIn2.Count); tableOnlyExistsIn2.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd())); } if (dictDifference.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("Mail Merge Templates DIFFERENT in {0} and {1}: {2}", Connection1.Name, Connection2.Name, dictDifference.Count); FormatTextTableHandler tableDifference = new FormatTextTableHandler(); tableDifference.SetHeader("AssociatedEntity", "Name", "Language", "Id"); foreach (KeyValuePair <Tuple <string, string, string, string>, List <string> > template in dictDifference) { tableDifference.CalculateLineLengths(template.Key.Item1, template.Key.Item2, template.Key.Item3, template.Key.Item4); } foreach (KeyValuePair <Tuple <string, string, string, string>, List <string> > template in dictDifference .OrderBy(w => w.Key.Item1) .ThenBy(w => w.Key.Item2) .ThenBy(w => w.Key.Item3) .ThenBy(w => w.Key.Item4) ) { content.AppendLine().Append(tabSpacer + tableDifference.FormatLine(template.Key.Item1, template.Key.Item2, template.Key.Item3, template.Key.Item4)); foreach (string str in template.Value) { content.AppendLine().Append(tabSpacer + tabSpacer + str); } } } if (tableOnlyExistsIn2.Count == 0 && tableOnlyExistsIn1.Count == 0 && dictDifference.Count == 0 ) { content.AppendLine("No difference in Mail Merge Templates."); } content.AppendLine().AppendLine().AppendLine(_iWriteToOutput.WriteToOutputEndOperation(null, operation)); string fileName = EntityFileNameFormatter.GetDifferenceConnectionsForFieldFileName(_OrgOrgName, "Mail Merge Templates"); string filePath = Path.Combine(_folder, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); await SaveOrganizationDifferenceImage(); return(filePath); }