Exemplo n.º 1
0
        /// <summary>
        /// VRChatのログを解析します。
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        private List <ActivityLog> ParseVRChatLog(string filePath)
        {
            string rawData      = "";
            var    activityLogs = new List <ActivityLog>();

            using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                using (var sr = new StreamReader(fs, Encoding.GetEncoding("UTF-8")))
                {
                    processingFilePath   = filePath;
                    processingLineNumber = 0;

                    while ((rawData = sr.ReadLine()) != null)
                    {
                        processingLineNumber++;

                        if (rawData.Length > 25 && rawData.Substring(20, 5) == "Error")
                        {
                            continue;
                        }

                        Match match = RegexPatterns.All.Match(rawData);

                        if (!match.Success)
                        {
                            continue;
                        }

                        processingLine = match.Value;

                        if (match.Groups[PatternType.ReceivedInvite].Value.Length != 0)
                        {
                            var m                    = RegexPatterns.ReceivedInviteDetail.Match(match.ToString());
                            var jsonRawData          = m.Groups[2].Value.Replace("{{", "{").Replace("}}", "}");
                            var numCurlyBracketBegin = jsonRawData.Count(c => c == '{');
                            var numCurlyBracketEnd   = jsonRawData.Count(c => c == '}');
                            if (numCurlyBracketBegin > numCurlyBracketEnd)
                            {
                                jsonRawData += new string('}', numCurlyBracketBegin - numCurlyBracketEnd);
                            }
                            dynamic content     = JsonConvert.DeserializeObject(jsonRawData);
                            var     activityLog = new ActivityLog
                            {
                                ActivityType   = ActivityType.ReceivedInvite,
                                Timestamp      = DateTime.Parse(m.Groups[1].Value),
                                NotificationID = content.id,
                                UserID         = content.senderUserId,
                                UserName       = content.senderUsername,
                                WorldID        = content.details.worldId,
                                WorldName      = content.details.worldName,
                            };
                            if (!activityLogs.Where(a => a.NotificationID == activityLog.NotificationID).Any())
                            {
                                activityLogs.Add(activityLog);
                            }
                        }
                        else if (match.Groups[PatternType.ReceivedRequestInvite].Value.Length != 0)
                        {
                            var     m           = RegexPatterns.ReceivedRequestInviteDetail.Match(match.ToString());
                            var     jsonRawData = m.Groups[2].Value.Replace("{{", "{").Replace("}}", "}");
                            dynamic content     = JsonConvert.DeserializeObject(jsonRawData);
                            var     activityLog = new ActivityLog
                            {
                                ActivityType   = ActivityType.ReceivedRequestInvite,
                                Timestamp      = DateTime.Parse(m.Groups[1].Value),
                                NotificationID = content.id,
                                UserID         = content.senderUserId,
                                UserName       = content.senderUsername,
                            };
                            if (!activityLogs.Where(a => a.NotificationID == activityLog.NotificationID).Any())
                            {
                                activityLogs.Add(activityLog);
                            }
                        }
                        else if (match.Groups[PatternType.SendInvite].Value.Length != 0)
                        {
                            var m = RegexPatterns.SendInviteDetail.Match(match.ToString());
                            activityLogs.Add(new ActivityLog
                            {
                                ActivityType = ActivityType.SendInvite,
                                Timestamp    = DateTime.Parse(m.Groups[1].Value),
                                UserID       = m.Groups[2].Value,
                                WorldID      = m.Groups[3].Value,
                                WorldName    = m.Groups[4].Value,
                            });
                        }
                        else if (match.Groups[PatternType.SendRequestInvite].Value.Length != 0)
                        {
                            var m = RegexPatterns.SendRequestInviteDetail.Match(match.ToString());
                            activityLogs.Add(new ActivityLog
                            {
                                ActivityType = ActivityType.SendRequestInvite,
                                Timestamp    = DateTime.Parse(m.Groups[1].Value),
                                UserID       = m.Groups[2].Value,
                            });
                        }
                        else if (match.Groups[PatternType.JoinedRoom1].Value.Length != 0)
                        {
                            var m = RegexPatterns.JoinedRoom1Detail.Match(match.ToString());
                            activityLogs.Add(new ActivityLog
                            {
                                ActivityType = ActivityType.JoinedRoom,
                                Timestamp    = DateTime.Parse(m.Groups[1].Value),
                                WorldID      = m.Groups[2].Value,
                            });
                        }
                        else if (match.Groups[PatternType.JoinedRoom2].Value.Length != 0)
                        {
                            var m = RegexPatterns.JoinedRoom2Detail.Match(match.ToString());
                            if (activityLogs.Any() && activityLogs[activityLogs.Count - 1].ActivityType == ActivityType.JoinedRoom)
                            {
                                activityLogs[activityLogs.Count - 1].WorldName = m.Groups[2].Value;
                            }
                            else
                            {
                                activityLogs.Add(new ActivityLog
                                {
                                    ActivityType = ActivityType.JoinedRoom,
                                    Timestamp    = DateTime.Parse(m.Groups[1].Value),
                                    WorldName    = m.Groups[2].Value,
                                });
                            }
                        }
                        else if (match.Groups[PatternType.MetPlayer].Value.Length != 0)
                        {
                            var m = RegexPatterns.MetPlayerDetail.Match(match.ToString());
                            activityLogs.Add(new ActivityLog
                            {
                                ActivityType = ActivityType.MetPlayer,
                                Timestamp    = DateTime.Parse(m.Groups[1].Value),
                                UserName     = m.Groups[2].Value,
                            });
                        }
                        else if (match.Groups[PatternType.SendFriendRequest].Value.Length != 0)
                        {
                            var m = RegexPatterns.SendFriendRequestDetail.Match(match.ToString());
                            activityLogs.Add(new ActivityLog
                            {
                                ActivityType = ActivityType.SendFriendRequest,
                                Timestamp    = DateTime.Parse(m.Groups[1].Value),
                                UserID       = m.Groups[2].Value,
                            });
                        }
                        else if (match.Groups[PatternType.ReceivedFriendRequest].Value.Length != 0)
                        {
                            var     m           = RegexPatterns.ReceivedFriendRequestDetail.Match(match.ToString());
                            var     jsonRawData = m.Groups[2].Value.Replace("{{", "{").Replace("}}", "}");
                            dynamic content     = JsonConvert.DeserializeObject(jsonRawData);
                            var     activityLog = new ActivityLog
                            {
                                ActivityType   = ActivityType.ReceivedFriendRequest,
                                Timestamp      = DateTime.Parse(m.Groups[1].Value),
                                NotificationID = content.id,
                                UserID         = content.senderUserId,
                                UserName       = content.senderUsername,
                            };
                            if (!activityLogs.Where(a => a.NotificationID == activityLog.NotificationID).Any())
                            {
                                activityLogs.Add(activityLog);
                            }
                        }
                        else if (match.Groups[PatternType.AcceptFriendRequest].Value.Length != 0)
                        {
                            var m = RegexPatterns.AcceptFriendRequestDetail.Match(match.ToString());
                            activityLogs.Add(new ActivityLog
                            {
                                ActivityType   = ActivityType.AcceptFriendRequest,
                                Timestamp      = DateTime.Parse(m.Groups[1].Value),
                                UserName       = m.Groups[2].Value,
                                UserID         = m.Groups[3].Value,
                                NotificationID = m.Groups[4].Value,
                            });
                        }
                        else
                        {
                            continue;
                        }

                        processingLine = string.Empty;
                    }

                    processingLineNumber = 0;
                    processingFilePath   = string.Empty;
                }

            return(activityLogs);
        }
