Beispiel #1
0
        /// <summary>
        /// Reads, inserts and create reports for each register in the file
        /// </summary>
        /// <param name="filePath"> file you wnat to read </param>
        public static void ReadFile(string filePath, List <bool> checkList)
        {
            int count = 1;

            try
            {
                foreach (string line in File.ReadLines(filePath, Encoding.UTF8))
                {
                    try
                    {
                        if (count != 1)
                        {
                            try
                            {
                                User     currentUser          = LineToModel(line);
                                DateTime currentUserBirthdate = currentUser.BirthDate.Value;
                                if (checkList[0])
                                {
                                    Thread thread1 = new Thread(() => InsertDB.Excecute(currentUser));
                                    thread1.Start();
                                }
                                if (checkList[1])
                                {
                                    Thread thread2 = new Thread(() => ReportLibrary.Report.GenerateReport(writePath + currentUser.Id + ".csv", currentUser.GetUserInfo()));
                                    thread2.Start();
                                }
                                if (checkList[2])
                                {
                                    Thread thread3 = new Thread(() => Log.ShowInformationMessage("User: (id:" + currentUser.Id + ",age:" + DateUtils.CalculateAge(currentUserBirthdate) + ")"));
                                    thread3.Start();
                                }
                            }
                            catch (Exception processException)
                            {
                                Log.ShowErrorMessage("Error excecuting the processes: " + processException.ToString());
                            }
                        }
                    }
                    catch
                    {
                        Log.ShowErrorMessage("Error reading line: " + count);
                    }
                    count++;
                }
            }
            catch
            {
                Log.ShowErrorMessage("Can´t read correctly the file: " + filePath);
            }
        }