示例#1
0
        public void ProcessWords(DictionaryFileRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("Request is empty");
            }

            String[] words = _fileService.ReadFile(request.FileName);

            IEnumerable <IEnumerable <string> > resultList = _dictionaryFileService.ProcessWords(request, words);

            _fileService.CreateOutputFile(request.ResultFileName, resultList);
        }
示例#2
0
        static async Task MainAsync(string[] args)
        {
            // Create service collection
            ServiceCollection serviceCollection = new ServiceCollection();

            ConfigureServices(serviceCollection);

            // Create service provider
            IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();

            await serviceProvider.GetService <App>().Run();

            IDictionaryFileAppService _dictionaryAppService = serviceProvider.GetService <IDictionaryFileAppService>();
            IFileService _fileService = serviceProvider.GetService <IFileService>();

            if (args == null)
            {
                throw new ArgumentNullException("Program must have arguments.");
            }

            if (args.Length != 4)
            {
                throw new ArgumentException("There must be 4 arguments in the list.");
            }

            if (!_dictionaryAppService.CheckWordLength(args[1], 4))
            {
                throw new ArgumentException("Start word must have 4 chars.");
            }

            if (!_dictionaryAppService.CheckWordLength(args[1], 4))
            {
                throw new ArgumentException("End word must have 4 chars.");
            }

            if (!_fileService.CheckFileExists(configuration.GetSection("FileBasePath").Value + args[0]))
            {
                throw new FileNotFoundException("File provided not found");
            }

            DictionaryFileRequest inputs = new DictionaryFileRequest
            {
                FileName       = configuration.GetSection("FileBasePath").Value + args[0],
                EndWord        = args[2],
                ResultFileName = configuration.GetSection("FileBasePath").Value + args[3],
                StartWord      = args[1],
                WordLength     = 4
            };

            _dictionaryAppService.ProcessWords(inputs);
        }
示例#3
0
        /// <summary>
        /// Input method to process file and generate output file
        /// </summary>
        /// <param name="request"></param>
        public IEnumerable <IEnumerable <string> > ProcessWords(DictionaryFileRequest request, String[] words)
        {
            if (request is null)
            {
                throw new ArgumentNullException("Request is empty");
            }

            IEnumerable <IEnumerable <string> > resultList = null;

            words = words.Where(w => w.Length == request.WordLength).ToArray();

            resultList = ShortestPathAlgorithm(request.StartWord, request.EndWord, words.ToList());

            return(resultList);
        }