Ejemplo n.º 1
0
        private void PostMessage(nntpMessage message)
        {
            var retryCount = 0;
            var retry = true;
            while (retry && retryCount < _configuration.MaxRetryCount)
            {
                try
                {
                    if (_client == null)
                    {
                        log.Debug("Constructing new client.");
                        _client = new SimpleNntpPostingClient(_connectionInfo);
                        _client.Connect();
                    }
                    var partMessageId = _client.PostYEncMessage(
                        _folderConfiguration.FromAddress,
                        message.Subject,
                        message.PostInfo.PostedGroups,
                        message.PostInfo.PostedDateTime,
                        message.Prefix,
                        message.YEncFilePart.EncodedLines,
                        message.Suffix);
                    lock (message.PostInfo.Segments)
                    {
                        message.PostInfo.Segments.Add(new PostedFileSegment
                        {
                            MessageId = partMessageId,
                            Bytes = message.YEncFilePart.Size,
                            SegmentNumber = message.YEncFilePart.Number
                        });
                    }
                    retry = false;
                    OnMessagePosted(message);
                }
                catch (Exception ex)
                {
                    if (_client != null)         //If we get an Exception we close the connection
                    {
                        log.Debug("Disposing client because of exception.");
                        _client.Dispose();
                        _client = null;
                    }
                    log.Warn("Posting yEnc message failed", ex);

                    if (retryCount++ < _configuration.MaxRetryCount)
                        log.InfoFormat("Retrying to post message, attempt {0}", retryCount);
                    else
                        log.Error("Maximum retry attempts reached. Posting is probably corrupt.");
                }
            }
        }
Ejemplo n.º 2
0
 private void PostingTask()
 {
     try
     {
         while (!Finished)
         {
             var message = GetNextMessageToPost();
             if (message != null)
             {
                 PostMessage(message);
             }
             else
             {
                 if (_client != null)         //If the queue runs dry we close the connection
                 {
                     log.Debug("Disposing client because of empty queue.");
                     _client.Dispose();
                     _client = null;
                 }
                 if (StopRequested)
                 {
                     Finished = true;
                 }
                 else
                 {
                     lock (monitor)
                     {
                         if (Finished)
                         {
                             break;
                         }
                         if (StopRequested)
                         {
                             Finished = true;
                             break;
                         }
                         Monitor.Wait(monitor, 100);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         log.Error("Exception in the posting thread.", ex);
     }
 }