public async Task <bool> ActualizeTestingDataAsync(Guid programmingTaskId) { // No need to actualize testing data if (await IsActualTestingData(programmingTaskId)) { return(true); } // Query actual testing data and it's hash code var queryResult = await _databaseContext.ProgrammingTasks .Where(t => t.Id == programmingTaskId) .Select(t => new { t.TestingData.DataPackageFile, t.TestingData.DataPackageHash }) .FirstAsync(); // Get local testing data path var testingDataLocalPath = GetTestingDataPathByProgrammingTaskId(programmingTaskId); // Delete old and create new directory for testing data FileSystemSharedMethods.SecureRecreateDirectory(testingDataLocalPath); // ReSharper disable once ConvertToUsingDeclaration await using (var fileStream = new MemoryStream(queryResult.DataPackageFile)) { // Testing data is stored as ZIP archive, we need to read it using var zipArchive = new ZipArchive(fileStream, ZipArchiveMode.Read, false, Encoding.UTF8); // Extract archive contents to newly created directory zipArchive.ExtractToDirectory(testingDataLocalPath, true); } // Save testing data hash into a file await File.WriteAllTextAsync( Path.Combine( testingDataLocalPath, _configuration.GetValue <string>("general:storage:custom_naming:hash_file") ), queryResult.DataPackageHash, Encoding.UTF8 ); // Data actualized return(true); }
public TempDirectoryAccessPoint GetTestingDataAccessPoint(Guid programmingTaskId) { _logger.Debug($"Executing {nameof(GetTestingDataAccessPoint)} method for programming task {programmingTaskId}..."); var dataDirectoryConfiguration = _configuration.GetSection("general:storage"); var testingDataPath = GetTestingDataPathByProgrammingTaskId(programmingTaskId); var temporaryAccessPointPath = Path.Combine( dataDirectoryConfiguration.GetValue <string>("path"), dataDirectoryConfiguration.GetValue <string>("custom_naming:temp_directory"), Guid.NewGuid().ToString() ); _logger.Debug($"{nameof(GetTestingDataAccessPoint)} for {programmingTaskId}: testing data access point path: {temporaryAccessPointPath}."); FileSystemSharedMethods.SecureCopyDirectory(testingDataPath, temporaryAccessPointPath); return(new TempDirectoryAccessPoint(temporaryAccessPointPath)); }
public void Dispose() { FileSystemSharedMethods.SecureDeleteDirectory(DirectoryFullName); }