public void TryParse_NonStringValue_ExceptionIsThrown() { var value = 20000101; var format = "yyyyMMdd"; var bitAttribute = new DateTimeAttribute(format); var couldParse = bitAttribute.TryParse(null, value, out object parsedFieldValue, out string failureMessage); }
public DateTimeExpression(PropertyType property, ValueOperator op, DateTimeAttribute value) { if (property == null) throw new ArgumentNullException("property"); if (property.DataType != DataType.DateTime) throw new ArgumentOutOfRangeException("property", "The DataType of 'property' must be DataType.DateTime"); _binExp = new BinaryExpression(property, BinaryExpression.GetOperator(op), BinaryExpression.GetNodeAttribute(value)); }
public DateTimeExpression(DateTimeAttribute property, ValueOperator op, PropertyType value) { if (value == null) throw new ArgumentNullException("value"); if (value.DataType != DataType.DateTime) throw GetWrongPropertyDataTypeException("value", DataType.DateTime); _binExp = new BinaryExpression((NodeAttribute)property, BinaryExpression.GetOperator(op), value); }
public void TryParse_ValidDate_CouldParse() { var value = "20000101"; var format = "yyyyMMdd"; var bitAttribute = new DateTimeAttribute(format); var couldParse = bitAttribute.TryParse(null, value, out object parsedFieldValue, out string failureMessage); Assert.IsTrue(couldParse); Assert.AreEqual(DateTime.Parse("2000-01-01"), (DateTime)parsedFieldValue); Assert.IsNull(failureMessage); }
public void TryParse_InvalidDate_CouldNotParse() { var value = "invalid"; var format = "yyyyMMdd"; var bitAttribute = new DateTimeAttribute(format); var couldParse = bitAttribute.TryParse(null, value, out object parsedFieldValue, out string failureMessage); Assert.IsFalse(couldParse); Assert.IsNull(parsedFieldValue); Assert.IsFalse(String.IsNullOrEmpty(failureMessage)); }
public DateTimeExpression(DateTimeAttribute property, ValueOperator op, PropertyType value) { if (value == null) { throw new ArgumentNullException("value"); } if (value.DataType != DataType.DateTime) { throw GetWrongPropertyDataTypeException("value", DataType.DateTime); } _binExp = new BinaryExpression((NodeAttribute)property, BinaryExpression.GetOperator(op), value); }
public DateTimeExpression(PropertyType property, ValueOperator op, DateTimeAttribute value) { if (property == null) { throw new ArgumentNullException("property"); } if (property.DataType != DataType.DateTime) { throw new ArgumentOutOfRangeException("property", "The DataType of 'property' must be DataType.DateTime"); } _binExp = new BinaryExpression(property, BinaryExpression.GetOperator(op), BinaryExpression.GetNodeAttribute(value)); }
public void SetValue_SetsDateTimeAttribute() { NewElement element = InitializeEmptyNewElement(); int id = 15; var att = new DateTimeAttribute() { Id = id }; element.DateTimeAttributes.Add(att); DateTime value = DateTime.Now; element.SetValue(id, value); Assert.Equal(value, att.Value); }
public static NodeAttribute GetNodeAttribute(DateTimeAttribute attr) { switch (attr) { case DateTimeAttribute.LockDate: return(NodeAttribute.LockDate); case DateTimeAttribute.LastLockUpdate: return(NodeAttribute.LastLockUpdate); case DateTimeAttribute.CreationDate: return(NodeAttribute.CreationDate); case DateTimeAttribute.ModificationDate: return(NodeAttribute.ModificationDate); default: throw new NotImplementedException("Unknown DateTimeAttribute"); } }
public static NodeAttribute GetNodeAttribute(DateTimeAttribute attr) { switch (attr) { case DateTimeAttribute.LockDate: return NodeAttribute.LockDate; case DateTimeAttribute.LastLockUpdate: return NodeAttribute.LastLockUpdate; case DateTimeAttribute.CreationDate: return NodeAttribute.CreationDate; case DateTimeAttribute.ModificationDate: return NodeAttribute.ModificationDate; default: throw new NotImplementedException("Unknown DateTimeAttribute"); } }
public DateTimeExpression(DateTimeAttribute property, ValueOperator op, DateTimeAttribute value) { _binExp = new BinaryExpression((NodeAttribute)property, BinaryExpression.GetOperator(op), BinaryExpression.GetNodeAttribute(value)); }
public SearchOrder(DateTimeAttribute propertyToOrder, OrderDirection direction) : this((NodeAttribute)propertyToOrder, direction) { }
public SearchOrder(DateTimeAttribute propertyToOrder) : this(propertyToOrder, OrderDirection.Asc) { }
public static string ToFormattedString(this DateTime dateTime, DateTimeAttribute dateTimeAttribute) { return(dateTime.ToString(GetFormat(dateTimeAttribute))); }
public static string ToFormattedString(this DateTime?dateTime, DateTimeAttribute dateTimeAttribute) { return(!dateTime.HasValue ? String.Empty : ToFormattedString(dateTime.Value, dateTimeAttribute)); }
private Element ConvertXElementToElement(XElement element) { var elementValues = new List <string>(); if (!element.Elements().Any()) { var tElem = _oldRoot.Descendants(element.Name).Where(x => GetParentsAsString(x, -1) == GetParentsAsString(element, -1) && !x.Elements().Any()).Select(e => e.Value); elementValues.AddRange(tElem); } var xElementList = _oldRoot.Descendants(element.Name).GroupBy(el => el.Parent).Select(g => new { g.Key, Count = g.Count() }).Where(x => x.Count > 1); Element returnElement; var elementName = element.Name.LocalName; var elementType = DataType.GetDataTypeFromList(elementValues, _dateFormat, _dateTimeFormat); switch (elementType.type) { case DataType.Type.Date: returnElement = new DateTimeElement(elementName, _dateFormat); break; case DataType.Type.DateTime: returnElement = new DateTimeElement(elementName, _dateTimeFormat); break; case DataType.Type.Bool: returnElement = new BoolElement(elementName, "True", "False"); break; case DataType.Type.@bool: returnElement = new BoolElement(elementName, "true", "false"); break; case DataType.Type.@int: returnElement = new IntElement(elementName); break; case DataType.Type.@decimal: returnElement = new DecimalElement(elementName); break; case DataType.Type.@string: returnElement = new StringElement(elementName); break; default: returnElement = new Element(elementName); break; } returnElement.Enumerable = xElementList.Any(); returnElement.Type = elementType; returnElement.OriginalElement = element; foreach (var xElement in element.Elements()) { returnElement.Elements.Add(ConvertXElementToElement(xElement)); } foreach (var xAttribute in element.Attributes()) { var tElements = _oldRoot.DescendantsAndSelf(element.Name).Where(x => GetParentsAsString(x, -1) == GetParentsAsString(element, -1)).ToList(); var xAttr = xAttribute; var attributeValues = tElements.Select(tElement => tElement.Attribute(xAttr.Name)).Select(attribute => attribute != null ? attribute.Value : "").ToList(); Attribute thisAttribute; var attributeName = xAttribute.Name.LocalName; if (xAttribute.IsNamespaceDeclaration) { returnElement.NamespaceAttributes.Add(xAttribute); continue; } if (attributeName == "schemaLocation") { thisAttribute = new SchemaLocationAttribute(attributeName, xAttribute.Value); returnElement.Attributes.Add(thisAttribute); continue; } var attributeType = DataType.GetDataTypeFromList(attributeValues, _dateFormat, _dateTimeFormat); switch (attributeType.type) { case DataType.Type.Date: thisAttribute = new DateTimeAttribute(attributeName, _dateFormat); break; case DataType.Type.DateTime: thisAttribute = new DateTimeAttribute(attributeName, _dateTimeFormat); break; case DataType.Type.Bool: thisAttribute = new BoolAttribute(attributeName, "True", "False"); break; case DataType.Type.@bool: thisAttribute = new BoolAttribute(attributeName, "true", "false"); break; case DataType.Type.@int: thisAttribute = new IntAttribute(attributeName); break; case DataType.Type.@decimal: thisAttribute = new DecimalAttribute(attributeName); break; case DataType.Type.@string: thisAttribute = new StringAttribute(attributeName); break; default: thisAttribute = new Attribute(attributeName); break; } thisAttribute.Type = attributeType; returnElement.Attributes.Add(thisAttribute); } return(returnElement); }
private static Expression ParseDateTimeExpression(XmlNode node, XmlNamespaceManager nsmgr, SchemaRoot schema) { ValueOperator op = ParseValueOperator(node); object leftValue = ParseLeftValue(node, nsmgr, schema); object rightValue = ParseRightValue(node, nsmgr, schema); PropertyType leftProp = leftValue as PropertyType; if (leftProp != null) { if (rightValue == null) { return(new DateTimeExpression(leftProp, op, (DateTime?)null)); } PropertyType rightProp = rightValue as PropertyType; if (rightProp != null) { return(new DateTimeExpression(leftProp, op, rightProp)); } string rightString = rightValue as String; if (rightString != null) { return(new DateTimeExpression(leftProp, op, XmlConvert.ToDateTime(rightString, XmlDateTimeSerializationMode.Unspecified))); } try { DateTimeAttribute rightAttr = (DateTimeAttribute)rightValue; return(new DateTimeExpression(leftProp, op, rightAttr)); } catch (Exception e) //rethrow { throw new ApplicationException(String.Concat("Unrecognized DateTimeAttribute: '", rightValue, "'. Source: ", node.OuterXml), e); } } else { DateTimeAttribute leftAttr = (DateTimeAttribute)leftValue; if (rightValue == null) { return(new DateTimeExpression(leftAttr, op, (DateTime?)null)); } PropertyType rightProp = rightValue as PropertyType; if (rightProp != null) { return(new DateTimeExpression(leftAttr, op, rightProp)); } string rightString = rightValue as String; if (rightString != null) { return(new DateTimeExpression(leftAttr, op, XmlConvert.ToDateTime(rightString, XmlDateTimeSerializationMode.Unspecified))); } try { DateTimeAttribute rightAttr = (DateTimeAttribute)rightValue; return(new DateTimeExpression(leftAttr, op, rightAttr)); } catch (Exception e) //rethrow { throw new ApplicationException(String.Concat("Unrecognized DateTimeAttribute: '", rightValue, "'. Source: ", node.OuterXml), e); } } }
public static string GetFormat(DateTimeAttribute dateTimeAttribute) { return(dateTimeAttribute == null ? DATE_FORMAT : DATA_TIME_FORMAT); }