예제 #1
0
        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);
        }
예제 #2
0
파일: CMD.cs 프로젝트: jeason0813/Asmodat
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        public static bool IsEnabled(this TickTimeout timeout)
        {
            if (timeout == null || !timeout.Enabled)
            {
                return(false);
            }

            return(true);
        }
예제 #5
0
        public static TickTimeout Copy(this TickTimeout timeout)
        {
            if (timeout == null)
            {
                return(null);
            }

            return((TickTimeout)timeout.Clone());
        }
예제 #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);
        }
예제 #7
0
        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);
        }
예제 #8
0
파일: CMD.cs 프로젝트: jeason0813/Asmodat
        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);
            }
        }
예제 #9
0
 public void SetTimeouts(TickTimeout value)
 {
     this._Timeout.PopulateClone(value);
 }