Пример #1
0
 //Добавить в комманду ошибку error, isRepeated - ошибка произошла в повторяемой операции
 public override void AddError(ErrorCommand error, bool isRepeated)
 {
     ChangeQuality(error, isRepeated);
     if (Parent != null)
     {
         Parent.AddError(error, true);
     }
 }
Пример #2
0
 //Добавить ошибку
 public virtual void AddError(CommandError err)
 {
     AddQuality(err.Quality);
     if (Parent != null)
     {
         Parent.AddError(err);
     }
 }
Пример #3
0
 //Добавить ошибку
 public override void AddError(CommandError err)
 {
     _isCorrect &= err.Quality != CommandQuality.Error;
     AddQuality(_lastRepeat ? err.Quality : CommandQuality.Repeat);
     if (_lastRepeat && Parent != null)
     {
         Parent.AddError(err);
     }
     else if (Logger.History != null)
     {
         Logger.History.WriteError(err);
     }
 }
Пример #4
0
 public void AddError(string name, string message)
 {
     errors.Add(Name + name + ": " + message);
     Parent?.AddError(Name + name, message);
 }
Пример #5
0
        public Command Run(Action action,           //операция
                           Func <bool> erorrAction) //операция, выполняемя между повторами
        {
            for (int i = 1; i <= _repetitions; i++)
            {
                Logger.CheckBreak();
                _lastRepeat = i == _repetitions;
                _isCorrect  = true;
                if (!_useThread) //однопоточный вариант
                {
                    if (RunAction(() => { action(); return(true); }))
                    {
                        return(Finish());
                    }
                }
                else //многопоточный
                {
                    var thread = new Thread(() => RunAction(() => { action(); return(true); }));
                    thread.Start();
                    while (thread.ThreadState == ThreadState.Running)
                    {
                        Thread.Sleep(50);
                        if (Logger.WasBreaked)
                        {
                            int n = 0;
                            while (thread.ThreadState == ThreadState.Running && (n += 50) < 2000)
                            {
                                Thread.Sleep(50);
                            }
                            if (thread.ThreadState == ThreadState.Running)
                            {
                                thread.Abort();
                                Thread.Sleep(100);
                            }
                            Logger.CheckBreak();
                            return(this);
                        }
                    }
                    Logger.CheckBreak();
                    if (_isCorrect)
                    {
                        return(Finish());
                    }
                }

                if (i == _repetitions)
                {
                    return(Finish());
                }
                if (Parent != null)
                {
                    Parent.AddError(new CommandError(_eventMess + ". Повтор операции из-за ошибки", null, "", "", CommandQuality.Repeat));
                }
                Logger.CheckBreak();
                while (Logger.Command != this)
                {
                    Logger.Finish();
                }

                if (_errWaiting != 0)
                {
                    int n = 0;
                    while ((n += 50) < _errWaiting)
                    {
                        Thread.Sleep(Math.Min(50, _errWaiting));
                        Logger.CheckBreak();
                    }
                }

                _isCorrect = true;
                if (erorrAction != null && !RunAction(erorrAction))
                {
                    return(Finish());
                }
            }
            return(this);
        }