/// <summary> /// Reconstructs the condition object from the specified XML node and XML element name. /// </summary> /// <param name="node">The XML node containing the condition XML.</param> /// <param name="elementName">The name of the XML element containing the condition data.</param> /// <returns>The condition object.</returns> public static Condition ReadConditionXml(XmlNode node, string elementName) { if (node == null) { throw new ArgumentNullException("node"); } if (string.IsNullOrEmpty(elementName)) { throw new ArgumentNullException("elementName"); } var condition = new Condition(); if (XmlHelper.EvaluateSingleNode(node, elementName)) { XmlNode conditionNode = XmlHelper.SelectSingleNode(node, elementName); condition.Operator = (ConditionType)XmlHelper.ReadElementEnum(conditionNode, "operator", typeof(ConditionType), ConditionType.Unspecified); condition.ColumnName = XmlHelper.ReadElementString(conditionNode, "columnName", string.Empty); //database type condition.ColumnType = DatabaseType.UnknownType; if (XmlHelper.EvaluateSingleNode(conditionNode, "type")) { XmlNode typeNode = XmlHelper.SelectSingleNode(conditionNode, "type"); condition.ColumnType = DatabaseType.FromXml(typeNode); } if (DatabaseTypeHelper.IsTypeRelationshipField(condition.ColumnType)) { XmlNode argumentsNode = XmlHelper.SelectSingleNode(conditionNode, "arguments"); foreach (XmlNode argumentNode in argumentsNode.ChildNodes) { TypedValue argument = TypedValueHelper.FromXml(argumentNode); if (argument != null) { condition.Arguments.Add(argument); if (argument.Value != null) { string strArgumentValue = argument.Value.ToString(); long longArgumentValue; if (long.TryParse(strArgumentValue, out longArgumentValue)) { Resource resource = Model.Entity.Get <Resource>(new EntityRef(longArgumentValue)); ConvertArgumentValue(strArgumentValue, resource == null ? "Missing" : resource.Name); } } } } } else { XmlNodeList argumentNodes = XmlHelper.SelectNodes(conditionNode, "arguments"); foreach (TypedValue argument in argumentNodes.Cast <XmlNode>().Select(argumentNode => TypedValueHelper.ReadTypedValueXml(argumentNode, "argument")).Where(argument => argument != null)) { condition.Arguments.Add(argument); } } } return(condition); }