/// <summary>
        /// Initialises the Azure credentials, batch client and blob client. Asks user for an Azure
        /// licence file and saves the credentials if the credentials have not previously been set.
        /// Once credentials are saved, it starts the job load worker.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void GetCredentials()
        {
            if (AzureCredentialsSetup.CredentialsExist())
            {
                // store credentials
                storageCredentials = StorageCredentials.FromConfiguration();
                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);

                if (!FetchJobs.IsBusy)
                {
                    FetchJobs.RunWorkerAsync();
                }
            }
            else
            {
                // ask user for a credentials file
                AzureCredentialsSetup cred = new AzureCredentialsSetup();
                cred.Finished += (sender, e) => GetCredentials();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initialises the uploader and batch client. Asks user for an Azure licence file and saves the credentials
        /// if the credentials have not previously been set.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GetCredentials(object sender, EventArgs e)
        {
            if (AzureCredentialsSetup.CredentialsExist())
            {
                // store credentials
                storageAuth = StorageCredentials.FromConfiguration();
                batchAuth   = BatchCredentials.FromConfiguration();

                storageAccount = new CloudStorageAccount(new Microsoft.Azure.Storage.Auth.StorageCredentials(storageAuth.Account, storageAuth.Key), true);
                uploader       = new FileUploader(storageAccount);
                var sharedCredentials = new Microsoft.Azure.Batch.Auth.BatchSharedKeyCredentials(batchAuth.Url, batchAuth.Account, batchAuth.Key);
                try
                {
                    batchCli = BatchClient.Open(sharedCredentials);
                }
                catch (UriFormatException)
                {
                    ShowErrorMessage("Error opening Azure Batch client: credentials are invalid.");
                    AzureCredentialsSetup cred = new AzureCredentialsSetup();
                    cred.Finished += GetCredentials;
                }
                catch (Exception ex)
                {
                    ShowError(ex);
                }
            }
            else
            {
                // ask user for a credentials file
                AzureCredentialsSetup cred = new AzureCredentialsSetup();
                cred.Finished += GetCredentials;
            }
        }