private void WriteContactsFromQueue()
        {
            Log.Logger.Debug($"Thread {Thread.CurrentThread.ManagedThreadId} started writing...");
            Contact contact;

            while (CurrentStatus.IsReading() || !CurrentStatus.IsQueueEmpty())
            {
                if (CurrentStatus.TryDequeue(out contact))
                {
                    try
                    {
                        ProcessContact(contact);
                        CurrentStatus.WriteCounterAdd(1);
                    }
                    catch (Exception ex)
                    {
                        HandleException(ex, contact);
                    }
                }
                else
                {
                    // Reader is running behind, give it some time
                    Thread.Sleep(100);
                }
            }

            Log.Logger.Debug($"Thread {Thread.CurrentThread.ManagedThreadId} is done writing...");
        }
Exemple #2
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...");
        }
Exemple #3
0
        private static async Task MainAsync(Arguments arguments)
        {
            try
            {
                List <Task>           executionTasks = new List <Task>();
                XConnectClientFactory readFactory    = new XConnectClientFactory("read");
                Reader reader;
                switch (arguments.CurrentReadMode)
                {
                case Arguments.ReadMode.IdList:
                    Configuration config = readFactory.Configuration;
                    config.IdListFileName = arguments.FileName;
                    reader = new IdListReader(readFactory.BuildClient(), config);
                    break;

                default:
                    reader = new DataExtractionReader(readFactory.BuildClient(true), readFactory.Configuration);
                    break;
                }

                Task readingTask = reader.Start();
                executionTasks.Add(readingTask);

                Writer writer;
                switch (arguments.CurrentWriteMode)
                {
                default:
                    XConnectClientFactory writeFactory = new XConnectClientFactory("write");
                    for (int i = 0; i < Configuration.WriterThreads; i++)
                    {
                        writer = new XConnectWriter(writeFactory.BuildClient(), writeFactory.Configuration);
                        Task writingTask = writer.Start();
                        executionTasks.Add(writingTask);
                    }

                    break;
                }

                while (CurrentStatus.IsReading() || !CurrentStatus.IsQueueEmpty())
                {
                    WriteLine(CurrentStatus.GetStatus(), ConsoleColor.White);
                    Thread.Sleep(5000);
                }

                await Task.WhenAll(executionTasks);
            }
            catch (Exception ex)
            {
                WriteLine($"FATAL: {ex.Message} at {ex.StackTrace}", ConsoleColor.Red);
            }
        }
Exemple #4
0
        protected override async void ReadContacts()
        {
            Log.Logger.Debug("Started reading...");
            IEnumerator <Guid> ids = GetIdsFromFile();

            while (CurrentStatus.IsReading())
            {
                if (CurrentStatus.ContactsQueued < Configuration.MaxQueueSize)
                {
                    await ReadBatch(ids);
                }
                else
                {
                    // Writers are running behind, give them some time
                    Thread.Sleep(100);
                }
            }

            Log.Logger.Debug("Done reading...");
        }