//Move Document public async Task MoveDocumentAsync(MetadataEntity meta, string newStorProvider) { try { var origStor = _config.Stors.FirstOrDefault(s => s.ShortName == meta.StorName).GetStorFromConfig(); var newStor = _config.Stors.FirstOrDefault(s => s.ShortName == newStorProvider).GetStorFromConfig(); if (String.IsNullOrWhiteSpace(origStor.ShortName)) { throw new Exception("Unable to find old stor within config"); } if (String.IsNullOrWhiteSpace(newStor.ShortName)) { throw new Exception("Unable to find new stor within config"); } var fileName = meta.GetServerFileName(); string hash; using (var origStream = await origStor.GetFileAsync(fileName)) { await newStor.SetFileAsync(fileName, origStream); hash = await newStor.GetFileHashAsync(fileName); if (hash != meta.MD5Hash) { await newStor.RemoveFileAsync(fileName); throw new Exception("File transfer failed MD5 hash is not equal"); } } await origStor.RemoveFileAsync(fileName); } catch (Exception ex) { throw new Exception("Unable to move document", ex); } }
//Rename public async Task RenameFileAsync(MetadataEntity oldFile, MetadataEntity newFile) { IStor stor = _config.Stors.First(s => s.ShortName == oldFile.StorName).GetStorFromConfig(); var oldFileName = oldFile.GetServerFileName(); var newFileName = newFile.GetServerFileName(); await stor.RenameFileAsync(oldFileName, newFileName); }
//Gets public async Task <Stream> GetDocumentAsync(MetadataEntity meta) { var stor = _config.Stors.First(s => s.ShortName == meta.StorName).GetStorFromConfig(); var fileName = meta.GetServerFileName(); var stream = await stor.GetFileAsync(fileName); return(stream); }
//Uploads all return MD5 public async Task <string> SetDocumentAsync(MetadataEntity meta, Stream doc) { var stor = _config.Stors.First(s => s.ShortName == meta.StorName).GetStorFromConfig(); var fileName = meta.GetServerFileName(); await stor.SetFileAsync(fileName, doc); var hash = await stor.GetFileHashAsync(fileName); return(hash); }
public async Task <IActionResult> Delete(int id) { string currentUser = HttpContext.User.Identity.Name; MetadataEntity origItem = _metadataRepository.GetById(id, true, true); if (origItem == null) { return(_securityRepository.GateNotFound(currentUser, AccessLogAction.DocumentDelete, "Metadata", id.ToString())); } if (!_securityRepository.UserIsAuthorisedByBuisnessAreas(HttpContext, AuthActions.Delete, origItem.BuisnessArea)) { return(_securityRepository.GateUnathorised(currentUser, AccessLogAction.DocumentDelete, "Metadata", id.ToString())); } foreach (var oldVer in origItem.Versions) { await _documentRepository.DeleteDocumentVersionAsync(oldVer); _logger.Log(LogLevel.Debug, "Document File:'{0}' Deleted By {1}", oldVer.GetServerFileName(), currentUser); _securityRepository.LogUserAction(currentUser, AccessLogAction.DocumentVersionDelete, oldVer.Id, "DocumentVersion", true); } await _documentRepository.DeleteDocumentAsync(origItem); _logger.Log(LogLevel.Debug, "Document File:'{0}' Deleted By {1}", origItem.GetServerFileName(), currentUser); _metadataRepository.Delete(origItem); _logger.Log(LogLevel.Debug, "Document {0} Deleted By {1}", origItem.Id, currentUser); _securityRepository.LogUserAction(currentUser, AccessLogAction.DocumentDelete, id, "Document", true); _metadataRepository.SaveChanges(); return(Ok()); }
//Deletes public async Task DeleteDocumentAsync(MetadataEntity meta) { IStor stor = _config.Stors.First(s => s.ShortName == meta.StorName).GetStorFromConfig(); var fileName = meta.GetServerFileName(); await stor.RemoveFileAsync(fileName); }