Exemple #1
0
        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);
        }
Exemple #2
0
        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.");
        }
Exemple #3
0
        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);
        }
Exemple #4
0
 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;
 }
Exemple #5
0
 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();
 }
Exemple #6
0
        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;
            });
        }
Exemple #7
0
        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");
        }
Exemple #8
0
 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;
     }
 }
Exemple #9
0
 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!");
 }
Exemple #10
0
 public ScheduleParserCal(TreasureEntities context) : base(context, null)
 {
 }
Exemple #11
0
 public LocallyCachedController(CacheItemType type, TreasureEntities dbContext, IThrottleService throttlingService)
 {
     Type              = type;
     DbContext         = dbContext;
     ThrottlingService = throttlingService;
 }
Exemple #12
0
 public ShipController(TreasureEntities dbContext, IThrottleService throttlingService) : base(CacheItemType.Ship, dbContext, throttlingService)
 {
 }
Exemple #13
0
 public UnitController(TreasureEntities dbContext, IMapper autoMapper, IThrottleService throttlingService) : base(CacheItemType.Unit, dbContext, throttlingService)
 {
 }
Exemple #14
0
 public DonationController(TreasureEntities dbContext, IMapper autoMapper, IThrottleService throttlingService, UserManager <ApplicationUser> userManager, IDonationService donationService) : base(dbContext, autoMapper, throttlingService)
 {
     _userManager     = userManager;
     _donationService = donationService;
 }
Exemple #15
0
 public ProfileContoller(TreasureEntities dbContext, IMapper autoMapper, IThrottleService throttlingService, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager) : base(dbContext, autoMapper, throttlingService)
 {
     _userManager = userManager;
 }
Exemple #16
0
 public UnitFlagParser(TreasureEntities context) : base(context, OptcDbUnitFlagData)
 {
 }
Exemple #17
0
 public MetadataService(TreasureEntities dbContext)
 {
     _dbContext = dbContext;
 }
Exemple #18
0
 public TeamMiniDbSearchService(TreasureEntities entities)
 {
     _entities = entities;
 }
Exemple #19
0
 public StageParser(TreasureEntities context) : base(context, OptcDbStageData)
 {
     _existing = new HashSet <int>();
 }
Exemple #20
0
 public TeamController(TeamSearchService searchService, TreasureEntities dbContext, IMapper autoMapper, IThrottleService throttlingService) : base(dbContext, autoMapper, throttlingService)
 {
     _searchService = searchService;
 }
Exemple #21
0
 public UnitAliasParser(TreasureEntities context) : base(context, OptcDbUnitData)
 {
 }
Exemple #22
0
 public PaypalDonationService(IHostingEnvironment env, IConfigurationRoot config, TreasureEntities entities) : base(env, config, entities)
 {
 }
Exemple #23
0
 public TeamCommentController(TreasureEntities dbContext, IMapper autoMapper, IThrottleService throttlingService) : base(dbContext, autoMapper, throttlingService)
 {
 }
Exemple #24
0
 public ShipParser(TreasureEntities context) : base(context, OptcDbUnitData)
 {
 }
Exemple #25
0
 protected DonationService(IHostingEnvironment env, IConfigurationRoot config, TreasureEntities entities)
 {
     IsTesting = env.IsDevelopment();
     Config    = config;
     Entities  = entities;
 }
Exemple #26
0
 public BoxController(IPreferenceService preferenceService, TreasureEntities dbContext, IMapper autoMapper, IThrottleService throttlingService) : base(dbContext, autoMapper, throttlingService)
 {
     Throttled          = true;
     _preferenceService = preferenceService;
 }
Exemple #27
0
 public PreferenceService(TreasureEntities entities)
 {
     _entities = entities;
 }
Exemple #28
0
 public EntityApiController(TreasureEntities dbContext, IMapper autoMapper, IThrottleService throttlingService)
 {
     DbContext         = dbContext;
     AutoMapper        = autoMapper;
     ThrottlingService = throttlingService;
 }
Exemple #29
0
 protected SearchableApiController(TreasureEntities dbContext, IMapper autoMapper, IThrottleService throttlingService) : base(dbContext, autoMapper, throttlingService)
 {
 }
Exemple #30
0
 public AuthExportService(IOptions <JwtIssuerOptions> jwtOptions, TreasureEntities context, IMapper mapper)
 {
     _jwtOptions = jwtOptions.Value;
     _context    = context;
     _mapper     = mapper;
 }