private void LegacyDbDumpReader_RecordsForDayRead(object sender, RecordsForDayReadEventArgs e)
        {
            loggingService.LogDebug($"Batch Read: {e.Records.First().Date} - {e.Records.Count()} record(s)");

            // Map the data
            var statsData = dataMappingService.MapData(e.Records);

            // Build filenames
            var filename   = $"FoldingStatsData-{e.Records.First().Date.ToString("yyyyMMdd")}.txt";
            var path       = fileSystemOperationsService.GetTempPath();
            var fullPath   = Path.Combine(path, filename);
            var targetPath = Path.Combine(outputPath, filename + fileCompressionService.FileExt);

            // Remove intermediate file, if it already exists
            DeleteFileIfExists(fullPath);

            // Write the data in stats file format
            statsDataWriter.Write(statsData, e.Records.First().Date, fullPath);

            try
            {
                // Compress the stats file
                var tempFile = fileSystemOperationsService.GetTempFilename();
                fileCompressionService.CompressFile(fullPath, tempFile);

                // Move to output folder
                fileSystemOperationsService.MoveFile(tempFile, targetPath);
            }
            finally
            {
                // Cleanup
                DeleteFileIfExists(fullPath);
            }
        }
Example #2
0
        private async void CompressButton_Click(object sender, EventArgs e)
        {
            await RunActionAsync(() =>
            {
                string compressDirectory = CompressDirectoryTextBox.Text;

                if (!Directory.Exists(compressDirectory))
                {
                    Log(
                        $"The directory does not exist, provide a new directory and try again. Directory: '{compressDirectory}'");
                    return(Task.CompletedTask);
                }

                string[] importFiles = Directory.GetFiles(compressDirectory, "*.txt", SearchOption.TopDirectoryOnly);

                if (importFiles.Length == 0)
                {
                    Log(
                        $"There are no text files in the top directory, provide a directory with files to compress and try again. Directory: '{compressDirectory}'");
                    return(Task.CompletedTask);
                }

                int filesRemaining = importFiles.Length;

                IFileCompressionService fileCompressionService = null;
                try
                {
                    fileCompressionService = WindsorContainer.Instance.Resolve <IFileCompressionService>();

                    Log($"'{filesRemaining}' files are to be imported");

                    foreach (string importFile in importFiles)
                    {
                        fileCompressionService.CompressFile(importFile, $"{importFile}.bz2");
                        filesRemaining--;
                        Log($"File imported. '{filesRemaining}' remaining files to be imported");
                    }
                }
                finally
                {
                    WindsorContainer.Instance.Release(fileCompressionService);
                }

                return(Task.CompletedTask);
            });
        }
 public void CompressFile(string filePath, string compressedFilePath)
 {
     innerService.CompressFile(filePath, compressedFilePath);
 }