Exemplo n.º 1
0
        private SchemaValidationErrorType CheckMinMax(SchemaFieldItem field, IConvertible value)
        {
            SchemaValidationErrorType result = SchemaValidationErrorType.None;

            if (field.FieldType == (int)SFIType.Number)
            {
                decimal dvalue = value.ToDecimal(CultureInfo.InvariantCulture);
                if (field.MinValue.HasValue && dvalue < field.MinValue.Value)
                {
                    result = SchemaValidationErrorType.LessThenMinNumber;
                }
                if (field.MaxValue.HasValue && dvalue > field.MaxValue.Value)
                {
                    result = SchemaValidationErrorType.GreaterThenMaxNumber;
                }
            }
            else if (field.FieldType == (int)SFIType.Date)
            {
                DateTime dtvalue = value.ToDateTime(CultureInfo.InvariantCulture);
                if (field.MinDateValue.HasValue && dtvalue < field.MinDateValue.Value)
                {
                    result = SchemaValidationErrorType.LessThenMinDate;
                }
                if (field.MaxDateValue.HasValue && dtvalue > field.MaxDateValue.Value)
                {
                    result = SchemaValidationErrorType.GreaterThenMaxDate;
                }
            }
            return(result);
        }
Exemplo n.º 2
0
 private SchemaValidationDecision OnHandleError(DataElement element,
                                                SchemaValidationErrorType errorType,
                                                string fieldName)
 {
     if (_errorHandler != null)
     {
         var error = new SchemaValidationError(this, element, errorType, fieldName);
         return(_errorHandler(error));
     }
     return(SchemaValidationDecision.Default);
 }
Exemplo n.º 3
0
 public SchemaValidationError(IAction action, DataElement element, SchemaValidationErrorType errorType, string fieldName)
 {
     if (action == null)
     {
         throw new ArgumentNullException("action");
     }
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     Action    = action;
     Element   = element;
     ErrorType = errorType;
     FieldName = fieldName;
 }
Exemplo n.º 4
0
        private bool ValidateValues(DataElement element, IObserver <IElement> sink)
        {
            var fields = _schema.GetTableSchemaDictionary(element.Name);
            var data   = element.Data.Schema.ToDictionary(x => x.Key, x => element.Data.Values[x.Value]);
            var names  = fields.Keys.Concat(data.Keys).Distinct();

            foreach (string name in names)
            {
                SchemaValidationErrorType error = SchemaValidationErrorType.None;

                if (!fields.ContainsKey(name))
                {
                    error = SchemaValidationErrorType.UnknownField;
                }
                else if (!data.ContainsKey(name))
                {
                    error = SchemaValidationErrorType.MissingField;
                }
                else
                {
                    error = CheckValue(fields[name], data[name]);
                }
                if (error != SchemaValidationErrorType.None)
                {
                    SchemaValidationDecision decision = OnHandleError(element, error, name);
                    switch (decision)
                    {
                    case SchemaValidationDecision.PassElement: return(true);

                    case SchemaValidationDecision.SkipElement: return(false);

                    case SchemaValidationDecision.DoComplete: sink.OnCompleted(); return(false);

                    case SchemaValidationDecision.DoError: sink.OnError(new SchemaValidationException(error)); return(false);

                    case SchemaValidationDecision.IgnoreError:
                    default:
                        break;
                    }
                }
            }
            return(true);
        }
Exemplo n.º 5
0
        private SchemaValidationErrorType CheckValue(SchemaFieldItem field, object value)
        {
            SchemaValidationErrorType result = SchemaValidationErrorType.None;

            if (value == null || value == DBNull.Value)
            {
                if (field.IsNotNull)
                {
                    result = SchemaValidationErrorType.NullValueNotNullField;
                }
            }
            else
            {
                result = SchemaValidationErrorType.InvalidFieldType;
                SFIType?fieldType = TryGetFieldType(value.GetType());
                if (fieldType.HasValue && (int)fieldType.Value == field.FieldType)
                {
                    result = CheckMinMax(field, (IConvertible)value);
                }
            }
            return(result);
        }
Exemplo n.º 6
0
 private static string GetMessage(SchemaValidationErrorType errorType)
 {
     return(String.Format(ERROR_TEXT, errorType));
 }
Exemplo n.º 7
0
 public SchemaValidationException(SchemaValidationErrorType errorType, Exception innerException) : base(GetMessage(errorType), innerException)
 {
 }
Exemplo n.º 8
0
 public SchemaValidationException(SchemaValidationErrorType errorType) : base(GetMessage(errorType))
 {
 }