public blob[] blobs(string c /* container */, string b, /* blobs filter */ bool d = false /* include detail */) { blob blob; List<blob> blobs = new List<blob>(); if (String.IsNullOrEmpty(c)) { c = "*"; } if (String.IsNullOrEmpty(b)) { b = "*"; } BlobHelper bh = new BlobHelper("default"); List<CloudBlob> blobList = new List<CloudBlob>(); string[] containerNames; if (c == null) { containerNames = new string[] { "*" }; } else { containerNames = c.Split(','); } foreach (string container in containerNames) { if (container.Contains("*")) /* wildcard - all containers */ { List<CloudBlobContainer> containers = new List<CloudBlobContainer>(); if (bh.ListContainers(out containers)) { foreach (CloudBlobContainer ctr in containers) { if (MatchWildcard(container, ctr.Name) && (bh.ListBlobs(ctr.Name, out blobList))) { foreach (CloudBlob cb in blobList) { blob = new blob() { containerName = ctr.Name, name = cb.Name, length = cb.Properties.Length }; if (MatchWildcard(b, cb.Name)) { if (d) { blob.blobType = cb.Properties.BlobType.ToString(); blob.contentType = cb.Properties.ContentType; blob.eTag = cb.Properties.ETag; blob.timeStamp = cb.Properties.LastModifiedUtc.ToString(); }; blobs.Add(blob); } } } } } } else { if (b.Contains("*")) { if (bh.ListBlobs(container, out blobList)) { foreach (CloudBlob cb in blobList) { blob = new blob() { containerName = container, name = cb.Name, length = cb.Properties.Length }; if (MatchWildcard(b, cb.Name)) { if (d) { blob.blobType = cb.Properties.BlobType.ToString(); blob.contentType = cb.Properties.ContentType; blob.eTag = cb.Properties.ETag; blob.timeStamp = cb.Properties.LastModifiedUtc.ToString(); }; blobs.Add(blob); } } } } else { blob = new blob() { containerName = container, name = b, length = 0 }; SortedList<string, string> properties = new SortedList<string,string>(); if (bh.GetBlobProperties(c, b, out properties)) { //TODO: blob.length = Convert.ToInt32(properties["Length"]); if (d) { blob.blobType = properties["BlobType"]; blob.contentType = properties["ContentType"]; blob.eTag = properties["ETag"]; blob.timeStamp = properties["LastModified"].ToString(); }; } blobs.Add(blob); } } } return blobs.ToArray(); }
public container[] containers(string c = "" /* container name */) { if (String.IsNullOrEmpty(c)) c = "*"; BlobHelper bh = new BlobHelper("default"); List<container> results = new List<container>(); string[] containerNames = c.Split(','); foreach (string cn in containerNames) { if (cn == String.Empty || cn.Contains("*")) /* all containers | wildcard */ { List<CloudBlobContainer> containers = new List<CloudBlobContainer>(); bh.ListContainers(out containers); for (int i = containers.Count() - 1; i >= 0; i--) { if (MatchWildcard(cn, containers[i].Name)) { results.Add(new container() { name = containers[i].Name, eTag = containers[i].Properties.ETag, timeStamp = containers[i].Properties.LastModifiedUtc.ToString() }); } } } else /* specific containers */ { CloudBlobContainer cb = bh.GetContainer(cn); if (cb != null) { results.Add(new container() { name = cb.Name, eTag = cb.Properties.ETag, timeStamp = cb.Properties.LastModifiedUtc.ToString() }); } } } return results.ToArray(); }