Пример #1
0
        public void Add(User user)
        {
            using (var db = new CassandraContextFactory().Get())
             	{
             		var family = db.GetColumnFamily<UTF8Type>("users");

             		dynamic record = family.CreateRecord(user.Id);
             		record.username = user.Username;

                db.Attach(record);
                db.SaveChanges();
             	}
        }
Пример #2
0
        public void Create(Tweet tweet)
        {
            using (var db = new CassandraContextFactory().Get())
            {
                var family = db.GetColumnFamily("tweets");

                var tweetId = Guid.NewGuid();
                dynamic record = family.CreateRecord(tweetId);
                record.userid = tweet.UserId;
                record.text = tweet.Text;
                record.date = tweet.Date;

                Regex reg = new Regex(@"((mailto\:|(news|(ht|f)tp(s?))\://){1}\S+)");
                var match = reg.Match(tweet.Text);
                if (match.Success)
                {
                    string url = match.Value;
                    var urlFamily = db.GetColumnFamily("urls");

                    var urlRow = urlFamily.CreateRecord(url);
                    urlRow.TrySetColumn(tweet.UserId, tweetId);

                    db.Attach(urlRow);

                    var userUrlFamily = db.GetSuperColumnFamily("user_urls");
                    dynamic userUrlRow = userUrlFamily.CreateRecord(tweet.UserId);
                    db.Attach(userUrlRow);

                    var superColumn = userUrlRow.CreateSuperColumn();
                    superColumn.TrySetColumn(tweetId, "");

                    userUrlRow[url] = superColumn;
                }

                db.Attach(record);
                db.SaveChanges();
            }
        }