コード例 #1
0
        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);
            }
        }