Esempio n. 1
0
        /// <summary>
        /// list azure table clients by query
        /// </summary>
        /// <param name="localChannel"></param>
        /// <param name="query">table query string</param>
        /// <returns></returns>
        internal IEnumerable <AzureStorageTable> ListTablesByQueryV2(IStorageTableManagement localChannel, string query)
        {
            IEnumerable <TableItem> tableItems = localChannel.QueryTables(query, this.CmdletCancellationToken);

            foreach (TableItem tableItem in tableItems)
            {
                yield return(localChannel.GetAzureStorageTable(tableItem.Name));
            }
        }
        /// <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);
            }
        }