Exemplo n.º 1
0
        public Task ListenNonQueryAsync(string catalog, NpgsqlCommand command)
        {
            try
            {
                if (command != null)
                {
                    if (ValidateCommand(command))
                    {
                        var task = new Task(delegate
                        {
                            try
                            {
                                using (var connection = new NpgsqlConnection(ConnectionString.GetConnectionString(catalog)))
                                {
                                    command.Connection = connection;
                                    connection.Notice += Connection_Notice;
                                    connection.Open();
                                    command.ExecuteNonQuery();
                                }
                            }
                            catch (NpgsqlException ex)
                            {
                                string errorMessage = ex.Message;

                                if (ex.Code.StartsWith("P"))
                                {
                                    errorMessage = GetDbErrorResource(ex);
                                }

                                var listen = this.Listen;

                                if (listen != null)
                                {
                                    var args = new DbNotificationArgs
                                    {
                                        Message = errorMessage
                                    };

                                    listen(this, args);
                                }
                            }
                        });

                        return(task);
                    }
                }
            }
            catch (NpgsqlException ex)
            {
                if (ex.Code.StartsWith("P"))
                {
                    string errorMessage = GetDbErrorResource(ex);
                    throw new DataAccessException(errorMessage, ex);
                }

                throw;
            }

            return(null);
        }
Exemplo n.º 2
0
        private void Connection_Notice(object sender, NpgsqlNoticeEventArgs e)
        {
            var listen = this.Listen;

            if (listen == null)
            {
                return;
            }

            var args = new DbNotificationArgs
            {
                Notice     = e.Notice,
                ColumnName = e.Notice.ColumnName
            };

            listen(this, args);
        }
Exemplo n.º 3
0
        private void Connection_Notice(object sender, NpgsqlNoticeEventArgs e)
        {
            var listen = this.Listen;

            if (listen == null) return;

            var args = new DbNotificationArgs
            {
                Notice = e.Notice,
                ColumnName = e.Notice.ColumnName
            };

            listen(this, args);
        }
Exemplo n.º 4
0
        public Task ListenNonQueryAsync(string catalog, NpgsqlCommand command)
        {
            try
            {
                if (command != null)
                {
                    if (ValidateCommand(command))
                    {
                        var task = new Task(delegate
                        {
                            try
                            {
                                using (var connection = new NpgsqlConnection(ConnectionString.GetConnectionString(catalog)))
                                {
                                    command.Connection = connection;
                                    connection.Notice += Connection_Notice;
                                    connection.Open();
                                    command.ExecuteNonQuery();
                                }
                            }
                            catch (NpgsqlException ex)
                            {
                                string errorMessage = ex.Message;

                                if (ex.Code.StartsWith("P"))
                                {
                                    errorMessage = GetDbErrorResource(ex);
                                }

                                var listen = this.Listen;

                                if (listen != null)
                                {
                                    var args = new DbNotificationArgs
                                    {
                                        Message = errorMessage
                                    };

                                    listen(this, args);
                                }
                            }
                        });

                        return task;
                    }
                }
            }
            catch (NpgsqlException ex)
            {
                if (ex.Code.StartsWith("P"))
                {
                    string errorMessage = GetDbErrorResource(ex);
                    throw new DataAccessException(errorMessage, ex);
                }

                throw;
            }

            return null;
        }