Example #1
0
File: Utils.cs Project: mo5h/omeo
        /// <summary>
        /// Memory saving replacement for the TextReader.ReadToEnd() method.
        /// </summary>
        public static string StreamReaderReadToEnd(TextReader reader)
        {
            Guard.NullArgument(reader, "reader");

            StringBuilder builder = StringBuilderPool.Alloc();

            try
            {
                int nextChar;
                while ((nextChar = reader.Read()) >= 0)
                {
                    builder.Append((char)nextChar);
                }
                return(builder.ToString());
            }
            finally
            {
                StringBuilderPool.Dispose(builder);
            }
        }
Example #2
0
File: Utils.cs Project: mo5h/omeo
        public static void UpdateHttpStatus(IStatusWriter writer, string name, int bytes)
        {
            IAsyncProcessor ap = Core.UserInterfaceAP;

            if (!ap.IsOwnerThread)
            {
                // update status in UI thread, because size formatting requires that
                ap.QueueJob(JobPriority.Immediate,
                            new UpdateHttpStatusDelegate(UpdateHttpStatus), writer, name, bytes);
            }
            else
            {
                bytes &= ~1023;
                StringBuilder builder = StringBuilderPool.Alloc();
                try
                {
                    builder.Append("Downloading ");
                    builder.Append(name);
                    if (bytes == 0)
                    {
                        builder.Append("...");
                    }
                    else
                    {
                        builder.Append(" (");
                        builder.Append(SizeToString(bytes));
                        builder.Append(')');
                    }
                    writer.ShowStatus(builder.ToString());
                }
                finally
                {
                    StringBuilderPool.Dispose(builder);
                }
            }
        }