/// <summary>
        /// Downloads the diagnostic data for the given test run
        /// </summary>
        /// <param name="testRunId"></param>
        internal static void DownloadDiagnosticData(string testRunId)
        {
            var testResults = CltWebApi.GetTestRunResults(testRunId);

            if (string.IsNullOrWhiteSpace(testResults.ResultsUrl))
            {
                Logger.LogMessage("No result available for run " + testRunId);
            }
            else
            {
                Logger.LogMessage("Downloading diagnostic data for run from uri: {0}", testResults.Diagnostics.DiagnosticStoreConnectionString);
                var resultFilePath = CltUploadDownloadHelper.DownloadDiagnosticData(testResults.Diagnostics.DiagnosticStoreConnectionString, testResults.Diagnostics.RelativePathToDiagnosticFiles);
                Logger.LogMessage("File location: {0}", Path.Combine(resultFilePath, testRunId));
            }
        }
        /// <summary>
        /// Creates a test run, uploads the load test sources and starts the run.
        /// </summary>
        /// <param name="localDirectory">the directory containing the test sources</param>
        /// <param name="loadTestFileName">the loadtest file name of the loadtest</param>
        /// <returns></returns>
        public static TestRun CreateAndStartRun(string localDirectory, string loadTestFileName)
        {
            //check for extension
            if (!Path.HasExtension(loadTestFileName))
            {
                loadTestFileName = string.Concat(loadTestFileName, ".loadtest");
                Logger.LogMessage("Appending .loadtest to the given loadtest name");
            }
            //check if load test file exists in test drop
            if (!File.Exists(Path.Combine(localDirectory, loadTestFileName)))
            {
                Logger.LogMessage(string.Format(CultureInfo.CurrentCulture, "LoadTest file not found in the test drop. Please ensure that the loadtest file is present in the drop and the correct name is provided. Also please ensure the test drop has all binaries and other files needed to run your test."));
                return(null);
            }
            // Create test drop
            Logger.LogMessage("Creating TestDrop....");
            var testDrop = CltWebApi.CreateTestDrop();

            Logger.LogMessage("Done. TestDropId = {0}", testDrop.Id);

            // Upload test files
            Logger.LogMessage("Uploading test sources....");
            CltUploadDownloadHelper.Upload(localDirectory, testDrop);
            Logger.LogMessage("Done");

            TestRun testRun     = CltObjectFactory.CreateTestRunObject(loadTestFileName);
            var     testDropRef = new TestDropRef();

            testRun.TestDrop     = testDropRef;
            testRun.TestDrop.Id  = testDrop.Id;
            testRun.TestSettings = CltObjectFactory.CreateTestSettingsObject();

            // Create testrun
            Logger.LogMessage("Creating test run....");
            var createdTestRun = CltWebApi.CreateTestRun(testRun);

            Logger.LogMessage("Done.");

            // Start test run
            Logger.LogMessage("Starting test run....");
            CltWebApi.StartTestRun(createdTestRun.Id);
            Logger.LogMessage("Done");

            // Print test run state
            return(CltWebApi.GetTestRun(createdTestRun.Id));
        }
        /// <summary>
        /// Downloads the result for the given test run, decompresses it to an ltrar file
        /// </summary>
        /// <param name="testRunId"></param>
        internal static void DownloadResult(string testRunId)
        {
            var testResults = CltWebApi.GetTestRunResults(testRunId);

            if (string.IsNullOrWhiteSpace(testResults.ResultsUrl))
            {
                Logger.LogMessage("No result available for run " + testRunId);
            }
            else
            {
                Logger.LogMessage("Downloading result file from uri: {0}", testResults.ResultsUrl);
                var resultFilePath = CltUploadDownloadHelper.DownloadResult(testResults.ResultsUrl);
                Logger.LogMessage("File location: {0}", resultFilePath);
                Console.WriteLine("Decompressing result.");
                var ltrarFilePath = CltUploadDownloadHelper.DecompressResult(resultFilePath);
                Logger.LogMessage("Ltrar file location: {0}", ltrarFilePath);
            }
        }