Example #1
0
        public static SpyLog Parse(string line)
        {
            Match  m       = LogRegex.Match(line);
            string no      = m.Groups["No"].Value;
            string hWnd    = m.Groups["hWnd"].Value;
            string nCode   = m.Groups["nCode"].Value;
            string wParam  = m.Groups["wParam"].Value;
            string lParam  = m.Groups["lParam"].Value;
            string timeStr = m.Groups["time"].Value;

            Match  mTime      = TimeRegex.Match(timeStr);
            int    year       = 2000;
            int    month      = 1;
            int    day        = 1;
            string hourStr    = mTime.Groups["Hour"].Value.PadLeft(2, '0');
            string minStr     = mTime.Groups["Minute"].Value.PadLeft(2, '0');
            string secStr     = mTime.Groups["Second"].Value.PadLeft(2, '0');
            string miliSecStr = mTime.Groups["Millisecond"].Value.PadLeft(3, '0');
            int    hms        = int.Parse(hourStr + minStr + secStr + miliSecStr);

            if (240000000 < hms)
            {
                day    += 1;
                hourStr = (int.Parse(hourStr) - 24).ToString().PadLeft(2, '0');
            }
            int      hour    = int.Parse(hourStr);
            int      min     = int.Parse(minStr);
            int      sec     = int.Parse(secStr);
            int      milisec = int.Parse(miliSecStr);
            DateTime time    = new DateTime(year, month, day, hour, min, sec, milisec);

            try
            {
                return(new SpyLog
                {
                    No = int.Parse(no),
                    hWnd = ParseHexNumber(hWnd),
                    nCode = Code.Parse(nCode),
                    nCodeStr = nCode,
                    wParam = ParseHexNumber(wParam),
                    lParam = ParseHexNumber(lParam),
                    Time = time,
                });
            }
            catch (Exception e)
            {
                Log.Write(e);

                return(new SpyLog
                {
                    No = -1,
                    hWnd = IntPtr.Zero,
                    nCode = 0u,
                    nCodeStr = string.Empty,
                    wParam = IntPtr.Zero,
                    lParam = IntPtr.Zero,
                    Time = DateTime.MinValue,
                });
            }
        }
Example #2
0
        private void ParseAnnotated(DirectoryInfo dir)
        {
            if (ScoreRegex.IsMatch(dir.Name))
            {
                Match mYear;
                if (!YearRegex.TryGetMatch(dir.Name, out mYear))
                {
                    Error($"No year match found for {dir.Name}");
                    return;
                }
                Year = mYear.Groups[1].Value;

//                Year = MatchInt(YearRegex, true);
                Match mTime;
                if (!TimeRegex.TryGetMatch(dir.Name, out mTime))
                {
                    Error($"No year match found for {dir.Name}");
                    return;
                }
                RunTime = mTime.Value;
//                RunTime = TimeRegex.Match(Name).Value;

                ParseRatings();
                Regex  spaceReg = new Regex(@"\s+");
                string tmpTitle =
                    Name.ReplaceWithString(Year).ReplaceWithString(RunTime);
                tmpTitle = tmpTitle.ReplaceWithString(OtherRegex.Match(tmpTitle).Value);
                Title    = spaceReg.ReplaceWithString(tmpTitle, " ");
                return;
            }
            ParseStd(dir);
            GetMetaWithoutScore(dir);
        }
Example #3
0
        private DateTime GetDate(string day, string time)
        {
            if (String.IsNullOrEmpty(day) || String.IsNullOrEmpty(time))
            {
                return(DateTime.MinValue);
            }

            var dow = (int)DateTime.Now.DayOfWeek;
            //if (dow < 0)
            //    dow += 7;

            var eday  = Int32.Parse(day);
            var date  = DateTime.Today.AddDays(eday < dow ?  (7 + eday - dow): (eday - dow));
            var match = TimeRegex.Match(time);

            if (!match.Success)
            {
                return(DateTime.MinValue);
            }

            date = date.AddHours(Double.Parse(match.Groups[1].Value)).AddMinutes(Double.Parse(match.Groups[2].Value));

            return(date);
        }
Example #4
0
        /// <summary>
        /// Parse date and time string
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static DateTime Parse(string text)
        {
            DateTime result = DateTime.MinValue;

            if (String.IsNullOrEmpty(text))
            {
                return(result);
            }

            text = text.Trim();
            int    n;
            Match  match;
            string s;

            match = DateRegex.Match(text);

            if (!match.Success)
            {
                match = null;
            }

            if (null == match)
            {
                match = NumericDateRegex.Match(text);
                if (!match.Success)
                {
                    match = null;
                }
            }

            if (null != match)
            {
                s = match.Groups["year"].Value;
                if (!string.IsNullOrEmpty(s) && 0 < (n = int.Parse(s)))
                {
                    result = result.AddYears(n - 1);
                }
                s = match.Groups["month"].Value;
                if (!string.IsNullOrEmpty(s) && 0 < (n = int.Parse(s)))
                {
                    if (n > 12)
                    {
                        return(DateTime.MinValue);
                    }
                    result = result.AddMonths(n - 1);
                }
                s = match.Groups["day"].Value;
                if (!string.IsNullOrEmpty(s) && 0 < (n = int.Parse(s)))
                {
                    switch (result.Month)
                    {
                    case 1:
                    case 3:
                    case 5:
                    case 7:
                    case 8:
                    case 10:
                    case 12:
                        if (n > 31)
                        {
                            return(DateTime.MinValue);
                        }
                        break;

                    case 2:
                        bool leap = (0 == result.Year % 4) && (0 < result.Year % 100 || 0 == result.Year % 400);
                        if (n > 28 + (leap ? 1 : 0))
                        {
                            return(DateTime.MinValue);
                        }
                        break;

                    case 4:
                    case 6:
                    case 9:
                    case 11:
                        if (n > 30)
                        {
                            return(DateTime.MinValue);
                        }
                        break;
                    }
                    result = result.AddDays(n - 1);
                }
                text = text.Substring(0, match.Index) + text.Substring(match.Index + match.Length);
            }

            match = TimeRegex.Match(text);

            if (match.Success)
            {
                s = match.Groups["hour"].Value;
                if (!string.IsNullOrEmpty(s) && 0 < (n = int.Parse(s)))
                {
                    result = result.AddHours(n);
                }
                s = match.Groups["minute"].Value;
                if (!string.IsNullOrEmpty(s) && 0 < (n = int.Parse(s)))
                {
                    result = result.AddMinutes(n);
                }
                s = match.Groups["second"].Value;
                if (!string.IsNullOrEmpty(s) && 0 < (n = int.Parse(s)))
                {
                    result = result.AddSeconds(n);
                }
                if (!string.IsNullOrEmpty(match.Groups["fraction"].Value))
                {
                    double d = double.Parse(string.Concat("0.", match.Groups["fraction"])
                                            , System.Globalization.NumberStyles.AllowDecimalPoint
                                            , System.Globalization.CultureInfo.InvariantCulture);
                    if (d > 0)
                    {
                        long t = (long)(TimeSpan.TicksPerSecond * d);
                        result = result.AddTicks(t);
                    }
                }
            }

            return(result);
        }