/// <summary>
 /// Constructor
 /// </summary>
 public AssignmentListWebPart()
 {
     culture        = new SlkCulture();
     displaySummary = true;
     listScope      = true;
     ToolTip        = culture.Format(culture.Resources.AlwpWebPartToolTipFormat, this.Title, this.Description);
 }
Ejemplo n.º 2
0
        /// <summary>See <see cref="SlkAppBasePage.OnInit"/>.</summary>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            // Query set page don't have normal master page so use custom culture switcher
            string culture = System.Web.HttpContext.Current.Request.QueryString["culture"];

            if (string.IsNullOrEmpty(culture) == false)
            {
                PageCulture = new SlkCulture(new CultureInfo(culture));
            }
        }
Ejemplo n.º 3
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>
        /// Render Error Message Image Tag
        /// </summary>
        /// <param name="errorType">ErrorType decides Image Src Attribute</param>
        private static Image RenderImage(ErrorType errorType)
        {
            //Controls to Render Error
            Image      imgErrorType = new Image();
            SlkCulture culture      = new SlkCulture();

            switch (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;
            }
            }

            return(imgErrorType);
        }
        /// <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));
        }
        /// <summary>
        /// Render TableGridColumn Contents
        /// </summary>
        /// <param name="writer">HtmlTextWriter</param>
        protected override void RenderContents(HtmlTextWriter writer)
        {
            //if FormType is Error render the Error Block

            if (ColumnType == FormType.FormError)
            {
                //place holder Content
                StringBuilder renderedContent = new StringBuilder();
                //Text Writer to write the content to content Render
                using (TextWriter contentWriter = new StringWriter(renderedContent, SlkCulture.GetCulture()))
                {
                    using (HtmlTextWriter originalStream = new HtmlTextWriter(contentWriter))
                    {
                        base.RenderContents(originalStream);
                        string renderedHtmlText = renderedContent.ToString();
                        RenderErrorBlock(writer, renderedHtmlText);
                    }
                }
            }
            else
            {
                //if FormType is Break render the image tag with blank gif
                if (ColumnType == FormType.FormBreak ||
                    ColumnType == FormType.SectionLine)
                {
                    //Add Attributes for the <Img> tag
                    writer.AddAttribute(HtmlTextWriterAttribute.Src, Constants.BlankGifUrl);
                    writer.AddAttribute(HtmlTextWriterAttribute.Width, "1");
                    writer.AddAttribute(HtmlTextWriterAttribute.Height,
                                        (ColumnType == FormType.SectionLine) ? "1" : "5");
                    writer.AddAttribute(HtmlTextWriterAttribute.Alt, "");
                    HtmlBlock.WriteFullTag(HtmlTextWriterTag.Img, 0, writer);
                }

                base.RenderContents(writer);
            }
        }
        private void RenderHead(HtmlTextWriter hw)
        {
            // render the "<head>" element and its contents
            using (new HtmlBlock(HtmlTextWriterTag.Head, 1, hw))
            {
                // create a link to "core.css";

                // "/_layouts/1033/styles/core.css" except with "1033" replaced with the
                // current SPWeb language code
                // Include 1033 one as a back up
                AddCoreCss(hw, 1033);
                SlkCulture culture = new SlkCulture(SPWeb);
                AddCoreCss(hw, culture.Culture.LCID);

#if SP2007
                //Adds the Theme Css Url to Enable Theming in the frame.
                if (!string.IsNullOrEmpty(SPWeb.ThemeCssUrl))
                {
                    hw.AddAttribute(HtmlTextWriterAttribute.Rel, "stylesheet");
                    hw.AddAttribute(HtmlTextWriterAttribute.Type, "text/css");
                    hw.AddAttribute(HtmlTextWriterAttribute.Href, SPWeb.ThemeCssUrl);
                    HtmlBlock.WriteFullTag(HtmlTextWriterTag.Link, 0, hw);
                }
#endif

                // create a link to ALWP's "Styles.css"
                hw.AddAttribute(HtmlTextWriterAttribute.Rel, "stylesheet");
                hw.AddAttribute(HtmlTextWriterAttribute.Type, "text/css");
                hw.AddAttribute(HtmlTextWriterAttribute.Href, "Include/Styles.css");
                HtmlBlock.WriteFullTag(HtmlTextWriterTag.Link, 0, hw);

                // write a "<script>" element that loads "QuerySet.js"
                hw.AddAttribute(HtmlTextWriterAttribute.Src, "Include/QuerySet.js");
                HtmlBlock.WriteFullTag(HtmlTextWriterTag.Script, 0, hw);
            }
        }
        /// <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);
                }
            }
        }
        /// <summary>Gets the name of a property to display.</summary>
        protected override string GetLocalizedString(string value)
        {
            SlkCulture culture = new SlkCulture();

            return(culture.Resources.ResourceManager.GetString(value));
        }
 /// <summary>See <see cref="Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase.OnInit"/>.</summary>
 protected override void OnInit(EventArgs e)
 {
     culture = new SlkCulture();
     base.OnInit(e);
 }
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Protected Methods
        //

        #region protected methods
        /// <summary>See <see cref="Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase.OnInit"/>.</summary>
        protected override void OnInit(EventArgs e)
        {
            PageCulture = new SlkCulture(SPWeb);
            base.OnInit(e);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                String queryCount = String.Empty;
                // render the HTML for the page
                using (HtmlTextWriter hw = new HtmlTextWriter(Response.Output, "  "))
                {
                    // render the "<html>" element and its contents
                    using (new HtmlBlock(HtmlTextWriterTag.Html, 0, hw))
                    {
                        // render the "<head>" element and its contents
                        using (new HtmlBlock(HtmlTextWriterTag.Head, 1, hw))
                        {
                            // create a link to "core.css";
                            // "/_layouts/1033/styles/core.css" except with "1033" replaced with the
                            // current SPWeb language code
                            // Include 1033 one as a back up
                            AddCoreCss(hw, 1033);
                            SlkCulture culture = new SlkCulture(SPWeb);
                            AddCoreCss(hw, culture.Culture.LCID);

#if SP2007
                            //Adds the Theme Css Url to Enable Theming in the frame.
                            hw.AddAttribute(HtmlTextWriterAttribute.Rel, "stylesheet");
                            hw.AddAttribute(HtmlTextWriterAttribute.Type, "text/css");
                            hw.AddAttribute(HtmlTextWriterAttribute.Href, SPWeb.ThemeCssUrl);
                            HtmlBlock.WriteFullTag(HtmlTextWriterTag.Link, 0, hw);
#endif

                            // create a link to ALWP's "Styles.css"
                            hw.AddAttribute(HtmlTextWriterAttribute.Rel, "stylesheet");
                            hw.AddAttribute(HtmlTextWriterAttribute.Type, "text/css");
                            hw.AddAttribute(HtmlTextWriterAttribute.Href, "Include/Styles.css");
                            HtmlBlock.WriteFullTag(HtmlTextWriterTag.Link, 0, hw);
                        }

                        // render the "<body>" element and its contents
                        hw.AddAttribute(HtmlTextWriterAttribute.Style, "width: 100%; overflow-y: auto; overflow-x: auto;");

                        using (new HtmlBlock(HtmlTextWriterTag.Body, 0, hw))
                        {
                            Microsoft.SharePointLearningKit.WebParts.AssignmentListWebPart.DumpCultures(hw, "Page_Load");
                            // render the outer table -- this contains only one row and one column, which
                            // in turn contains the entire query results table
                            hw.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
                            hw.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
                            hw.AddAttribute(HtmlTextWriterAttribute.Style, "width:100%;");
                            hw.AddAttribute(HtmlTextWriterAttribute.Border, "0");

                            RenderForm(hw);
                            RenderSortFunction(hw);

                            using (new HtmlBlock(HtmlTextWriterTag.Table, 0, hw))
                            {
                                // render the single row and column of the outer table
                                using (new HtmlBlock(HtmlTextWriterTag.Tr, 0, hw))
                                {
                                    using (new HtmlBlock(HtmlTextWriterTag.Td, 0, hw))
                                    {
                                        hw.WriteLine();

                                        try
                                        {
                                            // set <queryDef> to the QueryDefinition named <queryName>
                                            QueryDefinition queryDef = null;
                                            if (Query != null)
                                            {
                                                queryDef = SlkStore.Settings.FindQueryDefinition(Query);
                                            }

                                            if (queryDef == null)
                                            {
                                                throw new SafeToDisplayException(PageCulture.Resources.AlwpQuerySetNotFound, Query);
                                            }


                                            List <RenderedCell[]> renderedRows = PerformQuery(queryDef);

                                            //Set the QueryCount
                                            queryCount = renderedRows.Count.ToString(CultureInfo.InvariantCulture);
                                            //Renders the Result
                                            RenderQueryResults(queryDef, renderedRows, hw);
                                        }
                                        catch (Exception ex)
                                        {
                                            queryCount = PageCulture.Resources.AlwpQueryResultError;
                                            SlkError slkError;
                                            //Handles SqlException separate to capture the deadlock
                                            //and treat it differently
                                            SqlException sqlEx = ex as SqlException;
                                            if (sqlEx != null)
                                            {
                                                slkError = WebParts.ErrorBanner.WriteException(SlkStore, sqlEx);
                                            }
                                            else
                                            {
                                                slkError = SlkError.WriteException(SlkStore, ex);
                                            }

                                            WebParts.ErrorBanner.RenderErrorItems(hw, slkError);
                                        }
                                        finally
                                        {
                                            //Renders the JavaScript to set the Query Count.
                                            RenderQueryCount(queryCount);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }