示例#1
0
        public void PostMessage(nntpMessage message)
        {
            Boolean wait = true;
            while (wait)
            {
                lock (MessagesToPost)
                {
                    if (MessagesToPost.Count <= configuration.MaxConnectionCount * 2)
                    {
                        if (MessagesToPost.Count >= configuration.MaxConnectionCount)
                            StartPostingThreadsIfNotStarted();

                        MessagesToPost.Enqueue(message);
                        wait = false;
                    }
                }
                if (wait)
                {
                    lock (monitor)
                    {
                        if (!wait)
                        {
                            break;
                        }
                        Monitor.Wait(monitor, 1000);
                    }
                }
            }
        }
示例#2
0
 protected virtual void OnMessagePosted(nntpMessage e)
 {
     if (MessagePosted != null)
     {
         MessagePosted(this, e);
     }
 }
示例#3
0
        public void PostMessage(nntpMessage message)
        {
            Boolean wait = true;

            while (wait)
            {
                lock (MessagesToPost)
                {
                    if (MessagesToPost.Count <= configuration.MaxConnectionCount * 2)
                    {
                        if (MessagesToPost.Count >= configuration.MaxConnectionCount)
                        {
                            StartPostingThreadsIfNotStarted();
                        }

                        MessagesToPost.Enqueue(message);
                        wait = false;
                    }
                }
                if (wait)
                {
                    lock (monitor)
                    {
                        if (!wait)
                        {
                            break;
                        }
                        Monitor.Wait(monitor, 1000);
                    }
                }
            }
        }
示例#4
0
        private void PostPart(InntpMessagePoster poster, PostedFileInfo postedFileInfo, YEncFilePart part,
                              String subjectNameBase)
        {
            var message = new nntpMessage();

            message.Subject = String.Format(subjectNameBase, part.Number);

            message.YEncFilePart = part;
            message.PostInfo     = postedFileInfo;

            if (TotalParts > 1)
            {
                message.Prefix.Add(String.Format("=ybegin part={0} total={1} line={2} size={3} name={4}",
                                                 part.Number, TotalParts, configuration.YEncLineSize, File.Length, File.Name));

                message.Prefix.Add(String.Format("=ypart begin={0} end={1}",
                                                 part.Begin, part.End));

                message.Suffix.Add(String.Format("=yend size={0} part={1} pcrc32={2}",
                                                 part.Size, part.Number, part.CRC32));
            }
            else
            {
                message.Prefix.Add(String.Format("=ybegin line={0} size={1} name={2}",
                                                 configuration.YEncLineSize, File.Length, File.Name));

                message.Suffix.Add(String.Format("=yend size={0} crc32={1}",
                                                 File.Length, part.CRC32));
            }

            poster.PostMessage(message);
        }
示例#5
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.DebugFormat("Waiting {0} second(s) before retry.", _configuration.RetryDelaySeconds);
                        Thread.Sleep(new TimeSpan(0, 0, _configuration.RetryDelaySeconds));
                        log.InfoFormat("Retrying to post message, attempt {0}", retryCount);
                    }
                    else
                    {
                        log.Error("Maximum retry attempts reached. Posting is probably corrupt.");
                    }
                }
            }
        }
示例#6
0
 //TODO propagate this further instead of yEnc part? (combine the two ?)
 void postingThread_MessagePosted(object sender, nntpMessage e)
 {
     OnFilePartPosted(e.YEncFilePart);
 }
示例#7
0
 protected virtual void OnMessagePosted(nntpMessage e)
 {
     if (MessagePosted != null) MessagePosted(this, e);
 }
示例#8
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.");
                }
            }
        }
示例#9
0
        private void PostPart(InntpMessagePoster poster, PostedFileInfo postedFileInfo, YEncFilePart part, 
            String subjectNameBase)
        {
            var message = new nntpMessage();
            message.Subject = String.Format(subjectNameBase, part.Number);

            message.YEncFilePart = part;
            message.PostInfo = postedFileInfo;

            if (TotalParts > 1)
            {
                message.Prefix.Add(String.Format("=ybegin part={0} total={1} line={2} size={3} name={4}",
                    part.Number, TotalParts, configuration.YEncLineSize, File.Length, File.Name));

                message.Prefix.Add(String.Format("=ypart begin={0} end={1}",
                    part.Begin, part.End));

                message.Suffix.Add(String.Format("=yend size={0} part={1} pcrc32={2}",
                    part.Size, part.Number, part.CRC32));

            }
            else
            {
                message.Prefix.Add(String.Format("=ybegin line={0} size={1} name={2}",
                    configuration.YEncLineSize, File.Length, File.Name));

                message.Suffix.Add(String.Format("=yend size={0} crc32={1}",
                    File.Length, part.CRC32));
            }

            poster.PostMessage(message);
        }
示例#10
0
 void postingThread_MessagePosted(object sender, nntpMessage e)  //TODO propagate this further instead of yEnc part? (combine the two ?)
 {
     OnFilePartPosted(e.YEncFilePart);
 }