コード例 #1
0
        /// <summary>
        /// 1. Resolve a converter by mapping ID, to convert data => PaymentOutputModel
        /// 2. Standardized code to convert PaymentOutputModel to byte[] in here, in standard format in wiki
        /// </summary>
        /// <param name="mappingId">mapping id</param>
        /// <param name="data">list mapping object</param>
        /// <returns></returns>
        public async Task <Either <Error, byte[]> > ExportAsync(string inputType, ImmutableList <object> data)
        {
            return(await(ShouldNotNullOrEmpty(inputType), ShouldNotNullOrEmpty(data))
                   .Apply((inpt, d) => (inpt, listItems: d))
                   .MatchAsync(async d =>
            {
                if (!Enum.TryParse(d.inpt, true, out InputType inputTypeEnum) ||
                    inputTypeEnum == InputType.NotSupported)
                {
                    return Left <Error, byte[]>(
                        $"Not supported input type: {inputTypeEnum.ToString()}");
                }

                return (await _outputMappingRepository.GetAsync(inputTypeEnum))
                .Match(outputMapping =>
                {
                    return
                    outputMapping.IsXml
                                            ? ExportFromXml(d.listItems, outputMapping.XmlConfiguration,
                                                            outputMapping.NumberOfHeader, outputMapping.NumberOfFooter)
                                            : SerializerAsJson(d.listItems);
                },
                       () => Left <Error, byte[]>(
                           $"Not supported output mapping: {inputTypeEnum.ToString()}"));
            },
                               errors => errors.Join()));
        }
コード例 #2
0
        public async Task <Either <Error, IParser <T> > > GetParserAsync <T>(string key) where T : IStandardModel
        {
            return(await ShouldNotNullOrEmpty(key)
                   .MatchAsync(async k =>
            {
                // Get custom parser
                var parser = _customParsers?.OfType <ICustomParser <T> >().FirstOrDefault(p => p.Key == k);
                if (parser != null)
                {
                    return Right <Error, IParser <T> >(parser);
                }
                else
                {
                    var inputType = MapInputType <T>();
                    // Get beanio parser
                    var inputMapping = (await _inputMappingRepository
                                        .ListAsync(q => q.Where(e => e.Key == k && e.InputType == inputType)))
                                       .FirstOrDefault();

                    if (inputMapping == null)
                    {
                        return Left <Error, IParser <T> >($"No mapping by key: {k} & type: {inputType.ToString()}");
                    }
                    else if (inputMapping.XmlConfiguration.IsNullOrEmpty())
                    {
                        return Left <Error, IParser <T> >(
                            $"No xml configuration by key: {k} & type: {inputType.ToString()}");
                    }

                    var mapperSourceText = await _mstEntityRepository.GetAsync(inputMapping.MapperSourceTextId);
                    return Right <Error, IParser <T> >(new BeanParser <T>(
                                                           inputMapping.XmlConfiguration,
                                                           _fileLoaderServices.SingleOrDefault(fl => fl.Type == inputMapping.StreamType),
                                                           _beanMapperFactory.GetBeanMapper(inputMapping.Mapper),
                                                           mapperSourceText));
                }
            }, errors => errors.Join()));
        }
コード例 #3
0
 public async Task <IActionResult> FindMapperSourceText([FromRoute] int key)
 {
     return(await _mapperSourceTextRepository.GetAsync(key)
            .ToActionResultAsync());
 }
コード例 #4
0
 public async Task <IActionResult> FindOutputMapping([FromRoute] InputType key)
 {
     return(await _outputMappingRepository.GetAsync(key)
            .ToActionResultAsync());
 }