示例#1
0
        private static void Main(string[] args)
        {
            var characterReaders = new ICharacterReader[]
            {
                new SlowCharacterReader(), new SimpleCharacterReader()
            };

            using (var wordCounter = new ParallelWordCounter(characterReaders, StringComparer.InvariantCultureIgnoreCase))
            {
                wordCounter.EnableLogging(PrintOrderedWordCount, TimeSpan.FromSeconds(10));
                var wordCount = wordCounter.GetWordCount();
            }

            Console.WriteLine("Done...");
            Console.ReadKey();
        }
示例#2
0
        static int Main(string[] args)
        {
            const string commandNotFound = "Command not found";

            try
            {
                #region Check arguments

                if (args == null)
                {
                    throw new Exception(commandNotFound);
                }

                if (args.Length == 1)
                {
                    if (HelpRequired(args[0]))
                    {
                        DisplayHelp();
                        return(0);
                    }
                }

                if (args.Length < 2)
                {
                    throw new Exception(commandNotFound);
                }

                #endregion Check arguments

                var counter = new ParallelWordCounter();
                var result  = counter.CountWords(args[0]);

                FileHelpers.WriteDictionary(result, args[1]);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error occured: {e.Message}\nSource: {e.Source}");
                return(1);
            }

            return(0);
        }