Пример #1
0
        public async ValueTask <FluidValue> ProcessAsync(FluidValue input, FilterArguments arguments, LiquidTemplateContext context)
        {
            var shortcodeContext = new Context();

            // Retrieve the 'ContentItem' from the ambient liquid scope.
            var model = context.GetValue("Model").ToObjectValue();

            if (model is Shape shape && shape.Properties.TryGetValue("ContentItem", out var contentItem))
            {
                shortcodeContext["ContentItem"] = contentItem;
            }
Пример #2
0
        internal static async Task EnterScopeAsync(this LiquidTemplateContext context, object?model, Action <Scope> scopeAction)
        {
            if (context is LiquidTemplateContextInternal contextInternal)
            {
                if (!contextInternal.IsInitialized)
                {
                    context.AmbientValues.EnsureCapacity(9);
                    context.AmbientValues.Add("Services", context.Services);

                    var shapeRenderer = context.Services.GetRequiredService <IShapeRenderer>();
                    context.AmbientValues.Add("ShapeRenderer", shapeRenderer);

                    var shapeFactory = context.Services.GetRequiredService <IShapeFactory>();
                    context.AmbientValues.Add("ShapeFactory", shapeFactory);

                    var options = context.Services.GetRequiredService <IOptions <LiquidOptions> >().Value;

                    context.AddAsyncFilters(options);

                    foreach (var handler in context.Services.GetServices <ILiquidTemplateEventHandler>())
                    {
                        await handler.RenderingAsync(context);
                    }

                    context.CultureInfo           = CultureInfo.CurrentUICulture;
                    contextInternal.IsInitialized = true;
                }

                context.EnterChildScope();

                if (model != null)
                {
                    context.MemberAccessStrategy.Register(model.GetType());
                }

                if (context.GetValue("Model")?.ToObjectValue() == model && model is IShape shape)
                {
                    if (contextInternal.ShapeRecursions++ > LiquidTemplateContextInternal.MaxShapeRecursions)
                    {
                        throw new InvalidOperationException(
                                  $"The '{shape.Metadata.Type}' shape has been called recursively more than {LiquidTemplateContextInternal.MaxShapeRecursions} times.");
                    }
                }
                else
                {
                    contextInternal.ShapeRecursions = 0;
                }
            }

            context.SetValue("Model", model);
            scopeAction?.Invoke(context.LocalScope);
        }
Пример #3
0
        public ValueTask <FluidValue> ProcessAsync(FluidValue input, FilterArguments arguments, LiquidTemplateContext ctx)
        {
            var urlHelper = _urlHelperFactory.GetUrlHelper(ctx.ViewContext);

            var workflowContextValue = ctx.GetValue("Workflow");

            if (workflowContextValue.IsNil())
            {
                throw new ArgumentException("WorkflowExecutionContext missing while invoking 'signal_url'");
            }

            var workflowContext = (WorkflowExecutionContext)workflowContextValue.ToObjectValue();
            var signalName      = input.ToStringValue();
            var payload         = String.IsNullOrWhiteSpace(workflowContext.CorrelationId)
                ? SignalPayload.ForWorkflow(signalName, workflowContext.WorkflowId)
                : SignalPayload.ForCorrelation(signalName, workflowContext.CorrelationId);

            var token    = _securityTokenService.CreateToken(payload, TimeSpan.FromDays(7));
            var urlValue = new StringValue(urlHelper.Action("Trigger", "HttpWorkflow", new { area = "OrchardCore.Workflows", token }));

            return(new ValueTask <FluidValue>(urlValue));
        }