/// <summary> /// Appends supplied binary data chunk to file. /// </summary> /// <param name="itemId">Item id to obtain realted service id.</param> /// <param name="fileName">Non existent file name to append to.</param> /// <param name="path">Full path to existent file to append to.</param> /// <param name="chunk">Binary data chunk to append to.</param> /// <returns>Path to file that was appended with chunk.</returns> public static string AppendBackupBinaryChunk(int itemId, string fileName, string path, byte[] chunk) { // Load original meta item. SharePointEnterpriseSiteCollection item = (SharePointEnterpriseSiteCollection)PackageController.GetPackageItem(itemId); if (item == null) { return(null); } HostedSharePointServerEnt hostedSharePointServer = GetHostedSharePointServer(item.ServiceId); return(hostedSharePointServer.Enterprise_AppendTempFileBinaryChunk(fileName, path, chunk)); }
/// <summary> /// Restores SharePoint site collection. /// </summary> /// <param name="itemId">Site collection id within metabase.</param> /// <param name="uploadedFile"></param> /// <param name="packageFile"></param> /// <returns></returns> public static int RestoreSiteCollection(int itemId, string uploadedFile, string packageFile) { // Check account. int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) { return(accountCheck); } // Load original meta item. SharePointEnterpriseSiteCollection origItem = (SharePointEnterpriseSiteCollection)PackageController.GetPackageItem(itemId); if (origItem == null) { return(BusinessErrorCodes.ERROR_SHAREPOINT_PACKAGE_ITEM_NOT_FOUND); } // Check package. int packageCheck = SecurityContext.CheckPackage(origItem.PackageId, DemandPackage.IsActive); if (packageCheck < 0) { return(packageCheck); } // Log operation. TaskManager.StartTask("HOSTED_SHAREPOINT_ENTERPRISE", "BACKUP_SITE_COLLECTION", origItem.Name, itemId); try { // Create site collection on server. HostedSharePointServerEnt hostedSharePointServer = GetHostedSharePointServer(origItem.ServiceId); string backupFile = null; if (!String.IsNullOrEmpty(packageFile)) { // Copy package files to the remote SharePoint Server. string path = null; byte[] buffer = null; int offset = 0; do { // Read package file. buffer = FilesController.GetFileBinaryChunk(origItem.PackageId, packageFile, offset, FILE_BUFFER_LENGTH); // Write remote backup file string tempPath = hostedSharePointServer.Enterprise_AppendTempFileBinaryChunk(Path.GetFileName(packageFile), path, buffer); if (path == null) { path = tempPath; backupFile = path; } offset += FILE_BUFFER_LENGTH; }while (buffer.Length == FILE_BUFFER_LENGTH); } else if (!String.IsNullOrEmpty(uploadedFile)) { // Upladed files. backupFile = uploadedFile; } // Restore. if (!String.IsNullOrEmpty(backupFile)) { hostedSharePointServer.Enterprise_RestoreSiteCollection(origItem, backupFile); } return(0); } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }