コード例 #1
0
 public virtual void RunWithLifeCycle()
 {
     try
     {
         CommandLifeCycle.FirePreActions(this);
         if (SecondsBeforeTimeout <= 0)
         {
             Run();
         }
         else
         {
             var task = Task.Run(() => Run());
             if (!task.Wait(TimeSpan.FromSeconds(SecondsBeforeTimeout)))
             {
                 throw new Exception($"Scheduled command timed out after {SecondsBeforeTimeout} second(s).");
             }
         }
         CommandLifeCycle.FirePostActions(this);
     }
     catch (Exception exception)
     {
         Log.Error(this, exception);
         Failed(exception);
         throw new CommandFailedException("Command failed. See inner exception for details.", exception);
     }
 }
コード例 #2
0
 protected AbstractCommand()
 {
     Log              = LogManager.GetLogger(GetType());
     ScheduleId       = Guid.NewGuid().ToString();
     Name             = GetType().FullName;
     SchedulerGroup   = GetType().AssemblyQualifiedName;
     Write            = new Write();
     CommandLifeCycle = new CommandLifeCycle()
     {
         MailSettings = MailSettings
     };
     SecondsBeforeTimeout = 300;
 }