/// <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);
        }
        /// <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);
        }
        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));
        }
Exemplo n.º 5
0
        internal IAsyncResult BeginBatch(BatchStatement statement, AsyncCallback callback, object state, object tag = null)
        {
            var longActionAc = new AsyncResult <RowSet>(-1, callback, state, this, "SessionBatch", statement, tag);
            var handler      = new BatchRequestHandler()
            {
                Consistency  = statement.ConsistencyLevel ?? _cluster.Configuration.QueryOptions.GetConsistencyLevel(),
                Queries      = statement.Queries,
                BatchType    = statement.BatchType,
                Statement    = statement,
                LongActionAc = longActionAc,
                IsTracing    = statement.IsTracing
            };

            ExecConn(handler, false);
            return(longActionAc);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public BatchRequest(int protocolVersion, BatchStatement statement, ConsistencyLevel consistency)
        {
            ProtocolVersion = protocolVersion;
            if (ProtocolVersion < 2)
            {
                throw new NotSupportedException("Batch request is supported in C* >= 2.0.x");
            }

            var subRequests = new List <IQueryRequest>();

            foreach (var q in statement.Queries)
            {
                subRequests.Add(q.CreateBatchRequest(ProtocolVersion));
            }
            _type       = statement.BatchType;
            _requests   = subRequests;
            Consistency = consistency;
            _timestamp  = statement.Timestamp;
            if (statement.IsTracing)
            {
                _headerFlags = 0x02;
            }
            if (statement.SerialConsistencyLevel != ConsistencyLevel.Any)
            {
                if (protocolVersion < 3)
                {
                    throw new NotSupportedException("Serial consistency level for BATCH request is supported in Cassandra 2.1 or above.");
                }
                if (statement.SerialConsistencyLevel < ConsistencyLevel.Serial)
                {
                    throw new RequestInvalidException("Non-serial consistency specified as a serial one.");
                }
                _batchFlags       |= QueryProtocolOptions.QueryFlags.WithSerialConsistency;
                _serialConsistency = statement.SerialConsistencyLevel;
            }
            if (_timestamp != null)
            {
                if (protocolVersion < 3)
                {
                    throw new NotSupportedException("Timestamp for BATCH request is supported in Cassandra 2.1 or above.");
                }
                _batchFlags |= QueryProtocolOptions.QueryFlags.WithDefaultTimestamp;
            }
        }
Exemplo n.º 8
0
        public BatchRequest(int protocolVersion, BatchStatement statement, ConsistencyLevel consistency)
        {
            ProtocolVersion = protocolVersion;
            if (ProtocolVersion < 2)
            {
                throw new NotSupportedException("Batch request is supported in C* >= 2.0.x");
            }

            var subRequests = new List<IQueryRequest>();
            foreach (var q in statement.Queries)
            {
                subRequests.Add(q.CreateBatchRequest(ProtocolVersion));
            }
            _type = statement.BatchType;
            _requests = subRequests;
            Consistency = consistency;
            _timestamp = statement.Timestamp;
            if (statement.IsTracing)
            {
                _headerFlags = 0x02;
            }
            if (statement.SerialConsistencyLevel != ConsistencyLevel.Any)
            {
                if (protocolVersion < 3)
                {
                    throw new NotSupportedException("Serial consistency level for BATCH request is supported in Cassandra 2.1 or above.");
                }
                if (statement.SerialConsistencyLevel < ConsistencyLevel.Serial)
                {
                    throw new RequestInvalidException("Non-serial consistency specified as a serial one.");
                }
                _batchFlags |= QueryProtocolOptions.QueryFlags.WithSerialConsistency;
                _serialConsistency = statement.SerialConsistencyLevel;
            }
            if (_timestamp != null)
            {
                if (protocolVersion < 3)
                {
                    throw new NotSupportedException("Timestamp for BATCH request is supported in Cassandra 2.1 or above.");
                }
                _batchFlags |= QueryProtocolOptions.QueryFlags.WithDefaultTimestamp;
            }
        }
        /// <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);
        }
        private void DeleteFolder(Guid ownerId, Guid folderId)
        {
            var folderRemove = FOLDER_REMOVE_STMT.Bind(folderId);
            var skelRemove = SKEL_REMOVE_STMT.Bind(ownerId, folderId);
            var versionRemove = FOLDER_VERSION_REMOVE_STMT.Bind(ownerId, folderId);

            var batch = new BatchStatement()
                .Add(folderRemove)
                .Add(skelRemove);

            _session.Execute(batch);
            _session.Execute(versionRemove);
        }
        public void SaveFolder(InventoryFolder folder)
        {
            var skelUpdate = SKEL_UPDATE_STMT.Bind(folder.Name, folder.Type, folder.OwnerId, folder.FolderId);
            var contentUpdate = FOLDER_UPDATE_STMT.Bind(folder.Name, folder.Type, folder.FolderId);

            var batch = new BatchStatement()
                .Add(skelUpdate)
                .Add(contentUpdate);

            _session.Execute(batch);

            VersionInc(folder.OwnerId, folder.FolderId);
        }
        public void PurgeItem(InventoryItem item)
        {
            var removeItem = FOLDER_ITEM_REMOVE_STMT.Bind(item.FolderId, item.ItemId);
            var removeOwnership = ITEM_OWNERSHIP_REMOVE.Bind(item.ItemId);

            var batch = new BatchStatement()
                .Add(removeItem)
                .Add(removeOwnership);

            _session.Execute(batch);

            VersionInc(item.OwnerId, item.FolderId);
        }
        public void MoveItem(InventoryItem item, InventoryFolder parentFolder)
        {
            var insert = FOLDER_ITEM_INSERT_STMT.Bind(parentFolder.FolderId, item.ItemId, item.Name, item.AssetId, item.AssetType,
                item.BasePermissions, item.CreationDate, item.CreatorId, item.CurrentPermissions, item.Description, item.EveryonePermissions,
                item.Flags, item.GroupId, item.GroupOwned, item.GroupPermissions, item.InventoryType, item.NextPermissions,
                item.OwnerId, item.SaleType);

            var removeOld = FOLDER_ITEM_REMOVE_STMT.Bind(item.FolderId, item.ItemId);

            var ownershipUpdate = ITEM_OWNERSHIP_UPDATE.Bind(parentFolder.FolderId, item.ItemId);

            var batch = new BatchStatement()
                .Add(insert)
                .Add(ownershipUpdate)
                .Add(removeOld);

            _session.Execute(batch);

            VersionInc(item.OwnerId, item.FolderId);
            VersionInc(item.OwnerId, parentFolder.FolderId);
        }
        public void CreateItem(InventoryItem item)
        {
            var folderInsert = FOLDER_ITEM_INSERT_STMT.Bind(item.FolderId, item.ItemId, item.Name, item.AssetId, item.AssetType,
                item.BasePermissions, item.CreationDate, item.CreatorId, item.CurrentPermissions, item.Description, item.EveryonePermissions,
                item.Flags, item.GroupId, item.GroupOwned, item.GroupPermissions, item.InventoryType, item.NextPermissions,
                item.OwnerId, item.SaleType);

            var itemOwnership = ITEM_OWNERSHIP_INSERT.Bind(item.ItemId, item.FolderId);

            var batch = new BatchStatement()
                .Add(folderInsert)
                .Add(itemOwnership);

            _session.Execute(batch);

            VersionInc(item.OwnerId, item.FolderId);
        }
        public void CreateFolder(InventoryFolder folder)
        {
            var skelInsert = SKEL_INSERT_STMT.Bind(folder.OwnerId, folder.FolderId, folder.Name, folder.ParentId, folder.Type, (int)folder.Level);
            var contentInsert = FOLDER_ATTRIB_INSERT_STMT.Bind(folder.FolderId, FOLDER_MAGIC_ENTRY, folder.Name, folder.Type, UnixTimeNow(), folder.OwnerId);

            var batch = new BatchStatement()
                .Add(skelInsert)
                .Add(contentInsert);

            _session.Execute(batch);

            VersionInc(folder.OwnerId, folder.FolderId);
        }