/// <summary>
        /// remove azure table
        /// </summary>
        /// <param name="name">table name</param>
        /// <returns>
        /// true if the table is removed, false if user cancel the operation,
        /// otherwise throw an exception</returns>
        internal bool RemoveAzureTable(string name)
        {
            if (!NameUtil.IsValidTableName(name))
            {
                throw new ArgumentException(String.Format(Resources.InvalidTableName, name));
            }

            TableRequestOptions requestOptions = null;
            CloudTable          table          = Channel.GetTableReference(name);

            if (!Channel.DoesTableExist(table, requestOptions, OperationContext))
            {
                throw new ResourceNotFoundException(String.Format(Resources.TableNotFound, name));
            }

            if (force || ConfirmRemove(name))
            {
                Channel.Delete(table, requestOptions, OperationContext);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// remove azure table
        /// </summary>
        /// <param name="name">table name</param>
        /// <returns>
        /// true if the table is removed, false if user cancel the operation,
        /// otherwise throw an exception</returns>
        internal bool RemoveAzureTable(string name)
        {
            if (!NameUtil.IsValidTableName(name))
            {
                throw new ArgumentException(String.Format(Resources.InvalidTableName, name));
            }

            TableRequestOptions requestOptions = RequestOptions;
            CloudTable          table          = Channel.GetTableReference(name);

            if (!Channel.DoesTableExist(table, requestOptions, TableOperationContext))
            {
                throw new ResourceNotFoundException(String.Format(Resources.TableNotFound, name));
            }

            if (force || TableIsEmpty(table) || ShouldContinue(string.Format("Remove table and all content in it: {0}", name), ""))
            {
                Channel.Delete(table, requestOptions, TableOperationContext);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #3
0
        /// <summary>
        /// create an azure table
        /// </summary>
        /// <param name="localChannel"></param>
        /// <param name="tableName"></param>
        internal AzureStorageTable CreateAzureTableV2(IStorageTableManagement localChannel, string tableName)
        {
            if (!NameUtil.IsValidTableName(tableName))
            {
                throw new ArgumentException(String.Format(Resources.InvalidTableName, tableName));
            }

            if (!localChannel.CreateTableIfNotExists(tableName, this.CmdletCancellationToken))
            {
                throw new ResourceAlreadyExistException(String.Format(Resources.TableAlreadyExists, tableName));
            }

            return(localChannel.GetAzureStorageTable(tableName));
        }
Exemple #4
0
        /// <summary>
        /// create an azure table
        /// </summary>
        /// <param name="name">An AzureStorageTable object</param>
        internal AzureStorageTable CreateAzureTable(string name)
        {
            if (!NameUtil.IsValidTableName(name))
            {
                throw new ArgumentException(String.Format(Resources.InvalidTableName, name));
            }

            TableRequestOptions requestOptions = RequestOptions;
            CloudTable          table          = Channel.GetTableReference(name);
            bool created = Channel.CreateTableIfNotExists(table, requestOptions, OperationContext);

            if (!created)
            {
                throw new ResourceAlreadyExistException(String.Format(Resources.TableAlreadyExists, name));
            }

            return(new AzureStorageTable(table));
        }
        /// <summary>
        /// list azure tables by table name
        /// </summary>
        /// <param name="name">table name</param>
        /// <returns>An enumerable collection of CloudTable object</returns>
        internal IEnumerable <CloudTable> ListTablesByName(string name)
        {
            TableRequestOptions requestOptions = RequestOptions;
            String prefix = String.Empty;

            if (String.IsNullOrEmpty(name) || WildcardPattern.ContainsWildcardCharacters(name))
            {
                IEnumerable <CloudTable> tables   = Channel.ListTables(prefix, requestOptions, OperationContext);
                WildcardOptions          options  = WildcardOptions.IgnoreCase | WildcardOptions.Compiled;
                WildcardPattern          wildcard = null;

                if (!string.IsNullOrEmpty(name))
                {
                    wildcard = new WildcardPattern(name, options);
                }

                foreach (CloudTable table in tables)
                {
                    if (wildcard == null || wildcard.IsMatch(table.Name))
                    {
                        yield return(table);
                    }
                }
            }
            else
            {
                if (!NameUtil.IsValidTableName(name))
                {
                    throw new ArgumentException(String.Format(Resources.InvalidTableName, name));
                }

                CloudTable table = Channel.GetTableReference(name);

                if (Channel.DoesTableExist(table, requestOptions, OperationContext))
                {
                    yield return(table);
                }
                else
                {
                    throw new ResourceNotFoundException(String.Format(Resources.TableNotFound, name));
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// list azure table clients by full name or simple regular expression
        /// </summary>
        /// <param name="tableName">table name or simple regular expression</param>
        /// <returns></returns>
        internal IEnumerable <AzureStorageTable> ListTablesByNameV2(IStorageTableManagement localChannel, string tableName)
        {
            if (String.IsNullOrEmpty(tableName) || WildcardPattern.ContainsWildcardCharacters(tableName))
            {
                WildcardPattern wildcard = null;
                if (!string.IsNullOrEmpty(tableName))
                {
                    wildcard = new WildcardPattern(tableName, WildcardOptions.IgnoreCase | WildcardOptions.Compiled);
                }

                foreach (AzureStorageTable table in this.ListTablesByQueryV2(localChannel, query: null))
                {
                    if (wildcard == null || wildcard.IsMatch(table.Name))
                    {
                        yield return(table);
                    }
                }
            }
            else
            {
                if (!NameUtil.IsValidTableName(tableName))
                {
                    throw new ArgumentException(String.Format(Resources.InvalidTableName, tableName));
                }

                string query = $"TableName eq '{tableName}'";
                List <AzureStorageTable> tables = this.ListTablesByQueryV2(localChannel, query).ToList();
                if (tables.Count == 0)
                {
                    throw new ResourceNotFoundException(String.Format(Resources.TableNotFound, tableName));
                }

                foreach (AzureStorageTable table in tables)
                {
                    yield return(table);
                }
            }
        }
        /// <summary>
        /// remove azure table
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="tableName">table name</param>
        /// <returns>
        /// true if the table is removed, false if user has cancelled the operation,
        /// otherwise throw an exception</returns>
        internal bool RemoveAzureTableV2(IStorageTableManagement localChannel, string tableName)
        {
            if (!NameUtil.IsValidTableName(tableName))
            {
                throw new ArgumentException(String.Format(Resources.InvalidTableName, tableName));
            }

            // check whether table exists
            bool   exists = false;
            string query  = $"TableName eq '{tableName}'";
            IEnumerable <TableItem> tableItems = localChannel.QueryTables(query, this.CmdletCancellationToken);

            foreach (TableItem tableItem in tableItems)
            {
                exists = true;
                break;
            }

            if (!exists)
            {
                throw new ResourceNotFoundException(String.Format(Resources.TableNotFound, tableName));
            }

            // delete accordingly
            if (force ||
                this.IsTableEmpty(localChannel, tableName, this.CmdletCancellationToken) ||
                ShouldContinue(string.Format("Remove table and all content in it: {0}", tableName), ""))
            {
                localChannel.DeleteTable(tableName, this.CmdletCancellationToken);
                return(true);
            }
            else
            {
                return(false);
            }
        }