Beispiel #1
0
        static void Main(string[] args)
        {
            FileInfo = new FileInformation();


            while (ValueFormatter.isEmpty(FileInfo.InputFileName))
            {
                Out.WriteLine("Please copy and paste file path in .csv or .tsv format");
                FileInfo.InputFileName = ReadLine();
            }

            FileInfo.ReadResults = GetFileName.ReadFileName(FileInfo.InputFileName);



            string numberOfFields = null;
            int    temp2;

            while (ValueFormatter.isEmpty(numberOfFields) || !int.TryParse(numberOfFields, out temp2))
            {
                WriteLine("Enter number of fields");
                numberOfFields = ReadLine();
            }

            int fieldsInRecords = 0;

            try
            {
                fieldsInRecords         = Convert.ToInt32(numberOfFields);
                FileInfo.NumberOfFields = fieldsInRecords;

                FileInfo.Results    = GetLines.ReturnDetailRecords(FileInfo.ReadResults);
                FileInfo.NewResults = FileInfo.Results.Skip(1).ToList();
                char delimiter = GetFileName.CheckFileName(FileInfo.InputFileName);
                //Once you run this, it'll write the files to your bin direcotry
                FileInfo.EnvironmentDirectory = WriteToFile.GetEnvironmentDirectory();

                foreach (var rec in FileInfo.NewResults)
                {
                    var returnedFields  = GetLines.ReturnFields(rec, delimiter);
                    var isRecordCorrect = GetLines.GetFieldCount(returnedFields, fieldsInRecords);
                    if (isRecordCorrect == false)
                    {
                        var pathCombined = Path.Combine(FileInfo.EnvironmentDirectory, "errorrecs.txt");
                        Out.WriteLine($"directory is {pathCombined}");
                        WriteToFile.WriteErrorsToFile(pathCombined, rec);
                    }
                    else
                    {
                        var pathCombined = Path.Combine(FileInfo.EnvironmentDirectory, "correct.txt");
                        Out.WriteLine($"directory is {pathCombined}");
                        WriteToFile.WriteErrorsToFile(pathCombined, rec);
                    }
                }

                Console.WriteLine($"the delimiter is {delimiter}");
                Console.WriteLine(FileInfo.NewResults.Count);
            }
            catch (System.FormatException fe)
            {
                Out.WriteLine($"No fields were read {fe}");
            }

            Console.Out.WriteLine("Bonsoir, Elliot");
            Console.ReadKey();
        }