Ejemplo n.º 1
0
        public Task ListenNonQueryAsync(string tenant, SqlCommand command)
        {
            if (command == null)
            {
                return(null);
            }
            string connectionString = FrapidDbServer.GetConnectionString(tenant);

            var task = new Task(delegate
            {
                try
                {
                    using (var connection = new SqlConnection(connectionString))
                    {
                        command.Connection = connection;

                        connection.InfoMessage += this.Connection_Notice;

                        connection.Open();

                        command.ExecuteNonQuery();
                    }
                }
                catch (SqlException ex)
                {
                    var e = new EodEventArgs(ex.Message, "error");
                    var notificationReceived = this.NotificationReceived;
                    notificationReceived?.Invoke(this, e);
                }
            });

            return(task);
        }
Ejemplo n.º 2
0
        public void Perform(string tenant, long loginId)
        {
            Task eodTask;

            string sql = @"
                        DECLARE @UserId integer     = account.get_user_id_by_login_id(@LoginId);
                        DECLARE @OfficeId integer   = account.get_office_id_by_login_id(@LoginId);
                        DECLARE @ValueDate date     = finance.get_value_date(@OfficeId);

                        EXECUTE finance.perform_eod_operation @UserId, @LoginId, @OfficeId, @ValueDate;";

            using (var command = new SqlCommand(sql))
            {
                command.Parameters.AddWithNullableValue("@LoginId", loginId);

                command.CommandTimeout = 3600;
                eodTask = this.ListenNonQueryAsync(tenant, command);
            }
            try
            {
                eodTask.Start();
            }
            catch (Exception ex)
            {
                var e = new EodEventArgs(ex.Message, "error");
                var notificationReceived = this.NotificationReceived;
                notificationReceived?.Invoke(this, e);
            }
        }
Ejemplo n.º 3
0
        public void Perform(string tenant, long loginId)
        {
            string sql = "VACUUM ANALYZE VERBOSE;";
            Task   vacuumAnalyzeTask;
            Task   eodTask;

            using (var command = new NpgsqlCommand(sql))
            {
                command.CommandTimeout = 3600;
                vacuumAnalyzeTask      = this.ListenNonQueryAsync(tenant, command);
            }


            sql = "SELECT * FROM finance.perform_eod_operation(@LoginId::bigint);";

            using (var command = new NpgsqlCommand(sql))
            {
                command.Parameters.AddWithValue("@LoginId", loginId);
                command.CommandTimeout = 3600;
                eodTask = this.ListenNonQueryAsync(tenant, command);
            }
            try
            {
                vacuumAnalyzeTask.Start();

                vacuumAnalyzeTask.ContinueWith(delegate { eodTask.Start(); });
            }
            catch (Exception ex)
            {
                var e = new EodEventArgs(ex.Message, "error");
                var notificationReceived = this.NotificationReceived;
                notificationReceived?.Invoke(this, e);
            }
        }
Ejemplo n.º 4
0
        private void Connection_Notice(object sender, NpgsqlNoticeEventArgs e)
        {
            var notificationReceived = this.NotificationReceived;

            if (notificationReceived != null)
            {
                if (e.Notice != null)
                {
                    var args = new EodEventArgs(e.Notice.Message, e.Notice.Detail);

                    notificationReceived(this, args);
                }
            }
        }
Ejemplo n.º 5
0
        private void Connection_Notice(object sender, SqlInfoMessageEventArgs e)
        {
            var notificationReceived = this.NotificationReceived;

            if (notificationReceived == null)
            {
                return;
            }

            if (!string.IsNullOrWhiteSpace(e.Message))
            {
                var args = new EodEventArgs(e.Message, e.Source);
                notificationReceived(this, args);
            }

            foreach (SqlError error in e.Errors)
            {
                var args = new EodEventArgs(error.Message, error.Source);
                notificationReceived(this, args);
            }
        }
Ejemplo n.º 6
0
        public void Perform(string tenant, long loginId)
        {
            try
            {
                string sql = "VACUUM ANALYZE VERBOSE; SELECT * FROM finance.perform_eod_operation(@LoginId::bigint);";

                using (var command = new NpgsqlCommand(sql))
                {
                    command.Parameters.AddWithNullableValue("@LoginId", loginId);
                    command.CommandTimeout = 3600;

                    string connectionString = FrapidDbServer.GetConnectionString(tenant);

                    try
                    {
                        using (var connection = new NpgsqlConnection(connectionString))
                        {
                            command.Connection = connection;
                            connection.Notice += this.Connection_Notice;
                            connection.Open();
                            command.ExecuteNonQuery();
                        }
                    }
                    catch (NpgsqlException ex)
                    {
                        var e = new EodEventArgs(ex.Message, "error");
                        var notificationReceived = this.NotificationReceived;
                        notificationReceived?.Invoke(this, e);
                    }
                }
            }
            catch (Exception ex)
            {
                var e = new EodEventArgs(ex.Message, "error");
                var notificationReceived = this.NotificationReceived;
                notificationReceived?.Invoke(this, e);
            }
        }
Ejemplo n.º 7
0
 private void Performer_NotificationReceived(object sender, EodEventArgs e)
 {
     this.NotificationReceived?.Invoke(sender, e);
 }
Ejemplo n.º 8
0
 private void EOD_NotificationReceived(object sender, EodEventArgs e)
 {
     this.Clients.Caller.getNotification(e.Message, e.Condition);
 }