コード例 #1
0
ファイル: Program.cs プロジェクト: badyb14/ranagams
        static void Main(string[] args)
        {
            var    folder        = "Dictionaries";
            var    fileName      = "word*";
            string extra         = null;
            string exclusionList = null;

            var current       = Directory.GetCurrentDirectory();
            var path          = Path.Combine(current, folder);
            var baseNames     = Directory.GetFiles(path, fileName);
            var sourceFactory = new WordListFileSourceFactory(baseNames, path, extra, exclusionList);

            source1 = sourceFactory.GetWordList(true)[0];
            source1.Load();
            source2 = sourceFactory.GetWordList(false)[0];
            source2.Load();
            string word = "trainers"; //silent,elvis,samples,calipers,trainers, salesman, auctioned,mastering, discounted,reductions,percussion

            for (int i = 0; i < 1; i++)
            {
                RunTests(word);
            }

            Console.ReadKey();
        }
コード例 #2
0
        public void GetWordList_Case2()
        {
            //Arrange
            string[] baseNames       = new string[] { @"c:\d\w_en.txt", "badentry" };
            string   path            = @"c:\d";
            string   extraPrefix     = "";
            string   exclusionPrefix = "";
            var      objectUnderTest = new WordListFileSourceFactory(baseNames, path, extraPrefix, exclusionPrefix);

            //Act
            var actual = objectUnderTest.GetWordList(true);

            //Assert
            Assert.AreEqual(1, actual.Length);
        }
コード例 #3
0
ファイル: AnagramExtensions.cs プロジェクト: badyb14/ranagams
        public static IServiceCollection AddFileBasedAnagramService(this IServiceCollection collection, IConfiguration config)
        {
            var folder        = config["WordListConfig:FileProvider:Folder"];
            var fileName      = config["WordListConfig:FileProvider:BaseListName"];
            var extra         = config["WordListConfig:FileProvider:SupplementalName"];
            var exclusionList = config["WordListConfig:FileProvider:BadWords"];

            if (string.IsNullOrWhiteSpace(folder))
            {
                throw new ArgumentException("invalid folder configuration");
            }

            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentException("invalid file name configuration");
            }

            AnagramResolverService resolverService = null;
            //could take ILoggerFactory wrap it and make it a parameter for consumption.
            var logger    = LoggerFactory.CreateLogger("AnagramApi.AnagramResolverService");
            var current   = Directory.GetCurrentDirectory();
            var path      = Path.Combine(current, folder);
            var baseNames = Directory.GetFiles(path, fileName);

            logger.LogWarning("Configuration path {0}. File pattern {1}. File Count {2}", path, fileName, baseNames.Length);

            var sourceFactory = new WordListFileSourceFactory(baseNames, path, extra, exclusionList);
            var sources       = sourceFactory.GetWordList(true);

            resolverService = new AnagramResolverService(sources, (w) => new WordGenerator(w));

            collection.AddSingleton <IAnagramResolverService, AnagramResolverService>((s) => { return(resolverService); });

            EnsureAnagramServiceTelemetry(collection);

            return(collection);
        }