コード例 #1
0
 /// <summary>
 /// Gets the packages.
 /// </summary>
 public IQueryable <IPackage> GetPackages()
 {
     return(_blobClient
            .ListContainers(NsasConstants.ContainerPrefix)
            .Select(x => x.ListBlobs())
            .SelectMany(x => x)
            .OfType <CloudBlockBlob>()
            .Select(x => _packageSerializer.ReadFromMetadata(x))
            .Where(x => x != null)
            .AsQueryable <IPackage>());
 }
コード例 #2
0
        public IEnumerable <string> GetFiles(string path, string filter, bool recursive)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                var containers = blobClient.ListContainers().Select(x => x.Name + ".nupkg").ToList();
                return(containers);
            }
            var container = this.blobClient.GetContainerReference(path);

            return(container.ListBlobs().Select(x => x.Container.Name));
        }
コード例 #3
0
 public IEnumerable <string> ListContainers()
 {
     try
     {
         return(_cloudBlobClient.ListContainers().Select(c => c.Name));
     }
     catch (Exception e)
     {
         throw HandleException(e);
     }
 }
コード例 #4
0
        public MainWindow()
        {
            InitializeComponent();
            //ShowContainer("new");
            CloudBlobClient    cloudBlobClient = Login_Azure.AzureConnection();
            CloudBlobContainer container       = cloudBlobClient.GetContainerReference("new");

            foreach (CloudBlobContainer item in cloudBlobClient.ListContainers())
            {
                trvStructure.Items.Add(CreateTreeItem(item));
            }
        }
コード例 #5
0
        public void Run(string acctName, string acctKey, DirectoryInfo dir)
        {
            string connectionString            = "DefaultEndpointsProtocol=https;AccountName=" + acctName + ";AccountKey=" + acctKey;
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

            Console.WriteLine("Azure Client Connected");
            CloudBlobClient client = storageAccount.CreateCloudBlobClient();

            Console.WriteLine("Begin downloading of files...");
            ProcessContainers(client.ListContainers(), dir);
            Console.WriteLine("...Downloaded all files");
        }
コード例 #6
0
        public List <string> ContainerList()
        {
            var returnList = new List <string>();
            var containers = _CBC.ListContainers();

            foreach (var container in containers)
            {
                returnList.Add(container.Name);
            }

            return(returnList);
        }
コード例 #7
0
        /// <summary>
        /// Returns a reference to the CloudBlobContainer object in the given account.
        /// <param name="storageAccount">The account</param>
        /// <returns name="container">Returns the CloudBlobContainer</returns>
        /// <search>microsoft,azure,cloud,storage,link,account,cloud,blob,container</search>
        public static List <string> ListContainers(CloudStorageAccount storageAccount)
        {
            CloudBlobClient blobClient    = storageAccount.CreateCloudBlobClient();
            var             containers    = blobClient.ListContainers();
            List <string>   containerList = new List <string>();

            foreach (var item in containers)
            {
                containerList.Add(item.Name);
            }
            return(containerList);
        }
コード例 #8
0
        /// <summary>
        /// Checks if a container exists.
        /// </summary>
        /// <param name="containerName">Name of the container.</param>
        /// <returns>True if container exists; false otherwise</returns>
        public bool DoesContainerExist(string containerName)
        {
            bool returnValue = false;

            ExecuteWithExceptionHandling(
                () =>
            {
                IEnumerable <CloudBlobContainer> containers = _blobClient.ListContainers();
                returnValue = containers.Any(one => one.Name == containerName);
            });
            return(returnValue);
        }
コード例 #9
0
            public void Dispose()
            {
                Host.Stop();

                VerifyLockState("WebJobs.Internal.Blobs.Listener", LeaseState.Available, LeaseStatus.Unlocked);

                CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient();

                foreach (var testContainer in blobClient.ListContainers(TestArtifactPrefix))
                {
                    testContainer.Delete();
                }
            }
