public void DataContext_IsValid() { var context = new TreasureEntities("Server=(localdb)\\tcdb;Database=tcdb;Trusted_Connection=True;MultipleActiveResultSets=true"); var getStuff = context.UserProfiles.FirstOrDefault(); Assert.IsNotNull(context); }
public static async Task BuildCache <TEntity, TCache>(TreasureEntities entities, IMapper mapper, CacheItemType type, DateTimeOffset timestamp) where TEntity : class { Debug.WriteLine("Building cache for " + type); var data = entities.Set <TEntity>().AsQueryable(); var cast = await data.ProjectTo <TCache>(mapper.ConfigurationProvider).ToListAsync(); var json = JsonConvert.SerializeObject(cast, JsonSettings); var existing = await entities.CacheSets.SingleOrDefaultAsync(x => x.Type == type); var existed = existing != null; if (!existed) { existing = new CacheSet { Type = type }; entities.CacheSets.Add(existing); } existing.JSON = json; existing.EditedDate = timestamp; await entities.SaveChangesAsync(); Debug.WriteLine("Cache built."); }
private static async Task PostRun(TreasureEntities context, IMapper mapper) { await context.SaveChangesAsync(); var timestamp = DateTimeOffset.UtcNow; await CacheBuilder.BuildCache <Unit, UnitStubModel>(context, mapper, CacheItemType.Unit, timestamp); await CacheBuilder.BuildCache <Stage, StageStubModel>(context, mapper, CacheItemType.Stage, timestamp); await CacheBuilder.BuildCache <Ship, ShipStubModel>(context, mapper, CacheItemType.Ship, timestamp); }
public AccountController( UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, IOptions <IdentityCookieOptions> identityCookieOptions, ILoggerFactory loggerFactory, TreasureEntities entities) { _userManager = userManager; _signInManager = signInManager; _externalCookieScheme = identityCookieOptions.Value.ExternalCookieAuthenticationScheme; _logger = loggerFactory.CreateLogger <AccountController>(); _entities = entities; }
private static async Task PreRun(TreasureEntities context) { context.Teams.Clear(); context.TeamUnits.Clear(); context.ScheduledEvents.Clear(); context.StageAliases.Clear(); context.Stages.Clear(); context.Ships.Clear(); context.UnitAliases.Clear(); context.UnitEvolutions.Clear(); context.Units.Clear(); context.CacheSets.Clear(); await context.SaveChangesAsync(); }
private static void RunParsers(TreasureEntities context, IMapper mapper, IConfigurationRoot configuration) { IEnumerable <IParser> parsers = new IParser[] { new UnitParser(context), new UnitFlagParser(context), new UnitAliasParser(context), new UnitEvolutionParser(context), new ShipParser(context), new StageParser(context), new ScheduleParserCal(context) }; // parsers = parsers.Concat(RedditImporter.GetThreads(configuration)); Running = true; ParsersRunning = parsers.Count(); Task.Run(async() => { await PreRun(context); foreach (var parser in parsers) { var name = parser.GetType().Name; try { Debug.WriteLine($"Running {name}."); await parser.Execute(); Debug.WriteLine($"{name} Succeeded!"); } catch (Exception e) { Debug.WriteLine($"{name} Failed!"); Debug.WriteLine(e); } finally { ParsersRunning--; Debug.WriteLine($"{ParsersRunning} Parser(s) Remain"); } GC.Collect(); } await PostRun(context, mapper); Running = false; }); }
public static void Main(string[] args) { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile("redditthreads.json", optional: true, reloadOnChange: true); var configuration = builder.Build(); var context = new TreasureEntities(configuration.GetConnectionString("TreasureEntities")); var mapper = MapperConfig.Create(); AssureContextOpen(context); RunParsers(context, mapper, configuration); while (Running || ParsersRunning > 0) { // ... } Debug.WriteLine("Seeya"); }
public static async Task SaveChangesSafe(this TreasureEntities entities) { try { await entities.SaveChangesAsync(); } catch (DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { var message = $"{validationErrors.Entry.Entity}:{validationError.ErrorMessage}"; // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } }
private static void AssureContextOpen(TreasureEntities context) { Debug.WriteLine("Checking if database is accessible."); Debug.WriteLine("There are " + context.Units.Count() + " unit(s) in the database right now."); Debug.WriteLine("Success!"); }
public ScheduleParserCal(TreasureEntities context) : base(context, null) { }
public LocallyCachedController(CacheItemType type, TreasureEntities dbContext, IThrottleService throttlingService) { Type = type; DbContext = dbContext; ThrottlingService = throttlingService; }
public ShipController(TreasureEntities dbContext, IThrottleService throttlingService) : base(CacheItemType.Ship, dbContext, throttlingService) { }
public UnitController(TreasureEntities dbContext, IMapper autoMapper, IThrottleService throttlingService) : base(CacheItemType.Unit, dbContext, throttlingService) { }
public DonationController(TreasureEntities dbContext, IMapper autoMapper, IThrottleService throttlingService, UserManager <ApplicationUser> userManager, IDonationService donationService) : base(dbContext, autoMapper, throttlingService) { _userManager = userManager; _donationService = donationService; }
public ProfileContoller(TreasureEntities dbContext, IMapper autoMapper, IThrottleService throttlingService, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager) : base(dbContext, autoMapper, throttlingService) { _userManager = userManager; }
public UnitFlagParser(TreasureEntities context) : base(context, OptcDbUnitFlagData) { }
public MetadataService(TreasureEntities dbContext) { _dbContext = dbContext; }
public TeamMiniDbSearchService(TreasureEntities entities) { _entities = entities; }
public StageParser(TreasureEntities context) : base(context, OptcDbStageData) { _existing = new HashSet <int>(); }
public TeamController(TeamSearchService searchService, TreasureEntities dbContext, IMapper autoMapper, IThrottleService throttlingService) : base(dbContext, autoMapper, throttlingService) { _searchService = searchService; }
public UnitAliasParser(TreasureEntities context) : base(context, OptcDbUnitData) { }
public PaypalDonationService(IHostingEnvironment env, IConfigurationRoot config, TreasureEntities entities) : base(env, config, entities) { }
public TeamCommentController(TreasureEntities dbContext, IMapper autoMapper, IThrottleService throttlingService) : base(dbContext, autoMapper, throttlingService) { }
public ShipParser(TreasureEntities context) : base(context, OptcDbUnitData) { }
protected DonationService(IHostingEnvironment env, IConfigurationRoot config, TreasureEntities entities) { IsTesting = env.IsDevelopment(); Config = config; Entities = entities; }
public BoxController(IPreferenceService preferenceService, TreasureEntities dbContext, IMapper autoMapper, IThrottleService throttlingService) : base(dbContext, autoMapper, throttlingService) { Throttled = true; _preferenceService = preferenceService; }
public PreferenceService(TreasureEntities entities) { _entities = entities; }
public EntityApiController(TreasureEntities dbContext, IMapper autoMapper, IThrottleService throttlingService) { DbContext = dbContext; AutoMapper = autoMapper; ThrottlingService = throttlingService; }
protected SearchableApiController(TreasureEntities dbContext, IMapper autoMapper, IThrottleService throttlingService) : base(dbContext, autoMapper, throttlingService) { }
public AuthExportService(IOptions <JwtIssuerOptions> jwtOptions, TreasureEntities context, IMapper mapper) { _jwtOptions = jwtOptions.Value; _context = context; _mapper = mapper; }