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); } } }
public void RunBenchmark() { if (_testRunning) { return; } // The benchmark involves going through each folder of the mailbox if (_service.Url == null) { _logger.Log("Cannot benchmark, EWS failed to initialise"); return; } _conversationIdsToSearch = new Queue <string>(); _stopRequested = false; _testRunning = true; for (int i = 0; i < _testRuns; i++) { _logger.Log(String.Format("Starting test run {0}", i + 1)); Folder rootFolder = TimedFolderBind(WellKnownFolderName.MsgFolderRoot); RecurseFolders(rootFolder); if (_stopRequested) { break; } } if (_folderProcessingThreads > 1) { while (_foldersBeingProcessed > 0) { Thread.Yield(); } } _testRunning = false; // Benchmark has completed, so write the stats to the logger _logger.Log("--------------------------------------------------------------------------"); _logger.Log($"Statistics {_mailbox}"); _logger.Log("--------------------------------------------------------------------------"); _stats.LogStats(_logger); _logger.Log("--------------------------------------------------------------------------"); }
public void LogStats(ClassLogger Logger) { // Write the current stats to the logger foreach (string sStat in _responseTimes.Keys) { try { int iAverage = (int)_responseTimes[sStat].Average(); int iMinimum = (int)_responseTimes[sStat].Min(); int iMaximum = (int)_responseTimes[sStat].Max(); int iTotal = _responseTimes[sStat].Count; Logger.Log(String.Format("{0}: Average {1}ms, Min {2}ms, Max {3}ms, {4} total requests", sStat, iAverage, iMinimum, iMaximum, iTotal)); } catch { } } }