コード例 #10
0
        static void Main(string[] args)
        {
            Console.WriteLine("=========================================");
            Console.WriteLine("Azure Storage Blob Container Operations");
            Console.WriteLine("=========================================");

            while (true)
            {
                string containerName = null;
                storageAccount = CloudStorageAccount.Parse("Shared Access Signature Primary or Secondary Connection String");
                blobClient     = storageAccount.CreateCloudBlobClient();
                Console.WriteLine("\n1. Create a container\n2. View Containers\n3. Delete a container\n4. Exit\n");
                Console.Write("Enter your Option : ");
                switch (Convert.ToInt32(Console.ReadLine()))
                {
                case 1:
                    // Create a container if it doesn't exist.
                    Console.Write("Enter name of Container : ");
                    containerName = Console.ReadLine();
                    blobContainer = blobClient.GetContainerReference(containerName);
                    blobContainer.CreateIfNotExistsAsync();
                    blobContainer.SetPermissionsAsync(new BlobContainerPermissions {
                        PublicAccess = BlobContainerPublicAccessType.Blob
                    });
                    Console.WriteLine("Container created successfully.");
                    break;

                case 2:
                    // View all containers
                    IEnumerable <CloudBlobContainer> containers = blobClient.ListContainers();
                    foreach (CloudBlobContainer list in containers)
                    {
                        Console.WriteLine("Container Name : " + list.Name + "\tContainer Link: " + list.Uri);
                    }
                    break;

                case 3:
                    // Delete a container
                    Console.Write("Enter name of Container : ");
                    containerName = Console.ReadLine();
                    blobContainer = blobClient.GetContainerReference(containerName);
                    blobContainer.DeleteIfExistsAsync();
                    Console.WriteLine("Container deleted successfully.");
                    break;

                case 4:
                    System.Environment.Exit(1);
                    break;
                }
            }
        }
コード例 #11
0
        public static void CleanAccount(String accountName, String accountKey)
        {
            CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentialsAccountAndKey(accountName, accountKey), true);
            CloudBlobClient     blobClient     = storageAccount.CreateCloudBlobClient();

            foreach (CloudBlobContainer blobcontainer in blobClient.ListContainers())
            {
                if (blobcontainer.Name.Contains(ConfigurationManager.AppSettings.Get("Prefix")))
                {
                    blobcontainer.Delete();
                    Console.WriteLine("Deleting container: " + blobcontainer.Name);
                }
            }
        }
コード例 #12
0
        private void ListContainers(string connectionString)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
            CloudBlobClient     blobClient     = storageAccount.CreateCloudBlobClient();

            ContainersList.Items.Clear();
            foreach (var container in blobClient.ListContainers("", ContainerListingDetails.None, null, null))
            {
                ContainersList.Items.Add(container.Name);
            }

            this.config.AppSettings.Settings[StorageConnectionString].Value = connectionString;
            this.config.Save(ConfigurationSaveMode.Modified);
        }
コード例 #13
0
        static public void ExploreStorageAccount()
        {
            var containers = blobClient.ListContainers();

            foreach (var container in containers)
            {
                Console.WriteLine("Container {0}:", container.Name);

                foreach (var blob in container.ListBlobs(useFlatBlobListing:true))
                {
                    Console.WriteLine("\t\tBlob {0}", blob.Uri.ToString());
                }
            }
        }
コード例 #14
0
        static void InitializeImportClient(CloudBlobClient importClient)
        {
            // Remove all existing containers - note that this is a race condition with others executing the tests concurrently,
            // but this is unlikely enough to avoid contention
            // Use a wait to try to avoid contention
            if (importClient.ListContainers().Any())
            {
                Thread.Sleep(30000);
            }
            bool deletedContainers = false;

            foreach (var container in importClient.ListContainers())
            {
                container.Delete();
                deletedContainers = true;
            }
            // If we deleted any containers that will be recreated when the account is imported, we should
            // wait a while to allow XStore to get consistent around the deleted container
            if (deletedContainers)
            {
                Thread.Sleep(60000);
            }
        }
