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