public void RollbackFileVersion(IFileInfo file, int version, int userId) { var folderMapping = FolderMappingController.Instance.GetFolderMapping(file.PortalId, file.FolderMappingID); if (folderMapping == null) { return; } var folderProvider = FolderProvider.Instance(folderMapping.FolderProviderType); var folder = FolderManager.Instance.GetFolder(file.FolderId); using (var content = GetVersionContent(folderProvider, folder, file, version)) { FileManager.Instance.AddFile(folder, file.FileName, content, true, true, file.ContentType, userId); } // We need to refresh the file object file = FileManager.Instance.GetFile(file.FileId); var fileVersion = GetFileVersion(file, version); file.Extension = fileVersion.Extension; file.Size = fileVersion.Size; file.SHA1Hash = fileVersion.SHA1Hash; file.Width = fileVersion.Width; file.Height = fileVersion.Height; FileManager.Instance.UpdateFile(file); RemoveOldestsVersions(file); }
public void SetPublishedVersion(IFileInfo file, int newPublishedVersion) { DataProvider.Instance().SetPublishedVersion(file.FileId, newPublishedVersion); DataCache.RemoveCache("GetFileById" + file.FileId); // Rename the original file to the versioned name // Rename the new versioned name to the original file name var folderMapping = FolderMappingController.Instance.GetFolderMapping(file.PortalId, file.FolderMappingID); if (folderMapping == null) { return; } var folderProvider = FolderProvider.Instance(folderMapping.FolderProviderType); folderProvider.RenameFile(file, GetVersionedFilename(file, file.PublishedVersion)); folderProvider.RenameFile( new FileInfo { FileName = GetVersionedFilename(file, newPublishedVersion), Folder = file.Folder, FolderId = file.FolderId, FolderMappingID = folderMapping.FolderMappingID, PortalId = folderMapping.PortalID }, file.FileName); // Notify File Changed OnFileChanged(file, UserController.Instance.GetCurrentUserInfo().UserID); }
public void DeleteAllUnpublishedVersions(IFileInfo file, bool resetPublishedVersionNumber) { Requires.NotNull("file", file); var folderMapping = FolderMappingController.Instance.GetFolderMapping(file.PortalId, file.FolderMappingID); if (folderMapping == null) { return; } var folderProvider = FolderProvider.Instance(folderMapping.FolderProviderType); foreach (var version in GetFileVersions(file)) { folderProvider.DeleteFile(new FileInfo { FileName = version.FileName, Folder = file.Folder, FolderMappingID = folderMapping.FolderMappingID, PortalId = folderMapping.PortalID, FolderId = file.FolderId }); DataProvider.Instance().DeleteFileVersion(version.FileId, version.Version); } if (resetPublishedVersionNumber) { file.PublishedVersion = 1; DataProvider.Instance().ResetFilePublishedVersion(file.FileId); DataCache.RemoveCache("GetFileById" + file.FileId); } }
private void LoadHashProperty() { var fileManager = (FileManager)FileManager.Instance; var currentHashCode = FolderProvider.Instance(FolderMappingController.Instance.GetFolderMapping(FolderMappingID).FolderProviderType).GetHashCode(this); if (currentHashCode != _sha1Hash) { _sha1Hash = currentHashCode; fileManager.UpdateFile(this); } }
private static void RenameFile(IFileInfo file, string newFileName) { var folderMapping = FolderMappingController.Instance.GetFolderMapping(file.PortalId, file.FolderMappingID); if (folderMapping != null) { var folderProvider = FolderProvider.Instance(folderMapping.FolderProviderType); folderProvider.RenameFile(file, newFileName); } DataCache.RemoveCache("GetFileById" + file.FileId); }
public Stream GetVersionContent(IFileInfo file, int version) { var folderMapping = FolderMappingController.Instance.GetFolderMapping(file.PortalId, file.FolderMappingID); if (folderMapping == null) { return(null); } var folderProvider = FolderProvider.Instance(folderMapping.FolderProviderType); var folder = FolderManager.Instance.GetFolder(file.FolderId); return(GetVersionContent(folderProvider, folder, file, version)); }
public int DeleteFileVersion(IFileInfo file, int version) { Requires.NotNull("file", file); int newVersion; var folderMapping = FolderMappingController.Instance.GetFolderMapping(file.PortalId, file.FolderMappingID); if (folderMapping == null) { return(Null.NullInteger); } var folderProvider = FolderProvider.Instance(folderMapping.FolderProviderType); if (file.PublishedVersion == version) { folderProvider.DeleteFile(new FileInfo { FileId = file.FileId, FileName = file.FileName, Folder = file.Folder, FolderMappingID = folderMapping.FolderMappingID, PortalId = folderMapping.PortalID, FolderId = file.FolderId }); newVersion = DataProvider.Instance().DeleteFileVersion(file.FileId, version); folderProvider.RenameFile( new FileInfo { FileId = file.FileId, FileName = GetVersionedFilename(file, newVersion), Folder = file.Folder, FolderId = file.FolderId, FolderMappingID = folderMapping.FolderMappingID, PortalId = folderMapping.PortalID }, file.FileName); //Update the Last Modification Time var providerLastModificationTime = folderProvider.GetLastModificationTime(file); if (file.LastModificationTime != providerLastModificationTime) { DataProvider.Instance().UpdateFileLastModificationTime(file.FileId, providerLastModificationTime); } // Notify File Changed OnFileChanged(file, UserController.Instance.GetCurrentUserInfo().UserID); } else { newVersion = DataProvider.Instance().DeleteFileVersion(file.FileId, version); folderProvider.DeleteFile(new FileInfo { FileName = GetVersionedFilename(file, version), Folder = file.Folder, FolderMappingID = folderMapping.FolderMappingID, PortalId = folderMapping.PortalID, FolderId = file.FolderId }); } DataCache.RemoveCache("GetFileById" + file.FileId); return(newVersion); }
public int DeleteFileVersion(IFileInfo file, int version) { Requires.NotNull("file", file); int newVersion; var folderMapping = FolderMappingController.Instance.GetFolderMapping(file.PortalId, file.FolderMappingID); if (folderMapping == null) { return(Null.NullInteger); } var folderProvider = FolderProvider.Instance(folderMapping.FolderProviderType); if (file.PublishedVersion == version) { folderProvider.DeleteFile(new FileInfo { FileId = file.FileId, FileName = file.FileName, Folder = file.Folder, FolderMappingID = folderMapping.FolderMappingID, PortalId = folderMapping.PortalID, FolderId = file.FolderId }); newVersion = DataProvider.Instance().DeleteFileVersion(file.FileId, version); folderProvider.RenameFile( new FileInfo { FileId = file.FileId, FileName = GetVersionedFilename(file, newVersion), Folder = file.Folder, FolderId = file.FolderId, FolderMappingID = folderMapping.FolderMappingID, PortalId = folderMapping.PortalID }, file.FileName); } else { newVersion = DataProvider.Instance().DeleteFileVersion(file.FileId, version); folderProvider.DeleteFile(new FileInfo { FileName = GetVersionedFilename(file, version), Folder = file.Folder, FolderMappingID = folderMapping.FolderMappingID, PortalId = folderMapping.PortalID, FolderId = file.FolderId }); } DataCache.RemoveCache("GetFileById" + file.FileId); return(newVersion); }
private Stream GetVersionContent(FolderProvider provider, IFolderInfo folder, IFileInfo file, int version) { return(provider.GetFileStream(folder, file, version)); }