本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.GetBlobReferenceFromServer方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlobClient.GetBlobReferenceFromServer方法的具体用法?C# CloudBlobClient.GetBlobReferenceFromServer怎么用?C# CloudBlobClient.GetBlobReferenceFromServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient
的用法示例。
在下文中一共展示了CloudBlobClient.GetBlobReferenceFromServer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeletePackageFromBlob
public static void DeletePackageFromBlob(IServiceManagement channel, string storageName, string subscriptionId, Uri packageUri)
{
var storageService = channel.GetStorageKeys(subscriptionId, storageName);
var storageKey = storageService.StorageServiceKeys.Primary;
storageService = channel.GetStorageService(subscriptionId, storageName);
var blobStorageEndpoint = new Uri(storageService.StorageServiceProperties.Endpoints.Find(p => p.Contains(BlobEndpointIdentifier)));
var credentials = new StorageCredentials(storageName, storageKey);
var client = new CloudBlobClient(blobStorageEndpoint, credentials);
ICloudBlob blob = client.GetBlobReferenceFromServer(packageUri);
blob.DeleteIfExists();
}
示例2: DeletePackageFromBlob
public void DeletePackageFromBlob(string storageName, Uri packageUri)
{
StorageAccountGetKeysResponse keys = StorageManagementClient.StorageAccounts.GetKeys(storageName);
string storageKey = keys.PrimaryKey;
var storageService = StorageManagementClient.StorageAccounts.Get(storageName);
var blobStorageEndpoint = storageService.StorageAccount.Properties.Endpoints[0];
var credentials = new StorageCredentials(storageName, storageKey);
var client = new CloudBlobClient(blobStorageEndpoint, credentials);
ICloudBlob blob = client.GetBlobReferenceFromServer(packageUri);
blob.DeleteIfExists();
}
示例3: RemoveVHD
public static void RemoveVHD(IServiceManagement channel, string subscriptionId, Uri mediaLink)
{
var accountName = mediaLink.Host.Split('.')[0];
var blobEndpoint = new Uri(mediaLink.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped));
StorageService storageService;
using (new OperationContextScope(channel.ToContextChannel()))
{
storageService = channel.GetStorageKeys(subscriptionId, accountName);
}
var storageAccountCredentials = new StorageCredentials(accountName, storageService.StorageServiceKeys.Primary);
var client = new CloudBlobClient(blobEndpoint, storageAccountCredentials);
var blob = client.GetBlobReferenceFromServer(mediaLink);
blob.DeleteIfExists();
}
示例4: DownloadTestCredentials
public static void DownloadTestCredentials(string testEnvironment, string downloadDirectoryPath, string blobUri, string storageAccount, string storageKey)
{
string containerPath = string.Format(EnvironmentPathFormat, testEnvironment);
StorageCredentials credentials = new StorageCredentials(storageAccount, storageKey);
CloudBlobClient blobClient = new CloudBlobClient(new Uri(blobUri), credentials);
CloudBlobContainer container = blobClient.GetContainerReference(containerPath);
foreach (IListBlobItem blobItem in container.ListBlobs())
{
ICloudBlob blob = blobClient.GetBlobReferenceFromServer(blobItem.Uri);
Console.WriteLine("Downloading file {0} from blob Uri {1}", blob.Name, blob.Uri);
FileStream blobStream = new FileStream(Path.Combine(downloadDirectoryPath, blob.Name), FileMode.Create);
blob.DownloadToStream(blobStream);
blobStream.Flush();
blobStream.Close();
}
}
示例5: DownloadTestVhdsAndPackages
private static void DownloadTestVhdsAndPackages(string testEnvironment, string downloadDirectoryPath, string blobUri, string storageAccount, string storageKey)
{
StorageCredentials credentials = new StorageCredentials(storageAccount, storageKey);
CloudBlobClient blobClient = new CloudBlobClient(new Uri(blobUri), credentials);
blobContainer = blobClient.GetContainerReference(VhdFilesContainerName);
foreach (IListBlobItem blobItem in blobContainer.ListBlobs())
{
ICloudBlob blob = blobClient.GetBlobReferenceFromServer(blobItem.Uri);
Console.WriteLine("Downloading file {0} from blob Uri {1}", blob.Name, blob.Uri);
FileStream blobStream = new FileStream(Path.Combine(downloadDirectoryPath, blob.Name), FileMode.Create);
blob.DownloadToStream(blobStream);
blobStream.Flush();
blobStream.Close();
}
blobContainer = blobClient.GetContainerReference(toolsContainerName);
foreach (IListBlobItem blobItem in blobContainer.ListBlobs())
{
ICloudBlob blob = blobClient.GetBlobReferenceFromServer(blobItem.Uri);
Console.WriteLine("Downloading file {0} from blob Uri {1}", blob.Name, blob.Uri);
FileStream blobStream = new FileStream(Path.Combine(downloadDirectoryPath, @"..\..\", blob.Name), FileMode.Create);
blob.DownloadToStream(blobStream);
blobStream.Flush();
blobStream.Close();
}
}
示例6: CloudBlobContainerGetBlobReferenceFromServer
public void CloudBlobContainerGetBlobReferenceFromServer()
{
CloudBlobContainer container = GetRandomContainerReference();
try
{
container.Create();
SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy()
{
Permissions = SharedAccessBlobPermissions.Read,
SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
};
CloudBlockBlob blockBlob = container.GetBlockBlobReference("bb");
blockBlob.PutBlockList(new string[] { });
CloudPageBlob pageBlob = container.GetPageBlobReference("pb");
pageBlob.Create(0);
CloudAppendBlob appendBlob = container.GetAppendBlobReference("ab");
appendBlob.CreateOrReplace();
CloudBlobClient client;
ICloudBlob blob;
blob = container.GetBlobReferenceFromServer("bb");
Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob));
Assert.IsTrue(blob.StorageUri.Equals(blockBlob.StorageUri));
CloudBlockBlob blockBlobSnapshot = ((CloudBlockBlob)blob).CreateSnapshot();
blob.SetProperties();
Uri blockBlobSnapshotUri = new Uri(blockBlobSnapshot.Uri.AbsoluteUri + "?snapshot=" + blockBlobSnapshot.SnapshotTime.Value.UtcDateTime.ToString("o"));
blob = container.ServiceClient.GetBlobReferenceFromServer(blockBlobSnapshotUri);
AssertAreEqual(blockBlobSnapshot.Properties, blob.Properties);
Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(blockBlobSnapshot.Uri));
Assert.IsNull(blob.StorageUri.SecondaryUri);
blob = container.GetBlobReferenceFromServer("pb");
Assert.IsInstanceOfType(blob, typeof(CloudPageBlob));
Assert.IsTrue(blob.StorageUri.Equals(pageBlob.StorageUri));
CloudPageBlob pageBlobSnapshot = ((CloudPageBlob)blob).CreateSnapshot();
blob.SetProperties();
Uri pageBlobSnapshotUri = new Uri(pageBlobSnapshot.Uri.AbsoluteUri + "?snapshot=" + pageBlobSnapshot.SnapshotTime.Value.UtcDateTime.ToString("o"));
blob = container.ServiceClient.GetBlobReferenceFromServer(pageBlobSnapshotUri);
AssertAreEqual(pageBlobSnapshot.Properties, blob.Properties);
Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(pageBlobSnapshot.Uri));
Assert.IsNull(blob.StorageUri.SecondaryUri);
blob = container.GetBlobReferenceFromServer("ab");
Assert.IsInstanceOfType(blob, typeof(CloudAppendBlob));
Assert.IsTrue(blob.StorageUri.Equals(appendBlob.StorageUri));
CloudAppendBlob appendBlobSnapshot = ((CloudAppendBlob)blob).CreateSnapshot();
blob.SetProperties();
Uri appendBlobSnapshotUri = new Uri(appendBlobSnapshot.Uri.AbsoluteUri + "?snapshot=" + appendBlobSnapshot.SnapshotTime.Value.UtcDateTime.ToString("o"));
blob = container.ServiceClient.GetBlobReferenceFromServer(appendBlobSnapshotUri);
AssertAreEqual(appendBlobSnapshot.Properties, blob.Properties);
Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(appendBlobSnapshot.Uri));
Assert.IsNull(blob.StorageUri.SecondaryUri);
blob = container.ServiceClient.GetBlobReferenceFromServer(blockBlob.Uri);
Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob));
Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(blockBlob.Uri));
Assert.IsNull(blob.StorageUri.SecondaryUri);
blob = container.ServiceClient.GetBlobReferenceFromServer(pageBlob.Uri);
Assert.IsInstanceOfType(blob, typeof(CloudPageBlob));
Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(pageBlob.Uri));
Assert.IsNull(blob.StorageUri.SecondaryUri);
blob = container.ServiceClient.GetBlobReferenceFromServer(appendBlob.Uri);
Assert.IsInstanceOfType(blob, typeof(CloudAppendBlob));
Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(appendBlob.Uri));
Assert.IsNull(blob.StorageUri.SecondaryUri);
blob = container.ServiceClient.GetBlobReferenceFromServer(blockBlob.StorageUri);
Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob));
Assert.IsTrue(blob.StorageUri.Equals(blockBlob.StorageUri));
blob = container.ServiceClient.GetBlobReferenceFromServer(pageBlob.StorageUri);
Assert.IsInstanceOfType(blob, typeof(CloudPageBlob));
Assert.IsTrue(blob.StorageUri.Equals(pageBlob.StorageUri));
blob = container.ServiceClient.GetBlobReferenceFromServer(appendBlob.StorageUri);
Assert.IsInstanceOfType(blob, typeof(CloudAppendBlob));
Assert.IsTrue(blob.StorageUri.Equals(appendBlob.StorageUri));
string blockBlobToken = blockBlob.GetSharedAccessSignature(policy);
StorageCredentials blockBlobSAS = new StorageCredentials(blockBlobToken);
Uri blockBlobSASUri = blockBlobSAS.TransformUri(blockBlob.Uri);
StorageUri blockBlobSASStorageUri = blockBlobSAS.TransformUri(blockBlob.StorageUri);
string pageBlobToken = pageBlob.GetSharedAccessSignature(policy);
StorageCredentials pageBlobSAS = new StorageCredentials(pageBlobToken);
Uri pageBlobSASUri = pageBlobSAS.TransformUri(pageBlob.Uri);
StorageUri pageBlobSASStorageUri = pageBlobSAS.TransformUri(pageBlob.StorageUri);
string appendBlobToken = appendBlob.GetSharedAccessSignature(policy);
//.........这里部分代码省略.........
示例7: CloudBlobContainerGetBlobReferenceFromServer
public void CloudBlobContainerGetBlobReferenceFromServer()
{
CloudBlobContainer container = GetRandomContainerReference();
try
{
container.Create();
SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy()
{
Permissions = SharedAccessBlobPermissions.Read,
SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
};
CloudBlockBlob blockBlob = container.GetBlockBlobReference("bb");
blockBlob.PutBlockList(new string[] { });
CloudPageBlob pageBlob = container.GetPageBlobReference("pb");
pageBlob.Create(0);
ICloudBlob blob1 = container.GetBlobReferenceFromServer("bb");
Assert.IsInstanceOfType(blob1, typeof(CloudBlockBlob));
CloudBlockBlob blob1Snapshot = ((CloudBlockBlob)blob1).CreateSnapshot();
blob1.SetProperties();
Uri blob1SnapshotUri = new Uri(blob1Snapshot.Uri.AbsoluteUri + "?snapshot=" + blob1Snapshot.SnapshotTime.Value.UtcDateTime.ToString("o"));
ICloudBlob blob1SnapshotReference = container.ServiceClient.GetBlobReferenceFromServer(blob1SnapshotUri);
AssertAreEqual(blob1Snapshot.Properties, blob1SnapshotReference.Properties);
ICloudBlob blob2 = container.GetBlobReferenceFromServer("pb");
Assert.IsInstanceOfType(blob2, typeof(CloudPageBlob));
CloudPageBlob blob2Snapshot = ((CloudPageBlob)blob2).CreateSnapshot();
blob2.SetProperties();
Uri blob2SnapshotUri = new Uri(blob2Snapshot.Uri.AbsoluteUri + "?snapshot=" + blob2Snapshot.SnapshotTime.Value.UtcDateTime.ToString("o"));
ICloudBlob blob2SnapshotReference = container.ServiceClient.GetBlobReferenceFromServer(blob2SnapshotUri);
AssertAreEqual(blob2Snapshot.Properties, blob2SnapshotReference.Properties);
ICloudBlob blob3 = container.ServiceClient.GetBlobReferenceFromServer(blockBlob.Uri);
Assert.IsInstanceOfType(blob3, typeof(CloudBlockBlob));
ICloudBlob blob4 = container.ServiceClient.GetBlobReferenceFromServer(pageBlob.Uri);
Assert.IsInstanceOfType(blob4, typeof(CloudPageBlob));
string blockBlobToken = blockBlob.GetSharedAccessSignature(policy);
StorageCredentials blockBlobSAS = new StorageCredentials(blockBlobToken);
Uri blockBlobSASUri = blockBlobSAS.TransformUri(blockBlob.Uri);
string pageBlobToken = pageBlob.GetSharedAccessSignature(policy);
StorageCredentials pageBlobSAS = new StorageCredentials(pageBlobToken);
Uri pageBlobSASUri = pageBlobSAS.TransformUri(pageBlob.Uri);
ICloudBlob blob5 = container.ServiceClient.GetBlobReferenceFromServer(blockBlobSASUri);
Assert.IsInstanceOfType(blob5, typeof(CloudBlockBlob));
ICloudBlob blob6 = container.ServiceClient.GetBlobReferenceFromServer(pageBlobSASUri);
Assert.IsInstanceOfType(blob6, typeof(CloudPageBlob));
CloudBlobClient client7 = new CloudBlobClient(container.ServiceClient.BaseUri, blockBlobSAS);
ICloudBlob blob7 = client7.GetBlobReferenceFromServer(blockBlobSASUri);
Assert.IsInstanceOfType(blob7, typeof(CloudBlockBlob));
CloudBlobClient client8 = new CloudBlobClient(container.ServiceClient.BaseUri, pageBlobSAS);
ICloudBlob blob8 = client8.GetBlobReferenceFromServer(pageBlobSASUri);
Assert.IsInstanceOfType(blob8, typeof(CloudPageBlob));
}
finally
{
container.DeleteIfExists();
}
}
示例8: Start
/// <summary>
/// Begins orchestration of bootstrapper tasks.
/// </summary>
/// <param name="args">The validated args parsed from the commmand line.</param>
public void Start(BootStrapperArgs args)
{
if (RoleEnvironment.IsAvailable && RoleEnvironment.IsEmulated && !args.RunInEmulator)
{
// Skip running if under emulator
return;
}
try
{
Client = String.IsNullOrEmpty(args.StorageConnection) ? null : CloudStorageAccount.Parse(args.StorageConnection).CreateCloudBlobClient();
}
catch (Exception ex)
{
throw new ArgumentException("The Azure storage connection string is not valid: " + ex.Message, args.StorageConnection);
}
//download package (if not previously downloaded). RunAlways forces download always.
Uri targetUri = null;
String package = null;
if ( !String.IsNullOrEmpty(args.Get) )
{
Uri urlToDownload = null;
//if a storage account is present generate a SAS for the get
if (Client != null)
{
//x| var account = CloudStorageAccount.Parse(args.StorageConnection);
//x| var client = account.CreateCloudBlobClient();
//TODO BASEURI THING
// MAKE
var uri = new Uri(Client.BaseUri, args.Get);
var reference = Client.GetBlobReferenceFromServer(uri);
var sas = reference.GetSharedAccessSignature(
new SharedAccessBlobPolicy()
{
Permissions = SharedAccessBlobPermissions.Read,
SharedAccessExpiryTime = DateTime.Now.AddMinutes(10)
});
urlToDownload = new Uri(reference.Uri, sas);
}
else //otherwise, this is a standard get
{
if (!Uri.TryCreate(args.Get, UriKind.Absolute, out urlToDownload))
throw new ArgumentException("Invalid Uri", "args.Get");
}
//always download as a get
package = this.downloader.DownloadPackageToDisk(
urlToDownload,
args.RunAlways,
args.LocalResource
);
//Unzip without replace. RunAlways forces unzip with replace
if (args.Unzip)
{
this.unzipper.Unzip(package, args.UnzipTarget, args.RunAlways);
}
}
if ( !String.IsNullOrEmpty(args.Put) )
{
if ( Client != null )
{
try {
var uri = new Uri(Client.BaseUri, args.Put);
var blob = Client.GetBlobReferenceFromServer(uri);
blob.Container.CreateIfNotExists();
String target = blob.GetSharedAccessSignature(
new SharedAccessBlobPolicy() {
Permissions = SharedAccessBlobPermissions.Write,
SharedAccessExpiryTime = DateTime.Now.AddMinutes(30)
});
if (args.Overwrite)
blob.DeleteIfExists();
targetUri = new Uri(blob.Uri, target);
}
catch ( StorageException ex ) {
if (Uri.IsWellFormedUriString(args.Put, UriKind.Relative))
throw new ArgumentException(
"A valid connection string to Azure blob storage must be supplied when uploading to a relative URL.\n" + ex.Message,
args.StorageConnection);
}
}
if ( targetUri == null ) //i| fall back on standard put.
{
if ( !Uri.TryCreate(args.Put, UriKind.Absolute, out targetUri) )
throw new ArgumentException("Invalid URL was supplied for the PUT argument.", args.Put);
}
//i| Only package when we don't have a filename (didn't get), and the local resource is an existing folder.
//.........这里部分代码省略.........