本文整理汇总了C#中Microsoft.WindowsAzure.StorageClient.CloudBlobContainer.GetPermissions方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlobContainer.GetPermissions方法的具体用法?C# CloudBlobContainer.GetPermissions怎么用?C# CloudBlobContainer.GetPermissions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.StorageClient.CloudBlobContainer
的用法示例。
在下文中一共展示了CloudBlobContainer.GetPermissions方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Storage
public Storage(CloudStorageAccount account)
{
this.account = account;
fileStorage = account.CreateCloudBlobClient();
/* Initialize file container */
container = fileStorage.GetContainerReference(filesContainer);
container.CreateIfNotExist();
var permissions = container.GetPermissions();
/* Full permissions. From MSDN, Container-level public access. Anonymous clients can
* read blob content and metadata and container metadata, and can list the blobs within the container.
*
* Other alternatives are Blob (can read content but not metadata) and Off (no
* anonymous access).
*/
// permissions.PublicAccess = BlobContainerPublicAccessType.Container;
permissions.PublicAccess = BlobContainerPublicAccessType.Off;
permissions.SharedAccessPolicies.Remove("basic");
permissions.SharedAccessPolicies.Add("basic", new SharedAccessPolicy()
{
});
container.SetPermissions(permissions);
/* Initialize table (for file metadata) */
CloudTableClient.CreateTablesFromModel(
typeof(FileDataContext),
account.TableEndpoint.AbsoluteUri,
account.Credentials);
}
示例2: OnStart
public override bool OnStart()
{
// Set the maximum number of concurrent connections
ServicePointManager.DefaultConnectionLimit = 100;
//Initialize Indexer
storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("CrawlerStorage"));
//Initialize URL Queue
urlQueueClient = storageAccount.CreateCloudQueueClient();
urlQueue = urlQueueClient.GetQueueReference("urlqueue");
if (urlQueue.CreateIfNotExist())
{
//Add first URL to the queue
CloudQueueMessage firstURL = new CloudQueueMessage(startURL);
urlQueue.AddMessage(firstURL);
}
//Initialize Index Queue
indexQueueClient = storageAccount.CreateCloudQueueClient();
indexQueue = indexQueueClient.GetQueueReference("indexqueue");
indexQueue.CreateIfNotExist();
//Initialize Database Blob
databaseClient = storageAccount.CreateCloudBlobClient();
databaseContainer = databaseClient.GetContainerReference("wordfrequencies");
databaseContainer.CreateIfNotExist();
var permission = databaseContainer.GetPermissions();
permission.PublicAccess = BlobContainerPublicAccessType.Container;
databaseContainer.SetPermissions(permission);
return base.OnStart();
}
示例3: CreateIfNotExist
public void CreateIfNotExist(CloudBlobContainer cloudBlobContainer, bool isPublic = true)
{
cloudBlobContainer.CreateIfNotExist();
var permission = cloudBlobContainer.GetPermissions();
var blobContainerPermissions = new BlobContainerPermissions {PublicAccess = isPublic ? BlobContainerPublicAccessType.Container : BlobContainerPublicAccessType.Off};
cloudBlobContainer.SetPermissions(blobContainerPermissions);
}
示例4: OnStart
public override bool OnStart()
{
// Set the maximum number of concurrent connections
ServicePointManager.DefaultConnectionLimit = 12;
DiagnosticMonitor.Start("DiagnosticsConnectionString");
// For information on handling configuration changes
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
RoleEnvironment.Changing += RoleEnvironmentChanging;
// read storage account configuration settings
CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter)
=> configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)));
var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
// initialize blob storage
CloudBlobClient blobStorage = storageAccount.CreateCloudBlobClient();
container = blobStorage.GetContainerReference("converteddata");
// initialize queue storage
CloudQueueClient queueStorage = storageAccount.CreateCloudQueueClient();
queue = queueStorage.GetQueueReference("workercommands");
Trace.TraceInformation("Creating container and queue...");
bool storageInitialized = false;
while (!storageInitialized)
{
try
{
// create the blob container and allow public access
container.CreateIfNotExist();
var permissions = container.GetPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
container.SetPermissions(permissions);
// create the message queue
queue.CreateIfNotExist();
storageInitialized = true;
}
catch (StorageClientException e)
{
if (e.ErrorCode == StorageErrorCode.TransportError)
{
Trace.TraceError("Storage services initialization failure. "
+ "Check your storage account configuration settings. If running locally, "
+ "ensure that the Development Storage service is running. Message: '{0}'", e.Message);
Thread.Sleep(5000);
}
else
{
throw;
}
}
}
return base.OnStart();
}
示例5: OnStart
public override bool OnStart()
{
//Initialize Indexer
storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("CrawlerStorage"));
//Initialize Database Blob
databaseClient = storageAccount.CreateCloudBlobClient();
databaseContainer = databaseClient.GetContainerReference("wordfrequencies");
databaseContainer.CreateIfNotExist();
var permission = databaseContainer.GetPermissions();
permission.PublicAccess = BlobContainerPublicAccessType.Container;
databaseContainer.SetPermissions(permission);
return base.OnStart();
}
示例6: InitAzureStorage
/// <summary>
/// Init Azure Storage if needed
/// </summary>
private static void InitAzureStorage()
{
if (storageAccount == null)
{
storageAccount = CloudStorageAccount.FromConfigurationSetting(connectionString);
if (blobClient == null)
{
blobClient = storageAccount.CreateCloudBlobClient();
blobContainer = blobClient.GetContainerReference(FilesFolder);
blobContainer.CreateIfNotExist();
var permissions = blobContainer.GetPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
blobContainer.SetPermissions(permissions);
}
}
}
示例7: InitializeStorage
private void InitializeStorage()
{
if (storageInitialized)
{
return;
}
lock (gate)
{
if (storageInitialized)
{
return;
}
try
{
// read account configuration settings
CloudStorageAccount storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
CloudBlobClient blobStorage = storageAccount.CreateCloudBlobClient();
blobContainer = blobStorage.GetContainerReference(blobContainerAddress);
blobContainer.CreateIfNotExist();
// configure container for public access
BlobContainerPermissions permissions = blobContainer.GetPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
blobContainer.SetPermissions(permissions);
// create queue to communicate with worker role
queueClient = storageAccount.CreateCloudQueueClient();
CloudQueue requestQueue = queueClient.GetQueueReference(requestQueueAddress);
requestQueue.CreateIfNotExist();
CloudQueue responseQueue = queueClient.GetQueueReference(responseQueueAddress);
responseQueue.CreateIfNotExist();
}
catch (WebException)
{
throw new WebException("Storage services initialization failure. "
+ "Check your storage account configuration settings. If running locally, "
+ "ensure that the Development Storage service is running.");
}
storageInitialized = true;
}
}
示例8: SetReadOnlySharedAccessPolicy
private static void SetReadOnlySharedAccessPolicy(CloudBlobContainer container)
{
var blobSASExperiationTime = int.Parse(ConfigReader.GetConfigValue("BlobSASExperiationTime"), NumberStyles.Integer, CultureInfo.InvariantCulture);
var permissions = container.GetPermissions();
var options = new BlobRequestOptions
{
// Fail if someone else has already changed the container before we do.
AccessCondition = AccessCondition.IfMatch(container.Properties.ETag)
};
var sharedAccessPolicy = new SharedAccessPolicy
{
Permissions = SharedAccessPermissions.Read,
SharedAccessExpiryTime = DateTime.UtcNow + TimeSpan.FromDays(blobSASExperiationTime)
};
permissions.SharedAccessPolicies.Remove("readonly");
permissions.SharedAccessPolicies.Add("readonly", sharedAccessPolicy);
container.SetPermissions(permissions, options);
}
示例9: SetReadOnlySharedAccessPolicy
private static void SetReadOnlySharedAccessPolicy(CloudBlobContainer container)
{
var permissions = container.GetPermissions();
var options = new BlobRequestOptions
{
// Fail if someone else has already changed the container before we do.
AccessCondition = AccessCondition.IfMatch(container.Properties.ETag)
};
var sharedAccessPolicy = new SharedAccessPolicy
{
Permissions = SharedAccessPermissions.Read,
SharedAccessExpiryTime = DateTime.UtcNow + TimeSpan.FromDays(StorageServicesContext.Current.Configuration.BlobsSasExpirationTime)
};
permissions.SharedAccessPolicies.Remove("readonly");
permissions.SharedAccessPolicies.Add("readonly", sharedAccessPolicy);
container.SetPermissions(permissions, options);
}
示例10: CheckContainer
private void CheckContainer(string containerConfigName)
{
// Get a handle on account, create a blob service client and get container proxy
storageAccount = CloudStorageAccount.FromConfigurationSetting("BlobConnectionString");
blobStorageClient = storageAccount.CreateCloudBlobClient();
containerName = RoleEnvironment.GetConfigurationSettingValue(containerConfigName);
blobExcelContainer = blobStorageClient.GetContainerReference(containerName);
blobExcelContainer.CreateIfNotExist();
var permissions = blobExcelContainer.GetPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
blobExcelContainer.SetPermissions(permissions);
}
示例11: OnStart
public override bool OnStart( )
{
DiagnosticMonitor.Start( "DiagnosticsConnectionString" );
RoleEnvironment.Changing += new EventHandler<RoleEnvironmentChangingEventArgs>( RoleEnvironmentChanging );
CloudStorageAccount.SetConfigurationSettingPublisher( ( configName, configSetter ) => configSetter( RoleEnvironment.GetConfigurationSettingValue( configName ) ) );
CloudStorageAccount storageAccount = CloudStorageAccount.FromConfigurationSetting( "DataConnectionString" );
container = storageAccount.CreateCloudBlobClient( ).GetContainerReference( "fotogolpics" );
queue = storageAccount.CreateCloudQueueClient( ).GetQueueReference( "fotogolthumbs" );
Trace.TraceInformation( "Creating container and queue..." );
bool storageInitialized = false;
while ( !storageInitialized )
{
try
{
container.CreateIfNotExist( );
BlobContainerPermissions permissions = container.GetPermissions( );
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
container.SetPermissions( permissions );
queue.CreateIfNotExist( );
storageInitialized = true;
}
catch ( StorageClientException e )
{
if ( e.ErrorCode != StorageErrorCode.TransportError )
throw;
Trace.TraceError( "Storage services initialization failure. Check your storage account configuration settings. If running locally, ensure that the Development Storage service is running. Message: '{0}'", new object[] { e.Message } );
Thread.Sleep( 5000 );
}
}
return base.OnStart( );
}
示例12: Save
public Uri Save(bool test, Stream s, string blobName, string fileExtention, string fileContentType)
{
CloudStorageAccount storageAccount;
if (test)
{
storageAccount = CloudStorageAccount.FromConfigurationSetting("BlobConnectionString");
}
else
{
storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("BlobConnectionString"));
}
//storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=vestnstorage;AccountKey=OCZoZBQegbepYCxWNoOLYLkSBg461Bo0cac2F6Q9hpOwiOykYZmgwb5EsGgJWUfPuC3kalOuNk1Dp0C0HXsRaQ==");
blobClient = storageAccount.CreateCloudBlobClient();
blobContainer = blobClient.GetContainerReference(blobName);
blobContainer.CreateIfNotExist();
var permissions = blobContainer.GetPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
blobContainer.SetPermissions(permissions);
return AddBlob(fileExtention, fileContentType, s, blobName);
}