Beispiel #1
0
 public async Task ContributeAsync(PageToolbarContributionContext context)
 {
     if (await ShouldAddComponentAsync(context))
     {
         context.Items.Add(new PageToolbarItem(ComponentType, Arguments, Order));
     }
 }
Beispiel #2
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);
        }
Beispiel #3
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());
            }
        }
Beispiel #4
0
 public abstract Task ContributeAsync(PageToolbarContributionContext context);