public DateTime ParseDateTime(string line, DateTimeRule rule) { line = ApplyAnchors(line, rule.GeneralRule.StartAnchor, rule.GeneralRule.EndAnchor); var parsedValue = rule.GeneralRule.Matcher.Match(line); if (!parsedValue.Success) { throw new ArgumentException( $"Could not apply matcher '{rule.GeneralRule.Matcher}' to line '{line}' to extract date time"); } if (!string.IsNullOrWhiteSpace(rule.DateFormat)) { var parsedDateTime = DateTime.ParseExact(parsedValue.Value.Trim(), rule.DateFormat, CultureInfo.InvariantCulture); return(parsedDateTime); } else { var parsedDateTime = DateTime.Parse(parsedValue.Value); return(parsedDateTime); } }
/// <summary> /// Check if property is convertible to DateTime. /// </summary> /// <param name="format">specified format.</param> /// <returns>Current instance.</returns> public PropertyValidator <TRow> TryParseDateTime(string format) { DateTimeRule <TRow> method = new DateTimeRule <TRow>((x) => this.getter(x)); method.TryParseDateTime(format); this.validationRules.Add(method); return(this); }
public async Task <DateTimeRule> Edit(DateTimeRule model) { var isUpdated = await _dateTimeRuleRepository.Update(model); if (isUpdated) { return(await _dateTimeRuleRepository.Read(model.Id)); } throw new Exception($"Failed to update date time rule {model.Id}"); }
public IRule GetRule(RuleInfo ruleInfo) { IRule rule = new NullRule(ruleInfo); if (RelationOperatorRule(ruleInfo)) { rule = new RelationalRule(ruleInfo); } else if (ruleInfo.ValueType == ValueTypes.DateTime && ruleInfo.Operator == Operator.IsFuture) { rule = new DateTimeRule(ruleInfo); } else if (IsBandRule(ruleInfo) && ruleInfo.ValueType != ValueTypes.String) { rule = new BandRule(ruleInfo); } return(rule); }
public NormalizedLog ParseAll(string line, DateTimeRule dateTimeRule, SeverityRule severityRule, MessageRule messageRule, IEnumerable <GeneralRule> customAttributeRules) { var dateTime = ParseDateTime(line, dateTimeRule); var severity = ParseSeverityLevel(line, severityRule); var message = ParseMessage(line, messageRule); var customAttributes = new List <CustomAttributeValue>(); foreach (var customAttributeRule in customAttributeRules) { var result = ParseCustomAttribute(line, customAttributeRule); customAttributes.Add(new CustomAttributeValue { GeneralRule = customAttributeRule, Id = 0, Value = result, CustomAttributeRuleId = customAttributeRule.Id }); } // TODO check this return(new NormalizedLog(dateTime, severity, message, 0, 0, 0, customAttributes.ToArray())); }
public async Task <DateTimeRule> Create(DateTimeRule model) { var createdId = await _dateTimeRuleRepository.Create(model); return(await _dateTimeRuleRepository.Read(createdId)); }