示例#1
0
    /// <summary>
    /// Click event handler for the Send button
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void SendButton_Click(object sender, EventArgs e)
    {
        try
        {
            //Get posted values
            string sSender    = SenderTextBox.Text.Trim().ToLowerInvariant();
            string sRecipient = String.Empty;
            if (this._DisplayFormat == DisplayFormat.DropBox)
            {
                sSender    = SenderTextBox.Text.Trim().ToLowerInvariant();
                sRecipient = RecipientDropDownList.SelectedValue;
            }
            else
            {
                sSender    = SenderDropDownList.SelectedValue;
                sRecipient = RecipientTextBox.Text.Trim().ToLowerInvariant();
            }
            string sText = MessageTextBox.Text; //.Trim();

            //Confirm that we have a muid to access upload data
            System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(MuidHiddenField.Value) && (MuidHiddenField.Value == Request.QueryString[UploadMonitor.UploadIdParam]));

            //We could access it from Url, but this confirms it is a genuine post
            UploadData objUploadData = UploadMonitor.GetUploadData(MuidHiddenField.Value);
            if (objUploadData == null)
            {
                throw new ApplicationException(Resources.Web.glossary.QuickMessageControl_MissingUploadData);
            }

            //Recheck security code
            if (_DisplayFormat == DisplayFormat.QuickSend)
            {
                string sSecurityCode = (string)HttpRuntime.Cache[Memba.Common.Presentation.Constants.SecurityCode];
                if (String.IsNullOrEmpty(sSecurityCode))
                {
                    sSecurityCode = WebConfigurationManager.AppSettings[Memba.Common.Presentation.Constants.SecurityCode];
                    HttpRuntime.Cache.Add(
                        Memba.Common.Presentation.Constants.SecurityCode,
                        sSecurityCode,
                        null,
                        Cache.NoAbsoluteExpiration,
                        new TimeSpan(0, Memba.Common.Presentation.Constants.SlidingExpiration, 0),
                        CacheItemPriority.Default,
                        null);
                }
                if (!sSecurityCode.Equals(SecurityCodeTextBox.Text))
                {
                    throw new ApplicationException(Resources.Web.glossary.QuickMessageControl_SecurityCodeFailInfo);
                }
            }

            //Check any exception
            Exception objUploadException = objUploadData.Exception;
            if (objUploadException != null)
            {
                throw new ApplicationException(objUploadException.Message, objUploadException);
            }

            //Ensure that upload is complete
            if (objUploadData.ProgressStatus != UploadProgressStatus.Completed)
            {
                throw new ApplicationException(Resources.Web.glossary.QuickMessageControl_UploadNotComplete);
            }

            //Ensure we have at least one uploaded file (we should have at least one file input control)
            if ((objUploadData.UploadFiles == null) || (objUploadData.UploadFiles.Count < 1))
            {
                throw new ApplicationException(Resources.Web.glossary.QuickMessageControl_NoCompleteFile);
            }

            //Get path to file storage
            string sPath = FileStorage.Provider.ConnectionString;
            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(sPath);
            //Existence will be checked in FileBroker

            //Start building download links
            StringBuilder objStringBuilder = new StringBuilder();
            objStringBuilder.Append("<ul>");
            string sDownloadRoot = Request.Url.Scheme + Uri.SchemeDelimiter + Request.Url.Authority +
                                   this.ResolveUrl(Memba.Common.Presentation.PageUrls.Download);

            bool        bHasCompleteUploadFiles = false;
            List <File> lstAttachments          = new List <File>();
            foreach (UploadFile objUploadFile in objUploadData.UploadFiles)
            {
                if ((objUploadFile != null) && objUploadFile.IsComplete)
                {
                    bHasCompleteUploadFiles = true;

                    //Create file object
                    File f = new File(
                        objUploadFile.OriginalFileName,
                        objUploadFile.ContentType,
                        objUploadFile.ProviderFileKey.ToString(),
                        objUploadFile.ContentLength,
                        objUploadFile.HashValue);

                    //Add definition to file storage
                    FileBroker.Insert(f, di);

                    //Add to message attachments
                    lstAttachments.Add(f);

                    //Continue building download links
                    objStringBuilder.Append(
                        String.Format(
                            Resources.Web.glossary.Culture,
                            "<li><a href=\"{0}\" class=\"cssFieldHyperlink\">{1} ({2})</a></li>",
                            System.IO.Path.Combine(sDownloadRoot, f.Guid.ToString("N") + ".dat"),
                            f.FileName,
                            BODisplay.SizeFormat(f.Size, ByteFormat.Adapt)
                            )
                        );
                }
            }

            //Ensure we have at least one COMPLETED uploaded file to display
            if (!bHasCompleteUploadFiles)
            {
                throw new ApplicationException(Resources.Web.glossary.QuickMessageControl_NoCompleteFile);
            }

            //Create Message
            sText = BODisplay.RemoveAllHtmlTags(sText); //just in case

            Message m = new Message(
                sSender,
                sRecipient,
                sText,
                lstAttachments,
                sDownloadRoot);

            //Send message
            m.Send();

            //Release upload data
            UploadMonitor.Release(objUploadData.UploadId);

            //Finalize download links and display
            objStringBuilder.AppendLine("</ul>");
            FinalLinkLabel.Text = objStringBuilder.ToString();

            //Show InfoBox Message
            if (_InfoBox != null)
            {
                _InfoBox.Type = InfoBoxType.OK;
                _InfoBox.Text = Resources.Web.glossary.QuickMessageControl_SendOKInfo;
            }
        }
        catch (Exception Ex)
        {
            Session[Memba.Common.Presentation.Constants.LastError] = Ex.Message;
            //Response.Redirect(Memba.Common.Presentation.PageUrls.Error);
            throw; //Redirects to error handler in Global.asax
        }
    }
