/// <summary>See <see cref="Page.Render"/>.</summary>
        protected override void Render(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "1");
            writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
            using (new HtmlBlock(HtmlTextWriterTag.Table, 0, writer))
            {
                using (new HtmlBlock(HtmlTextWriterTag.Tr, 0, writer))
                {
                    using (GetTd(writer))
                    {
                        using (GetAnchor(writer))
                        {
                            using (GetImage(writer))
                            { }
                        }
                    }

                    using (GetTd(writer))
                    {
                        using (GetAnchor(writer))
                        {
                            writer.Write(SlkUtilities.GetHtmlEncodedText(Text));
                        }
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// writes the exeception to the event Log and outs the SlkError Object.
        /// </summary>
        /// <param name="store">The ISlkStore to write exceptions to.</param>
        /// <param name="ex">Exception</param>
        /// <returns></returns>
        public static SlkError WriteException(ISlkStore store, Exception ex)
        {
            SlkError slkError = null;

            //Check for Exception Type. For all Handled Exceptions
            //Add the Exception Message in Error
            //Or Add the Standard Error Message  and
            //log the exception in EventLog.
            if (ex is SafeToDisplayException || ex is UserNotFoundException || ex is SlkNotConfiguredException || ex is NotAnInstructorException)
            {
                slkError = new SlkError(ErrorType.Error, SlkUtilities.GetHtmlEncodedText(ex.Message));
            }
            else if (ex is UnauthorizedAccessException || ex is LearningStoreSecurityException)
            {
                slkError = new SlkError(ErrorType.Error, SlkUtilities.GetHtmlEncodedText(SlkCulture.GetResources().AccessDenied));
            }
            else
            {
                //Set the Standard Error text
                SlkCulture culture   = new SlkCulture();
                string     errorText = culture.Resources.SlkGenericError;

                SqlException sqlEx = ex as SqlException;
                if (sqlEx != null)
                {
                    //check whether deadlock occured
                    if (sqlEx.Number == 1205)
                    {
                        errorText = culture.Resources.SlkExWorkFlowSqlDeadLockError;
                    }
                }


                //log the exception in EventLog.
                if (store != null)
                {
                    store.LogException(ex);
                }

                slkError = new SlkError(ErrorType.Error, SlkUtilities.GetHtmlEncodedText(errorText));
            }

            return(slkError);
        }
        /// <summary>
        /// Checks for deadlock and writes the SqlExeception to the event Log and outs the SlkError Object.
        /// </summary>
        /// <param name="store">The ISlkStore to log exceptions.</param>
        /// <param name="sqlEx">SqlException</param>
        /// <returns></returns>
        internal static SlkError WriteException(ISlkStore store, SqlException sqlEx)
        {
            //Set the Standard Error text
            SlkCulture culture   = new SlkCulture();
            string     errorText = culture.Resources.SlkGenericError;

            //check whether deadlock occured
            if (sqlEx.Number == 1205)
            {
                errorText = culture.Resources.SlkExAlwpSqlDeadLockError;
            }

            //Slk Error with Generic or dead lock error message.
            errorText = Constants.Space + SlkUtilities.GetHtmlEncodedText(errorText);

            //log the exception
            store.LogException(sqlEx);

            //Add the Error to Error Collection.
            return(new SlkError(ErrorType.Error, errorText));
        }
示例#4
0
        /// <summary>
        /// Control Render Method
        /// </summary>
        /// <param name="writer"></param>
        protected override void Render(HtmlTextWriter writer)
        {
            //Renders the Validation Error Message on Top of the Control.

            if (!IsValid)
            {
                if (!String.IsNullOrEmpty(SlkUtilities.Trim(this.ErrorMessage)))
                {
                    Label lblErrorText = new Label();
                    lblErrorText.Text     = SlkUtilities.GetHtmlEncodedText(this.ErrorMessage);
                    lblErrorText.CssClass = "ms-formvalidation";

                    using (new HtmlBlock(HtmlTextWriterTag.Div, 0, writer))
                    {
                        lblErrorText.RenderControl(writer);
                    }
                }
            }
            //Render the CheckBox List
            RenderCustomCheckBox(writer);
        }
示例#5
0
        /// <summary>
        /// Process the posted data before it is saved by the shared code. This allows checking the file attachments
        /// and making sure they meet the requirements of the SlkSettings.
        /// </summary>
        public bool ProcessPostedData(LearningSession session, HttpRequest request, Dictionary <string, HttpPostedFile> files)
        {
            // Save initial value of FinalPoints
            m_initialTotalPoints = session.TotalPoints;

            // Check the files for validity and fill in the output collection
            HttpFileCollection attachedFiles = Request.Files;
            int numFilesAttached             = attachedFiles.Count;

            if (numFilesAttached > 0)
            {
                // Check if posted data meets requirements in SlkSettings. Additionally, check if there are files
                // that refer to files that do not exist (i.e. have 0 length).

                int maxKb = SlkStore.Settings.MaxAttachmentKilobytes;
                ICollection <string> attachmentTypes        = SlkStore.Settings.ApprovedAttachmentTypes;
                List <string>        invalidFileAttachments = new List <string>(numFilesAttached);
                List <string>        invalidFileSize        = new List <string>(numFilesAttached);
                List <string>        filesDontExist         = new List <string>(numFilesAttached);

                // Keep track of whether there is at least
                bool hasInvalidFileAttachment = false;
                bool hasInvalidFileSize       = false;
                bool fileExists = true;

                // Go through posted files and test if they meet requirements
                foreach (string fileKey in attachedFiles)
                {
                    HttpPostedFile file        = attachedFiles[fileKey];
                    bool           fileIsValid = true; // is this file a valid file attachment?

                    string filename = file.FileName;
                    // If the filename is empty, the file wasn't actually attached.
                    if (!String.IsNullOrEmpty(filename))
                    {
                        if (file.ContentLength == 0)
                        {
                            filesDontExist.Add(filename);
                            fileExists  = false;
                            fileIsValid = false;
                        }
                        else if ((file.ContentLength / 1024) > maxKb)
                        {
                            invalidFileSize.Add(filename);
                            hasInvalidFileSize = true;
                            fileIsValid        = false;
                        }

                        if (!attachmentTypes.Contains(Path.GetExtension(filename)))
                        {
                            invalidFileAttachments.Add(filename);
                            hasInvalidFileAttachment = true;
                            fileIsValid = false;
                        }
                    }
                    // else: The file was valid on a previous posting, so consider it valid here

                    if (fileIsValid)
                    {
                        // Add it to the returned list of valid files
                        files.Add(fileKey, file);
                    }
                }

                // if any of the posted files are invalid, then we need to write the message
                if (hasInvalidFileSize || hasInvalidFileAttachment || !fileExists)
                {
                    StringBuilder message = new StringBuilder(1000);
                    if (hasInvalidFileAttachment)
                    {
                        message.Append(ResHelper.GetMessage(SlkFrameset.CON_InvalidFileExtensionMsgHtml));
                        message.Append("<br><br><ul>");
                        foreach (string filename in invalidFileAttachments)
                        {
                            message.AppendFormat("<li>{0}</li>", SlkUtilities.GetHtmlEncodedText(filename));
                        }
                        message.Append("</ul>");
                    }

                    if (hasInvalidFileSize)
                    {
                        message.AppendFormat(ResHelper.GetMessage(SlkFrameset.CON_MaxFileSizeExceededMsgHtml, Convert.ToString(maxKb, CultureInfo.CurrentCulture.NumberFormat)));
                        message.Append("<br><br><ul>");
                        foreach (string filename in invalidFileSize)
                        {
                            message.AppendFormat("<li>{0}</li>", SlkUtilities.GetHtmlEncodedText(filename));
                        }
                        message.Append("</ul>");
                    }

                    if (!fileExists)
                    {
                        message.AppendFormat(SlkFrameset.CON_FilesDontExistHtml);
                        message.Append("<br><br><ul>");
                        foreach (string filename in filesDontExist)
                        {
                            message.AppendFormat("<li>{0}</li>", SlkUtilities.GetHtmlEncodedText(filename));
                        }
                        message.Append("</ul>");
                    }

                    // If one of the cases that relates to SLK settings is true, then tell user that there are settings
                    // that affect the error
                    if (hasInvalidFileSize || hasInvalidFileAttachment)
                    {
                        message.AppendFormat(CultureInfo.InvariantCulture, "{0}<br><br>", ResHelper.GetMessage(SlkFrameset.CON_InvalidFileAttachmentMsgHtml));
                    }

                    message.Append(FramesetResources.CON_FileAttachmentErrorEndHtml);

                    // Add information for the 'Continue' link
                    JScriptString js = new JScriptString(ResHelper.FormatInvariant("API_GetFramesetManager().DoChoice(\"{0}\");",
                                                                                   FramesetUtil.GetStringInvariant(session.CurrentActivityId)));
                    message.AppendFormat(CultureInfo.InvariantCulture, "<br><br><a href='{0}' >{1}</a>",
                                         js.ToJavascriptProtocol(), HttpUtility.HtmlEncode(FramesetResources.HID_ReloadCurrentContent));

                    RegisterError(SlkFrameset.CON_InvalidFileAttachmentTitleHtml, message.ToString(), false);
                }
            }
            return(true);
        }
 /// <summary>
 /// Adds the SlkError to the Error Collection
 /// and makes the Error Banner visible in the Page.
 /// ErrorText Will be HtmlEncoded.
 /// </summary>
 /// <param name="errorType">ErrorType</param>
 /// <param name="errorText">Plain Error Text to be displayed</param>
 internal void AddError(ErrorType errorType, String errorText)
 {
     //adds the Error to the Error Collection
     AddHtmlErrorText(errorType,
                      SlkUtilities.GetHtmlEncodedText(errorText));
 }
示例#7
0
        /// <summary>
        /// Render the Custom made CheckboxControl parses the content of
        /// List Items and Render the Items
        /// </summary>
        /// <param name="htmlTextWriter">HtmlTextWriter</param>
        protected void RenderCustomCheckBox(HtmlTextWriter htmlTextWriter)
        {
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Width, "100%");
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Class, "UserGenericText");
            using (new HtmlBlock(HtmlTextWriterTag.Table, 1, htmlTextWriter))
            {
                if (!String.IsNullOrEmpty(SlkUtilities.Trim(this.HeaderText)))
                {
                    using (new HtmlBlock(HtmlTextWriterTag.Tr, 1, htmlTextWriter))
                    {
                        htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Width, "100%");
                        htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
                        using (new HtmlBlock(HtmlTextWriterTag.Td, 1, htmlTextWriter))
                        {
                            LiteralControl ltrl = new LiteralControl(SlkUtilities.GetHtmlEncodedText(this.HeaderText));
                            ltrl.RenderControl(htmlTextWriter);
                        }
                    }
                }

                //for each item in  the collection of SlkCheckBoxItem objects render
                //Checkbox and Associated label Control.
                foreach (SlkCheckBoxItem item in this.Items)
                {
                    using (new HtmlBlock(HtmlTextWriterTag.Tr, 1, htmlTextWriter))
                    {
                        CheckBox checkBox = ControlToRepeat;
                        htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Width, "1%");
                        htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Valign, "top");
                        using (new HtmlBlock(HtmlTextWriterTag.Td, 1, htmlTextWriter))
                        {
                            checkBox.ID      = item.Value;
                            checkBox.ToolTip = item.ToolTip;
                            checkBox.Checked = item.Selected;

                            if (this.HasAttributes)
                            {
                                foreach (string text1 in this.Attributes.Keys)
                                {
                                    checkBox.Attributes[text1] = this.Attributes[text1];
                                }
                            }

                            checkBox.RenderControl(htmlTextWriter);
                        }

                        htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Width, "100%");
                        htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Valign, "top");
                        htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Style, "border-top: none; padding-top:2px");
                        using (new HtmlBlock(HtmlTextWriterTag.Td, 1, htmlTextWriter))
                        {
                            Label label = ControlToAssociate;
                            label.ToolTip             = item.ToolTip;
                            label.Text                = item.Text;
                            label.AssociatedControlID = item.Value;
                            label.RenderControl(htmlTextWriter);
                        }
                    }
                }
            }
        }