WriteException() public static method

public static WriteException ( Exception ex ) : void
ex System.Exception
return void
        /// <summary>
        /// Manage stored access policies specified on the queue
        /// </summary>
        /// <param name="cloudQueueClient"></param>
        /// <returns></returns>
        private static async Task QueueAclSample(CloudQueueClient cloudQueueClient)
        {
            // Create the queue name -- use a guid in the name so it's unique.
            string queueName = "demotest-" + Guid.NewGuid();

            // Create the queue with this name.
            Console.WriteLine("Creating queue with name {0}", queueName);
            CloudQueue queue = cloudQueueClient.GetQueueReference(queueName);

            try
            {
                await queue.CreateIfNotExistsAsync();

                Console.WriteLine("    Queue created successfully.");
            }
            catch (StorageException exStorage)
            {
                Common.WriteException(exStorage);
                Console.WriteLine(
                    "Please make sure your storage account is specified correctly in the app.config - then restart the sample.");
                Console.WriteLine("Press any key to exit");
                Console.ReadLine();
                throw;
            }
            catch (Exception ex)
            {
                Console.WriteLine("    Exception thrown creating queue.");
                Common.WriteException(ex);
                throw;
            }

            // Set queue permissions
            SharedAccessQueuePolicy accessQueuePolicy = new SharedAccessQueuePolicy
            {
                SharedAccessStartTime  = new DateTimeOffset(DateTime.Now),
                SharedAccessExpiryTime = new DateTimeOffset(DateTime.Now.AddMinutes(10)),
                Permissions            = SharedAccessQueuePermissions.Update
            };
            QueuePermissions permissions = new QueuePermissions();

            permissions.SharedAccessPolicies.Add("key1", accessQueuePolicy);
            Console.WriteLine("Set queue permissions");
            await queue.SetPermissionsAsync(permissions);

            // Get queue permissions
            Console.WriteLine("Get queue permissions:");
            permissions = await queue.GetPermissionsAsync();

            foreach (var keyValue in permissions.SharedAccessPolicies)
            {
                Console.WriteLine("  {0}:", keyValue.Key);
                Console.WriteLine("    permissions: {0}:", keyValue.Value.Permissions);
                Console.WriteLine("    start time: {0}:", keyValue.Value.SharedAccessStartTime);
                Console.WriteLine("    expiry time: {0}:", keyValue.Value.SharedAccessExpiryTime);
            }

            // Delete queue
            Console.WriteLine("Deleting queue with name {0}", queueName);
            queue.DeleteIfExists();
        }
        /// <summary>
        /// Create, list and delete queues
        /// </summary>
        /// <param name="cloudQueueClient"></param>
        /// <returns></returns>
        private static async Task ListQueuesSample(CloudQueueClient cloudQueueClient)
        {
            // Create 3 queues.

            // Create the queue name -- use a guid in the name so it's unique.
            string baseQueueName = "demotest-" + System.Guid.NewGuid().ToString();

            // Keep a list of the queues so you can compare this list
            //   against the list of queues that we retrieve.
            List <string> queueNames = new List <string>();

            for (int i = 0; i < 3; i++)
            {
                // Set the name of the queue, then add it to the generic list.
                string queueName = baseQueueName + "-0" + i;
                queueNames.Add(queueName);

                // Create the queue with this name.
                Console.WriteLine("Creating queue with name {0}", queueName);
                CloudQueue cloudQueue = cloudQueueClient.GetQueueReference(queueName);
                try
                {
                    await cloudQueue.CreateIfNotExistsAsync();

                    Console.WriteLine("    Queue created successfully.");
                }
                catch (StorageException exStorage)
                {
                    Common.WriteException(exStorage);
                    Console.WriteLine(
                        "Please make sure your storage account is specified correctly in the app.config - then restart the sample.");
                    Console.WriteLine("Press any key to exit");
                    Console.ReadLine();
                    throw;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("    Exception thrown creating queue.");
                    Common.WriteException(ex);
                    throw;
                }
            }

            Console.WriteLine(string.Empty);
            Console.WriteLine("List of queues in the storage account:");

            // List the queues for this storage account
            QueueContinuationToken token          = null;
            List <CloudQueue>      cloudQueueList = new List <CloudQueue>();

            do
            {
                QueueResultSegment segment = await cloudQueueClient.ListQueuesSegmentedAsync(baseQueueName, token);

                token = segment.ContinuationToken;
                cloudQueueList.AddRange(segment.Results);
            }while (token != null);

            try
            {
                foreach (CloudQueue cloudQ in cloudQueueList)
                {
                    Console.WriteLine("Cloud Queue name = {0}", cloudQ.Name);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("    Exception thrown listing queues.");
                Common.WriteException(ex);
                throw;
            }

            // Now clean up after yourself, using the list of queues that you created in case there were other queues in the account.
            foreach (string oneQueueName in queueNames)
            {
                CloudQueue cloudQueue = cloudQueueClient.GetQueueReference(oneQueueName);
                cloudQueue.DeleteIfExists();
            }
        }
        /// <summary>
        /// Test some of the queue storage operations.
        /// </summary>
        public async Task RunQueueStorageAdvancedOpsAsync()
        {
            try
            {
                //***** Setup *****//
                Console.WriteLine("Getting reference to the storage account.");

                // Retrieve storage account information from connection string
                // How to create a storage connection string - http://msdn.microsoft.com/en-us/library/azure/ee758697.aspx
                CloudStorageAccount storageAccount = Common.CreateStorageAccountFromConnectionString(CloudConfigurationManager.GetSetting("StorageConnectionString"));

                Console.WriteLine("Instantiating queue client.");
                Console.WriteLine(string.Empty);

                // Create a queue client for interacting with the queue service.
                CloudQueueClient cloudQueueClient = storageAccount.CreateCloudQueueClient();

                // Create 3 queues.

                // Create the queue name -- use a guid in the name so it's unique.
                string baseQueueName = "demotest-" + System.Guid.NewGuid().ToString();

                // Keep a list of the queues so you can compare this list
                //   against the list of queues that we retrieve.
                List <string> queueNames = new List <string>();

                for (int i = 0; i < 3; i++)
                {
                    // Set the name of the queue, then add it to the generic list.
                    string queueName = baseQueueName + "-0" + i;
                    queueNames.Add(queueName);

                    // Create the queue with this name.
                    Console.WriteLine("Creating queue with name {0}", queueName);
                    CloudQueue cloudQueue = cloudQueueClient.GetQueueReference(queueName);
                    try
                    {
                        await cloudQueue.CreateIfNotExistsAsync();

                        Console.WriteLine("    Queue created successfully.");
                    }
                    catch (StorageException exStorage)
                    {
                        Common.WriteException(exStorage);
                        Console.WriteLine("Please make sure your storage account is specified correctly in the app.config - then restart the sample.");
                        Console.WriteLine("Press any key to exit");
                        Console.ReadLine();
                        throw;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("    Exception thrown creating queue.");
                        Common.WriteException(ex);
                        throw;
                    }
                }

                Console.WriteLine(string.Empty);
                Console.WriteLine("List of queues in the storage account:");

                // List the queues for this storage account
                IEnumerable <CloudQueue> cloudQueueList = cloudQueueClient.ListQueues();
                try
                {
                    foreach (CloudQueue cloudQ in cloudQueueList)
                    {
                        Console.WriteLine("Cloud Queue name = {0}", cloudQ.Name);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("    Exception thrown listing queues.");
                    Common.WriteException(ex);
                    throw;
                }

                // Now clean up after yourself, using the list of queues that you created in case there were other queues in the account.
                foreach (string oneQueueName in queueNames)
                {
                    CloudQueue cloudQueue = cloudQueueClient.GetQueueReference(oneQueueName);
                    cloudQueue.DeleteIfExists();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("    Exception thrown. Message = {0}{1}    Strack Trace = {2}", ex.Message, Environment.NewLine, ex.StackTrace);
            }
        }