Exemplo n.º 1
0
 public void SetUp()
 {
     _dbWrapper      = new DbWrapper();
     _db             = new DbWrapper();
     _userManagement = new UserManager(_dbWrapper);
     _packageManager = new PackageManager(_dbWrapper);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Gets an available Database Connection from the pool of available connections
        /// </summary>
        /// <param name="useTransaction">indicates whether to begin a transaction for the returned database connection</param>
        /// <param name="database">the database that is available for usage</param>
        /// <returns>a connection that is unused at the moment</returns>
        public IResourceLock AcquireConnection(bool useTransaction, out IDbWrapper database)
        {
            while (!disposed)
            {
                try
                {
                    database = factory.LoadPlugin <IDbWrapper>("dummy", databaseConstructor, false);
                    ITransaction trans = null;
                    if (useTransaction)
                    {
                        trans = database.AcquireTransaction();
                    }

                    OnConnectionAcquiring(database);
                    return(new ResourceDisposer(database, trans));
                }
                catch (Exception ex)
                {
                    LogEnvironment.LogEvent(ex.Message, LogSeverity.Error, "DataAccess");
                }
            }

            database = null;
            return(null);
        }
        /// <summary>
        /// Creates an array of Database compatible parameters from the provided array of parameters
        /// </summary>
        /// <param name="inputParams">the parameters that were provided by the client</param>
        /// <param name="connection">the connection that can be used to re-create parameters that were lost</param>
        /// <returns>an array of parameters that is compatible to the underlaying database connection</returns>
        private IDbDataParameter[] BuildParameters(IDbDataParameter[] inputParams, IDbWrapper connection)
        {
            IDbDataParameter[] retVal = null;
            if (parameters != null)
            {
                retVal = new IDbDataParameter[inputParams.Length];
                for (int i = 0; i < inputParams.Length; i++)
                {
                    RemoteDataParameter param = inputParams[i] as RemoteDataParameter;
                    if (param == null)
                    {
                        throw new InvalidOperationException(
                                  "Need to provide Parameters that were created by the connection!");
                    }

                    lock (this.parameters)
                    {
                        IDbDataParameter dbParam;
                        if (this.parameters.ContainsKey(param.ObjectId))
                        {
                            dbParam = this.parameters[param.ObjectId];
                        }
                        else
                        {
                            dbParam = connection.GetParameter(param.ParameterName, param.Value);
                        }

                        param.ApplyTo(dbParam);
                        retVal[i] = dbParam;
                    }
                }
            }

            return(retVal);
        }
Exemplo n.º 4
0
 public SqlDataBackend(IDbWrapper databaseWrapper)
 {
     if (databaseWrapper == null)
     {
         throw new ArgumentNullException("databaseWrapper");
     }
     _database = databaseWrapper;
 }
Exemplo n.º 5
0
 public AdminControl()
 {
     this.DataContext = this;
     _dbWrapper       = new DbWrapper();
     _userManager     = new UserManager(_dbWrapper);
     _packageManager  = new PackageManager(_dbWrapper);
     this.InitializeComponent();
 }
Exemplo n.º 6
0
        public void SetupDatabase(IDbWrapper sqLiteLink)
        {
            sqLiteLink.ExecuteCommand(
                @"Create table Log (LogId Integer Primary Key, EventTime DateTime not null, Severity int not null, EventContext varchar(512), EventText text not null);
create index idx_EventTime on Log(EventTime);
create index idx_EventSeverity on Log(Severity);
create index idx_EventContext on Log(EventContext);");
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SqlDALContext"/> class
        /// </summary>
        /// <param name="dbWrapper"></param>
        public SqlDALContext(IDbWrapper dbWrapper)
        {
            if (dbWrapper == null)
            {
                throw new ArgumentNullException("dbWrapper");
            }

            _dbWrapper = dbWrapper;
        }
        private IDbWrapper OpenLog()
        {
            if (currentLogWrapper == null && currentLog != null)
            {
                currentLogWrapper = new SqLiteWrapper(currentLog);
            }

            return(currentLogWrapper);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets the Command including arguments
        /// </summary>
        /// <param name="wrapper">the wrapper used to connect to the database</param>
        /// <param name="arguments">the arguments used to bind all the search columns</param>
        /// <returns>a string representing this where clause</returns>
        public string GetCommand(IDbWrapper wrapper, out IDbDataParameter[] arguments)
        {
            StringBuilder           bld        = new StringBuilder();
            List <IDbDataParameter> parameters = new List <IDbDataParameter>();

            BuildCommand(wrapper, bld, parameters);
            arguments = parameters.ToArray();
            return(bld.ToString());
        }
Exemplo n.º 10
0
        private IEnumerable <LogDataModel> ReadLogData()
        {
            IDbWrapper logWrapper = OpenLog();

            if (logWrapper == null)
            {
                return(null);
            }

            return(logWrapper.GetResults <LogDataModel>($"Select * from Log {filterSettings} order by EventTime", filterSettings?.GetArguments(logWrapper) ?? new IDbDataParameter[] {}));
        }
Exemplo n.º 11
0
 public AgentPage()
 {
     this.InitializeComponent();
     try
     {
         _dbWrapper      = new DbWrapper();
         _packageManager = new PackageManager(_dbWrapper);
         LoadCategories();
     }
     catch (Exception e)
     {
     }
 }
Exemplo n.º 12
0
        /// <summary>
        /// Checks whether the log should be re-initialized before loggint events in it
        /// </summary>
        private void CheckDb()
        {
            DateTime now         = DateTime.Now;
            var      desiredName = initializer.GetPreciseDatabaseName(logName);
            bool     reOpen      = string.IsNullOrEmpty(currentName) || currentName != desiredName;

            if (reOpen)
            {
                if (database != null)
                {
                    database.Dispose();
                    database = null;
                }

                database    = new SqLiteWrapper(logName, 0, initializer);
                currentName = desiredName;
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// builds the Command of a Where including nested wheres
        /// </summary>
        /// <param name="wrapper"></param>
        /// <param name="bld"></param>
        /// <param name="argumentList"></param>
        private void BuildCommand(IDbWrapper wrapper, StringBuilder bld, List <IDbDataParameter> argumentList)
        {
            string           parameterName  = null;
            string           parameterName2 = null;
            IDbDataParameter param          = null;
            IDbDataParameter param2         = null;

            if (wrapper != null && argumentList != null)
            {
                int id = argumentList.Count + 1;
                parameterName  = string.Format("Argument{0}", id);
                parameterName2 = string.Format("Argument{0}", id + 1);
                param          = wrapper.GetParameter(parameterName, column.Value ?? DBNull.Value);
                parameterName  = param.ParameterName;
                argumentList.Add(param);
                if (column.ComparisonMode == ComparisonMode.Between)
                {
                    param2         = wrapper.GetParameter(parameterName2, column.Value2 ?? DBNull.Value);
                    parameterName2 = param2.ParameterName;
                    argumentList.Add(param2);
                }
            }

            bool brackets = subWheres.Count != 0;

            bld.AppendFormat("{0} {1}{2} {3} {4}", whereMode, brackets ? "(" : "", column.ColumnName, Operators[(int)column.ComparisonMode], parameterName ?? string.Format("\"{0}\"", column.Value));
            if (column.ComparisonMode == ComparisonMode.Between)
            {
                bld.AppendFormat(" and {0}", parameterName2 ?? string.Format("\"{0}\"", column.Value2));
            }

            bld.Append(" ");
            foreach (Where w in subWheres)
            {
                w.BuildCommand(wrapper, bld, argumentList);
            }

            if (brackets)
            {
                bld.Append(")");
            }
        }
Exemplo n.º 14
0
        public IDbDataParameter[] GetArguments(IDbWrapper database)
        {
            List <IDbDataParameter> retVal = new List <IDbDataParameter>
            {
                database.GetParameter("startDate", StartDate),
                database.GetParameter("endDate", EndDate)
            };

            if (!string.IsNullOrEmpty(CategoryFilter))
            {
                retVal.Add(database.GetParameter("evContext", $"%{CategoryFilter}%"));
            }

            if (!string.IsNullOrEmpty(EventFilter))
            {
                retVal.Add(database.GetParameter("evText", $"%{EventFilter}%"));
            }

            return(retVal.ToArray());
        }
Exemplo n.º 15
0
 public GroupManager(IDbWrapper dbWrapper)
 {
     _dbWrapper = dbWrapper;
 }
Exemplo n.º 16
0
 public UserManager(IDbWrapper dbWrapper)
 {
     _dbWrapper = dbWrapper;
 }
Exemplo n.º 17
0
        /// <summary>
        /// Gets an available Database Connection from the pool of available connections
        /// </summary>
        /// <param name="useTransaction">indicates whether to begin a transaction for the returned database connection</param>
        /// <param name="database">the database that is available for usage</param>
        /// <returns>a connection that is unused at the moment</returns>
        public IResourceLock AcquireConnection(bool useTransaction, out IDbWrapper database)
        {
            string threadId = Thread.CurrentThread.LocalOwner();

            DatabaseContainer db;
            IResourceLock     inner = null;

            while (!disposing)
            {
                try
                {
                    lock (connections)
                    {
                        var tmp =
                            (from t in connections
                             where !t.InUse && !t.Disposed && t.ThreadId == threadId
                             select t).FirstOrDefault
                                ();
                        if (tmp != null)
                        {
                            tmp.InUse     = true;
                            tmp.LastUsage = DateTime.Now;
                        }

                        db = tmp;
                    }

                    if (db == null)
                    {
                        db = new DatabaseContainer
                        {
                            Database = factory.LoadPlugin <IDbWrapper>(DataAccessResources.ParallelDummyInstanceName,
                                                                       databaseConstructor,
                                                                       false),
                            LastUsage = DateTime.Now,
                            InUse     = true,
                            ThreadId  = threadId
                        };
                        lock (connections)
                        {
                            connections.Add(db);
                        }
                    }

                    if (useTransaction)
                    {
                        inner = db.Database.AcquireTransaction();
                    }



                    database = db.Database;
                    lock (activeConnectionLock)
                    {
                        activeConnectionCount++;
                    }

                    OnConnectionAcquiring(database);
                    return(new DataBufferResourceLock(this, db, inner));
                }
                catch (Exception ex)
                {
                    LogEnvironment.LogEvent(ex.Message, LogSeverity.Error, "DataAccess");
                }
            }

            database = null;
            return(null);
        }
 public void Initialize()
 {
     _dbWrapperMock = _mockRepository.StrictMock<IDbWrapper>();
 }
 public PackageManager(IDbWrapper dbWrapper)
 {
     _dbWrapper   = dbWrapper;
     _userManager = new UserManager(_dbWrapper);
 }
Exemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of the RecordBuffer class
 /// </summary>
 /// <param name="database">the database in which the buffered data is originally located</param>
 /// <param name="dumperStrategy">the Strategy used to dump and load data from the filesystem</param>
 public RecordBuffer(IDbWrapper database, IDataDumper dumperStrategy)
     : this()
 {
     this.database     = database;
     this.dumpStrategy = dumperStrategy;
 }
Exemplo n.º 21
0
 public LightDBMapper(DataHolderTableMapping mapping, IDbWrapper db)
 {
     m_mapping = mapping;
     m_db      = db;
     db.Prepare(this);
 }
 public void TestInitialize()
 {
     _dbWrapper = _mockRepository.Stub<IDbWrapper>();
     _dataReader = _mockRepository.StrictMock<IDataReader>();
 }
Exemplo n.º 23
0
 /// <summary>
 /// Raises the OnConnectionAcquiring Event
 /// </summary>
 /// <param name="obj">the new created database wrapper</param>
 protected virtual void OnConnectionAcquiring(IDbWrapper obj)
 {
     ConnectionAcquiring?.Invoke(obj);
 }
Exemplo n.º 24
0
 public EmployeeRepository(IDbWrapper <Employee> employeeDbWrapper)
 {
     _employeeDbWrapper = employeeDbWrapper;
 }
Exemplo n.º 25
0
 public CompanyRepository(IDbWrapper <Company> companyDbWrapper)
 {
     _companyDbWrapper = companyDbWrapper;
 }
Exemplo n.º 26
0
 public void SetUp()
 {
     _dbWrapper = new DbWrapper();
 }
Exemplo n.º 27
0
 /// <summary>
 /// Gets a Database connection and opens a transaction is requested
 /// </summary>
 /// <param name="useTransaction">indicates whether to open a new transaction on the returned connection</param>
 /// <param name="database">the database connection</param>
 /// <returns>a ResourceLock - Object that enables the caller to free the Database implicitly after using</returns>
 public IResourceLock AcquireDatabase(bool useTransaction, out IDbWrapper database)
 {
     return(connector.AcquireConnection(useTransaction, out database));
 }