コード例 #1
0
        /// <summary>
        /// Formata a mensagem do erro.
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="descriptor"></param>
        /// <param name="queryResult">Resulta da consulta associada.</param>
        /// <returns></returns>
        private static string FormatMessage(string fieldName, Record.RecordDescriptor descriptor, IQueryResult queryResult)
        {
            QueryCommand command = null;

            if (queryResult is IQueryCommandContainer)
            {
                command = ((IQueryCommandContainer)queryResult).Command;
            }
            var fieldsAvailables = string.Join("; ", descriptor.Select(f => f.Name).ToArray());

            if (command != null)
            {
                return(ResourceMessageFormatter.Create(() => Properties.Resources.RecordFieldNotFoundExceptionWithQueryCommand_Message, fieldName, fieldsAvailables, command.ToString()).Format());
            }
            else
            {
                return(ResourceMessageFormatter.Create(() => Properties.Resources.RecordFieldNotFoundException_Message, fieldName, fieldsAvailables).Format());
            }
        }
コード例 #2
0
        /// <summary>
        /// Construtor padrão.
        /// </summary>
        /// <param name="typeBindStrategy">Instancia da estratégia de vinculação associada.</param>
        /// <param name="descriptor"></param>
        public TypeBindRecordDescriptorSchema(TypeBindStrategy typeBindStrategy, Record.RecordDescriptor descriptor)
        {
            _properties = new List <Property>();
            var typeProperties = typeBindStrategy.Type.GetProperties(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
            var stringComparer = StringComparer.InvariantCultureIgnoreCase;

            foreach (var field in descriptor)
            {
                var prop = typeProperties.Where(f => f.CanWrite && stringComparer.Equals(f.Name, field.Name)).FirstOrDefault();
                if (prop != null)
                {
                    if (_properties.Exists(f => stringComparer.Equals(f.FieldName, field.Name)))
                    {
                        throw new TypeBindStrategyException(ResourceMessageFormatter.Create(() => Properties.Resources.TypeBindStrategy_DuplicateFieldName, field.Name, typeBindStrategy.Type.FullName, string.Join(", ", descriptor.Select(f => f.Name).ToArray())).Format());
                    }
                    var converter = System.ComponentModel.TypeDescriptor.GetConverter(prop.PropertyType);
                    _properties.Add(new Property(field.Name, prop, converter));
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// Valida os dados do registro.
 /// </summary>
 /// <param name="record"></param>
 /// <param name="queryInfo"></param>
 /// <returns></returns>
 public static ValidationQueryResult Validate(this Record record, QueryInfo queryInfo)
 {
     Record.RecordDescriptor descriptor = null;
     if (record == null || queryInfo == null)
     {
         return(new ValidationQueryResult(ValidationQueryResult.ValidationError.None, null));
     }
     descriptor = record.Descriptor;
     if (descriptor == null)
     {
         return(new ValidationQueryResult(ValidationQueryResult.ValidationError.None, null));
     }
     if (descriptor != null && queryInfo.Projection != null && queryInfo.Projection.Count > 0)
     {
         var projection = queryInfo.Projection;
         var isMatch    = (descriptor.Count == projection.Count);
         if (isMatch)
         {
             for (var i = 0; i < projection.Count; i++)
             {
                 var fieldName = GetFieldName(projection[i]);
                 if (string.IsNullOrEmpty(fieldName))
                 {
                     continue;
                 }
                 if (!StringComparer.InvariantCultureIgnoreCase.Equals(fieldName, descriptor[i].Name))
                 {
                     isMatch = false;
                     break;
                 }
             }
         }
         if (!isMatch)
         {
             var message = ResourceMessageFormatter.Create(() => Properties.Resources.ValidationQueryResult_NotMatchFields, string.Join("; ", projection.Select(f => GetFieldName(f)).ToArray()), string.Join("; ", descriptor.Select(f => f.Name).ToArray()));
             return(new ValidationQueryResult(ValidationQueryResult.ValidationError.InvalidFields, message));
         }
     }
     return(new ValidationQueryResult(ValidationQueryResult.ValidationError.None, null));
 }
コード例 #4
0
 /// <summary>
 /// Formata a mensagem do erro.
 /// </summary>
 /// <param name="descriptor"></param>
 /// <returns></returns>
 private static string FormatMessage(Record.RecordDescriptor descriptor)
 {
     return(ResourceMessageFormatter.Create(() => Properties.Resources.InvalidRecordChecksumException_Message, string.Join("; ", descriptor.Select(f => f.Name).ToArray())).Format());
 }