예제 #1
0
        /// <summary>
        /// Write TOC Html elements for the table of contents
        /// </summary>
        /// <returns></returns>
        public void TocElementsHtml(HttpRequest Request, string AssignmentGradingViewName)
        {
            // If there was an error on page load, do nothing here.
            if (m_session == null)
            {
                return;
            }

            TableOfContentsElement toc = m_session.GetTableOfContents(true);    // get toc without sequencing information

            using (HtmlStringWriter sw = new HtmlStringWriter(Response.Output))
            {
                sw.Indent = 2;  // start at table level 2, since that's where we are

                WriteTocEntry(sw, toc);

                string SLKView = Request.QueryString["SlkView"];

                // Write the TOC entry to submit the training, only in Execute view or RandomAccess (SLK only) views

                if ((m_session.View == SessionView.Execute) ||
                    ((m_session.View == SessionView.Review) && (SLKView.ToLower() == AssignmentGradingViewName.ToLower())))
                {
                    WriteSubmitPageEntry(sw);
                }
            }
        }
예제 #2
0
 public CaptureScope(HtmlTextWriter context, Action <IHtmlString> callback)
 {
     _context             = context;
     _oldWriter           = _context.InnerWriter;
     _callback            = callback;
     _context.InnerWriter = _writer = new HtmlStringWriter();
 }
예제 #3
0
        /// <summary>
        /// Write an element in to the TOC that allows submitting the attempt.
        /// </summary>
        /// <param name="sw">The string writer to write the toc entry to.</param>
        private void WriteSubmitPageEntry(HtmlStringWriter sw)
        {
            string     activityId     = "SUBMIT";
            HtmlString activityIdHtml = new PlainTextString(activityId).ToHtmlString();
            HtmlString titleHtml      = new PlainTextString(m_submitPageLinkText).ToHtmlString();

            sw.AddAttribute(HtmlTextWriterAttribute.Class, new PlainTextString("NodeParent"));
            sw.AddAttribute("activityId", activityIdHtml);
            sw.AddAttribute("isValidChoice", "true");
            sw.AddAttribute(HtmlTextWriterAttribute.Id, ResHelper.FormatInvariant("div{0}", activityIdHtml));
            sw.RenderBeginTag(HtmlTextWriterTag.Div);   // #Div1

            sw.AddAttribute(HtmlTextWriterAttribute.Id, ResHelper.FormatInvariant("icon{0}", activityIdHtml));
            sw.AddAttribute(HtmlTextWriterAttribute.Src, "Theme/Leaf.gif");
            sw.AddAttribute(HtmlTextWriterAttribute.Align, "absMiddle");
            sw.RenderBeginTag(HtmlTextWriterTag.Img);
            sw.RenderEndTag();

            sw.AddAttribute(HtmlTextWriterAttribute.Src, "Theme/1px.gif");
            sw.AddAttribute(HtmlTextWriterAttribute.Align, "absMiddle");
            sw.RenderBeginTag(HtmlTextWriterTag.Img);
            sw.RenderEndTag();
            sw.WriteLine();

            sw.AddAttribute(HtmlTextWriterAttribute.Href, "");
            sw.AddAttribute(HtmlTextWriterAttribute.Id, ResHelper.FormatInvariant("a{0}", activityIdHtml));
            sw.AddAttribute(HtmlTextWriterAttribute.Style, "FONT-WEIGHT: normal;visibility:visible");
            sw.AddAttribute(HtmlTextWriterAttribute.Title, titleHtml);
            sw.RenderBeginTag(HtmlTextWriterTag.A);
            sw.WriteHtml(titleHtml);
            sw.RenderEndTag();

            sw.RenderEndTag();  // div (see #Div1, above)
            sw.WriteLine();
        }
예제 #4
0
        public IHtmlString DisplayChildren(dynamic shape)
        {
            var writer = new HtmlStringWriter();

            foreach (var item in shape)
            {
                writer.Write(Display(item));
            }
            return(writer);
        }
예제 #5
0
        /// <summary>
        /// Generate the report.
        /// </summary>
        public void Generate()
        {
            if (Status == ReportStatus.Generating)
            {
                return;
            }

            HtmlStringWriter.GetStringBuilder().Clear();
            Status = ReportStatus.Generating;
            Build();
            Status = ReportStatus.Completed;
        }
        private IHtmlString PerformInvoke(DisplayContext displayContext, MethodInfo methodInfo, object serviceInstance)
        {
            var output    = new HtmlStringWriter();
            var arguments = methodInfo.GetParameters()
                            .Select(parameter => BindParameter(displayContext, parameter, output));

            var returnValue = methodInfo.Invoke(serviceInstance, arguments.ToArray());

            if (methodInfo.ReturnType != typeof(void))
            {
                output.Write(CoerceHtmlString(returnValue));
            }
            return(output);
        }
