Пример #1
0
        /// <summary>
        /// Attempt to create WurmDateTime from wurm log line, throws exception on error
        /// </summary>
        /// <exception cref="WurmApiException">Parsing failed</exception>
        /// <param name="logLine"></param>
        private WurmDateTime?TryCreateWurmDateTimeFromLogLine(string logLine)
        {
            //[16:24:19] It is 09:00:48 on day of the Wurm in week 4 of the Bear's starfall in the year of 1035.

            //time
            Match wurmTime = Regex.Match(logLine, @" \d\d:\d\d:\d\d ", RegexOptions.Compiled);

            if (!wurmTime.Success)
            {
                return(null);
            }
            int hour   = Convert.ToInt32(wurmTime.Value.Substring(1, 2));
            int minute = Convert.ToInt32(wurmTime.Value.Substring(4, 2));
            int second = Convert.ToInt32(wurmTime.Value.Substring(7, 2));
            //day
            WurmDay?day = null;

            foreach (string name in WurmDay.AllNormalizedNames)
            {
                if (Regex.IsMatch(logLine, name, RegexOptions.Compiled | RegexOptions.IgnoreCase))
                {
                    day = new WurmDay(name);
                    break;
                }
            }
            //week
            Match wurmWeek = Regex.Match(logLine, @"week (\d)", RegexOptions.Compiled);

            if (!wurmWeek.Success)
            {
                return(null);
            }
            int week = Convert.ToInt32(wurmWeek.Groups[1].Value);
            //month(starfall)
            WurmStarfall?starfall = null;

            foreach (string name in WurmStarfall.AllNormalizedNames)
            {
                if (Regex.IsMatch(logLine, name, RegexOptions.Compiled | RegexOptions.IgnoreCase))
                {
                    starfall = new WurmStarfall(name);
                    break;
                }
            }
            //year
            Match wurmYear = Regex.Match(logLine, @"in the year of (\d+)", RegexOptions.Compiled);

            if (!wurmYear.Success)
            {
                return(null);
            }
            int year = Convert.ToInt32(wurmYear.Groups[1].Value);

            if (day == null || starfall == null)
            {
                return(null);
            }

            return(new WurmDateTime(year, starfall.Value, week, day.Value, hour, minute, second));
        }
Пример #2
0
        static WurmDateTime GetWurmDateTimeFromWdtWebString(string logline)
        {
            //time
            Match wurmTime = Regex.Match(logline, @" \d\d:\d\d:\d\d ");
            int   hour     = Convert.ToInt32(wurmTime.Value.Substring(1, 2));
            int   minute   = Convert.ToInt32(wurmTime.Value.Substring(4, 2));
            int   second   = Convert.ToInt32(wurmTime.Value.Substring(7, 2));
            //day
            WurmDay?day = null;

            foreach (string name in WurmDay.AllNormalizedNames)
            {
                if (Regex.IsMatch(logline, name, RegexOptions.Compiled | RegexOptions.IgnoreCase))
                {
                    day = new WurmDay(name);
                    break;
                }
            }
            //week
            Match wurmWeek = Regex.Match(logline, @"week (\d)");
            int   week     = Convert.ToInt32(wurmWeek.Groups[1].Value);
            //month(starfall)
            WurmStarfall?starfall = null;

            foreach (string name in WurmStarfall.AllNormalizedNames)
            {
                if (Regex.IsMatch(logline, name, RegexOptions.Compiled | RegexOptions.IgnoreCase))
                {
                    starfall = new WurmStarfall(name);
                    break;
                }
            }
            //year
            Match wurmYear = Regex.Match(logline, @"in the year of (\d+)");
            int   year     = Convert.ToInt32(wurmYear.Groups[1].Value);

            if (day == null || starfall == null)
            {
                throw new Exception("log line was not parsed correctly into day or starfall: " + (logline ?? "NULL"));
            }

            return(new WurmDateTime(year, starfall.Value, week, day.Value, hour, minute, second));
        }
