本文整理汇总了C#中Tree.AddValidationError方法的典型用法代码示例。如果您正苦于以下问题:C# Tree.AddValidationError方法的具体用法?C# Tree.AddValidationError怎么用?C# Tree.AddValidationError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tree
的用法示例。
在下文中一共展示了Tree.AddValidationError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildTree
public static Tree BuildTree(string treeId, XDocument document)
{
Tree tree = new Tree(treeId);
tree.BuildProcessContext = new BuildProcessContext();
tree.BuildResult = new BuildResult();
if (ValidateMarkup(tree, document) == false) return tree;
try
{
BuildAutoAttachmentPoints(tree, document);
BuildAllowedAttachmentPoints(tree, document);
XElement elementRootElement = document.Descendants(TreeMarkupConstants.Namespace + "ElementRoot").Single();
tree.RootTreeNode = BuildInnerTree(elementRootElement, null, tree);
if ((tree.AttachmentPoints.OfType<DataItemAttachmentPoint>().Any()) &&
(tree.RootTreeNode.ChildNodes.Any()))
{
// Only simple tree nodes allowed if data item attaching is done
tree.AddValidationError("", "TreeValidationError.DataAttachments.NoElementsAllowed");
}
if (tree.BuildResult.ValidationErrors.Count() == 0)
{
tree.RootTreeNode.Initialize();
}
}
catch (Exception ex)
{
tree.AddValidationError("", "TreeValidationError.Common.UnknownException", ex.Message);
}
return tree;
}
示例2: BuildDataFolderElementsTreeNode
private static TreeNode BuildDataFolderElementsTreeNode(XElement element, Tree tree)
{
XAttribute typeAttribute = element.Attribute("Type");
XAttribute fieldGroupingNameAttribute = element.Attribute("FieldGroupingName");
XAttribute dateFormatAttribute = element.Attribute("DateFormat");
XAttribute iconAttribute = element.Attribute("Icon");
XAttribute rangeAttribute = element.Attribute("Range");
XAttribute firstLetterOnlyAttribute = element.Attribute("FirstLetterOnly");
XAttribute showForeignItemsAttribute = element.Attribute("ShowForeignItems");
XAttribute leafDisplayAttribute = element.Attribute("Display");
XAttribute sortDirectionAttribute = element.Attribute("SortDirection");
if (fieldGroupingNameAttribute == null)
{
tree.AddValidationError(element, "TreeValidationError.Common.MissingAttribute", "FieldGroupingName");
return null;
}
Type interfaceType = null;
if (typeAttribute != null)
{
interfaceType = TypeManager.TryGetType(typeAttribute.Value);
if (interfaceType == null)
{
tree.AddValidationError(element, "TreeValidationError.Common.UnknownInterfaceType", typeAttribute.Value);
return null;
}
}
bool firstLetterOnly = false;
if (firstLetterOnlyAttribute != null)
{
if (!firstLetterOnlyAttribute.TryGetBoolValue(out firstLetterOnly))
{
tree.AddValidationError(element, "TreeValidationError.Common.WrongAttributeValue", "FirstLetterOnly");
}
}
LeafDisplayMode leafDisplay = LeafDisplayModeHelper.ParseDisplayMode(leafDisplayAttribute, tree);
SortDirection sortDirection = ParseSortDirection(sortDirectionAttribute, tree);
return new DataFolderElementsTreeNode
{
Tree = tree,
Id = tree.BuildProcessContext.CreateNewNodeId(),
InterfaceType = interfaceType,
Icon = FactoryHelper.GetIcon(iconAttribute.GetValueOrDefault(DefaultDataGroupingFolderResourceName)),
FieldName = fieldGroupingNameAttribute.Value,
DateFormat = dateFormatAttribute.GetValueOrDefault(null),
Range = rangeAttribute.GetValueOrDefault(null),
FirstLetterOnly = firstLetterOnly,
ShowForeignItems = showForeignItemsAttribute.GetValueOrDefault("true").ToLowerInvariant() == "true",
Display = leafDisplay,
SortDirection = sortDirection
};
}
示例3: ValidateMarkup
private static bool ValidateMarkup(Tree tree, XDocument document)
{
try
{
if (document.Root == null)
{
tree.AddValidationError("", "TreeValidationError.Markup.NoRootElement");
return false;
}
bool schemaValidationResult = true;
Action<object, ValidationEventArgs> onValidationError = (obj, args) =>
{
tree.AddValidationError("", "TreeValidationError.Markup.SchemaError", args.Message, args.Exception.LineNumber, args.Exception.LinePosition);
schemaValidationResult = false;
};
XDocument schemaDocument = XDocumentUtils.Load(Path.Combine(PathUtil.Resolve("~/Composite/schemas/Trees"), "Tree.xsd"));
IEnumerable<XElement> elements = schemaDocument.Descendants((XNamespace)"http://www.w3.org/2001/XMLSchema" + "import").ToList();
foreach (XElement element in elements)
{
element.Remove();
}
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
xmlReaderSettings.ValidationType = ValidationType.Schema;
using (XmlReader schemaReader = schemaDocument.CreateReader())
{
xmlReaderSettings.Schemas.Add(null, schemaReader);
}
xmlReaderSettings.Schemas.AddFromPath(null, Path.Combine(PathUtil.Resolve("~/Composite/schemas/Functions"), "Function.xsd"));
//xmlReaderSettings.Schemas.AddFromPath(null, Path.Combine(PathUtil.Resolve("~/Composite/schemas/Trees"), "Tree.xsd"));
xmlReaderSettings.ValidationEventHandler += new ValidationEventHandler(onValidationError);
xmlReaderSettings.ValidationFlags = XmlSchemaValidationFlags.ProcessSchemaLocation | XmlSchemaValidationFlags.ReportValidationWarnings;
XmlReader xmlReader = XmlReader.Create(new StringReader(document.ToString()), xmlReaderSettings);
while (xmlReader.Read()) ;
if (schemaValidationResult == false)
{
return false;
}
}
catch (Exception ex)
{
tree.AddValidationError("", "TreeValidationError.Common.UnknownException", ex.Message);
return false;
}
return true;
}
示例4: CreateOrderByNode
public static OrderByNode CreateOrderByNode(XElement element, Tree tree)
{
if (element.Name == TreeMarkupConstants.Namespace + "Field")
{
XAttribute nameAttribute = element.Attribute("FieldName");
XAttribute directionAttribute = element.Attribute("Direction");
if (nameAttribute == null)
{
tree.AddValidationError(element.GetXPath(), "TreeValidationError.Common.MissingAttribute", "FieldName");
return null;
}
return new FieldOrderByNode
{
XPath = element.GetXPath(),
FieldName = nameAttribute.Value,
Direction = directionAttribute.GetValueOrDefault("ascending")
};
}
else
{
throw new InvalidOperationException(string.Format("OrderBy node {0} not supported", element.Name));
}
}
示例5: CreateTreeNode
public static TreeNode CreateTreeNode(XElement element, Tree tree)
{
if (element.Name == TreeMarkupConstants.Namespace + "ElementRoot")
{
return BuildRootTreeNode(element, tree);
}
if (element.Name == TreeMarkupConstants.Namespace + "Element")
{
return BuildSimpleElementTreeNode(element, tree);
}
if (element.Name == TreeMarkupConstants.Namespace + "FunctionElementGenerator")
{
return BuildFunctionElementGeneratorTreeNode(element, tree);
}
if (element.Name == TreeMarkupConstants.Namespace + "DataElements")
{
return BuildDataElementsTreeNode(element, tree);
}
if (element.Name == TreeMarkupConstants.Namespace + "DataFolderElements")
{
return BuildDataFolderElementsTreeNode(element, tree);
}
tree.AddValidationError(element, "TreeValidationError.Common.UnknownElement", element.Name);
return null;
}
示例6: ParseDisplayMode
/// <exclude />
public static LeafDisplayMode ParseDisplayMode(XAttribute attribute, Tree tree)
{
if (attribute != null)
{
LeafDisplayMode parsedValue;
if (Enum.TryParse(attribute.Value, out parsedValue))
{
return parsedValue;
}
tree.AddValidationError(attribute.GetXPath(), "TreeValidationError.Common.WrongAttributeValue", attribute.Value);
}
return LeafDisplayMode.Lazy;
}
示例7: BuildAllowedAttachmentPoints
private static void BuildAllowedAttachmentPoints(Tree tree, XDocument document)
{
XElement element = document.Root.Elements(TreeMarkupConstants.Namespace + "ElementStructure.AllowedAttachments").SingleOrDefault();
if (element == null) return;
XAttribute applicationNameAttribute = element.Attribute("ApplicationName");
if (applicationNameAttribute != null)
{
tree.AllowedAttachmentApplicationName = applicationNameAttribute.Value;
}
else
{
tree.AddValidationError(element.GetXPath(), "TreeValidationError.Common.MissingAttribute", "ApplicationName");
return;
}
//This is just illustrating the generic way of handling these things. Please leave this commet /MRJ
//IEnumerable<INamedAttachmentPoint> namedAttachmentPoints = BuildNamedAttachmentPoints(tree, element, () => new NamedPossibleAttachmentPoint());
//tree.PossibleAttachmentPoints.AddRange(namedAttachmentPoints.Cast<IPossibleAttachmentPoint>());
IEnumerable<IDataItemAttachmentPoint> namedAttachmentPoints = BuildDataItemPoints(tree, element, () => new DataItemPossibleAttachmentPoint());
tree.PossibleAttachmentPoints.AddRange(namedAttachmentPoints.Cast<IPossibleAttachmentPoint>());
}
示例8: BuildRootTreeNode
private static TreeNode BuildRootTreeNode(XElement element, Tree tree)
{
XAttribute shareRootElementByIdAttribute = element.Attribute("ShareRootElementById");
if (shareRootElementByIdAttribute != null)
{
tree.ShareRootElementById = (bool) shareRootElementByIdAttribute;
if (tree.ShareRootElementById)
{
int count = tree.AttachmentPoints.OfType<NamedAttachmentPoint>().Count();
if (count != 1 || tree.AttachmentPoints.Count > count)
{
tree.AddValidationError(shareRootElementByIdAttribute, "TreeValidationError.ElementRoot.ShareRootElementByIdNotAllowed");
}
}
}
return new RootTreeNode
{
Tree = tree,
Id = tree.BuildProcessContext.CreateNewNodeId()
};
}
示例9: BuildSimpleElementTreeNode
private static TreeNode BuildSimpleElementTreeNode(XElement element, Tree tree)
{
XAttribute idAttribute = element.Attribute("Id");
XAttribute labelAttribute = element.Attribute("Label");
XAttribute toolTipAttribute = element.Attribute("ToolTip");
XAttribute iconAttribute = element.Attribute("Icon");
XAttribute openedIconAttribute = element.Attribute("OpenedIcon");
if (idAttribute == null)
{
tree.AddValidationError(element, "TreeValidationError.Common.MissingAttribute", "Id");
return null;
}
if (idAttribute.Value == "" || idAttribute.Value == "RootTreeNode" || idAttribute.Value.StartsWith("NodeAutoId_"))
{
tree.AddValidationError(idAttribute, "TreeValidationError.SimpleElement.WrongIdValue");
}
else if (tree.BuildProcessContext.AlreadyUsed(idAttribute.Value))
{
tree.AddValidationError(idAttribute, "TreeValidationError.SimpleElement.AlreadyUsedId", idAttribute.Value);
}
else
{
tree.BuildProcessContext.AddUsedId(idAttribute.Value);
}
if (labelAttribute == null)
{
tree.AddValidationError(element, "TreeValidationError.Common.MissingAttribute", "Label");
return null;
}
ResourceHandle icon = FactoryHelper.GetIcon(iconAttribute.GetValueOrDefault(DefaultFolderResourceName));
ResourceHandle openedIcon =
FactoryHelper.GetIcon(openedIconAttribute.GetValueOrDefault(DefaultOpenedFolderResourceName));
if (iconAttribute != null && openedIconAttribute == null)
{
openedIcon = icon;
}
return new SimpleElementTreeNode
{
Tree = tree,
Id = idAttribute.Value,
Label = labelAttribute.Value,
ToolTip = toolTipAttribute.GetValueOrDefault(labelAttribute.Value),
Icon = icon,
OpenIcon = openedIcon
};
}
示例10: BuildFunctionElementGeneratorTreeNode
private static TreeNode BuildFunctionElementGeneratorTreeNode(XElement element, Tree tree)
{
XAttribute labelAttribute = element.Attribute("Label");
XAttribute toolTipAttribute = element.Attribute("ToolTip");
XAttribute iconAttribute = element.Attribute("Icon");
XElement functionMarkupContainerElement = element.Element(TreeMarkupConstants.Namespace + "FunctionMarkup");
if (functionMarkupContainerElement == null)
{
//MRJ: DSLTree: FunctionElementGeneratorTreeNode: Validation error
}
XElement functionMarkupElement = functionMarkupContainerElement.Element((XNamespace) FunctionTreeConfigurationNames.NamespaceName +
FunctionTreeConfigurationNames.FunctionTagName);
if (functionMarkupElement == null)
{
//MRJ: DSLTree: FunctionElementGeneratorTreeNode: Validation error
}
if (labelAttribute == null)
{
tree.AddValidationError(element, "TreeValidationError.Common.MissingAttribute", "Label");
return null;
}
return new FunctionElementGeneratorTreeNode
{
Tree = tree,
Id = tree.BuildProcessContext.CreateNewNodeId(),
FunctionMarkup = functionMarkupElement,
Label = labelAttribute.Value,
ToolTip = toolTipAttribute.GetValueOrDefault(labelAttribute.Value),
Icon = FactoryHelper.GetIcon(iconAttribute.GetValueOrDefault(DefaultFolderResourceName))
};
}
示例11: BuildDataElementsTreeNode
private static TreeNode BuildDataElementsTreeNode(XElement element, Tree tree)
{
XAttribute typeAttribute = element.Attribute("Type");
XAttribute labelAttribute = element.Attribute("Label");
XAttribute toolTipAttribute = element.Attribute("ToolTip");
XAttribute iconAttribute = element.Attribute("Icon");
XAttribute openedIconAttribute = element.Attribute("OpenedIcon");
XAttribute showForeignItemsAttribute = element.Attribute("ShowForeignItems");
XAttribute leafDisplayAttribute = element.Attribute("Display");
if (typeAttribute == null)
{
tree.AddValidationError(element, "TreeValidationError.Common.MissingAttribute", "Type");
return null;
}
Type interfaceType = TypeManager.TryGetType(typeAttribute.Value);
if (interfaceType == null)
{
tree.AddValidationError(element, "TreeValidationError.Common.UnknownInterfaceType",
typeAttribute.Value);
return null;
}
LeafDisplayMode leafDisplay = LeafDisplayModeHelper.ParseDisplayMode(leafDisplayAttribute, tree);
ResourceHandle icon = null;
if (iconAttribute != null) icon = FactoryHelper.GetIcon(iconAttribute.Value);
ResourceHandle openedIcon = null;
if (icon != null && openedIconAttribute == null) openedIcon = icon;
else if (openedIconAttribute != null) openedIcon = FactoryHelper.GetIcon(openedIconAttribute.Value);
var dataElementsTreeNode = new DataElementsTreeNode
{
Tree = tree,
Id = tree.BuildProcessContext.CreateNewNodeId(),
InterfaceType = interfaceType,
Label = labelAttribute.GetValueOrDefault(null),
ToolTip = toolTipAttribute.GetValueOrDefault(null),
Icon = icon,
OpenedIcon = openedIcon,
ShowForeignItems = showForeignItemsAttribute.GetValueOrDefault("true").ToLowerInvariant() == "true",
Display = leafDisplay
};
List<TreeNode> treeNodes;
if (tree.BuildProcessContext.DataInteraceToTreeNodes.TryGetValue(interfaceType, out treeNodes) == false)
{
treeNodes = new List<TreeNode>();
tree.BuildProcessContext.DataInteraceToTreeNodes.Add(interfaceType, treeNodes);
}
treeNodes.Add(dataElementsTreeNode);
return dataElementsTreeNode;
}
示例12: ParseSortDirection
public static SortDirection ParseSortDirection(XAttribute attribute, Tree tree)
{
if (attribute != null)
{
SortDirection parsedValue;
if (Enum.TryParse(attribute.Value, out parsedValue))
{
return parsedValue;
}
tree.AddValidationError(attribute, "TreeValidationError.Common.WrongAttributeValue", attribute.Value);
}
return SortDirection.Ascending;
}
示例13: CreateFilterNode
public static FilterNode CreateFilterNode(XElement filterElement, Tree tree)
{
if (filterElement.Name == TreeMarkupConstants.Namespace + "ParentIdFilter")
{
XAttribute parentTypeAttribute = filterElement.Attribute("ParentType");
XAttribute referenceFieldNameAttribute = filterElement.Attribute("ReferenceFieldName");
if (parentTypeAttribute == null)
{
tree.AddValidationError(filterElement.GetXPath(), "TreeValidationError.Common.MissingAttribute", "ParentType");
return null;
}
if (referenceFieldNameAttribute == null)
{
tree.AddValidationError(filterElement.GetXPath(), "TreeValidationError.Common.MissingAttribute", "ReferenceFieldName");
return null;
}
Type parentInterfaceType = TypeManager.TryGetType(parentTypeAttribute.Value);
if (parentInterfaceType == null)
{
tree.AddValidationError(filterElement.GetXPath(), "TreeValidationError.Common.UnknownInterfaceType", parentTypeAttribute.Value);
return null;
}
return new ParentIdFilterNode
{
XPath = filterElement.GetXPath(),
Id = tree.BuildProcessContext.FilterIdCounter++,
ParentFilterType = parentInterfaceType,
ReferenceFieldName = referenceFieldNameAttribute.Value
};
}
if (filterElement.Name == TreeMarkupConstants.Namespace + "FieldFilter")
{
XAttribute fieldNameAttribute = filterElement.Attribute("FieldName");
XAttribute fieldValueAttribute = filterElement.Attribute("FieldValue");
XAttribute operatorValueAttribute = filterElement.Attribute("Operator");
if (fieldNameAttribute == null)
{
tree.AddValidationError(filterElement.GetXPath(), "TreeValidationError.Common.MissingAttribute", "FieldName");
return null;
}
if (fieldValueAttribute == null)
{
tree.AddValidationError(filterElement.GetXPath(), "TreeValidationError.Common.MissingAttribute", "FieldValue");
return null;
}
FieldFilterNodeOperator filterOperator;
string operatorValue = operatorValueAttribute.GetValueOrDefault("equal");
switch (operatorValue)
{
case "equal":
filterOperator = FieldFilterNodeOperator.Equal;
break;
case "inequal":
filterOperator = FieldFilterNodeOperator.Inequal;
break;
case "lesser":
filterOperator = FieldFilterNodeOperator.Lesser;
break;
case "greater":
filterOperator = FieldFilterNodeOperator.Greater;
break;
case "lesserequal":
filterOperator = FieldFilterNodeOperator.LesserEqual;
break;
case "greaterequal":
filterOperator = FieldFilterNodeOperator.GreaterEqual;
break;
default:
tree.AddValidationError(filterElement.GetXPath(), "TreeValidationError.FieldFilter.UnknownOperatorName", operatorValue);
return null;
}
return new FieldFilterNode
{
XPath = filterElement.GetXPath(),
Id = tree.BuildProcessContext.FilterIdCounter++,
FieldName = fieldNameAttribute.Value,
FieldValue = fieldValueAttribute.Value,
Operator = filterOperator
};
}
if (filterElement.Name == TreeMarkupConstants.Namespace + "FunctionFilter")
{
XElement functionMarkupElement = filterElement.Element((XNamespace)FunctionTreeConfigurationNames.NamespaceName + FunctionTreeConfigurationNames.FunctionTagName);
//.........这里部分代码省略.........
示例14: GetActionLocation
public static ActionLocation GetActionLocation(XElement element, Tree tree, ActionLocation defaultActionLocation = null)
{
XAttribute locationAttribute = element.Attribute("Location");
if (locationAttribute == null) return ActionLocation.OtherPrimaryActionLocation;
switch (locationAttribute.Value)
{
case "Add":
return ActionLocation.AddPrimaryActionLocation;
case "Edit":
return ActionLocation.EditPrimaryActionLocation;
case "Delete":
return ActionLocation.DeletePrimaryActionLocation;
case "Other":
return ActionLocation.OtherPrimaryActionLocation;
default:
if (defaultActionLocation != null) return defaultActionLocation;
tree.AddValidationError(element.GetXPath(), "TreeValidationError.Common.WrongLocationValue", locationAttribute.Value);
return ActionLocation.OtherPrimaryActionLocation;
}
}
示例15: BuildNamedAttachmentPoints
private static IEnumerable<INamedAttachmentPoint> BuildNamedAttachmentPoints(Tree tree, XElement containerElement, Func<INamedAttachmentPoint> namedAttachmentPointFactory)
{
IEnumerable<XElement> namedElements = containerElement.Elements(TreeMarkupConstants.Namespace + "NamedParent");
foreach (XElement namedElement in namedElements)
{
XAttribute nameAttribute = namedElement.Attribute("Name");
if (nameAttribute == null)
{
tree.AddValidationError(namedElement.GetXPath(), "TreeValidationError.Common.MissingAttribute", "Name");
yield break;
}
AttachingPoint attachingPoint;
switch (nameAttribute.Value)
{
case "PerspectivesRoot":
attachingPoint = AttachingPoint.PerspectivesRoot;
break;
case "Content":
attachingPoint = AttachingPoint.ContentPerspective;
break;
case "Content.WebsiteItems":
attachingPoint = AttachingPoint.ContentPerspectiveWebsiteItems;
break;
case "Data":
attachingPoint = AttachingPoint.DataPerspective;
break;
case "Layout":
attachingPoint = AttachingPoint.DesignPerspective;
break;
case "Media":
attachingPoint = AttachingPoint.MediaPerspective;
break;
case "Function":
attachingPoint = AttachingPoint.FunctionPerspective;
break;
case "System":
attachingPoint = AttachingPoint.SystemPerspective;
break;
case null:
case "":
tree.AddValidationError(nameAttribute.GetXPath(), "TreeValidationError.AutoAttachments.UnknownAttachmentPoint", nameAttribute.Value);
attachingPoint = null;
break;
default:
attachingPoint = AttachingPoint.VirtualElementAttachingPoint(nameAttribute.Value);
break;
}
if (attachingPoint == null) yield break;
INamedAttachmentPoint namedAttachmentPoint = namedAttachmentPointFactory();
namedAttachmentPoint.AttachingPoint = attachingPoint;
namedAttachmentPoint.Position = GetPosition(tree, namedElement);
yield return namedAttachmentPoint;
}
}