예제 #7
0
        private IHtmlString PerformInvoke(DisplayContext displayContext, MethodInfo methodInfo, object serviceInstance)
        {
            var output    = new HtmlStringWriter();
            var arguments = methodInfo.GetParameters()
                            .Select(parameter => BindParameter(displayContext, parameter, output));

            try {
                var returnValue = methodInfo.Invoke(serviceInstance, arguments.ToArray());
                if (methodInfo.ReturnType != typeof(void))
                {
                    output.Write(CoerceHtmlString(returnValue));
                }
                return(output);
            }
            catch (TargetInvocationException e) {
                // Throwing a TIE here will probably kill the web process
                // in Azure. For unknown reasons.
                throw new Exception(string.Concat("TargetInvocationException ", methodInfo.Name), e.InnerException);
            }
        }
        public ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
        {
            var viewResult = themeAwareViewEngine.FindPartialView(controllerContext, viewName, useCache, true);

            if (viewResult.View == null)
            {
                return(viewResult);
            }

            ThemedAttribute attribute;

            if (!ThemeFilter.IsApplied(controllerContext.RequestContext, out attribute))
            {
                return(viewResult);
            }

            var layoutView = new LayoutView((viewContext, writer, viewDataContainer) =>
            {
                Logger.Info("Rendering layout view");

                var childContentWriter = new HtmlStringWriter();

                var childContentViewContext = new ViewContext(
                    viewContext,
                    viewContext.View,
                    viewContext.ViewData,
                    viewContext.TempData,
                    childContentWriter);

                viewResult.View.Render(childContentViewContext, childContentWriter);
                workContext.Layout.Metadata.ChildContent = childContentWriter;

                var display        = displayHelperFactory.CreateHelper(viewContext, viewDataContainer);
                IHtmlString result = display(workContext.Layout);
                writer.Write(result.ToHtmlString());

                Logger.Info("Done rendering layout view");
            }, (context, view) => viewResult.ViewEngine.ReleaseView(context, viewResult.View));

            return(new ViewEngineResult(layoutView, this));
        }
예제 #9
0
        /// <summary>
        /// Write TOC Html elements for the table of contents
        /// </summary>
        /// <returns></returns>
        ///
        public void TocElementsHtml()
        {
            // If there was an error on page load, do nothing here.
            if (this.mSession == null)
            {
                return;
            }

            TableOfContentsElement toc = this.mSession.GetTableOfContents(true);

            // get toc without sequencing information
            using (HtmlStringWriter sw = new HtmlStringWriter(this.Response.Output))
            {
                sw.Indent = 2; // start at table level 2, since that's where we are

                this.WriteTocEntry(sw, toc);

                // Write the TOC entry to submit the training, only in Execute view or RandomAccess (SLK only) views
                if ((this.mSession.View == SessionView.Execute) || (this.mSession.View == SessionView.RandomAccess))
                {
                    this.WriteSubmitPageEntry(sw);
                }
            }
        }
