Ejemplo n.º 1
0
        public static void ExceptionLogic_DeleteLogs(DeleteLogParametersEmbedded parameters, StringBuilder sb, CancellationToken token)
        {
            void Remove(ProcessState processState, DateTime dateLimit, bool withExceptions)
            {
                var query = Database.Query <ProcessEntity>().Where(p => p.State == processState && p.CreationDate < dateLimit && (!withExceptions || p.Exception != null));

                query.SelectMany(a => a.ExceptionLines()).UnsafeDeleteChunksLog(parameters, sb, token);
                query.UnsafeDeleteChunksLog(parameters, sb, token);
            }

            var dateLimit = parameters.GetDateLimitDelete(typeof(ProcessEntity).ToTypeEntity());

            if (dateLimit != null)
            {
                Remove(ProcessState.Canceled, dateLimit.Value, false);
                Remove(ProcessState.Finished, dateLimit.Value, false);
                Remove(ProcessState.Error, dateLimit.Value, false);
            }

            dateLimit = parameters.GetDateLimitDeleteWithExceptions(typeof(ProcessEntity).ToTypeEntity());
            if (dateLimit == null)
            {
                return;
            }

            Remove(ProcessState.Canceled, dateLimit.Value, true);
            Remove(ProcessState.Finished, dateLimit.Value, true);
            Remove(ProcessState.Error, dateLimit.Value, true);
        }
Ejemplo n.º 2
0
        public static void ExceptionLogic_DeleteLogs(DeleteLogParametersEmbedded parameters, StringBuilder sb, CancellationToken token)
        {
            var dateLimit = parameters.GetDateLimitDelete(typeof(SessionLogEntity).ToTypeEntity());

            if (dateLimit != null)
            {
                Database.Query <SessionLogEntity>().Where(a => a.SessionStart < dateLimit.Value).UnsafeDeleteChunksLog(parameters, sb, token);
            }
        }
Ejemplo n.º 3
0
        private static void ExceptionLogic_DeleteRestLogs(DeleteLogParametersEmbedded parameters, StringBuilder sb, CancellationToken token)
        {
            var dateLimit = parameters.GetDateLimitDelete(typeof(RestLogEntity).ToTypeEntity());

            if (dateLimit == null)
            {
                return;
            }

            Database.Query <RestLogEntity>().Where(a => a.StartDate < dateLimit.Value).UnsafeDeleteChunksLog(parameters, sb, token);
        }
Ejemplo n.º 4
0
        public static void DeleteLogsAndExceptions(DeleteLogParametersEmbedded parameters, StringBuilder sb, CancellationToken token)
        {
            using (Connector.CommandTimeoutScope(DeleteLogsTimeOut))
                using (var tr = Transaction.None())
                {
                    foreach (var action in DeleteLogs.GetInvocationListTyped())
                    {
                        token.ThrowIfCancellationRequested();

                        action(parameters, sb, token);
                    }

                    WriteRows(sb, "Updating ExceptionEntity.Referenced = false", () => Database.Query <ExceptionEntity>().UnsafeUpdate().Set(a => a.Referenced, a => false).Execute());

                    token.ThrowIfCancellationRequested();

                    var ex         = Schema.Current.Table <ExceptionEntity>();
                    var referenced = (FieldValue)ex.GetField(ReflectionTools.GetPropertyInfo((ExceptionEntity e) => e.Referenced));

                    var commands = (from t in Schema.Current.GetDatabaseTables()
                                    from c in t.Columns.Values
                                    where c.ReferenceTable == ex
                                    select(table: t, command: new SqlPreCommandSimple("UPDATE ex SET {1} = 1 FROM {0} ex JOIN {2} log ON ex.Id = log.{3}"
                                                                                      .FormatWith(ex.Name, referenced.Name, t.Name, c.Name)))).ToList();

                    foreach (var p in commands)
                    {
                        token.ThrowIfCancellationRequested();

                        WriteRows(sb, "Updating Exceptions.Referenced from " + p.table.Name.Name, () => p.command.ExecuteNonQuery());
                    }

                    token.ThrowIfCancellationRequested();

                    var dateLimit = parameters.GetDateLimitDelete(typeof(ExceptionEntity).ToTypeEntity());

                    if (dateLimit != null)
                    {
                        Database.Query <ExceptionEntity>()
                        .Where(a => !a.Referenced && a.CreationDate < dateLimit)
                        .UnsafeDeleteChunksLog(parameters, sb, token);
                    }

                    tr.Commit();
                }
        }
Ejemplo n.º 5
0
        public static void ExceptionLogic_DeleteLogs(DeleteLogParametersEmbedded parameters, StringBuilder sb, CancellationToken token)
        {
            var dateLimit = parameters.GetDateLimitDelete(typeof(EmailMessageEntity).ToTypeEntity());

            if (dateLimit != null)
            {
                Database.Query <EmailMessageEntity>().Where(o => o.CreationDate < dateLimit !.Value).UnsafeDeleteChunksLog(parameters, sb, token);
            }

            dateLimit = parameters.GetDateLimitDeleteWithExceptions(typeof(EmailMessageEntity).ToTypeEntity());
            if (dateLimit == null)
            {
                return;
            }

            Database.Query <EmailMessageEntity>().Where(o => o.CreationDate < dateLimit !.Value && o.Exception != null).UnsafeDeleteChunksLog(parameters, sb, token);
        }
