Beispiel #1
0
        protected override async void ReadContacts()
        {
            Log.Logger.Debug("Started reading...");
            IAsyncEntityBatchEnumerator <Contact> cursor =
                await Client.CreateContactEnumerator(GetExpandOptions(), Config.BatchSize);

            while (CurrentStatus.IsReading())
            {
                if (CurrentStatus.ContactsQueued < Configuration.MaxQueueSize)
                {
                    if (await cursor.MoveNext())
                    {
                        foreach (Contact contact in cursor.Current)
                        {
                            CurrentStatus.QueueContact(contact);
                        }

                        CurrentStatus.ReadCounterAdd(1);
                        Log.Logger.Debug($"Read {CurrentStatus.ReadCounter} batches");
                    }
                    else
                    {
                        CurrentStatus.ReadingIsDone();
                    }
                }
                else
                {
                    // Writers are running behind, give them some time
                    Thread.Sleep(100);
                }
            }

            Log.Logger.Debug("Done reading...");
        }
Beispiel #2
0
        private async Task ReadBatch(IEnumerator <Guid> ids)
        {
            List <Guid> batchIds      = new List <Guid>();
            bool        isReadingDone = false;

            for (int i = 0; i < Config.BatchSize; i++)
            {
                if (ids.MoveNext())
                {
                    batchIds.Add(ids.Current);
                }
                else
                {
                    isReadingDone = true;
                }
            }

            ReadOnlyCollection <IEntityLookupResult <Contact> > lookupResults = await Client.GetContactsAsync(batchIds, GetExpandOptions());

            foreach (IEntityLookupResult <Contact> lookupResult in lookupResults)
            {
                if (lookupResult.Exists)
                {
                    CurrentStatus.QueueContact(lookupResult.Entity);
                }
                else
                {
                    Log.Logger.Information($"Contact with id {lookupResult.Reference.Id} was not found!");
                }
            }

            CurrentStatus.ReadCounterAdd(1);
            if (isReadingDone)
            {
                CurrentStatus.ReadingIsDone();
            }

            Log.Logger.Debug($"Read {CurrentStatus.ReadCounter} batches");
        }