/// <summary> /// Gets the drawing context. /// </summary> /// <param name="contextId">A context id like 2d.</param> /// <returns>An object that defines the drawing context.</returns> public IRenderingContext GetContext(String contextId) { if (_current != null && _current.ContextId.Equals(contextId, StringComparison.OrdinalIgnoreCase)) { return(_current); } var renderService = Owner.Options.GetService <IRenderingService>(); if (renderService == null) { return(null); } var context = renderService.CreateContext(contextId); if (context != null) { context.Host = this; _mode = GetModeFrom(contextId); _current = context; } return(context); }
public void Draw(IRenderingContext renderContext, int layer, string text, Point position) { if (charTex == null) charTex = renderContext.LoadResource(info.ImagePath); if (!info.CaseSensitive) { text = text.ToUpper(); } int xpos = position.X; foreach (char c in text) { if (c == ' ') { xpos += info.CharWidth; continue; } var location = info[c]; if (location != null) { renderContext.Draw(charTex, layer, new Point(xpos, position.Y), new Rectangle(location.Value.X, location.Value.Y, info.CharWidth, info.CharWidth)); xpos += info.CharWidth; } } }
public GlassRenderingParametersContext( ISitecoreContext sitecoreContext, IRenderingContext renderingContext) { SitecoreContext = sitecoreContext; RenderingContext = renderingContext; }
private void Draw(IRenderingContext context, float off_x, float off_y) { if (this._info.Tiles.Tileset == null) { throw new InvalidOperationException("Screen has no tileset to draw with."); } var layer = _info.Foreground ? 5 : 0; var tileSize = this._info.Tiles.Tileset.TileSize; for (int y = 0; y < this._info.Tiles.Height; y++) { for (int x = 0; x < this._info.Tiles.Width; x++) { float xpos = x * tileSize + off_x + this._info.Tiles.BaseX; float ypos = y * tileSize + off_y + this._info.Tiles.BaseY; if (xpos + tileSize < 0 || ypos + tileSize < 0) { continue; } if (xpos > Game.CurrentGame.PixelsAcross || ypos > Game.CurrentGame.PixelsDown) { continue; } this._squares[y][x].Draw(context, layer, xpos, ypos); } } }
/// <summary> /// Gets a collection of elements indexed by the value of a given METAL attribute. /// </summary> /// <returns>The elements found.</returns> /// <param name="context">The rendering context within which to search.</param> /// <param name="metalAttribute">The name of the METAL attribute for which to search.</param> public virtual IDictionary<string, IZptElement> GetChildElementsByMetalAttributeValue(IRenderingContext context, string metalAttribute) { return context.Element .SearchChildrenByMetalAttribute(metalAttribute) .ToDictionary(k => k.GetMetalAttribute(metalAttribute).Value, v => v); }
public void Draw(IRenderingContext context, int layer, float posX, float posY) { if (Tile.Sprite != null) { Tile.Sprite.Draw(context, Tile.Sprite.Layer, posX, posY); } }
private void RenderSections(IList <AbstractSection> sections, IRenderingContext ctx) { foreach (var section in sections) { ctx.Render(section); } }
/// <summary> /// Gets the drawing context. /// </summary> /// <param name="contextId">A context id like 2d.</param> /// <returns>An object that defines the drawing context.</returns> public IRenderingContext GetContext(String contextId) { if (_current == null || contextId.Isi(_current.ContextId)) { var renderServices = Owner.Options.GetServices<IRenderingService>(); foreach (var renderService in renderServices) { if (renderService.IsSupportingContext(contextId)) { var context = renderService.CreateContext(this, contextId); if (context != null) { _mode = GetModeFrom(contextId); _current = context; } return context; } } return null; } return _current; }
public TopicContainerViewModel( IRenderingContext renderingContext, ITextTranslator textTranslator) { RenderingContext = renderingContext; TextTranslator = textTranslator; }
public StubController( ISitecoreContext sitecoreContext, IGlassHtml glassHtml, IRenderingContext renderingContextWrapper, HttpContextBase httpContext) : base(sitecoreContext, glassHtml, renderingContextWrapper, httpContext) { }
/// <summary> /// Gets the drawing context. /// </summary> /// <param name="contextId">A context id like 2d.</param> /// <returns>An object that defines the drawing context.</returns> public IRenderingContext GetContext(String contextId) { if (_current == null || contextId.Isi(_current.ContextId)) { foreach (var renderService in _renderServices) { if (renderService.IsSupportingContext(contextId)) { var context = renderService.CreateContext(this, contextId); if (context != null) { _mode = GetModeFrom(contextId); _current = context; } return(context); } } return(null); } return(_current); }
private void RenderIndicatorResult(IndicatorResult result, IRenderingContext context) { context.Document.WriteLine("<h2>Indicators</h2>"); RenderIndicatorSummary(result, context); RenderIndicatorDetails(result.Report, context); }
public void Draw(IRenderingContext context, int layer, float positionX, float positionY) { if (!Visible || Count == 0 || context == null) { return; } if (texture == null) { texture = context.LoadResource(SheetPath, PaletteName); } bool flipHorizontal = HorizontalFlip ^ Reversed; bool flipVertical = VerticalFlip; int hx = (HorizontalFlip ^ Reversed) ? Width - HotSpot.X : HotSpot.X; int hy = VerticalFlip ? Height - HotSpot.Y : HotSpot.Y; var drawTexture = this.texture; context.Draw(drawTexture, layer, new Common.Geometry.Point((int)(positionX - hx), (int)(positionY - hy)), new Common.Geometry.Rectangle(CurrentFrame.SheetLocation.X, CurrentFrame.SheetLocation.Y, CurrentFrame.SheetLocation.Width, CurrentFrame.SheetLocation.Height), flipHorizontal, flipVertical); }
/// <summary> /// Handle the related attribute types which exist upon the element exposed by the given context, if any. /// </summary> /// <returns>A response type providing information about the result of this operation.</returns> /// <param name="context">The rendering context, which exposes a ZPT element.</param> public AttributeHandlingResult Handle(IRenderingContext context) { if(context == null) { throw new ArgumentNullException(nameof(context)); } IRenderingContext[] output = null; var attribute = context.GetTalAttribute(ZptConstants.Tal.RepeatAttribute); if(attribute != null) { string repeatVariableName, expression; this.ParseAttributeValue(attribute, out repeatVariableName, out expression, context.Element); var sequence = this.GetSequence(expression, context.TalModel, context); if(sequence != null) { var repetitionInfos = this.GetRepetitions(sequence, context.Element, repeatVariableName); output = this.HandleRepetitions(repetitionInfos, context); } } if(output == null) { output = new [] { context }; } return new AttributeHandlingResult(output, true); }
public void Draw(IRenderingContext renderContext, int layer, string text, Point position) { if (charTex == null) { charTex = renderContext.LoadResource(info.ImagePath); } if (!info.CaseSensitive) { text = text.ToUpper(); } int xpos = position.X; foreach (char c in text) { if (c == ' ') { xpos += info.CharWidth; continue; } var location = info[c]; if (location != null) { renderContext.Draw(charTex, layer, new Point(xpos, position.Y), new Rectangle(location.Value.X, location.Value.Y, info.CharWidth, info.CharWidth)); xpos += info.CharWidth; } } }
/// <summary> /// Visit the given context and return a collection of the resultant contexts. /// </summary> /// <returns>Zero or more <see cref="IRenderingContext"/> instances, determined by the outcome of this visit.</returns> /// <param name="context">The rendering context to visit.</param> public override IRenderingContext[] Visit(IRenderingContext context) { if(context == null) { throw new ArgumentNullException(nameof(context)); } IEnumerable<IRenderingContext> output = new [] { context }, newlyExposedElements = new RenderingContext[0]; var macroAttribute = context.Element.GetMetalAttribute(ZptConstants.Metal.DefineMacroAttribute); if(macroAttribute != null) { context.TalModel.AddLocal(MACRONAME, macroAttribute.Value); } foreach(var handler in _handlers) { var handlingResult = new HashSet<AttributeHandlingResult>(); foreach(var ctx in output) { var processedBatch = handler.Handle(ctx); handlingResult.Add(processedBatch); } newlyExposedElements = newlyExposedElements.Union(handlingResult.SelectMany(x => x.NewlyExposedContexts)); output = handlingResult.Where(x => x.ContinueHandling).SelectMany(x => x.Contexts).ToArray(); } output = output.Union(newlyExposedElements.SelectMany(x => this.Visit(x))); return output.ToArray(); }
private void RenderTableBody(IEnumerable <IndicatorResult> indicatorResults, IRenderingContext context) { foreach (var result in indicatorResults) { RenderIndicatorSummeryRow(result, context); } }
/// <summary> /// Visits a rendering context and returns a collection of contexts which represent the result of that visit. /// </summary> /// <returns>The rendering contexts instances which are exposed after the visiting process is complete.</returns> /// <param name="context">The rendering context to visit.</param> public override IRenderingContext[] VisitContext(IRenderingContext context) { context.Element.PurgeTalElements(); context.Element.PurgeTalAttributes(); return new [] { context }; }
public RenderingModel(TPageItem pageItem, TRenderingItem renderingItem, IItemFactory factory = null) { _pageItem = pageItem; _pageContext = new RenderingContext(pageItem); _renderingItem = renderingItem; _renderingItemContext = new RenderingContext(renderingItem); _itemFactory = factory; }
public void Render(PlainTextSection section, IRenderingContext context) { context.Document.WriteLine("<h2>{0}</h2>", section.Name); context.Document.WriteLine("<p>"); context.Document.WriteLine(section.GetText()); context.Document.WriteLine("</p>"); }
public RenderAction(IRenderingContext context, GenericChartSection section) { myContext = context; mySection = section; myModelSettings = new GenericStockChartViewModel.Settings(); myModelSettings.CurvesPreRenderingOperators.Add(new ReducePointsOperator(ChartWidth / 4)); }
public void Draw(IRenderingContext renderContext) { if (texture == null) texture = renderContext.CreateColorResource(color); renderContext.Draw(texture, layer, new MegaMan.Common.Geometry.Point((int)x, (int)y), new MegaMan.Common.Geometry.Rectangle((int)x, (int)y, (int)width, (int)height)); }
public GlassRenderingItemContext( ISitecoreContext sitecoreContext, IRenderingContext renderingContext, IGlobalSitecoreService globalService) { SitecoreContext = sitecoreContext; RenderingContext = renderingContext; GlobalService = globalService; }
public void Render(Report report, IRenderingContext context) { context.Document.WriteLine("<html>"); RenderHeader(report, context); RenderBody(report, context); context.Document.WriteLine("</html>"); }
private void RenderReport(Report report, IRenderingContext context) { using (var childCtx = context.CreateChildContext(report.Name + ".html")) { childCtx.Render(report); context.Document.WriteLine("<a href=\"{0}\">{1}</a>", childCtx.RelativeDocumentUrl(context), report.Name); } }
private void RenderBody(Report report, IRenderingContext ctx) { ctx.Document.WriteLine("<body>"); ctx.Document.WriteLine("<h1>{0}</h1>", report.Title); RenderSections(report.Sections, ctx); ctx.Document.WriteLine("</body>"); }
private static void RenderIndicatorSummary(IndicatorResult result, IRenderingContext context) { context.Document.WriteLine("<table>"); context.Document.WriteLine("<tr><td>Signal</td><td>{0}</td></tr>", HtmlRenderingUtils.GetDisplayText(result.Signal)); context.Document.WriteLine("<tr><td>Gain/Risk ratio</td><td>{0}</td></tr>", HtmlRenderingUtils.GetDisplayText(result.GainRiskRatio)); context.Document.WriteLine("<tr><td>Expected gain</td><td>{0}</td></tr>", HtmlRenderingUtils.GetDisplayText(result.ExpectedGain)); context.Document.WriteLine("</table>"); }
public void Draw(IRenderingContext renderContext) { if (texture == null) { texture = renderContext.CreateColorResource(color); } renderContext.Draw(texture, layer, new MegaMan.Common.Geometry.Point((int)x, (int)y), new MegaMan.Common.Geometry.Rectangle((int)x, (int)y, (int)width, (int)height)); }
/// <summary> /// Examines the given <see cref="IRenderingContext"/> and - if it extends a METAL macro - gets that macro from the /// model contained within that context. /// </summary> /// <returns>Either an <see cref="IZptElement"/> instance representing the macro extended, or a <c>null</c> reference.</returns> /// <param name="context">The rendering context.</param> public virtual IZptElement GetExtendedMacro(IRenderingContext context) { var output = this.GetReferencedMacro(context, ZptConstants.Metal.ExtendMacroAttribute); if(output != null) { output = output.Clone(); } return output; }
/// <summary> /// Returns DocumentUrl relative the "outer" context. /// </summary> public static string RelativeDocumentUrl(this IRenderingContext self, IRenderingContext outerContext) { var relativePath = self.DocumentUrl.Substring(outerContext.DocumentUrlRoot.Length); while (relativePath.StartsWith("/") || relativePath.StartsWith("\\")) { relativePath = relativePath.Substring(1); } return(relativePath); }
public void Render(GenericChartSection section, IRenderingContext context) { if (section.Chart.IsEmpty) { return; } var renderAction = new RenderAction(context, section); renderAction.Render(); }
public AdvancedHtmlHeader(IRenderingContext context) { myContext = context; myFileSystem = new Blade.IO.RealFS.FileSystemImpl(); myDocumentRoot = myFileSystem.Directory(context.DocumentRoot); var documentUrlRoot = myFileSystem.Directory(myContext.DocumentUrlRoot); myBacksteps = documentUrlRoot.GetPathBackToRoot(myDocumentRoot); }
public SocialConnectedSettingsProvider( ILinkManager linkManager, IPageContext pageContext, IRenderingContext renderingContext, IDatabase database) { _linkManager = linkManager; _pageContext = pageContext; _renderingContext = renderingContext; _database = database; }
private void RenderIndicatorSummeryRow(IndicatorResult result, IRenderingContext context) { context.Document.WriteLine("<tr>"); context.Document.WriteLine("<td>{0}</td>", result.Indicator); RenderSignal(result, context); context.Document.WriteLine("<td align=\"right\">{0}</td>", HtmlRenderingUtils.GetDisplayText(result.GainRiskRatio)); context.Document.WriteLine("<td align=\"right\">{0}</td>", HtmlRenderingUtils.GetDisplayText(result.ExpectedGain)); context.Document.WriteLine("</tr>"); }
private void RenderTableHeader(IRenderingContext context) { context.Document.WriteLine("<tr>"); context.Document.WriteLine("<th>Indicator</th>"); context.Document.WriteLine("<th>Signal</th>"); context.Document.WriteLine("<th>Gain/Risk ratio</th>"); context.Document.WriteLine("<th>Expected gain</th>"); context.Document.WriteLine("</tr>"); }
public void Not_setting_rendering_context_results_in_original_behaviour() { // Arrange var glassUserControl = new GlassUserControl <StubClass>(); // Act IRenderingContext result = glassUserControl.RenderingContext; // Assert result.Should().NotBeNull(); result.GetType().Should().Be(typeof(RenderingContextUserControlWrapper)); }
public void Not_setting_rendering_context_results_in_original_behaviour() { // Arrange var glassUserControl = new GlassUserControl <StubClass>(); // Act IRenderingContext result = glassUserControl.RenderingContext; // Assert Assert.NotNull(result); Assert.AreEqual(typeof(RenderingContextUserControlWrapper), result.GetType()); }
protected override BuiltinContextsContainer GetBuiltinContexts(IRenderingContext context) { if(context == null) { throw new ArgumentNullException(nameof(context)); } var originalAttrs = new Lazy<OriginalAttributeValuesCollection>(() => context.GetOriginalAttributes()); return new MvcContextsContainer(this.GetKeywordOptions(), this.GetRepetitionSummaries(), originalAttrs, ViewContext); }
/// <summary> /// Initializes a new instance of the <see cref="CSF.Zpt.Tal.AttributeHandlingResult"/> class. /// </summary> /// <param name="elements">The elements which remain after processing.</param> /// <param name="continueHandling">If set to <c>true</c> continue handling.</param> /// <param name="newlyExposedElements">An optional collection of elements which are newly-exposed but must be processed from scratch.</param> public AttributeHandlingResult(IRenderingContext[] elements, bool continueHandling, IRenderingContext[] newlyExposedElements = null) { if(elements == null) { throw new ArgumentNullException(nameof(elements)); } this.Contexts = elements; this.ContinueHandling = continueHandling; this.NewlyExposedContexts = newlyExposedElements?? new IRenderingContext[0]; }
public SocialConnectedRenderingController( SocialConnectedSettings settings, IPageContext pageContext, IRenderingContext renderingContext, IAuthenticationManager authenticationManager, ITranslate translate) { _settings = settings; _pageContext = pageContext; _renderingContext = renderingContext; _authenticationManager = authenticationManager; _translate = translate; }
public void Begin() { DeviceEventArgs args = new DeviceEventArgs(); if (GetDevice != null) { GetDevice(this, args); } GraphicsDevice = args.Device; renderContext = new XnaRenderingContext(GraphicsDevice); initialized = true; Start(); }
/// <summary> /// Visit the given context and return a collection of the resultant contexts. /// </summary> /// <returns>Zero or more <see cref="IRenderingContext"/> instances, determined by the outcome of this visit.</returns> /// <param name="context">The rendering context to visit.</param> public override IRenderingContext[] Visit(IRenderingContext context) { if(context == null) { throw new ArgumentNullException(nameof(context)); } IZptAttribute attrib; if((attrib = context.GetMetalAttribute(ZptConstants.Metal.DefineMacroAttribute)) != null) { context.MetalModel.AddGlobal(attrib.Value, context.Element); } return new [] { _macroExpander.ExpandMacros(context) }; }
private void Draw(Sprite sprite, IRenderingContext context, int layer) { if (PositionSrc == null) { throw new InvalidOperationException("SpriteComponent has not been initialized with a position source."); } float off_x = Parent.Screen.OffsetX; float off_y = Parent.Screen.OffsetY; if (sprite != null && Visible) { sprite.VerticalFlip = Parent.IsGravitySensitive ? Parent.Container.IsGravityFlipped : verticalFlip; sprite.Draw(context, layer, PositionSrc.Position.X - off_x, PositionSrc.Position.Y - off_y); } }
/// <summary> /// Evaluate the specified expression, for the given element and model. /// </summary> /// <param name="expression">The expression to evaluate.</param> /// <param name="context">The rendering context for the expression being evaluated.</param> /// <param name="model">The ZPT model, providing the context for evaluation.</param> public override ExpressionResult Evaluate(Expression expression, IRenderingContext context, ITalesModel model) { object result; try { result = _host.Evaluate(expression.Content, model.GetAllDefinitions()); } catch(Exception ex) { string message = String.Format(Resources.ExceptionMessages.EvaluationFailureFormat, expression.Content); throw new ModelEvaluationException(message, ex); } return new ExpressionResult(result); }
/// <summary> /// Gets a specific attribute by name (a TALES path fragment). /// </summary> /// <returns><c>true</c> if the path traversal was a success; <c>false</c> otherwise.</returns> /// <param name="pathFragment">The path fragment.</param> /// <param name="result">Exposes the result if the traversal was a success</param> /// <param name="currentContext">Gets the current rendering context.</param> public bool HandleTalesPath(string pathFragment, out object result, IRenderingContext currentContext) { bool output; if(_attributes.ContainsKey(pathFragment)) { result = _attributes[pathFragment].Value; output = true; } else { result = null; output = false; } return output; }
/// <summary> /// Visit the given context, as well as its child contexts, and return a collection of the resultant contexts. /// </summary> /// <remarks> /// <para> /// This operation performs the same work as <see cref="Visit"/>, but it then visits all of the resultant contexts, /// recursively moving down the exposed document tree, visiting each context in turn. /// </para> /// </remarks> /// <returns>Zero or more <see cref="IRenderingContext"/> instances, determined by the outcome of this visit.</returns> /// <param name="context">The rendering context to visit.</param> public virtual IRenderingContext[] VisitRecursively(IRenderingContext context) { if(context == null) { throw new ArgumentNullException(nameof(context)); } var output = this.Visit(context); var children = output.SelectMany(x => x.GetChildContexts()); foreach(var child in children) { this.VisitRecursively(child); } return output; }
/// <summary> /// Evaluate the specified expression and return the result. /// </summary> /// <remarks> /// <para> /// This implementation is hard-coded to return an <see cref="ExpressionResult"/> which indicates an evaluation /// failure. /// </para> /// </remarks> /// <param name="expression">The expression to evaluate.</param> /// <param name="element">The element for which we are evaluating a result.</param> public override ExpressionResult Evaluate(string expression, IRenderingContext context) { object result; ExpressionResult output; if(this.TryGetItem(expression, context, out result)) { output = new ExpressionResult(result); } else { string message = String.Format("The item '{0}' was not found in the model.", expression); throw new InvalidOperationException(message); } return output; }
/// <summary> /// Examines the given <see cref="IZptElement"/> and - if it has an attribute referencing another macro - gets that /// macro from the given <see cref="Model"/>. /// </summary> /// <returns>Either an <see cref="IZptElement"/> instance representing the referenced macro, or a <c>null</c> reference.</returns> /// <param name="context">The rendering context.</param> /// <param name="attributeName">The name of the desired attribute, which references a macro if present.</param> private IZptElement GetReferencedMacro(IRenderingContext context, string attributeName) { if(context == null) { throw new ArgumentNullException(nameof(context)); } IZptElement output; var attrib = context.GetMetalAttribute(attributeName); if(attrib != null) { ExpressionResult result; try { result = context.MetalModel.Evaluate(attrib.Value, context); output = result.GetValue<IZptElement>().Clone(); } catch(Exception ex) { string message = String.Format(Resources.ExceptionMessages.UnexpectedExceptionGettingMacro, attributeName, attrib.Value, context.Element.GetFullFilePathAndLocation()); throw new RenderingException(message, ex); } if(output == null) { string message = String.Format(Resources.ExceptionMessages.CannotFindMacro, attributeName, attrib.Value, context.Element.GetFullFilePathAndLocation()); throw new MacroNotFoundException(message); } } else { output = null; } return output; }
/// <summary> /// Handle the related attribute types which exist upon the element exposed by the given context, if any. /// </summary> /// <returns>A response type providing information about the result of this operation.</returns> /// <param name="context">The rendering context, which exposes a ZPT element.</param> public AttributeHandlingResult Handle(IRenderingContext context) { if(context == null) { throw new ArgumentNullException(nameof(context)); } AttributeHandlingResult output; var attrib = context.GetTalAttribute(ZptConstants.Tal.OmitTagAttribute); if(attrib != null) { if(attrib.Value.Length == 0) { var children = context.Element.Omit(); output = new AttributeHandlingResult(new RenderingContext[0], false, children.Select(x => context.CreateSiblingContext(x)).ToArray()); } else { // Normal handling by detecting an attribute and using its value var result = context.TalModel.Evaluate(attrib.Value, context); if(!result.CancelsAction && result.GetValueAsBoolean()) { var children = context.Element.Omit(); output = new AttributeHandlingResult(new RenderingContext[0], false, children.Select(x => context.CreateSiblingContext(x)).ToArray()); } else { output = new AttributeHandlingResult(new [] { context }, true); } } } else { output = new AttributeHandlingResult(new [] { context }, true); } return output; }
/// <summary> /// Initializes a new instance of the <see cref="CSF.Zpt.Metal.SlotToFill"/> class. /// </summary> /// <param name="slot">The slot definition.</param> /// <param name="filler">The slow filler.</param> /// <param name="name">The slot name.</param> public SlotToFill(IRenderingContext slot, IRenderingContext filler, string name) { if(slot == null) { throw new ArgumentNullException(nameof(slot)); } if(filler == null) { throw new ArgumentNullException(nameof(filler)); } if(name == null) { throw new ArgumentNullException(nameof(name)); } Slot = slot; Filler = filler; Name = name; }
/// <summary> /// Handle the related attribute types which exist upon the element exposed by the given context, if any. /// </summary> /// <returns>A response type providing information about the result of this operation.</returns> /// <param name="context">The rendering context, which exposes a ZPT element.</param> public AttributeHandlingResult Handle(IRenderingContext context) { if(context == null) { throw new ArgumentNullException(nameof(context)); } AttributeHandlingResult output; var attrib = context.GetTalAttribute(ZptConstants.Tal.OnErrorAttribute); if(attrib != null) { string mode; var expressionResult = this.GetAttributeResult(attrib, context, out mode); if(expressionResult.CancelsAction) { output = new AttributeHandlingResult(new [] { context }, true); } else if(expressionResult.Value == null) { context.Element.RemoveAllChildren(); output = new AttributeHandlingResult(new [] { context }, true); } else { context.Element.ReplaceChildrenWith(expressionResult.GetValue<string>(), mode == STRUCTURE_INDICATOR); output = new AttributeHandlingResult(new [] { context }, true); } ZptConstants.TraceSource.TraceInformation(Resources.LogMessageFormats.TalErrorHandled, context.Element.GetFullFilePathAndLocation(), nameof(OnErrorAttributeHandler), nameof(Handle)); } else { output = new AttributeHandlingResult(new [] { context }, true); } return output; }
/// <summary> /// Gets the drawing context. /// </summary> /// <param name="contextId">A context id like 2d.</param> /// <returns>An object that defines the drawing context.</returns> public IRenderingContext GetContext(String contextId) { if (_current != null && contextId.Isi(_current.ContextId)) return _current; var renderService = Owner.Options.GetService<IRenderingService>(); if (renderService == null) return null; var context = renderService.CreateContext(this, contextId); if (context != null) { _mode = GetModeFrom(contextId); _current = context; } return context; }
/// <summary> /// Gets the drawing context. /// </summary> /// <param name="contextId">A context id like 2d.</param> /// <returns>An object that defines the drawing context.</returns> public IRenderingContext GetContext(String contextId) { if (_current != null && _current.ContextId.Equals(contextId, StringComparison.OrdinalIgnoreCase)) return _current; var renderService = Owner.Options.GetService<IRenderingService>(); if (renderService == null) return null; var context = renderService.CreateContext(this, contextId); if (context != null) { _mode = GetModeFrom(contextId); _current = context; } return context; }
public override ExpressionResult Evaluate(string expression, IRenderingContext context) { object result; ExpressionResult output; if(this.TryGetItem(expression, context, out result)) { output = new ExpressionResult(result); } else { string message = String.Format(Resources.ExceptionMessages.ModelDoesNotContainItem, expression); throw new ModelEvaluationException(message) { ElementName = context.Element.Name, ExpressionText = expression.ToString(), }; } return output; }
/// <summary> /// Handle the related attribute types which exist upon the element exposed by the given context, if any. /// </summary> /// <returns>A response type providing information about the result of this operation.</returns> /// <param name="context">The rendering context, which exposes a ZPT element.</param> public AttributeHandlingResult Handle(IRenderingContext context) { if(context == null) { throw new ArgumentNullException(nameof(context)); } AttributeHandlingResult output = new AttributeHandlingResult(new [] { context }, true); var attribute = context.GetTalAttribute(ZptConstants.Tal.ConditionAttribute); if(attribute != null) { ExpressionResult result; try { result = context.TalModel.Evaluate(attribute.Value, context); } catch(Exception ex) { string message = String.Format(ExceptionMessages.ExpressionEvaluationException, ZptConstants.Tal.Namespace, ZptConstants.Tal.ConditionAttribute, attribute.Value, context.Element.Name); throw new ModelEvaluationException(message, ex) { ExpressionText = attribute.Value, ElementName = context.Element.Name, }; } var removeElement = result.CancelsAction? false : !result.GetValueAsBoolean(); if(removeElement) { context.Element.Remove(); output = new AttributeHandlingResult(new RenderingContext[0], false); } } return output; }
/// <summary> /// Evaluate the specified expression, for the given element and model. /// </summary> /// <param name="expression">The expression to evaluate.</param> /// <param name="context">The rendering context for the expression being evaluated.</param> /// <param name="model">The ZPT model, providing the context for evaluation.</param> public override ExpressionResult Evaluate(Expression expression, IRenderingContext context, ITalesModel model) { if(expression == null) { throw new ArgumentNullException(nameof(expression)); } if(context == null) { throw new ArgumentNullException(nameof(context)); } if(model == null) { throw new ArgumentNullException(nameof(model)); } var trimmedContent = expression.Content.TrimStart(); var result = model.Evaluate(ExpressionCreator.Create(trimmedContent), context); bool booleanResult = this.CoerceToBoolean(result); return new ExpressionResult(!booleanResult); }
/// <summary> /// Evaluate the specified expression, for the given element and model. /// </summary> /// <param name="expression">The expression to evaluate.</param> /// <param name="context">The rendering context for the expression being evaluated.</param> /// <param name="model">The ZPT model, providing the context for evaluation.</param> public override ExpressionResult Evaluate(Expression expression, IRenderingContext context, ITalesModel model) { if(expression == null) { throw new ArgumentNullException(nameof(expression)); } if(context == null) { throw new ArgumentNullException(nameof(context)); } if(model == null) { throw new ArgumentNullException(nameof(model)); } string source = expression.Content, output; var escapeSequenceIndices = this.FindAndUnescapePlaceholders(source, out output); output = this.ApplyPlaceholderReplacements(output, escapeSequenceIndices, context, model); return new ExpressionResult(output); }
/// <summary> /// Expands the given context, replacing it with a new context - representing a macro - if it is required. /// </summary> /// <param name="context">The context to expand.</param> public virtual IRenderingContext ExpandMacros(IRenderingContext context) { if(context == null) { throw new ArgumentNullException(nameof(context)); } IRenderingContext output; var macro = GetUsedMacro(context); if(macro != null) { output = ExtendAndSubstitute(context, macro); } else { output = HandleNoUsedMacro(context); } return output; }
/// <summary> /// Evaluate the specified expression, for the given element and model. /// </summary> /// <param name="expression">The expression to evaluate.</param> /// <param name="context">The rendering context for the expression being evaluated.</param> /// <param name="model">The ZPT model, providing the context for evaluation.</param> public override ExpressionResult Evaluate(Expression expression, IRenderingContext context, ITalesModel model) { if(expression == null) { throw new ArgumentNullException(nameof(expression)); } if(context == null) { throw new ArgumentNullException(nameof(context)); } if(model == null) { throw new ArgumentNullException(nameof(model)); } var expressionText = expression.Content; var allDefinitions = model.GetAllDefinitions(); var csharpExpression = _expressionService.GetExpression(expressionText, allDefinitions.Keys); return new ExpressionResult(csharpExpression.Evaluate(allDefinitions)); }
/// <summary> /// Gets the result of the attribute value. /// </summary> /// <returns>The attribute result.</returns> /// <param name="attribute">The content or replace attribute.</param> /// <param name="context">The rendering context.</param> /// <param name="mode">Exposes the mode (either <c>text</c>, <c>structure</c> or a <c>null</c> reference).</param> private ExpressionResult GetAttributeResult(IZptAttribute attribute, IRenderingContext context, out string mode) { var match = ValueMatcher.Match(attribute.Value); if(!match.Success) { string message = String.Format(ExceptionMessages.ZptAttributeParsingError, ZptConstants.Tal.Namespace, attribute.Name, attribute.Value, context.Element.Name); throw new ParserException(message) { SourceAttributeName = attribute.Name, SourceAttributeValue = attribute.Value, SourceElementName = context.Element.Name }; } mode = match.Groups[1].Value; return context.TalModel.Evaluate(match.Groups[2].Value, context); }