Exemplo n.º 1
0
        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...");
        }
Exemplo n.º 2
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);
            }
        }