Ejemplo n.º 1
0
        DelegatingConversionStep ApplyConverter(MappingStep mapping, bool withFallback)
        {
            dynamic instance = null;

            try
            {
                instance = conversionPatternRepository.LeaseConversionPatternFor(mapping.SourceValueType, mapping.TargetValueType);
                if (ReferenceEquals((object)instance, null) == false)
                {
                    var expression = instance.BuildConversionExpression(mapping) as LambdaExpression;
                    if (expression != null)
                    {
                        return(new DelegatingConversionStep(expression));
                    }
                }
            }
            finally
            {
                conversionPatternRepository.Recycle((object)instance);
            }
            if (withFallback == false || mapping.TargetValueType.IsAssignableFrom(mapping.SourceValueType))
            {
                return(null);
            }
            // fallabck behavior
            instance = Activator.CreateInstance(typeof(MapConversionPattern <>).MakeGenericType(mapping.TargetValueType));
            return(new DelegatingConversionStep(instance.BuildConversionExpression(mapping) as LambdaExpression));
        }
        public static IServiceCollection AddBookingPipelines(this IServiceCollection services)
        {
            var sp = services.BuildServiceProvider();

            // Create each step of the pipeline
            var mapping     = new MappingStep(sp.GetRequiredService <ILogger <MappingStep> >());
            var getRequest  = new GetRequestStep(sp.GetRequiredService <ILogger <GetRequestStep> >());
            var getResponse = new GetResponseStep(sp.GetRequiredService <ILogger <GetResponseStep> >());
            var aggregate   = new AggregateStep(sp.GetRequiredService <ILogger <AggregateStep> >());
            var dedupe      = new DedupeStep(sp.GetRequiredService <ILogger <DedupeStep> >());

            // Build the pipeline using the steps, in the desired order
            var searchPipeline = new Pipeline <HubRequest, HubResponse>(hubRq => hubRq
                                                                        .AddStep(mapping)
                                                                        // Sub-pipeline with three steps, two of them also use the input from parent
                                                                        .AddStep(new Pipeline <ConnectorRequest, ConnectorResponse>(connRq => connRq
                                                                                                                                    .AddStep(getRequest, hubRq)
                                                                                                                                    .AddStep(getResponse, hubRq)
                                                                                                                                    .AddStep(aggregate))
                                                                                 )
                                                                        .AddStep(dedupe));

            // Inject this pipeline to the service provider (it is used in the controller)
            return(services.AddSingleton <IPipelineStep <HubRequest, HubResponse> >(searchPipeline));
        }
Ejemplo n.º 3
0
        public void WillNotReplaceValuesNotMapped()
        {
            var input  = "this will not be replaced";
            var step   = new MappingStep(MappingTable.Create(Tables.B_1));
            var output = step.Run(input);

            Assert.Equal(input, output);
        }
        public void WillNotReplaceValuesNotMapped()
        {
            const string input  = "this will not be replaced";
            var          step   = new MappingStep(MappingTable.Create(Mapping.B1));
            var          output = step.Run(input);

            output.ShouldBe(input);
        }
Ejemplo n.º 5
0
        public void WillReplaceValuesMappedToNothing()
        {
            var input    = "this value: " + Convert.ToChar(0x180B) + " will be replaced";
            var expected = "this value:  will be replaced";
            var step     = new MappingStep(MappingTable.Create(Tables.B_1));
            var output   = step.Run(input);

            Assert.Equal(expected, output);
        }
