Beispiel #1
0
        public static async Task Main(string[] args)
        {
            try
            {
                var arguments = ArgumentParser.ParseArguments(args);

                var scanner = new FileScanner();

                var files = scanner.GetFiles(@"^Message\d{4}-\d{2}-\d{2}\.log$");

                LogPackage package = null;
                try
                {
                    var packager = new LogPackager();
                    package = packager.CreatePackage(files);

                    var uploader = new LogUploaderClient(arguments.ServiceUrl);
                    var result   = await uploader.UploadPackageAsync(package);

                    if (result.Errors?.Any() == true)
                    {
                        Console.Error.WriteLine("Failed to upload file:");
                        foreach (var error in result.Errors)
                        {
                            Console.Error.WriteLine(error);
                        }
                    }
                }
                finally
                {
                    if (package != null)
                    {
                        package.Delete();
                    }
                }
            }
            catch (Exception exception)
            {
                Console.Error.WriteLine($"Fatal error: {exception.Message}");
            }
        }
Beispiel #2
0
        public LogPackage CreatePackage(IEnumerable <string> files)
        {
            var fileName = Path.GetTempFileName();

            using (var stream = new FileStream(fileName, FileMode.Create))
            {
                using var archive = new ZipArchive(stream, ZipArchiveMode.Create);
                int id = 1;
                foreach (var fullPath in files)
                {
                    var entryName = $"{id++}.{Path.GetFileName(fullPath)}";
                    archive.CreateEntryFromFile(fullPath, entryName, CompressionLevel.Optimal);
                }
            }

            var package = new LogPackage()
            {
                FileName = fileName,
            };

            package.SourcePaths.AddRange(files);

            return(package);
        }