Пример #1
0
        public static int RunCSVProcessing(string filePath)
        {
            List <String> csvRows = new List <string>();
            int           counter = 1;

            Console.Write($"Found {filePath} !");
            try
            {
                Console.WriteLine();
                Console.Write($"Processing ....");
                MemoryStream fileMemory = new MemoryStream(Encoding.ASCII.GetBytes(File.ReadAllText(filePath)));
                StreamReader fileStream = new StreamReader(fileMemory);
                while ((fileLine = fileStream.ReadLine()) != null)
                {
                    counter++;
                    if (counter % 50 == 0)
                    {
                        Console.Write(".");
                    }
                    csvRows.Add(CSVProcessor.ProcessCSVFile(fileLine));
                }

                Console.WriteLine($"Processed {filePath}");
                StoreCSV(filePath, csvRows);
                Console.WriteLine($"Stored {Path.GetFileName(filePath)} \n");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error converting {filePath}: " + ex.Message);
                throw;
            }
            return(1);
        }
Пример #2
0
        static void Main(string[] args)
        {
            Flavour.ConfigureConsole();
            CSVProcessor.CheckOrCreateOutputDirectory();

            Thread.Sleep(600);
            Console.WriteLine("Press any key to continue");
            Console.ReadKey();
            Console.Clear();
            Console.WriteLine("\n \n   Enter file path \n");
            var folderLocation = Console.ReadLine();

            Console.WriteLine("Starting .. \n");
            Thread.Sleep(300);

            bool pathInvalid = true;

            while (pathInvalid)
            {
                try
                {
                    filePaths = Directory.GetFiles(folderLocation, "*.csv",
                                                   SearchOption.TopDirectoryOnly);
                    pathInvalid = false;
                }
                catch (Exception ex)
                {
                    Console.Clear();
                    Console.WriteLine("Uhm..");
                    Console.WriteLine(ex.Message);
                    Console.WriteLine();
                    Console.WriteLine("Press any key to continue");
                    Console.ReadKey();
                    Console.Clear();
                    Console.WriteLine("\n \n   Enter file path \n");
                    folderLocation = Console.ReadLine();
                    Console.WriteLine("Starting .. \n");
                }
            }

            int csvProcessedCount = 0;

            foreach (var filePath in filePaths)
            {
                try
                {
                    csvProcessedCount += CSVProcessor.RunCSVProcessing(filePath);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Error occured processing {filePath}!!:" + e.Message);
                    Console.WriteLine("Continuing");
                    continue;
                }
            }

            Console.WriteLine($"\n\nProcessed {csvProcessedCount} documents successfully ! :)");
            Console.WriteLine("Files will be in your output folder");
            var dir = Environment.CurrentDirectory + "\\output";

            Process.Start("explorer.exe", $"/open, {dir}");
            Console.ReadKey();
            Console.WriteLine();
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }