コード例 #1
0
        public void CloudQueueClientListQueuesBasic()
        {
            string        prefix     = "dotnetqueuetest" + Guid.NewGuid().ToString("N");
            List <string> queueNames = new List <string>();
            int           count      = 30;

            for (int i = 0; i < count; i++)
            {
                queueNames.Add(prefix + i);
            }

            CloudQueueClient  client       = GenerateCloudQueueClient();
            List <CloudQueue> emptyResults = client.ListQueues(prefix, QueueListingDetails.All, null, null).ToList();

            Assert.AreEqual <int>(0, emptyResults.Count);

            foreach (string name in queueNames)
            {
                client.GetQueueReference(name).Create();
            }

            List <CloudQueue> results = client.ListQueues(prefix, QueueListingDetails.All, null, null).ToList();

            Assert.AreEqual <int>(results.Count, queueNames.Count);

            foreach (CloudQueue queue in results)
            {
                if (queueNames.Remove(queue.Name))
                {
                    queue.Delete();
                }
                else
                {
                    Assert.Fail();
                }
            }

            Assert.AreEqual <int>(0, queueNames.Count);
        }
コード例 #2
0
    private void CreateMissingQueues(CloudQueueClient cloudQueueClient)
    {
        var shards = cloudQueueClient.ListQueues()
            .Where(q => q.Name.StartsWith(queueName, StringComparison.InvariantCulture))
            .Select(q => q.Name);

        var queueNames = Enumerable.Range(0, queueCount)
            .Select(i => queueName + i)
            .Where(n => !shards.Contains(n))
            .ToList();

        foreach (var name in queueNames)
        {
            var q = cloudQueueClient.GetQueueReference(name);
            q.CreateIfNotExists();
        }
    }
