public static RolePermission[] BuildRolePermissions()
        {
            //grant all permissions to admin role
            var rolePermissions = DefaultPermissions.All().Select(p =>
                                                                  new RolePermission
            {
                PermissionId = p.Id,
                RoleId       = DefaultRoles.Admin.Id
            }).ToList();

            //grant member access permission to member role
            rolePermissions.Add(new RolePermission
            {
                PermissionId = DefaultPermissions.MemberAccess.Id,
                RoleId       = DefaultRoles.Member.Id
            });

            return(rolePermissions.ToArray());
        }
Example #2
0
        public static int Main(string[] args)
        {
            //AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                         .Enrich.FromLogContext()
                         .WriteTo.Console()
                         .WriteTo.File(
                "Logs/Logs.txt",
                fileSizeLimitBytes: 1_000_000,
                rollOnFileSizeLimit: true,
                shared: true,
                flushToDiskInterval: TimeSpan.FromSeconds(1))
                         .CreateLogger();

            try
            {
                Log.Information("Starting web host");

                Log.Information("Starting web host");
                var host = BuildWebHost(args);
                using (var scope = host.Services.CreateScope())
                {
                    var permissionAppService = scope.ServiceProvider.GetRequiredService <IPermissionService>();
                    permissionAppService.InitializePermissions(DefaultPermissions.All());
                }

                host.Run();
                return(0);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Host terminated unexpectedly");
                return(1);
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }
Example #3
0
 public static Permission[] BuildPermissions()
 {
     return(DefaultPermissions.All().ToArray());
 }