예제 #10
0
        [SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")]    // parameter is validated
        private void WriteTocEntry(HtmlStringWriter sw, TableOfContentsElement currentElement)
        {
            FramesetUtil.ValidateNonNullParameter("sw", sw);
            FramesetUtil.ValidateNonNullParameter("currentElement", currentElement);

            string     activityId         = FramesetUtil.GetStringInvariant(currentElement.ActivityId);
            bool       elementHasChildren = currentElement.Children.Count > 0;
            HtmlString activityIdHtml     = new PlainTextString(activityId).ToHtmlString();
            HtmlString titleHtml          = new PlainTextString(currentElement.Title).ToHtmlString();

            // If the current element is visible or is an invisible leaf node, then render it. (If it's an
            // invisible leaf node, the node will exist but not be visible.)
            if (RenderThisNode(currentElement))
            {
                sw.AddAttribute(HtmlTextWriterAttribute.Class, new PlainTextString("NodeParent"));
                sw.AddAttribute("activityId", activityIdHtml);
                sw.AddAttribute("isValidChoice", (currentElement.IsValidChoiceNavigationDestination ? "true" : "false"));
                sw.AddAttribute(HtmlTextWriterAttribute.Id, ResHelper.FormatInvariant("div{0}", activityIdHtml));
                sw.RenderBeginTag(HtmlTextWriterTag.Div);   // #Div1

                if (currentElement.IsVisible)
                {
                    sw.AddAttribute(HtmlTextWriterAttribute.Id, ResHelper.FormatInvariant("icon{0}", activityIdHtml));
                    if (currentElement.HasVisibleChildren)
                    {
                        sw.AddAttribute(HtmlTextWriterAttribute.Src, "Theme/MinusBtn.gif");
                    }
                    else
                    {
                        sw.AddAttribute(HtmlTextWriterAttribute.Src, "Theme/Leaf.gif");
                    }
                    sw.AddAttribute(HtmlTextWriterAttribute.Align, "absMiddle");
                    sw.RenderBeginTag(HtmlTextWriterTag.Img);
                    sw.RenderEndTag();

                    sw.AddAttribute(HtmlTextWriterAttribute.Src, "Theme/1px.gif");
                    sw.AddAttribute(HtmlTextWriterAttribute.Align, "absMiddle");
                    sw.RenderBeginTag(HtmlTextWriterTag.Img);
                    sw.RenderEndTag();
                    sw.WriteLine();

                    sw.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:void(0)");
                    sw.AddAttribute(HtmlTextWriterAttribute.Id, ResHelper.FormatInvariant("a{0}", activityIdHtml));
                    if (!currentElement.IsValidChoiceNavigationDestination)
                    {
                        sw.AddAttribute(HtmlTextWriterAttribute.Disabled, "true");
                        sw.AddAttribute("class", "disable");
                    }

                    sw.AddAttribute(HtmlTextWriterAttribute.Style,
                                    ResHelper.FormatInvariant("FONT-WEIGHT: normal;visibility:{0}", (currentElement.IsVisible ? "visible" : "hidden")));
                    sw.AddAttribute(HtmlTextWriterAttribute.Title, titleHtml);
                    sw.RenderBeginTag(HtmlTextWriterTag.A);
                    sw.WriteHtml(titleHtml);
                    sw.RenderEndTag();
                }
            }

            // Write sub-elements (regardless of whether or not this node is rendered)
            if (elementHasChildren)
            {
                sw.WriteLine();
                bool clusterStarted = false;
                if (currentElement.IsVisible)
                {
                    sw.AddAttribute(HtmlTextWriterAttribute.Id, ResHelper.FormatInvariant("divCluster{0}", activityIdHtml));
                    sw.AddAttribute(HtmlTextWriterAttribute.Style, "MARGIN-TOP: 5px; DISPLAY: block; MARGIN-LEFT: 18px;");
                    sw.RenderBeginTag(HtmlTextWriterTag.Div);
                    clusterStarted = true;
                }

                foreach (TableOfContentsElement childElement in currentElement.Children)
                {
                    WriteTocEntry(sw, childElement);
                }

                if (clusterStarted)
                {
                    sw.RenderEndTag(); // end div
                    sw.WriteLine();
                }
            }

            if (RenderThisNode(currentElement))
            {
                sw.RenderEndTag();  // div (see #Div1, above)
                sw.WriteLine();
            }
        }
예제 #11
0
 /// <summary>
 /// Write a hidden control to the string writer. The controlId shows up in id= and name= attributes. The 
 /// value is the Value of the control.
 /// </summary>
 private static void WriteHiddenControl(HtmlStringWriter sw, PlainTextString controlId, PlainTextString value)
 {
     sw.AddAttribute(HtmlTextWriterAttribute.Type, new HtmlString("hidden"));
     sw.AddAttribute(HtmlTextWriterAttribute.Id, controlId.ToHtmlString());
     sw.AddAttribute(HtmlTextWriterAttribute.Name, controlId.ToHtmlString());
     sw.AddAttribute(HtmlTextWriterAttribute.Value, value.ToHtmlString());
     sw.RenderBeginTag(HtmlTextWriterTag.Input);
     sw.RenderEndTag();
 }
예제 #12
0
        /// <summary>
        /// Render all hidden controls on to the page. 
        /// </summary>
        public void WriteHiddenControls()
        {
            // If the page did not load successfully, don't do anything
            if (!this.mPageLoadSuccessful)
            {
                return;
            }

            // Error situation. Nothing to write.
            if (this.Session == null)
            {
                return;
            }

            HtmlStringWriter sw = new HtmlStringWriter(this.Response.Output);

            foreach (HiddenControlInfo ctrlInfo in this.mHiddenControlInfos)
            {
                if ((ctrlInfo.Id != null) && (ctrlInfo.Value != null))
                {
                    WriteHiddenControl(sw, ctrlInfo.Id, ctrlInfo.Value);
                    this.Response.Write("\r\n");
                }
            }
            sw.EndRender();
        }
예제 #13
0
 public void Dispose()
 {
     HtmlWriter.Dispose();
     HtmlStringWriter.Dispose();
 }