/// <summary>
        /// Creates the table if not exist implementation.
        /// </summary>
        /// <param name="tableName">The table name.</param>
        /// <param name="setResult">The set result.</param>
        /// <returns>A sequence of tasks to do the operation.</returns>
        private TaskSequence CreateTableIfNotExistImpl(string tableName, Action <bool> setResult)
        {
            CommonUtils.CheckStringParameter(tableName, false, "tableName", Protocol.Constants.TableServiceMaxStringPropertySizeInChars);
            TableServiceUtilities.CheckTableName(tableName, "tableName");

            var doesTableExistTask = new InvokeTaskSequenceTask <bool>((set) => this.DoesTableExistImpl(tableName, set));

            yield return(doesTableExistTask);

            if (doesTableExistTask.Result)
            {
                setResult(false);
            }
            else
            {
                var createTableTask = TaskImplHelper.GetRetryableAsyncTask <InvalidOperationException>((resultSetter) => this.CreateTableImpl(tableName, resultSetter), RetryPolicy);

                yield return(createTableTask);

                // wrap any exceptions
                try
                {
                    if (createTableTask.Result == null)
                    {
                        setResult(true);
                    }
                    else
                    {
                        StorageClientException exception = Utilities.TranslateDataServiceClientException(createTableTask.Result) as StorageClientException;
                        if (exception != null &&
                            exception.ErrorCode == StorageErrorCode.ResourceAlreadyExists &&
                            exception.ExtendedErrorInformation != null &&
                            exception.ExtendedErrorInformation.ErrorCode == TableErrorCodeStrings.TableAlreadyExists)
                        {
                            setResult(false);
                        }
                        else
                        {
                            throw createTableTask.Result;
                        }
                    }
                }
                catch (InvalidOperationException ex)
                {
                    throw Utilities.TranslateDataServiceClientException(ex);
                }
            }
        }
Exemplo n.º 2
0
        private bool _handleStorageClientException(CloudBlob blob, StorageClientException err)
        {
            switch (err.ErrorCode)
            {
                case StorageErrorCode.ResourceNotFound:
                    blob.UploadText(_lockFile);
                    return true;

                case StorageErrorCode.ContainerNotFound:
                    // container is missing, we should create it.
                    _azureDirectory.BlobContainer.Delete();
                    _azureDirectory.CreateContainer();
                    return true;

                default:
                    return false;
            }
        }
Exemplo n.º 3
0
        private Exception WrapException(StorageClientException ex)
        {
            if (ex.ErrorCode == StorageErrorCode.AccessDenied
              || ex.ErrorCode == StorageErrorCode.AccountNotFound
              || ex.ErrorCode == StorageErrorCode.AuthenticationFailure) {
            return new BlobSecurityException(ex);
              }

              return ex;
        }
 public TestableStorageClientException(StorageClientException ex)
 {
     ErrorCode = ex.ErrorCode;
 }