Esempio n. 1
0
        public async Task findNewEventsOnPagesInDb()
        {
            List <string> eventsToFetch = new List <string>();

            //small version of an Event (Light Event) containing just the necessary data fields.
            Dictionary <String, Object> projectionContent = new Dictionary <string, object>()
            {
                { "fbId", 1 }
            };
            ProjectionDefinition <Page, Page> projDefinition = new BsonDocument(projectionContent);

            var collection = pageRepo.GetCollection();

            using (var cursor = await collection.Find(new BsonDocument()).Project(projDefinition).ToCursorAsync()) {
                while (await cursor.MoveNextAsync())
                {
                    var batch = cursor.Current;

                    var parallelOptions = new ParallelOptions {
                        MaxDegreeOfParallelism = 10
                    };
                    Parallel.ForEach(batch, parallelOptions,
                                     page => {
                        parsePageAndCollectEventsToFetch(page.fbId, eventsToFetch);
                    });
                }
            }

            fetchEventsFromEventIdList(eventsToFetch);
        }