/// <summary>
        /// Submits an uploaded video to the catalog.
        /// </summary>
        public async Task SubmitUploadedVideo(SubmitUploadedVideo uploadedVideo)
        {
            var timestamp = DateTimeOffset.UtcNow;

            // Store the information we have now in Cassandra
            PreparedStatement[] prepared = await _statementCache.NoContext.GetOrAddAllAsync(
                "INSERT INTO videos (videoid, userid, name, description, tags, location_type, added_date) VALUES (?, ?, ?, ?, ?, ?, ?) USING TIMESTAMP ?",
                "INSERT INTO user_videos (userid, added_date, videoid, name) VALUES (?, ?, ?, ?) USING TIMESTAMP ?"
            );

            var batch = new BatchStatement();

            batch.Add(prepared[0].Bind(uploadedVideo.VideoId, uploadedVideo.UserId, uploadedVideo.Name, uploadedVideo.Description,
                                       uploadedVideo.Tags, VideoCatalogConstants.UploadedVideoType, timestamp,
                                       timestamp.ToMicrosecondsSinceEpoch()));
            batch.Add(prepared[1].Bind(uploadedVideo.UserId, timestamp, uploadedVideo.VideoId, uploadedVideo.Name,
                                       timestamp.ToMicrosecondsSinceEpoch()));

            await _session.ExecuteAsync(batch).ConfigureAwait(false);

            // Tell the world we've accepted an uploaded video (it hasn't officially been added until we get a location for the
            // video playback and thumbnail)
            await _bus.Publish(new UploadedVideoAccepted
            {
                VideoId = uploadedVideo.VideoId,
                UploadUrl = uploadedVideo.UploadUrl,
                Timestamp = timestamp
            }).ConfigureAwait(false);
        }
        /// <summary>
        /// Records a user comment on a video.
        /// </summary>
        public async Task CommentOnVideo(CommentOnVideo comment)
        {
            // Use a client side timestamp for the writes that we can include when we publish the event
            var timestamp = DateTimeOffset.UtcNow;

            PreparedStatement[] preparedStatements = await _statementCache.NoContext.GetOrAddAllAsync(
                "INSERT INTO comments_by_video (videoid, commentid, userid, comment) VALUES (?, ?, ?, ?) USING TIMESTAMP ?",
                "INSERT INTO comments_by_user (userid, commentid, videoid, comment) VALUES (?, ?, ?, ?) USING TIMESTAMP ?");

            // Use a batch to insert into all tables
            var batch = new BatchStatement();

            // INSERT INTO comments_by_video
            batch.Add(preparedStatements[0].Bind(comment.VideoId, comment.CommentId, comment.UserId, comment.Comment,
                                                 timestamp.ToMicrosecondsSinceEpoch()));

            // INSERT INTO comments_by_user
            batch.Add(preparedStatements[1].Bind(comment.UserId, comment.CommentId, comment.VideoId, comment.Comment,
                                                 timestamp.ToMicrosecondsSinceEpoch()));

            await _session.ExecuteAsync(batch).ConfigureAwait(false);

            // Tell the world about the comment
            await _bus.Publish(new UserCommentedOnVideo
            {
                UserId = comment.UserId,
                VideoId = comment.VideoId,
                CommentId = comment.CommentId,
                Timestamp = timestamp
            }).ConfigureAwait(false);
        }
