/// <summary> /// Adds the SlkError to the Error Collection /// and makes the Error Banner visible in the Page. /// </summary> /// <param name="slkError">Error Item to be displayed</param> internal void AddError(SlkError slkError) { //adds the Error to the Error Collection m_slkErrorCollection.Add(slkError); //Show the Error Banner this.Visible = true; }
/// <summary> /// Adds the Exeception to the Error Collection and log /// the Exeception details in event Log /// The Exception message will be HtmlEncoded. /// </summary> /// <param name="store">The ISlkStore to log to.</param> /// <param name="ex">Exception</param> public void AddException(ISlkStore store, Exception ex) { //Call the WriteException to Add the Error Message //to collection and log the exception in EventLog as needed. SlkError slkError = SlkError.WriteException(store, ex); //Add the Error object to collection AddError(slkError); // if <ex> contains validation results, add them to the error banner SafeToDisplayException safeEx = ex as SafeToDisplayException; if ((safeEx != null) && (safeEx.ValidationResults != null) && (safeEx.ValidationResults.HasErrors || safeEx.ValidationResults.HasErrors)) { foreach (ValidationResult result in safeEx.ValidationResults.Results) { if (result.IsWarning) { AddError(ErrorType.Warning, result.Message); } else if (result.IsError) { AddError(ErrorType.Error, result.Message); } } } }
/// <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> /// Render the Error Items /// </summary> /// <param name="item">SlkError Item</param> /// <param name="htmlTextWriter">htmlTextWriter</param> private static void RenderErrorItem(SlkError item, HtmlTextWriter htmlTextWriter) { //Controls to Render Error Image imgErrorType = new Image(); Literal lcErrorText = new Literal(); imgErrorType.ID = "imgErrorType"; lcErrorText.ID = "lcErrorText"; using (new HtmlBlock(HtmlTextWriterTag.Tr, 1, htmlTextWriter)) { //Add Attributes for the <TD> tag htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Style, "width: 22px;"); htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Valign, "top"); htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Align, "left"); using (new HtmlBlock(HtmlTextWriterTag.Td, 0, htmlTextWriter)) { SlkCulture culture = new SlkCulture(); switch (item.ErrorType) { case ErrorType.Error: { //Error Image Tag imgErrorType.ImageUrl = Constants.ImagePath + Constants.ErrorIcon; imgErrorType.ToolTip = culture.Resources.SlkErrorTypeErrorToolTip; break; } case ErrorType.Info: { //Info Image Tag imgErrorType.ImageUrl = Constants.ImagePath + Constants.InfoIcon; imgErrorType.ToolTip = culture.Resources.SlkErrorTypeInfoToolTip; break; } case ErrorType.Warning: { //ErrorType Image Tag imgErrorType.ImageUrl = Constants.ImagePath + Constants.WarningIcon; imgErrorType.ToolTip = culture.Resources.SlkErrorTypeWarningToolTip; break; } default: { //Error Image Tag imgErrorType.ImageUrl = Constants.ImagePath + Constants.ErrorIcon; imgErrorType.ToolTip = culture.Resources.SlkErrorTypeErrorToolTip; break; } } imgErrorType.RenderControl(htmlTextWriter); } //Render Error Text htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Valign, "top"); htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Width, "100%"); htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Align, "left"); htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Class, "ms-formvalidation"); using (new HtmlBlock(HtmlTextWriterTag.Td, 0, htmlTextWriter)) { lcErrorText.Text = item.ErrorText; lcErrorText.RenderControl(htmlTextWriter); } } }