protected void Page_Load(object sender, EventArgs e) { if (!RequestHelper.IsPostBack()) { AttachmentHistoryInfo ai = (AttachmentHistoryInfo)InfoToClone; string uniqueName = ai.Generalized.GetUniqueName(ai.AttachmentName, 0, ATTACHMENT_NAME, "_{0}" + ai.AttachmentExtension, "([_](\\d+))?\\" + ai.AttachmentExtension + "$", true); txtFileName.Text = Path.GetFileNameWithoutExtension(uniqueName); } }
private Attachment CreateAttachmentHistory(int attachmentHistoryId) { var attachmentInfo = new AttachmentHistoryInfo { AttachmentHistoryID = attachmentHistoryId, AttachmentGUID = ATTACHMENT_GUID }; return(new Attachment(attachmentInfo)); }
/// <summary> /// Ensures the info objects. /// </summary> private void LoadInfos() { switch (baseImageEditor.ImageType) { default: case ImageHelper.ImageTypeEnum.Attachment: if (ai == null) { baseImageEditor.Tree = new TreeProvider(CMSContext.CurrentUser); // If using workflow then get versioned attachment if (VersionHistoryID != 0) { AttachmentHistoryInfo attachmentVersion = VersionManager.GetAttachmentVersion(VersionHistoryID, attachmentGuid); if (attachmentVersion == null) { ai = null; } else { ai = new AttachmentInfo(attachmentVersion.Generalized.DataClass); ai.AttachmentID = attachmentVersion.AttachmentHistoryID; } } // else get file without binary data else { ai = AttachmentManager.GetAttachmentInfoWithoutBinary(attachmentGuid, CurrentSiteName); } } break; case ImageHelper.ImageTypeEnum.Metafile: if (mf == null) { mf = MetaFileInfoProvider.GetMetaFileInfoWithoutBinary(metafileGuid, CurrentSiteName, true); } break; case ImageHelper.ImageTypeEnum.PhysicalFile: // Skip loading info for physical files break; } }
/// <summary> /// Gets the file from version history. /// </summary> /// <param name="attachmentGuid">Atachment GUID</param> /// <param name="versionHistoryId">Version history ID</param> protected AttachmentInfo GetFile(Guid attachmentGuid, int versionHistoryId) { VersionManager vm = new VersionManager(TreeProvider); // Get the attachment version AttachmentHistoryInfo attachmentVersion = vm.GetAttachmentVersion(versionHistoryId, attachmentGuid); if (attachmentVersion == null) { return(null); } else { // Create the attachment object from the version AttachmentInfo ai = new AttachmentInfo(attachmentVersion.Generalized.DataClass); ai.AttachmentVersionHistoryID = versionHistoryId; return(ai); } }
/// <summary> /// Initializes common properties used for processing image. /// </summary> private void baseImageEditor_InitializeProperties() { var currentUser = MembershipContext.AuthenticatedUser; // Process attachment switch (baseImageEditor.ImageType) { // Process physical file case ImageHelper.ImageTypeEnum.PhysicalFile: { if (!String.IsNullOrEmpty(filePath)) { if ((currentUser != null) && currentUser.IsGlobalAdministrator) { try { // Load the file from disk string physicalPath = Server.MapPath(filePath); byte[] data = File.ReadAllBytes(physicalPath); baseImageEditor.ImgHelper = new ImageHelper(data); } catch { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.loading")); } } else { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.rights")); } } else { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.loading")); } } break; // Process metafile case ImageHelper.ImageTypeEnum.Metafile: { // Get metafile mf = MetaFileInfoProvider.GetMetaFileInfoWithoutBinary(metafileGuid, CurrentSiteName, true); // If file is not null and current user is global administrator then set image if (mf != null) { if (UserInfoProvider.IsAuthorizedPerObject(mf.MetaFileObjectType, mf.MetaFileObjectID, PermissionsEnum.Modify, CurrentSiteName, MembershipContext.AuthenticatedUser)) { // Ensure metafile binary data mf.MetaFileBinary = MetaFileInfoProvider.GetFile(mf, CurrentSiteName); if (mf.MetaFileBinary != null) { baseImageEditor.ImgHelper = new ImageHelper(mf.MetaFileBinary); } else { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.loading")); } } else { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.rights")); } } else { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.loading")); } } break; default: { baseImageEditor.Tree = new TreeProvider(currentUser); // If using workflow then get versioned attachment if (VersionHistoryID != 0) { // Get the versioned attachment AttachmentHistoryInfo attachmentVersion = VersionManager.GetAttachmentVersion(VersionHistoryID, attachmentGuid); if (attachmentVersion != null) { // Create new attachment object ai = new AttachmentInfo(attachmentVersion.Generalized.DataClass); if (ai != null) { AttachmentHistoryID = attachmentVersion.AttachmentHistoryID; ai.AttachmentVersionHistoryID = VersionHistoryID; } } } // Else get file without binary data else { ai = AttachmentInfoProvider.GetAttachmentInfoWithoutBinary(attachmentGuid, CurrentSiteName); } // If file is not null and current user is set if (ai != null) { TreeNode node; if (ai.AttachmentDocumentID > 0) { node = baseImageEditor.Tree.SelectSingleDocument(ai.AttachmentDocumentID); } else { // Get parent node ID in case attachment is edited for document not created yet int parentNodeId = QueryHelper.GetInteger("parentId", 0); node = baseImageEditor.Tree.SelectSingleNode(parentNodeId); } // If current user has appropriate permissions then set image - check hash fro live site otherwise check node permissions if ((currentUser != null) && (node != null) && ((IsLiveSite && QueryHelper.ValidateHash("hash")) || (!IsLiveSite && (currentUser.IsAuthorizedPerDocument(node, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Allowed)))) { // Ensure attachment binary data if (VersionHistoryID == 0) { ai.AttachmentBinary = AttachmentInfoProvider.GetFile(ai, CurrentSiteName); } if (ai.AttachmentBinary != null) { baseImageEditor.ImgHelper = new ImageHelper(ai.AttachmentBinary); } else { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.loading")); } } else { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.filemodify")); } } else { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.loading")); } } break; } // Check that image is in supported formats if ((!baseImageEditor.LoadingFailed) && (baseImageEditor.ImgHelper.ImageFormatToString() == null)) { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.format")); } // Disable editor if loading failed if (baseImageEditor.LoadingFailed) { Enabled = false; } }
/// <summary> /// Initializes properties. /// </summary> private void InitializeAttachment() { AttachmentInfo attachmentInfo = null; if (InfoObject != null) { attachmentInfo = InfoObject as AttachmentInfo; } else { // If using workflow then get versioned attachment if (VersionHistoryID != 0) { // Get the versioned attachment with binary data AttachmentHistoryInfo attachmentHistory = VersionManager.GetAttachmentVersion(VersionHistoryID, ObjectGuid, false); if (attachmentHistory == null) { attachmentInfo = null; } else { // Create new attachment object attachmentInfo = new AttachmentInfo(attachmentHistory.Generalized.DataClass); attachmentInfo.AttachmentID = attachmentHistory.AttachmentHistoryID; } } // else get file without binary data else { attachmentInfo = AttachmentManager.GetAttachmentInfoWithoutBinary(ObjectGuid, SiteName); } InfoObject = attachmentInfo; } if (attachmentInfo != null) { // Check permissions if (CheckPermissions) { // If attachment is temporary, check 'Create' permission on parent node. Else check 'Modify' permission. NodePermissionsEnum permission = nodeIsParent ? NodePermissionsEnum.Create : NodePermissionsEnum.Modify; if (Node == null) { RedirectToInformation(GetString("editeddocument.notexists")); } if (CMSContext.CurrentUser.IsAuthorizedPerDocument(Node, permission) != AuthorizationResultEnum.Allowed) { RedirectToAccessDenied(GetString("metadata.errors.filemodify")); } } // Fire event GetObjectExtension if (GetObjectExtension != null) { GetObjectExtension(attachmentInfo.AttachmentExtension); } } else { RedirectToInformation(GetString("editedobject.notexists")); } }