Exemple #1
0
    /// <summary>
    /// Ensures the info objects.
    /// </summary>
    private void LoadInfos()
    {
        switch (baseImageEditor.ImageType)
        {
        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;

        default:
            if (ai == null)
            {
                baseImageEditor.Tree = new TreeProvider(MembershipContext.AuthenticatedUser);

                // If using workflow then get versioned attachment
                if (VersionHistoryID != 0)
                {
                    ai = DocumentHelper.GetAttachment(attachmentGuid, VersionHistoryID);
                }
                // Else get file without binary data
                else
                {
                    ai = AttachmentInfoProvider.GetAttachmentInfoWithoutBinary(attachmentGuid, CurrentSiteName);
                }
            }
            break;
        }
    }
 private void LoadMetafile()
 {
     if (metafile == null)
     {
         metafile = MetaFileInfoProvider.GetMetaFileInfoWithoutBinary(metafileGuid, CurrentSiteName, true);
     }
 }
    /// <summary>
    /// Initializes metafile.
    /// </summary>
    private void InitializeMetaFile()
    {
        MetaFileInfo metaFileInfo;

        if (InfoObject != null)
        {
            metaFileInfo = InfoObject as MetaFileInfo;
        }
        else
        {
            // Get metafile
            metaFileInfo = MetaFileInfoProvider.GetMetaFileInfoWithoutBinary(ObjectGuid, SiteName, true);
            InfoObject   = metaFileInfo;
        }

        // If file is not null and current user is global administrator then set image
        if (metaFileInfo != null)
        {
            // Check modify permission
            if (CheckPermissions && !UserInfoProvider.IsAuthorizedPerObject(metaFileInfo.MetaFileObjectType, metaFileInfo.MetaFileObjectID, PermissionsEnum.Modify, SiteContext.CurrentSiteName, MembershipContext.AuthenticatedUser))
            {
                RedirectToAccessDenied(GetString("metadata.errors.filemodify"));
            }

            // Fire event GetObjectExtension
            if (GetObjectExtension != null)
            {
                GetObjectExtension(metaFileInfo.MetaFileExtension);
            }
        }
        else
        {
            URLHelper.Redirect(AdministrationUrlHelper.GetInformationUrl("editedobject.notexists"));
        }
    }
Exemple #4
0
    /// <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;
        }
    }
Exemple #5
0
    /// <summary>
    /// Processes the specified file.
    /// </summary>
    /// <param name="fileGuid">File guid</param>
    protected void ProcessFile(Guid fileGuid)
    {
        // Get the file
        MetaFileInfo fileInfo = MetaFileInfoProvider.GetMetaFileInfoWithoutBinary(fileGuid, CurrentSiteName, true);

        if (fileInfo != null)
        {
            bool resizeImage = (ImageHelper.IsImage(fileInfo.MetaFileExtension) && MetaFileInfoProvider.CanResizeImage(fileInfo, Width, Height, MaxSideSize));

            // Get the data
            if ((outputFile == null) || (outputFile.MetaFile == null))
            {
                outputFile             = NewOutputFile(fileInfo, null);
                outputFile.Width       = Width;
                outputFile.Height      = Height;
                outputFile.MaxSideSize = MaxSideSize;
                outputFile.Resized     = resizeImage;
            }
        }
    }
    /// <summary>
    /// Processes the file.
    /// </summary>
    protected void ProcessFile()
    {
        outputFile = null;

        // Get file GUID from querystring
        fileGuid = QueryHelper.GetGuid("fileguid", Guid.Empty);
        if (fileGuid == Guid.Empty)
        {
            // Get file GUID from context
            fileGuid = ValidationHelper.GetGuid(Context.Items["fileguid"], Guid.Empty);
        }

        if (fileGuid == Guid.Empty)
        {
            return;
        }

        // Get the file
        var fileInfo = MetaFileInfoProvider.GetMetaFileInfoWithoutBinary(fileGuid, CurrentSiteName, true);

        if (fileInfo == null)
        {
            return;
        }

        bool resizeImage = (ImageHelper.IsImage(fileInfo.MetaFileExtension) && MetaFileInfoProvider.CanResizeImage(fileInfo, Width, Height, MaxSideSize));

        // Get the data
        if ((outputFile == null) || (outputFile.MetaFile == null))
        {
            outputFile             = NewOutputFile(fileInfo, null);
            outputFile.Width       = Width;
            outputFile.Height      = Height;
            outputFile.MaxSideSize = MaxSideSize;
            outputFile.Resized     = resizeImage;
        }
    }
    /// <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 common properties used for processing image.
    /// </summary>
    private void baseImageEditor_InitializeProperties()
    {
        // Process attachment
        switch (baseImageEditor.ImageType)
        {
        // Process physical file
        case ImageHelper.ImageTypeEnum.PhysicalFile:
        {
            if (!String.IsNullOrEmpty(filePath))
            {
                if (CheckPhysicalFilePermissions())
                {
                    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
            metafile = MetaFileInfoProvider.GetMetaFileInfoWithoutBinary(metafileGuid, CurrentSiteName, true);

            // If file is not null and current user is global administrator then set image
            if (metafile != null)
            {
                if (CheckMetafilePermissions())
                {
                    // Ensure metafile binary data
                    metafile.MetaFileBinary = MetaFileInfoProvider.GetFile(metafile, CurrentSiteName);
                    if (metafile.MetaFileBinary != null)
                    {
                        baseImageEditor.ImgHelper = new ImageHelper(metafile.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:
        {
            LoadAttachment();

            if (attachment != null)
            {
                // If current user has appropriate permissions then set image
                if ((node != null) &&
                    (
                        (IsLiveSite && QueryHelper.ValidateHash("hash")) ||   // Live site checks hash, not permissions
                        (!IsLiveSite && CheckAttachmentPermissions())         // Normal editing checks edit permission for document
                    ))
                {
                    attachment.Generalized.EnsureBinaryData();

                    if (attachment.AttachmentBinary != null)
                    {
                        baseImageEditor.ImgHelper = new ImageHelper(attachment.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;
        }
    }