/// <summary> /// Creates a VCalendar text with the specified parameters. /// </summary> /// <param name="meetingUniqueIdentifier">This uniquely identifies the meeting and is used for changes / cancellations. It is recommended to use the ID of the owner object.</param> public static string AddVCalendarView(this IEmailMessage @this, string meetingUniqueIdentifier, DateTime start, DateTime end, string subject, string description, string location) { var dateFormat = "yyyyMMddTHHmmssZ"; Func <string, string> cleanUp = s => s.Or("").Remove("\r").Replace("\n", "\\n"); var r = new StringBuilder(); r.AppendLine(@"BEGIN:VCALENDAR"); r.AppendLine(@"PRODID:-//Microsoft Corporation//Outlook 12.0 MIMEDIR//EN"); r.AppendLine(@"VERSION:1.0"); r.AppendLine(@"BEGIN:VEVENT"); r.AddFormattedLine(@"DTSTART:{0}", start.ToString(dateFormat)); r.AddFormattedLine(@"DTEND:{0}", end.ToString(dateFormat)); r.AddFormattedLine(@"UID:{0}", meetingUniqueIdentifier); r.AddFormattedLine(@"SUMMARY:{0}", cleanUp(subject)); r.AppendLine("LOCATION:" + cleanUp(location)); r.AppendLine("DESCRIPTION:" + cleanUp(description)); // bodyCalendar.AppendLine(@"PRIORITY:3"); r.AppendLine(@"END:VEVENT"); r.AppendLine(@"END:VCALENDAR"); return(@this.VCalendarView = r.ToString()); }
string GenerateExcelWorksheet() { var r = new StringBuilder(); r.AddFormattedLine(@"<Worksheet ss:Name=""{0}"">", DocumentName.Remove("/", @"\", "?", "*", ":", "[", "]", "\r", "\n").KeepReplacing(" ", " ").Summarize(31, enforceMaxLength: true).XmlEncode()); r.AddFormattedLine(@"<Table DefaultColumnWidth=""{0}"">", DefaultColumnWidth); r.AppendLine(Columns.Select((h, i) => GenerateColumnTag(h, i + 1)).Trim().ToLinesString()); r.AppendLine(GenerateHeaderGroupings()); if (!ExcludeHeader) { r.AppendLine(GenerateSheetHeaderRow()); } r.AppendLine(GenerateDataRows()); r.AppendLine(@"</Table>"); r.AppendLine(GenerateDropDownDataValidation()); r.AppendLine(GenerateWorksheetSettings()); r.AppendLine(@"</Worksheet>"); return(r.ToString()); }
string GenerateEmailView() { var r = new StringBuilder(); r.AppendLine("<a href='/?Web.Test.Command=testEmail&to=" + To + "'><< Back</a>"); r.AppendLine("<h2>Subject: <u>" + Email.Subject.Or("[NO SUBJECT]") + "</u></h2>"); r.AppendLine("<table cellspacing='0'>"); var body = GetBodyHtml(Email.Body.Or("[EMPTY BODY]"), Email.Html); var toShow = new Dictionary <string, object> { { "Date", Email.Date.ToString("yyyy-MM-dd") + " at " + Email.Date.ToString("HH:mm") }, { "From", GetFrom(Email) }, { "To", Email.To }, { "Bcc", Email.Bcc }, { "Cc", Email.Cc }, { "Subject", Email.Subject.Or("[NO SUBJECT]").HtmlEncode().WithWrappers("<b>", "</b>") }, { "Body", body.WithWrappers("<div class='body'>", "</div>") }, { "Attachments", GetAttachmentLinks(Email) } }; foreach (var item in toShow.Where(x => x.Value.ToStringOrEmpty().HasValue())) { r.AppendLine("<tr>"); r.AddFormattedLine("<td class='label'>{0}:</td>", item.Key.HtmlEncode()); r.AddFormattedLine("<td>{0}</td>", item.Value); r.AppendLine("</tr>"); } r.AppendLine("</table>"); return(r.ToString()); }
string GenerateStyleTemplate() { var r = new StringBuilder(); r.AppendLine(@"<Style ss:ID=""[#Style.ID#]"">"); r.AddFormattedLine(@"<Alignment ss:Horizontal=""{0}"" ss:Vertical=""{1}"" ss:Rotate=""{2}""{3}/>", Alignment, VerticalAlignment, GetCellRotation(), " ss:WrapText=\"1\"".OnlyWhen(WrapText)); r.AddFormattedLine(@"<Font ss:FontName=""{0}"" x:Family=""Swiss"" ss:Size=""{1}"" ss:Color=""{2}"" ss:Bold=""{3}"" ss:Italic=""{4}"" />", FontName, FontSize, ForeColor, Bold ? 1 : 0, Italic ? 1 : 0); if (BackgroundColor.HasValue() && BackgroundColor.ToUpper() != "#FFFFFF") { r.AddFormattedLine(@"<Interior ss:Color=""{0}"" ss:Pattern=""Solid""/>", BackgroundColor); } if (BorderWidth > 0) { r.AddFormattedLine(@"<Borders> <Border ss:Position=""Bottom"" ss:LineStyle=""Continuous"" ss:Weight=""{1}"" ss:Color=""{0}""/> <Border ss:Position=""Left"" ss:LineStyle=""Continuous"" ss:Weight=""{1}"" ss:Color=""{0}""/> <Border ss:Position=""Right"" ss:LineStyle=""Continuous"" ss:Weight=""{1}"" ss:Color=""{0}""/> <Border ss:Position=""Top"" ss:LineStyle=""Continuous"" ss:Weight=""{1}"" ss:Color=""{0}""/> </Borders>", BorderColor, BorderWidth); } if (NumberFormat.HasValue()) { r.AddFormattedLine(@"<NumberFormat ss:Format=""{0}"" />", NumberFormat.HtmlEncode()); } r.AppendLine(@"</Style>"); return(r.ToString()); }
void AddPaginationControl(StringBuilder builder, string text, string ariaText, bool isDisabled, int pageNumber) { builder.AppendFormat("<li{0}>", " class=\"disabled\"".OnlyWhen(isDisabled)); builder.AddFormattedLine("<a {0} aria-label=\"{1}\">", GetLinkAttributes(pageNumber), ariaText); builder.AddFormattedLine("<span aria-hidden=\"true\">{0}</span>", text); builder.AppendLine("</a>"); builder.AppendLine("</li>"); }
async Task <string> GenerateInbox() { var r = new StringBuilder(); var emails = await GetEmails(); r.AppendLine("<h2>Emails sent to <u>" + To.Or("ALL") + "</u></h2>"); r.AppendLine("<table cellspacing='0'>"); r.AppendLine("<tr>"); r.AppendLine("<th>Date</th>"); r.AppendLine("<th>Time</th>"); r.AppendLine("<th>From</th>"); r.AppendLine("<th>ReplyTo</th>"); r.AppendLine("<th>To</th>"); r.AppendLine("<th>Cc</th>"); r.AppendLine("<th>Bcc</th>"); r.AppendLine("<th>Subject</th>"); r.AppendLine("<th>Attachments</th>"); r.AppendLine("</tr>"); if (emails.None()) { r.AppendLine("<tr>"); r.AppendLine("<td colspan='8'>No emails in the system</td>"); r.AppendLine("</tr>"); } else { foreach (var item in emails) { r.AppendLine("<tr>"); r.AddFormattedLine("<td>{0}</td>", item.SendableDate.ToString("yyyy-MM-dd")); r.AddFormattedLine("<td>{0}</td>", item.SendableDate.ToSmallTime()); r.AddFormattedLine("<td>{0}</td>", item.GetEffectiveFromName() + "(" + item.GetEffectiveFromAddress() + ")"); r.AddFormattedLine("<td>{0}</td>", item.GetEffectiveReplyToName() + "(" + item.GetEffectiveReplyToAddress() + ")"); r.AddFormattedLine("<td>{0}</td>", item.To); r.AddFormattedLine("<td>{0}</td>", item.Cc); r.AddFormattedLine("<td>{0}</td>", item.Bcc); r.AddFormattedLine("<td><a href='/?Web.Test.Command=testEmail&id={0}&to={1}&ReturnUrl={2}'>{3}</a></td>", item.GetId(), To, ReturnUrl.UrlEncode(), item.Subject.Or("[NO SUBJECT]").HtmlEncode()); r.AddFormattedLine("<td>{0}</td>", GetAttachmentLinks(item)); r.AppendLine("</tr>"); } } r.AppendLine("</table>"); return(r.ToString()); }
async Task <string> GenerateInbox() { var r = new StringBuilder(); var emails = await GetEmails(); r.AppendLine("<h2>Emails sent to <u>" + To.Or("ALL") + "</u></h2>"); r.AppendLine("<table cellspacing='0'>"); r.AppendLine("<tr>"); r.AppendLine("<th>Date</th>"); r.AppendLine("<th>Time</th>"); r.AppendLine("<th>From</th>"); r.AppendLine("<th>ReplyTo</th>"); r.AppendLine("<th>To</th>"); r.AppendLine("<th>Cc</th>"); r.AppendLine("<th>Bcc</th>"); r.AppendLine("<th>Subject</th>"); r.AppendLine("<th>Attachments</th>"); r.AppendLine("</tr>"); if (emails.None()) { r.AppendLine("<tr>"); r.AppendLine("<td colspan='8'>No emails in the system</td>"); r.AppendLine("</tr>"); } else { foreach (var item in emails) { var mail = await MessageCreator.Create(item); r.AppendLine("<tr>"); r.AddFormattedLine("<td>{0}</td>", item.SendableDate.ToString("yyyy-MM-dd")); r.AddFormattedLine("<td>{0}</td>", item.SendableDate.ToSmallTime()); r.AddFormattedLine("<td>{0}</td>", mail.From.DisplayName + "(" + mail.From.Address + ")"); r.AddFormattedLine("<td>{0}</td>", mail.ReplyToList.First().DisplayName + "(" + mail.ReplyToList.First().Address + ")"); r.AddFormattedLine("<td>{0}</td>", item.To); r.AddFormattedLine("<td>{0}</td>", item.Cc); r.AddFormattedLine("<td>{0}</td>", item.Bcc); var text = item.Subject.Or("[NO SUBJECT]").HtmlEncode(); var url = $"/cmd/{Name}?id={item.GetId()}&to={To}&ReturnUrl={ReturnUrl.UrlEncode()}"; r.AppendLine($"<td><a href='{url}'>{text}</a></td>"); r.AddFormattedLine("<td>{0}</td>", GetAttachmentLinks(item)); r.AppendLine("</tr>"); } } r.AppendLine("</table>"); return(r.ToString()); }
static string GenerateStyles(params ExcelExporter <T>[] sheets) { var r = new StringBuilder(); r.AppendLine("<Styles>"); // Link style r.AddFormattedLine(@"<Style ss:ID=""linkStyle""> <Font ss:Color=""#0000FF"" ss:Underline=""Single""/> </Style>", sheets.First().HeaderBackGroundColor); // Merge settings: sheets.Do(s => s.MergeStyles()); var uniqueStyles = sheets.SelectMany(x => x.GetAllStyles()).Distinct(x => x.GetStyleId()).ToList(); foreach (var style in uniqueStyles) { r.AppendLine(style.GenerateStyle()); } r.AppendLine("</Styles>"); return(r.ToString()); }
static HtmlString GenerateCheckBoxes(this IHtmlHelper html, string name, IEnumerable selectedItems, IEnumerable <SelectListItem> selectList, object htmlAttributes = null, PropertyInfo property = null, bool setContainerId = true) { var currentItems = new string[0]; if (selectedItems != null) { if (selectedItems is string) { currentItems = new[] { (string)selectedItems } } ; else { currentItems = (selectedItems as IEnumerable).Cast <object>().ExceptNull() .Select(x => ((x as IEntity)?.GetId()).ToStringOrEmpty().Or(x.ToString())).ToArray(); } } var settings = ToHtmlAttributes(htmlAttributes); var r = new StringBuilder(); r.Append("<div class=\"checkbox-list\""); r.AppendIf($" id=\"{name}\"", setContainerId); r.AppendLine(">"); var isRequiredProperty = property?.IsDefined(typeof(RequiredAttribute)) == true; var requiredValidationMessage = isRequiredProperty ? GetRequiredValidationMessage(property) : string.Empty; foreach (var item in selectList) { r.AddFormattedLine("<div{0}>", settings); var id = name + "_" + selectList.IndexOf(item); r.AppendLine($"<input type=\"checkbox\" id=\"{id}\" name=\"{name}\" value=\"{item.Value}\" class=\"form-check-input\""); if (currentItems.Contains(item.Value)) { r.Append(" checked=\"checked\""); } r.AppendIf(" disabled", item.Disabled); r.AppendIf($" data-val=\"true\" data-val-selection-required data-val-required=\"{requiredValidationMessage}\"", isRequiredProperty); r.AppendLine(">"); r.AppendLine($"<label for=\"{id}\" class=\"form-check-label\">{item.Text}</label>"); r.AppendLine("</div>"); } r.AppendLine("</div>"); return(new HtmlString(r.ToString())); }
async Task <string> GenerateEmailView() { var email = await Email(); var r = new StringBuilder(); var mail = await MessageCreator.Create(email); r.AppendLine($"<a href='/cmd/{Name}?to={To}'><< Back</a>"); r.AppendLine("<h2>Subject: <u>" + mail.Subject + "</u></h2>"); r.AppendLine("<table cellspacing='0'>"); var body = GetBodyHtml(email.Body.Or("[EMPTY BODY]"), email.Html); var toShow = new Dictionary <string, object> { { "Date", email.SendableDate.ToString("yyyy-MM-dd") + " at " + email.SendableDate.ToString("HH:mm") }, { "From", mail.From?.Address }, { "ReplyTo", mail.ReplyToList.FirstOrDefault()?.Address }, { "To", mail.To.Select(x => x.Address).ToString(", ") }, { "Cc", mail.CC.Select(x => x.Address).ToString(", ") }, { "Bcc", mail.Bcc.Select(x => x.Address).ToString(", ") }, { "Subject", mail.Subject.HtmlEncode().WithWrappers("<b>", "</b>") }, { "Body", body.WithWrappers("<div class='body'>", "</div>") }, { "Attachments", GetAttachmentLinks(email) } }; foreach (var item in toShow.Where(x => x.Value.ToStringOrEmpty().HasValue())) { r.AppendLine("<tr>"); r.AddFormattedLine("<td class='label'>{0}:</td>", item.Key.HtmlEncode()); r.AddFormattedLine("<td>{0}</td>", item.Value); r.AppendLine("</tr>"); } r.AppendLine("</table>"); return(r.ToString()); }
string CreateCode <K>(string condition, string expression) { var r = new StringBuilder(); var namespaces = new[] { ListType, typeof(K) }.Select(t => t.Namespace) .Concat(new[] { "System", "System.Linq", "System.Collections", "System.Collections.Generic" }).Distinct(); foreach (var n in namespaces) { r.AddFormattedLine("using {0};", n); } r.AppendLine("public static class Class"); r.AppendLine("{"); r.AddFormattedLine("public static IEnumerable<{1}> Run(IEnumerable<{0}> list)", FullTypeName, typeof(K).FullName); r.AppendLine("{"); r.AppendLine("foreach (var each in list)"); r.AppendLine("{"); if (condition.HasValue()) { r.AddFormattedLine("if ({0})", condition); } r.AddFormattedLine("yield return {0};", expression); r.AppendLine("}"); //r.AddFormattedLine("return list.{0}(each => {1});", method, expression); r.AppendLine("}"); r.AppendLine("}"); // Class return(r.ToString()); }
string GenerateSheetHeaderRow() { var r = new StringBuilder(); r.AppendLine(@"<Row>"); foreach (var c in Columns) { r.AppendFormat("<Cell ss:StyleID=\"{0}\">", c.HeaderStyle.GetStyleId()); r.AddFormattedLine("<Data ss:Type=\"String\">{0}</Data>", c.HeaderText.XmlEncode()); r.AppendLine("</Cell>"); } r.AppendLine("</Row>"); return(r.ToString()); }
public static string GenerateExcelXml(params ExcelExporter <T>[] sheets) { if (sheets == null || sheets.None()) { throw new ArgumentException("No excel sheets specified."); } if (sheets.GroupBy(s => s.DocumentName).Any(x => x.Count() > 1)) { throw new ArgumentException("Sheet names should be unique. At least 2 sheets in the provided list have the same DocumentName."); } var r = new StringBuilder(); r.AppendLine(@"<?xml version=""1.0""?><?mso-application progid=""Excel.Sheet""?>"); r.AppendLine(@"<Workbook xmlns=""urn:schemas-microsoft-com:office:spreadsheet"""); r.AppendLine(@"xmlns:o=""urn:schemas-microsoft-com:office:office"""); r.AppendLine(@"xmlns:x=""urn:schemas-microsoft-com:office:excel"""); r.AppendLine(@"xmlns:ss=""urn:schemas-microsoft-com:office:spreadsheet"""); r.AppendLine(@"xmlns:html=""http://www.w3.org/TR/REC-html40"">"); // Generate styles r.AppendLine(GenerateStyles(sheets)); // NamedRanges: var namedRanges = sheets.SelectMany(s => s.Columns.OfType <ExcelDropDownColumn <T> >()).Distinct(c => c.EnumerationName); var nameRangeNodes = namedRanges.Select(c => "<NamedRange ss:Name=\"{0}\" ss:RefersTo=\"={0}!R1C1:R{1}C1\"/>".FormatWith(c.EnumerationName, c.PossibleValues.Length)); r.AddFormattedLine("<Names>{0}</Names>", nameRangeNodes.ToLinesString()); foreach (var sheet in sheets) { r.AppendLine(sheet.GenerateExcelWorksheet()); } r.AppendLine(namedRanges.Select(c => GenerateDropDownSourceSheet(c)).ToLinesString()); r.AppendLine(@"</Workbook>"); return(r.ToString()); }
string GenerateHeaderGroupings() { var groups = GetGroups(); if (groups.None()) { return(string.Empty); } var r = new StringBuilder(); r.AppendLine(@"<Row>"); foreach (var g in groups) { r.AddFormattedLine("<Cell ss:StyleID=\"{0}\" ss:MergeAcross=\"{1}\"><Data ss:Type=\"String\" >{2}</Data></Cell>", g.Style.GetStyleId(), g.Quantity, g.GroupName); } r.AppendLine("</Row>"); return(r.ToString()); }
string GenerateDataRows() { var r = new StringBuilder(); foreach (var row in DataRows) { r.AppendLine(@"<Row>"); for (int i = 0; i < row.Length; i++) { var cell = row[i]; var column = Columns[i]; var cellInfo = cell as ExcelCell; var value = cell?.ToString().OrEmpty(); if (column.DataType == "Link") { if (value.IsEmpty()) { r.AppendLine("<Cell><Data ss:Type=\"String\"></Data></Cell>"); } else { var parts = value.Split(LinkSeperator.ToCharArray().Single()); if (parts.Length != 2) { throw new Exception("Invalid Link value for ExporttoExcel: " + value); } r.AddFormattedLine("<Cell ss:StyleID=\"linkStyle\" ss:HRef=\"{0}\"><Data ss:Type=\"String\">{1}</Data></Cell>", parts[1].XmlEncode(), parts[0].XmlEncode()); } } else { if (value.HasValue()) { value = value.Remove("\r").XmlEncode().Replace("\n", " "); } r.Append("<Cell"); var style = cellInfo?.Style ?? column.RowStyle; r.AppendFormat(" ss:StyleID=\"{0}\"", style.GetStyleId()); if (column.Formula.HasValue()) { r.AppendFormat(" ss:Formula=\"{0}\"", column.Formula); } r.Append(">"); if (value.HasValue()) { r.AddFormattedLine("<Data ss:Type=\"{0}\">{1}</Data>", column.DataType, value); } r.AppendLine("</Cell>"); } } r.AppendLine("</Row>"); } return(r.ToString()); }
public HtmlString Render() { if (Paging.PageSize == null || Paging.TotalItemsCount == 0) { return(null); } if (ListPagination.DisplayForSinglePage == false && Paging.LastPage == 1) { return(null); } FindBoundaries(); var r = new StringBuilder(); if (ListPagination.WrapperCssClass.HasValue()) { r.AppendLine($"<div class=\"{ListPagination.WrapperCssClass}\">"); } r.AddFormattedLine("<ul{0}>", OliveMvcExtensions.ToHtmlAttributes(HtmlAttributes)); var isFirst = Paging.CurrentPage == 1; var isLast = Paging.CurrentPage == Paging.LastPage; // add first page control if (Paging.ShowFirstLastLinks) { AddPaginationControl(r, Paging.FirstText, "First page", Paging.CurrentPage == 1, 1); } // add previous page control if (Paging.ShowPreviousNextLinks) { var previousPage = isFirst ? 1 : Paging.CurrentPage - 1; AddPaginationControl(r, Paging.PreviousText, "Previous page", isFirst, previousPage); } for (var i = Start; i <= End; i++) { r.AppendFormat("<li {0}>", " class=\"active\"".OnlyWhen(i == Paging.CurrentPage)); r.AddFormattedLine("<a {0}>{1}</a></li>", GetLinkAttributes(i), i); } // add next page control if (Paging.ShowPreviousNextLinks) { var nextPage = isLast ? Paging.LastPage : Paging.CurrentPage + 1; AddPaginationControl(r, Paging.NextText, "Next page", isLast, nextPage); } // add last page control if (Paging.ShowFirstLastLinks) { AddPaginationControl(r, Paging.LastText, "Last page", isLast, Paging.LastPage); } r.AppendLine("</ul>"); r.AppendLineIf("</div>", ListPagination.WrapperCssClass.HasValue()); return(new HtmlString(r.ToString())); }