Example #1
0
        static void Main(string[] args)
        {
            do
            {
                InfoWriter.WriteToFile(args);

                Console.WriteLine();
                Console.WriteLine("To continue press Enter. To stop press Escape");
            }while (Console.ReadKey().Key != ConsoleKey.Escape);
        }
        /// <summary>
        /// This is main method for work. It just gets rougth params from cmd and does all needed work
        /// </summary>
        /// <param name="args"></param>
        public static void WriteToFile(string[] args)
        {
            try
            {
                string   pathInput, pathOutput;
                string[] flags;

                ArgumentsParser.ParseArguments(args, out flags, out pathInput);
                pathOutput = InfoWriter.readFileName("Input path for output file: ");

                string[] linesInput;
                if (pathInput == null)
                {
                    Console.WriteLine();
                    Console.WriteLine("Input text in Console. To stop enter empty line");
                    linesInput = FileParser.GetAllLines();
                }
                else
                {
                    linesInput = FileParser.GetAllLines(pathInput);
                }

                string[] linesOutput = (string[])linesInput.Clone();

                if (checkForExisting(flags, "-c"))
                {
                    linesOutput = removeEmptyLines(trueWordsPlusSeparators(linesOutput));
                }
                if (checkForExisting(flags, "-s"))
                {
                    linesOutput = removeEmptyLines(stayOnlyOneSeparator(linesOutput));
                }
                if (!checkForExisting(flags, "-q"))
                {
                    File.WriteAllLines(pathOutput, linesOutput);
                }
                if (checkForExisting(flags, "-p"))
                {
                    outputStaticInformation(linesInput, linesOutput);
                }
                if (checkForExisting(flags, "-l"))
                {
                    outputLengthInformation(linesInput);
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
        }