Пример #1
0
        public static void DeleteLogsAndExceptions(DeleteLogParametersEntity 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);
            }
        }
Пример #2
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();
                }
        }