Ejemplo n.º 6
0
        public static void ExceptionLogic_DeleteLogs(DeleteLogParametersEmbedded parameters, StringBuilder sb, CancellationToken token)
        {
            var dateLimit = parameters.GetDateLimitDelete(typeof(SystemEventLogEntity).ToTypeEntity());

            if (dateLimit != null)
            {
                Database.Query <SystemEventLogEntity>().Where(a => a.Date < dateLimit.Value).UnsafeDeleteChunksLog(parameters, sb, token);
            }

            dateLimit = parameters.GetDateLimitDeleteWithExceptions(typeof(SystemEventLogEntity).ToTypeEntity());
            if (dateLimit == null)
            {
                return;
            }

            Database.Query <SystemEventLogEntity>().Where(a => a.Date < dateLimit.Value && a.Exception != null)
            .UnsafeUpdate()
            .Set(a => a.Exception, a => null)
            .ExecuteChunksLog(parameters, sb, token);
        }
Ejemplo n.º 7
0
    public static void ExceptionLogic_DeleteLogs(DeleteLogParametersEmbedded parameters, StringBuilder sb, CancellationToken token)
    {
        void Remove(DateTime?dateLimit, bool withExceptions)
        {
            if (dateLimit == null)
            {
                return;
            }

            var query = Database.Query <SystemEventLogEntity>().Where(a => a.Date < dateLimit);

            if (withExceptions)
            {
                query = query.Where(a => a.Exception != null);
            }

            query.UnsafeDeleteChunksLog(parameters, sb, token);
        }

        Remove(parameters.GetDateLimitDelete(typeof(SystemEventLogEntity).ToTypeEntity()), withExceptions: false);
        Remove(parameters.GetDateLimitDeleteWithExceptions(typeof(SystemEventLogEntity).ToTypeEntity()), withExceptions: true);
    }
Ejemplo n.º 8
0
        public static void ExceptionLogic_DeleteLogs(DeleteLogParametersEmbedded parameters, StringBuilder sb, CancellationToken token)
        {
            Database.Query <SchedulerTaskExceptionLineEntity>().Where(a => a.SchedulerTaskLog == null).UnsafeDeleteChunksLog(parameters, sb, token);

            var dateLimit = parameters.GetDateLimitDelete(typeof(ScheduledTaskLogEntity).ToTypeEntity());

            if (dateLimit != null)
            {
                var query = Database.Query <ScheduledTaskLogEntity>().Where(a => a.StartTime < dateLimit.Value);
                query.SelectMany(a => a.ExceptionLines()).UnsafeDeleteChunksLog(parameters, sb, token);
                query.UnsafeDeleteChunksLog(parameters, sb, token);
            }

            dateLimit = parameters.GetDateLimitDeleteWithExceptions(typeof(ScheduledTaskLogEntity).ToTypeEntity());
            if (dateLimit == null)
            {
                return;
            }

            var queryWithExceptions = Database.Query <ScheduledTaskLogEntity>().Where(a => a.StartTime < dateLimit.Value && a.Exception != null);

            queryWithExceptions.SelectMany(a => a.ExceptionLines()).UnsafeDeleteChunksLog(parameters, sb, token);
            queryWithExceptions.UnsafeUpdate().Set(a => a.Exception, a => null).ExecuteChunksLog(parameters, sb, token);
        }
Ejemplo n.º 9
0
        public static void ExceptionLogic_DeleteLogs(DeleteLogParametersEmbedded parameters, StringBuilder sb, CancellationToken token)
        {
            void Remove(DateTime?dateLimit, bool withExceptions)
            {
                if (dateLimit == null)
                {
                    return;
                }

                var query = Database.Query <ScheduledTaskLogEntity>().Where(a => a.StartTime < dateLimit);

                if (withExceptions)
                {
                    query = query.Where(a => a.Exception != null);
                }

                query.SelectMany(a => a.ExceptionLines()).UnsafeDeleteChunksLog(parameters, sb, token);
                query.Where(a => !a.ExceptionLines().Any()).UnsafeDeleteChunksLog(parameters, sb, token);
            }

            Database.Query <SchedulerTaskExceptionLineEntity>().Where(a => a.SchedulerTaskLog == null).UnsafeDeleteChunksLog(parameters, sb, token);
            Remove(parameters.GetDateLimitDelete(typeof(ScheduledTaskLogEntity).ToTypeEntity()), withExceptions: false);
            Remove(parameters.GetDateLimitDeleteWithExceptions(typeof(ScheduledTaskLogEntity).ToTypeEntity()), withExceptions: true);
        }