public void MoveFile(string fromVirtualPath, string destinationVirtualPath) { var source = FileSystemPath.File(fromVirtualPath); var target = FileSystemPath.File(destinationVirtualPath); using (var trx = Session.BeginTransaction()) { AssertParentExists(target); var file = GetSpecificItem(source); file.Path = target; file.Updated = Utility.CurrentTime(); trx.Commit(); } if (FileMoved != null) { FileMoved.Invoke(this, new FileEventArgs(destinationVirtualPath, fromVirtualPath)); } }
public void CopyFile(string fromVirtualPath, string destinationVirtualPath) { var source = FileSystemPath.File(fromVirtualPath); var target = FileSystemPath.File(destinationVirtualPath); var s = Session; using (var trx = s.BeginTransaction()) { AssertParentExists(target); var file = GetSpecificItem(source); var copy = new FileSystemItem { Path = target, Length = file.Length, Created = Utility.CurrentTime(), Updated = Utility.CurrentTime() }; s.Save(copy); foreach (var sourceChunk in GetChunks(file)) { var chunkCopy = CreateChunk(copy, sourceChunk.Offset, sourceChunk.Data); s.Save(chunkCopy); s.Flush(); s.Evict(sourceChunk); s.Evict(chunkCopy); } trx.Commit(); } if (FileCopied != null) { FileCopied.Invoke(this, new FileEventArgs(destinationVirtualPath, fromVirtualPath)); } }
public void DeleteFile(string virtualPath) { using (var trx = Session.BeginTransaction()) { var path = FileSystemPath.File(virtualPath); var file = GetSpecificItem(path); int deletedChunks = Session.CreateQuery("delete from " + typeof(FileSystemChunk).Name + " where BelongsTo = :file") .SetParameter("file", file) .ExecuteUpdate(); Session.Delete(file); logger.Debug("Deleted 1 item and " + deletedChunks + " chunks at " + path); trx.Commit(); } if (FileDeleted != null) { FileDeleted.Invoke(this, new FileEventArgs(virtualPath, null)); } }
public bool FileExists(string virtualPath) { var path = FileSystemPath.File(virtualPath); var item = GetSpecificItem(path); return item != null && item.Length.HasValue; }