Esempio n. 1
0
 protected IdManager(IDatabase db, string entityName, ILogger <THasId> log)
 {
     this.db         = db;
     this.entityName = entityName;
     this.log        = log;
     database        = new WrappedDbConnection(db, typeof(THasId));
 }
Esempio n. 2
0
            /// <summary>
            /// Defines the method to be called when the command is invoked.
            /// </summary>
            /// <param name="parameter">The connection parameter.</param>
            public void Execute(object parameter)
            {
                DbConnectionParameter       connectionParameter = (DbConnectionParameter)parameter;
                IWrappedDbConnectionFactory connectionFactory   = DbConnectionFactoryProvider.GetFactory(connectionParameter.Provider);
                WrappedDbConnection         dbConnection        = null;
                bool succeeded = false;

                try {
                    dbConnection = connectionFactory.CreateConnection(connectionParameter);
                    succeeded    = true;
                }
                catch (WrappedDbException) {
                }
                finally {
                    if (dbConnection != null)
                    {
                        dbConnection.Dispose();
                    }
                }

                if (succeeded)
                {
                    MessageBox.Show("Connection succeeded", "Connection Test", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("Connection failed", "Connection Test", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExecutionProcessor"/> class.
        /// </summary>
        /// <param name="cmdArgs">The CMD args.</param>
        public ExecutionProcessor(CSqlOptions csqlOptions)
        {
            this.options = csqlOptions;
            DbConnectionParameter connectionParameter = csqlOptions.ConnectionParameter;

            this.connection              = DbConnectionFactoryProvider.CreateConnection(connectionParameter);
            this.connection.InfoMessage += new EventHandler <DbMessageEventArgs>(InfoMessageEventHandler);
        }
        //
        // Get methods
        //

        public T GetValue <T>(string query)
        {
            T res;

            using (var conn = new WrappedDbConnection(ConnectionFactory.GetDBConnecton(this._connectionString, this._dbAdapter)))
            {
                res = conn.ExecuteScalar <T>(query);
                conn.Close();
            }
            return(res);
        }
        public bool DeleteRange(IEnumerable <TEntity> entities)
        {
            bool res = false;

            using (var conn = new WrappedDbConnection(ConnectionFactory.GetDBConnecton(this._connectionString, this._dbAdapter)))
            {
                res = conn.Delete(entities);
                conn.Close();
            }
            return(res);
        }
        public long AddRange(IEnumerable <TEntity> entities)
        {
            long id = 0;

            using (var conn = new WrappedDbConnection(ConnectionFactory.GetDBConnecton(this._connectionString, this._dbAdapter)))
            {
                id = conn.Insert(entities);
                conn.Close();
            }
            return(id);
        }
        public long Add <T>(T entity) where T : class
        {
            long id = 0;

            using (var conn = new WrappedDbConnection(ConnectionFactory.GetDBConnecton(this._connectionString, this._dbAdapter)))
            {
                id = conn.Insert(entity);
                conn.Close();
            }
            return(id);
        }
        public bool Update <T>(T entity) where T : class
        {
            bool res;

            using (var conn = new WrappedDbConnection(ConnectionFactory.GetDBConnecton(this._connectionString, this._dbAdapter)))
            {
                res = conn.Update(entity);
                conn.Close();
            }
            return(res);
        }
        public List <T> GetAll <T>() where T : class
        {
            List <T> res = new List <T>();

            using (var conn = new WrappedDbConnection(ConnectionFactory.GetDBConnecton(this._connectionString, this._dbAdapter)))
            {
                res = conn.GetAll <T>().ToList();
                conn.Close();
            }
            return(res);
        }
Esempio n. 10
0
        public TEntity Get(long id)
        {
            TEntity res;

            using (var conn = new WrappedDbConnection(ConnectionFactory.GetDBConnecton(this._connectionString, this._dbAdapter)))
            {
                res = conn.Get <TEntity>(id);
                conn.Close();
            }
            return(res);
        }