コード例 #1
0
            private async Task <int> GetInt(StreamReader sr)
            {
                string line = await ReadLine(sr);

                try {
                    Match m = StringValRegex.Match(line);
                    if (string.IsNullOrWhiteSpace(m.Groups[1].Value))
                    {
                        return(-1);
                    }

                    return(int.Parse(m.Groups[1].Value));
                }
                catch (Exception) {
                    Console.WriteLine("Offending Line: " + line);
                    throw;
                }
            }
コード例 #2
0
            public async Task <bool> ReadData(StreamReader sr)
            {
                string firstLine = await ReadLine(sr);                   //Opening Bracket

                if (firstLine.Contains("}"))
                {
                    return(false);
                }

                Target   = StringValRegex.Match(await ReadLine(sr)).Groups[1].Value;
                Giver    = StringValRegex.Match(await ReadLine(sr)).Groups[1].Value;
                Message  = StringValRegex.Match(await ReadLine(sr)).Groups[1].Value;
                EPBefore = await GetInt(sr);

                EPAfter = await GetInt(sr);

                GPBefore = await GetInt(sr);

                GPAfter = await GetInt(sr);

                string itemLine = await ReadLine(sr);

                string timestampLine = itemLine;
                Match  itemMatch     = ItemValRegex.Match(itemLine);

                if (itemMatch.Success)
                {
                    ItemID        = int.Parse(itemMatch.Groups[1].Value);
                    ItemName      = itemMatch.Groups[2].Value;
                    timestampLine = await ReadLine(sr);
                }

                bool TryTimestamp()
                {
                    Match timestampMatch = TimestampValRegex.Match(timestampLine);

                    try {
                        int secondsSince = int.Parse(timestampMatch.Groups[1].Value);
                        Timestamp = DateTimeOffset.FromUnixTimeSeconds(secondsSince).DateTime - TimeSpan.FromHours(5);                             //Convert to central time
                        return(true);
                    }
                    catch (Exception) {
                        return(false);
                    }
                }

                if (TryTimestamp() == false)
                {
                    timestampLine = await ReadLine(sr);

                    if (TryTimestamp() == false)
                    {
                        throw new Exception("Failed to get timestamp");
                    }
                }


                while (true)
                {
                    string bracket = await ReadLine(sr);                       //Closing Bracket

                    if (bracket.Trim().StartsWith("}"))
                    {
                        break;
                    }
                }

                //Console.WriteLine( $"{ Target } - { Message } - { GPBefore } - { GPAfter } - { ItemName }" );

                return(true);
            }