コード例 #15
0
ファイル: MainForm.cs プロジェクト: vczh-codeplex/gac
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            var account    = new CloudStorageAccount(new StorageCredentialsAccountAndKey(textBoxBlobName.Text, textBoxAccessKey.Text), true);
            var blobClient = new CloudBlobClient(account.BlobEndpoint.AbsoluteUri, account.Credentials);

            this.currentBlobClient = blobClient;
            var containers = blobClient.ListContainers().ToArray();

            comboBoxContainers.Items.Clear();
            comboBoxContainers.Items.AddRange(containers.Select(c => c.Name).ToArray());
            if (comboBoxContainers.Items.Count > 0)
            {
                comboBoxContainers.SelectedIndex = 0;
            }
        }
コード例 #16
0
        /// <summary>
        /// Deletes all blobs in all containers.
        /// Used only in tests tear-down method
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        public static void DeleteAllBlobs(string connectionString)
        {
            CloudBlobClient _client = TableStorage.StorageAccount(connectionString).CreateCloudBlobClient();

            _client.DefaultRequestOptions = GetDefaultBlobRequestOptions();

            foreach (CloudBlobContainer containerRef in _client.ListContainers())
            {
                IEnumerable <IListBlobItem> blobs = containerRef.ListBlobs(useFlatBlobListing: true);
                foreach (IListBlobItem blob in blobs)
                {
                    var blobRef = _client.GetBlobReferenceFromServer(blob.Uri); // v.1.7: GetBlobReference(blob.Uri.AbsoluteUri)
                    blobRef.DeleteIfExists();
                }
            }
        }
コード例 #17
0
        public static void CleanCompleteBlobs()
        {
            // Delete all joined data
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(MockCommandCenter.StorageConnectionString);
            CloudBlobClient     blobClient     = storageAccount.CreateCloudBlobClient();
            IEnumerable <CloudBlobContainer> completeContainers = blobClient.ListContainers("complete");

            var parallelOptions = new ParallelOptions {
                MaxDegreeOfParallelism = Environment.ProcessorCount * 2
            };

            foreach (CloudBlobContainer container in completeContainers)
            {
                Parallel.ForEach(container.ListBlobs(), parallelOptions, blob => ((CloudBlockBlob)blob).Delete());
            }
        }
コード例 #18
0
            public void Dispose()
            {
                CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient();

                foreach (var testContainer in blobClient.ListContainers(TestArtifactsPrefix))
                {
                    testContainer.Delete();
                }

                CloudQueueClient queueClient = StorageAccount.CreateCloudQueueClient();

                foreach (var testQueue in queueClient.ListQueues(TestArtifactsPrefix))
                {
                    testQueue.Delete();
                }
            }
コード例 #19
0
        public static void DeleteAllBlobContainer()
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                CloudConfigurationManager.GetSetting("StorageConnectionString"));

            // Create the blob client.
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            IEnumerable <CloudBlobContainer> containerList = blobClient.ListContainers();
            int count = containerList.Count();

            foreach (CloudBlobContainer container in containerList)
            {
                container.Delete();
                Console.Write("\r{0} - Container Remaining to delete   ", count--);
            }
        }
コード例 #20
0
 protected override async Task ExecuteAsync(CancellationToken stoppingToken)
 {
     while (!stoppingToken.IsCancellationRequested)
     {
         //delete all unwanted/old blobs
         foreach (var container in blobClient.ListContainers())
         {
             var res = DateTime.UtcNow - container.Properties.LastModified.Value.DateTime;
             if (res.Hours > cleanupTime)//if time period exceeds configured hour, then we will delete the container
             {
                 container.Delete();
             }
         }
         await Task.Delay(5 * 60 * 1000);
     }
 }
