Esempio n. 1
0
        public T ReadNext(TickTime previous)
        {
            TickTime time;
            T        result = ReadNext(out time, previous);

            return(result);
        }
Esempio n. 2
0
        public bool ExitWait(string key, long timeout_ms = -1, int intensity_ms = 1)
        {
            TickTime start = TickTime.Now;

            if (!this.Contains(key))
            {
                return(false);
            }

            if (!intensity_ms.InClosedInterval(1, int.MaxValue))
            {
                intensity_ms = 1;
            }

            while (!this.Exit(key))
            {
                if (timeout_ms > 0 && TickTime.Timeout(start, timeout_ms, TickTime.Unit.ms))
                {
                    return(false);
                }

                try
                {
                    Thread.Sleep(intensity_ms);
                }
                catch// (Exception ex)
                {
                    //Exceptions.Write(ex);
                    return(false);
                }
            }

            return(true);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="Timeout">timeout</param>
 /// <param name="Unit">timeout unit</param>
 /// <param name="Start">timer start time</param>
 /// <param name="Enabled">defines if timeout shoud be enabled</param>
 public TickTimeout(long Timeout, TickTime.Unit Unit, TickTime Start, bool Enabled = true)
 {
     this.Start   = Start;
     this.Timeout = Timeout;
     this.Unit    = Unit;
     this.Enabled = Enabled;
 }
Esempio n. 4
0
        public bool GetLastObject(out T data)
        {
            TickTime first = TickTime.Now;
            int      index = -1;

            lock (locker)
            {
                for (int i = 0; i < Length; i++)
                {
                    if (Times[i] < first && Times[i] > TickTime.Default)
                    {
                        first = Times[i];
                        index = i;
                        continue;
                    }
                }

                if (index >= 0)
                {
                    data = Elements[index];
                    return(true);
                }
                else
                {
                    data = default(T);
                    return(false);
                }
            }
        }
Esempio n. 5
0
        public bool Read(out T data, out TickTime time)
        {
            TickTime first = TickTime.Now;
            int      index = -1;

            lock (locker)
            {
                for (int i = 0; i < Length; i++)
                {
                    if (!Reads[i] && Times[i] < first && Times[i] > TickTime.MinValue)
                    {
                        first = Times[i];
                        index = i;
                        continue;
                    }
                }

                if (index >= 0)
                {
                    data         = Elements[index];
                    time         = Times[index];
                    Reads[index] = true;
                    return(true);
                }
                else
                {
                    data = default(T);
                    time = TickTime.Default;
                    return(false);
                }
            }
        }
Esempio n. 6
0
        public bool EnterWait(long timeout_ms = -1, int intensity_ms = 1)
        {
            TickTime start = TickTime.Now;

            if (!intensity_ms.InClosedInterval(1, int.MaxValue))
            {
                intensity_ms = 1;
            }

            while (!this.Enter())
            {
                if (timeout_ms > 0 && start.Timeout(timeout_ms))
                {
                    return(false);
                }

                try
                {
                    Thread.Sleep(intensity_ms);
                }
                catch
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        public void Write(T data, TickTime time)
        {
            Cleanup();

            Buffer.Add(time.Copy(), data, true);
            _TickerWrite.SetNow();
        }
Esempio n. 9
0
 public void Start()
 {
     lock (locker)
     {
         _StartTime = TickTime.Now;
         IsStarded  = true;
     }
 }
Esempio n. 10
0
        public void Write(T data, TickTime time)
        {
            if (Size > 0 && Buffer.Count > Size)
            {
                this.Cleanup();
            }

            Buffer.Add(time.Copy(), data);
            _TickerWrite.SetNow();
        }
Esempio n. 11
0
        /* public KeyValuePair<TickTime, string>[] GetNextData(TickTime init)
         * {
         *   var data = new List<KeyValuePair<TickTime, string>>();
         *   data.AddRange(GetNextOutputs(init));
         *   data.AddRange(GetNextErrors(init));
         *   data.AddRange(GetNextInputs(init));
         *   return data.ToArray();
         * }*/

        public TickTime GetNextPointer(TickTime init)
        {
            var data = this.GetNextData(DataType.Any, init);

            if (data.IsNullOrEmpty())
            {
                return(TickTime.Default);
            }

            return(data.Min(x => x.Key));
        }
Esempio n. 12
0
        public void Reset(bool startNow = false)
        {
            lock (locker)
            {
                //Clear ticks on start
                _Ticks = 0;

                if (startNow)
                {
                    this.Start();
                }
                else
                {
                    _StartTime = TickTime.Default;
                    IsStarded  = false;
                }
            }
        }
Esempio n. 13
0
        public KeyValuePair <TickTime, string>[] GetNextData(DataType type, TickTime init)
        {
            ThreadedDictionary <TickTime, string> data = new ThreadedDictionary <TickTime, string>();

            if ((type & DataType.Input) > 0)
            {
                data.AddRange(InputData.ToDictionary());
            }
            if ((type & DataType.Error) > 0)
            {
                data.AddRange(ErrorData.ToDictionary());
            }
            if ((type & DataType.Output) > 0)
            {
                data.AddRange(OutputData.ToDictionary());
            }

            return(data?.Where(x => x.Key > init)?.Select(x => { return new KeyValuePair <TickTime, string>(x.Key.Copy(), x.Value); })?.ToArray() ?? new KeyValuePair <TickTime, string> [0]);
        }
Esempio n. 14
0
        public T ReadNext(out TickTime time, TickTime previous)
        {
            T result = default(T);

            time = previous.Copy();
            var keys = Buffer.KeysArray;

            foreach (var key in keys)
            {
                if (key > time)
                {
                    time   = key;
                    result = Buffer[key];
                }
            }

            _TickerRead.SetNow();
            return(result);
        }
Esempio n. 15
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);
            }
        }
Esempio n. 16
0
        public (DataType type, string value) GetData(TickTime time)
        {
            if (!time.IsDefault)
            {
                lock (_locker)
                {
                    if (InputData.ContainsKey(time))
                    {
                        return(DataType.Input, InputData[time]);
                    }
                    if (ErrorData.ContainsKey(time))
                    {
                        return(DataType.Error, ErrorData[time]);
                    }
                    if (OutputData.ContainsKey(time))
                    {
                        return(DataType.Output, OutputData[time]);
                    }
                }
            }

            return(DataType.None, null);
        }
Esempio n. 17
0
 public static decimal TimeoutSpan(this TickTime start, long timeout, TickTime.Unit unit, TickTime.Unit unit_result)
 {
     return(TickTime.TimeoutSpan(start, timeout, unit, unit_result));
 }
Esempio n. 18
0
 public static bool Timeout(this TickTime start, long timeout, TickTime.Unit unit = TickTime.Unit.ms)
 {
     return(TickTime.Timeout(start, timeout, unit));
 }
Esempio n. 19
0
 public T ReadNext(TickTime previous)
 {
     return(ReadNext(out TickTime time, previous));
 }
Esempio n. 20
0
 public T ReadLast(out TickTime time)
 {
     return(this.ReadNext(out time, TickTime.Default));
 }