예제 #1
0
        public static Result <None> RegisterTextDrawerComponents(WindsorContainer container, Options options, Dictionary <string, int> wordsStatistics)
        {
            var imageSize       = Result.Of(() => new Size(options.ImageWidth, options.ImageHeight)).RefineError("Incorrect size");
            var backgroundColor = ColorParser.Parse(options.BackgroundColor).RefineError("Incorrect background color");
            var fontFamily      = Result.Of(() => new FontFamily(options.FontFamily)).RefineError("Incorrect font family");

            container.Register(
                Component
                .For <ILayouter>()
                .ImplementedBy <CircularCloudLayouter>());
            var placerRegisterResult = imageSize.Then(size =>
                                                      container.Register(
                                                          Component
                                                          .For <IWordsPlacer>()
                                                          .ImplementedBy <LinearAreaGrowthWordsPlacer>()
                                                          .DependsOn(Dependency.OnValue <Size>(size))));

            var brushRegisterResult = BrushSelectorRegisterActions[options.TextBrushSelector](options, container, wordsStatistics);

            var returnResult = from placerRes in placerRegisterResult
                               from brushRes in brushRegisterResult
                               from backColor in backgroundColor
                               from size in imageSize
                               from fontFam in fontFamily
                               select
                               container.Register(
                Component
                .For <ITextDrawer>()
                .ImplementedBy <PngTextDrawer>()
                .DependsOn(Dependency.OnValue <Color>(backColor))
                .DependsOn(Dependency.OnValue <Size>(size))
                .DependsOn(Dependency.OnValue <FontFamily>(fontFam)));

            return(returnResult.Then(x => { }));
        }
예제 #2
0
 private static Result <None> RegisterSingleColorBrushSelector(WindsorContainer container, Options options, Dictionary <string, int> wordsStatistics)
 {
     return(ColorParser.Parse(options.TextColor)
            .Then(color =>
                  container.Register(
                      Component
                      .For <IBrushSelector>()
                      .ImplementedBy <SingleColorBrushSelector>()
                      .DependsOn(Dependency.OnValue <Color>(color))))
            .Then(x => { }));
 }
예제 #3
0
        private static Result <None> RegisterGradientColorBrushSelector(WindsorContainer container, Options options, Dictionary <string, int> wordsStatistics)
        {
            var colorsPair =
                from mostFrequentColor in ColorParser.Parse(options.MostFrequentTextColor).RefineError("Most frequent color incorrect")
                from leastFrequentColor in ColorParser.Parse(options.LeastFrequentTextColor).RefineError("Least frequent color incorrect")
                select new GradientColorsPair(mostFrequentColor, leastFrequentColor);

            return(colorsPair
                   .Then(colors => container.Register(
                             Component
                             .For <IBrushSelector>()
                             .ImplementedBy <GradientBrushSelector>()
                             .DependsOn(Dependency.OnValue <IEnumerable <int> >(wordsStatistics.Select(pair => pair.Value)))
                             .DependsOn(Dependency.OnValue <GradientColorsPair>(colors))))
                   .Then(x => { }));
        }