Пример #1
0
 /// <summary>
 /// Initialize labels according to current image type.
 /// </summary>
 private void baseImageEditor_InitializeLabels(bool reloadName)
 {
     //Initialize strings depending on image type
     if (baseImageEditor.ImageType == ImageHelper.ImageTypeEnum.MediaFile)
     {
         // Initialize media file thumbnail
         if (isPreview && (previewFile != null) && !String.IsNullOrEmpty(PreviewPath))
         {
             baseImageEditor.TxtFileName.Text       = Path.GetFileName(PreviewPath);
             baseImageEditor.LblExtensionValue.Text = Path.GetExtension(PreviewPath);
             baseImageEditor.LblImageSizeValue.Text = DataHelper.GetSizeString(previewFile.Length);
             baseImageEditor.LblWidthValue.Text     = baseImageEditor.ImgHelper.ImageWidth.ToString();
             baseImageEditor.LblHeightValue.Text    = baseImageEditor.ImgHelper.ImageHeight.ToString();
         }
         // Initialize regular media file
         else if ((mfi != null) && (mfi.FileBinary != null))
         {
             if (!RequestHelper.IsPostBack() || reloadName)
             {
                 baseImageEditor.TxtFileName.Text = mfi.FileName;
             }
             baseImageEditor.LblExtensionValue.Text = mfi.FileExtension;
             baseImageEditor.LblImageSizeValue.Text = DataHelper.GetSizeString(mfi.FileSize);
             baseImageEditor.LblWidthValue.Text     = mfi.FileImageWidth.ToString();
             baseImageEditor.LblHeightValue.Text    = mfi.FileImageHeight.ToString();
             baseImageEditor.SetTitleAndDescription(mfi.FileTitle, mfi.FileDescription);
             // Set media file info object
             baseImageEditor.SetMetaDataInfoObject(mfi);
         }
     }
 }
Пример #2
0
    /// <summary>
    /// Initializes common properties used for processing image.
    /// </summary>
    private void baseImageEditor_InitializeProperties()
    {
        // Process media file
        if (baseImageEditor.ImageType == ImageHelper.ImageTypeEnum.MediaFile)
        {
            // Get mediafile
            mfi = MediaFileInfoProvider.GetMediaFileInfo(mediafileGuid, CurrentSiteName);
            // If file is not null
            if (mfi != null)
            {
                MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(mfi.FileLibraryID);

                if ((mli != null) && (MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "filemodify")))
                {
                    // Load media file thumbnail
                    if (isPreview)
                    {
                        PreviewPath = MediaFileInfoProvider.GetPreviewFilePath(mfi);
                        if (PreviewPath != null)
                        {
                            OldPreviewExt = Path.GetExtension(PreviewPath);
                            try
                            {
                                // Get file contents from file system
                                previewFile = File.ReadAllBytes(PreviewPath);
                            }
                            catch (Exception ex)
                            {
                                EventLogProvider.LogException("ImageEditor", "GetPreviewFile", ex);
                            }
                            if (previewFile != null)
                            {
                                baseImageEditor.ImgHelper = new ImageHelper(previewFile);
                            }
                            else
                            {
                                baseImageEditor.LoadingFailed = true;
                                baseImageEditor.ShowError(GetString("img.errors.loading"));
                            }
                        }
                        else
                        {
                            baseImageEditor.LoadingFailed = true;
                            baseImageEditor.ShowError(GetString("img.errors.loading"));
                        }
                    }
                    // Load media file
                    else
                    {
                        mfi.FileBinary = MediaFileInfoProvider.GetFile(mfi, mli.LibraryFolder, CurrentSiteName);
                        // Ensure metafile binary data
                        if (mfi.FileBinary != null)
                        {
                            baseImageEditor.ImgHelper = new ImageHelper(mfi.FileBinary);
                        }
                        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"));
            }
        }

        // 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;
        }
    }