コード例 #21
0
        public List <Container> fntListBlobContainerLst(User usrUser)
        {
            cldStorageAccount = Common.Common.fntCreateStorageAccountForBlobs();

            // Create the blob client.
            CloudBlobClient clcBlobClient = cldStorageAccount.CreateCloudBlobClient();

            //Get the list of the blob from the above container
            var containers = clcBlobClient.ListContainers(usrUser.fntCompanyStr).Select(c =>
                                                                                        new Container {
                fntCompanyStr = usrUser.fntCompanyStr,
                fntNameStr    = string.Format("{0}", c.Uri.Segments[cnsContainerMetadata.IndexOfNameUri]),
                fntUri        = c.Uri
            }).ToList();

            return(containers);
        }
コード例 #22
0
ファイル: AzureHelper.cs プロジェクト: dhakalsamip/LoT
        public void CleanAccount(string pattern = "")
        {
            CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentialsAccountAndKey(this.remoteInfo.accountName, this.remoteInfo.accountKey), true);
            CloudBlobClient     blobClient     = storageAccount.CreateCloudBlobClient();

            foreach (CloudBlobContainer blobcontainer in blobClient.ListContainers())
            {
                if (!pattern.Equals("") && blobcontainer.Name.Contains(pattern))
                {
                    blobcontainer.Delete(GetBlobRequestOptions());
                }
                else
                {
                    blobcontainer.Delete(GetBlobRequestOptions());
                }
            }
        }
        /// <summary>
        /// Fetches the list of Blob Storage containers with blobs to be restored
        /// </summary>
        /// <param name="cloudBlobClient">>CloudBlobClient to interact with the Blob Storage Account</param>
        /// <returns></returns>
        public static List <string> GetListOfContainersInStorageAccount(CloudBlobClient cloudBlobClient)
        {
            Console.WriteLine("Fetching list of container names");

            List <string> containerNames = new List <string>();

            foreach (CloudBlobContainer eachContainer in cloudBlobClient.ListContainers())
            {
                if (eachContainer.Name.StartsWith("backup"))
                {
                    Console.WriteLine("Found backup container: {0}", eachContainer.Name);
                    containerNames.Add(eachContainer.Name);
                }
            }

            return(containerNames);
        }
コード例 #24
0
ファイル: Access.cs プロジェクト: tsangtmc/BlobIM
        public static void ListAll_ContianersAndBlobs(string accountname, string accountkey)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=" + accountname + ";AccountKey=" + accountkey);
            CloudBlobContainer  blobContainer  = storageAccount.CreateCloudBlobClient().GetContainerReference("pentest");

            CloudBlobClient  blobClient = storageAccount.CreateCloudBlobClient();
            var              containers = blobClient.ListContainers();
            List <CloudBlob> blobsArray = new List <CloudBlob>();

            foreach (var container in containers)
            {
                var blobs = container.ListBlobs(new BlobRequestOptions()
                {
                    BlobListingDetails = BlobListingDetails.All,
                    UseFlatBlobListing = true,
                }).Cast <CloudBlockBlob>();

                Console.WriteLine("===========================================================");
                Console.WriteLine("containers: " + container.Name);

                foreach (var listBlobItem in blobs)
                {
                    Console.WriteLine("Name: " + listBlobItem.Name);
                    Console.WriteLine("Size: " + listBlobItem.Properties.Length);

                    // can use the md5 function to "help" check small files.. since md5 appears to be meta data you can
                    // both read and set for a blob if you have the key, you would have to download the file and then
                    // do a local md5 check of the existing file against recorded/set md5 value on the blob

                    // NEED TO DO: need to check on blob storage pricing models.. if a text read vs a file download makes
                    // a difference in pricing/costs, or if its all the same.

                    Console.WriteLine("MD5: " + listBlobItem.Properties.ContentMD5.ToString());

                    //try to find a way to read only certain bytes from a blob to try to do a signature check on those... problem
                    //is however that something like this has to be done in the blob storage itself which is not possibe. To check
                    //certain bytes you would have to download the whole file over the wire anyway...

                    //for big files... it would have to be a very superficial check based on metadata properties or something of the sort...

                    Console.WriteLine("Content type: " + listBlobItem.Properties.ContentType);
                    Console.WriteLine("Download location: " + listBlobItem.Uri);
                    Console.WriteLine(" ");
                }
            }
        }
