예제 #1
0
    protected void btForumPerfTest_Click(object sender, EventArgs e)
    {
        System.Diagnostics.Stopwatch elapsed = new System.Diagnostics.Stopwatch();
        elapsed.Start();

        Eucalypto.Forum.Category category = Eucalypto.Forum.ForumManager.GetCategoryByName("performance", false);
        if (category == null)
            category = Eucalypto.Forum.ForumManager.CreateCategory("performance", "Performance test");

        for (int t = 0; t < 20; t++)
        {
            string title = "Performance test " + DateTime.Now.ToString() + " (" + t + ")";

            Eucalypto.Forum.Topic topic;
            Eucalypto.Forum.Message message;
            Eucalypto.Forum.ForumManager.CreateTopic(category, "TestUser1", title,
                                            "<p>Topic</p>", null, out topic, out message);

            for (int m = 0; m < 20; m++)
            {
                Eucalypto.Attachment.FileInfo attach = new Eucalypto.Attachment.FileInfo("attach.txt", "text/plain", System.Text.Encoding.UTF8.GetBytes("test attach string " + m.ToString()));
                Eucalypto.Forum.Message message1 = Eucalypto.Forum.ForumManager.CreateMessage(topic, message.Id,
                                                                    "TestUser2", "RE: " + title, "<p>Response + " + m.ToString() + "</p>", attach);
            }
        }

        elapsed.Stop();
        lblPerfResult.InnerText = elapsed.Elapsed.ToString();
    }
예제 #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="file"></param>
        /// <param name="acceptedExtensions">The list of accepted extensions.</param>
        /// <param name="maximumSize">Maximum KB for the uploaded file</param>
        public static void CheckFile(FileInfo file, string acceptedExtensions, int maximumSize)
        {
            int sizeKb = file.ContentData.Length / 1024;
            if (sizeKb > maximumSize)
                throw new FileExceedMaxSizeException(file.Name);

            if (IsValidFileExtension(acceptedExtensions, file.Name) == false)
                throw new FileExtensionNotValidException(file.Name);
        }
예제 #3
0
    protected void btSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            Eucalypto.Forum.Category forum = GetForum();

            //Check permission
            if (Eucalypto.SecurityHelper.CanInsert(Page.User, forum))
            {
                Eucalypto.XHTMLText xhtml = new Eucalypto.XHTMLText();
                xhtml.Load(newMessage.MessageBodyHtml);

                Exception validateError;
                if (xhtml.IsValid(forum.XHtmlMode, out validateError) == false)
                    throw new Eucalypto.TextNotValidException(validateError);

                Eucalypto.Attachment.FileInfo attachment = null;
                //Create attachment
                if (newMessage.AttachmentFile.HasFile)
                    attachment = new Eucalypto.Attachment.FileInfo(newMessage.AttachmentFile.FileName,
                                                                newMessage.AttachmentFile.PostedFile.ContentType,
                                                                newMessage.AttachmentFile.FileBytes);

                //Insert the topic
                Eucalypto.Forum.ForumManager.CreateTopic(forum, User.Identity.Name,
                                                    newMessage.MessageSubject,
                                                    xhtml.GetXhtml(),
                                                    attachment);
            }
            else
                throw new Eucalypto.InvalidPermissionException("insert new message");

            Navigation.Forum_ViewForum(ForumName).Redirect(this);
        }
        catch (Exception ex)
        {
            ((IErrorMessage)Master).SetError(GetType(), ex);
        }
    }