internal static Uri GetWasbStoragePath(Uri httpPath) { httpPath.ArgumentNotNull("httpPath"); if ( !(string.Equals(httpPath.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) || string.Equals(httpPath.Scheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase))) { throw new ArgumentException("httpPath should have a uri scheme of http", "httpPath"); } int segmentTakeCount = 1; string containerName = httpPath.Segments.First(); if (containerName == "/" && httpPath.Segments.Length > segmentTakeCount) { containerName = httpPath.Segments.Skip(segmentTakeCount).FirstOrDefault(); segmentTakeCount++; } string asvPath = string.Format( CultureInfo.InvariantCulture, "{0}://{1}@{2}/{3}", WabsProtocol, containerName.TrimEnd('/'), httpPath.Host, string.Join(string.Empty, httpPath.Segments.Skip(segmentTakeCount))); return new Uri(asvPath); }
/// <summary> /// Initializes a new instance of the <see cref="ScannerInformation"/> class. /// </summary> /// <param name="location">The location.</param> /// <param name="tableName">Name of the table.</param> public ScannerInformation(Uri location, string tableName) { location.ArgumentNotNull("location"); tableName.ArgumentNotNullNorEmpty("tableName"); Location = location; TableName = tableName; }
public async Task<bool> Exists(Uri path) { path.ArgumentNotNull("path"); var httpPath = ConvertToHttpPath(path); this.AssertPathRootedToThisAccount(httpPath); var blobReference = await this.GetBlobReference(httpPath, false); return blobReference != null; }
/// <summary> /// Initializes a new instance of the <see cref="ScannerInformation"/> class. /// </summary> /// <param name="location">The location.</param> /// <param name="tableName">Name of the table.</param> /// <param name="responseHeaderCollection">additional header information from the response</param> public ScannerInformation(Uri location, string tableName, WebHeaderCollection responseHeaderCollection) { location.ArgumentNotNull("location"); tableName.ArgumentNotNullNorEmpty("tableName"); responseHeaderCollection.ArgumentNotNull("responseHeaderCollection"); Location = location; TableName = tableName; ResponseHeaderCollection = responseHeaderCollection; }
/// <summary> /// Initializes a new instance of the <see cref="ClusterCredentials"/> class. /// </summary> /// <param name="clusterUri">The cluster URI.</param> /// <param name="userName">The username.</param> /// <param name="password">The password.</param> public ClusterCredentials(Uri clusterUri, string userName, SecureString password) { clusterUri.ArgumentNotNull("clusterUri"); userName.ArgumentNotNullNorEmpty("username"); password.ArgumentNotNull("securePassword"); ClusterUri = clusterUri; UserName = userName; _clusterPassword = password.Copy(); _clusterPassword.MakeReadOnly(); }
public void Delete(Uri path) { path.ArgumentNotNull("path"); string localPath = path.LocalPath; var client = this.GetStorageClient(); var container = client.GetContainerReference(this.credentials.ContainerName); localPath = localPath.TrimStart('/'); foreach (CloudBlockBlob blob in container.ListBlobs(localPath, true, BlobListingDetails.None, null, null)) { blob.Delete(); } }
internal static string GetRelativeHttpPath(Uri path) { path.ArgumentNotNull("path"); return path.UserInfo + "/" + string.Join(string.Empty, path.Segments).TrimStart('/'); }
internal static Uri ConvertToHttpPath(Uri asvPath) { asvPath.ArgumentNotNull("path"); if (!string.Equals(asvPath.Scheme, Constants.WabsProtocol, StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException("asvPath should have a uri scheme of asv", "asvPath"); } string httpPath = string.Format( CultureInfo.InvariantCulture, "http://{0}/{1}{2}", asvPath.Host, asvPath.UserInfo, string.Join(string.Empty, asvPath.Segments)); return new Uri(httpPath); }
private void AssertPathRootedToThisAccount(Uri path) { path.ArgumentNotNull("path"); if (!string.Equals(this.StorageAccountUri.DnsSafeHost, path.DnsSafeHost, StringComparison.Ordinal)) { throw new ArgumentException("Path is not rooted in the storage account.", "path"); } }
public async Task DownloadToFile(Uri path, string localFileName) { path.ArgumentNotNull("path"); localFileName.ArgumentNotNullOrEmpty("localFileName"); var httpPath = ConvertToHttpPath(path); this.AssertPathRootedToThisAccount(httpPath); var blobReference = await this.GetBlobReference(httpPath, true); // Read blob in chunks of up to 4MB long chunkSize = 4 * 1024 * 1024; if (blobReference.Properties.Length < chunkSize) { blobReference.DownloadToFile(localFileName, FileMode.OpenOrCreate); } else { byte[] buffer = new byte[chunkSize]; using (var blobStream = blobReference.OpenRead()) { using (var fileStream = File.Create(localFileName)) { int bytesRead; while ((bytesRead = blobStream.Read(buffer, 0, buffer.Length)) > 0) { fileStream.Write(buffer, 0, bytesRead); } } } } }
public async Task<IEnumerable<Uri>> List(Uri path, bool recursive) { path.ArgumentNotNull("path"); var httpPath = ConvertToHttpPath(path); this.AssertPathRootedToThisAccount(httpPath); var client = this.GetStorageClient(); var directoryPath = GetRelativeHttpPath(path); var directoryContents = new List<Uri>(); if (directoryPath == RootDirectoryPath) { var containers = client.ListContainers().ToList(); directoryContents.AddRange(containers.Select(item => ConvertToAsvPath(item.Uri))); } else { var asyncResult = client.BeginListBlobsSegmented(directoryPath, null, null, null); var blobs = await Task.Factory.FromAsync(asyncResult, (result) => client.EndListBlobsSegmented(result)); var blobDirectory = blobs.Results.FirstOrDefault(blob => blob is CloudBlobDirectory) as CloudBlobDirectory; if (blobDirectory != null) { var blobItems = blobDirectory.ListBlobs(true).ToList(); directoryContents.AddRange(blobItems.Select(item => ConvertToAsvPath(item.Uri))); } } return directoryContents; }
public async Task<Stream> Read(Uri path) { path.ArgumentNotNull("path"); var httpPath = ConvertToHttpPath(path); this.AssertPathRootedToThisAccount(httpPath); var blobReference = await this.GetBlobReference(httpPath, true); var blobStream = new MemoryStream(); blobReference.DownloadToStream(blobStream); blobStream.Seek(0, SeekOrigin.Begin); return blobStream; }
public async Task<IHttpResponseMessageAbstraction> GetComponentSettings(Uri componentUri) { componentUri.ArgumentNotNull("componentUri"); return await this.MakeAsyncGetRequest(componentUri); }
/// <summary> /// Initializes a new instance of the <see cref="ClusterCredentials"/> class. /// </summary> /// <param name="clusterUri">The cluster URI.</param> public ClusterCredentials(Uri clusterUri) { clusterUri.ArgumentNotNull("clusterUri"); ClusterUri = clusterUri; }
public async Task<Stream> Read(Uri path) { path.ArgumentNotNull("path"); var httpPath = ConvertToHttpPath(path); this.AssertPathRootedToThisAccount(httpPath); var blobReference = await this.GetBlobReference(httpPath, true); var blobStream = await blobReference.OpenReadAsync(); return blobStream; }