本文整理汇总了C#中Microsoft.WindowsAzure.StorageClient.CloudBlobContainer.GetBlobReference方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlobContainer.GetBlobReference方法的具体用法?C# CloudBlobContainer.GetBlobReference怎么用?C# CloudBlobContainer.GetBlobReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.StorageClient.CloudBlobContainer
的用法示例。
在下文中一共展示了CloudBlobContainer.GetBlobReference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EnsureGzipFiles
public const int CacheControlOneWeekExpiration = 7 * 24 * 60 * 60; // 1 week
#endregion Fields
#region Methods
/// <summary>
/// Finds all js and css files in a container and creates a gzip compressed
/// copy of the file with ".gzip" appended to the existing blob name
/// </summary>
public static void EnsureGzipFiles(
CloudBlobContainer container,
int cacheControlMaxAgeSeconds)
{
string cacheControlHeader = "public, max-age=" + cacheControlMaxAgeSeconds.ToString();
var blobInfos = container.ListBlobs(
new BlobRequestOptions() { UseFlatBlobListing = true });
Parallel.ForEach(blobInfos, (blobInfo) =>
{
string blobUrl = blobInfo.Uri.ToString();
CloudBlob blob = container.GetBlobReference(blobUrl);
// only create gzip copies for css and js files
string extension = Path.GetExtension(blobInfo.Uri.LocalPath);
if (extension != ".css" && extension != ".js")
return;
// see if the gzip version already exists
string gzipUrl = blobUrl + ".gzip";
CloudBlob gzipBlob = container.GetBlobReference(gzipUrl);
if (gzipBlob.Exists())
return;
// create a gzip version of the file
using (MemoryStream memoryStream = new MemoryStream())
{
// push the original blob into the gzip stream
using (GZipStream gzipStream = new GZipStream(
memoryStream, CompressionMode.Compress, CompressionLevel.BestCompression))
using (BlobStream blobStream = blob.OpenRead())
{
blobStream.CopyTo(gzipStream);
}
// the gzipStream MUST be closed before its safe to read from the memory stream
byte[] compressedBytes = memoryStream.ToArray();
// upload the compressed bytes to the new blob
gzipBlob.UploadByteArray(compressedBytes);
// set the blob headers
gzipBlob.Properties.CacheControl = cacheControlHeader;
gzipBlob.Properties.ContentType = GetContentType(extension);
gzipBlob.Properties.ContentEncoding = "gzip";
gzipBlob.SetProperties();
}
});
}
示例2: UploadBlob
private static void UploadBlob(CloudBlobContainer container, string blobName, string filename)
{
CloudBlob blob = container.GetBlobReference(blobName);
using (FileStream fileStream = File.OpenRead(filename))
blob.UploadFromStream(fileStream);
}
示例3: deleteFromBlob
public void deleteFromBlob(string uri, string blobname)
{
CloudStorageAccount storageAccount;
storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("BlobConnectionString"));
blobClient = storageAccount.CreateCloudBlobClient();
blobContainer = blobClient.GetContainerReference(blobname);
var blob = blobContainer.GetBlobReference(uri);
blob.DeleteIfExists();
}
示例4: SaveToAzureBlob
/// <summary>
/// Save the data table to the given azure blob. This will overwrite an existing blob.
/// </summary>
/// <param name="table">instance of table to save</param>
/// <param name="container">conatiner</param>
/// <param name="blobName">blob name</param>
public static void SaveToAzureBlob(this DataTable table, CloudBlobContainer container, string blobName)
{
var blob = container.GetBlobReference(blobName);
using (BlobStream stream = blob.OpenWrite())
using (TextWriter writer = new StreamWriter(stream))
{
table.SaveToStream(writer);
}
}
示例5: AzureTapeStream
public AzureTapeStream(string name, string connectionString, string containerName, ITapeStreamSerializer serializer)
{
_serializer = serializer;
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
blobClient = storageAccount.CreateCloudBlobClient();
container = blobClient.GetContainerReference(containerName);
container.CreateIfNotExist();
_blob = container.GetBlobReference(name);
}
示例6: AzureStorageSourceDataCollection
public AzureStorageSourceDataCollection(CloudBlobContainer container, string blobRootPath)
{
mContainer = container;
mBlobRootPath = blobRootPath;
Names
.Where(i => mContainer.GetBlobReference(mBlobRootPath + "/" + i.Value + ".txt") != null)
.ForEach(i => mStreams.Add(i.Key, ((Func<string, Stream>)GetStream).Curry()(i.Value)));
var missing = Required.Except(mStreams.Keys);
if (missing.Count() > 0)
throw new ArgumentOutOfRangeException("Missing mandatory data.");
}
示例7: UploadWithMd5
static void UploadWithMd5(CloudBlobContainer container, string name, string path)
{
var blob = container.GetBlobReference(name);
blob.Properties.ContentMD5 = GetMd5(path);
semaphore.WaitOne();
var stream = File.OpenRead(path);
Interlocked.Increment(ref count);
blob.BeginUploadFromStream(stream, (ar) => {
blob.EndUploadFromStream(ar);
stream.Close();
semaphore.Release();
Interlocked.Decrement(ref count);
}, null);
}
示例8: CopyFromBlobToLocal
private void CopyFromBlobToLocal(CloudBlobContainer blobContainer, LocalResource localStorage, string blobName)
{
CloudBlob node = blobContainer.GetBlobReference(blobName);
using (BlobStream nodestream = node.OpenRead()) {
var nodefile = Path.Combine(localStorage.RootPath, blobName);
if (!System.IO.File.Exists(nodefile)) {
using (var fileStream = new FileStream(nodefile, FileMode.CreateNew)) {
nodestream.CopyTo(fileStream);
fileStream.Flush();
fileStream.Close();
}
}
}
}
示例9: Mutex
// The mutex must already exists
public Mutex(CloudBlobContainer container, string mutexName, Exception e)
{
blob = container.GetBlobReference(mutexName);
byte[] b1 = { 1 };
BlobRequestOptions requestOpt = new BlobRequestOptions();
bool keepGoing = true;
string oldEtag = "";
int lastChange = 0;
do
{
byte[] b;
string eTag;
try
{
blob.FetchAttributes();
eTag = blob.Attributes.Properties.ETag;
if (eTag != oldEtag)
{
lastChange = Environment.TickCount;
oldEtag = eTag;
}
b = blob.DownloadByteArray();
}
catch (Exception)
{
throw e;
}
requestOpt.AccessCondition = AccessCondition.IfMatch(eTag);
if (b[0] == 0 || Environment.TickCount - lastChange > 3000) // on ne peut garder un lock plus de 3 s
{
try
{
blob.UploadByteArray(b1, requestOpt);
keepGoing = false;
}
catch (StorageClientException ex)
{
if (ex.ErrorCode != StorageErrorCode.ConditionFailed)
throw;
}
}
else
Thread.Sleep(50); // constante arbitraire
} while (keepGoing);
}
示例10: ReadFromAzureBlob
/// <summary>
/// Read a data table from azure blob. This will read the entire blob into memory and return a mutable data table.
/// </summary>
/// <param name="builder">builder</param>
/// <param name="container">conatiner</param>
/// <param name="blobName">blob name</param>
/// <returns>in-memory mutable datatable from blob</returns>
public static MutableDataTable ReadFromAzureBlob(this DataTableBuilder builder, CloudBlobContainer container, string blobName)
{
CloudBlob blob = container.GetBlobReference(blobName);
if (!Exists(blob))
{
string containerName = container.Name;
string accountName = container.ServiceClient.Credentials.AccountName;
throw new FileNotFoundException(string.Format("container.blob {0}.{0} does not exist on the storage account '{2}'", containerName, blobName, accountName));
}
// We're returning a MutableDataTable (which is in-memory) anyways, so fine to download into an in-memory buffer.
// Avoid downloading to a file because Azure nodes may not have a local file resource.
string content = blob.DownloadText();
var stream = new StringReader(content);
return DataTable.New.Read(stream);
}
示例11: SetUp
public void SetUp()
{
blobSettings = new LeaseBlockBlobSettings
{
ConnectionString = "UseDevelopmentStorage=true",
ContainerName = "test" + Guid.NewGuid().ToString("N"),
BlobPath = "lease.blob",
ReAquirePreviousTestLease = false,
RetryCount = 2,
RetryInterval = TimeSpan.FromMilliseconds(250)
};
maximumStopDurationEstimateSeconds = 10;
var storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
var client = storageAccount.CreateCloudBlobClient();
container = client.GetContainerReference(blobSettings.ContainerName);
container.CreateIfNotExist();
leaseBlob = container.GetBlobReference(blobSettings.BlobPath);
leaseBlob.UploadByteArray(new byte[0]);
}
示例12: DownloadText
public string DownloadText(CloudBlobContainer cloudBlobContainer, string blobName)
{
return cloudBlobContainer.GetBlobReference(blobName).DownloadText();
}
示例13: DownloadByteArray
public byte[] DownloadByteArray(CloudBlobContainer cloudBlobContainer, string blobName)
{
return cloudBlobContainer.GetBlobReference(blobName).DownloadByteArray();
}
示例14: DeleteIfExists
public bool DeleteIfExists(CloudBlobContainer cloudBlobContainer, string blobName)
{
return cloudBlobContainer.GetBlobReference(blobName).DeleteIfExists();
}
示例15: Rename
public bool Rename(CloudBlobContainer cloudBlobContainer, string oldBlobName, string newBlobName)
{
var oldCloudBlob = cloudBlobContainer.GetBlobReference(oldBlobName);
cloudBlobContainer.GetBlobReference(newBlobName).CopyFromBlob(oldCloudBlob);
return oldCloudBlob.DeleteIfExists();
}