Example #1
0
        public static async Task Main(string[] args)
        {
            var builder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
            var config  = builder.Build();

            TelemetryConfiguration telemetryConfig = TelemetryConfiguration.CreateDefault();

            telemetryConfig.InstrumentationKey = config.GetSection("ApplicationInsights:InstrumentationKey").Value;
            TelemetryClient telemetryClient = new TelemetryClient(telemetryConfig);

            try
            {
                Setup.SetCulture();

                AzureFileStorageClient fileStorageClient = new AzureFileStorageClient();
                await fileStorageClient.DownloadFile();

                //if (Directory.Exists(config["FilesDirectory"]))
                //{
                //    DirectoryInfo dirInfo = new DirectoryInfo(config["FilesDirectory"]);
                //    foreach (string filePath in Directory.EnumerateFiles(config["FilesDirectory"], "*.txt"))
                //    {
                //        var lines = File.ReadLines(filePath);
                //        int lineCount = lines.Count();
                //        int count = 0;
                //        bool isContent;
                //        if (lineCount > 2)
                //        {
                //            foreach (string line in lines)
                //            {
                //                count++;
                //                isContent = (count > 1 && count < lineCount);

                //                if (isContent)
                //                {
                //                    Empregado empregado = new Empregado(line, count);
                //                    Console.WriteLine(string.Format("Fim do processamento da linha {0}", count));
                //                }
                //            }
                //            Console.WriteLine("Fim do processamento do arquivo \"{0}\"", filePath);
                //        }
                //        else
                //        {
                //            throw new FileLoadException("O arquivo não pode ser processado pois deve conter no mínimo três linhas: header, conteúdo e trailer.");
                //        }
                //    }
                //}

                Console.ReadKey();
            }
            catch (Exception ex)
            {
                telemetryClient.TrackException(ex);
            }
        }
Example #2
0
        public static async Task Main(string[] args)
        {
            do
            {
                var builder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
                var config  = builder.Build();

                TelemetryConfiguration telemetryConfig = TelemetryConfiguration.CreateDefault();
                telemetryConfig.InstrumentationKey = config.GetSection("ApplicationInsights:InstrumentationKey").Value;
                TelemetryClient telemetryClient = new TelemetryClient(telemetryConfig);

                try
                {
                    Setup.SetCulture();

                    AzureFileStorageClient fileStorageClient = new AzureFileStorageClient();
                    var cloudFiles = await fileStorageClient.GetFiles();

                    //if (Directory.Exists(config["FilesDirectory"]))
                    //{
                    //    DirectoryInfo dirInfo = new DirectoryInfo(config["FilesDirectory"]);
                    foreach (CloudFile cloudFile in cloudFiles)
                    {
                        //var lines = File.ReadLines(filePath);
                        //string lines = cloudFile.DownloadTextAsync().Result;

                        FileInfo f = new FileInfo(Path.Combine(@"D:\OneDrive\Novo", Path.GetFileName(cloudFile.Name) + "111.txt"));
                        //File.Create(Path.Combine(@"\\FELIPE-DELLG7\Temp\", Path.GetFileName(cloudFile.Name)));
                        if (File.Exists(f.FullName))
                        {
                            StreamReader stream = new StreamReader(f.FullName);
                            //using (var stream = await cloudFile.OpenReadAsync())
                            {
                                int    count = 0;
                                bool   isContent;
                                string line;

                                //if (lineCount > 2)
                                //{
                                //using (StreamReader reader = new StreamReader(stream))
                                //{
                                while (!stream.EndOfStream)
                                {
                                    Console.WriteLine();
                                    line = stream.ReadLine();
                                    count++;
                                    isContent = count > 1;

                                    if (isContent)
                                    {
                                        string    realFileName = cloudFile.Name.Substring(cloudFile.Name.LastIndexOf("/") + 1);
                                        Empregado empregado    = new Empregado(line, count, realFileName);
                                        Console.WriteLine(string.Format("Fim do processamento da linha {0}", count));
                                    }
                                }
                                //Console.WriteLine("Fim do processamento do arquivo \"{0}\"", cloudFile.Name);
                                //}
                                //}
                                //else
                                //{
                                //    throw new FileLoadException("O arquivo não pode ser processado pois deve conter no mínimo três linhas: header, conteúdo e trailer.");
                                //}
                            }
                            stream.Close();

                            // se sucesso
                            string newFileName     = Path.GetFileName(cloudFile.Name) + "111.txt";
                            string originPath      = Path.Combine(@"D:\OneDrive\Novo", newFileName);
                            string destinationPath = Path.Combine(@"D:\OneDrive\Parcialmentebemsucedido", newFileName);
                            File.Move(originPath, destinationPath);
                        }

                        //File.Move(Path.Combine(@"\\FELIPE-DELLG7\Temp\", Path.GetFileName(cloudFile.Name)), Path.Combine(@"\\FELIPE-DELLG7\Temp2\", Path.GetFileName(cloudFile.Name)));
                    }

                    //Console.ReadKey();
                }
                catch (Exception ex)
                {
                    telemetryClient.TrackException(ex);
                }

                Thread.Sleep(1000);
            } while (true);
        }