本文整理匯總了C#中Microsoft.WindowsAzure.Storage.Table.CloudTable.GetPermissionsAsync方法的典型用法代碼示例。如果您正苦於以下問題:C# CloudTable.GetPermissionsAsync方法的具體用法?C# CloudTable.GetPermissionsAsync怎麽用?C# CloudTable.GetPermissionsAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Microsoft.WindowsAzure.Storage.Table.CloudTable
的用法示例。
在下文中一共展示了CloudTable.GetPermissionsAsync方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: TableAclSample
/// <summary>
/// Manage stored access policies specified on the table
/// </summary>
/// <param name="table"></param>
/// <returns></returns>
private static async Task TableAclSample(CloudTable table)
{
// Set table permissions
SharedAccessTablePolicy accessTablePolicy = new SharedAccessTablePolicy();
accessTablePolicy.SharedAccessStartTime = new DateTimeOffset(DateTime.Now);
accessTablePolicy.SharedAccessExpiryTime = new DateTimeOffset(DateTime.Now.AddMinutes(10));
accessTablePolicy.Permissions = SharedAccessTablePermissions.Update;
TablePermissions permissions = new TablePermissions();
permissions.SharedAccessPolicies.Add("key1", accessTablePolicy);
Console.WriteLine("Set table permissions");
await table.SetPermissionsAsync(permissions);
// Get table permissions
Console.WriteLine("Get table permissions:");
permissions = await table.GetPermissionsAsync();
foreach (var keyValue in permissions.SharedAccessPolicies)
{
Console.WriteLine(" {0}:", keyValue.Key);
Console.WriteLine(" permissions: {0}:", keyValue.Value.Permissions);
Console.WriteLine(" start time: {0}:", keyValue.Value.SharedAccessStartTime);
Console.WriteLine(" expiry time: {0}:", keyValue.Value.SharedAccessExpiryTime);
}
}
示例2: GetTablePermissionsAsync
/// <summary>
/// Return a task that asynchronously fetch table permissions
/// </summary>
/// <param name="table">target table</param>
/// <param name="requestOptions">request options</param>
/// <param name="operationContext">context</param>
/// <returns></returns>
public Task<TablePermissions> GetTablePermissionsAsync(CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext)
{
return table.GetPermissionsAsync(requestOptions, operationContext);
}
示例3: CreateSharedAccessPolicy
/// <summary>
/// Creates a shared access policy on the table.
/// </summary>
/// <param name="table">A CloudTable object.</param>
/// <param name="policyName">The name of the stored access policy.</param>
/// <returns>A Task object</returns>
private static async Task CreateSharedAccessPolicy(CloudTable table, string policyName)
{
// Create a new shared access policy and define its constraints.
// The access policy provides add, update, and query permissions.
SharedAccessTablePolicy sharedPolicy = new SharedAccessTablePolicy()
{
// Permissions enable users to add, update, query, and delete entities in the table.
SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24),
Permissions = SharedAccessTablePermissions.Add | SharedAccessTablePermissions.Update |
SharedAccessTablePermissions.Query | SharedAccessTablePermissions.Delete
};
try
{
// Get the table's existing permissions.
TablePermissions permissions = await table.GetPermissionsAsync();
// Add the new policy to the table's permissions, and update the table's permissions.
permissions.SharedAccessPolicies.Add(policyName, sharedPolicy);
await table.SetPermissionsAsync(permissions);
}
catch (StorageException e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
throw;
}
}