Пример #1
0
        public static ExtractStatus Extract <V>(this IMultiFieldValueMapper <V> mapper, IFileReader reader)
            where V : class, new()
        {
            ExtractStatus r = ExtractStatus.Failed;

            if (mapper.SignatureFieldMapper == null)
            {
                if (mapper.Value == null)
                {
                    mapper.Value = new V();
                }
            }
            else
            {
                mapper.SignatureFieldMapper.Target = mapper.Value;
                r = mapper.SignatureFieldMapper.Extract(reader);
                if (r != ExtractStatus.Success)
                {
                    return(r);
                }
                if (mapper.Value == null)
                {
                    mapper.Value = mapper.SignatureFieldMapper.Target;
                }
            }

            if (null == mapper.Value)
            {
                if (mapper.IsMandatory)
                {
                    throw new Exception(mapper.FieldInfo + "Mandatory field is empty.");
                }
            }
            else if (null != mapper.FieldMappers)
            {
                foreach (var f in mapper.FieldMappers)
                {
                    f.Target = mapper.Value;
                    r        = f.Extract(reader);
                    if (r != ExtractStatus.Success)
                    {
                        break;
                    }
                }
            }

            return(ExtractStatus.Success);
        }
Пример #2
0
        private static ExtractStatus ExtractValues <V>(IMultiFieldValueMapper <V> mapper, IFileReader reader)
            where V : class, new()
        {
            ExtractStatus r = ExtractStatus.Success;

            if (null != mapper.FieldMappers)
            {
                foreach (var f in mapper.FieldMappers)
                {
                    f.Target = mapper.Value;
                    r        = f.Extract(reader);
                    if (r != ExtractStatus.Success)
                    {
                        break;
                    }
                }
            }
            return(r);
        }
Пример #3
0
        public static ExtractStatus Import <T, V>(this IMultiRecordMapper <T, V> recordMapper, IFileReader reader)
            where V : class, new()
        {
            ExtractStatus r     = ExtractStatus.Failed;
            int           count = 0;

            do
            {
                V v = null;
                if (null == recordMapper.SignatureRecordMapper)
                {
                    v = new V();
                    r = ExtractStatus.Success;
                }
                else
                {
                    recordMapper.SignatureRecordMapper.Target = recordMapper.Target;
                    recordMapper.SignatureRecordMapper.Value  = null;
                    r = recordMapper.SignatureRecordMapper.Import(reader);
                    v = recordMapper.SignatureRecordMapper.Value;

                    if (r == ExtractStatus.Success && v == null || r == ExtractStatus.Failed)
                    {
                        if (count >= recordMapper.MinOccurrence &&
                            (recordMapper.MaxOccurrence == 0 || count <= recordMapper.MaxOccurrence))
                        {
                            r = ExtractStatus.Success;
                        }
                        else
                        {
                            r         = ExtractStatus.Failed;
                            r.Message = String.Format(LessMessage, count, recordMapper.ToString(), recordMapper.MinOccurrence);
                        }
                        return(r);
                    }
                    else if (r == ExtractStatus.SkipTheRest)
                    {
                        break;
                    }
                }

                if (r == ExtractStatus.Success)
                {
                    ++count;
                    recordMapper.Value = v;
                    recordMapper.SetProperty();
                    if (null != recordMapper.RecordMappers)
                    {
                        foreach (var m in recordMapper.RecordMappers)
                        {
                            m.Target = v;
                            r        = m.Import(reader);
                            if (r != ExtractStatus.Success)
                            {
                                break;
                            }
                        }
                    }
                }
            } while (recordMapper.MaxOccurrence == 0 || count < recordMapper.MaxOccurrence);

            return(r);
        }