public override object Clone() { var clone = (ChunkedUploadSession)MemberwiseClone(); clone.File = (File)File.Clone(); return(clone); }
private File SaveConvertedFile(File file, string convertedFileUrl) { var fileSecurity = FileSecurity; var fileDao = DaoFactory.FileDao; var folderDao = DaoFactory.FolderDao; File newFile = null; var newFileTitle = FileUtility.ReplaceFileExtension(file.Title, FileUtility.GetInternalExtension(file.Title)); if (!FilesSettingsHelper.StoreOriginalFiles && fileSecurity.CanEdit(file)) { newFile = (File)file.Clone(); newFile.Version++; } else { var folderId = GlobalFolderHelper.FolderMy; var parent = folderDao.GetFolder(file.FolderID); if (parent != null && fileSecurity.CanCreate(parent)) { folderId = parent.ID; } if (Equals(folderId, 0)) { throw new SecurityException(FilesCommonResource.ErrorMassage_FolderNotFound); } if (FilesSettingsHelper.UpdateIfExist && (parent != null && folderId != parent.ID || !file.ProviderEntry)) { newFile = fileDao.GetFile(folderId, newFileTitle); if (newFile != null && fileSecurity.CanEdit(newFile) && !EntryManager.FileLockedForMe(newFile.ID) && !FileTracker.IsEditing(newFile.ID)) { newFile.Version++; } else { newFile = null; } } if (newFile == null) { newFile = ServiceProvider.GetService <File>(); newFile.FolderID = folderId; } } newFile.Title = newFileTitle; newFile.ConvertedType = null; newFile.Comment = string.Format(FilesCommonResource.CommentConvert, file.Title); var req = (HttpWebRequest)WebRequest.Create(convertedFileUrl); if (WorkContext.IsMono && ServicePointManager.ServerCertificateValidationCallback == null) { ServicePointManager.ServerCertificateValidationCallback += (s, c, n, p) => true; //HACK: http://ubuntuforums.org/showthread.php?t=1841740 } try { using (var convertedFileStream = new ResponseStream(req.GetResponse())) { newFile.ContentLength = convertedFileStream.Length; newFile = fileDao.SaveFile(newFile, convertedFileStream); } } catch (WebException e) { using var response = e.Response; var httpResponse = (HttpWebResponse)response; var errorString = string.Format("WebException: {0}", httpResponse.StatusCode); if (httpResponse.StatusCode != HttpStatusCode.NotFound) { using var responseStream = response.GetResponseStream(); if (responseStream != null) { using var readStream = new StreamReader(responseStream); var text = readStream.ReadToEnd(); errorString += string.Format(" Error message: {0}", text); } } throw new Exception(errorString); } FilesMessageService.Send(newFile, MessageInitiator.DocsService, MessageAction.FileConverted, newFile.Title); FileMarker.MarkAsNew(newFile); var tagDao = DaoFactory.TagDao; var tags = tagDao.GetTags(file.ID, FileEntryType.File, TagType.System).ToList(); if (tags.Any()) { tags.ForEach(r => r.EntryId = newFile.ID); tagDao.SaveTags(tags); } return(newFile); }