コード例 #3
0
        //******************
        //*                *
        //*  LoadLeftPane  *
        //*                *
        //******************
        // Load a list of storage containers/queues/tables into the left pane of the storage view.

        public void LoadLeftPane()
        {
            Cursor = Cursors.Wait;

            NewAction();

            AccountTitle.Text = Account.Name;

            ClearMainPane();

            TreeViewItem blobSection = new TreeViewItem()
            {
                Header = "Blob Containers",
                Tag = new OutlineItem()
                {
                    ItemType = ItemType.BLOB_SERVICE /* 100 */,
                    Container = null
                }
            };

            TreeViewItem queueSection = new TreeViewItem()
            {
                Header = "Queues",
                Tag = new OutlineItem()
                {
                    ItemType = ItemType.QUEUE_SERVICE /* 200 */,
                    Container = null
                }
            };

            TreeViewItem tableSection = new TreeViewItem()
            {
                Header = "Tables",
                Tag = new OutlineItem()
                {
                    ItemType = ItemType.TABLE_SERVICE /* 300 */,
                    Container = null
                }
            };

            AccountTreeView.Items.Clear();

            AccountTreeView.Items.Add(blobSection);
            AccountTreeView.Items.Add(queueSection);
            AccountTreeView.Items.Add(tableSection);

            CloudStorageAccount account = OpenStorageAccount();

            blobClient = account.CreateCloudBlobClient();
            tableClient = account.CreateCloudTableClient();
            queueClient = account.CreateCloudQueueClient();

            try
            { 
                var serviceProperties = blobClient.GetServiceProperties();

                if (serviceProperties.Cors.CorsRules.Count == 0)
                {
                    ButtonBlobServiceCORSIcon.Source = new BitmapImage(new Uri("pack://application:,,/Images/unchecked.png"));
                    ButtonBlobServiceCORSLabel.Text = "CORS";
                }
                else
                {
                    ButtonBlobServiceCORSIcon.Source = new BitmapImage(new Uri("pack://application:,,/Images/checked.png"));
                    ButtonBlobServiceCORSLabel.Text = "CORS (" + serviceProperties.Cors.CorsRules.Count.ToString() + ")";
                }
            }
            catch(Exception)
            {
                // Disallowed for developer storage account.
            }

            try
            {
                // Check for $logs container and add it if present ($logs is not included in the general ListContainers call).
                
                CloudBlobContainer logsContainer = blobClient.GetContainerReference("$logs");
                if (logsContainer.Exists())
                {
                    StackPanel stack = new StackPanel();
                    stack.Orientation = Orientation.Horizontal;

                    Image cloudFolderImage = new Image();
                    cloudFolderImage.Source = new BitmapImage(new Uri("pack://application:,,/Images/cloud_folder.png"));
                    cloudFolderImage.Height = 24;

                    Label label = new Label();
                    label.Content = logsContainer.Name;

                    stack.Children.Add(cloudFolderImage);
                    stack.Children.Add(label);

                    TreeViewItem blobItem = new TreeViewItem()
                    {
                        Header = stack,
                        Tag = new OutlineItem()
                        {
                            ItemType = ItemType.BLOB_CONTAINER,
                            Container = logsContainer.Name,
                            Permissions = logsContainer.GetPermissions()
                        }
                    };
                    blobSection.Items.Add(blobItem);
                }

                IEnumerable<CloudBlobContainer> containers = blobClient.ListContainers();
                if (containers != null)
                {
                    if (containers != null)
                    {
                        foreach (CloudBlobContainer container in containers)
                        {
                            StackPanel stack = new StackPanel();
                            stack.Orientation = Orientation.Horizontal;

                            Image cloudFolderImage = new Image();
                            cloudFolderImage.Source = new BitmapImage(new Uri("pack://application:,,/Images/cloud_folder.png"));
                            cloudFolderImage.Height = 24;

                            Label label = new Label();
                            label.Content = container.Name;

                            stack.Children.Add(cloudFolderImage);
                            stack.Children.Add(label);

                            TreeViewItem blobItem = new TreeViewItem()
                            {
                                Header = stack,
                                Tag = new OutlineItem()
                                {
                                    ItemType = ItemType.BLOB_CONTAINER,
                                    Container = container.Name,
                                    Permissions = container.GetPermissions()
                                }
                            };
                            blobSection.Items.Add(blobItem);
                        }
                    }
                }
                blobSection.Header = "Blob Containers (" + containers.Count().ToString() + ")";

                switch(LastItemType)
                {
                    case ItemType.BLOB_SERVICE:
                    case ItemType.BLOB_CONTAINER:
                        blobSection.IsExpanded = true;
                        break;
                    case ItemType.QUEUE_SERVICE:
                    case ItemType.QUEUE_CONTAINER:
                        queueSection.IsExpanded = true;
                        break;
                    case ItemType.TABLE_SERVICE:
                    case ItemType.TABLE_CONTAINER:
                        tableSection.IsExpanded = true;
                        break;
                    default:
                        blobSection.IsExpanded = true;
                        break;
                }


            }
            catch (Exception ex)
            {
                ShowError("Error enumering blob containers in the storage account: " + ex.Message);
            }

            try
            { 
                IEnumerable<CloudQueue> queues = queueClient.ListQueues();

                if (queues != null)
                {
                    foreach (CloudQueue queue in queues)
                    {
                        StackPanel stack = new StackPanel();
                        stack.Orientation = Orientation.Horizontal;

                        Image cloudFolderImage = new Image();
                        cloudFolderImage.Source = new BitmapImage(new Uri("pack://application:,,/Images/cloud_queue.png"));
                        cloudFolderImage.Height = 24;

                        Label label = new Label();
                        label.Content = queue.Name;

                        stack.Children.Add(cloudFolderImage);
                        stack.Children.Add(label);

                        queueSection.Items.Add(new TreeViewItem()
                        {
                            Header = stack,
                            Tag = new OutlineItem()
                            {
                                ItemType = ItemType.QUEUE_CONTAINER,
                                Container = queue.Name
                            }
                        });
                    }
                }
                queueSection.Header = "Queues (" + queues.Count().ToString() + ")";
            }
            catch (Exception ex)
            {
                ShowError("Error enumering queues in storage account: " + ex.Message);
            }

            // OData version number occurs here:
            // Could not load file or assembly 'Microsoft.Data.OData, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

            try
            {
                IEnumerable<CloudTable> tables = tableClient.ListTables();
                if (tables != null)
                {
                    foreach (CloudTable table in tables)
                    {
                        StackPanel stack = new StackPanel();
                        stack.Orientation = Orientation.Horizontal;

                        Image cloudFolderImage = new Image();
                        cloudFolderImage.Source = new BitmapImage(new Uri("pack://application:,,/Images/cloud_table.png"));
                        cloudFolderImage.Height = 24;

                        Label label = new Label();
                        label.Content = table.Name;

                        stack.Children.Add(cloudFolderImage);
                        stack.Children.Add(label);

                        tableSection.Items.Add(new TreeViewItem()
                        {
                            Header = stack,
                            Tag = new OutlineItem()
                            {
                                ItemType = ItemType.TABLE_CONTAINER,
                                Container = table.Name
                            }
                        });
                    }
                }
                tableSection.Header = "Tables (" + tables.Count().ToString() + ")";
            }
            catch(Exception ex)
            {
                ShowError("Error enumerating tables in storage account: " + ex.Message);
            }

            Cursor = Cursors.Arrow;
        }