public void Execute() { var user = ExecutionMode.Global().Using(_ => CurrentProcess.User.RetrieveAndRemember()); using (UserHolder.UserSession(user)) { using (ProcessLogic.OnApplySession(CurrentProcess)) { if (UserEntity.Current == null) { UserEntity.Current = AuthLogic.SystemUser !; } try { Algorithm.Execute(this); CurrentProcess.ExecutionEnd = TimeZoneManager.Now; CurrentProcess.State = ProcessState.Finished; CurrentProcess.Progress = null; CurrentProcess.User.ClearEntity(); using (OperationLogic.AllowSave <ProcessEntity>()) CurrentProcess.Save(); } catch (OperationCanceledException e) { if (!e.CancellationToken.Equals(this.CancellationToken)) { throw; } CurrentProcess.SuspendDate = TimeZoneManager.Now; CurrentProcess.State = ProcessState.Suspended; using (OperationLogic.AllowSave <ProcessEntity>()) CurrentProcess.Save(); } catch (Exception e) { if (Transaction.InTestTransaction) { throw; } CurrentProcess.State = ProcessState.Error; CurrentProcess.ExceptionDate = TimeZoneManager.Now; CurrentProcess.Exception = e.LogException(el => el.ActionName = CurrentProcess.Algorithm.ToString()).ToLite(); using (OperationLogic.AllowSave <ProcessEntity>()) CurrentProcess.Save(); } finally { ProcessRunnerLogic.OnFinally?.Invoke(this); } } } }
public void TakeForThisMachine() { CurrentProcess.State = ProcessState.Executing; CurrentProcess.ExecutionStart = TimeZoneManager.Now; CurrentProcess.ExecutionEnd = null; CurrentProcess.Progress = 0; CurrentProcess.MachineName = Environment.MachineName; CurrentProcess.ApplicationName = Schema.Current.ApplicationName; using (Transaction tr = new Transaction()) { if (CurrentProcess.InDB().Any(a => a.State == ProcessState.Executing)) { throw new InvalidOperationException("The process {0} is allready Executing!".FormatWith(CurrentProcess.Id)); } using (OperationLogic.AllowSave <ProcessEntity>()) CurrentProcess.Save(); tr.Commit(); } }