public IUpdateStream <TDocument> Subscribe(UpdateStreamFilter updateStreamFilter, CancellationToken cancellationToken = default) { var updateStream = new UpdateStream <TDocument>(); PipelineDefinition <ChangeStreamDocument <TDocument>, ChangeStreamDocument <TDocument> > pipeline = new EmptyPipelineDefinition <ChangeStreamDocument <TDocument> >(); pipeline = pipeline.Match(x => x.OperationType == ChangeStreamOperationType.Update && updateStreamFilter.UpdateTypes.HasFlag(UpdateTypes.Update) || x.OperationType == ChangeStreamOperationType.Insert && updateStreamFilter.UpdateTypes.HasFlag(UpdateTypes.Insert) || x.OperationType == ChangeStreamOperationType.Delete && updateStreamFilter.UpdateTypes.HasFlag(UpdateTypes.Delete) || x.OperationType == ChangeStreamOperationType.Replace && updateStreamFilter.UpdateTypes.HasFlag(UpdateTypes.Replace) || updateStreamFilter.UpdateTypes == UpdateTypes.Undefined ); if (updateStreamFilter.RtId.HasValue) { var filter = Builders <ChangeStreamDocument <TDocument> > .Filter.Eq("fullDocument." + Constants.IdField, updateStreamFilter.RtId.Value.ToObjectId()); pipeline = pipeline.Match(filter); } updateStream.Watch(_documentCollection, pipeline, cancellationToken); return(updateStream); }
private IObservable <object> Subscribe(IResolveEventStreamContext context) { var messageHandlingContext = (MessageHandlingContext)context.UserContext; var tenantContext = messageHandlingContext.Get <ITenantContext>(Statics.TenantContext); var ckId = context.FieldDefinition.GetMetadata <string>(Statics.CkId); var rtId = context.GetArgument <OspObjectId?>(Statics.RtIdArg, null); var updateTypeDtoList = context.GetArgument <ICollection <UpdateTypesDto> >(Statics.UpdateTypesArg); UpdateTypes updateType = UpdateTypes.Undefined; foreach (var updateTypeDto in updateTypeDtoList) { updateType |= (UpdateTypes)updateTypeDto; } var updateStreamFilter = new UpdateStreamFilter { UpdateTypes = updateType, RtId = rtId }; var messages = tenantContext.Repository.SubscribeToRtEntities(ckId, updateStreamFilter, context.CancellationToken); var observable = messages.GetUpdates().Select(x => new DynamicUpdateMessageDto <RtEntityUpdateItemDto> { Items = new List <RtEntityUpdateItemDto> { new RtEntityUpdateItemDto { UserContext = x.Document, UpdateState = (UpdateTypesDto)x.UpdateType } } }); return(observable); }