示例#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);
        }
示例#2
0
        public static void ExceptionLogic_DeletePackages <T>(DeleteLogParametersEmbedded parameters, StringBuilder sb, CancellationToken token) where T : PackageEntity
        {
            var toDelete = Database.Query <T>().Where(pack => !Database.Query <ProcessEntity>().Any(pr => pr.Data == pack));

            toDelete.SelectMany(a => a.Lines()).UnsafeDeleteChunksLog(parameters, sb, token);
            toDelete.UnsafeDeleteChunksLog(parameters, sb, token);
        }
示例#3
0
        public static void DeleteLogsAndExceptions(DeleteLogParametersEmbedded parameters)
        {
            using (Connector.CommandTimeoutScope(DeleteLogsTimeOut))
            {
                foreach (var action in DeleteLogs.GetInvocationListTyped())
                {
                    action(parameters);
                }

                int exceptions = Database.Query <ExceptionEntity>().UnsafeUpdate().Set(a => a.Referenced, a => false).Execute();

                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 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 c in commands)
                {
                    c.ExecuteNonQuery();
                }

                int deletedExceptions = Database.Query <ExceptionEntity>()
                                        .Where(a => !a.Referenced && a.CreationDate < parameters.DateLimit)
                                        .UnsafeDeleteChunks(parameters.ChunkSize, parameters.MaxChunks);
            }
        }
示例#4
0
        public static void ExceptionLogic_DeleteLogs(DeleteLogParametersEmbedded parameters, StringBuilder sb, CancellationToken token)
        {
            var usedDatas = Database.Query <ProcessEntity>().Select(a => a.Data);

            Database.Query <PackageLineEntity>().Where(line => !usedDatas.Contains(line.Package.Entity)).UnsafeDeleteChunksLog(parameters, sb, token);
            Database.Query <PackageOperationEntity>().Where(po => !usedDatas.Contains(po)).UnsafeDeleteChunksLog(parameters, sb, token);
            Database.Query <PackageEntity>().Where(po => !usedDatas.Contains(po)).UnsafeDeleteChunksLog(parameters, sb, token);
        }
示例#5
0
        public static void ExceptionLogic_DeletePackages(DeleteLogParametersEmbedded parameters, StringBuilder sb, CancellationToken token)
        {
            Database.Query <SMSSendPackageEntity>().Where(pack => !Database.Query <ProcessEntity>().Any(pr => pr.Data == pack) && !pack.SMSMessages().Any())
            .UnsafeDeleteChunksLog(parameters, sb, token);

            Database.Query <SMSUpdatePackageEntity>().Where(pack => !Database.Query <ProcessEntity>().Any(pr => pr.Data == pack) && !pack.SMSMessages().Any())
            .UnsafeDeleteChunksLog(parameters, sb, token);
        }
示例#6
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);
            }
        }
示例#7
0
 public static void ExecuteChunksLog <T>(this IUpdateable <T> sources, DeleteLogParametersEmbedded parameters, StringBuilder sb, CancellationToken cancellationToken)
     where T : Entity
 {
     WriteRows(sb, "Updating " + typeof(T).Name, () => sources.ExecuteChunks(
                   parameters.ChunkSize,
                   parameters.MaxChunks,
                   pauseMilliseconds: parameters.PauseTime,
                   cancellationToken: cancellationToken));
 }
示例#8
0
 public static void DiffLogic_DeleteLogs(DeleteLogParametersEmbedded parameters, StringBuilder sb, CancellationToken token)
 {
     Database.Query <OperationLogEntity>().Where(o => o.Start < parameters.DateLimit && o.Exception != null).UnsafeDeleteChunksLog(parameters, sb, token);
     Database.Query <OperationLogEntity>().Where(o => o.Start < parameters.DateLimit && !o.Mixin <DiffLogMixin>().Cleaned).UnsafeUpdate()
     .Set(a => a.Mixin <DiffLogMixin>().InitialState, a => null)
     .Set(a => a.Mixin <DiffLogMixin>().FinalState, a => null)
     .Set(a => a.Mixin <DiffLogMixin>().Cleaned, a => true)
     .ExecuteChunks(parameters.ChunkSize, parameters.MaxChunks);
 }
示例#9
0
        public static void DiffLogic_CleanLogs(DeleteLogParametersEmbedded parameters, StringBuilder sb, CancellationToken token)
        {
            var dateLimit = parameters.GetDateLimitClean(typeof(OperationLogEntity).ToTypeEntity());

            Database.Query <OperationLogEntity>().Where(o => o.Start < dateLimit && o.Exception != null).UnsafeDeleteChunksLog(parameters, sb, token);
            Database.Query <OperationLogEntity>().Where(o => o.Start < dateLimit && !o.Mixin <DiffLogMixin>().Cleaned).UnsafeUpdate()
            .Set(a => a.Mixin <DiffLogMixin>().InitialState, a => null)
            .Set(a => a.Mixin <DiffLogMixin>().FinalState, a => null)
            .Set(a => a.Mixin <DiffLogMixin>().Cleaned, a => true)
            .ExecuteChunksLog(parameters, sb, token);
        }
示例#10
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);
        }
示例#11
0
        public static void ExceptionLogic_DeleteLogs(DeleteLogParametersEmbedded parameters, StringBuilder sb, CancellationToken token)
        {
            void Remove(ProcessState processState)
            {
                var query = Database.Query <ProcessEntity>().Where(p => p.State == processState && p.CreationDate < parameters.DateLimit);

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

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

            Remove(ProcessState.Canceled);
            Remove(ProcessState.Finished);
            Remove(ProcessState.Error);
        }
示例#12
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);
        }
示例#13
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();
                }
        }
示例#14
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);
        }
示例#15
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);
    }
示例#16
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);
        }
示例#17
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);
        }
示例#18
0
 public static void ExceptionLogic_DeleteLogs(DeleteLogParametersEmbedded parameters)
 {
     Database.Query <OperationLogEntity>().Where(o => o.Start < parameters.DateLimit).UnsafeDeleteChunks(parameters.ChunkSize, parameters.MaxChunks);
 }
示例#19
0
 public static void ExceptionLogic_DeleteLogs(DeleteLogParametersEmbedded parameters, StringBuilder sb, CancellationToken token)
 {
     Database.Query <OperationLogEntity>().Where(o => o.Start < parameters.DateLimit).UnsafeDeleteChunksLog(parameters, sb, token);
 }
示例#20
0
 private static void ExceptionLogic_DeleteRestLogs(DeleteLogParametersEmbedded parameters, StringBuilder sb, CancellationToken token)
 {
     Database.Query <RestLogEntity>().Where(a => a.StartDate < parameters.DateLimit).UnsafeDeleteChunksLog(parameters, sb, token);
 }
示例#21
0
 public static void ExceptionLogic_DeleteLogs(DeleteLogParametersEmbedded parameters, StringBuilder sb, CancellationToken token)
 {
     Database.Query <WorkflowEventTaskConditionResultEntity>()
     .Where(a => a.CreationDate < parameters.DateLimit)
     .UnsafeDeleteChunksLog(parameters, sb, token);
 }