Example #1
0
        public void ParseTest()
        {
            //--------------------------------------------------------------------------------------------------------------------------
            // ie-utf8.bak has been created by dumping an upload post using the RequestSTreamDumpModule in place fo the UploadHttpModule
            // You can generate as many dumps and corresponding tests as required. We just provide one sample here.
            // The following values can be red when opening the dumped request with a text editor
            //--------------------------------------------------------------------------------------------------------------------------

            string   REQUESTSTREAM     = "..\\..\\Memba.Tests\\TestData\\ie-utf8.bak";
            long     CONTENTLENGTH     = 127535L;
            Encoding ENCODING          = Encoding.UTF8;
            string   MULTIPARTBOUNDARY = "-----------------------------7d68919104a6";

            StringBuilder objStringBuilder = new StringBuilder();

            objStringBuilder.Append("-----------------------------7d68919104a6\r\n");
            objStringBuilder.Append("Content-Disposition: form-data; name=\"__VIEWSTATE\"\r\n\r\n");
            objStringBuilder.Append("/wEPDwUKMTQ2OTkzNDMyMWRk/QGEIG6aoQo7wQztaRW4VtvYCBw=\r\n");
            objStringBuilder.Append("-----------------------------7d68919104a6\r\n");
            objStringBuilder.Append("Content-Disposition: form-data; name=\"UploadButton\"\r\n\r\n");
            objStringBuilder.Append("Upload\r\n");
            objStringBuilder.Append("-----------------------------7d68919104a6\r\n");
            objStringBuilder.Append("Content-Disposition: form-data; name=\"__EVENTVALIDATION\"\r\n\r\n");
            objStringBuilder.Append("/wEWAgKoz5qmBQLeyN+CDNaH4hynC6YqRKcear2EXPS7WTFO\r\n");
            objStringBuilder.Append("-----------------------------7d68919104a6--\r\n");

            string FILTEREDREQUEST = objStringBuilder.ToString();

            string   sRequestDump = Path.Combine(TestContext.TestDir, REQUESTSTREAM);
            FileInfo objFileInfo  = new FileInfo(sRequestDump);

            Assert.IsTrue(objFileInfo.Exists);

            FileStream    objRequestStream = new FileStream(sRequestDump, FileMode.Open, FileAccess.Read);
            HashAlgorithm objHashAlgorithm = CryptoConfig.CreateFromName("SHA1") as HashAlgorithm;
            UploadData    objUploadData    = UploadMonitor.SetUploadData(null, "dummy");

            object requestFilterObject = Memba_FileUpload_RequestFilterAccessor.CreatePrivate(
                objRequestStream,
                objHashAlgorithm,
                CONTENTLENGTH,
                ENCODING,
                MULTIPARTBOUNDARY,
                objUploadData
                );

            Memba_FileUpload_RequestFilterAccessor requestFilterAccessor = new Memba_FileUpload_RequestFilterAccessor(requestFilterObject);

            object mimeParserObject = Memba_FileUpload_MimeParserAccessor.CreatePrivate(
                requestFilterAccessor
                );

            Memba_FileUpload_MimeParserAccessor mimeParserAccessor = new Memba_FileUpload_MimeParserAccessor(mimeParserObject);

            mimeParserAccessor.Parse();

            Assert.AreEqual(FILTEREDREQUEST, requestFilterAccessor._FilteredRequestStringBuilder.ToString());
        }
Example #2
0
    /// <summary>
    /// Click event handler for the Stop button
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void StopButton_Click(object sender, EventArgs e)
    {
        UploadMonitor.CancelUpload(MuidHiddenField.Value);

        //Update InfoBox
        if (_InfoBox != null)
        {
            _InfoBox.Type = InfoBoxType.Warning;
            _InfoBox.Text = Resources.Web.glossary.QuickMessageControl_StopInfo;
        }
    }
 public static UploadMonitor WithInputFileHistory(this UploadMonitor uploadMonitor, InputFileHistory inputFileHistory)
 {
     uploadMonitor.InputFileHistory = inputFileHistory;
     return(uploadMonitor);
 }
 public static UploadMonitor WithStepDescription(this UploadMonitor uploadMonitor, String stepDescription)
 {
     uploadMonitor.StepDescription = stepDescription;
     return(uploadMonitor);
 }
 public static UploadMonitor WithTimeOccured(this UploadMonitor uploadMonitor, DateTime timeOccured)
 {
     uploadMonitor.TimeOccured = timeOccured;
     return(uploadMonitor);
 }
 public static UploadMonitor WithInputFileCode(this UploadMonitor uploadMonitor, Guid inputFileCode)
 {
     uploadMonitor.InputFileCode = inputFileCode;
     return(uploadMonitor);
 }
 public static UploadMonitor WithPosition(this UploadMonitor uploadMonitor, Int32 position)
 {
     uploadMonitor.Position = position;
     return(uploadMonitor);
 }
 public static UploadMonitor WithCode(this UploadMonitor uploadMonitor, Guid code)
 {
     uploadMonitor.Code = code;
     return(uploadMonitor);
 }
Example #9
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
        }
    }
Example #10
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);
        }
    }