本文整理汇总了C#中ValidationResult.AddMessage方法的典型用法代码示例。如果您正苦于以下问题:C# ValidationResult.AddMessage方法的具体用法?C# ValidationResult.AddMessage怎么用?C# ValidationResult.AddMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ValidationResult
的用法示例。
在下文中一共展示了ValidationResult.AddMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
ValidationResult result = new ValidationResult();
result.AddMessage(
new ValidationMessage
{
Severity = SeverityType.Error,
Message = "Sample error message 1."
}).AddMessage(
new ValidationMessage
{
Severity = SeverityType.Error,
Message = "Sample error message 2."
});
ValidationResult deepClone = result.DeepClone();
ValidationResult shallowClone = result.ShallowClone();;
}
示例2: ConvertXamlToHtml
/// <summary>
/// Converts an flow document to html string.
/// </summary>
/// <param name="flowDocument">Flow document.</param>
/// <param name="conversionResult">Conversion result to store error and warning messages. Can be null.</param>
/// <returns>
/// Well-formed xml string representing html equivalent for the input flow document.
/// </returns>
public static string ConvertXamlToHtml(FlowDocument flowDocument, ValidationResult conversionResult)
{
StringBuilder htmlStringBuilder = new StringBuilder();
System.IO.StringWriter stringWriter = null;
try
{
stringWriter = new System.IO.StringWriter(htmlStringBuilder);
using (XmlTextWriter htmlWriter = new XmlTextWriter(stringWriter))
{
try
{
foreach (Block block in flowDocument.Blocks)
{
AddBlock(block, htmlWriter, conversionResult);
}
}
catch (Exception ex)
{
if (conversionResult != null)
conversionResult.AddMessage(new ConversionMessage(ModelValidationViolationType.Error, "Conversion failed: " + ex.Message));
}
finally
{
stringWriter = null;
}
}
}
finally
{
if (stringWriter != null)
stringWriter.Dispose();
}
string htmlString = htmlStringBuilder.ToString();
return htmlString;
}
示例3: AddList
/// <summary>
/// Convert an flow document list into its html representation.
/// </summary>
/// <param name="list">Flow document list.</param>
/// <param name="htmlWriter">XmlTextWriter producing resulting html.</param>
/// <param name="conversionResult">Conversion result to store error and warning messages. Can be null.</param>
private static void AddList(List list, XmlTextWriter htmlWriter, ValidationResult conversionResult)
{
if (list.MarkerStyle == System.Windows.TextMarkerStyle.Disc)
htmlWriter.WriteStartElement("ul");
else if (list.MarkerStyle == System.Windows.TextMarkerStyle.Decimal)
htmlWriter.WriteStartElement("ol");
else
{
if (conversionResult != null)
conversionResult.AddMessage(new ConversionMessage(ModelValidationViolationType.Error, "Unknown list marker style: " + list.MarkerStyle.ToString()));
return;
}
// process list items
foreach (ListItem item in list.ListItems)
{
htmlWriter.WriteStartElement("li");
// process blocks
foreach (Block block in item.Blocks)
AddBlock(block, htmlWriter, conversionResult);
htmlWriter.WriteEndElement();
}
htmlWriter.WriteEndElement();
}
示例4: AddBlock
/// <summary>
/// Convert an flow document paragraph into its html representation.
/// </summary>
/// <param name="block">Flow document block.</param>
/// <param name="htmlWriter">XmlTextWriter producing resulting html.</param>
/// <param name="conversionResult">Conversion result to store error and warning messages. Can be null.</param>
/// <remarks>
/// List, Paragraph, Table are supported Block elements. Section is not supported.
/// </remarks>
private static void AddBlock(Block block, XmlTextWriter htmlWriter, ValidationResult conversionResult)
{
if (block is List)
{
AddList(block as List, htmlWriter, conversionResult);
}
else if (block is Paragraph)
{
AddParagraph(block as Paragraph, htmlWriter, conversionResult);
}
else if (block is Table)
{
AddTable(block as Table, htmlWriter, conversionResult);
}
else
{
// not supported: Section
if (conversionResult != null)
{
conversionResult.AddMessage(new ConversionMessage(ModelValidationViolationType.Warning,
"AddBlock: Unknown block element: " + block.ToString()));
}
}
}
示例5: AddInline
/// <summary>
/// Adds inline elements.
/// </summary>
/// <param name="xamlParentElement">Parent xaml element, to which new converted element will be added </param>
/// <param name="htmlNode"> Source html element subject to convert to xaml.</param>
/// <param name="sourceContext"></param>
/// <param name="conversionResult">Conversion result to store error and warning messages. Can be null.</param>
/// <param name="vModellDirectory">Directory of the VModell instance containing the element that has a html property.</param>
private static void AddInline(XmlElement xamlParentElement, HtmlNode htmlNode, List<HtmlNode> sourceContext, ValidationResult conversionResult, string vModellDirectory)
{
if (htmlNode.NodeType == HtmlNodeType.Comment)
{
AddCommentText(xamlParentElement, htmlNode, conversionResult, vModellDirectory);
}
else if (htmlNode.NodeType == HtmlNodeType.Text)
{
AddTextRun(xamlParentElement, htmlNode, conversionResult, vModellDirectory);
}
else if (htmlNode.NodeType == HtmlNodeType.Element)
{
// Identify element name
string htmlElementName = htmlNode.Name.ToLower();
// Put source element to the stack
sourceContext.Add(htmlNode);
switch (htmlElementName)
{
case "a":
AddHyperlink(xamlParentElement, htmlNode, sourceContext, conversionResult, vModellDirectory);
break;
case "img":
AddImage(xamlParentElement, htmlNode, sourceContext, conversionResult, vModellDirectory);
break;
case "b":
case "u":
case "i":
AddSpanOrRun(xamlParentElement, htmlNode, sourceContext, conversionResult, vModellDirectory);
break;
default:
if (conversionResult != null)
{
conversionResult.AddMessage(new ConversionMessage(ModelValidationViolationType.Warning,
"AddInline: Unknown inline element: " + htmlElementName));
}
break;
}
// Ignore all other elements non-(block/inline/image)
// Remove the element from the stack
System.Diagnostics.Debug.Assert(sourceContext.Count > 0 && sourceContext[sourceContext.Count - 1] == htmlNode);
sourceContext.RemoveAt(sourceContext.Count - 1);
}
}
示例6: AddListItem
/// <summary>
/// Converts htmlLIElement into Xaml ListItem element, and appends it to the parent xamlListElement
/// </summary>
/// <param name="xamlListElement">XmlElement representing Xaml List element to which the converted td/th should be added</param>
/// <param name="htmlLIElement">XmlElement representing Html li element to be converted</param>
/// <param name="sourceContext">Source context.</param>
/// <param name="conversionResult">Conversion result to store error and warning messages. Can be null.</param>
/// <param name="vModellDirectory">Directory of the VModell instance containing the element that has a html property.</param>
private static void AddListItem(XmlElement xamlListElement, HtmlNode htmlLIElement, List<HtmlNode> sourceContext, ValidationResult conversionResult, string vModellDirectory)
{
// Parameter validation
System.Diagnostics.Debug.Assert(xamlListElement != null);
System.Diagnostics.Debug.Assert(xamlListElement.LocalName == Xaml_List);
System.Diagnostics.Debug.Assert(htmlLIElement != null);
System.Diagnostics.Debug.Assert(htmlLIElement.Name.ToLower() == "li");
XmlElement xamlListItemElement = xamlListElement.OwnerDocument.CreateElement(null, HtmlToXamlConverter.Xaml_ListItem, HtmlToXamlConverter.Xaml_Namespace);
// We do not support any attributes on list items
foreach (HtmlAttribute attribute in htmlLIElement.Attributes)
{
if (conversionResult != null)
{
conversionResult.AddMessage(new ConversionMessage(ModelValidationViolationType.Warning,
"AddList: Unknown attribute " + attribute.Name + ":" + attribute.Value + " on list: " + htmlLIElement.Name));
}
}
// Process children of the ListItem
for (HtmlNode htmlChildNode = htmlLIElement.FirstChild; htmlChildNode != null; htmlChildNode = htmlChildNode != null ? htmlChildNode.NextSibling : null)
{
htmlChildNode = AddBlock(xamlListItemElement, htmlChildNode, sourceContext, conversionResult, vModellDirectory);
}
// Add resulting ListBoxItem to a xaml parent
xamlListElement.AppendChild(xamlListItemElement);
}
示例7: AddList
/// <summary>
/// Converts Html ul or ol element into Xaml list element. During conversion if the ul/ol element has any children
/// that are not li elements, they are ignored and not added to the list element
/// </summary>
/// <param name="xamlParentElement">XmlElement representing Xaml parent to which the converted element should be added</param>
/// <param name="htmlListElement">XmlElement representing Html ul/ol element to be converted</param>
/// <param name="sourceContext"></param>
/// <param name="conversionResult">Conversion result to store error and warning messages. Can be null.</param>
/// <param name="vModellDirectory">Directory of the VModell instance containing the element that has a html property.</param>
private static void AddList(XmlElement xamlParentElement, HtmlNode htmlListElement, List<HtmlNode> sourceContext, ValidationResult conversionResult, string vModellDirectory)
{
string htmlListElementName = htmlListElement.Name.ToLower();
// Create Xaml List element
XmlElement xamlListElement = xamlParentElement.OwnerDocument.CreateElement(null, HtmlToXamlConverter.Xaml_List, HtmlToXamlConverter.Xaml_Namespace);
// We do not support any attributes on lists
foreach (HtmlAttribute attribute in htmlListElement.Attributes)
{
if (conversionResult != null)
{
conversionResult.AddMessage(new ConversionMessage(ModelValidationViolationType.Warning,
"AddList: Unknown attribute " + attribute.Name + ":" + attribute.Value + " on list: " + htmlListElement.Name));
}
}
// Set default list markers
if (htmlListElementName == "ol")
{
// Ordered list
xamlListElement.SetAttribute(HtmlToXamlConverter.Xaml_List_MarkerStyle, Xaml_List_MarkerStyle_Decimal);
}
else
{
// Unordered list - all elements other than OL treated as unordered lists
xamlListElement.SetAttribute(HtmlToXamlConverter.Xaml_List_MarkerStyle, Xaml_List_MarkerStyle_Disc);
}
// Recurse into list subtree
for (HtmlNode htmlChildNode = htmlListElement.FirstChild; htmlChildNode != null; htmlChildNode = htmlChildNode.NextSibling)
{
if (htmlChildNode.NodeType == HtmlNodeType.Element && htmlChildNode.Name.ToLower() == "li")
{
sourceContext.Add(htmlChildNode);
AddListItem(xamlListElement, htmlChildNode, sourceContext, conversionResult, vModellDirectory);
System.Diagnostics.Debug.Assert(sourceContext.Count > 0 && sourceContext[sourceContext.Count - 1] == htmlChildNode);
sourceContext.RemoveAt(sourceContext.Count - 1);
}
else
{
// Not an li element. Add it to previous ListBoxItem
// We need to append the content to the end
// of a previous list item.
}
}
// Add the List element to xaml tree - if it is not empty
if (xamlListElement.HasChildNodes)
{
xamlParentElement.AppendChild(xamlListElement);
}
}
示例8: AddImage
/// <summary>
/// Adds an image.
/// </summary>
/// <param name="xamlParentElement">XmlElement representing Xaml parent to which the converted element should be added</param>
/// <param name="htmlElement">Source html element subject to convert to xaml.</param>
/// <param name="sourceContext"></param>
/// <param name="conversionResult">Conversion result to store error and warning messages. Can be null.</param>
/// <param name="vModellDirectory">Directory of the VModell instance containing the element that has a html property.</param>
private static void AddImage(XmlElement xamlParentElement, HtmlNode htmlElement, List<HtmlNode> sourceContext, ValidationResult conversionResult, string vModellDirectory)
{
// Very simple processing for now
bool bFoundImage = false;
XmlElement xamlElement = xamlParentElement.OwnerDocument.CreateElement(null, HtmlToXamlConverter.Xaml_Image, HtmlToXamlConverter.Xaml_Namespace_Tum_VMX_Types);
string src = GetAttribute(htmlElement, "src");
if (src != null)
{
string filePath = vModellDirectory + "\\" + src;
if (System.IO.File.Exists(filePath))
{
try
{
// try to load image
System.Windows.Controls.Image image = new System.Windows.Controls.Image();
BitmapImage bimg = new BitmapImage();
bimg.BeginInit();
bimg.UriSource = new Uri(filePath, UriKind.Absolute);
bimg.EndInit();
image.Source = bimg;
string width = GetAttribute(htmlElement, "width");
string height = GetAttribute(htmlElement, "height");
if (width != null && height != null)
{
xamlElement.SetAttribute("MaxWidth", width);
xamlElement.SetAttribute("MaxHeight", height);
}
xamlElement.SetAttribute("Stretch", "Uniform");
XmlElement source = xamlElement.OwnerDocument.CreateElement(null, HtmlToXamlConverter.Xaml_Image_Source, HtmlToXamlConverter.Xaml_Namespace_Tum_VMX_Types);
XmlElement bmp = source.OwnerDocument.CreateElement(null, HtmlToXamlConverter.Xaml_Image_BitmapImage, HtmlToXamlConverter.Xaml_Namespace);
bmp.SetAttribute(HtmlToXamlConverter.Xaml_UriSource, filePath);
source.AppendChild(bmp);
xamlElement.AppendChild(source);
bFoundImage = true;
}
catch { }
}
}
if (!bFoundImage)
{
xamlElement.SetAttribute("Source", "pack://application:,,,/Tum.PDE.ToolFramework.Images;component/Ribbon/Save-32.png");
xamlElement.SetAttribute("Width", "32");
xamlElement.SetAttribute("Height", "32");
}
foreach (HtmlAttribute attribute in htmlElement.Attributes)
{
string name = attribute.Name.ToLower();
switch (name)
{
case "align":
xamlElement.SetAttribute(HtmlToXamlConverter.Xaml_HorizontalAlignment, attribute.Value);
break;
case "alt":
xamlElement.SetAttribute("AlternativeText", attribute.Value);
break;
case "id":
xamlElement.SetAttribute("Id", attribute.Value);
break;
case "src":
xamlElement.SetAttribute("RelativeSource", attribute.Value);
break;
case "width":
xamlElement.SetAttribute("ExportWidth", attribute.Value);
break;
case "height":
xamlElement.SetAttribute("ExportHeight", attribute.Value);
break;
default:
if (conversionResult != null)
{
conversionResult.AddMessage(new ConversionMessage(ModelValidationViolationType.Warning,
"AddImage: Unknown attribute on img: " + name));
}
break;
}
}
// Add the new element to the parent.
xamlParentElement.AppendChild(xamlElement);
//.........这里部分代码省略.........
示例9: AddTable
/// <summary>
/// Converts htmlTableElement to a Xaml Table element. Adds tbody elements if they are missing so
/// that a resulting Xaml Table element is properly formed.
/// </summary>
/// <param name="xamlParentElement">Parent xaml element to which a converted table must be added.</param>
/// <param name="htmlTableElement">XmlElement reprsenting the Html table element to be converted</param>
/// <param name="sourceContext">Source context.</param>
/// <param name="conversionResult">Conversion result to store error and warning messages. Can be null.</param>
/// <param name="vModellDirectory">Directory of the VModell instance containing the element that has a html property.</param>
private static void AddTable(XmlElement xamlParentElement, HtmlNode htmlTableElement, List<HtmlNode> sourceContext, ValidationResult conversionResult, string vModellDirectory)
{
// Parameter validation
System.Diagnostics.Debug.Assert(htmlTableElement.Name.ToLower() == "table");
System.Diagnostics.Debug.Assert(xamlParentElement != null);
// Create xamlTableElement
XmlElement xamlTableElement = xamlParentElement.OwnerDocument.CreateElement(null, HtmlToXamlConverter.Xaml_Table, HtmlToXamlConverter.Xaml_Namespace);
Hashtable inheritedProperties = new Hashtable();
// apply local table properties, only border is supported
foreach (HtmlAttribute attribute in htmlTableElement.Attributes)
{
string name = attribute.Name.ToLower();
switch (name)
{
case "border":
inheritedProperties.Add("border", attribute.Value);
//xamlTableElement.SetAttribute(Xaml_BorderThickness, ParseBorderThickness(attribute.Value, conversionResult));
//xamlTableElement.SetAttribute(Xaml_BorderBrush, "Black");
break;
default:
if (conversionResult != null)
{
conversionResult.AddMessage(new ConversionMessage(ModelValidationViolationType.Warning,
"AddTable: Unknown attribute on table: " + name));
}
break;
}
}
// Process table body - TR elements
HtmlNode htmlChildNode = htmlTableElement.FirstChild;
while (htmlChildNode != null)
{
string htmlChildName = htmlChildNode.Name.ToLower();
if (htmlChildName == "tr")
{
XmlElement xamlTableRowGroup = xamlTableElement.OwnerDocument.CreateElement(null, HtmlToXamlConverter.Xaml_TableRowGroup, HtmlToXamlConverter.Xaml_Namespace);
htmlChildNode = AddTableRows(xamlTableRowGroup, htmlChildNode, sourceContext, conversionResult, vModellDirectory, inheritedProperties);
//if (xamlTableRowGroup.HasChildNodes)
//{
xamlTableElement.AppendChild(xamlTableRowGroup);
//}
}
else
{
if (conversionResult != null)
{
if (String.IsNullOrWhiteSpace(htmlChildNode.InnerText) && htmlChildNode.NodeType == HtmlNodeType.Text)
{
// for some reason, there is always a white space behind the table/tr/td elements.. so dont react on that
// do we need a warning?
}
else
conversionResult.AddMessage(new ConversionMessage(ModelValidationViolationType.Warning,
"AddTable: Unknown child: " + htmlChildName + ":" + htmlChildNode.OuterHtml));
}
htmlChildNode = htmlChildNode.NextSibling;
}
}
//if (xamlTableElement.HasChildNodes)
//{
xamlParentElement.AppendChild(xamlTableElement);
//}
}
示例10: AddParagraph
/// <summary>
/// Generates Paragraph element from P.
/// </summary>
/// <param name="xamlParentElement">XmlElement representing Xaml parent to which the converted element should be added</param>
/// <param name="htmlElement">XmlElement representing Html element to be converted</param>
/// <param name="conversionResult">Conversion result to store error and warning messages. Can be null.</param>
/// <param name="vModellDirectory">Directory of the VModell instance containing the element that has a html property.</param>
/// <param name="sourceContext"></param>
private static void AddParagraph(XmlElement xamlParentElement, HtmlNode htmlElement, List<HtmlNode> sourceContext, ValidationResult conversionResult, string vModellDirectory)
{
// Create a XAML element corresponding to this html element
XmlElement xamlElement = xamlParentElement.OwnerDocument.CreateElement(null, HtmlToXamlConverter.Xaml_Paragraph, HtmlToXamlConverter.Xaml_Namespace);
// apply local paragraph properties
bool bAlignmentSet = false;
foreach (HtmlAttribute attribute in htmlElement.Attributes)
{
string name = attribute.Name.ToLower();
switch (name)
{
case "align":
xamlElement.SetAttribute(Xaml_TextAlignment, ParseTextAlignment(attribute.Value, conversionResult));
bAlignmentSet = true;
break;
case "style":
Hashtable cssAttributes = GetCssAttributes(attribute.Value);
// only margins are supported in inline style attribute
bool marginSet = false;
string marginTop = "0";
string marginBottom = "0";
string marginLeft = "0";
string marginRight = "0";
foreach (string cssName in cssAttributes.Keys)
{
string attributeValue = cssAttributes[cssName].ToString();
switch (cssName)
{
case "margin-top":
marginSet = true;
marginTop = attributeValue;
break;
case "margin-right":
marginSet = true;
marginRight = attributeValue;
break;
case "margin-bottom":
marginSet = true;
marginBottom = attributeValue;
break;
case "margin-left":
marginSet = true;
marginLeft = attributeValue;
break;
case "margin":
marginSet = true;
marginLeft = marginRight = marginTop = marginBottom = attributeValue;
break;
default:
if (conversionResult != null)
{
conversionResult.AddMessage(new ConversionMessage(ModelValidationViolationType.Warning,
"AddParagraph: Unknown style attribute on paragraph: " + attribute.Value));
}
break;
}
}
if (marginSet)
{
xamlElement.SetAttribute(Xaml_Margin, ParseMargin(marginLeft, marginRight, marginTop, marginBottom, conversionResult));
}
break;
default:
if (conversionResult != null)
{
conversionResult.AddMessage(new ConversionMessage(ModelValidationViolationType.Warning,
"AddParagraph: Unknown attribute on paragraph: " + name));
}
break;
}
}
if (!bAlignmentSet)
xamlElement.SetAttribute(Xaml_TextAlignment, "Left");
// Recurse into element subtree
for (HtmlNode htmlChildNode = htmlElement.FirstChild; htmlChildNode != null; htmlChildNode = htmlChildNode.NextSibling)
{
AddInline(xamlElement, htmlChildNode, sourceContext, conversionResult, vModellDirectory);
}
// Add the new element to the parent.
xamlParentElement.AppendChild(xamlElement);
}
示例11: ConvertHtmlToXaml
/// <summary>
/// Converts an html string into xaml string.
/// </summary>
/// <param name="htmlDocument">Html document.</param>
/// <param name="conversionResult">Conversion result to store error and warning messages. Can be null.</param>
/// <param name="vModellDirectory">Directory of the VModell instance containing the element that has a html property.</param>
/// <returns>
/// Well-formed xml string representing XAML equivalent for the input html.
/// </returns>
public static string ConvertHtmlToXaml(HtmlDocument htmlDocument, ValidationResult conversionResult, string vModellDirectory)
{
// Decide what name to use as a root
string rootElementName = HtmlToXamlConverter.Xaml_FlowDocument;
// Create an XmlDocument for generated xaml
XmlDocument xamlTree = new XmlDocument();
XmlElement xamlFlowDocumentElement = xamlTree.CreateElement(null, rootElementName, HtmlToXamlConverter.Xaml_Namespace_Tum_VMX_Types);
//xamlFlowDocumentElement.SetAttribute("TextOptions.TextFormattingMode", "Display");
try
{
// Source context is a stack of all elements - ancestors of a parentElement
List<HtmlNode> sourceContext = new List<HtmlNode>(10);
// convert root html element
AddBlock(xamlFlowDocumentElement, htmlDocument.DocumentNode, sourceContext, conversionResult, vModellDirectory);
// Return a string representing resulting Xaml
xamlFlowDocumentElement.SetAttribute("xml:space", "preserve");
}
catch (Exception ex)
{
if (conversionResult != null)
conversionResult.AddMessage(new ConversionMessage(ModelValidationViolationType.Error, "Conversion failed: " + ex.Message));
}
return xamlFlowDocumentElement.OuterXml;
}
示例12: ParseMarginValue
/// <summary>
/// Parses the html margin attribute given as a string.
/// </summary>
/// <param name="margin">Html margin attribute value.</param>
/// <param name="conversionResult">Conversion result to store error and warning messages. Can be null.</param>
/// <returns>
/// Returns the corresponding xaml margin value as a string.
/// Should the given value not be recognized, the default value ('0') is returned.</returns>
private static string ParseMarginValue(string margin, ValidationResult conversionResult)
{
string marginValue = margin.ToLower();
if (String.IsNullOrEmpty(marginValue))
{
if (conversionResult != null)
{
conversionResult.AddMessage(new ConversionMessage(ModelValidationViolationType.Warning,
"ParseMargin: Unknown value: " + margin));
}
}
else
{
int result;
if (Int32.TryParse(marginValue, out result))
{
return result.ToString();
}
else
{
if (conversionResult != null)
{
conversionResult.AddMessage(new ConversionMessage(ModelValidationViolationType.Warning,
"ParseMargin: Value is not a number: " + margin));
}
}
}
return "0";
}
示例13: ParseBorderThickness
/// <summary>
/// Parses the html border attribute given as a string.
/// </summary>
/// <param name="border">Html border attribute value.</param>
/// <param name="conversionResult">Conversion result to store error and warning messages. Can be null.</param>
/// <returns>
/// Returns the corresponding xaml border thickness value as a string.
/// Should the given value not be recognized, the default value ('0') is returned.</returns>
public static string ParseBorderThickness(string border, ValidationResult conversionResult)
{
string bordernValue = border.ToLower();
if (String.IsNullOrEmpty(bordernValue))
{
if (conversionResult != null)
{
conversionResult.AddMessage(new ConversionMessage(ModelValidationViolationType.Warning,
"ParseBorderThickness: Unknown value: " + border));
}
}
else
{
int result;
if (Int32.TryParse(bordernValue, out result))
{
return result.ToString();
}
else
{
if (conversionResult != null)
{
conversionResult.AddMessage(new ConversionMessage(ModelValidationViolationType.Warning,
"ParseBorderThickness: Value is not a number: " + border));
}
}
}
return "0";
}
示例14: ParseTextAlignment
/// <summary>
/// Parses the html align attribute given as a string.
/// </summary>
/// <param name="alignment">Html align attribute value.</param>
/// <param name="conversionResult">Conversion result to store error and warning messages. Can be null.</param>
/// <returns>
/// Returns the corresponding xaml alignment value as a string.
/// Should the given value not be recognized, the default value ('Left') is returned.</returns>
public static string ParseTextAlignment(string alignment, ValidationResult conversionResult)
{
string alignmentValue = alignment.ToLower();
switch (alignmentValue)
{
case "left":
return "Left";
case "right":
return "Right";
case "center":
return "Center";
case "justify":
return "Justify";
default:
if (conversionResult != null)
{
conversionResult.AddMessage(new ConversionMessage(ModelValidationViolationType.Warning,
"ParseTextAlignment: Unknown value: " + alignment));
}
return "Left";
}
}
示例15: AddTable
/// <summary>
/// Convert an flow document table into its html representation.
/// </summary>
/// <param name="table">Flow document table.</param>
/// <param name="htmlWriter">XmlTextWriter producing resulting html.</param>
/// <param name="conversionResult">Conversion result to store error and warning messages. Can be null.</param>
private static void AddTable(Table table, XmlTextWriter htmlWriter, ValidationResult conversionResult)
{
htmlWriter.WriteStartElement("table");
/*
if (table.BorderThickness.Left == table.BorderThickness.Right &&
table.BorderThickness.Right == table.BorderThickness.Top &&
table.BorderThickness.Top == table.BorderThickness.Bottom)
{
if (table.BorderThickness.Left != 0)
htmlWriter.WriteAttributeString("border", table.BorderThickness.Left.ToString());
}
*/
double border = 0.0;
foreach (TableRowGroup group in table.RowGroups)
{
foreach (TableRow row in group.Rows)
{
foreach (TableCell cell in row.Cells)
{
if (cell.BorderThickness.Left == cell.BorderThickness.Right &&
cell.BorderThickness.Right == cell.BorderThickness.Top &&
cell.BorderThickness.Top == cell.BorderThickness.Bottom)
{
border = cell.BorderThickness.Left;
break;
}
}
if (border > 0)
break;
}
if (border > 0)
break;
}
if (border > 0)
// set border attribute
htmlWriter.WriteAttributeString("border", border.ToString());
foreach (TableRowGroup group in table.RowGroups)
{
foreach (TableRow row in group.Rows)
{
// add tr
htmlWriter.WriteStartElement("tr");
foreach (TableCell cell in row.Cells)
{
if (cell.BorderThickness.Left == cell.BorderThickness.Right &&
cell.BorderThickness.Right == cell.BorderThickness.Top &&
cell.BorderThickness.Top == cell.BorderThickness.Bottom)
{
if (cell.BorderThickness.Left != 0)
if (border != cell.BorderThickness.Left)
{
// error
if (conversionResult != null)
{
conversionResult.AddMessage(new ConversionMessage(ModelValidationViolationType.Warning,
"AddInline: All border values on table cells within one table need to be equal, ignoring newly found border value."));
}
}
}
// add td
htmlWriter.WriteStartElement("td");
// process blocks
foreach (Block block in cell.Blocks)
AddBlock(block, htmlWriter, conversionResult);
htmlWriter.WriteEndElement();
}
htmlWriter.WriteEndElement();
}
}
htmlWriter.WriteEndElement();
}