Ejemplo n.º 6
0
        public void WillReplaceValuesWithMultipleReplacements()
        {
            var input    = "this value: " + Convert.ToChar(0x00DF) + " will be replaced";
            var expected = "this value: " + Convert.ToChar(0x0073) + Convert.ToChar(0x0073) + " will be replaced";
            var step     = new MappingStep(MappingTable.Create(Tables.B_2));
            var output   = step.Run(input);

            Assert.Equal(expected, output);
        }
        public void WillReplaceValues()
        {
            var input    = $"this value: {Convert.ToChar(0x0041)} will be replaced";
            var expected = $"this value: {Convert.ToChar(0x0061)} will be replaced";
            var step     = new MappingStep(MappingTable.Create(Mapping.B2));
            var output   = step.Run(input);

            output.ShouldBe(expected);
        }
        public void WillReplaceWithMultipleCharacters()
        {
            var input    = $"this value: {Convert.ToChar(0x00DF)} will be replaced";
            var expected = $"this value: {Convert.ToChar(0x0073)}{Convert.ToChar(0x0073)} will be replaced";
            var step     = new MappingStep(MappingTable.Create(Mapping.B2));
            var output   = step.Run(input);

            output.ShouldBe(expected);
        }
        public void WillReplaceValuesMappedToNothing()
        {
            var          input    = $"this value: {Convert.ToChar(0x180B)} will be replaced";
            const string expected = "this value:  will be replaced";
            var          step     = new MappingStep(MappingTable.Create(Mapping.B1));
            var          output   = step.Run(input);

            output.ShouldBe(expected);
        }
Ejemplo n.º 10
0
 public Expression <Func <T?, IMapper, MappingContext, T> > BuildConversionExpression(MappingStep mapping)
 {
     return((d, m, c) => d.GetValueOrDefault());
 }
 public Expression <Func <DateTime, IMapper, MappingContext, DateTime> > BuildConversionExpression(MappingStep mapping)
 {
     return((s, m, c) => TimeZoneInfo.ConvertTime(s, c.Argument <TimeZoneInfo>()).Date);
 }
 public Expression <Func <IHasId, IMapper, MappingContext, Identifier> > BuildConversionExpression(MappingStep mapping)
 {
     return((s, m, c) => new Identifier(s.ItemId, s.LastModified));
 }
Ejemplo n.º 13
0
 public Expression <Func <T1?, IMapper, MappingContext, T2?> > BuildConversionExpression(MappingStep mapping)
 {
     return((d, m, c) => d.HasValue ? m.Convert <T2>(d.Value) : default(T2));
 }
        public Expression <Func <T, IMapper, MappingContext, T?> > BuildConversionExpression(MappingStep mapping)
        {
            if (mapping.SourceValueType == typeof(T?))
            {
                return(null);
            }

            return((d, m, c) => d);            //implicit conversion
        }
Ejemplo n.º 15
0
 public Expression <Func <T, IMapper, MappingContext, T> > BuildConversionExpression(MappingStep mapping)
 {
     return((d, m, c) => d);
 }
Ejemplo n.º 16
0
 public Expression <Func <decimal, IMapper, MappingContext, decimal> > BuildConversionExpression(MappingStep mapping)
 {
     return((d, m, c) => Decimal.Round(d, 2));
 }
Ejemplo n.º 17
0
        static Expression BuildParameterExpression(MappingStep step, MappingStrategy strategy)
        {
            var map = step.Apply(strategy, step.Conversion);

            return(map);
        }
Ejemplo n.º 18
0
 public Expression <Func <IEnumerable, IMapper, MappingContext, TTargetItem[]> > BuildConversionExpression(MappingStep mapping)
 {
     return((source, mapper, context) => CollectionConversionHelper.MapCollection <TTargetItem>(source, context));
 }
Ejemplo n.º 19
0
        public Expression <Func <object, IMapper, MappingContext, TTo> > BuildConversionExpression(MappingStep mapping)
        {
            if (mapping.SourceValueType.Is(mapping.TargetValueType))
            {
                // no conversion needed
                return(null);
            }

            return((source, mapper, context) => mapper.Convert <TTo>(source));
        }
Ejemplo n.º 20
0
 public void AddMappingStep(MappingStep mappingStep)
 {
     mappingSteps.Add(mappingStep);
 }
Ejemplo n.º 21
0
 public Expression <Func <TSource, IMapper, MappingContext, TTarget> > BuildConversionExpression(MappingStep mapping)
 {
     return((d, m, c) => (TTarget)Convert.ChangeType(d, typeof(TTarget)));
 }
 public Expression <Func <T, IMapper, MappingContext, string> > BuildConversionExpression(MappingStep mapping)
 {
     return((d, m, c) => d.ToString());
 }