示例#2
0
    /// <summary>
    /// Gets a formatted maximum total size of uploads
    /// </summary>
    /// <returns></returns>
    protected string GetMaxFileSize()
    {
        long lMaxRequestLengthBytes = Memba.FileUpload.UploadHttpModule.GetMaxRequestLengthBytes(this.Context, true);

        return(BODisplay.SizeFormat(lMaxRequestLengthBytes, ByteFormat.Adapt));
    }
示例#3
0
    protected void SubmitButton_Click(object sender, EventArgs e)
    {
        try
        {
            //Confirm that we have a muid to access upload data
            System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(Request.QueryString[UploadMonitor.UploadIdParam]));
            UploadData objUploadData = UploadMonitor.GetUploadData(Request.QueryString[UploadMonitor.UploadIdParam]);
            if (objUploadData == null)
            {
                throw new ApplicationException("Oops! No upload data");
            }

            //Check any exception
            Exception objUploadException = objUploadData.Exception;
            if (objUploadException != null)
            {
                throw new ApplicationException(objUploadException.Message, objUploadException);
            }

            //Ensure that upload is complete
            if (objUploadData.ProgressStatus != UploadProgressStatus.Completed)
            {
                throw new ApplicationException("Oops! Upload not complete");
            }

            //Ensure we have at least one uploaded file (we should have at least one file input control)
            if ((objUploadData.UploadFiles == null) || (objUploadData.UploadFiles.Count < 1))
            {
                throw new ApplicationException("Oops! No uploaded file");
            }

            //Keep it simple: we now there is only one file upload control on the page
            UploadFile objUploadFile = objUploadData.UploadFiles[0];
            if ((objUploadFile == null) || (!objUploadFile.IsComplete))
            {
                throw new ApplicationException("Oops! Uploaded file is not complete");
            }

            //Create file object
            File f = new File(
                objUploadFile.OriginalFileName,
                objUploadFile.ContentType,
                objUploadFile.ProviderFileKey.ToString(),
                objUploadFile.ContentLength,
                objUploadFile.HashValue);

            //Get path to file storage
            string sPath = FileStorage.Provider.ConnectionString;
            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(sPath);

            //Add definition to file storage
            FileBroker.Insert(f, di);

            //Create download link
            DownloadLink.Text        = "Download: " + f.FileName + " (" + BODisplay.SizeFormat(f.Size, ByteFormat.Adapt) + ")";
            DownloadLink.NavigateUrl = System.IO.Path.Combine(this.Request.ApplicationPath, f.Guid.ToString("N") + ".dat");

            //Release upload data
            UploadMonitor.Release(objUploadData.UploadId);
        }
        catch (Exception Ex)
        {
            Response.Write(Ex.Message);
        }
    }