예제 #1
0
        /// <summary>
        ///     Recebe uma entrada do usuário.
        /// </summary>
        /// <param name="isSensitive">Indica se deve ser tratado como dado sensível.</param>
        /// <returns>Entrada do usuário</returns>
        public override string Read(bool isSensitive = false)
        {
            if (_lastAnswer != null)
            {
                return(string.Empty);
            }

            Stopwatch.Stop();
            Filename.Refresh();

            if (!Filename.Exists || Filename.Length <= 0)
            {
                return(null);
            }

            var lines = System.IO.File.ReadAllLines(Filename.FullName).ToList();

            if (lines.Count <= 0)
            {
                return(null);
            }

            var answer = lines[0];

            lines.RemoveAt(0);
            System.IO.File.WriteAllLines(Filename.FullName, lines.ToArray());

            if (answer != InputAnswerToExit && answer != InputAnswerToRoot)
            {
                return(answer);
            }
            _lastAnswer = answer;
            return(string.Empty);
        }
예제 #2
0
        /// <summary>
        ///     Verifica se possui resposta prévia.
        /// </summary>
        public override bool HasRead()
        {
            // ReSharper disable once ArrangeRedundantParentheses
            if (_lastAnswer == InputAnswerToExit || (_lastAnswer == InputAnswerToRoot && !IsModuleRoot))
            {
                return(true);
            }
            _lastAnswer = null;

            if (Stopwatch.IsRunning && Stopwatch.ElapsedMilliseconds <= Interval)
            {
                return(_lastHasRead);
            }

            Stopwatch.Restart();
            Filename.Refresh();
            if (Filename.Exists && Filename.Length > 0)
            {
                _lastHasRead = System.IO.File.ReadAllLines(Filename.FullName).Any();
            }
            else
            {
                _lastHasRead = false;
            }

            return(_lastHasRead);
        }