本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer类的典型用法代码示例。如果您正苦于以下问题:C# CloudBlobContainer类的具体用法?C# CloudBlobContainer怎么用?C# CloudBlobContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CloudBlobContainer类属于Microsoft.WindowsAzure.Storage.Blob命名空间,在下文中一共展示了CloudBlobContainer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ParallelUploadFile
public static void ParallelUploadFile(CloudBlobContainer blobContainer, string blobName, string filePath, string contentType = null)
{
var start = DateTime.Now;
Console.WriteLine("\nUpload file in parallel.");
CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(blobName);
// 2M blocks for demo
int blockLength = 2 * 1000 * 1024;
byte[] dataToUpload = File.ReadAllBytes(filePath);
int numberOfBlocks = (dataToUpload.Length / blockLength) + 1;
string[] blockIds = new string[numberOfBlocks];
Parallel.For(0, numberOfBlocks, x =>
{
var blockId = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
var currentLength = Math.Min(blockLength, dataToUpload.Length - (x * blockLength));
using (var memStream = new MemoryStream(dataToUpload, x * blockLength, currentLength))
{
blockBlob.PutBlock(blockId, memStream, null);
}
blockIds[x] = blockId;
Console.WriteLine("BlockId:{0}", blockId);
});
if (!String.IsNullOrEmpty(contentType)) { blockBlob.Properties.ContentType = contentType; }
blockBlob.PutBlockList(blockIds);
Console.WriteLine("URL:{0}, ETag:{1}", blockBlob.Uri, blockBlob.Properties.ETag);
var timespan = DateTime.Now - start;
Console.WriteLine("{0} seconds.", timespan.Seconds);
}
开发者ID:paulbouwer,项目名称:BlobStorageDemos,代码行数:33,代码来源:11_ParallelBlobUpload.cs
示例2: CopyContainer
public async Task CopyContainer(CloudBlobContainer sourceContainer, string destination)
{
var uri = new Uri(sourceContainer.Uri.AbsoluteUri.TrimEnd('/') + '/');
destination = Path.Combine(destination, sourceContainer.Name);
BlobContinuationToken continuationToken = null;
do
{
var segments = await sourceContainer.ListBlobsSegmentedAsync(prefix: null, useFlatBlobListing: true,
blobListingDetails: BlobListingDetails.Metadata, maxResults: MaxParallelDownloads,
currentToken: continuationToken, options: null, operationContext: null);
var tasks = new BlockingCollection<Task>(MaxParallelDownloads);
Parallel.ForEach(segments.Results.Cast<CloudBlockBlob>(), srcFile =>
{
var relativePath = uri.MakeRelativeUri(srcFile.Uri);
var destLocation = Path.Combine(destination, relativePath.OriginalString);
if (File.Exists(destLocation) && File.GetLastWriteTimeUtc(destLocation) == srcFile.Properties.LastModified)
{
// If the file looks unchanged, skip it.
return;
}
Directory.CreateDirectory(Path.GetDirectoryName(destLocation));
tasks.Add(srcFile.DownloadToFileAsync(destLocation, FileMode.Create));
});
await Task.WhenAll(tasks);
continuationToken = segments.ContinuationToken;
} while (continuationToken != null);
}
开发者ID:pranavkm,项目名称:AzureBlobTransfer,代码行数:32,代码来源:BlobTransferManager.cs
示例3: SetContainerPermission
protected void SetContainerPermission(CloudBlobContainer container, BlobContainerPublicAccessType perimssion)
{
container.SetPermissionsAsync(new BlobContainerPermissions
{
PublicAccess = perimssion
});
}
开发者ID:sergeyb12345,项目名称:MarketHunter,代码行数:7,代码来源:AzureStorageClient.cs
示例4: UploadFileToBlob
public static void UploadFileToBlob(string fileName, string containerSAS)
{
Console.WriteLine("Uploading {0} to {1}", fileName, containerSAS);
CloudBlobContainer container = new CloudBlobContainer(new Uri(containerSAS));
CloudBlockBlob blob = container.GetBlockBlobReference(fileName);
blob.UploadFromStream(new FileStream(fileName, FileMode.Open, FileAccess.Read));
}
开发者ID:romitgirdhar,项目名称:azure-batch-samples,代码行数:7,代码来源:ImgProcUtils.cs
示例5: ListBlobs
public static void ListBlobs(CloudBlobContainer blobContainer, BlobListing blobListing, String prefix = null)
{
if (blobListing == BlobListing.Flat)
{
foreach (var blockBlob in blobContainer.ListBlobs(prefix: null, useFlatBlobListing: true))
{
Console.WriteLine("{0,-10} - {1}", @"Blob", ((CloudBlockBlob)blockBlob).Name);
Console.WriteLine("{0,-10} - {1}", String.Empty, blockBlob.Uri);
}
}
else if (blobListing == BlobListing.Hierarchical)
{
foreach (var blockBlob in blobContainer.ListBlobs(prefix: prefix, useFlatBlobListing: false))
{
if (blockBlob is CloudBlockBlob)
{
Console.WriteLine("{0,-10} - {1}", @"Blob", ((CloudBlockBlob)blockBlob).Name);
Console.WriteLine("{0,-10} - {1}", String.Empty, blockBlob.Uri);
}
else if (blockBlob is CloudBlobDirectory)
{
Console.WriteLine("{0,-10} - {1}", @"Directory", ((CloudBlobDirectory)blockBlob).Prefix);
Console.WriteLine("{0,-10} - {1}", String.Empty, blockBlob.Uri);
ListBlobs(blobContainer, BlobListing.Hierarchical, ((CloudBlobDirectory)blockBlob).Prefix);
}
}
}
}
开发者ID:paulbouwer,项目名称:BlobStorageDemos,代码行数:29,代码来源:03_ListBlobs.cs
示例6: CloudBlobDirectorySetupWithDelimiterAsync
private async Task<bool> CloudBlobDirectorySetupWithDelimiterAsync(CloudBlobContainer container, string delimiter = "/")
{
try
{
for (int i = 1; i < 3; i++)
{
for (int j = 1; j < 3; j++)
{
for (int k = 1; k < 3; k++)
{
String directory = "TopDir" + i + delimiter + "MidDir" + j + delimiter + "EndDir" + k + delimiter + "EndBlob" + k;
CloudPageBlob blob1 = container.GetPageBlobReference(directory);
await blob1.CreateAsync(0);
}
}
CloudPageBlob blob2 = container.GetPageBlobReference("TopDir" + i + delimiter + "Blob" + i);
await blob2.CreateAsync(0);
}
return true;
}
catch (Exception e)
{
throw e;
}
}
开发者ID:huoxudong125,项目名称:azure-sdk-for-net,代码行数:28,代码来源:CloudBlobDirectoryTest.cs
示例7: CreateBlobsTask
public static List<string> CreateBlobsTask(CloudBlobContainer container, int count, BlobType type)
{
string name;
List<string> blobs = new List<string>();
for (int i = 0; i < count; i++)
{
switch (type)
{
case BlobType.BlockBlob:
name = "bb" + Guid.NewGuid().ToString();
CloudBlockBlob blockBlob = container.GetBlockBlobReference(name);
blockBlob.PutBlockListAsync(new string[] { }).Wait();
blobs.Add(name);
break;
case BlobType.PageBlob:
name = "pb" + Guid.NewGuid().ToString();
CloudPageBlob pageBlob = container.GetPageBlobReference(name);
pageBlob.CreateAsync(0).Wait();
blobs.Add(name);
break;
}
}
return blobs;
}
开发者ID:huoxudong125,项目名称:azure-sdk-for-net,代码行数:25,代码来源:BlobTestBase.cs
示例8: CopyBlobData
/// <summary>
/// Initiates the SolCat Azure blob data sync.
/// </summary>
public static void CopyBlobData()
{
// Authentication Credentials for Azure Storage:
var credsSrc
= new StorageCredentials(
ConfigHelper.GetConfigValue("HubContainerName"),
ConfigHelper.GetConfigValue("HubContainerKey"));
var credsDest
= new StorageCredentials(
ConfigHelper.GetConfigValue("NodeContainerKey"),
ConfigHelper.GetConfigValue("NodeContainerKey"));
// Source Container: Hub (Development)
_srcContainer =
new CloudBlobContainer(
new Uri(ConfigHelper.GetConfigValue("HubContainerUri")),
credsSrc);
// Destination Container: Node (Production)
_destContainer =
new CloudBlobContainer(
new Uri(ConfigHelper.GetConfigValue("NodeContainerUri")),
credsDest);
// Set permissions on the container:
var permissions = new BlobContainerPermissions {PublicAccess = BlobContainerPublicAccessType.Blob};
_srcContainer.SetPermissions(permissions);
_destContainer.SetPermissions(permissions);
// Call the blob copy master method:
CopyBlobs(_srcContainer, _destContainer);
}
开发者ID:nocarrier,项目名称:AzureStorage,代码行数:36,代码来源:BlobManager.cs
示例9: GetBlobs
public List<CloudBlockBlob> GetBlobs(CloudBlobContainer container, string filter = "")
{
return container.ListBlobs()
.OfType<CloudBlockBlob>()
.Where(b => String.IsNullOrEmpty(filter) || b.Name.Contains(filter))
.ToList();
}
开发者ID:sxkote,项目名称:sxcore,代码行数:7,代码来源:AzureFileStorageService.cs
示例10: ContainerElementViewModel
public ContainerElementViewModel(CloudBlobContainer container)
{
if (container == null)
throw new ArgumentNullException(nameof(container));
_container = container;
}
开发者ID:gest01,项目名称:BetterStorageExplorer,代码行数:7,代码来源:ContainerElementViewModel.cs
示例11: BlobManager
public BlobManager(){
try
{
storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"));
blobClient = storageAccount.CreateCloudBlobClient();
container = blobClient.GetContainerReference("supstorage");
container.CreateIfNotExists();
}
catch (ArgumentNullException)
{
Trace.TraceInformation("CloudStorageAccount Exception null ou vide");
// Use Application Local Storage Account String
}
catch (NullReferenceException)
{
Trace.TraceInformation("CloudBlobClient Or CloudBlobContainer Exception");
// Create Container
}
catch (FormatException)
{
Trace.TraceInformation("CloudStorageAccount Exception Connection String Invalid");
}
catch (ArgumentException)
{
Trace.TraceInformation("CloudStorageAccount Exception connectionString ne peut pas être analysée");
}
}
开发者ID:oumartraore,项目名称:SupStorage,代码行数:28,代码来源:BlobManager.cs
示例12: CreateBlobsAsync
public static async Task<List<string>> CreateBlobsAsync(CloudBlobContainer container, int count, BlobType type)
{
string name;
List<string> blobs = new List<string>();
for (int i = 0; i < count; i++)
{
switch (type)
{
case BlobType.BlockBlob:
name = "bb" + Guid.NewGuid().ToString();
CloudBlockBlob blockBlob = container.GetBlockBlobReference(name);
await blockBlob.PutBlockListAsync(new string[] { });
blobs.Add(name);
break;
case BlobType.PageBlob:
name = "pb" + Guid.NewGuid().ToString();
CloudPageBlob pageBlob = container.GetPageBlobReference(name);
await pageBlob.CreateAsync(0);
blobs.Add(name);
break;
case BlobType.AppendBlob:
name = "ab" + Guid.NewGuid().ToString();
CloudAppendBlob appendBlob = container.GetAppendBlobReference(name);
await appendBlob.CreateOrReplaceAsync();
blobs.Add(name);
break;
}
}
return blobs;
}
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:32,代码来源:BlobTestBase.cs
示例13: CreateLogs
public static List<string> CreateLogs(CloudBlobContainer container, StorageService service, int count, DateTime start, string granularity)
{
string name;
List<string> blobs = new List<string>();
for (int i = 0; i < count; i++)
{
CloudBlockBlob blockBlob;
switch (granularity)
{
case "hour":
name = string.Concat(service.ToString().ToLowerInvariant(), "/", start.AddHours(i).ToString("yyyy/MM/dd/HH", CultureInfo.InvariantCulture), "00/000001.log");
break;
case "day":
name = string.Concat(service.ToString().ToLowerInvariant(), "/", start.AddDays(i).ToString("yyyy/MM/dd/HH", CultureInfo.InvariantCulture), "00/000001.log");
break;
case "month":
name = string.Concat(service.ToString().ToLowerInvariant(), "/", start.AddMonths(i).ToString("yyyy/MM/dd/HH", CultureInfo.InvariantCulture), "00/000001.log");
break;
default:
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "CreateLogs granularity of '{0}' is invalid.", granularity));
}
blockBlob = container.GetBlockBlobReference(name);
blockBlob.PutBlockList(new string[] { });
blobs.Add(name);
}
return blobs;
}
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:34,代码来源:AnalyticsTestBase.cs
示例14: BlobStorage
public BlobStorage(BlobSettings appSettings)
{
try
{
if (appSettings.ImageSize != null)
ResizeLayer = new ResizeLayer(appSettings.ImageSize, ResizeMode.Min);
UploadThumbnail = appSettings.UploadThumbnail;
StorageAccountName = appSettings.StorageAccountName;
StorageAccountAccessKey = appSettings.StorageAccountAccessKey;
// Create a blob client and retrieve reference to images container
BlobClient = StorageAccount.CreateCloudBlobClient();
Container = BlobClient.GetContainerReference(appSettings.ContainerName);
// Create the "images" container if it doesn't already exist.
if (Container.CreateIfNotExists())
{
// Enable public access on the newly created "images" container
Container.SetPermissions(
new BlobContainerPermissions
{
PublicAccess =
BlobContainerPublicAccessType.Blob
});
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
开发者ID:victorhugom,项目名称:AzureApiHelpers,代码行数:34,代码来源:BlobStorage.cs
示例15: InitStorage
private static void InitStorage()
{
var credentials = new StorageCredentials(AppKeys.Storage_Account_Name, AppKeys.PrimaryAccessKey);
var storageAccount = new CloudStorageAccount(credentials, true);
var blobClient = storageAccount.CreateCloudBlobClient();
imagesContainer = blobClient.GetContainerReference("images");
}
开发者ID:antataiv,项目名称:ASP.Net-Photo-Contest-Web-Application,代码行数:7,代码来源:BaseController.cs
示例16: AzureFileSystem
public AzureFileSystem(string containerName, string root, bool isPrivate, CloudStorageAccount storageAccount) {
// Setup the connection to custom storage accountm, e.g. Development Storage
_storageAccount = storageAccount;
ContainerName = containerName;
_root = String.IsNullOrEmpty(root) ? "": root + "/";
_absoluteRoot = Combine(Combine(_storageAccount.BlobEndpoint.AbsoluteUri, containerName), _root);
//using ( new HttpContextWeaver() )
{
BlobClient = _storageAccount.CreateCloudBlobClient();
// Get and create the container if it does not exist
// The container is named with DNS naming restrictions (i.e. all lower case)
Container = BlobClient.GetContainerReference(ContainerName);
Container.CreateIfNotExists();
Container.SetPermissions(isPrivate
? new BlobContainerPermissions
{PublicAccess = BlobContainerPublicAccessType.Off}
: new BlobContainerPermissions
{PublicAccess = BlobContainerPublicAccessType.Blob}); // deny listing
}
}
开发者ID:grbbod,项目名称:drconnect-jungo,代码行数:25,代码来源:AzureFileSystem.cs
示例17: AzureImageUploader
public AzureImageUploader()
{
var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
_blobClient = storageAccount.CreateCloudBlobClient();
_container = FindOrCreateContainer(ContainerName);
_filecontainer = FindOrCreateContainer(FileContainerName);
}
开发者ID:skyfighter007,项目名称:Britespokes-Dev,代码行数:7,代码来源:AzureImageUploader.cs
示例18: Init
public async Task Init( string name, IProviderRuntime providerRuntime, IProviderConfiguration config )
{
Log = providerRuntime.GetLogger( this.GetType().Name );
try
{
ConfigureJsonSerializerSettings( config );
if( !config.Properties.ContainsKey( "DataConnectionString" ) )
{
throw new BadProviderConfigException(
"The DataConnectionString setting has not been configured in the cloud role. Please add a DataConnectionString setting with a valid Azure Storage connection string." );
}
else
{
var account = CloudStorageAccount.Parse( config.Properties[ "DataConnectionString" ] );
var blobClient = account.CreateCloudBlobClient();
var containerName = config.Properties.ContainsKey( "ContainerName" ) ? config.Properties[ "ContainerName" ] : "grainstate";
container = blobClient.GetContainerReference( containerName );
await container.CreateIfNotExistsAsync();
}
}
catch( Exception ex )
{
Log.Error( 0, ex.ToString(), ex );
throw;
}
}
开发者ID:DebugOfTheRoad,项目名称:BlobDemo,代码行数:28,代码来源:BlobStorageProvider.cs
示例19: Initialise
/// <summary>
/// Occurs when a storage provider operation has completed.
/// </summary>
//public event EventHandler<StorageProviderEventArgs> StorageProviderOperationCompleted;
#endregion
// Initialiser method
private void Initialise(string storageAccount, string containerName)
{
if (String.IsNullOrEmpty(containerName))
throw new ArgumentException("You must provide the base Container Name", "containerName");
ContainerName = containerName;
_account = CloudStorageAccount.Parse(storageAccount);
_blobClient = _account.CreateCloudBlobClient();
_container = _blobClient.GetContainerReference(ContainerName);
try
{
_container.FetchAttributes();
}
catch (StorageException)
{
Trace.WriteLine(string.Format("Create new container: {0}", ContainerName), "Information");
_container.Create();
// set new container's permissions
// Create a permission policy to set the public access setting for the container.
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
// The public access setting explicitly specifies that the container is private,
// so that it can't be accessed anonymously.
containerPermissions.PublicAccess = BlobContainerPublicAccessType.Off;
//Set the permission policy on the container.
_container.SetPermissions(containerPermissions);
}
}
开发者ID:Cache22,项目名称:wedge,代码行数:39,代码来源:AzureBlobStorageProvider.cs
示例20: AzureIndexInput
public AzureIndexInput(AzureDirectory azuredirectory, ICloudBlob blob)
: base(blob.Name)
{
_name = blob.Uri.Segments[blob.Uri.Segments.Length - 1];
_fileMutex = BlobMutexManager.GrabMutex(_name);
_fileMutex.WaitOne();
try
{
_azureDirectory = azuredirectory;
_blobContainer = azuredirectory.BlobContainer;
_blob = blob;
string fileName = _name;
StreamOutput fileStream = _azureDirectory.CreateCachedOutputAsStream(fileName);
// get the blob
_blob.DownloadToStream(fileStream);
fileStream.Flush();
Debug.WriteLine("GET {0} RETREIVED {1} bytes", _name, fileStream.Length);
fileStream.Close();
// and open it as an input
_indexInput = CacheDirectory.openInput(fileName, IOContext.DEFAULT);
}
finally
{
_fileMutex.ReleaseMutex();
}
}
开发者ID:JayBeavers,项目名称:AzureDirectory,代码行数:33,代码来源:AzureIndexInput.cs
注:本文中的Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论