Beispiel #1
0
        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);
        }