/// <summary> /// /// </summary> public void ManagerFile() { var pagedResult = _operations.GetPaged(1, 100); var files = pagedResult.Results.ToList(); byte[] buffer = new byte[4096]; int len; files.ForEach(file => { Parallel.Invoke(() => { file.Status = Infrastructure.Enums.FileStatus.InProcess; file.ProcessDate = DateTime.Now; file.InitialDate = DateTime.Now; _operations.Update(file.Key.ToString(), _mapper.Map <FileDataContract>(file)); }); try { using (var originStream = new FileStream($"{file.OriginPath}{file.Name}", FileMode.OpenOrCreate)) { using (var destinyStream = new FileStream($"{file.DestinyPath}{file.Name}", FileMode.CreateNew)) { while ((len = originStream.Read(buffer, 0, buffer.Length)) > 0) { destinyStream.Write(buffer, 0, len); } } } Parallel.Invoke(() => { file.FinishProcessDate = DateTime.Now; if (VerifyCheckSumBetweenFiles($"{file.OriginPath}{file.Name}", $"{file.DestinyPath}{file.Name}", out string result)) { file.Checksum = result; file.Status = Infrastructure.Enums.FileStatus.Moved; } else { file.Checksum = result; file.Status = Infrastructure.Enums.FileStatus.Error; } _operations.Update(file.Key.ToString(), _mapper.Map <FileDataContract>(file)); } ); } catch (SystemException ex) { throw new Exception(ex.Message); } }); }
public ActionResult Get(int page, int size, [FromServices] IFileOperations operations) { try { var result = operations.GetPaged(page, size); if (result == null) { return(NotFound("Files", "")); } return(OkWithSuccess(result)); } catch { return(BadRequest()); } }