private async Task <TestEnvironmentOutputFilesInfo> PrepareOutputFilesAsync() { var tempFolder = Path.Combine(HostingEnvironment.MapPath($"/Temp/TestEnvironment/OutputFiles/{Guid.NewGuid()}")); Directory.CreateDirectory(tempFolder); var fileNames = await Task.WhenAll(_outputFileRepository.GetAll() .Select(x => new { FileName = x.FileId, ResourceName = GetFullResourceName(x.FileId) }) .Where(x => x.ResourceName != null) .Select(async x => { using (var resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(x.ResourceName)) { using (var fileStream = new FileStream(Path.Combine(tempFolder, x.FileName), FileMode.Create)) { await resourceStream.CopyToAsync(fileStream).ConfigureAwait(false); await fileStream.FlushAsync().ConfigureAwait(false); } } return(x.FileName); })).ConfigureAwait(false); return(new TestEnvironmentOutputFilesInfo() { LocalFolder = tempFolder, FileNames = fileNames }); }
/// <summary> /// Validate output files for starting run. Only files defined in /// IOutputFilesRepository are processed. /// </summary> /// <param name="run"></param> private List <SystemMessage> ValidateOutputFilesForStartRun(Run run) { List <SystemMessage> messages = new List <SystemMessage>(); var outputFiles = _outputFileRepository.GetAll(); if (outputFiles == null || !outputFiles.Any()) { messages.Add(FormatSystemMessage(SystemMessage.OutputFileDataMissing)); } return(messages); }
/// <summary> /// Returns all output files referenced by the SQL. /// /// It is possible that this function might return files that it /// shouldn't. It just means an un-necessary Raven file download /// </summary> /// <param name="sql"></param> /// <returns></returns> private List <OutputFile> GetOutputFilesForSQL(string sql) { List <OutputFile> outputFilesFound = new List <OutputFile>(); foreach (OutputFile outputFile in _outputFileRepository.GetAll()) { if (sql.ToUpper().Contains(outputFile.QueryFileName.ToUpper())) { outputFilesFound.Add(outputFile); } } return(outputFilesFound); }
public IEnumerable <OutputFile> GetAll() => _outputFileRepository.GetAll();