public ClassBenchmark(string Mailbox, ExchangeCredentials Credentials, ClassStats Stats, ClassLogger Logger, string EWSUrl = "")
        {
            _service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
            ServicePointManager.ServerCertificateValidationCallback = ValidateCertificate;
            _service.Credentials = Credentials;
            _mailbox             = Mailbox;
            _stats  = Stats;
            _logger = Logger;
            long startTicks = DateTime.Now.Ticks;

            if (!String.IsNullOrEmpty(EWSUrl))
            {
                _logger.Log($"Using EWS URL: {EWSUrl}");
                _service.Url = new Uri(EWSUrl);
            }
            else
            {
                _logger.Log(String.Format("Performing autodiscover for {0}", Mailbox));
                try
                {
                    _service.AutodiscoverUrl(Mailbox, AutodiscoverCallback);
                }
                catch (Exception ex)
                {
                    _logger.Log(String.Format("Autodiscover failed: {0}", ex.Message));
                }
                finally
                {
                    long endTicks = DateTime.Now.Ticks;
                    Stats.AddStat("Autodiscover", endTicks - startTicks);
                }
            }
        }
 private bool Throttled(Exception ex)
 {
     // Check if we were throttled, and if so, back off for the specified time
     if (ex is ServerBusyException)
     {
         // Need to read BackoffMilliseconds and work out when we can next send data
         _backOffEndTime = DateTime.Now.AddMilliseconds(((ServerBusyException)ex).BackOffMilliseconds);
         _stats.AddStat("Throttled", 1);
         return(true);
     }
     Logger?.Log($"Unexpected error: {ex.Message}");
     return(false);
 }