private void EnsureSaved(Text text) { if (text.Id == default(long)) { SaveText(text); } }
public Text SaveText(Text text) { if (text == null) throw new ArgumentNullException(nameof(text)); var redisTexts = _redisClient.As<Text>(); text.Id = redisTexts.GetNextSequence(); return InjectRepository(redisTexts.Store(text)); }
public string GetBody(Text text) { if (text == null) throw new ArgumentNullException(nameof(text)); return text.Id != default(long) ? _redisClient.Hashes[TextBodiesHashes][text.Id.ToString()] : null; }
public string[] GetAllWords(Text text) { if (text == null) throw new ArgumentNullException(nameof(text)); return text.Id != default(long) ? _redisClient.Sets[GetWordsSetId(text.Id)].GetAll().ToArray() : new string[0]; }
public void SetBody(Text text, string body) { if (text == null) throw new ArgumentNullException(nameof(text)); if (body == null) throw new ArgumentNullException(nameof(body)); EnsureSaved(text); var bodyHash = _redisClient.Hashes[TextBodiesHashes]; bodyHash[text.Id.ToString()] = body; }
public void SetWords(Text text, IEnumerable<string> words) { if (text == null) throw new ArgumentNullException(nameof(text)); if (words == null) throw new ArgumentNullException(nameof(words)); EnsureSaved(text); var wordsSet = _redisClient.Sets[GetWordsSetId(text.Id)]; words.ForEach(wordsSet.Add); }
public long SaveText(string name, string body, IEnumerable<string> words) { if (name == null) throw new ArgumentNullException(nameof(name)); if (body == null) throw new ArgumentNullException(nameof(body)); if (words == null) throw new ArgumentNullException(nameof(words)); var text = new Text {Name = name, TextRepository = _textRepository}; text.SetBody(body); text.SetWords(words); _textRepository.SaveText(text); return text.Id; }
private Text InjectRepository(Text text) { text.TextRepository = this; return text; }