当前位置: 首页>>代码示例>>C#>>正文


C# CloudFile.FetchAttributes方法代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.Storage.File.CloudFile.FetchAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# CloudFile.FetchAttributes方法的具体用法?C# CloudFile.FetchAttributes怎么用?C# CloudFile.FetchAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.WindowsAzure.Storage.File.CloudFile的用法示例。


在下文中一共展示了CloudFile.FetchAttributes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WaitForCopy

 public static void WaitForCopy(CloudFile file)
 {
     bool copyInProgress = true;
     while (copyInProgress)
     {
         Thread.Sleep(1000);
         file.FetchAttributes();
         copyInProgress = (file.CopyState.Status == CopyStatus.Pending);
     }
 }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:10,代码来源:FileTestBase.cs

示例2: FileDirectoryEscapingTest

        private void FileDirectoryEscapingTest(string directoryName, string fileName)
        {
            CloudFileClient service = GenerateCloudFileClient();
            CloudFileShare share = GetRandomShareReference();

            try
            {
                share.Create();
                string text = Guid.NewGuid().ToString();

                // Create from CloudFileShare.
                CloudFileDirectory directory = share.GetRootDirectoryReference().GetDirectoryReference(directoryName);
                directory.Create();
                CloudFile originalFile = directory.GetFileReference(fileName);
                originalFile.Create(0);

                // List directories from share.
                IListFileItem directoryFromShareListingFiles = share.GetRootDirectoryReference().ListFilesAndDirectories().First();
                Assert.AreEqual(directory.Uri, directoryFromShareListingFiles.Uri);

                // List files from directory.
                IListFileItem fileFromDirectoryListingFiles = directory.ListFilesAndDirectories().First();
                Assert.AreEqual(originalFile.Uri, fileFromDirectoryListingFiles.Uri);

                // Check Name
                Assert.AreEqual<string>(fileName, originalFile.Name);

                // Absolute URI access from CloudFile
                CloudFile fileInfo = new CloudFile(originalFile.Uri, service.Credentials);
                fileInfo.FetchAttributes();

                // Access from CloudFileDirectory
                CloudFileDirectory cloudFileDirectory = share.GetRootDirectoryReference().GetDirectoryReference(directoryName);
                CloudFile fileFromCloudFileDirectory = cloudFileDirectory.GetFileReference(fileName);
                Assert.AreEqual(fileInfo.Uri, fileFromCloudFileDirectory.Uri);
            }
            finally
            {
                share.Delete();
            }
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:41,代码来源:FileEscapingTests.cs

示例3: CloudFileSASSharedProtocolsQueryParam

        public void CloudFileSASSharedProtocolsQueryParam()
        {
            CloudFileShare share = GetRandomShareReference();
            try
            {
                share.Create();
                CloudFile file;
                SharedAccessFilePolicy policy = new SharedAccessFilePolicy()
                {
                    Permissions = SharedAccessFilePermissions.Read,
                    SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
                };

                CloudFile fileWithKey = share.GetRootDirectoryReference().GetFileReference("filefile");
                byte[] data = new byte[] { 0x1, 0x2, 0x3, 0x4 };
                byte[] target = new byte[4];
                fileWithKey.UploadFromByteArray(data, 0, 4);

                foreach (SharedAccessProtocol? protocol in new SharedAccessProtocol?[] { null, SharedAccessProtocol.HttpsOrHttp, SharedAccessProtocol.HttpsOnly })
                {
                    string fileToken = fileWithKey.GetSharedAccessSignature(policy, null, null, protocol, null);
                    StorageCredentials fileSAS = new StorageCredentials(fileToken);
                    Uri fileSASUri = new Uri(fileWithKey.Uri + fileSAS.SASToken);
                    StorageUri fileSASStorageUri = new StorageUri(new Uri(fileWithKey.StorageUri.PrimaryUri + fileSAS.SASToken), new Uri(fileWithKey.StorageUri.SecondaryUri + fileSAS.SASToken));

                    int httpPort = fileSASUri.Port;
                    int securePort = 443;

                    if (!string.IsNullOrEmpty(TestBase.TargetTenantConfig.FileSecurePortOverride))
                    {
                        securePort = Int32.Parse(TestBase.TargetTenantConfig.FileSecurePortOverride);
                    }

                    var schemesAndPorts = new[] {
                        new { scheme = Uri.UriSchemeHttp, port = httpPort},
                        new { scheme = Uri.UriSchemeHttps, port = securePort}
                    };
                    
                    foreach (var item in schemesAndPorts)
                    {
                        fileSASUri = TransformSchemeAndPort(fileSASUri, item.scheme, item.port);
                        fileSASStorageUri = new StorageUri(TransformSchemeAndPort(fileSASStorageUri.PrimaryUri, item.scheme, item.port), TransformSchemeAndPort(fileSASStorageUri.SecondaryUri, item.scheme, item.port));

                        if (protocol.HasValue && protocol == SharedAccessProtocol.HttpsOnly && string.CompareOrdinal(item.scheme, Uri.UriSchemeHttp) == 0)
                        {
                            file = new CloudFile(fileSASUri);
                            TestHelper.ExpectedException(() => file.FetchAttributes(), "Access a file using SAS with a shared protocols that does not match", HttpStatusCode.Unused);

                            file = new CloudFile(fileSASStorageUri, null);
                            TestHelper.ExpectedException(() => file.FetchAttributes(), "Access a file using SAS with a shared protocols that does not match", HttpStatusCode.Unused);
                        }
                        else
                        {
                            file = new CloudFile(fileSASUri);
                            file.DownloadRangeToByteArray(target, 0, 0, 4, null, null, null);
                            for (int i = 0; i < 4; i++)
                            {
                                Assert.AreEqual(data[i], target[i]);
                            }

                            file = new CloudFile(fileSASStorageUri, null);
                            file.DownloadRangeToByteArray(target, 0, 0, 4, null, null, null);
                            for (int i = 0; i < 4; i++)
                            {
                                Assert.AreEqual(data[i], target[i]);
                            }
                        }
                    }
                }
            }
            finally
            {
                share.DeleteIfExists();
            }
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:76,代码来源:FileSASTests.cs


注:本文中的Microsoft.WindowsAzure.Storage.File.CloudFile.FetchAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。