Пример #1
0
        /// <summary>
        /// Loads the uploaded images into the specified virtual path, resets each upload control in turn
        /// </summary>
        public void ProcessUploadedImages()
        {
            if (String.IsNullOrEmpty(ImageKey))
            {
                throw new MyFlightbookException("No Image Key specified in ProcessUploadedImages");
            }
            if (Class == MFBImageInfo.ImageClass.Unknown)
            {
                throw new MyFlightbookException("Unknown image class in ProcessUploadedImages");
            }

            switch (Mode)
            {
            case UploadMode.Legacy:
                if (m_fHasProcessed)
                {
                    return;
                }
                m_fHasProcessed = true;
                foreach (mfbFileUpload fu in FileUploadControls)
                {
                    ProcessSingleNonAjaxUpload(fu);
                }
                break;

            case UploadMode.Ajax:
                string[] rgIDs = PendingIDs.ToArray();      // make a copy of the PendingIDs, since we're going to be removing from the Pending list as we go.

                foreach (string szID in rgIDs)
                {
                    MFBPendingImage mfbpi = (MFBPendingImage)Session[szID];
                    if (mfbpi == null || mfbpi.PostedFile == null)
                    {
                        continue;
                    }

                    // skip anything that isn't an image if we're not supposed to include non-image docs.
                    if (ValidateFileType(MFBImageInfo.ImageTypeFromFile(mfbpi.PostedFile)))
                    {
                        mfbpi.Commit(Class, ImageKey);
                    }

                    // Regardless, clean up the temp file and
                    Session.Remove(szID);         // free up some memory and prevent duplicate processing.
                    PendingIDs.Remove(szID);
                }
                RefreshPreviewList();
                GC.Collect();        // could be a lot of memory used and/or temp files from the images, so clean them up.
                break;
            }
        }
    protected void RefreshPreviewList()
    {
        // Refresh the image list
        List <MFBPendingImage> lst = new List <MFBPendingImage>();

        string[] rgIDs = PendingIDs.ToArray();  // get a copy since we may modify pendingIDs
        foreach (string szID in rgIDs)
        {
            MFBPendingImage mfbpi = (MFBPendingImage)Session[szID];
            if (mfbpi != null && mfbpi.IsValid)
            {
                lst.Add((MFBPendingImage)Session[szID]);
            }
            else
            {
                Session[szID] = null;
                PendingIDs.Remove(szID);
            }
        }
        ImageList imglist = new ImageList(lst.ToArray());

        mfbImageListPending.Images = imglist;
        mfbImageListPending.Refresh(false);
    }
    /// <summary>
    /// Loads the uploaded images into the specified virtual path, resets each upload control in turn
    /// </summary>
    public void ProcessUploadedImages()
    {
        MFBImageInfo mfbii;

        if (String.IsNullOrEmpty(ImageKey))
        {
            throw new MyFlightbookException("No Image Key specified in ProcessUploadedImages");
        }
        if (Class == MFBImageInfo.ImageClass.Unknown)
        {
            throw new MyFlightbookException("Unknown image class in ProcessUploadedImages");
        }

        switch (Mode)
        {
        case UploadMode.Legacy:
            if (m_fHasProcessed)
            {
                return;
            }
            m_fHasProcessed = true;
            if (rgmfbFu == null)
            {
                throw new MyFlightbookValidationException("rgmfbu is null in mfbMultiFileUpload; shouldn't be.");
            }
            foreach (Controls_mfbFileUpload fu in rgmfbFu)
            {
                if (fu.HasFile)
                {
                    // skip anything that isn't an image if we're not supposed to include non-image docs.
                    if (!ValidateFileType(MFBImageInfo.ImageTypeFromFile(fu.PostedFile)))
                    {
                        continue;
                    }

                    mfbii = new MFBImageInfo(Class, ImageKey, fu.PostedFile, fu.Comment, null);
                }
                // clear the comment field now that it is uploaded.
                fu.Comment = "";
            }
            break;

        case UploadMode.Ajax:
            string[] rgIDs = PendingIDs.ToArray();      // make a copy of the PendingIDs, since we're going to be removing from the Pending list as we go.

            foreach (string szID in rgIDs)
            {
                MFBPendingImage mfbpi = (MFBPendingImage)Session[szID];
                if (mfbpi == null || mfbpi.PostedFile == null)
                {
                    continue;
                }

                // skip anything that isn't an image if we're not supposed to include non-image docs.
                if (!ValidateFileType(MFBImageInfo.ImageTypeFromFile(mfbpi.PostedFile)))
                {
                    continue;
                }

                mfbii = mfbpi.Commit(Class, ImageKey);
                Session[FileObjectSessionKey(szID)] = null;         // free up some memory and prevent duplicate processing.
                PendingIDs.Remove(szID);
            }
            RefreshPreviewList();
            break;
        }
    }