本文整理汇总了C#中Microsoft.WindowsAzure.Storage.CloudStorageAccount.CreateCloudFileClient方法的典型用法代码示例。如果您正苦于以下问题:C# CloudStorageAccount.CreateCloudFileClient方法的具体用法?C# CloudStorageAccount.CreateCloudFileClient怎么用?C# CloudStorageAccount.CreateCloudFileClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.CloudStorageAccount
的用法示例。
在下文中一共展示了CloudStorageAccount.CreateCloudFileClient方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AzureSession
public AzureSession(string connectionString, string shareName, string systemDir, int waitForLockMilliseconds = 5000, bool optimisticLocking = true,
bool enableCache = true, CacheEnum objectCachingDefaultPolicy = CacheEnum.Yes)
: base(systemDir, waitForLockMilliseconds, optimisticLocking, enableCache, objectCachingDefaultPolicy)
{
m_cloudStorageAccount = CloudStorageAccount.Parse(connectionString);
if (Path.IsPathRooted(systemDir) == false)
SystemDirectory = systemDir;
m_shareName = shareName;
m_cloudFileClient = m_cloudStorageAccount.CreateCloudFileClient();
m_cloudShare = m_cloudFileClient.GetShareReference(shareName);
if (m_cloudShare.Exists())
{
m_rootDir = m_cloudShare.GetRootDirectoryReference();
m_databaseDir = m_rootDir.GetDirectoryReference(systemDir);
m_databaseDir.CreateIfNotExists();
}
}
示例2: RunFileTest
public void RunFileTest(SharedAccessAccountPolicy policy, Action<Action> testHandler, int? httpsPort)
{
CloudFileClient fileClient = GenerateCloudFileClient();
string shareName = "s" + Guid.NewGuid().ToString("N");
try
{
CloudStorageAccount account = new CloudStorageAccount(fileClient.Credentials, false);
string accountSASToken = account.GetSharedAccessSignature(policy);
StorageCredentials accountSAS = new StorageCredentials(accountSASToken);
StorageUri storageUri = fileClient.StorageUri;
if (httpsPort != null)
{
storageUri = new StorageUri(TransformSchemeAndPort(storageUri.PrimaryUri, "https", httpsPort.Value), TransformSchemeAndPort(storageUri.SecondaryUri, "https", httpsPort.Value));
}
CloudStorageAccount accountWithSAS = new CloudStorageAccount(accountSAS, null, null, null, storageUri);
CloudFileClient fileClientWithSAS = accountWithSAS.CreateCloudFileClient();
CloudFileShare shareWithSAS = fileClientWithSAS.GetShareReference(shareName);
CloudFileShare share = fileClient.GetShareReference(shareName);
share.Create();
string fileName = "file";
CloudFile file = share.GetRootDirectoryReference().GetFileReference(fileName);
CloudFile fileWithSAS = shareWithSAS.GetRootDirectoryReference().GetFileReference(fileName);
byte[] content = new byte[] { 0x1, 0x2, 0x3, 0x4 };
file.Create(content.Length);
using (Stream stream = new MemoryStream(content))
{
file.WriteRange(stream, 0);
}
testHandler(() =>
{
byte[] result = new byte[content.Length];
fileWithSAS.DownloadRangeToByteArray(result, 0, 0, content.Length);
for (int i = 0; i < content.Length; i++)
{
Assert.AreEqual(content[i], result[i]);
}
});
}
finally
{
fileClient.GetShareReference(shareName).DeleteIfExists();
}
}
示例3: RunPermissionsTestFiles
public void RunPermissionsTestFiles(SharedAccessAccountPolicy policy)
{
CloudFileClient fileClient = GenerateCloudFileClient();
string shareName = "s" + Guid.NewGuid().ToString("N");
try
{
CloudStorageAccount account = new CloudStorageAccount(fileClient.Credentials, false);
string accountSASToken = account.GetSharedAccessSignature(policy);
StorageCredentials accountSAS = new StorageCredentials(accountSASToken);
CloudStorageAccount accountWithSAS = new CloudStorageAccount(accountSAS, null, null, null, fileClient.StorageUri);
CloudFileClient fileClientWithSAS = accountWithSAS.CreateCloudFileClient();
CloudFileShare shareWithSAS = fileClientWithSAS.GetShareReference(shareName);
CloudFileShare share = fileClient.GetShareReference(shareName);
// General pattern - If current perms support doing a thing with SAS, do the thing with SAS and validate with shared
// Otherwise, make sure SAS fails and then do the thing with shared key.
// Things to do:
// Create the share (Create / Write perms, Container RT)
// List shares with prefix (List perms, Service RT)
// Create a new file (Create / Write, Object RT)
// Add a range to the file (Write, Object RT)
// Read the data from the file (Read, Object RT)
// Overwrite a file (Write, Object RT)
// Delete the file (Delete perms, Object RT)
if ((((policy.Permissions & SharedAccessAccountPermissions.Create) == SharedAccessAccountPermissions.Create) || ((policy.Permissions & SharedAccessAccountPermissions.Write) == SharedAccessAccountPermissions.Write)) &&
((policy.ResourceTypes & SharedAccessAccountResourceTypes.Container) == SharedAccessAccountResourceTypes.Container))
{
shareWithSAS.Create();
}
else
{
TestHelper.ExpectedException<StorageException>(() => shareWithSAS.Create(), "Creating a share with SAS should fail without Create or Write and Container-level perms.");
share.Create();
}
Assert.IsTrue(share.Exists());
if (((policy.Permissions & SharedAccessAccountPermissions.List) == SharedAccessAccountPermissions.List) &&
((policy.ResourceTypes & SharedAccessAccountResourceTypes.Service) == SharedAccessAccountResourceTypes.Service))
{
Assert.AreEqual(shareName, fileClientWithSAS.ListShares(shareName).First().Name);
}
else
{
TestHelper.ExpectedException<StorageException>(() => fileClientWithSAS.ListShares(shareName).First(), "Listing shared with SAS should fail without List and Service-level perms.");
}
string filename = "fileName";
CloudFile fileWithSAS = shareWithSAS.GetRootDirectoryReference().GetFileReference(filename);
CloudFile file = share.GetRootDirectoryReference().GetFileReference(filename);
byte[] content = new byte[] { 0x1, 0x2, 0x3, 0x4 };
if ((((policy.Permissions & SharedAccessAccountPermissions.Create) == SharedAccessAccountPermissions.Create) || ((policy.Permissions & SharedAccessAccountPermissions.Write) == SharedAccessAccountPermissions.Write)) &&
((policy.ResourceTypes & SharedAccessAccountResourceTypes.Object) == SharedAccessAccountResourceTypes.Object))
{
fileWithSAS.Create(content.Length);
}
else
{
TestHelper.ExpectedException<StorageException>(() => fileWithSAS.Create(content.Length), "Creating a file with SAS should fail without Create or Write and Object-level perms.");
file.Create(content.Length);
}
Assert.IsTrue(file.Exists());
using (Stream stream = new MemoryStream(content))
{
if (((policy.Permissions & SharedAccessAccountPermissions.Write) == SharedAccessAccountPermissions.Write) &&
((policy.ResourceTypes & SharedAccessAccountResourceTypes.Object) == SharedAccessAccountResourceTypes.Object))
{
fileWithSAS.WriteRange(stream, 0);
}
else
{
TestHelper.ExpectedException<StorageException>(() => fileWithSAS.WriteRange(stream, 0), "Writing a range to a file with SAS should fail without Write and Object-level perms.");
stream.Seek(0, SeekOrigin.Begin);
file.WriteRange(stream, 0);
}
}
byte[] result = new byte[content.Length];
file.DownloadRangeToByteArray(result, 0, 0, content.Length);
for (int i = 0; i < content.Length; i++)
{
Assert.AreEqual(content[i], result[i]);
}
if (((policy.Permissions & SharedAccessAccountPermissions.Read) == SharedAccessAccountPermissions.Read) &&
((policy.ResourceTypes & SharedAccessAccountResourceTypes.Object) == SharedAccessAccountResourceTypes.Object))
{
result = new byte[content.Length];
fileWithSAS.DownloadRangeToByteArray(result, 0, 0, content.Length);
for (int i = 0; i < content.Length; i++)
{
Assert.AreEqual(content[i], result[i]);
}
}
else
{
TestHelper.ExpectedException<StorageException>(() => fileWithSAS.DownloadRangeToByteArray(result, 0, 0, content.Length), "Reading a file with SAS should fail without Read and Object-level perms.");
//.........这里部分代码省略.........
示例4: GetMyFileIPAddressFromService
private IPAddress GetMyFileIPAddressFromService()
{
CloudFileClient fileClient = GenerateCloudFileClient();
string shareName = "c" + Guid.NewGuid().ToString("N");
CloudFileShare share = fileClient.GetShareReference(shareName);
try
{
share.Create();
string fileName = "file";
share.GetRootDirectoryReference().CreateIfNotExists();
CloudFile file = share.GetRootDirectoryReference().GetFileReference(fileName);
file.Create(1024);
byte[] data = new byte[] { 0x1, 0x2, 0x3, 0x4 };
file.UploadFromByteArray(data, 0, 4);
SharedAccessAccountPolicy policy = GetPolicyWithFullPermissions();
IPAddress invalidIP = IPAddress.Parse("255.255.255.255");
policy.IPAddressOrRange = new IPAddressOrRange(invalidIP.ToString());
CloudStorageAccount account = new CloudStorageAccount(fileClient.Credentials, false);
string accountSASToken = account.GetSharedAccessSignature(policy);
StorageCredentials accountSAS = new StorageCredentials(accountSASToken);
CloudStorageAccount accountWithSAS = new CloudStorageAccount(accountSAS, null, null, null, fileClient.StorageUri);
CloudFileClient fileClientWithSAS = accountWithSAS.CreateCloudFileClient();
CloudFileShare shareWithSAS = fileClientWithSAS.GetShareReference(shareName);
CloudFile fileWithSAS = shareWithSAS.GetRootDirectoryReference().GetFileReference(fileName);
byte[] target = new byte[4];
IPAddress actualIP = null;
bool exceptionThrown = false;
try
{
fileWithSAS.DownloadRangeToByteArray(target, 0, 0, 4);
}
catch (StorageException e)
{
string[] parts = e.RequestInformation.HttpStatusMessage.Split(' ');
actualIP = IPAddress.Parse(parts[parts.Length - 1].Trim('.'));
exceptionThrown = true;
Assert.IsNotNull(actualIP);
}
Assert.IsTrue(exceptionThrown);
return actualIP;
}
finally
{
share.DeleteIfExists();
}
}