本文整理汇总了C#中System.Web.UI.HtmlTextWriter.AddTag方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlTextWriter.AddTag方法的具体用法?C# HtmlTextWriter.AddTag怎么用?C# HtmlTextWriter.AddTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.HtmlTextWriter
的用法示例。
在下文中一共展示了HtmlTextWriter.AddTag方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HtmlPage
public HtmlPage(string pageTitle = "NUnitGo Report", string styleFullPath = "")
{
var strWr = new StringWriter();
using (var writer = new HtmlTextWriter(strWr))
{
//writer.RenderBeginTag(HtmlTextWriterTag.Html);
writer.Write("<!DOCTYPE html>");
writer.Write(Environment.NewLine);
writer.RenderBeginTag(HtmlTextWriterTag.Head);
writer.AddTag(HtmlTextWriterTag.Meta, new Dictionary<string, string>
{
{"http-equiv", "X-UA-Compatible"},
{"content", @"IE=edge"},
{"charset", "utf-8"}
});
writer.AddTag(HtmlTextWriterTag.Title, pageTitle);
writer.AddTag(HtmlTextWriterTag.Style, new Dictionary<HtmlTextWriterAttribute, string>
{
{HtmlTextWriterAttribute.Type, @"text/css"}
});
writer.AddTag(HtmlTextWriterTag.Link, new Dictionary<HtmlTextWriterAttribute, string>
{
{HtmlTextWriterAttribute.Rel, @"stylesheet"},
{HtmlTextWriterAttribute.Type, @"text/css"},
{HtmlTextWriterAttribute.Href, styleFullPath.Equals("") ? Output.Files.ReportStyleFile : styleFullPath}
});
writer.RenderEndTag(); //HEAD
writer.AddTag(HtmlTextWriterTag.Body);
writer.Write(Environment.NewLine);
writer.AddTag("footer");
//writer.RenderEndTag(); //HTML
writer.Write(Environment.NewLine);
writer.Write("</html>");
writer.Write(Environment.NewLine);
}
_page = strWr.ToString();
}
示例2: Tooltip
public Tooltip(string tooltipText, string innerText, string backgroundColor, string id, double width, string href = "")
{
Style = GetStyle();
var strWr = new StringWriter();
using (var writer = new HtmlTextWriter(strWr))
{
writer.AddAttribute("data-tooltip", tooltipText);
writer.AddAttribute(HtmlTextWriterAttribute.Class, "tooltip");
writer.AddAttribute(HtmlTextWriterAttribute.Id, id);
writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, backgroundColor);
writer.AddStyleAttribute(HtmlTextWriterStyle.Width, width.ToString("00.000", CultureInfo.InvariantCulture) + @"%");
writer.RenderBeginTag(HtmlTextWriterTag.Div);
if (!href.Equals(""))
{
var button = new OpenButton("", href, backgroundColor);
writer.Write(button.ButtonHtml);
}
writer.AddStyleAttribute(HtmlTextWriterStyle.Display, "inline-block");
writer.AddStyleAttribute(HtmlTextWriterStyle.Overflow, "hidden");
writer.AddAttribute(HtmlTextWriterAttribute.Id, "tooltip-item-inner-text");
writer.RenderBeginTag(HtmlTextWriterTag.A);
if (innerText.Contains(Environment.NewLine))
{
var lines = innerText.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
foreach (var line in lines)
{
writer.Write(line);
writer.AddTag(HtmlTextWriterTag.Br);
}
}
else
{
writer.Write(innerText);
}
writer.RenderEndTag(); //A
writer.RenderEndTag(); //DIV
}
HtmlCode = strWr.ToString();
}
示例3: GetMailBody
public static string GetMailBody(NunitGoTest nunitGoTest, bool addLinks,
bool isEventEmail = false, string eventName = "", TestEvent previousRunEvent = null)
{
var strWr = new StringWriter();
using (var writer = new HtmlTextWriter(strWr))
{
writer.Write("<!DOCTYPE html>");
writer.Write(Environment.NewLine);
writer.RenderBeginTag(HtmlTextWriterTag.Head);
writer.Tag(HtmlTextWriterTag.Meta, new Dictionary<string, string>
{
{"http-equiv", "X-UA-Compatible"},
{"content", @"IE=edge"},
{"charset", "utf-8"}
});
writer.Tag(HtmlTextWriterTag.Title, "NUnitGo Email");
writer.Tag(HtmlTextWriterTag.Style, new Dictionary<HtmlTextWriterAttribute, string>
{
{HtmlTextWriterAttribute.Type, @"text/css"}
});
writer.Tag(HtmlTextWriterTag.Link, new Dictionary<HtmlTextWriterAttribute, string>
{
{HtmlTextWriterAttribute.Rel, @"stylesheet"},
{HtmlTextWriterAttribute.Type, @"text/css"}
});
writer.RenderEndTag(); //HEAD
writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, Colors.White);
writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "10px");
writer.AddStyleAttribute("border", "10px solid " + Colors.TestBorderColor);
writer.AddStyleAttribute(HtmlTextWriterStyle.Margin, "0px");
writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "100%");
writer.AddStyleAttribute(HtmlTextWriterStyle.FontFamily, "Tahoma,Verdana,Segoe,sans-serif");
writer.RenderBeginTag(HtmlTextWriterTag.Body);
writer.AddStyleAttribute("box-sizing", "border-box");
writer.AddStyleAttribute(HtmlTextWriterStyle.Overflow, "auto");
writer.AddStyleAttribute(HtmlTextWriterStyle.Top, "0%");
writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "100%");
writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "10px");
writer.AddAttribute(HtmlTextWriterAttribute.Class, "test-window");
writer.AddAttribute(HtmlTextWriterAttribute.Title, "Test");
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "10px");
writer.AddAttribute(HtmlTextWriterAttribute.Id, nunitGoTest.Guid.ToString());
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.RenderBeginTag(HtmlTextWriterTag.P);
writer.AddTag(HtmlTextWriterTag.B, "Test full name: ");
writer.Write(nunitGoTest.FullName);
writer.RenderEndTag(); //P
writer.RenderBeginTag(HtmlTextWriterTag.P);
writer.AddTag(HtmlTextWriterTag.B, "Test name: ");
writer.Write(nunitGoTest.Name);
writer.RenderEndTag(); //P
if (isEventEmail && previousRunEvent != null)
{
var currentEvent = nunitGoTest.Events.First(x => x.Name.Equals(eventName));
writer.RenderBeginTag(HtmlTextWriterTag.P);
writer.AddTag(HtmlTextWriterTag.B, "Event name: ");
writer.Write(currentEvent.Name);
writer.RenderEndTag(); //P
writer.RenderBeginTag(HtmlTextWriterTag.P);
writer.AddTag(HtmlTextWriterTag.B, string.Format("Current duration (event finished at {0}): ", currentEvent.Finished));
writer.Write(TimeSpan.FromSeconds(currentEvent.Duration).ToString(@"hh\:mm\:ss\:fff"));
writer.RenderEndTag(); //P
writer.RenderBeginTag(HtmlTextWriterTag.P);
writer.AddTag(HtmlTextWriterTag.B, string.Format("Previous duration (event finished at {0}): ", previousRunEvent.Finished));
writer.Write(TimeSpan.FromSeconds(previousRunEvent.Duration).ToString(@"hh\:mm\:ss\:fff"));
writer.RenderEndTag(); //P
writer.RenderBeginTag(HtmlTextWriterTag.P);
writer.AddTag(HtmlTextWriterTag.B, "Difference: ");
writer.Write(TimeSpan.FromSeconds(currentEvent.Duration - previousRunEvent.Duration).ToString(@"hh\:mm\:ss\:fff"));
writer.RenderEndTag(); //P
}
writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, nunitGoTest.GetColor());
writer.RenderBeginTag(HtmlTextWriterTag.P);
writer.RenderBeginTag(HtmlTextWriterTag.B);
writer.Write("Test result: ");
writer.RenderEndTag(); //B
writer.Write(nunitGoTest.Result);
writer.RenderEndTag(); //P
writer.RenderBeginTag(HtmlTextWriterTag.P);
writer.AddTag(HtmlTextWriterTag.B, "Test duration: ");
writer.Write(TimeSpan.FromSeconds(nunitGoTest.TestDuration).ToString(@"hh\:mm\:ss\:fff"));
writer.RenderEndTag(); //P
writer.RenderBeginTag(HtmlTextWriterTag.P);
writer.AddTag(HtmlTextWriterTag.B, "Time period: ");
var start = nunitGoTest.DateTimeStart.ToString("dd.MM.yy HH:mm:ss.fff");
var end = nunitGoTest.DateTimeFinish.ToString("dd.MM.yy HH:mm:ss.fff");
writer.Write(start + " - " + end);
writer.RenderEndTag(); //P
writer.RenderBeginTag(HtmlTextWriterTag.P);
//.........这里部分代码省略.........
示例4: NunitTestHtml
public NunitTestHtml(NunitGoTest nunitGoTest)
{
ModalWindowsHtml = "";
Style = GetStyle();
BackgroundColor = nunitGoTest.GetBackgroundColor();
var strWr = new StringWriter();
using (var writer = new HtmlTextWriter(strWr))
{
writer.AddStyleAttribute(HtmlTextWriterStyle.Left, "0%");
writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%");
writer.AddAttribute(HtmlTextWriterAttribute.Class, "test-window");
writer.AddAttribute(HtmlTextWriterAttribute.Title, Title);
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.AddAttribute(HtmlTextWriterAttribute.Id, Id);
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.AddStyleAttribute(HtmlTextWriterStyle.Margin, "1% 2% 3% 97%");
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.Write(new CloseButton("Back", "./../../" + Output.Files.TestListFile).ButtonHtml);
writer.RenderEndTag(); //DIV
writer.RenderBeginTag(HtmlTextWriterTag.P);
writer.AddTag(HtmlTextWriterTag.B, "Test full name: ");
writer.Write(nunitGoTest.FullName);
writer.RenderEndTag(); //P
writer.RenderBeginTag(HtmlTextWriterTag.P);
writer.AddTag(HtmlTextWriterTag.B, "Test name: ");
writer.Write(nunitGoTest.Name);
writer.RenderEndTag(); //P
writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, nunitGoTest.GetBackgroundColor());
writer.RenderBeginTag(HtmlTextWriterTag.P);
writer.RenderBeginTag(HtmlTextWriterTag.B);
writer.Write("Test result: ");
writer.RenderEndTag(); //B
writer.Write(nunitGoTest.Result);
writer.RenderEndTag(); //P
writer.RenderBeginTag(HtmlTextWriterTag.P);
writer.AddTag(HtmlTextWriterTag.B, "Test duration: ");
writer.Write(nunitGoTest.TestDuration);
writer.RenderEndTag(); //P
writer.RenderBeginTag(HtmlTextWriterTag.P);
writer.AddTag(HtmlTextWriterTag.B, "Time period: ");
var start = nunitGoTest.DateTimeStart.ToString("dd.MM.yy HH:mm:ss.fff");
var end = nunitGoTest.DateTimeFinish.ToString("dd.MM.yy HH:mm:ss.fff");
writer.Write(start + " - " + end);
writer.RenderEndTag(); //P
writer.RenderBeginTag(HtmlTextWriterTag.P);
writer.AddTag(HtmlTextWriterTag.B, "Screenshots: ");
writer.Write(nunitGoTest.Screenshots.Count);
writer.RenderEndTag(); //P
var screens = nunitGoTest.Screenshots.OrderBy(x => x.Date);
foreach (var screenshot in screens)
{
writer.Write("Screenshot (Date: " + screenshot.Date.ToString("dd.MM.yy HH:mm:ss.fff") + "):");
writer.AddAttribute(HtmlTextWriterAttribute.Href, @"./../../Screenshots/" + screenshot.Name);
writer.RenderBeginTag(HtmlTextWriterTag.A);
writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%");
writer.AddAttribute(HtmlTextWriterAttribute.Src, @"./../../Screenshots/" + screenshot.Name);
writer.AddAttribute(HtmlTextWriterAttribute.Alt, screenshot.Name);
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();//IMG
writer.RenderEndTag();//A
}
if (nunitGoTest.HasOutput)
{
var openButton = new OpenButton("View full log", nunitGoTest.LogHref, Colors.OpenLogsButtonBackground);
writer.Write(openButton.ButtonHtml);
//writer.Write(GenerateHtmlView(nunitGoTest.AttachmentsPath + Structs.Outputs.Out));
}
if (!nunitGoTest.IsSuccess())
{
writer.RenderBeginTag(HtmlTextWriterTag.P);
writer.AddTag(HtmlTextWriterTag.B, "Stack trace: ");
writer.Write(GenerateTxtView(nunitGoTest.TestStackTrace));
writer.RenderEndTag(); //P
writer.RenderBeginTag(HtmlTextWriterTag.P);
writer.AddTag(HtmlTextWriterTag.B, "Message: ");
writer.Write(GenerateTxtView(nunitGoTest.TestMessage));
writer.RenderEndTag(); //P
}
writer.RenderBeginTag(HtmlTextWriterTag.P);
writer.AddTag(HtmlTextWriterTag.B, "Test guid: ");
writer.Write(nunitGoTest.Guid);
writer.RenderEndTag(); //P
writer.RenderEndTag(); //DIV
writer.RenderEndTag(); //DIV
//.........这里部分代码省略.........