本文整理汇总了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;
}
}