Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    // This seeds the domain databse
                    StorageConfigurator.SeedDatabase(services);
                    // This seeds the Identity database
                    var context     = services.GetRequiredService <PoliceStationManagementIdentityDbContext>();
                    var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    PoliceStationManagementIdentityDbContextSeeder.SeedAsync(context, userManager, roleManager).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }

            host.Run();
        }
Exemplo n.º 2
0
        public long GetDatabaseTransactionVersionSizeInBytes()
        {
            if (getDatabaseTransactionVersionSizeInBytesErrorValue != 0)
            {
                return(getDatabaseTransactionVersionSizeInBytesErrorValue);
            }

            try
            {
                const string categoryName = "Database ==> Instances";
                if (PerformanceCounterCategory.Exists(categoryName) == false)
                {
                    return(getDatabaseTransactionVersionSizeInBytesErrorValue = -1);
                }
                var          category      = new PerformanceCounterCategory(categoryName);
                var          instances     = category.GetInstanceNames();
                var          ravenInstance = instances.FirstOrDefault(x => x.Contains(uniquePrefix));
                const string counterName   = "Version Buckets Allocated";
                if (ravenInstance == null || !category.CounterExists(counterName))
                {
                    return(getDatabaseTransactionVersionSizeInBytesErrorValue = -2);
                }
                using (var counter = new PerformanceCounter(categoryName, counterName, ravenInstance, readOnly: true))
                {
                    var value = counter.NextValue();
                    return((long)(value * StorageConfigurator.GetVersionPageSize()));
                }
            }
            catch (Exception e)
            {
                if (reportedGetDatabaseTransactionCacheSizeInBytesError == false)
                {
                    reportedGetDatabaseTransactionCacheSizeInBytesError = true;
                    log.WarnException("Failed to get Version Buckets Allocated value, this error will only be reported once.", e);
                }
                return(getDatabaseTransactionVersionSizeInBytesErrorValue = -3);
            }
        }