Ejemplo n.º 1
0
        private void CreateSqliteInMemoryTables(IDbConnectionFactory dbFactory)
        {
            try
            {
                using (IDbConnection db = dbFactory.OpenDbConnection())
                {
                    db.CreateTable<Todo>(true);
                    db.CreateTable<Account>(false);
                    db.CreateTable<Service>(false);
                    db.CreateTable<Tag>(false);
                    db.CreateTable<Content>(false);
                    db.CreateTable<ContentTag>(false);

                    Guid accountId = Guid.NewGuid();
                    Guid serviceId = Guid.NewGuid();

                    db.Insert<Todo>(new Todo { Id = Guid.NewGuid(), Content = "bla", Done = false, Order = 1 });
                    db.Insert<Account>(new Account { Id = accountId, FullName = "Metaintellect" });
                    db.Insert<Service>(new Service { Id = serviceId, Name = "content" });
                    db.Insert<Content>(new Content { Id = Guid.NewGuid(), Title = "New Title", CreatedAt = DateTime.Now, AccountId = accountId, ServiceId = serviceId });
                    db.Insert<Tag>(GetTags(accountId).ToArray());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                throw;
            }
        }
Ejemplo n.º 2
0
 public RepositoryProxy(IDbConnectionFactory dbConnectionFactory, IRedisClientsManager redisClientsManager)
 {
     DbConnectionFactory= dbConnectionFactory;
     RedisClientsManager= redisClientsManager;
     CreateCommand();
     CreateRedisClient();
 }
        public given_sender()
        {
            this.connectionFactory = System.Data.Entity.Database.DefaultConnectionFactory;
            this.sender = new MessageSender(this.connectionFactory, "TestSqlMessaging", "Test.Commands");

            MessagingDbInitializer.CreateDatabaseObjects(this.connectionFactory.CreateConnection("TestSqlMessaging").ConnectionString, "Test", true);
        }
Ejemplo n.º 4
0
        public DbAuthenticator(IDbConnectionFactory factory)
        {
            if (factory == null)
                throw new ArgumentNullException ("factory");

            connFactory = factory;
        }
Ejemplo n.º 5
0
        public Bootstrapper(IDbConnectionFactory connectionFactory)
        {
            _connectionFactory = connectionFactory;

            StaticConfiguration.DisableErrorTraces = false;
            StaticConfiguration.EnableRequestTracing = true;

            //Cross origin resource sharing
            ApplicationPipelines.AfterRequest.AddItemToEndOfPipeline(x => x.Response.WithHeader("Access-Control-Allow-Origin", "*"));
            ApplicationPipelines.AfterRequest.AddItemToEndOfPipeline(x => x.Response.WithHeader("Access-Control-Allow-Methods", "DELETE, GET, HEAD, POST, PUT, OPTIONS, PATCH"));
            ApplicationPipelines.AfterRequest.AddItemToEndOfPipeline(x => x.Response.WithHeader("Access-Control-Allow-Headers", "Content-Type"));
            ApplicationPipelines.AfterRequest.AddItemToEndOfPipeline(x => x.Response.WithHeader("Accept", "application/json"));

            //Default format to JSON (very low priority)
            ApplicationPipelines.BeforeRequest.AddItemToStartOfPipeline(x => {
                x.Request.Headers.Accept = x.Request.Headers.Accept.Concat(new Tuple<string, decimal>("application/json", 0.01m));
                return null;
            });

            //Make sure this is being accessed over a secure connection
            var httpsRedirect = SecurityHooks.RequiresHttps(redirect: false);
            ApplicationPipelines.BeforeRequest.AddItemToEndOfPipeline(x => {
                if (!IsSecure(x))
                    return httpsRedirect(x);
                return null;
            });
        }
Ejemplo n.º 6
0
        public static IBlogManager CreateManager(IBlogRepository repository = null,
            IDbConnectionFactory connectionFactory = null)
        {
            if (repository == null)
                repository = new BlogRepository();

            if (connectionFactory == null && repository.DbFactory == null)
            {
                if (ConfigurationManager.ConnectionStrings["BlogDB"] == null)
                {
                    connectionFactory =
                        new OrmLiteConnectionFactory(
                            ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString,
                            SqlServerOrmLiteDialectProvider.Instance);
                    repository.DbFactory = connectionFactory;
                }
                else
                {
                    connectionFactory =
                        new OrmLiteConnectionFactory(
                            ConfigurationManager.ConnectionStrings["BlogDB"].ConnectionString,
                            SqlServerOrmLiteDialectProvider.Instance);

                    repository.DbFactory = connectionFactory;
                }
            }

            return new BlogManager
            {
                BlogRepo = repository
            };
        }
 public SqlContextTransactionManager(IDbConnectionFactory connectionFactory, IContextTransactionLifetimeManager contextTransactionLifetimeManager, ILoggerFactory loggerFactory)
 {
     _connectionFactory = connectionFactory;
     _contextTransactionLifetimeManager = contextTransactionLifetimeManager;
     _loggerFactory = loggerFactory;
     _logger = loggerFactory.Create("EventSourcing.SqlContextTransactionManager");
 }
        public static LogViewerManager CreateManager(ILogViewerRepository repository = null, IDbConnectionFactory connectionFactory = null, string connectionStringMapping = null)
        {
            if (repository == null)
                repository = new LogViewerRepository();

            if (connectionStringMapping == null)
                connectionStringMapping = "LoggingConnection1";

            if (connectionFactory == null && repository.DbFactory == null)
            {
                if (ConfigurationManager.ConnectionStrings[connectionStringMapping] == null)
                {
                    connectionFactory =
                        new OrmLiteConnectionFactory(
                            ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString,
                            SqlServerOrmLiteDialectProvider.Instance);
                    repository.DbFactory = connectionFactory;
                }
                else
                {
                    connectionFactory =
                        new OrmLiteConnectionFactory(
                            ConfigurationManager.ConnectionStrings[connectionStringMapping].ConnectionString,
                            SqlServerOrmLiteDialectProvider.Instance);

                    repository.DbFactory = connectionFactory;
                }
            }

            return new LogViewerManager
            {
                LogViewerRepo = repository
            };
        }
Ejemplo n.º 9
0
        protected DbRepository(IDbConnectionFactory dbConnectionFactory)
        {
            if(dbConnectionFactory == null)
                throw new ArgumentNullException("dbConnectionFactory");

            this._dbConnectionFactory = dbConnectionFactory;
        }
Ejemplo n.º 10
0
        private void RecreateTables(IDbConnectionFactory factory)
        {
            factory.Run(x =>
            {
                using (var transaction = x.BeginTransaction())
                {
                    try
                    {
                        //core tables
                        x.DropAndCreateTables(typeof(VCALENDAR), typeof(VEVENT), typeof(VTODO), typeof(VFREEBUSY), typeof(FREEBUSY), typeof(VJOURNAL), typeof(VTIMEZONE), typeof(STANDARD), typeof(DAYLIGHT), typeof(AUDIO_ALARM), typeof(DISPLAY_ALARM), typeof(EMAIL_ALARM), typeof(ORGANIZER), typeof(ATTENDEE), typeof(COMMENT), typeof(RELATEDTO), typeof(ATTACH_BINARY), typeof(ATTACH_URI), typeof(CONTACT), typeof(RDATE), typeof(EXDATE), typeof(RECUR), typeof(RECURRENCE_ID), typeof(REQUEST_STATUS), typeof(RESOURCES), typeof(TZNAME));

                        //3NF relational tables
                        x.DropAndCreateTables(typeof(REL_CALENDARS_EVENTS), typeof(REL_CALENDARS_TODOS), typeof(REL_CALENDARS_FREEBUSIES), typeof(REL_CALENDARS_JOURNALS), typeof(REL_CALENDARS_TIMEZONES),  typeof(REL_EVENTS_ATTACHBINS), typeof(REL_EVENTS_ATTACHURIS), typeof(REL_EVENTS_ATTENDEES), typeof(REL_EVENTS_AUDIO_ALARMS), typeof(REL_EVENTS_COMMENTS), typeof(REL_EVENTS_CONTACTS), typeof(REL_EVENTS_DISPLAY_ALARMS), typeof(REL_EVENTS_EMAIL_ALARMS), typeof(REL_EVENTS_EXDATES), typeof(REL_EVENTS_RDATES), typeof(REL_EVENTS_RELATEDTOS), typeof(REL_EVENTS_REQSTATS), typeof(REL_EVENTS_RESOURCES), typeof(REL_TODOS_ATTACHBINS), typeof(REL_TODOS_ATTACHURIS), typeof(REL_TODOS_ATTENDEES), typeof(REL_TODOS_AUDIO_ALARMS), typeof(REL_TODOS_COMMENTS), typeof(REL_TODOS_CONTACTS), typeof(REL_TODOS_DISPLAY_ALARMS), typeof(REL_TODOS_EMAIL_ALARMS), typeof(REL_TODOS_EXDATES), typeof(REL_TODOS_RDATES), typeof(REL_TODOS_RELATEDTOS), typeof(REL_TODOS_REQSTATS), typeof(REL_TODOS_RESOURCES), typeof(REL_FREEBUSIES_ATTACHBINS), typeof(REL_FREEBUSIES_ATTACHURIS), typeof(REL_FREEBUSIES_ATTENDEES), typeof(REL_FREEBUSIES_COMMENTS), typeof(REL_FREEBUSIES_REQSTATS), typeof(REL_FREEBUSIES_VFREEBUSIES), typeof(REL_JOURNALS_ATTACHBINS), typeof(REL_JOURNALS_ATTACHURIS), typeof(REL_JOURNALS_ATTENDEES), typeof(REL_JOURNALS_COMMENTS), typeof(REL_JOURNALS_CONTACTS), typeof(REL_JOURNALS_EXDATES), typeof(REL_JOURNALS_RDATES), typeof(REL_JOURNALS_RELATEDTOS), typeof(REL_JOURNALS_REQSTATS), typeof(REL_JOURNALS_RESOURCES), typeof(REL_EALARMS_ATTACHBINS), typeof(REL_EALARMS_ATTACHURIS), typeof(REL_EALARMS_ATTENDEES), typeof(REL_TIMEZONES_STANDARDS), typeof(REL_TIMEZONES_DAYLIGHT), typeof(REL_STANDARDS_COMMENTS), typeof(REL_STANDARDS_RDATES), typeof(REL_STANDARDS_TZNAMES), typeof(REL_DAYLIGHTS_COMMENTS), typeof(REL_DAYLIGHTS_RDATES), typeof(REL_DAYLIGHTS_TZNAMES));

                        transaction.Commit();
                    }
                    catch (ApplicationException)
                    {
                        transaction.Rollback();
                        throw;
                    }
                    catch (InvalidOperationException)
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            });
        }
 public OrmLiteBenchmark()
 {
     // Don't like having to hardcode the connection string into the app, should be able to
     // specify a named connection in app.config :/
     this.connectionFactory = new OrmLiteConnectionFactory(
         @"Data Source=C:\Source\GitHub\MicroORM.Benchmark\SQLiteTest.db3;Version=3;",
         SqliteDialect.Provider);
 }
        public DbContextTestsForSqlCe()
        {
            _previousConnectionFactory = DefaultConnectionFactoryResolver.Instance.ConnectionFactory;

            var sqlCeConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0",
                                                                    AppDomain.CurrentDomain.BaseDirectory, "");
            DefaultConnectionFactoryResolver.Instance.ConnectionFactory = sqlCeConnectionFactory;
        }
        public SimpleScenariosForLocalDb()
        {
            _previousConnectionFactory = DefaultConnectionFactoryResolver.Instance.ConnectionFactory;
            _previousDataDirectory = AppDomain.CurrentDomain.GetData("DataDirectory");

            AppDomain.CurrentDomain.SetData("DataDirectory", Path.GetTempPath());
            DefaultConnectionFactoryResolver.Instance.ConnectionFactory = new LocalDbConnectionFactory("v11.0");
        }
Ejemplo n.º 14
0
 public MigrationStep(IMigration migration, IScheduledMigrationMetadata metadata, ConnectionInfo connectionInfo, IProvider provider, IProviderMetadata providerMetadata, IDbConnectionFactory connectionFactory, ISqlDispatcher sqlDispatcher)
     : base(migration, provider, providerMetadata)
 {
     _metadata = metadata;
     _connectionInfo = connectionInfo;
     _connectionFactory = connectionFactory;
     _sqlDispatcher = sqlDispatcher;
 }
Ejemplo n.º 15
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="AudioAlarmOrmRepository" /> class.
        /// </summary>
        public AudioAlarmOrmRepository(IKeyGenerator<Guid> keygenerator, IDbConnectionFactory factory)
        {
            if (keygenerator == null) throw new ArgumentNullException(nameof(keygenerator));
            if (factory == null) throw new ArgumentNullException(nameof(factory));

            this.keygenerator = keygenerator;
            DbConnectionFactory = factory;
        }
		public static List<UserAuth> GetByUserName(this UserAuth request, 
		                                           IDbConnectionFactory DbFactory){
			var un= request.UserName;
			
			return DbFactory.Exec(dbCmd=> dbCmd.Select<UserAuth>
			                      (q=> q.UserName.Contains(un))).
			                      OrderBy( q=> q.UserName).ToList();
			
		}
		public static List<City> GetByCountryId(this City request, 
		                                           IDbConnectionFactory DbFactory){
			
			
			return DbFactory.Exec(dbCmd=> dbCmd.Select<City>
			                      (q=> q.CountryId ==request.CountryId )).
			                      OrderBy( q=> q.Name).ToList();
			
		}
		public static List<Person> GetByJobCityId(this Person request, 
		                                           IDbConnectionFactory DbFactory){
			
			
			return DbFactory.Exec(dbCmd=> dbCmd.Select<Person>
			                      (q=> q.JobCityId ==request.JobCityId)).
			                      OrderBy( q=> q.Name).ToList();
			
		}
Ejemplo n.º 19
0
 /// <summary>Parameterized constructor.
 /// </summary>
 public SqlServerEventStore(string connectionString, string eventTable, string commitIndexName, string versionIndexName)
 {
     _connectionString = connectionString;
     _eventTable = eventTable;
     _commitIndexName = commitIndexName;
     _versionIndexName = versionIndexName;
     _binarySerializer = ObjectContainer.Resolve<IBinarySerializer>();
     _connectionFactory = ObjectContainer.Resolve<IDbConnectionFactory>();
 }
Ejemplo n.º 20
0
 public static void Seed(IDbConnectionFactory dbFactory)
 {
     dbFactory.Run(db =>
     {
         CategorySeeder.Seed(db);
         PrioritySeeder.Seed(db);
         StatusSeeder.Seed(db);
     });
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProductLoader"/> class.
        /// </summary>
        /// <param name="targetFactory">Target connection factory.</param>
        public ProductLoader(IDbConnectionFactory targetFactory)
        {
            if (targetFactory == null)
            {
                throw new ArgumentNullException("targetFactory");
            }

            this.targetFactory = targetFactory;
        }
Ejemplo n.º 22
0
        public DatabaseBackend(IDbConnectionFactory conn_factory, IDbStorageFactory storage_factory, IAuthenticator auth,
		                        OAuthHandler handler)
            : base(conn_factory)
        {
            oauthHandler = handler;
            storageFactory = storage_factory;

            // TODO move this into (Encrypted)DbStorageFactory implementation
            CreateSchema (conn_factory);
        }
Ejemplo n.º 23
0
        public CalendarDapperRepository(IDbConnectionFactory factory, IKeyGenerator<Guid> keygenerator, IEventRepository eventrepository)
        {
            dbconnection.ThrowIfNull("factory");
            keygenerator.ThrowIfNull("keygenerator");
            eventrepository.ThrowIfNull("eventrepository");

            this.factory = factory;
            this.keygenerator = keygenerator;
            this.eventrepository = eventrepository;
        }
        public void on_set_up()
        {
            LogManager.LogFactory = new Log4NetFactory(true);
            _dbConnectionFactory = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider);
            DataBaseHelper.Settup_Test_Database(_dbConnectionFactory);

            _appHost = new Auth_202AppHost(_dbConnectionFactory);
            _appHost.Init();
            _appHost.Start(ListeningOn);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CalendarOrmRepository"/> class.
        /// </summary>
        /// <param name="keygenerator">The generator for generating keys</param>
        /// <param name="eventrepository">The repository for calendar events</param>
        /// <param name="factory">The database connection factory</param>
        public CalendarOrmRepository(IKeyGenerator<Guid> keygenerator, IEventRepository eventrepository, IDbConnectionFactory factory)
        {
            if (keygenerator == null) throw new ArgumentNullException(nameof(keygenerator));
            if (eventrepository == null) throw new ArgumentNullException(nameof(eventrepository));
            if (factory == null) throw new ArgumentNullException(nameof(factory));

            this.keygenerator = keygenerator;
            this.eventrepository = eventrepository;
            this.factory = factory;
        }
Ejemplo n.º 26
0
 public DbMessageStream(IDbConnectionFactory db)
 {
     this.db = db;
      BatchSize = 1000;
      messageId = new Int64Field {Name = "MessageId"};
      format = new StringField {Name = "Format"};
      source = new StringField {Name = "Source"};
      createdOn = new DateTimeOffsetField {Name = "CreatedOn"};
      sequence = new Int64Field {Name = "Sequence"};
      content = new StringField {Name = "Content"};
 }
        public OrmLiteChangesetQuery(IDbConnectionFactory dbConnectionFactory)
        {
            if (dbConnectionFactory == null)
              {
            throw new ArgumentNullException("dbConnectionFactory");
              }

              _dbConnectionFactory = dbConnectionFactory;

              _predicateComposer = new ChangesetPredicateComposer();
        }
Ejemplo n.º 28
0
        public DbEncryptedStorage(IDbConnectionFactory factory, DBUser user, string encryption_master_key,
		                           bool use_history = true)
            : base(factory, user.Username, use_history)
        {
            this.User = user;

            if (encryption_master_key == null)
                throw new ArgumentNullException ("encryption_master_key");

            encryptionMasterKey = encryption_master_key;
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Create GuruxAMI Service.
 /// </summary>
 /// <param name="prefix">table prefix.</param>
 public GXDBService(string urlBase, IDbConnectionFactory connectionFactory, string prefix)
 {
     if (this.appHost != null)
     {
         this.appHost.Stop();
     }
     this.Url = urlBase;
     this.appHost = new GXAppHost(connectionFactory, prefix);
     this.appHost.Init();
     this.appHost.Start(this.Url);
 }
Ejemplo n.º 30
0
        public override void OnBeforeEachTest()
        {
            base.OnBeforeEachTest();

            this.Container.Register<IDbConnectionFactory>(c =>
                new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider));

            this.DbFactory = this.Container.Resolve<IDbConnectionFactory>();

            using (var db = DbFactory.Open())
                db.DropAndCreateTable<Movie>();
        }
Ejemplo n.º 31
0
 public ConcurrentDbConnectionFactory(IDbConnectionFactory dbConnectionFactory)
 {
     this._dbConnectionFactory = dbConnectionFactory;
 }
 public OrganisationsDatastore(IDbConnectionFactory dbConnectionFactory, ILogger <OrganisationsDatastore> logger, ISyncPolicyFactory policy) :
     base(dbConnectionFactory, logger, policy)
 {
 }
 public ServiceConfigurationSettingConnectionFactory(IDbConnectionFactory parent)
 {
     this.parent = parent;
 }
Ejemplo n.º 34
0
 public OrmLiteAuthRepositoryMultitenancy(IDbConnectionFactory dbFactory, params string[] connectionStrings)
     : base(dbFactory, connectionStrings)
 {
 }
Ejemplo n.º 35
0
 public GetNodesDbQuery(IDbConnectionFactory connectionFactory)
 {
     this.connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
 }
Ejemplo n.º 36
0
 public HenDepreciationServiceTests()
 {
     factory = DatabaseTestInitializer.GetConnectionFactory();
     service = new HenDepreciationService(factory);
 }
Ejemplo n.º 37
0
 public OrmLiteAuthRepository(IDbConnectionFactory dbFactory) : base(dbFactory)
 {
 }
 public GetPatientDtoByKeyRequestHandler(IPatientRepository patientRepository, ISystemAccountRepository systemAccountRepository, IDbConnectionFactory dbConnectionFactory)
 {
     _patientRepository       = patientRepository;
     _systemAccountRepository = systemAccountRepository;
     _dbConnectionFactory     = dbConnectionFactory;
 }
Ejemplo n.º 39
0
 public UserRepository(IDbConnectionFactory dbConnection)
 {
     _dbConnection = dbConnection;
 }
Ejemplo n.º 40
0
 public DatabaseProvider(IDbConnectionFactory dbConnectionFactory)
 {
     this._dbConnectionFactory = dbConnectionFactory;
 }
Ejemplo n.º 41
0
 public TodoGrain(ILogger <TodoGrain> logger, IDbConnectionFactory dbConnectionFactory)
 {
     this.logger = logger;
     this.dbConnectionFactory = dbConnectionFactory;
 }
Ejemplo n.º 42
0
 public SecurityRepository(IDbConnectionFactory connectionFactory)
 {
     this.connectionFactory = connectionFactory;
 }
Ejemplo n.º 43
0
 public OrmLiteAuthRepository(IDbConnectionFactory dbFactory, IHashProvider passwordHasher) : base(dbFactory, passwordHasher)
 {
 }
 /// <summary>
 /// Constructs a new <see cref="SqlServerMessageQueue{T}"/>.
 /// </summary>
 /// <param name="dbConnectionFactory">A factory class that generates instances of type <see cref="IDbConnection"/>.</param>
 /// <param name="queueNameResolver">Resolves the queue name.</param>
 /// <param name="workerJsonOptions">These are the options regarding json Serialization. They are used internally for persisting payloads.</param>
 public SqlServerMessageQueue(IDbConnectionFactory dbConnectionFactory, IQueueNameResolver <T> queueNameResolver, WorkerJsonOptions workerJsonOptions)
 {
     _dbConnectionFactory   = dbConnectionFactory ?? throw new ArgumentNullException(nameof(dbConnectionFactory));
     _queueNameResolver     = queueNameResolver ?? throw new ArgumentNullException(nameof(queueNameResolver));
     _jsonSerializerOptions = workerJsonOptions?.JsonSerializerOptions ?? throw new ArgumentNullException(nameof(workerJsonOptions));
 }
Ejemplo n.º 45
0
 public PatientUpdater(IDbConnectionFactory connectionFactory)
 {
     _connectionFactory = connectionFactory;
 }
Ejemplo n.º 46
0
 public DevicesController(IDbConnectionFactory connectionFactory)
 {
     _connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
 }
Ejemplo n.º 47
0
 public PersonRepository(IUnitOfWork unitOfWork, IDbConnectionFactory dbConnectionFactory, IMapper mapper)
 {
     _dbConnectionFactory = dbConnectionFactory;
     _mapper    = mapper;
     UnitOfWork = unitOfWork;
 }
Ejemplo n.º 48
0
 public OrmLiteOperatorAgentRepository(IDbConnectionFactory dbFactory, string namedConnnection = null)
     : base(dbFactory, namedConnnection)
 {
 }
Ejemplo n.º 49
0
 public DapperRepository(IDbConnectionFactory dbConnectionFactory)
 {
     this.dbConnectionFactory = dbConnectionFactory;
 }
Ejemplo n.º 50
0
 public OrmLiteOperatorAgentRepository(IDbConnectionFactory dbFactory) : base(dbFactory)
 {
 }
Ejemplo n.º 51
0
 public OrmLiteAuthRepository(IDbConnectionFactory dbFactory, string namedConnection = null)
     : base(dbFactory, namedConnection)
 {
 }
Ejemplo n.º 52
0
 public ContactDatastore(IDbConnectionFactory dbConnectionFactory, ILogger <ContactDatastore> logger, ISyncPolicyFactory policy) :
     base(dbConnectionFactory, logger, policy)
 {
 }
Ejemplo n.º 53
0
 public ProcessedEpisodesRepository(IDbConnectionFactory dbFactory, Compiler sqlCompiler)
     : base("ProcessedEpisodes", dbFactory, sqlCompiler)
 {
 }
 public SqlServerRestore(IDbConnectionFactory dbConnection)
 {
     _dbConnection = dbConnection;
 }
Ejemplo n.º 55
0
            public IDbConnection Create(string connectionString, IDbConnectionFactory adapter, bool useCache = true)
            {
                if (string.IsNullOrEmpty(connectionString))
                {
                    throw new ArgumentException("数据库链接无效!", nameof(connectionString));
                }

                List <IDispatchConnection> connections = connectionCache.GetOrAdd(connectionString, _ => new List <IDispatchConnection>());

                if (useCache && connections.Count > 0)
                {
                    lock (connections)
                    {
                        foreach (var item in connections)
                        {
                            if (item.IsAlive && !item.IsActive)
                            {
                                return(item.ReuseConnection());
                            }
                        }
                    }
                }

                IDispatchConnection connection;

                if (adapter.MaxPoolSize == connections.Count && connections.RemoveAll(x => x.IsReleased) == 0)
                {
                    lock (connections)
                    {
                        connection = connections //? 线程已关闭的。
                                     .FirstOrDefault(x => !x.IsThreadActive) ?? connections
                                     .Where(x => !x.IsActive)
                                     .OrderBy(x => x.ActiveTime) //? 移除最长时间不活跃的链接。
                                     .FirstOrDefault() ?? throw new DException($"链接数超限(最大连接数:{adapter.MaxPoolSize})!");

                        return(connection.ReuseConnection());
                    }
                }

                var conn = adapter.Create(connectionString);

                if (conn is System.Data.Common.DbConnection dbConnection)
                {
                    connection = new DispatchConnection(dbConnection, adapter.ConnectionHeartbeat, useCache);
                }
                else
                {
                    connection = new DbConnection(conn, adapter.ConnectionHeartbeat, useCache);
                }

                lock (connections)
                {
                    connections.Add(connection);
                }

                if (!_clearTimerRun)
                {
                    _clearTimer.Start();
                    _clearTimerRun = true;
                }

                return(connection);
            }
Ejemplo n.º 56
0
 public UserRepository(IDbConnectionFactory connectionFactory, IDateTimeProvider dateTimeProvider)
 {
     _connectionFactory = connectionFactory;
     _dateTimeProvider  = dateTimeProvider;
 }
Ejemplo n.º 57
0
 public OrmLiteMultiTenantApplicationRegistryService(IDbConnectionFactory connectionFactory, ICacheClient cacheClient)
 {
     _connectionFactory = connectionFactory;
     _cacheClient       = cacheClient;
 }
Ejemplo n.º 58
0
 public EvaluationRepository(IDbConnectionFactory factory)
 {
     ThrowIf.ArgumentIsNull(factory);
     this.connectionFactory = factory;
 }
Ejemplo n.º 59
0
 /// <summary>Initializes a new instance of the <see cref="AssessmentInstanceRepository" /> class.</summary>
 /// <param name="unitOfWorkProvider">The unit of work provider.</param>
 /// <param name="connectionFactory">The connection factory.</param>
 public AssessmentInstanceRepository(IUnitOfWorkProvider unitOfWorkProvider, IDbConnectionFactory connectionFactory)
     : base(unitOfWorkProvider)
 {
     _connectionFactory = connectionFactory;
 }
Ejemplo n.º 60
0
 public SQLiteContext(IDbConnectionFactory dbConnectionFactory)
     : this(dbConnectionFactory, true)
 {
 }