public AsyncMessagePersister()
        {
            IUnityContainer container = new UnityContainer().LoadConfiguration("default");
            _messageWriter = container.Resolve<IMessageWriter>
                ("Writer", new ParameterOverrides
                {
                    { "messageFormater",container.Resolve<IMessageFormater>("Formater")}
                });

            _messageWriter.CreateTodaysRepository();
            AddTask();
        }
        private void Processing()
        {
            Interlocked.Increment(ref _numberOfThreads);
            while (!_exit)
            {
                if ((DateTimeProvider.Now - _curDate).Days != 0)
                {
                    _curDate = DateTimeProvider.Now;
                    _messageWriter.CreateTodaysRepository();
                }

                if (_stop && _messages.Count == 0)
                {
                    _exit = true;
                }

                if (_messages.Count <= 0)
                {
                    continue;
                }

                if (_messages.Count > 50 * _numberOfThreads && _numberOfThreads < Environment.ProcessorCount)
                {
                    AddTask();
                }
                if (_messages.Count < 50 * (_numberOfThreads - 1) && _numberOfThreads > 0)
                {
                    DeleteTask();
                }
                IMessage message;
                bool     processed = false;
                while (!_messages.TryDequeue(out message))
                {
                    Thread.Sleep(10);
                }
                try
                {
                    processed = _messageWriter.CreateNewMessageEntry(message);
                    if (processed)
                    {
                        Interlocked.Decrement(ref _numberOfMessages);
                    }
                }
                catch (Exception)
                {
                    if (!processed)
                    {
                        _messages.Enqueue(message);
                    }
                }
            }
        }
        public AsyncMessagePersister()
        {
            IUnityContainer container = new UnityContainer().LoadConfiguration("default");

            _messageWriter = container.Resolve <IMessageWriter>
                                 ("Writer", new ParameterOverrides
            {
                { "messageFormater", container.Resolve <IMessageFormater>("Formater") }
            });


            _messageWriter.CreateTodaysRepository();
            AddTask();
        }
 public AsyncMessagePersister(IMessageWriter messageWriter)
 {
     _messageWriter = messageWriter;
     _messageWriter.CreateTodaysRepository();
     AddTask();
 }
 public AsyncMessagePersister(IMessageWriter messageWriter)
 {
     _messageWriter = messageWriter;
     _messageWriter.CreateTodaysRepository();
     AddTask();
 }