Ejemplo n.º 1
0
        public virtual DbConnection Connect(string name, string databaseName, SqlDPragmaModel pragmaOptions)
        {
            Name          = name ?? throw new ArgumentNullException(nameof(name));
            DatabaseName  = databaseName ?? throw new ArgumentNullException(nameof(databaseName));
            PragmaOptions = pragmaOptions ?? throw new ArgumentNullException(nameof(pragmaOptions));

            var builder = new SQLiteConnectionStringBuilder();

            builder.DataSource = databaseName;
            ConnectionString   = $"{builder};cache=shared";
            Connection         = CreateConnection();
            ApplyPragmaOptions(pragmaOptions);

            return(this);
        }
Ejemplo n.º 2
0
        private void ApplyPragmaOptions(SqlDPragmaModel pragmaOptions)
        {
            if (!string.IsNullOrEmpty(pragmaOptions.QueryOnly))
            {
                this.ExecuteCommand($"PRAGMA QUERY_ONLY={pragmaOptions.QueryOnly};");
            }

            if (!string.IsNullOrEmpty(pragmaOptions.PageSize))
            {
                this.ExecuteCommand($"PRAGMA PAGE_SIZE={pragmaOptions.PageSize};");
            }

            if (!string.IsNullOrEmpty(pragmaOptions.CountChanges))
            {
                this.ExecuteCommand($"PRAGMA COUNT_CHANGES={pragmaOptions.CountChanges};");
            }

            if (!string.IsNullOrEmpty(pragmaOptions.JournalMode))
            {
                this.ExecuteCommand($"PRAGMA JOURNAL_MODE={pragmaOptions.JournalMode};");
            }

            if (!string.IsNullOrEmpty(pragmaOptions.LockingMode))
            {
                this.ExecuteCommand($"PRAGMA LOCKING_MODE={pragmaOptions.LockingMode};");
            }

            if (!string.IsNullOrEmpty(pragmaOptions.Synchronous))
            {
                this.ExecuteCommand($"PRAGMA SYNCHRONOUS={pragmaOptions.Synchronous};");
            }

            if (!string.IsNullOrEmpty(pragmaOptions.TempStore))
            {
                this.ExecuteCommand($"PRAGMA TEMP_STORE={pragmaOptions.TempStore};");
            }
        }
Ejemplo n.º 3
0
 public DbConnection ConnectedTo(string name, string databaseName, SqlDPragmaModel pragma)
 {
     return(new DbConnection().Connect(name, databaseName, pragma));
 }
Ejemplo n.º 4
0
        public ConnectionListener Hosting(Assembly startAssembly, string name, string dbConnectionString, SqlDPragmaModel pragma, EndPoint localEndPoint, params EndPoint[] forwardEndPoints)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (dbConnectionString == null)
            {
                throw new ArgumentNullException(nameof(dbConnectionString));
            }

            var dbConnection       = new DbConnection().Connect(name, dbConnectionString, pragma);
            var connectionListener = ConnectionListenerFactory.Get(startAssembly, dbConnection, localEndPoint, forwardEndPoints);

            return(connectionListener);
        }