ShoutLib.Shouter.ShoutString C# (CSharp) Method

ShoutString() private method

Converts a string from lowercase to uppercase, taking an extra long time. During that time, it periodically calls testCancel so that the caller can abort the operation if it's taking too long.
private ShoutString ( string text, ThrowIfAborted throwIfAborted ) : string
text string
throwIfAborted ThrowIfAborted
return string
        private string ShoutString(string text, ThrowIfAborted throwIfAborted)
        {
            string upperText = text.ToUpper();

            // Pretend like we're working hard and taking time.  Time is a function of
            // the number of letters in the word.
            var workDeadline = DateTime.UtcNow + TimeSpan.FromSeconds(
                 upperText.Length * (int)Math.Log(upperText.Length));
            var oneSecond = TimeSpan.FromSeconds(1);
            while (workDeadline > DateTime.UtcNow)
            {
                throwIfAborted();
                System.Threading.Thread.Sleep(oneSecond);
            }

            // Simulate different kinds of errors depending on text.
            if (upperText.Contains("CHICKEN"))
            {
                // Simulate a fatal error that cannot possible be handled.
                throw new FatalException("Oh no!  Not chickens!");
            }
            if (upperText.Contains("CORN"))
            {
                // Simulate a flaky error that happens sometimes, but not always.
                if (_init.Random.Next(3) > 0)
                    throw new CornException();
            }
            if (upperText.Contains("COW"))
            {
                // Simulate an error that eventually times out with error.
                throw new CowException();
            }
            return upperText;
        }