コード例 #1
0
 protected async Task EnqueueServiceOperationUpdate(AzureServiceManagementClient serviceClient, string operationId, string refreshToken = null, CloudStorageAccount namespaceAccount = null, string asyncQueueName = null)
 {
     await EnqueueServiceOperationUpdate(serviceClient.SubscriptionId, serviceClient.ServiceName, operationId, refreshToken, namespaceAccount, asyncQueueName);
 }
コード例 #2
0
        static async Task<IEnumerable<Task<string>>> CreateStorageAccounts(AzureServiceManagementClient serviceClient, Configuration newConfig, IEnumerable<StorageAccountCreationInfo> newAccounts)
        {
            string location = await serviceClient.GetServiceLocation();
            return newAccounts
                .Select(accountToCreate =>
                {
                    DashTrace.TraceInformation("Creating storage account: [{0}]", accountToCreate.AccountInfo.AccountName);
                    // Determine if we're blocking or async
                    Func<Task<string>> createTask = accountToCreate.IsBlockingOperation ?
                        (Func<Task<string>>)(() => serviceClient.CreateStorageAccount(accountToCreate.AccountInfo.AccountName, location)) :
                        (Func<Task<string>>)(() => serviceClient.BeginCreateStorageAccount(accountToCreate.AccountInfo.AccountName, location));
                    return createTask()
                        .ContinueWith(antecedent =>
                        {
                            switch (antecedent.Status)
                            {
                                case TaskStatus.RanToCompletion:
                                    string accountKey = accountToCreate.IsBlockingOperation ? antecedent.Result : String.Empty;
                                    if (!accountToCreate.IsBlockingOperation)
                                    {
                                        // Although this isn't a blocking operation, we do have to block until we can retrieve the storage key
                                        try
                                        {
                                            accountKey = serviceClient.GetStorageAccountKey(accountToCreate.AccountInfo.AccountName, 
                                                2500,
                                                new CancellationTokenSource(serviceClient.StorageAccountGetKeysTimeout()).Token).Result;
                                        }
                                        catch (AggregateException ex)
                                        {
                                            throw new OperationCanceledException(
                                                String.Format("Failed to obtain access keys for storage account [{0}]. Details: {1}", 
                                                    accountToCreate.AccountInfo.AccountName, 
                                                    ex.InnerException));
                                        }
                                    }
                                    accountToCreate.AccountInfo.AccountKey = accountKey;
                                    // Update the config
                                    if (!String.IsNullOrWhiteSpace(accountToCreate.ConfigKey))
                                    {
                                        newConfig.AccountSettings[accountToCreate.ConfigKey] = GenerateConnectionString(accountToCreate.AccountInfo);
                                    }
                                    // For async operations return the request id
                                    return accountToCreate.IsBlockingOperation ? String.Empty : antecedent.Result;

                                case TaskStatus.Faulted:
                                    throw new OperationCanceledException(
                                        String.Format("Failed to create storage account [{0}]. Details: {1}",
                                            accountToCreate.AccountInfo.AccountName, 
                                            antecedent.Exception is AggregateException ? antecedent.Exception.InnerException : antecedent.Exception));

                                case TaskStatus.Canceled:
                                    throw new OperationCanceledException(String.Format("Creation of storage account [{0}] was cancelled.", accountToCreate.AccountInfo.AccountKey));

                                default:
                                    System.Diagnostics.Debug.Assert(false);
                                    throw new TaskCanceledException(String.Format("Creation of storage account [{0}] failed in unhandled state [{1}].", accountToCreate.AccountInfo.AccountKey, antecedent.Status));
                            }
                        });
                })
                .ToList();
        }
コード例 #3
0
ファイル: ServiceUpdater.cs プロジェクト: farukc/Dash
        public static async Task<bool> UpdateOperationStatus(AzureServiceManagementClient serviceClient, UpdateConfigStatus.ConfigUpdate operationStatus)
        {
            var response = await serviceClient.GetOperationStatus(operationStatus.CloudServiceUpdateOperationId);
            switch (response.Status)
            {
                case Microsoft.WindowsAzure.OperationStatus.InProgress:
                    break;

                case Microsoft.WindowsAzure.OperationStatus.Failed:
                    if (operationStatus.EndTime == DateTime.MinValue)
                    {
                        operationStatus.EndTime = DateTime.UtcNow;
                    }
                    await operationStatus.UpdateStatus(UpdateConfigStatus.States.Failed, String.Format("Azure service managment failure. {0}:{1}", response.Error.Code, response.Error.Message));
                    break;

                case Microsoft.WindowsAzure.OperationStatus.Succeeded:
                    if (operationStatus.EndTime == DateTime.MinValue)
                    {
                        operationStatus.EndTime = DateTime.UtcNow;
                    }
                    await operationStatus.UpdateStatus(UpdateConfigStatus.States.Completed, "Operation completed successfully");
                    break;
            }
            return response.Status == Microsoft.WindowsAzure.OperationStatus.InProgress;
        }