protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {
        if (e == null)
        {
            throw new ArgumentNullException("e");
        }
        if (e.State != AjaxControlToolkit.AjaxFileUploadState.Success)
        {
            return;
        }

        string szKey = FileObjectSessionKey(e.FileId);

        PendingIDs.Add(szKey);
        Session[szKey] = new MFBPendingImage(new MFBPostedFile(e.FileName, e.ContentType, e.FileSize, e.GetContents(), e.FileId), szKey);
        e.DeleteTemporaryData();

        RefreshPreviewList();

        if (Mode == UploadMode.Legacy)
        {
            Mode = UploadMode.Ajax;
        }

        if (UploadComplete != null)
        {
            UploadComplete(this, e);
        }
    }
Esempio n. 2
0
    protected void imgAdd_Command(object sender, CommandEventArgs e)
    {
        if (e == null)
        {
            throw new ArgumentNullException(nameof(e));
        }

        // Find the appropriate image
        List <GoogleMediaItem> items       = new List <GoogleMediaItem>(RetrievedGooglePhotos.mediaItems);
        GoogleMediaItem        clickedItem = items.Find(i => i.productUrl.CompareOrdinal((string)e.CommandArgument) == 0);

        if (clickedItem == null)
        {
            throw new ArgumentOutOfRangeException("Can't find item with id " + e.CommandArgument);
        }

        PositionEventArgs pea = new PositionEventArgs(null, clickedItem.mediaMetadata.CreationTime);

        ImportingGooglePhoto?.Invoke(sender, pea);

        MFBPostedFile pf = RetrievedGooglePhotos.ImportImage(e.CommandArgument.ToString());

        if (pf == null)
        {
            return;
        }

        MFBPendingImage pi = AddPostedFile(pf, pea.ExpectedPosition);

        rptGPhotos.DataSource = RetrievedGooglePhotos.mediaItems;
        rptGPhotos.DataBind();

        pnlGPResult.Visible = RetrievedGooglePhotos.mediaItems.Any();
    }
Esempio n. 3
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;
            }
        }
Esempio n. 4
0
    protected MFBPendingImage AddPostedFile(MFBPostedFile pf, LatLong ll)
    {
        if (pf == null)
        {
            throw new ArgumentNullException(nameof(pf));
        }

        string szKey = FileObjectSessionKey(pf.FileID);

        PendingIDs.Add(szKey);
        MFBPendingImage result = new MFBPendingImage(pf, szKey);

        if (ll != null)
        {
            result.Location = ll;
        }
        Session[szKey] = result;
        UploadComplete?.Invoke(this, new EventArgs());
        RefreshPreviewList();
        return(result);
    }
Esempio n. 5
0
 protected void ProcessClipboardImage()
 {
     // Regardless of mode, see if there's a clipboard image
     if (!String.IsNullOrEmpty(hImg.Value))
     {
         try
         {
             MFBPostedFile pf = new MFBPostedFile(hImg.Value);
             if (ValidateFileType(MFBImageInfo.ImageTypeFromFile(pf)))
             {
                 // create a pending file.
                 string szKey = FileObjectSessionKey(pf.FileName);
                 PendingIDs.Add(szKey);
                 Session[szKey] = new MFBPendingImage(pf, szKey);
                 RefreshPreviewList();
                 UploadComplete?.Invoke(this, new EventArgs());
             }
         }
         catch (FormatException) { } // if it's bad data, just don't do anything.
         hImg.Value = string.Empty;  // don't send it back down the wire!!!
     }
 }
    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;
        }
    }