public string ReadSection(ImapResponseReader reader)
        {
            var received = 0;
            int size;
            var success = SectionHelper.TryReadResponseLength(reader.CurrentLine, out size);

            if (!success)
            {
                Debug.WriteLine(FailureMessages.ResponseBlockSizeNotDetectedMessage);
                return(string.Empty);
            }

            received += reader.ReadNextLine();
            reader.Client.InvokeDownloadProgressChanged(received, size);

            using (var sw = new StringWriter()) {
                while (true)
                {
                    sw.WriteLine(reader.CurrentLine);
                    reader.ReadNextLine();

                    if (sw.GetStringBuilder().Length == size)
                    {
                        break;
                    }
                }
                return(sw.ToString());
            }
        }
示例#2
0
        public string ReadSection(ImapResponseReader reader)
        {
            var chunkSize = reader.Client.UpdateDownloadProgressTriggerChunkSize.Bytes;
            var trigger   = chunkSize;
            var received  = 0;
            int size;

            var success = SectionHelper.TryReadResponseLength(reader.CurrentLine, out size);

            if (!success)
            {
                Debug.WriteLine(FailureMessages.ResponseBlockSizeNotDetectedMessage);
                return(string.Empty);
            }

            received += reader.ReadNextLine();
            reader.Client.InvokeDownloadProgressChanged(received, size);

            using (var sw = new StringWriter()) {
                var builder = sw.GetStringBuilder();
                while (true)
                {
                    var delta = size - builder.Length;
                    if (delta < reader.CurrentLine.Length)
                    {
                        sw.WriteLine(reader.CurrentLine.Substring(0, delta));
                    }
                    else
                    {
                        sw.WriteLine(reader.CurrentLine);
                    }

                    if (trigger - received < 0)
                    {
                        reader.Client.InvokeDownloadProgressChanged(received, size);
                        trigger += chunkSize;
                    }

                    if (builder.Length >= size)
                    {
                        reader.Client.InvokeDownloadProgressChanged(size, size);
                        break;
                    }

                    if (reader.IsCompleted)
                    {
                        break;
                    }

                    received += reader.ReadNextLine();
                }
                return(sw.ToString());
            }
        }