public TickTimeout GetLastTimeout(long min = 0, long max = long.MaxValue)
        {
            if (_Timeout.IsNullOrEmpty())
            {
                return(null);
            }

            int xParts = _Timeout.Width();
            int yParts = _Timeout.Height();

            decimal     select = max;
            TickTimeout result = null;
            int         x = 0, y;

            for (; x < xParts; x++)
            {
                for (y = 0; y < yParts; y++)
                {
                    TickTimeout tt = _Timeout[x, y];
                    if (!tt.IsEnabled())
                    {
                        continue;
                    }

                    if (tt.Span.InClosedInterval(min, max) && tt.Span <= select)
                    {
                        select = tt.Span;
                        result = tt.Copy();
                    }
                }
            }

            return(result);
        }
Beispiel #2
0
        public bool WaitForResponse(DataType responseType, TickTime init, int timeout_ms, bool waitForAnyIsCaseSensitive, params string[] waitForAny)
        {
            if (waitForAny.IsNullOrEmpty())
            {
                return(false);
            }

            var timeout = new TickTimeout(timeout_ms, TickTime.Unit.ms);

            while (!timeout.IsTriggered)
            {
                if ((responseType & DataType.Output) > 0 &&
                    waitForAny != null &&
                    (OutputData.Any(p => p.Key > init && p.Value.ContainsAny(waitForAny, waitForAnyIsCaseSensitive == true))))
                {
                    return(true);
                }

                if ((responseType & DataType.Error) > 0 &&
                    waitForAny != null &&
                    (ErrorData.Any(p => p.Key > init && p.Value.ContainsAny(waitForAny, waitForAnyIsCaseSensitive == true))))
                {
                    return(true);
                }

                Thread.Sleep(10);
            }

            return(false);
        }
        public object Clone()
        {
            TickTimeout obj = new TickTimeout(this.Timeout, this.Unit, this.Enabled);

            obj.Start      = this.Start.Copy();
            obj.Forced     = this.Forced;
            obj.TiggerSpan = this.TiggerSpan.Copy();
            return(obj);
        }
        public static bool IsEnabled(this TickTimeout timeout)
        {
            if (timeout == null || !timeout.Enabled)
            {
                return(false);
            }

            return(true);
        }
        public static TickTimeout Copy(this TickTimeout timeout)
        {
            if (timeout == null)
            {
                return(null);
            }

            return((TickTimeout)timeout.Clone());
        }
Beispiel #6
0
        public decimal JoinStop(int timeout_ms)
        {
            TickTimeout timeout = new TickTimeout(timeout_ms, TickTime.Unit.ms);

            while (!this.Stopped && !timeout.IsTriggered)
            {
                Thread.Sleep(1);
            }

            return(timeout.Span);
        }
        public TickTimeout GetFirstTimeout(long min = 0, long max = long.MaxValue)
        {
            if (_Timeout.IsNullOrEmpty())
            {
                return(null);
            }

            int xParts = _Timeout.Width();
            int yParts = _Timeout.Height();

            decimal select = min;
            int     sx = -1, sy = -1;

            int x = 0, y;

            for (; x < xParts; x++)
            {
                for (y = 0; y < yParts; y++)
                {
                    TickTimeout tt = _Timeout[x, y];

                    if (!tt.IsEnabled())
                    {
                        continue;
                    }

                    if (tt.Span.InClosedInterval(min, max) && tt.Span >= select)
                    {
                        select = tt.Span;
                        sx     = x;
                        sy     = y;
                    }
                }
            }

            if (sx >= 0 && sy >= 0)
            {
                return(_Timeout[sx, sy].Copy());
            }


            return(null);
        }
Beispiel #8
0
        public TickTime WriteLine(string cmd, int timeout_ms)
        {
            lock (_locker)
            {
                TickTime ttOutput = TickTime.Now, ttError = TickTime.Now, ttInit = TickTime.Now;
                Process.StandardInput.WriteLine(cmd);

                if (!cmd.IsNullOrEmpty())
                {
                    if (InputData.Count >= MaxInputDataLength)
                    {
                        InputData.Remove(OutputData.FirstKey);
                    }

                    InputData.Add(ttInit, cmd);
                }

                if (timeout_ms <= 0)
                {
                    return(ttInit);
                }

                TickTimeout   timeout = new TickTimeout(timeout_ms, TickTime.Unit.ms);
                List <string> output = new List <string>(), error = new List <string>();

                while (!timeout.IsTriggered && !Process.HasExited)
                {
                    var outputKeys = OutputData.KeysArray;

                    if (ErrorData.Any(x => x.Key > ttInit) || OutputData.Any(x => x.Key > ttInit))
                    {
                        break;
                    }

                    Thread.Sleep(10);
                }

                return(ttInit);
            }
        }
 public void SetTimeouts(TickTimeout value)
 {
     this._Timeout.PopulateClone(value);
 }