Exemple #1
0
        public void ListenNonQuery(NpgsqlCommand command)
        {
            try
            {
                if (command != null)
                {
                    if (ValidateCommand(command))
                    {
                        ThreadStart queryStart = delegate
                        {
                            try
                            {
                                using (NpgsqlConnection connection = new NpgsqlConnection(DbConnection.GetConnectionString()))
                                {
                                    command.Connection = connection;
                                    connection.Notice += Connection_Notice;
                                    connection.Open();
                                    command.ExecuteNonQuery();
                                }
                            }
                            catch (NpgsqlException ex)
                            {
                                EventHandler <DbNotificationArgs> listen = this.Listen;

                                if (listen != null)
                                {
                                    DbNotificationArgs args = new DbNotificationArgs
                                    {
                                        Message = ex.Message
                                    };

                                    listen(this, args);
                                }
                            }
                        };

                        queryStart += () => { Thread.Sleep(15000); };

                        Thread query = new Thread(queryStart)
                        {
                            IsBackground = true
                        };
                        query.Start();
                    }
                }
            }
            catch (NpgsqlException ex)
            {
                if (ex.Code.StartsWith("P"))
                {
                    string errorMessage = GetDBErrorResource(ex.Code);
                    throw new MixERPException(errorMessage, ex);
                }

                throw;
            }
        }
Exemple #2
0
        private void Connection_Notice(object sender, NpgsqlNoticeEventArgs e)
        {
            EventHandler <DbNotificationArgs> listen = this.Listen;

            if (listen != null)
            {
                DbNotificationArgs args = new DbNotificationArgs
                {
                    Notice  = e.Notice,
                    Message = e.Notice.Message
                };

                listen(this, args);
            }
        }
Exemple #3
0
        private void Connection_Notice(object sender, NpgsqlNoticeEventArgs e)
        {
            EventHandler<DbNotificationArgs> listen = this.Listen;

            if (listen != null)
            {
                DbNotificationArgs args = new DbNotificationArgs
                {
                    Notice = e.Notice,
                    Message = e.Notice.Message
                };

                listen(this, args);
            }
        }
Exemple #4
0
        public void ListenNonQuery(string catalog, NpgsqlCommand command)
        {
            try
            {
                if (command != null)
                {
                    if (ValidateCommand(command))
                    {
                        ThreadStart queryStart = delegate
                        {
                            try
                            {
                                using (
                                    NpgsqlConnection connection =
                                        new NpgsqlConnection(DbConnection.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);
                                }

                                EventHandler<DbNotificationArgs> listen = this.Listen;

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

                                    listen(this, args);
                                }
                            }
                        };

                        queryStart += () => { Thread.Sleep(15000); };

                        Thread query = new Thread(queryStart) {IsBackground = true};
                        query.Start();
                    }
                }
            }
            catch (NpgsqlException ex)
            {
                if (ex.Code.StartsWith("P"))
                {
                    string errorMessage = GetDBErrorResource(ex);
                    throw new MixERPException(errorMessage, ex);
                }

                throw;
            }
        }
Exemple #5
0
        public Task ListenNonQuery(string catalog, NpgsqlCommand command)
        {
            try
            {
                if (command != null)
                {
                    if (ValidateCommand(command))
                    {
                        Task task = new Task(delegate
                        {
                            try
                            {
                                using (
                                    NpgsqlConnection connection =
                                        new NpgsqlConnection(DbConnection.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);
                                }

                                EventHandler<DbNotificationArgs> listen = this.Listen;

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

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

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

                throw;
            }

            return null;
        }
Exemple #6
0
        public Task ListenNonQuery(string catalog, NpgsqlCommand command)
        {
            try
            {
                if (command != null)
                {
                    if (ValidateCommand(command))
                    {
                        Task task = new Task(delegate
                        {
                            try
                            {
                                using (
                                    NpgsqlConnection connection =
                                        new NpgsqlConnection(DbConnection.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);
                                }

                                EventHandler <DbNotificationArgs> listen = this.Listen;

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

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

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

                throw;
            }

            return(null);
        }
        private void Listen(object sender, DbNotificationArgs e)
        {
            var notificationReceived = this.NotificationReceived;

            if (notificationReceived != null)
            {
                if (e.Notice == null && !string.IsNullOrWhiteSpace(e.Message))
                {
                    MixERPPGEventArgs args = new MixERPPGEventArgs(e.Message, "error", 0);
                    notificationReceived(this, args);
                    return;
                }

                if (e.Notice != null && e.Notice.Severity.ToUpperInvariant().Equals("INFO"))
                {
                    MixERPPGEventArgs args = new MixERPPGEventArgs(e.Notice.Message, e.Notice.Detail, 0);

                    notificationReceived(this, args);
                }
            }
        }