Ejemplo n.º 1
0
        public MessageModel(string message)
        {
            Poster = new CharacterModel {Name = string.Empty};
            IsHistoryMessage = true;
            Type = message.StartsWith("[")
                ? MessageType.Normal
                : MessageType.Ad;

            Message = message;
        }
Ejemplo n.º 2
0
        public MessageModel(string fullText, Func<string, ICharacter> getCharacter, DateTime dateOfLogs)
        {
            var adSignifier = "[Ad]";
            Poster = new CharacterModel {Name = string.Empty};
            Type = fullText.StartsWith(adSignifier)
                ? MessageType.Ad
                : MessageType.Normal;

            IsHistoryMessage = true;
            Message = fullText;


            var parts = fullText.Split(new[] { ": " }, 2, StringSplitOptions.RemoveEmptyEntries);
            if (parts.Length == 2)
            {
                try
                {
                    var nameBadge = parts[0];
                    var message = parts[1];

                    if (nameBadge.StartsWith(adSignifier)) nameBadge = nameBadge.Substring(adSignifier.Length);

                    var format = DateTimeExtensions.GetTimestampFormat();
                    var nameIdx = nameBadge.IndexOf(format.Trim().Last()) + 1;

                    var name = nameBadge.Substring(nameIdx).Trim();
                    var timeStamp = nameBadge.Substring(0, nameIdx).Trim();


                    // parse our date, and set the date component based on the last write time of the log
                    DateTime parsedDate;
                    if (!DateTime.TryParseExact(timeStamp, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out parsedDate)) return;
                    parsedDate = new DateTime(dateOfLogs.Year, dateOfLogs.Month, dateOfLogs.Day, parsedDate.Hour, parsedDate.Minute, parsedDate.Second);

                    PostedTime = parsedDate;
                    Poster = getCharacter(name);
                    Message = message;
                    IsHistoryMessage = false;
                }
                catch
                {
                }
            }
        }