public static ScheduledTaskLogEntity ExecuteSync(ITaskEntity task, ScheduledTaskEntity?scheduledTask, IUserEntity?user) { IUserEntity entityIUser = (user ?? (IUserEntity?)scheduledTask?.User.RetrieveAndRemember()) !; var isolation = entityIUser.TryIsolation(); if (isolation == null) { var ientity = task as IEntity; isolation = ientity?.TryIsolation(); } using (IsolationEntity.Override(isolation)) { ScheduledTaskLogEntity stl = new ScheduledTaskLogEntity { Task = task, ScheduledTask = scheduledTask, StartTime = TimeZoneManager.Now, MachineName = Environment.MachineName, ApplicationName = Schema.Current.ApplicationName, User = entityIUser.ToLite(), }; using (AuthLogic.Disable()) { using (Transaction tr = Transaction.ForceNew()) { stl.Save(); tr.Commit(); } } try { var ctx = new ScheduledTaskContext(stl); RunningTasks.TryAdd(stl, ctx); using (UserHolder.UserSession(entityIUser)) { using (Transaction tr = Transaction.ForceNew()) { stl.ProductEntity = ExecuteTask.Invoke(task, ctx); using (AuthLogic.Disable()) { stl.EndTime = TimeZoneManager.Now; stl.Remarks = ctx.StringBuilder.ToString(); stl.Save(); } tr.Commit(); } } } catch (Exception ex) { using (AuthLogic.Disable()) { if (Transaction.InTestTransaction) { throw; } var exLog = ex.LogException().ToLite(); using (Transaction tr = Transaction.ForceNew()) { stl.Exception = exLog; stl.EndTime = TimeZoneManager.Now; stl.Save(); tr.Commit(); } } throw; } finally { RunningTasks.TryRemove(stl, out var ctx); OnFinally?.Invoke(stl); } return(stl); } }
public ScheduledTaskContext(ScheduledTaskLogEntity log) { Log = log; }
public static IQueryable <SchedulerTaskExceptionLineEntity> ExceptionLines(this ScheduledTaskLogEntity e) => As.Expression(() => Database.Query <SchedulerTaskExceptionLineEntity>().Where(a => a.SchedulerTaskLog.Is(e)));
public static IQueryable <SchedulerTaskExceptionLineEntity> ExceptionLines(this ScheduledTaskLogEntity e) { return(ExceptionLinesExpression.Evaluate(e)); }