本文整理汇总了C#中StorageCredentials类的典型用法代码示例。如果您正苦于以下问题:C# StorageCredentials类的具体用法?C# StorageCredentials怎么用?C# StorageCredentials使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StorageCredentials类属于命名空间,在下文中一共展示了StorageCredentials类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SensorAccess
public SensorAccess()
{
credentials = new StorageCredentials(_accountName, _key);
storageAccount = new CloudStorageAccount(credentials, true);
tableClient = storageAccount.CreateCloudTableClient();
table = tableClient.GetTableReference("AccelerometerTable");
}
开发者ID:shijiong,项目名称:FallDetection,代码行数:7,代码来源:StorageSensor.cs
示例2: CloudQueueClient
/// <summary>Initializes a new instance of the <see cref="CloudQueueClient"/> class.</summary>
/// <param name="usePathStyleUris">True to use path style Uris. </param>
/// <param name="baseAddressUri">The base address Uri. </param>
/// <param name="credentials">The credentials. </param>
internal CloudQueueClient(bool? usePathStyleUris, Uri baseAddressUri, StorageCredentials credentials)
{
CommonUtils.AssertNotNull("baseAddress", baseAddressUri);
CommonUtils.AssertNotNull("credentials", credentials);
if (!credentials.CanSignRequest)
{
throw new ArgumentException(SR.CredentialsCantSignRequest, "credentials");
}
this.BaseUri = baseAddressUri;
if (!this.BaseUri.IsAbsoluteUri)
{
CommonUtils.ArgumentOutOfRange("baseAddress", baseAddressUri);
}
this.Timeout = Constants.DefaultClientSideTimeout;
this.RetryPolicy = RetryPolicies.RetryExponential(
RetryPolicies.DefaultClientRetryCount, RetryPolicies.DefaultClientBackoff);
this.Credentials = credentials;
// if use path style uris doesn't have a value, automatically decide whether to use host style uri or path style uri
this.UsePathStyleUris = usePathStyleUris.HasValue ? usePathStyleUris.Value : CommonUtils.UsePathStyleAddressing(this.BaseUri);
}
开发者ID:wforney,项目名称:azure-sdk-for-net,代码行数:29,代码来源:CloudQueueClient.cs
示例3: TableServiceContext
/// <summary>Initializes a new instance of the <see cref="TableServiceContext"/> class.</summary>
/// <param name="baseAddress">The Table service endpoint to use create the service context. </param>
/// <param name="credentials">The account credentials. </param>
public TableServiceContext(string baseAddress, StorageCredentials credentials)
: base(new Uri(baseAddress))
{
if (string.IsNullOrEmpty(baseAddress))
{
throw new ArgumentNullException("baseAddress");
}
if (credentials == null)
{
throw new ArgumentNullException("credentials");
}
if ((!credentials.CanSignRequest) || (!credentials.CanSignRequestLite))
{
throw new ArgumentException(SR.CredentialsCantSignRequest, "credentials");
}
this.SendingRequest += this.DataContextSendingRequest;
this.StorageCredentials = credentials;
this.IgnoreMissingProperties = true;
this.MergeOption = MergeOption.PreserveChanges;
this.RetryPolicy = RetryPolicies.RetryExponential(
RetryPolicies.DefaultClientRetryCount, RetryPolicies.DefaultClientBackoff);
this.Timeout = (int)TimeSpan.FromSeconds(90).TotalSeconds;
}
开发者ID:wforney,项目名称:azure-sdk-for-net,代码行数:31,代码来源:TableServiceContext.cs
示例4: TableStorageAppender
public TableStorageAppender(StorageCredentials credentials)
{
if (credentials.AccountName.StartsWith("devstoreaccount"))
StorageAccount = CloudStorageAccount.DevelopmentStorageAccount;
else
StorageAccount = new CloudStorageAccount(credentials, true);
TableName = "WADLogsTable";
TransferIntervalInMinutes = 5;
LogmarkerIntervalInMinutes = 30;
}
开发者ID:rajeshgupthar,项目名称:Ms.Azure.Logging,代码行数:10,代码来源:TableStorageAppender.cs
示例5: 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();
}
开发者ID:OctopusDeploy,项目名称:azure-sdk-tools,代码行数:11,代码来源:AzureBlob.cs
示例6: 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();
}
开发者ID:Viachaslau,项目名称:azure-sdk-tools,代码行数:16,代码来源:Disks.cs
示例7: CloudQueue
/// <summary>
/// Initializes a new instance of the <see cref="CloudQueue"/> class.
/// </summary>
/// <param name="usePathStyleUris">True to use path style Uris.</param>
/// <param name="address">The address.</param>
/// <param name="credentials">The credentials.</param>
internal CloudQueue(bool? usePathStyleUris, string address, StorageCredentials credentials)
{
CommonUtils.AssertNotNullOrEmpty("address", address);
CommonUtils.AssertNotNull("credentials", credentials);
if (!credentials.CanSignRequest)
{
throw new ArgumentException(SR.CredentialsCantSignRequest, "credentials");
}
this.EncodeMessage = true;
this.attributes = new QueueAttributes() { Uri = new Uri(address) };
string baseAddress = NavigationHelper.GetServiceClientBaseAddress(this.Uri, usePathStyleUris);
this.ServiceClient = new CloudQueueClient(baseAddress, credentials);
this.Name = NavigationHelper.GetQueueNameFromUri(this.Uri, this.ServiceClient.UsePathStyleUris);
}
开发者ID:nickchal,项目名称:pash,代码行数:24,代码来源:CloudQueue.cs
示例8: GetStorageCredentials
/// <summary>
/// Attempts to get the user's credentials from the given Storage Context or the current subscription, if the former is null.
/// Throws a terminating error if the credentials cannot be determined.
/// </summary>
public static StorageCredentials GetStorageCredentials(this ServiceManagementBaseCmdlet cmdlet, AzureStorageContext storageContext)
{
StorageCredentials credentials = null;
if (storageContext != null)
{
credentials = storageContext.StorageAccount.Credentials;
}
else
{
var storageAccountName = cmdlet.CurrentSubscription.CurrentStorageAccountName;
if (!string.IsNullOrEmpty(storageAccountName))
{
var keys = cmdlet.StorageClient.StorageAccounts.GetKeys(storageAccountName);
if (keys != null)
{
var storageAccountKey = string.IsNullOrEmpty(keys.PrimaryKey) ? keys.SecondaryKey : keys.PrimaryKey;
credentials = new StorageCredentials(storageAccountName, storageAccountKey);
}
}
}
if (credentials == null)
{
cmdlet.ThrowTerminatingError(
new ErrorRecord(
new UnauthorizedAccessException(Resources.AzureVMDscDefaultStorageCredentialsNotFound),
string.Empty,
ErrorCategory.PermissionDenied,
null));
}
if (string.IsNullOrEmpty(credentials.AccountName))
{
cmdlet.ThrowInvalidArgumentError(Resources.AzureVMDscStorageContextMustIncludeAccountName);
}
return credentials;
}
开发者ID:kangyangthu,项目名称:azure-sdk-tools,代码行数:46,代码来源:ServiceManagementBaseCmdletExtentions.cs
示例9: Storage
public Storage()
{
var accountName = WebConfigurationManager.AppSettings["AccountName"];
var accountKey = WebConfigurationManager.AppSettings["AccountKey"];
bool useHttps = WebConfigurationManager.AppSettings["DefaultEndpointsProtocol"].ToLower() == "https";
StorageCredentials credentials = new StorageCredentials(accountName, accountKey);
CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, useHttps);
// Create the blob client.
var blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
Messages = blobClient.GetContainerReference("messages");
Users = blobClient.GetContainerReference("users");
// Create the container if it doesn't already exist.
Messages.CreateIfNotExists();
Users.CreateIfNotExists();
}
开发者ID:nikkios,项目名称:SignalRChat,代码行数:21,代码来源:Storage.cs
示例10: RetrieveTable
internal List<ProductEntity> RetrieveTable()
{
StorageCredentials creds = new StorageCredentials(accountName, accountKey);
CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);
CloudTableClient tableClient = account.CreateCloudTableClient();
// Retrieve storage account from the connection string
// CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
// ConfigurationManager.ConnectionStrings["BlobStorageConnectionString"].ConnectionString);
// Create the table client
//CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
// Create the CloudTable object that represents the "product" table
CloudTable table = tableClient.GetTableReference("products");
// Construct the query operation for all product entities
TableQuery<ProductEntity> query = new TableQuery<ProductEntity>();
var products = table.ExecuteQuery(query).ToList();
return products;
}
开发者ID:Slettan,项目名称:ProductsAPI,代码行数:23,代码来源:ProductRepository.cs
示例11: GetSasUrlStr
protected string GetSasUrlStr(string storageName, string storageKey, string containerName, string blobName)
{
var cred = new StorageCredentials(storageName, storageKey);
var storageAccount = string.IsNullOrEmpty(this.StorageEndpointSuffix)
? new CloudStorageAccount(cred, true)
: new CloudStorageAccount(cred, this.StorageEndpointSuffix, true);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(containerName);
var cloudBlob = container.GetBlockBlobReference(blobName);
var sasToken = cloudBlob.GetSharedAccessSignature(
new SharedAccessBlobPolicy()
{
SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24.0),
Permissions = SharedAccessBlobPermissions.Read
});
// Try not to use a Uri object in order to keep the following
// special characters in the SAS signature section:
// '+' -> '%2B'
// '/' -> '%2F'
// '=' -> '%3D'
return cloudBlob.Uri + sasToken;
}
开发者ID:EmmaZhu,项目名称:azure-sdk-tools,代码行数:24,代码来源:SetAzureVMCustomScriptExtension.cs
示例12: CloudPageBlob
/// <summary>
/// Initializes a new instance of the <see cref="CloudPageBlob"/> class using an absolute URI to the blob.
/// </summary>
/// <param name="blobAddress">The absolute URI to the blob.</param>
/// <param name="credentials">The account credentials.</param>
public CloudPageBlob(string blobAddress, StorageCredentials credentials)
: base(blobAddress, credentials)
{
this.Properties.BlobType = BlobType.PageBlob;
}
开发者ID:aliakb,项目名称:azure-sdk-for-net,代码行数:10,代码来源:CloudPageBlob.cs
示例13: InitializeAzureTableLogging
/// <summary>
/// Initializes log4net with azure table logging.
/// </summary>
public static void InitializeAzureTableLogging(StorageCredentials credentials, string customTable = null, Level logLevel = null)
{
if (credentials.AccountName.StartsWith("devstoreaccount"))
InitializeAzureTableLogging(CloudStorageAccount.DevelopmentStorageAccount, customTable, logLevel);
else
InitializeAzureTableLogging(new CloudStorageAccount(credentials, true), customTable, logLevel);
}
开发者ID:rajeshgupthar,项目名称:Ms.Azure.Logging,代码行数:10,代码来源:LoggingHelper.cs
示例14: CloudBlob
/// <summary>
/// Initializes a new instance of the <see cref="CloudBlob"/> class using an absolute URI to the blob, and the snapshot timestamp,
/// if the blob is a snapshot.
/// </summary>
/// <param name="blobAbsoluteUri">The absolute URI to the blob.</param>
/// <param name="snapshotTime">The snapshot timestamp, if the blob is a snapshot.</param>
/// <param name="credentials">The account credentials.</param>
public CloudBlob(string blobAbsoluteUri, DateTime? snapshotTime, StorageCredentials credentials)
: this(blobAbsoluteUri, snapshotTime, new CloudBlobClient(NavigationHelper.GetServiceClientBaseAddress(blobAbsoluteUri, null), credentials))
{
}
开发者ID:rmarinho,项目名称:azure-sdk-for-net,代码行数:11,代码来源:CloudBlob.cs
示例15: SetupCommands
private void SetupCommands()
{
Add_Patient = new DelegateCommand(async () =>
{
Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 2);
MessageDialog mm = new MessageDialog("mission Started");
//await mm.ShowAsync();
// Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 2);
if (string.IsNullOrWhiteSpace(Pa.FName) ||
string.IsNullOrWhiteSpace(Pa.LName) ||
string.IsNullOrWhiteSpace(Pa.Gender) ||
string.IsNullOrWhiteSpace(Pa.MaritalStatus) ||
string.IsNullOrWhiteSpace(Pa.SocialID) ||
string.IsNullOrWhiteSpace(Pa.Email) ||
string.IsNullOrWhiteSpace(Pa.Phone))
{
//show message
mm = new MessageDialog("Please fill in all the fields");
await mm.ShowAsync();
return;
}
// Pa.Dob = Convert.ToDateTime(String.Format("{0:d}", Pa.Dob));
switch (Pa.Gender)
{
case "0":
Pa.Gender = "Male";
break;
case "1":
Pa.Gender = "Female";
break;
}
switch (Pa.MaritalStatus)
{
case "0":
Pa.MaritalStatus = "Single";
break;
case "1":
Pa.MaritalStatus = "Married";
break;
}
/////////////////////////////////////////////////////////////// save the image
string errorString = string.Empty;
if (media != null)
{
// Set blob properties of TodoItem.
Pa.ContainerName = "patientimagestorageimages";
Pa.ResourceName = media.Name;
}
else
{
if( Pa.Gender == "Male"){
var uri = new Uri("ms-appx:///Assets/Administrator-icon.png");
media = await StorageFile.GetFileFromApplicationUriAsync(uri);
Pa.ContainerName = "patientimagestorageimages";
Pa.ResourceName = media.Name;
}
else
{
var uri = new Uri("ms-appx:///Assets/Office-Girl-icon.png");
media = await StorageFile.GetFileFromApplicationUriAsync(uri);
Pa.ContainerName = "patientimagestorageimages";
Pa.ResourceName = media.Name;
}
}
/////////////////////////////////////////////////////////////////
try
{
await patientsTable.InsertAsync(Pa);
}
catch (Exception e)
{
mm = new MessageDialog("error occured");
mm.ShowAsync();
}
//if (media != null)
//{
if (!string.IsNullOrEmpty(Pa.SasQueryString))
{
using (var fileStream = await media.OpenStreamForReadAsync())
{
StorageCredentials cred = new StorageCredentials(Pa.SasQueryString);
//.........这里部分代码省略.........
开发者ID:Zainabalhaidary,项目名称:Clinic,代码行数:101,代码来源:PatientViewModel.cs
示例16: SharedKeyAuthenticationHttpHandler
public SharedKeyAuthenticationHttpHandler(ICanonicalizer canonicalizer, StorageCredentials credentials, string accountName)
{
this.canonicalizer = canonicalizer;
this.credentials = credentials;
this.accountName = accountName;
}
开发者ID:BurtHarris,项目名称:azure-storage-net,代码行数:6,代码来源:SharedKeyAuthenticationHttpHandler.cs
示例17: CloudBlobContainer
/// <summary>
/// Initializes a new instance of the <see cref="CloudBlobContainer"/> class.
/// </summary>
/// <param name="containerAddress">The absolute URI to the container.</param>
/// <param name="credentials">The account credentials.</param>
public CloudBlobContainer(string containerAddress, StorageCredentials credentials)
: this(containerAddress, new CloudBlobClient(NavigationHelper.GetServiceClientBaseAddress(containerAddress, null), credentials))
{
}
开发者ID:rmarinho,项目名称:azure-sdk-for-net,代码行数:9,代码来源:CloudBlobContainer.cs
示例18: CloudBlockBlob
/// <summary>
/// Initializes a new instance of the <see cref="CloudBlockBlob"/> class using an absolute URI to the blob.
/// </summary>
/// <param name="blobAbsoluteUri">The absolute URI to the blob.</param>
/// <param name="credentials">The account credentials.</param>
/// <param name="usePathStyleUris"><c>True</c> to use path-style URIs; otherwise, <c>false</c>.</param>
public CloudBlockBlob(string blobAbsoluteUri, StorageCredentials credentials, bool usePathStyleUris)
: base(blobAbsoluteUri, credentials, usePathStyleUris)
{
this.Properties.BlobType = BlobType.BlockBlob;
}
开发者ID:nagyist,项目名称:azure-sdk-for-mono,代码行数:11,代码来源:CloudBlockBlob.cs
示例19: BasicStorageBlockBlobOperationsWithAccountSASAsync
/// <summary>
/// Basic operations to work with block blobs
/// </summary>
/// <returns>Task<returns>
private static async Task BasicStorageBlockBlobOperationsWithAccountSASAsync()
{
const string imageToUpload = "HelloWorld.png";
string blockBlobContainerName = "demoblockblobcontainer-" + Guid.NewGuid();
// Call GetAccountSASToken to get a sasToken based on the Storage Account Key
string sasToken = GetAccountSASToken();
// Create an AccountSAS from the SASToken
StorageCredentials accountSAS = new StorageCredentials(sasToken);
//Informational: Print the Account SAS Signature and Token
Console.WriteLine();
Console.WriteLine("Account SAS Signature: " + accountSAS.SASSignature);
Console.WriteLine("Account SAS Token: " + accountSAS.SASToken);
Console.WriteLine();
// Create a container for organizing blobs within the storage account.
Console.WriteLine("1. Creating Container using Account SAS");
// Get the Container Uri by passing the Storage Account and the container Name
Uri ContainerUri = GetContainerSASUri(blockBlobContainerName);
// Create a CloudBlobContainer by using the Uri and the sasToken
CloudBlobContainer container = new CloudBlobContainer(ContainerUri, new StorageCredentials(sasToken));
try
{
await container.CreateIfNotExistsAsync();
}
catch (StorageException)
{
Console.WriteLine("If you are running with the default configuration please make sure you have started the storage emulator. Press the Windows key and type Azure Storage to select and run it from the list of applications - then restart the sample.");
Console.ReadLine();
throw;
}
// To view the uploaded blob in a browser, you have two options. The first option is to use a Shared Access Signature (SAS) token to delegate
// access to the resource. See the documentation links at the top for more information on SAS. The second approach is to set permissions
// to allow public access to blobs in this container. Uncomment the line below to use this approach. Then you can view the image
// using: https://[InsertYourStorageAccountNameHere].blob.core.windows.net/democontainer/HelloWorld.png
// await container.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
// Upload a BlockBlob to the newly created container
Console.WriteLine("2. Uploading BlockBlob");
CloudBlockBlob blockBlob = container.GetBlockBlobReference(imageToUpload);
await blockBlob.UploadFromFileAsync(imageToUpload, FileMode.Open);
// List all the blobs in the container
Console.WriteLine("3. List Blobs in Container");
foreach (IListBlobItem blob in container.ListBlobs())
{
// Blob type will be CloudBlockBlob, CloudPageBlob or CloudBlobDirectory
// Use blob.GetType() and cast to appropriate type to gain access to properties specific to each type
Console.WriteLine("- {0} (type: {1})", blob.Uri, blob.GetType());
}
// Download a blob to your file system
Console.WriteLine("4. Download Blob from {0}", blockBlob.Uri.AbsoluteUri);
await blockBlob.DownloadToFileAsync(string.Format("./CopyOf{0}", imageToUpload), FileMode.Create);
// Create a read-only snapshot of the blob
Console.WriteLine("5. Create a read-only snapshot of the blob");
CloudBlockBlob blockBlobSnapshot = await blockBlob.CreateSnapshotAsync(null, null, null, null);
// Clean up after the demo
Console.WriteLine("6. Delete block Blob and all of its snapshots");
await blockBlob.DeleteIfExistsAsync(DeleteSnapshotsOption.IncludeSnapshots, null, null, null);
Console.WriteLine("7. Delete Container");
await container.DeleteIfExistsAsync();
}
开发者ID:BarryBurke,项目名称:storage-blob-dotnet-getting-started,代码行数:76,代码来源:Program.cs
示例20: SharedKeyLiteAuthenticationHandler
public SharedKeyLiteAuthenticationHandler(ICanonicalizer canonicalizer, StorageCredentials credentials, string resourceAccountName)
{
this.canonicalizer = canonicalizer;
this.credentials = credentials;
this.resourceAccountName = resourceAccountName;
}
开发者ID:Juliako,项目名称:azure-sdk-for-net,代码行数:6,代码来源:SharedKeyLiteAuthenticationHandler.cs
注:本文中的StorageCredentials类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论