Esempio n. 1
0
        /// <summary>
        /// Checks whether an exception was thrown by 'ShuffleHeaven'
        /// and sets the error message given by 'errorMesssage' parameter.
        ///
        /// Call this function after a function is called from 'ShuffleHeaven' that
        /// retrieves a response from Random.org.
        /// </summary>
        /// <param name="errorMessage">The string that lets the user know what is wrong.</param>
        /// <returns></returns>
        private bool HasShuffleHeavenThrownException(string errorMessage)
        {
            bool hasException = ShuffleHeaven.GetExceptionThrown();

            if (hasException)
            {
                labelErrorMessage.Text =
                    "An issue with the connectivity was detected. \r\n" + errorMessage;
                ShowErrorMessage();
            }

            return(hasException);
        }
Esempio n. 2
0
        private void buttonCheckQuota_Click(object sender, EventArgs e)
        {
            ChangeCursor();
            HideOutputScreen();

            ShuffleHeaven.GetUsage();

            if (!HasShuffleHeavenThrownException(ERROR_QUOTA))
            {
                labelBitsLeft.Text     = "Bits Left: " + ShuffleHeaven.GetBitsLeft();
                labelRequestsLeft.Text = "Requests Left: " + ShuffleHeaven.GetRequestsLeft();

                ShowQuota();
            }
        }
Esempio n. 3
0
        /* Event Handlers */



        /*
         * Generates a true or pseudo random number
         * depending on whether the Random.org API Key has been set.
         */
        private void buttonGenerateNumber_Click(object sender, EventArgs e)
        {
            ChangeCursor();
            HideOutputScreen();
            buttonGenerateNumber.Enabled = false; // Lock the button

            List <int> generatedNumbers;
            string     formattedNumbers = String.Empty;



            /* Generates a true or pseudo random number, depending on whether the Random.org API Key is set or not */
            if (settingsForm.IsAPIKeySet())
            {
                generatedNumbers = ShuffleHeaven.GetTrueRandomNumber((int)inputNumberOfNumbers.Value, (int)inputMinRange.Value, (int)inputMaxRange.Value);

                // Shows an error message if 'ShuffleHeaven' throws an exception
                HasShuffleHeavenThrownException(ERROR_NUMBER);
            }
            else
            {
                /* Generates a pseudo random number */
                generatedNumbers = ShuffleHeaven.GeneratePseudoRandomNumber((int)inputNumberOfNumbers.Value, (int)inputMinRange.Value, (int)inputMaxRange.Value);
            }



            formattedNumbers = ConvertListIntsToString(generatedNumbers);

            labelNumberDisplay.Text =
                inputNumberOfNumbers.Value > 1 ?
                "Your random numbers are: " : "Your random number is: " + formattedNumbers;

            labelMultipleNumbers.Text =
                inputNumberOfNumbers.Value > 1 ?
                formattedNumbers : String.Empty;

            ShowNumber();

            AddToLog(formattedNumbers);

            buttonGenerateNumber.Enabled = true; // Unlock the button
        }