public void CopyCrossAccountFromFile2SASFile() { string destShareName = Utility.GenNameString("destshare"); CloudFileShare destShare = fileUtil2.EnsureFileShareExists(destShareName); string sourceShareName = Utility.GenNameString("sourceshare"); CloudFileShare sourceShare = fileUtil.EnsureFileShareExists(sourceShareName); try { StorageFile.CloudFile sourceFile = fileUtil.CreateFile(sourceShare.GetRootDirectoryReference(), Utility.GenNameString("SourceFile")); string destFileName = Utility.GenNameString("destfile"); string destSasToken = destShare.GetSharedAccessSignature(new SharedAccessFilePolicy() { Permissions = SharedAccessFilePermissions.Read | SharedAccessFilePermissions.Write, SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1) }); object destContext = CommandAgent.GetStorageContextWithSASToken(StorageAccount2, destSasToken); Test.Assert(CommandAgent.StartFileCopy(sourceFile, destShareName, destFileName, destContext), "Copy to file with sas token credential should fail."); Test.Assert(CommandAgent.GetFileCopyState(destShareName, destFileName, destContext, true), "Get file copy state should succeed."); CloudFileUtil.ValidateCopyResult(sourceFile, destShare.GetRootDirectoryReference().GetFileReference(destFileName)); } finally { fileUtil.DeleteFileShareIfExists(sourceShareName); fileUtil2.DeleteFileShareIfExists(destShareName); } }
private void CopyFromFile2File(Action <CloudFileShare> SetSourceContext, Func <CloudFileShare, object> getDestContext) { string destShareName = Utility.GenNameString("destshare"); CloudFileShare destShare = fileUtil.EnsureFileShareExists(destShareName); string sourceShareName = Utility.GenNameString("sourceshare"); CloudFileShare sourceShare = fileUtil.EnsureFileShareExists(sourceShareName); try { StorageFile.CloudFile sourceFile = fileUtil.CreateFile(sourceShare.GetRootDirectoryReference(), Utility.GenNameString("SourceFile")); object destContext = getDestContext(destShare); SetSourceContext(sourceShare); string destFileName = Utility.GenNameString("destfile"); Test.Assert(CommandAgent.StartFileCopyFromFile(sourceShareName, sourceFile.Name, destShareName, destFileName, destContext), "Copy to file with sas token credential should succeed."); var destFile = fileUtil.GetFileReference(destShare.GetRootDirectoryReference(), destFileName); Test.Assert(CommandAgent.GetFileCopyState(destFile, destContext, true), "Get file copy state should succeed."); CloudFileUtil.ValidateCopyResult(sourceFile, destFile); } finally { fileUtil.DeleteFileShareIfExists(sourceShareName); fileUtil.DeleteFileShareIfExists(destShareName); } }
private void CopyFromBlob2SASFile(Action <CloudBlobContainer> SetSourceContext) { string destShareName = Utility.GenNameString("destshare"); CloudFileShare destShare = fileUtil.EnsureFileShareExists(destShareName); string sourceContainerName = Utility.GenNameString("container"); CloudBlobContainer container = blobUtil.CreateContainer(sourceContainerName); try { CloudBlob sourceBlob = blobUtil.CreateRandomBlob(container, Utility.GenNameString("BlobName")); string destSasToken = destShare.GetSharedAccessSignature(new SharedAccessFilePolicy() { Permissions = SharedAccessFilePermissions.Read | SharedAccessFilePermissions.Write, SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1) }); object destContext = CommandAgent.GetStorageContextWithSASToken(StorageAccount, destSasToken); SetSourceContext(container); Test.Assert(CommandAgent.StartFileCopyFromBlob(sourceContainerName, sourceBlob.Name, destShareName, sourceBlob.Name, destContext), "Copy to file with sas token credential should succeed."); Test.Assert(CommandAgent.GetFileCopyState(destShareName, sourceBlob.Name, destContext, true), "Waiting for async copying state should succeed."); CloudFileUtil.ValidateCopyResult(sourceBlob, destShare.GetRootDirectoryReference().GetFileReference(sourceBlob.Name)); } finally { blobUtil.RemoveContainer(sourceContainerName); fileUtil.DeleteFileShareIfExists(destShareName); } }
public void GetCopyStateWithSAS() { string destShareName = Utility.GenNameString("destshare"); CloudFileShare destShare = fileUtil.EnsureFileShareExists(destShareName); try { string fileName = Utility.GenNameString("DestFile"); StorageFile.CloudFile destFile = fileUtil.GetFileReference(destShare.GetRootDirectoryReference(), fileName); object destContext; if (lang == Language.PowerShell) { destContext = PowerShellAgent.GetStorageContext(StorageAccount.ToString(true)); } else { destContext = NodeJSAgent.GetStorageContext(StorageAccount.ToString(true)); } string bigBlobUri = Test.Data.Get("BigBlobUri"); Test.Assert(CommandAgent.StartFileCopy(bigBlobUri, destShareName, fileName, destContext), "Copy to file should succeed."); string sasToken = destShare.GetSharedAccessSignature(new SharedAccessFilePolicy() { Permissions = SharedAccessFilePermissions.Read, SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1) }); CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, sasToken); Test.Assert(CommandAgent.GetFileCopyState(destShareName, fileName, destContext), "Get copy state with sas token should succeed."); string copyId = null; if (lang == Language.NodeJS) { copyId = ((JObject)CommandAgent.Output[0]["copy"])["id"].ToString(); } NodeJSAgent.AgentConfig.ConnectionString = StorageAccount.ToString(true); Test.Assert(CommandAgent.StopFileCopy(destFile, copyId), "Stop file copy should succeed."); } finally { fileUtil.DeleteFileShareIfExists(destShareName); } }
private void CopyFromBlob2File(Action <CloudBlobContainer> SetSourceContext) { string destShareName = Utility.GenNameString("destshare"); CloudFileShare destShare = fileUtil.EnsureFileShareExists(destShareName); string sourceContainerName = Utility.GenNameString("container"); CloudBlobContainer container = blobUtil.CreateContainer(sourceContainerName); try { CloudBlob sourceBlob = blobUtil.CreateRandomBlob(container, Utility.GenNameString("BlobName")); object destContext; if (lang == Language.PowerShell) { destContext = PowerShellAgent.GetStorageContext(StorageAccount.ToString(true)); } else { destContext = NodeJSAgent.GetStorageContext(StorageAccount.ToString(true)); } SetSourceContext(container); string destFileName = Utility.GenNameString("destfile"); Test.Assert(CommandAgent.StartFileCopyFromBlob(sourceContainerName, sourceBlob.Name, destShareName, destFileName, destContext), "Copy to file with sas token credential should succeed."); var destFile = fileUtil.GetFileReference(destShare.GetRootDirectoryReference(), destFileName); Test.Assert(CommandAgent.GetFileCopyState(destFile, destContext, true), "Get file copy state should succeed."); CloudFileUtil.ValidateCopyResult(sourceBlob, destFile); } finally { blobUtil.RemoveContainer(sourceContainerName); fileUtil.DeleteFileShareIfExists(destShareName); } }