Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool Validate(object entity)
        {
            foreach (var _memberDescriptor in PropertyDescriptors)
            {
                var _isRequired = _memberDescriptor.ActionDescriptors.IsDeclared(x => x.IsRequired &&
                                                                                 x.PropertyDirection.HasFlag(DbQueryPropertyDirections.Input));

                if (_isRequired)
                {
                    var _value = _memberDescriptor.GetValue(entity);

                    if (!ValueValidator.Validate(_value))
                    {
                        if (null != Failed)
                        {
                            var _message   = string.Format("The '{0}' property cannot be null.", _memberDescriptor.Name);
                            var _exception = new DbQueryException(_message);

                            Failed(this, new DbQueryFailedEventArgs(_exception));
                        }
                    }

                    if (null != Validated)
                    {
                        Validated(this, EventArgs.Empty);
                    }
                }
            }

            return(true);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public IDbQueryResult Execute()
        {
            var _execution   = new DbQueryExecutingEventArgs();
            var _queryResult = (IDbQueryResult)null;

            if (null != Executing)
            {
                Executing(this, _execution);
            }

            if (!_execution.Cancel)
            {
                if (!_executionOnly)
                {
                    _connection.Open();
                }

                try
                {
                    _queryResult = ExecuteImpl(_command);

                    if (null != Executed)
                    {
                        Executed(this, new DbQueryExecutedEventArgs(_queryResult));
                    }
                }
                catch (SqlException ex)
                {
                    if (null != Failed)
                    {
                        var _exception = new DbQueryException(ex);
                        var _failure   = new DbQueryFailedEventArgs(_exception);

                        Failed(this, _failure);
                    }
                }
                catch (DbQueryException ex)
                {
                    if (null != Failed)
                    {
                        Failed(this, new DbQueryFailedEventArgs(ex));
                    }
                }

                if (!_executionOnly)
                {
                    _connection.Close();
                }
            }


            return(_queryResult);
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        public void Close()
        {
            try
            {
                Connection.Close();

                State = DbQueryOperatingSessionStates.Closed;
            }
            catch (SqlException ex)
            {
                var _exception = new DbQueryException(ex);
                var _arguments = new DbQueryFailedEventArgs(_exception);

                RaiseOperationFailedEvent(_arguments);
            }
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        public void Open()
        {
            try
            {
                if (!Connection.IsAlive)
                {
                    State = DbQueryOperatingSessionStates.ConnectionFaulted;

                    throw new DbQueryException("The connection is unavailable");
                }

                Connection.Open();

                State = DbQueryOperatingSessionStates.Opened;
            }
            catch (SqlException ex)
            {
                var _exception = new DbQueryException(ex);
                var _arguments = new DbQueryFailedEventArgs(_exception);

                RaiseOperationFailedEvent(_arguments);
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="exception"></param>
 public DbQueryFailedEventArgs(DbQueryException exception)
     : base()
 {
     _exception = exception;
 }