コード例 #25
0
        public string Validate(dynamic data)
        {
            string message = null;

            try
            {
                var creds = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", data.storagename, data.storagekey);
                CloudStorageAccount sa = CloudStorageAccount.Parse(creds);
                CloudBlobClient     bc = sa.CreateCloudBlobClient();
                bc.ListContainers();
            }
            catch (Exception e)
            {
                message = e.Message;
            }

            return(message);
        }
コード例 #26
0
        static void Main(string[] args)
        {
            var account = new CloudStorageAccount(
                storageCredentials,
                false /* useHttps */);
            CloudBlobClient blobClient = account.CreateCloudBlobClient();
            var             tasks      = new List <Task>();

            foreach (var container in blobClient.ListContainers())
            {
                if (containersToProcess.Contains(container.Name))
                {
                    var c = container;
                    tasks.Add(Task.Run(() => FixHeaders(c)));
                }
            }
            Task.WaitAll(tasks.ToArray());
        }
コード例 #27
0
        public static void Delete(string account, string key, string containerName)
        {
            if (string.IsNullOrEmpty(containerName))
            {
                return;
            }

            CloudBlobClient blobClient = Client.GetBlobClient(account, key);

            foreach (CloudBlobContainer container in blobClient.ListContainers())
            {
                if (container.Name == containerName)
                {
                    container.Delete();
                    break;
                }
            }
        }
コード例 #28
0
        /// <summary>
        /// Deletes all blobs in all containers.
        /// Used only in tests tear-down method
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        public static void DeleteAllBlobs(string connectionString)
        {
            CloudBlobClient _client = TableStorage.StorageAccount(connectionString).CreateCloudBlobClient();

            _client.RetryPolicy = GetDefaultRetryPolicy();

            foreach (CloudBlobContainer containerRef in _client.ListContainers())
            {
                BlobRequestOptions options = new BlobRequestOptions();
                options.UseFlatBlobListing = true;
                IEnumerable <IListBlobItem> blobs = containerRef.ListBlobs(options);
                foreach (IListBlobItem blob in blobs)
                {
                    var blobRef = _client.GetBlobReference(blob.Uri.AbsoluteUri);
                    blobRef.DeleteIfExists();
                }
            }
        }
コード例 #29
0
        private void DisplayFilesOfContainer(string containerName)
        {
            CloudBlobContainer          Container  = cloudBlobClient.ListContainers().Where(n => n.Name == containerName).FirstOrDefault();
            IEnumerable <IListBlobItem> mediaBlobs = Container.ListBlobs();

            listViewFiles.Items.Clear();

            foreach (IListBlobItem b in mediaBlobs)
            {
                CloudBlockBlob cloudBlockBlob = b as CloudBlockBlob;
                string         lastModified   = "";
                ListViewItem   item           = new ListViewItem(Path.GetFileName(b.Uri.ToString()), 0);
                lastModified = cloudBlockBlob.Properties.LastModified.Value.UtcDateTime.ToLocalTime().ToString();
                item.SubItems.Add(lastModified);
                item.SubItems.Add(AssetInfo.FormatByteSize(cloudBlockBlob.Properties.Length));
                listViewFiles.Items.Add(item);
            }
            listViewFiles.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
        }
コード例 #30
0
ファイル: StorageAzure.cs プロジェクト: melnx/Bermuda
 /// <summary>
 /// get the containers
 /// </summary>
 /// <param name="Buckets"></param>
 /// <returns></returns>
 public bool GetBuckets(out IEnumerable <string> Buckets)
 {
     Buckets = null;
     try
     {
         CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageAccount"]);
         CloudBlobClient     blobClient     = storageAccount.CreateCloudBlobClient();
         var           containers           = blobClient.ListContainers();
         List <string> list = new List <string>();
         containers.ToList().ForEach(c => list.Add(c.Name));
         Buckets = list;
         return(true);
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex.ToString());
     }
     return(false);
 }