예제 #1
0
 private void EnsureSaved(Text text)
 {
     if (text.Id == default(long))
     {
         SaveText(text);
     }
 }
예제 #2
0
        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));
        }
예제 #3
0
        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;
        }
예제 #4
0
        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];
        }
예제 #5
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;
        }
예제 #6
0
 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);
 }
예제 #7
0
        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;
        }
예제 #8
0
 private Text InjectRepository(Text text)
 {
     text.TextRepository = this;
     return text;
 }