public Result <Bitmap> DrawCloud(string pathToWordsFile, BaseCloudLayouter layouter, Size imageSize, FontFamily fontFamily, IColorSelector colorSelector, IWordPainter?wordPainter = null) { wordPainter ??= new SimpleWordPainter(); layouter.ClearLayout(); if (!File.Exists(pathToWordsFile)) { return(Result.Fail <Bitmap>($"File {pathToWordsFile} not found")); } var interestingWords = Result.Of(() => Path.GetExtension(pathToWordsFile)) .Then(ext => readers.First(x => x.Types.Contains(ext))) .Then(reader => reader.ReadAllLinesFromFile(pathToWordsFile)) .Then(WordPreparer.GetInterestingWords); var statistic = interestingWords.Then(words => WordPreparer.GetWordsStatistic(words)); return(statistic.Then(_ => DrawCloud( RectanglesForWordsCreator.GetReadyWords( statistic.GetValueOrThrow(), layouter, fontFamily, wordPainter), imageSize, colorSelector, wordPainter))); }
public Bitmap DrawCloud(string pathToWordsFile, BaseCloudLayouter layouter, Size imageSize, FontFamily fontFamily, IColorSelector colorSelector, IWordPainter?wordPainter = null) { wordPainter ??= new SimpleWordPainter(); layouter.ClearLayout(); if (!File.Exists(pathToWordsFile)) { throw new FileNotFoundException(); } var ext = Path.GetExtension(pathToWordsFile); var reader = readers.First(x => x.Types.Contains(ext)); var interestingWords = WordPreparer.GetInterestingWords(reader.ReadAllLinesFromFile(pathToWordsFile)); var statistic = WordPreparer.GetWordsStatistic(interestingWords); return(DrawCloud(RectanglesForWordsCreator.GetReadyWords(statistic, layouter, fontFamily, wordPainter), imageSize, colorSelector, wordPainter)); }