Ejemplo n.º 1
0
 public async Task ContributeAsync(PageToolbarContributionContext context)
 {
     if (await ShouldAddComponentAsync(context))
     {
         context.Items.Add(new PageToolbarItem(ComponentType, Arguments, Order));
     }
 }
Ejemplo n.º 2
0
 public Task ContributeAsync(PageToolbarContributionContext context)
 {
     context.Items.RemoveAll(i => i.ComponentType == typeof(MyPageComponent1));
     context.Items.Add(new PageToolbarItem(typeof(MyPageComponent3)));
     context.Items.Add(new PageToolbarItem(typeof(MyPageComponent4)));
     return(Task.CompletedTask);
 }
Ejemplo n.º 3
0
    protected virtual async Task <bool> ShouldAddComponentAsync(PageToolbarContributionContext context)
    {
        if (RequiredPolicyName != null)
        {
            var authorizationService = context.ServiceProvider.GetRequiredService <IAuthorizationService>();
            if (!await authorizationService.IsGrantedAsync(RequiredPolicyName))
            {
                return(false);
            }
        }

        return(true);
    }
Ejemplo n.º 4
0
    public virtual async Task <PageToolbarItem[]> GetItemsAsync(PageToolbar toolbar)
    {
        if (toolbar == null || !toolbar.Contributors.Any())
        {
            return(Array.Empty <PageToolbarItem>());
        }

        using (var scope = ServiceScopeFactory.CreateScope())
        {
            var context = new PageToolbarContributionContext(scope.ServiceProvider);

            foreach (var contributor in toolbar.Contributors)
            {
                await contributor.ContributeAsync(context);
            }

            return(context.Items.OrderBy(i => i.Order).ToArray());
        }
    }
Ejemplo n.º 5
0
 public Task ContributeAsync(PageToolbarContributionContext context)
 {
     context.Items.Add(new PageToolbarItem(typeof(MyPageComponent1)));
     context.Items.Add(new PageToolbarItem(typeof(MyPageComponent2)));
     return(Task.CompletedTask);
 }
Ejemplo n.º 6
0
 public abstract Task ContributeAsync(PageToolbarContributionContext context);