/// <summary> /// Enqueue ab idle connection /// </summary> /// <param name="dbContext">DB context</param> /// <returns>True(Enqueue successfully)/False(Exceeds the max connection and the connection will be disposed)</returns> public static bool Enqueue(PgDbContext dbContext) { lock (enqueueLock) { if (dbContextQueue.Count < MaxConnections) { dbContextQueue.Enqueue(dbContext); Debug.WriteLine($"[DbContextFactory] Enqueue succeed, current stored connections: {dbContextQueue.Count}"); return(true); } else { Debug.WriteLine($"[DbContextFactory] Enqueue failed, current stored connections: {dbContextQueue.Count}"); if (dbContext != null) { dbContext.Database.CloseConnection(); dbContext.Dispose(); dbContext = null; } return(false); } } }
/// <summary> /// Dequeue a preserved connection or create a new one /// </summary> /// <param name="db">Database</param> /// <returns>DB context</returns> public static PgDbContext Dequeue(string dbName) { if (string.IsNullOrEmpty(dbName)) { throw new ArgumentNullException("dbName"); } if (ConnectionStrings == null || !ConnectionStrings.ContainsKey(dbName)) { // Warning log //Debug.WriteLine($"{dbName} does not have the connection string in {nameof(DbContextFactory)}"); return(null); } if (dbContextQueue.TryDequeue(out PgDbContext output)) { Debug.WriteLine($"[DbContextFactory] Dequeue succeed, current stored connections: {dbContextQueue.Count}"); return(output); } else { Debug.WriteLine($"[DbContextFactory] Dequeue failed, current stored connections: {dbContextQueue.Count}"); // Create new DB context var connStr = ConnectionStrings[dbName]; var optionsBuilder = new DbContextOptionsBuilder <PgDbContext>(); optionsBuilder.UseNpgsql(connStr); var newDbContext = new PgDbContext(optionsBuilder.Options); // newDbContext.ChangeTracker.AutoDetectChangesEnabled = false; // Optional return(newDbContext); } }
public async Task <ApiUserInfo> GetUser([FromRoute] string name) { return(this.dbcontext.Set <User>().Include(u => u.Metadata).Where(x => x.Name.Equals(name)).Select(x => new ApiUserInfo { Name = x.Name, Phone = x.Phone, CardNo = x.CardNo, Secret = PgDbContext.DbSymDecrypt(x.Secret), Metadata = x.Metadata }).FirstOrDefault()); }
public async Task <IActionResult> AddUser([FromBody] User user) { await this.dbcontext.Set <User>().AddAsync(this.dbcontext.Set <User>().Select(x => new User { Name = user.Name, Password = user.Password, Phone = user.Phone, CardNo = user.CardNo, Secret = PgDbContext.DbSymEncrypt("some secret"), Metadata = new SysMetadata { CreateBy = "Admin", CreateOn = DateTimeOffset.UtcNow } }).First()); await this.dbcontext.SaveChangesAsync(); return(this.Ok()); }
public AccountRepository(PgDbContext dbContext) : base(dbContext) { }
public SubscriberService(PgDbContext pgDbContext, ICapPublisher capPublisher) { _pgDbContext = pgDbContext; _capPublisher = capPublisher; }
public CharacterRepository(PgDbContext dbContext) : base(dbContext) { }
public PublishController(ICapPublisher capPublisher, PgDbContext pgDbContext) { _capPublisher = capPublisher; _pgDbContext = pgDbContext; }
public CategoryRepository(PgDbContext dbContext) { _dbContext = dbContext; }
public async Task <IActionResult> SignIn([FromBody] ApiUser user) { var matchedUser = this.dbcontext.Set <User>().FirstOrDefault(x => x.Name.Equals(user.Name) && PgDbContext.DbHashMatch(user.Password, x.Password)); if (matchedUser != null) { return(this.Ok()); } else { return(this.BadRequest()); } }
public PermissionsRepository(PgDbContext dbContext) { this.dbContext = dbContext; }
public ProductRepository(PgDbContext context) : base(context) { }
public UserRoleRepository(PgDbContext dbContext) { this.dbContext = dbContext; }
public UnitOfWorkActionFilter(PgDbContext dbContext) => _dbContext = dbContext;
public ShopRepository(PgDbContext context) : base(context) { }
public PgRepository(PgDbContext pgDbContext) { this.pgDbContext = pgDbContext; }
public TransactionBehaviour(PgDbContext dbContext, ILogger <TransactionBehaviour <TRequest, TResponse> > logger) { _dbContext = dbContext ?? throw new ArgumentException(nameof(PgDbContext)); _logger = logger ?? throw new ArgumentException(nameof(ILogger)); }
public PgUnitOfWork(PgDbContext context) { _context = context; Sensors = new PgSensorRepository(_context); Controllers = new PgControllerRepository(_context); }
public ProductRepository(PgDbContext db) : base(db) { }
public PgSensorRepository(PgDbContext context) { _context = context; }
public UnitOfWork(PgDbContext pgContext) { _pgContext = pgContext; }
public DemoController(PgDbContext dbcontext, IOptions <AppSettings> configuration) { this.dbcontext = dbcontext; }
public RepositoryBase(PgDbContext context) { this.context = context; }
public RacesRepository(PgDbContext context) : base(context) { }
public WeaponItemPropertyRepository(PgDbContext context) : base(context) { }
public GenericRepository(PgDbContext pgContext) { _pgContext = pgContext; }
public WeaponRepository(PgDbContext context) : base(context) { }
public PgControllerRepository(PgDbContext context) { _context = context; }
public Repository(PgDbContext db) { Db = db; DbSet = db.Set <T>(); }