Example #1
0
        public IEnumerable <string> Get()
        {
            IAsyncCursor <BsonDocument> cursor = mongoRepository.GetCollection("Entity").FindSync <BsonDocument>(FilterDefinition <BsonDocument> .Empty);
            List <string> returnVal            = new List <string>();

            while (cursor.MoveNext())
            {
                IEnumerable <BsonDocument> batch = cursor.Current;
                foreach (BsonDocument document in batch)
                {
                    returnVal.Add(document.ToString());
                }
            }

            return(returnVal);
        }
        public EntityProjection(MongoDBRepository projectionRepository)
        {
            When <EntityCreated>(e =>
            {
                if (e.EntityId == null || e.EntityName == null)
                {
                    return;
                }

                projectionRepository.Connect();
                var entityCollection = projectionRepository.GetCollection("Entity");

                var document = new BsonDocument
                {
                    { "Id", e.EntityId.ToString() },
                    { "Name", e.EntityName }
                };

                entityCollection.InsertOne(document);
            });

            When <BasicDetailsAdded>(e =>
            {
                if (e.DateOfBirth == null || e.CountryOfResidence == null)
                {
                    return;
                }

                projectionRepository.Connect();

                var filter           = Builders <BsonDocument> .Filter.Eq("Id", e.EntityId.ToString());
                var entityCollection = projectionRepository.GetCollection("Entity");

                var searchResult = entityCollection.Find(filter);

                if (searchResult.CountDocuments() == 0)
                {
                    return;
                }

                var update = Builders <BsonDocument> .Update
                             .Set("DateOfBirth", e.DateOfBirth)
                             .Set("CountryOfResidence", e.CountryOfResidence);

                entityCollection.UpdateOne(filter, update);
            });
        }
Example #3
0
        Position?GetPosition(Type projection)
        {
            projectionRepository.Connect();

            var projectionStateCollection = projectionRepository.GetCollection("ProjectionState");

            var filter = Builders <BsonDocument> .Filter.Eq("Id", projection.Name);

            var count = projectionStateCollection.Find(filter).CountDocuments();

            if (count == 0)
            {
                return(new Position(0, 0));
            }

            var             stateData = projectionStateCollection.Find(filter).First();
            ProjectionState state     = new ProjectionState();

            state.Id              = stateData.GetValue("Id").ToString();
            state.CommitPosition  = stateData.GetValue("CommitPosition").ToInt64();
            state.PreparePosition = stateData.GetValue("PreparePosition").ToInt64();

            return(new Position(state.CommitPosition, state.PreparePosition));
        }
        public CaseProjection(MongoDBRepository projectionRepository)
        {
            When <CaseInitiated>(e =>
            {
                if (e.CaseId == null)
                {
                    return;
                }

                projectionRepository.Connect();
                var caseCollection = projectionRepository.GetCollection("Case");

                var document = new BsonDocument
                {
                    { "Id", e.CaseId.ToString() },
                    { "EntityId", e.EntityId.ToString() },
                    { "Type", Enum.GetName(typeof(CaseType), e.CaseType) }
                };

                caseCollection.InsertOne(document);
            });
        }