Пример #1
0
        public static async Task DeleteTableAsync(string connectString, string sessionId, string responseTableName)
        {
            var info = new QueueInfo(sessionId, responseTableName);

            info.ETag = "*"; // no etag cannot delete.
            try
            {
                var table           = GetTableClient(connectString).GetTableReference(queueTableName);
                var deleteOperation = TableOperation.Delete(info);
                await table.ExecuteAsync(deleteOperation);
            }
            catch (Exception e)
            {
                BrokerTracing.TraceError(
                    "[AzureStorageTool] .DeleteTableAsync: Table={0} delete from storage table failed, the exception, {1}",
                    responseTableName,
                    e);
                throw;
            }

            try
            {
                var responseTable = GetTableClient(connectString).GetTableReference(responseTableName);
                await responseTable.DeleteIfExistsAsync();
            }
            catch (Exception e)
            {
                BrokerTracing.TraceError(
                    "[AzureStorageTool] .DeleteTableAsync: Table={0} delete failed, the exception, {1}",
                    responseTableName,
                    e);
                throw;
            }
        }
Пример #2
0
        public static async Task <CloudQueue> CreateQueueAsync(
            string connectString,
            string sessionId,
            string queueName,
            string clientId,
            bool isRequest,
            string note)
        {
            var info = new QueueInfo(sessionId, queueName, clientId, isRequest, note);

            try
            {
                var table = GetTableClient(connectString).GetTableReference(queueTableName);
                await table.CreateIfNotExistsAsync();

                var insertOperation = TableOperation.Insert(info);
                await table.ExecuteAsync(insertOperation);
            }
            catch (Exception e)
            {
                BrokerTracing.TraceError(
                    "[AzureStorageTool] .CreateQueueAsync: queueName={0} create info to table failed, the exception, {1}",
                    queueName,
                    e);
                throw;
            }

            try
            {
                var queue = GetQueueClient(connectString).GetQueueReference(queueName);
                if (await queue.CreateIfNotExistsAsync())
                {
                    return(queue);
                }

                BrokerTracing.TraceWarning(
                    "[AzureStorageTool] .CreateQueueAsync: queueName={0} has existed.",
                    queueName);
                throw new Exception("Queue with the queueName has existed.");
            }
            catch (Exception e)
            {
                BrokerTracing.TraceError(
                    "[AzureStorageTool] .CreateQueueAsync: queueName={0} create queue failed, the exception, {1}",
                    queueName,
                    e);
                throw;
            }
        }
Пример #3
0
        public static async Task <CloudTable> CreateTableAsync(
            string connectString,
            string sessionId,
            string tableName,
            string clientId,
            bool isRequest,
            string note)
        {
            var info = new QueueInfo(sessionId, tableName, clientId, isRequest, note);

            try
            {
                var table = GetTableClient(connectString).GetTableReference(queueTableName);
                await table.CreateIfNotExistsAsync();

                var insertOperation = TableOperation.Insert(info);
                await table.ExecuteAsync(insertOperation);
            }
            catch (Exception e)
            {
                BrokerTracing.TraceError(
                    "[AzureStorageTool] .CreateTableAsync: Table={0} insert info in storage table failed, the exception, {1}",
                    tableName,
                    e);
                throw;
            }

            try
            {
                var responseTable = GetTableClient(connectString).GetTableReference(tableName);
                if (await responseTable.CreateIfNotExistsAsync())
                {
                    return(responseTable);
                }

                throw new Exception("Table with the tableName has existed.");
            }
            catch (Exception e)
            {
                BrokerTracing.TraceError(
                    "[AzureStorageTool] .CreateTableAsync: Table={0} create error, the exception, {1}",
                    tableName,
                    e);
                throw;
            }
        }