Ejemplo n.º 1
0
        public void fileReader(string path)
        {
            List <VendedorModel> Salesman = new List <VendedorModel>();
            List <ClienteModel>  Client   = new List <ClienteModel>();
            List <VendaModel>    Sale     = new List <VendaModel>();
            Stream stream = null;

            try
            {
                FileInfo fl = new FileInfo(path);
                while (IsFileLocked(fl))
                {
                    Thread.Sleep(2000);
                }

                stream = new FileStream(path, FileMode.OpenOrCreate);

                // Open the text file using a stream reader.
                using (var sr = new StreamReader(stream))
                {
                    stream = null;
                    while ((line = sr.ReadLine()) != null)
                    {
                        var lineArr = line.Split("ç");
                        if (line.Length > 0)
                        {
                            switch (line.Split("ç")[0])
                            {
                            case "001":
                                Salesman.Add(DataProcess.SalesmanProcess(lineArr));
                                break;

                            case "002":
                                Client.Add(DataProcess.ClientProcess(lineArr));
                                break;

                            case "003":
                                Sale.Add(DataProcess.SaleProcess(lineArr));
                                break;

                            default:
                                Console.WriteLine("Default case");
                                break;
                            }
                        }
                    }
                }
            }
            catch (IOException ex)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (stream != null)
                {
                    stream.Dispose();
                }
            }

            createOutFile(generateAnalytics.AnalyticProcess(Sale, Client, Salesman), Path.GetFileNameWithoutExtension(path));
        }