Пример #3
0
        static WurmDateTime GetWurmDateTimeFromWdtWebString(string logline)
        {
            //time
            Match wurmTime = Regex.Match(logline, @" \d\d:\d\d:\d\d ");
            int hour = Convert.ToInt32(wurmTime.Value.Substring(1, 2));
            int minute = Convert.ToInt32(wurmTime.Value.Substring(4, 2));
            int second = Convert.ToInt32(wurmTime.Value.Substring(7, 2));
            //day
            WurmDay? day = null;
            foreach (string name in WurmDay.AllNormalizedNames)
            {
                //todo might be faster to just catch exception
                if (Regex.IsMatch(logline, name, RegexOptions.Compiled | RegexOptions.IgnoreCase))
                {
                    day = new WurmDay(name);
                    break;
                }
            }
            //week
            Match wurmWeek = Regex.Match(logline, @"week (\d)");
            int week = Convert.ToInt32(wurmWeek.Groups[1].Value);
            //month(starfall)
            WurmStarfall? starfall = null;
            foreach (string name in WurmStarfall.AllNormalizedNames)
            {
                //todo might be faster to just catch exception
                if (Regex.IsMatch(logline, name, RegexOptions.Compiled | RegexOptions.IgnoreCase))
                {
                    starfall = new WurmStarfall(name);
                    break;
                }
            }
            //year
            Match wurmYear = Regex.Match(logline, @"in the year of (\d+)");
            int year = Convert.ToInt32(wurmYear.Groups[1].Value);

            if (day == null || starfall == null)
                throw new Exception("log line was not parsed correctly into day or starfall: " + (logline ?? "NULL"));

            return new WurmDateTime(year, starfall.Value, week, day.Value, hour, minute, second);
        }
Пример #4
0
        /// <summary>
        /// Attempt to create WurmDateTime from wurm log line, throws exception on error
        /// </summary>
        /// <exception cref="WurmApiException">Parsing failed</exception>
        /// <param name="logLine"></param>
        private WurmDateTime? TryCreateWurmDateTimeFromLogLine(string logLine)
        {
            //[16:24:19] It is 09:00:48 on day of the Wurm in week 4 of the Bear's starfall in the year of 1035.

            //time
            Match wurmTime = Regex.Match(logLine, @" \d\d:\d\d:\d\d ", RegexOptions.Compiled);
            if (!wurmTime.Success)
            {
                return null;
            }
            int hour = Convert.ToInt32(wurmTime.Value.Substring(1, 2));
            int minute = Convert.ToInt32(wurmTime.Value.Substring(4, 2));
            int second = Convert.ToInt32(wurmTime.Value.Substring(7, 2));
            //day
            WurmDay? day = null;
            foreach (string name in WurmDay.AllNormalizedNames)
            {
                //todo might be faster to just catch exception
                if (Regex.IsMatch(logLine, name, RegexOptions.Compiled | RegexOptions.IgnoreCase))
                {
                    day = new WurmDay(name);
                    break;
                }
            }
            //week
            Match wurmWeek = Regex.Match(logLine, @"week (\d)", RegexOptions.Compiled);
            if (!wurmWeek.Success)
            {
                return null;
            }
            int week = Convert.ToInt32(wurmWeek.Groups[1].Value);
            //month(starfall)
            WurmStarfall? starfall = null;
            foreach (string name in WurmStarfall.AllNormalizedNames)
            {
                //todo might be faster to just catch exception
                if (Regex.IsMatch(logLine, name, RegexOptions.Compiled | RegexOptions.IgnoreCase))
                {
                    starfall = new WurmStarfall(name);
                    break;
                }
            }
            //year
            Match wurmYear = Regex.Match(logLine, @"in the year of (\d+)", RegexOptions.Compiled);
            if (!wurmYear.Success)
            {
                return null;
            }
            int year = Convert.ToInt32(wurmYear.Groups[1].Value);

            if (day == null || starfall == null)
            {
                return null;
            }

            return new WurmDateTime(year, starfall.Value, week, day.Value, hour, minute, second);
        }