public async Task <MessageDataEntity> AddAsync(MessageDataEntity messageData) { await Task.Run(() => File.AppendAllText( _filename, messageData.ToString() + '\n', _encoding)); return(messageData); }
public static MessageDataEntity ParseOrDefault(string line) { MessageDataEntity res = null; try { res = Parse(line); } catch (Exception ex) { res = null; } return(res); }
public async Task <IList <MessageDataEntity> > GetAsync(int limit, CancellationToken token = default) { if (limit < 0) { throw new ArgumentNullException(nameof(limit)); } var lines = await FileHelper.GetStringMessagesAsync(_filename, _encoding, 0, token); Console.WriteLine("readed: {0}", lines.Length); return(lines .Skip(lines.Length <= limit || limit == 0 ? 0 : lines.Length - limit) .Select(l => MessageDataEntity.ParseOrDefault(l)) .Where(m => m != null && m.Text != "Logon" && m.Text != "Logout") .ToArray()); }