/// <summary>
		/// </summary>
		/// <param name="context"></param>
		protected override void DoExecute(IMansionContext context)
		{
			// get the XML output pipe
			var outputPipe = context.OutputPipe as JsonOutputPipe;
			if (outputPipe == null)
				throw new InvalidOperationException("No JSON output pipe found on thet stack. Open an JSON output pipe first.");
			var propertyName = GetAttribute<string>(context, "propertyName");
			if (string.IsNullOrEmpty(propertyName))
				throw new InvalidOperationException("The propertyName attribute is required.");

			object content;
			if (!TryGetAttribute(context, "value", out content))
			{
				// push a memory pipe to the stack
				var buffer = new StringBuilder();
				using (var pipe = new StringOutputPipe(buffer))
				using (context.OutputPipeStack.Push(pipe))
					ExecuteChildTags(context);
				content = buffer.ToString();
			}

			// write the attribute
			outputPipe.JsonWriter.WritePropertyName(propertyName);
			outputPipe.JsonWriter.WriteValue(content);
		}
		/// <summary>
		/// Invokes a procedure and returns it output.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="procedureName">The name of the section which to render.</param>
		/// <param name="arguments">The arguments of the procedure.</param>
		/// <returns></returns>
		public string Evaluate(IMansionContext context, string procedureName, params object[] arguments)
		{
			// validate arguments
			if (context == null)
				throw new ArgumentNullException("context");
			if (string.IsNullOrEmpty(procedureName))
				throw new ArgumentNullException("procedureName");
			if (arguments == null)
				throw new ArgumentNullException("arguments");

			// get the procedure
			ScriptTag procedure;
			if (!context.ProcedureStack.TryPeek(procedureName, out procedure))
				throw new InvalidOperationException(string.Format("No procedure found with name '{0}'", procedureName));

			// assemble the arguments
			var procedureArguments = new PropertyBag();
			for (var index = 0; index < arguments.Length; ++index)
				procedureArguments.Set(index.ToString(CultureInfo.InvariantCulture), arguments[index]);

			// render the control
			var buffer = new StringBuilder();
			using (var pipe = new StringOutputPipe(buffer))
			using (context.OutputPipeStack.Push(pipe))
			using (context.Stack.Push("Arguments", procedureArguments))
				procedure.Execute(context);

			// make sure the break procedure flag is cleared
			context.BreakTopMostProcedure = false;

			// return the buffer
			return buffer.ToString();
		}
 /// <summary>
 /// Gets the content which to add to the message.
 /// </summary>
 /// <param name="context">The <see cref="IMansionWebContext"/>.</param>
 /// <returns>Returns the content.</returns>
 protected override string GetContent(IMansionWebContext context)
 {
     // get the content
     var content = new StringBuilder();
     using (var pipe = new StringOutputPipe(content))
     using (context.OutputPipeStack.Push(pipe))
         ExecuteChildTags(context);
     return content.ToString();
 }
		/// <summary>
		/// Renders a section and returns it's content.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="sectionName">The name of the section which to render..</param>
		/// <returns></returns>
		public string Evaluate(IMansionContext context, string sectionName)
		{
			// validate arguments
			if (context == null)
				throw new ArgumentNullException("context");
			if (string.IsNullOrEmpty(sectionName))
				throw new ArgumentNullException("sectionName");

			// render the control
			var buffer = new StringBuilder();
			using (var pipe = new StringOutputPipe(buffer))
			using (context.OutputPipeStack.Push(pipe))
				templateService.Render(context, sectionName, TemplateServiceConstants.OutputTargetField).Dispose();

			// return the buffer
			return buffer.ToString();
		}
