/// <summary> /// Initializes a new instance of the <see cref="BlobUriBuilder"/> /// class with the specified <see cref="Uri"/>. /// </summary> /// <param name="uri"> /// The <see cref="Uri"/> to a storage resource. /// </param> public BlobUriBuilder(Uri uri) { this.Scheme = uri.Scheme; this.Host = uri.Host; this.Port = uri.Port; this.AccountName = ""; this.ContainerName = ""; this.BlobName = ""; this.Snapshot = ""; //this.VersionId = ""; this.Sas = null; // Find the account, container, & blob names (if any) if (!String.IsNullOrEmpty(uri.AbsolutePath)) { // If path starts with a slash, remove it var path = (uri.AbsolutePath[0] == '/') ? uri.AbsolutePath.Substring(1) : uri.AbsolutePath; var startIndex = 0; if (IsHostIPEndPointStyle(uri.Host)) { var accountEndIndex = path.IndexOf("/", StringComparison.InvariantCulture); // Slash not found; path has account name & no container name if (accountEndIndex == -1) { this.AccountName = path; startIndex = path.Length; } else { this.AccountName = path.Substring(0, accountEndIndex); startIndex = accountEndIndex + 1; } } // Find the next slash (if it exists) var containerEndIndex = path.IndexOf("/", startIndex, StringComparison.InvariantCulture); if (containerEndIndex == -1) { this.ContainerName = path.Substring(startIndex); // Slash not found; path has container name & no blob name } else { this.ContainerName = path.Substring(startIndex, containerEndIndex - startIndex); // The container name is the part between the slashes this.BlobName = path.Substring(containerEndIndex + 1); // The blob name is after the container slash } } // Convert the query parameters to a case-sensitive map & trim whitespace var paramsMap = new UriQueryParamsCollection(uri.Query); if (paramsMap.TryGetValue(SnapshotParameterName, out var snapshotTime)) { this.Snapshot = snapshotTime; // If we recognized the query parameter, remove it from the map paramsMap.Remove(SnapshotParameterName); } //if(paramsMap.TryGetValue(VersionIdParameterName, out var versionId)) //{ // this.VersionId = versionId; // // If we recognized the query parameter, remove it from the map // paramsMap.Remove(VersionIdParameterName); //} if (paramsMap.ContainsKey(SasVersionKey)) { this.Sas = new SasQueryParameters(paramsMap); } this.UnparsedParams = paramsMap.ToString(); }
/// <summary> /// Initializes a new instance of the <see cref="FileUriBuilder"/> /// class with the specified <see cref="Uri"/>. /// </summary> /// <param name="uri"> /// The <see cref="Uri"/> to a storage resource. /// </param> public FileUriBuilder(Uri uri) { this.Scheme = uri.Scheme; this.Host = uri.Host; this.Port = uri.Port; this.AccountName = ""; this.ShareName = ""; this.DirectoryOrFilePath = ""; this.Snapshot = ""; this.Sas = null; // Find the share & directory/file path (if any) if (!String.IsNullOrEmpty(uri.AbsolutePath)) { // If path starts with a slash, remove it var path = (uri.AbsolutePath[0] == '/') ? uri.AbsolutePath.Substring(1) : uri.AbsolutePath; var startIndex = 0; if (IsHostIPEndPointStyle(uri.Host)) { var accountEndIndex = path.IndexOf("/", StringComparison.InvariantCulture); // Slash not found; path has account name & no share name if (accountEndIndex == -1) { this.AccountName = path; startIndex = path.Length; } else { this.AccountName = path.Substring(0, accountEndIndex); startIndex = accountEndIndex + 1; } } // Find the next slash (if it exists) var shareEndIndex = path.IndexOf("/", startIndex, StringComparison.InvariantCulture); if (shareEndIndex == -1) { this.ShareName = path.Substring(startIndex); // Slash not found; path has share name & no directory/file path } else { this.ShareName = path.Substring(startIndex, shareEndIndex - startIndex); // The share name is the part between the slashes this.DirectoryOrFilePath = path.Substring(shareEndIndex + 1); // The directory/file path name is after the share slash } } // Convert the query parameters to a case-sensitive map & trim whitespace var paramsMap = new UriQueryParamsCollection(uri.Query); if (paramsMap.TryGetValue(Constants.SnapshotParameterName, out var snapshotTime)) { this.Snapshot = snapshotTime; // If we recognized the query parameter, remove it from the map paramsMap.Remove(Constants.SnapshotParameterName); } if (paramsMap.ContainsKey(Constants.Sas.Parameters.Version)) { this.Sas = new SasQueryParameters(paramsMap); } this.UnparsedParams = paramsMap.ToString(); }