コード例 #1
0
    //protected void Page_Load(object sender, EventArgs e)
    //{
    //
    //}
    /// <summary>
    ///
    /// </summary>
    /// <param name="e"></param>
    protected override void OnPreRender(EventArgs e)
    {
        //get current sitemap node to determine page icon and title
        SiteMapProvider objSiteMapProvider = SiteMap.Providers["RootSiteMapProvider"];

        System.Diagnostics.Debug.Assert(objSiteMapProvider != null);
        SiteMapNode objCurrentNode = objSiteMapProvider.CurrentNode;

        if (objCurrentNode != null) //This is for defaultErr.aspx which is not referenced as a node
        {
            //set page icon and title
            Page.Header.Title = Resources.Web.glossary.App_Name + " - " + objCurrentNode.Title;
            if (string.IsNullOrEmpty(PageTitle.Text))
            {
                PageTitle.Text = objCurrentNode.Title;
            }
            if (string.IsNullOrEmpty(PageTitle.ImageUrl))
            {
                PageTitle.ImageUrl = Icons.GetIcon32(objCurrentNode["image"]);
            }
        }

        //Display errors of postback events
        if (Page.Session[Constants.LastError] != null) //&& Page.IsPostBack
        {
            InfoBox.Type = InfoBoxType.Error;
            InfoBox.Text = BODisplay.Encode(Session[Constants.LastError]);
            Session[Constants.LastError] = null;
        }

        //Required to avoid "Script controls may not be registered before PreRender."
        base.OnPreRender(e);
    }
コード例 #2
0
    /// <summary>
    /// The PreRender event which occurs after page load
    /// </summary>
    /// <param name="e"></param>
    protected override void OnPreRender(EventArgs e)
    {
        WebMasterPage objMasterPage = Page.Master as WebMasterPage;

        Page.Header.Title = Resources.Web.glossary.App_Name + " - " + this.GetLocalResourceObject("PageTitle").ToString();

        InfoBox objPageTitle = objMasterPage.FindControl("PageTitle") as InfoBox;

        objPageTitle.ImageUrl = Icons.GetIcon32("errorreport.gif");
        objPageTitle.Text     = this.GetLocalResourceObject("PageTitle").ToString();

        InfoBox objInfoBox = objMasterPage.FindControl("InfoBox") as InfoBox;

        objInfoBox.Type = InfoBoxType.Error;

        try
        {
            if (Session[Constants.LastError] != null)
            {
                objInfoBox.Text = BODisplay.Encode(Session[Constants.LastError]);
                Session[Constants.LastError] = null;
            }
            else
            {
                string errorCode = Context.Request.QueryString["e"];
                int    iHttpCode;
                bool   bTry = Int32.TryParse(errorCode, out iHttpCode);
                if ((bTry) && (iHttpCode > 200) && (iHttpCode < 600))
                {
                    this.Response.StatusCode = iHttpCode;
                }
                objInfoBox.Text = this.GetLocalResourceObject(errorCode).ToString();
            }
        }
        catch
        {
            objInfoBox.Text = this.GetLocalResourceObject("0").ToString();
        }

        //Required to avoid "Script controls may not be registered before PreRender."
        base.OnPreRender(e);
    }
コード例 #3
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));
    }
コード例 #4
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
        }
    }
コード例 #5
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);
        }
    }