示例#5
0
        /// <summary>
        /// Renders the specified <paramref name="blockProperties"/> to the output pipe.
        /// </summary>
        /// <param name="context">The <see cref="IMansionContext"/>.</param>
        /// <param name="blockProperties">The <see cref="IPropertyBag"/> of the block which to render.</param>
        /// <returns>Returns the HTML for this block.</returns>
        public string Evaluate(IMansionContext context, IPropertyBag blockProperties)
        {
            // validate arguments
            if (context == null)
                throw new ArgumentNullException("context");
            if (blockProperties == null)
                throw new ArgumentNullException("blockProperties");

            // render the block
            var buffer = new StringBuilder();
            using (var pipe = new StringOutputPipe(buffer))
            using (context.OutputPipeStack.Push(pipe))
                portalService.RenderBlock(context, blockProperties, TemplateServiceConstants.OutputTargetField);

            // return the bufferred content
            return buffer.ToString();
        }
        /// <summary>
        /// Renders a column with the specified <paramref name="columnName"/> to the output pipe.
        /// </summary>
        /// <param name="context">The <see cref="IMansionContext"/>.</param>
        /// <param name="columnName">The name of the column which to render.</param>
        /// <param name="ownerProperties">The <see cref="IPropertyBag"/> to which the column belongs.</param>
        /// <param name="blockDataset">The <see cref="Dataset"/> containing the all blocks of the <paramref name="ownerProperties"/>.</param>
        /// <returns>Returns the HTML for this column.</returns>
        public string Evaluate(IMansionContext context, string columnName, IPropertyBag ownerProperties, Dataset blockDataset)
        {
            // validate arguments
            if (context == null)
                throw new ArgumentNullException("context");
            if (string.IsNullOrEmpty(columnName))
                throw new ArgumentNullException("columnName");
            if (ownerProperties == null)
                throw new ArgumentNullException("ownerProperties");
            if (blockDataset == null)
                throw new ArgumentNullException("blockDataset");

            // render the column
            var buffer = new StringBuilder();
            using (var pipe = new StringOutputPipe(buffer))
            using (context.OutputPipeStack.Push(pipe))
                portalService.RenderColumn(context, columnName, ownerProperties, blockDataset, TemplateServiceConstants.OutputTargetField);

            // return the bufferred content
            return buffer.ToString();
        }
		/// <summary>
		/// Renders the paging control for the given dataset.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="dataset">The <see cref="Dataset"/>.</param>
		/// <param name="id">The ID of the dataset which to page.</param>
		/// <param name="cssClasses">Additional css classes</param>
		/// <returns>Returns the HTML of the paging control.</returns>
		public string Evaluate(IMansionContext context, Dataset dataset, string id, string cssClasses)
		{
			// validate arguments
			if (context == null)
				throw new ArgumentNullException("context");
			if (dataset == null)
				throw new ArgumentNullException("dataset");
			if (string.IsNullOrEmpty(id))
				throw new ArgumentNullException("id");

			// check if this dataset does not support paging
			if (!dataset.IsPaged || dataset.RowCount == 0 || dataset.PageCount < 2)
				return string.Empty;

			// render the control
			var buffer = new StringBuilder();

			// get the control template
			var controlTemplateResourcePath = applicationResourceService.ParsePath(context, Control.ControlTemplatePathProperties);
			var controlTemplateResource = applicationResourceService.Get(context, controlTemplateResourcePath);

			// open the buffer pipe, control templates and render
			using (var pipe = new StringOutputPipe(buffer))
			using (context.OutputPipeStack.Push(pipe))
			using (templateService.Open(context, controlTemplateResource))
			{
				// construct the paging properties
				var pagingProperties = new PropertyBag
				                       {
				                       	{"id", id},
				                       	{"cssClasses", cssClasses},
				                       	/* row values */
				                       	{"rowStart", ((dataset.CurrentPage - 1)*dataset.PageSize) + 1},
				                       	{"rowEnd", Math.Min((dataset.CurrentPage*dataset.PageSize), dataset.TotalSize)},
				                       	{"rowTotal", dataset.TotalSize},
				                       	/* page values */
				                       	{"currentPage", dataset.CurrentPage},
				                       	{"pageCount", dataset.PageCount},
				                       	{"pageSize", dataset.PageSize}
				                       };

				// render the control
				using (context.Stack.Push("ControlProperties", pagingProperties))
				using (context.Stack.Push("PagingProperties", pagingProperties))
				using (templateService.Render(context, "PagingControl", TemplateServiceConstants.OutputTargetField))
				{
					// render all the page options
					var displayPageNumberStart = Math.Max(dataset.CurrentPage - NumberOfAdjacentPagesToDisplay, 1);
					var displayPageNumberEnd = Math.Min(dataset.CurrentPage + NumberOfAdjacentPagesToDisplay, dataset.PageCount);
					for (var pageNumber = displayPageNumberStart; pageNumber <= displayPageNumberEnd; pageNumber++)
					{
						using (context.Stack.Push("PageOption", new PropertyBag
						                                        {
						                                        	{"number", pageNumber}
						                                        }))
							templateService.Render(context, "PagingControlPageOption").Dispose();
					}
				}
			}

			// return the buffer
			return buffer.ToString();
		}
        /// <summary>
        /// Renders the crumb trail.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="trail"></param>
        /// <returns></returns>
        private string RenderTrail(IMansionContext context, IEnumerable<Crumb> trail)
        {
            // validate arguments
            if (context == null)
                throw new ArgumentNullException("context");
            if (trail == null)
                throw new ArgumentNullException("trail");

            // create a dataset from the trail
            var dataset = new Dataset();
            foreach (var crumb in trail)
                dataset.AddRow(PropertyBagAdapterFactory.Adapt(context, crumb));

            // create a buffer in which to store the output
            var templateBuffer = new StringBuilder();
            using (var templateBufferPipe = new StringOutputPipe(templateBuffer))
            using (context.OutputPipeStack.Push(templateBufferPipe))
            using (templateService.Render(context, "CrumbTrail", TemplateServiceConstants.OutputTargetField))
            {
                // create the loop
                var loop = new Loop(dataset);
                using (context.Stack.Push("Loop", loop))
                {
                    // render the leafs recursively
                    foreach (var crumb in loop.Rows)
                    {
                        using (context.Stack.Push("CrumbProperties", crumb))
                            templateService.Render(context, "CrumbTrailItem").Dispose();
                    }
                }
            }

            // return the contents of the buffer
            return templateBuffer.ToString();
        }
        /// <summary>
        /// Renders the navigation tree.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="navigationTree"></param>
        /// <returns></returns>
        private string RenderNavigationTree(IMansionContext context, Leaf navigationTree)
        {
            // create a buffer in which to store the output
            var templateBuffer = new StringBuilder();
            using (var templateBufferPipe = new StringOutputPipe(templateBuffer))
            using (context.OutputPipeStack.Push(templateBufferPipe))
                // render the main navigation section
            using (context.Stack.Push("NavigationNode", navigationTree.Node, false))
            using (templateService.Open(context, applicationResourceService.Get(context, applicationResourceService.ParsePath(context, new PropertyBag
                                                                                                                                       {
                                                                                                                                       	{"type", navigationTree.Node.Pointer.Type},
                                                                                                                                       	{"extension", TemplateServiceConstants.DefaultTemplateExtension}
                                                                                                                                       }))))
            using (templateService.Render(context, "NavigationRoot", TemplateServiceConstants.OutputTargetField))
            {
                // render the leafs recursively
                RenderLeafs(context, navigationTree.Children);
            }

            // return the contents of the buffer
            return templateBuffer.ToString();
        }