public void DeleteFile(Guid id) { var file = repository.FindById(id); store.Delete(file.Path, file.Name); repository.Delete(id); }
/// <summary> /// Удаляет файл /// </summary> /// <param name="idFile">Id файла, по которому будет производиться удаление</param> /// <returns></returns> public async Task DeleteAsync(Guid idFile) { var result = await _context.Files.SingleOrDefaultAsync(x => x.FileId == idFile); if (result == null) { throw new NullReferenceException($"Файла с таким id({idFile}) нету."); } await _fileStore.Delete(idFile.ToString()); _context.Files.Remove(result); await _context.SaveChangesAsync(); }
/// <summary> /// Will process the report generated by the Compare methods by adding, removing and updating files to the <paramref name="destStore"/> file store. /// </summary> /// <param name="report">The report, generated by one of the Compare methods, to process.</param> /// <param name="sourcePath">The source directory to process.</param> /// <param name="destStore">The file store to process.</param> /// <param name="feedback">Provides a means to gather feedback from the mirroring process.</param> public static void MirrorSourceToDestination( IEnumerable <ICompareResult> report, string sourcePath, IFileStore destStore, Action <ICompareResult, double> feedback) { // **** initialize var total = (from x in report where x.ItemType == CompareType.File && (x.Action == CompareAction.New || x.Action == CompareAction.Update || x.Action == CompareAction.Remove) select x).Count(); var count = 0; // **** save the original 'original filenames' var originalFilenames = ((IFileStoreAdvanced)destStore).GetOriginalFilenames(); // **** delete REMOVE files from MIRROR foreach (var item in from x in report where x.ItemType == CompareType.File && x.Action == CompareAction.Remove select x) { if (feedback != null) { feedback(item, (double)((double)count / (double)total)); ++count; } if (destStore.Contains(item.DestinationRootFilename)) { destStore.Delete(item.DestinationRootFilename); } } // **** add NEW and UPDATE files to SOURCE foreach (var item in from x in report where x.ItemType == CompareType.File && (x.Action == CompareAction.New || x.Action == CompareAction.Update) select x) { if (feedback != null) { feedback(item, (double)((double)count / (double)total)); ++count; } destStore.Add(item.SourceRootFilename, item.SourceFullPath, item.SourceLastModifiedTimeUtc, item.SourceFileSizeInBytes); } // **** save store (finalize mirror process) feedback?.Invoke(null, 1); destStore.Save(false); // **** clear/restore the 'original filenames' ((IFileStoreAdvanced)destStore).ClearOriginalFilenames(); ((IFileStoreAdvanced)destStore).SetOriginalFilenames(originalFilenames); }
public void Delete(FileId id) { ExceptionHelper.ThrowIfNull(id, "id"); _FileStore.Delete(id); }
/// <summary> /// Will process the report generated by the Compare methods by adding, removing and updating files to the <paramref name="destStore"/> file store. /// </summary> /// <param name="report">The report, generated by one of the Compare methods, to process.</param> /// <param name="sourceStore">The file store to process.</param> /// <param name="destStore">The file store to process.</param> /// <param name="feedback">Provides a means to gather feedback from the mirroring process.</param> public static void MirrorSourceToDestination( IEnumerable <ICompareResult> report, IFileStore sourceStore, IFileStore destStore, Action <ICompareResult, double> feedback) { // **** initialize var total = (from x in report where x.ItemType == CompareType.File && (x.Action == CompareAction.New || x.Action == CompareAction.Update || x.Action == CompareAction.Remove) select x).Count(); var count = 0; // create temporary extraction folder var tempPath = CreateTemporaryDirectory(); // temporarily change source extraction path var originalExtractionPath = sourceStore.ExtractionRootDirectory; sourceStore.ExtractionRootDirectory = tempPath; // save the original 'original filenames' var originalFilenames = ((IFileStoreAdvanced)destStore).GetOriginalFilenames(); // **** extract NEW and UPDATE files from SOURCE to temporary extraction folder var list = new List <IFileStoreItem>(); foreach (var item in from x in report where x.ItemType == CompareType.File && (x.Action == CompareAction.New || x.Action == CompareAction.Update) select x) { if (feedback != null) { feedback(item, (double)((double)count / (double)total)); ++count; } if (sourceStore.Contains(item.SourceRootFilename)) { list.Add(sourceStore.Get(item.SourceRootFilename)); } } sourceStore.Extract(list, true); // **** delete REMOVE files from MIRROR foreach (var item in from x in report where x.ItemType == CompareType.File && x.Action == CompareAction.Remove select x) { if (feedback != null) { feedback(item, (double)((double)count / (double)total)); ++count; } if (destStore.Contains(item.DestinationRootFilename)) { destStore.Delete(item.DestinationRootFilename); } } // **** add/update NEW and UPDATE files, from temporary extraction folder, into MIRROR foreach (var item in list) { destStore.Add(item.RootFilename, item.ExtractedFilename, item.RootFileLastModifiedTimeUtc, item.FileSize); } // **** save store (finalize mirror process) destStore.Save(false); // **** clear/restore the 'original filenames' ((IFileStoreAdvanced)destStore).ClearOriginalFilenames(); ((IFileStoreAdvanced)destStore).SetOriginalFilenames(originalFilenames); // **** restore original source extraction path sourceStore.ExtractionRootDirectory = originalExtractionPath; // **** delete temporary extraction folder DeleteDirectory(tempPath); }