/// <summary> /// Constructor. Requires Azure credentials to already be set in ApsimNG.Properties.Settings. /// </summary> /// <param name="id"></param> /// <param name="jobName"></param> /// <param name="path"></param> /// <param name="explorer"></param> /// <param name="export"></param> /// <param name="includeDebugFiles"></param> /// <param name="keepOutputFiles"></param> public AzureResultsDownloader(Guid id, string jobName, string path, AzureJobDisplayPresenter explorer, bool getResults, bool export, bool includeDebugFiles, bool keepOutputFiles, bool unzipResultFiles) { numBlobsComplete = 0; jobId = id; downloadResults = getResults; exportToCsv = export; saveDebugFiles = includeDebugFiles; saveRawOutputFiles = keepOutputFiles; outputPath = path; rawResultsPath = outputPath + "\\" + jobName.ToString() + "_Results"; tempPath = Path.GetTempPath() + "\\" + jobId; progressMutex = new object(); dbMutex = new object(); presenter = explorer; unzipResults = unzipResultFiles; try { // if we need to save files, create a directory under the output directory if ((saveDebugFiles || saveRawOutputFiles || exportToCsv) && !Directory.Exists(rawResultsPath)) { Directory.CreateDirectory(rawResultsPath); } } catch (Exception err) { presenter.ShowError(err); return; } name = jobName; StorageCredentials storageCredentials = StorageCredentials.FromConfiguration(); BatchCredentials batchCredentials = BatchCredentials.FromConfiguration(); storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(storageCredentials.Account, storageCredentials.Key), true); var sharedCredentials = new Microsoft.Azure.Batch.Auth.BatchSharedKeyCredentials(batchCredentials.Url, batchCredentials.Account, batchCredentials.Key); batchClient = BatchClient.Open(sharedCredentials); blobClient = storageAccount.CreateCloudBlobClient(); blobClient.DefaultRequestOptions.RetryPolicy = new Microsoft.WindowsAzure.Storage.RetryPolicies.LinearRetry(TimeSpan.FromSeconds(3), 10); }