public static List <FileInfoDTO> Parse(IFormFile file) { var fileInfos = new List <FileInfoDTO>(); using (var reader = new StreamReader(file.OpenReadStream())) { var doc = XDocument.Load(reader); foreach (var transaction in doc.Element("Transactions").Elements("Transaction")) { var fileInfo = new FileInfoDTO { TransactionId = transaction.Attribute("id").Value, Date = DateTime.ParseExact(transaction.Element("TransactionDate").Value, "yyyy-MM-ddTHH:mm:ss", null), Amount = decimal.Parse(transaction.Element("PaymentDetails").Element("Amount").Value), CurrencyCode = transaction.Element("PaymentDetails").Element("CurrencyCode").Value }; fileInfo.Status = transaction.Element("Status").Value switch { "Approved" => StatusTransaction.Approved, "Rejected" => StatusTransaction.Rejected, "Done" => StatusTransaction.Done, _ => fileInfo.Status }; fileInfos.Add(fileInfo); } } return(fileInfos); } }
public static List <FileInfoDTO> Parse(IFormFile file) { var fileInfos = new List <FileInfoDTO>(); using (var reader = new TextFieldParser(file.OpenReadStream())) { reader.TextFieldType = FieldType.Delimited; reader.SetDelimiters(","); while (!reader.EndOfData) { var fields = reader.ReadFields(); var fileInfo = new FileInfoDTO { TransactionId = fields[0], Amount = decimal.Parse(fields[1]), CurrencyCode = fields[2], Date = DateTime.ParseExact(fields[3], "dd/MM/yyyy HH:mm:ss", null) }; fileInfo.Status = fields[4] switch { "Approved" => StatusTransaction.Approved, "Failed" => StatusTransaction.Failed, "Finished" => StatusTransaction.Finished, _ => fileInfo.Status }; fileInfos.Add(fileInfo); } } return(fileInfos); } }
public void Dto_to_entity_works() { var dto = new FileInfoDTO(createTestEntity()); var entity = dto.ToEntity(); compareEntityToDto(entity, dto); }
public void Entity_to_dto_works() { var entity = createTestEntity(); var dto = new FileInfoDTO(entity); compareEntityToDto(entity, dto); }
void compareEntityToDto(FileInfo entity, FileInfoDTO dto) { Assert.AreEqual(entity.Path, dto.Path, "faulty Path"); Assert.AreEqual(entity.FileCreationTime, dto.FileCreationTime, "faulty FileCreationTime"); Assert.AreEqual(entity.FileHash?.Data, dto.FileHash, "faulty FileHash"); Assert.AreEqual(entity.LastWriteTime, dto.LastWriteTime, "faulty LastWriteTime"); Assert.AreEqual(entity.DirectorySetupId, (DirectorySetupId)dto.DirectorySetupId, "faulty DirectorySetupId"); Assert.AreEqual(entity.IsAccessible, dto.IsAccessible, "faulty IsAccessible"); Assert.AreEqual(entity.FileSize, dto.FileSize, "faulty FileSize"); }
public void serialization_works() { var srcEntity = createTestEntity(); var srcDto = new FileInfoDTO(srcEntity); var str = JsonSerializer.Serialize(srcDto); var dstDto = JsonSerializer.Deserialize <FileInfoDTO>(str); var dstEntity = dstDto.ToEntity(); compareEntities(srcEntity, dstEntity); }
private void DeleteFile(FileInfoDTO file) { if (file == null) { return; } string fullPath = Path.Combine(HttpContext.Current.Server.MapPath("~/Files/Assignments"), file.FileGuid); if (File.Exists(fullPath)) { File.Delete(fullPath); } }
public static FileInfo ConvertToFileInfo(FileInfoDTO fileInfoDto) { if (fileInfoDto == null) { throw new ArgumentNullException(); } return(new FileInfo { Id = fileInfoDto.Id, Name = fileInfoDto.Name, ContentType = fileInfoDto.ContentType, SizeKB = fileInfoDto.SizeKB }); }
public static CreateFileRequest ConvertToCreateFileRequest(FileInfoDTO file) { if (file == null) { throw new ArgumentNullException(nameof(file)); } var createFileRequest = new CreateFileRequest { ContentType = file.ContentType, Name = file.Name, SizeKB = file.SizeKB }; return(createFileRequest); }
public static PostFile ConvertToPostFile(FileInfoDTO fileDTO) { var postFile = new PostFile { File = new FileInfo { Id = fileDTO.Id, Name = fileDTO.Name, ContentType = fileDTO.ContentType, SizeKB = fileDTO.SizeKB } }; return(postFile); }
public static FileInfoDTO ConvertToFileInfoDTO(FileInfoViewModel file) { if (file == null) { throw new ArgumentNullException(nameof(file)); } var fileInfoDTO = new FileInfoDTO() { Id = file.Id, Name = file.Name, ContentType = file.ContentType, SizeKB = file.SizeKB }; return(fileInfoDTO); }