public static void ExecuteAndLogToFile(ArgsParser arguments)
        {
            FileStream file;

            if (File.Exists(arguments.OutputFileName))
            {
                file = new FileStream($"{arguments.OutputFileName}", FileMode.Append);
            }
            else
            {
                file = new FileStream($"{arguments.OutputFileName}", FileMode.OpenOrCreate);
            }
            var consoleOutput = Console.Out;

            using (var sWriter = new StreamWriter(file))
            {
                //  Trace the console out to the file.
                Console.SetOut(sWriter);
                var analyzer = new NGramAnalyzer(2);
                analyzer.AnalyzeFile(arguments);

                //  Restore the original console output.
                Console.SetOut(consoleOutput);
            }
        }
 public void AnalyzeInputs(ArgsParser parsed)
 {
     FrequencyTable = new Dictionary <string, int>();
     foreach (var input in parsed.Inputs)
     {
         var creator        = new NGramCreator();
         var FrequencyTable = new Dictionary <string, int>();
         foreach (var nGram in creator.ParseTokens(input, NGramSize))
         {
             // Protect against potentially copying massive sized bigram strings into the dictionary as keys.
             string key;
             if (nGram.Length > 1000)
             {
                 key = nGram.Substring(0, 1000).ToLower();
             }
             else
             {
                 key = nGram.ToLower();
             }
             if (FrequencyTable.ContainsKey(key))
             {
                 FrequencyTable[key] += 1;
             }
             else
             {
                 FrequencyTable.Add(key, 1);
             }
         }
         DisplayCurrentAnalysis(FrequencyTable, input);
     }
 }
        static void Main(string[] args)
        {
            _args = args;
            if (args.Length == 0)
            {
                DisplayHelp();
                return;
            }
            var parsedArguments = new ArgsParser(args);
            var outputEnabled   = !string.IsNullOrEmpty(parsedArguments.OutputFileName);

            if (outputEnabled)
            {
                ExecuteAndLogToFile(parsedArguments);
            }
            else
            {
                ExecuteInteractively(parsedArguments);
            }
        }
        public static void ExecuteInteractively(ArgsParser arguments)
        {
            var analyzer = new NGramAnalyzer(2);

            analyzer.AnalyzeInputs(arguments);
        }