Пример #1
0
        /// <summary>
        /// Check - does log file ended?
        /// </summary>
        /// <returns></returns>
        internal bool ____checkLogFileEnded()
        {
            bool resLogFileEnded = false;

            if (contentsLogFile.Count() == 0)
            {
                ReadLogFileContents();
            }

            //скопируем и поменяем порядок строк на обратный
            List <string> contentsLogFileReversed = new List <string>(contentsLogFile);

            contentsLogFileReversed.Reverse();

            //Прочитаем последние 3 строки и проверим его
            var LastThreeLines = contentsLogFileReversed.Take(3);

            foreach (string StLn in LastThreeLines)
            {
                if (StLn.Contains("Action complete.") || StLn.Contains("Action stopped.") || StLn.Contains("Stopping."))
                {
                    resLogFileEnded = true;
                    break;
                }
            }

            return(resLogFileEnded);
        }
Пример #2
0
        /// <summary>
        /// Check - if selected log file is current running log file
        /// </summary>
        /// <returns></returns>
        internal bool checkLogFileIsValid()
        {
            bool     resNameAgeValid   = false;
            bool     resChangeAgeValid = false;
            bool     resContentsValid  = false;
            bool     resFinal          = false;
            DateTime LogDate           = new DateTime();

            // Get file name only
            // format ccdap20170212_124827
            string curName = Path.GetFileNameWithoutExtension(currentLogFile.Name);


            //1. Check date from name
            if (curName.Substring(0, 5) == "ccdap")
            {
                if (DateTime.TryParseExact(curName.Substring(5), "yyyyMMdd_HHmmss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out LogDate))
                {
                    TimeSpan LogFileAge = DateTime.Now - LogDate;
                    if (LogFileAge.TotalSeconds > _MAX_VALID_CCDAP_LOGFILE_NAMEAGE)
                    {
                        //log file is too old
                        resNameAgeValid = false;
                    }
                    else
                    {
                        resNameAgeValid = true;
                    }
                }
                else
                {
                    resNameAgeValid = false; //date invalid
                }
            }
            else
            {
                //имя файла не по шаблону
                resNameAgeValid = false;
            }


            //2. Check file change date
            int sinceMod = GetTimeSinceLogFileModified();

            resChangeAgeValid = (sinceMod < _MAX_VALID_CCDAP_LOGFILE_MODAGE) || true;


            //3. Check file contents if all dates are in range
            if (resNameAgeValid && resChangeAgeValid)
            {
                resContentsValid = true;
                contentsLogFile  = File.ReadLines(currentLogFile.FullName);
                var LastThreeLines = contentsLogFile.Reverse().Take(3);

                foreach (string StLn in LastThreeLines)
                {
                    if (StLn.Contains("Session completed"))
                    {
                        resContentsValid = false;
                        break;
                    }
                }
            }


            resFinal = resNameAgeValid && resChangeAgeValid && resContentsValid;

            return(resFinal);
        }