本文整理汇总了C#中DotLiquid.Context.GetWorkContext方法的典型用法代码示例。如果您正苦于以下问题:C# Context.GetWorkContext方法的具体用法?C# Context.GetWorkContext怎么用?C# Context.GetWorkContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DotLiquid.Context
的用法示例。
在下文中一共展示了Context.GetWorkContext方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IncludeResource
protected RequireSettings IncludeResource(string resourceType, string resourcePath, Context context)
{
var workContext = context.GetWorkContext();
var resourceManager = workContext.Resolve<IResourceManager>();
var pathResolver = workContext.Resolve<ITemplateItemProvidedPathResolver>();
var renderingContext = context.GetTemplateRenderingContext();
// If a template file is being rendered then resources paths can be used as usual from themes; if a
// template item is rendered then relative virtual paths should be handled the same way (those reference
// flat files).
if (renderingContext.TemplateType == Models.TemplateType.TemplateFile ||
(resourcePath.StartsWith("~") && pathResolver.IsRealVirtualPath(resourcePath)))
{
var resourceRegister = new ResourceRegister(
new DummyWebPage { VirtualPath = renderingContext.TemplatePath },
resourceManager,
resourceType);
return resourceRegister.Include(resourcePath);
}
else
{
if (!resourcePath.StartsWith("//") &&
!resourcePath.StartsWith("http://", StringComparison.OrdinalIgnoreCase) &&
!resourcePath.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
{
resourcePath = pathResolver.GenerateUrlFromPath(resourcePath);
}
return resourceManager.Include(resourceType, resourcePath, resourcePath);
}
}
示例2: Display
public static string Display(Context context, dynamic input)
{
if (input == null || !(input is StaticShape)) return string.Empty;
StaticShape shape = input;
var wc = context.GetWorkContext();
// Checking if the shape is displayed multiple times. If yes it can be legitimate (although rare) but
// can also indicate unwanted recursion, so capping it.
if (shape.Shape.DisplayedCount == null) shape.Shape.DisplayedCount = 0;
if (shape.Shape.DisplayedCount >= Constants.MaxAllowedShapeDisplayCount)
{
wc.LogSecurityNotificationWithContext(typeof(DisplayFilter), "Too many displays of the same shape prevented.");
return string.Empty;
}
shape.Shape.DisplayedCount++;
if (!context.ShapeIsWithinAllowedRecursionDepth(shape.Metadata.Type))
{
wc.LogSecurityNotificationWithContext(typeof(DisplayFilter), "Too many recursive shape displays prevented.");
return string.Empty;
}
context.AddCurrentShapeAsParentToShape((IShape)shape.Shape);
return wc.Resolve<IShapeDisplay>().Display(shape.Shape);
}
示例3: Render
public override void Render(Context context, TextWriter result)
{
if (string.IsNullOrEmpty(_titleParameter)) return;
context
.GetWorkContext()
.Resolve<IPageTitleBuilder>()
.AddTitleParts(_titleParameter.EvaluateAsStringProducingParameter(context));
}
示例4: Render
public override void Render(Context context, TextWriter result)
{
var wc = context.GetWorkContext();
var resourceManager = wc.Resolve<IResourceManager>();
resourceManager.SetMeta(new MetaEntry
{
Charset = _charsetParameter.EvaluateAsStringProducingParameter(context),
Content = _contentParameter.EvaluateAsStringProducingParameter(context),
HttpEquiv = _httpEquivParameter.EvaluateAsStringProducingParameter(context),
Name = _nameParameter.EvaluateAsStringProducingParameter(context)
});
}
示例5: Render
public override void Render(Context context, TextWriter result)
{
var wc = context.GetWorkContext();
var resourceManager = wc.Resolve<IResourceManager>();
resourceManager.RegisterLink(new LinkEntry
{
Condition = _conditionParameter.EvaluateAsStringProducingParameter(context),
Href = _hrefParameter.EvaluateAsStringProducingParameter(context),
Rel = _relParameter.EvaluateAsStringProducingParameter(context),
Title = _titleParameter.EvaluateAsStringProducingParameter(context),
Type = _typeParameter.EvaluateAsStringProducingParameter(context)
});
}
示例6: Render
public override void Render(Context context, TextWriter result)
{
if (string.IsNullOrEmpty(_shapeType)) return;
var wc = context.GetWorkContext();
if (!context.ShapeIsWithinAllowedRecursionDepth(_shapeType))
{
wc.LogSecurityNotificationWithContext(typeof(DisplayTag), "Too many recursive shape displays prevented.");
return;
}
var argumentsDictionary = _arguments.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.EvaluateAsParameter(context));
var shape = wc.Resolve<IShapeFactory>().Create(_shapeType, Arguments.From(argumentsDictionary));
context.AddCurrentShapeAsParentToShape(shape);
result.Write(wc.Resolve<IShapeDisplay>().Display(shape));
}
示例7: Render
public override void Render(Context context, TextWriter result)
{
if (string.IsNullOrEmpty(_resourceReferenceParameter)) return;
var resourceManager = context.GetWorkContext().Resolve<IResourceManager>();
var evaluatedResourceReferenceParameter = _resourceReferenceParameter.EvaluateAsStringProducingParameter(context);
RequireSettings script;
// _resourceReference can be a resource name or an URL.
if (TagName.Equals("scriptrequire", StringComparison.InvariantCultureIgnoreCase))
{
script = RequireResource("script", evaluatedResourceReferenceParameter, context);
}
else
{
script = IncludeResource("script", evaluatedResourceReferenceParameter, context);
}
script.Location = _location;
}
示例8: Render
public override void Render(Context context, TextWriter result)
{
if (_parameters == null || !_parameters.Any()) return;
context.GetWorkContext().Resolve<IPageClassBuilder>().AddClassNames(GetEvaluatedParameters(context));
}
示例9: RequireResource
protected RequireSettings RequireResource(string resourceType, string resourceName, Context context)
{
return context.GetWorkContext().Resolve<IResourceManager>().Require(resourceType, resourceName);
}