Exemplo n.º 2
0
        /// <summary>
        /// VRChatのログを解析します。
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        private List <ActivityLog> ParseVRChatLog(string filePath)
        {
            string rawData      = "";
            var    activityLogs = new List <ActivityLog>();

            using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                using (var sr = new StreamReader(fs, Encoding.GetEncoding("UTF-8")))
                {
                    processingFilePath   = filePath;
                    processingLineNumber = 0;

                    while ((rawData = sr.ReadLine()) != null)
                    {
                        processingLineNumber++;

                        if (rawData.Length > 25 && rawData.Substring(20, 5) == "Error")
                        {
                            continue;
                        }

                        Match match = RegexPatterns.All.Match(rawData);

                        if (!match.Success)
                        {
                            continue;
                        }

                        processingLine = match.Value;

                        if (match.Groups[PatternType.ReceivedInvite].Value.Length != 0)
                        {
                            var m           = RegexPatterns.ReceivedInviteDetail.Match(match.ToString());
                            var activityLog = new ActivityLog
                            {
                                ActivityType   = ActivityType.ReceivedInvite,
                                Timestamp      = DateTime.Parse(m.Groups[1].Value),
                                NotificationID = m.Groups[4].Value,
                                UserID         = m.Groups[3].Value,
                                UserName       = m.Groups[2].Value,
                                WorldID        = m.Groups[5].Value,
                                WorldName      = m.Groups[6].Value,
                            };

                            if (m.Groups[8].Success)
                            {
                                activityLog.Message = m.Groups[8].Value;
                            }

                            if (m.Groups[10].Success)
                            {
                                activityLog.Url = m.Groups[10].Value;
                            }

                            activityLogs.Add(activityLog);
                        }
                        else if (match.Groups[PatternType.ReceivedRequestInvite].Value.Length != 0)
                        {
                            var m           = RegexPatterns.ReceivedRequestInviteDetail.Match(match.ToString());
                            var activityLog = new ActivityLog
                            {
                                ActivityType   = ActivityType.ReceivedRequestInvite,
                                Timestamp      = DateTime.Parse(m.Groups[1].Value),
                                NotificationID = m.Groups[4].Value,
                                UserID         = m.Groups[3].Value,
                                UserName       = m.Groups[2].Value,
                            };

                            if (m.Groups[6].Success)
                            {
                                activityLog.Message = m.Groups[6].Value;
                            }

                            if (m.Groups[8].Success)
                            {
                                activityLog.Url = m.Groups[8].Value;
                            }

                            activityLogs.Add(activityLog);
                        }
                        else if (match.Groups[PatternType.SendInvite].Value.Length != 0)
                        {
                            var m           = RegexPatterns.SendInviteDetail.Match(match.ToString());
                            var activityLog = new ActivityLog
                            {
                                ActivityType = ActivityType.SendInvite,
                                Timestamp    = DateTime.Parse(m.Groups[1].Value),
                                UserID       = m.Groups[2].Value,
                                WorldID      = m.Groups[3].Value,
                                WorldName    = m.Groups[4].Value,
                            };

                            if (m.Groups[6].Success)
                            {
                                activityLog.Message = m.Groups[6].Value;
                            }

                            activityLogs.Add(activityLog);
                        }
                        else if (match.Groups[PatternType.SendRequestInvite].Value.Length != 0)
                        {
                            var m           = RegexPatterns.SendRequestInviteDetail.Match(match.ToString());
                            var activityLog = new ActivityLog
                            {
                                ActivityType = ActivityType.SendRequestInvite,
                                Timestamp    = DateTime.Parse(m.Groups[1].Value),
                                UserID       = m.Groups[2].Value,
                            };

                            if (m.Groups[3].Success)
                            {
                                activityLog.Message = m.Groups[3].Value;
                            }

                            activityLogs.Add(activityLog);
                        }
                        else if (match.Groups[PatternType.JoinedRoom1].Value.Length != 0)
                        {
                            var m = RegexPatterns.JoinedRoom1Detail.Match(match.ToString());
                            activityLogs.Add(new ActivityLog
                            {
                                ActivityType = ActivityType.JoinedRoom,
                                Timestamp    = DateTime.Parse(m.Groups[1].Value),
                                WorldID      = m.Groups[3].Value,
                            });
                        }
                        else if (match.Groups[PatternType.JoinedRoom2].Value.Length != 0)
                        {
                            var m = RegexPatterns.JoinedRoom2Detail.Match(match.ToString());
                            if (activityLogs.Any() && activityLogs[activityLogs.Count - 1].ActivityType == ActivityType.JoinedRoom)
                            {
                                activityLogs[activityLogs.Count - 1].WorldName = m.Groups[3].Value;
                            }
                            else
                            {
                                activityLogs.Add(new ActivityLog
                                {
                                    ActivityType = ActivityType.JoinedRoom,
                                    Timestamp    = DateTime.Parse(m.Groups[1].Value),
                                    WorldName    = m.Groups[3].Value,
                                });
                            }
                        }
                        else if (match.Groups[PatternType.MetPlayer].Value.Length != 0)
                        {
                            var m = RegexPatterns.MetPlayerDetail.Match(match.ToString());
                            activityLogs.Add(new ActivityLog
                            {
                                ActivityType = ActivityType.MetPlayer,
                                Timestamp    = DateTime.Parse(m.Groups[1].Value),
                                UserName     = m.Groups[3].Value,
                            });
                        }
                        else if (match.Groups[PatternType.SendFriendRequest].Value.Length != 0)
                        {
                            var m = RegexPatterns.SendFriendRequestDetail.Match(match.ToString());
                            activityLogs.Add(new ActivityLog
                            {
                                ActivityType = ActivityType.SendFriendRequest,
                                Timestamp    = DateTime.Parse(m.Groups[1].Value),
                                UserID       = m.Groups[2].Value,
                            });
                        }
                        else if (match.Groups[PatternType.ReceivedFriendRequest].Value.Length != 0)
                        {
                            var m           = RegexPatterns.ReceivedFriendRequestDetail.Match(match.ToString());
                            var activityLog = new ActivityLog
                            {
                                ActivityType   = ActivityType.ReceivedFriendRequest,
                                Timestamp      = DateTime.Parse(m.Groups[1].Value),
                                NotificationID = m.Groups[4].Value,
                                UserID         = m.Groups[3].Value,
                                UserName       = m.Groups[2].Value,
                            };

                            activityLogs.Add(activityLog);
                        }
                        else if (match.Groups[PatternType.AcceptFriendRequest].Value.Length != 0)
                        {
                            var m = RegexPatterns.AcceptFriendRequestDetail.Match(match.ToString());
                            activityLogs.Add(new ActivityLog
                            {
                                ActivityType   = ActivityType.AcceptFriendRequest,
                                Timestamp      = DateTime.Parse(m.Groups[1].Value),
                                UserName       = m.Groups[2].Value,
                                UserID         = m.Groups[3].Value,
                                NotificationID = m.Groups[4].Value,
                            });
                        }
                        else if (match.Groups[PatternType.ReceivedInviteResponse].Value.Length != 0)
                        {
                            var m           = RegexPatterns.ReceivedInviteResponseDetail.Match(match.ToString());
                            var activityLog = new ActivityLog
                            {
                                ActivityType   = ActivityType.ReceivedInviteResponse,
                                Timestamp      = DateTime.Parse(m.Groups[1].Value),
                                NotificationID = m.Groups[4].Value,
                                UserName       = m.Groups[2].Value,
                                UserID         = m.Groups[3].Value,
                            };

                            if (m.Groups[6].Success)
                            {
                                activityLog.Message = m.Groups[6].Value;
                            }

                            if (m.Groups[8].Success)
                            {
                                activityLog.Url = m.Groups[8].Value;
                            }

                            activityLogs.Add(activityLog);
                        }
                        else if (match.Groups[PatternType.ReceivedRequestInviteResponse].Value.Length != 0)
                        {
                            var m           = RegexPatterns.ReceivedRequestInviteResponseDetail.Match(match.ToString());
                            var activityLog = new ActivityLog
                            {
                                ActivityType   = ActivityType.ReceivedRequestInviteResponse,
                                Timestamp      = DateTime.Parse(m.Groups[1].Value),
                                NotificationID = m.Groups[4].Value,
                                UserName       = m.Groups[2].Value,
                                UserID         = m.Groups[3].Value,
                            };

                            if (m.Groups[6].Success)
                            {
                                activityLog.Message = m.Groups[6].Value;
                            }

                            if (m.Groups[8].Success)
                            {
                                activityLog.Url = m.Groups[8].Value;
                            }

                            activityLogs.Add(activityLog);
                        }
                        else
                        {
                            continue;
                        }

                        processingLine = string.Empty;
                    }

                    processingLineNumber = 0;
                    processingFilePath   = string.Empty;
                }

            return(activityLogs);
        }