Пример #3
0
        public void AddTopic(Guid topicId, string title, string body)
        {
            //We will be inserting 2 rows in 2 column families.
            //One for the topic and other for the first message (the topic body).
            //We will do it in a batch, this way we can ensure that the 2 rows are inserted in the same atomic operation.
            var batch = new BatchStatement();

            //bind the parameters on each statement and add them to the batch
            batch.Add(_insertTopicStatement.Bind(topicId, title, DateTime.Now));
            batch.Add(_insertMessageStatement.Bind(topicId, DateTime.Now, body));

            //You can set other options of the batch execution, for example the consistency level.
            batch.SetConsistencyLevel(ConsistencyLevel.Quorum);
            //Execute the insert of the 2 rows
            Session.Execute(batch);
        }
        public static void pushToDataStore(String metaData, String rawFile, String jointdata2d, String angleData)
        {
            Cluster cluster = Cluster.Builder().AddContactPoint("127.0.0.1").Build();
            ISession session = cluster.Connect("kinectproject");

            var insertStatement = session.Prepare("insert into basickinectdatastore (id, metadata, rawdata, jointdata2d, angledata) values(?,?,?,?,?)");
            var batch = new BatchStatement();
            batch.Add(insertStatement.Bind(System.Guid.NewGuid(), metaData, rawFile, jointdata2d, angleData));
            // Insert Job
            session.Execute(batch);
        }
        public Task AddAsync(string groupId, SignalType signal, long version, List<AffinityGroupMostSignaledInsertOptions> options)
        {
            string rowKey = BuildRowKey(groupId, signal, version);

            var batch = new BatchStatement();
            foreach (var option in options)
            {
                BoundStatement boundStatement = _insertStatement.Value.Bind(rowKey, option.Count, option.ItemId);
                batch.Add(boundStatement);
            }

            return _session.Get().ExecuteAsync(batch.SetConsistencyLevel(ConsistencyLevel.One));
        }
        /// <summary>
        /// Submits a YouTube video to the catalog.
        /// </summary>
        public async Task SubmitYouTubeVideo(SubmitYouTubeVideo youTubeVideo)
        {
            // Use a batch to insert the YouTube video into multiple tables
            PreparedStatement[] prepared = await _statementCache.NoContext.GetOrAddAllAsync(
                "INSERT INTO videos (videoid, userid, name, description, location, preview_image_location, tags, added_date, location_type) " +
                "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) USING TIMESTAMP ?",
                "INSERT INTO user_videos (userid, added_date, videoid, name, preview_image_location) VALUES (?, ?, ?, ?, ?) USING TIMESTAMP ?",
                "INSERT INTO latest_videos (yyyymmdd, added_date, videoid, userid, name, preview_image_location) VALUES (?, ?, ?, ?, ?, ?) USING TIMESTAMP ? AND TTL ?");

            // Calculate date-related info and location/thumbnail for YouTube video
            var addDate = DateTimeOffset.UtcNow;
            string yyyymmdd = addDate.ToString("yyyyMMdd");

            string location = youTubeVideo.YouTubeVideoId;      // TODO: Store URL instead of ID?
            string previewImageLocation = string.Format("//img.youtube.com/vi/{0}/hqdefault.jpg", youTubeVideo.YouTubeVideoId);

            var batch = new BatchStatement();
            batch.Add(prepared[0].Bind(youTubeVideo.VideoId, youTubeVideo.UserId, youTubeVideo.Name, youTubeVideo.Description, location,
                                       previewImageLocation, youTubeVideo.Tags, addDate, VideoCatalogConstants.YouTubeVideoType,
                                       addDate.ToMicrosecondsSinceEpoch()));
            batch.Add(prepared[1].Bind(youTubeVideo.UserId, addDate, youTubeVideo.VideoId, youTubeVideo.Name, previewImageLocation,
                                       addDate.ToMicrosecondsSinceEpoch()));
            batch.Add(prepared[2].Bind(yyyymmdd, addDate, youTubeVideo.VideoId, youTubeVideo.UserId, youTubeVideo.Name, previewImageLocation,
                                       addDate.ToMicrosecondsSinceEpoch(), VideoCatalogConstants.LatestVideosTtlSeconds));
            
            // Send the batch to Cassandra
            await _session.ExecuteAsync(batch).ConfigureAwait(false);

            // Tell the world about the new YouTube video
            await _bus.Publish(new YouTubeVideoAdded
            {
                VideoId = youTubeVideo.VideoId,
                UserId = youTubeVideo.UserId,
                Name = youTubeVideo.Name,
                Description = youTubeVideo.Description,
                Location = location,
                PreviewImageLocation = previewImageLocation,
                Tags = youTubeVideo.Tags,
                AddedDate = addDate,
                Timestamp = addDate
            }).ConfigureAwait(false);
        }