in sdk/storage/Azure.Storage.Files.Shares/src/ShareFileClient.cs [577:1058]
public virtual Response<ShareFileInfo> Create(
long maxSize,
ShareFileCreateOptions options = default,
ShareFileRequestConditions conditions = default,
CancellationToken cancellationToken = default) =>
CreateInternal(
maxSize,
httpHeaders: options?.HttpHeaders,
metadata: options?.Metadata,
smbProperties: options?.SmbProperties,
filePermission: options?.FilePermission?.Permission,
filePermissionFormat: options?.FilePermission?.PermissionFormat,
posixProperties: options?.PosixProperties,
conditions,
async: false,
cancellationToken)
.EnsureCompleted();
/// <summary>
/// Creates a new file or replaces an existing file.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/create-file">
/// Create File</see>.
/// </summary>
/// <remarks>
/// This method only initializes the file.
/// To add content, use <see cref="UploadRangeAsync(HttpRange, Stream, byte[], IProgress{long}, ShareFileRequestConditions, CancellationToken)"/>.
/// </remarks>
/// <param name="maxSize">
/// Required. Specifies the maximum size for the file in bytes. The max supported file size is 4 TiB.
/// </param>
/// <param name="options">
/// Optional parameters.
/// </param>
/// <param name="conditions">
/// Optional <see cref="ShareFileRequestConditions"/> to add conditions
/// on creating the file.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{StorageFileInfo}"/> describing the
/// state of the file.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
/// containing each failure instance.
/// </remarks>
public virtual async Task<Response<ShareFileInfo>> CreateAsync(
long maxSize,
ShareFileCreateOptions options = default,
ShareFileRequestConditions conditions = default,
CancellationToken cancellationToken = default) =>
await CreateInternal(
maxSize,
httpHeaders: options?.HttpHeaders,
metadata: options?.Metadata,
smbProperties: options?.SmbProperties,
filePermission: options?.FilePermission?.Permission,
filePermissionFormat: options?.FilePermission?.PermissionFormat,
posixProperties: options?.PosixProperties,
conditions,
async: true,
cancellationToken)
.ConfigureAwait(false);
/// <summary>
/// Creates a new file or replaces an existing file.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/create-file">
/// Create File</see>.
/// </summary>
/// <remarks>
/// This method only initializes the file.
/// To add content, use <see cref="UploadRangeAsync(HttpRange, Stream, byte[], IProgress{long}, ShareFileRequestConditions, CancellationToken)"/>.
/// </remarks>
/// <param name="maxSize">
/// Required. Specifies the maximum size for the file in bytes. The max supported file size is 4 TiB.
/// </param>
/// <param name="httpHeaders">
/// Optional standard HTTP header properties that can be set for the file.
/// </param>
/// <param name="metadata">
/// Optional custom metadata to set for the file.
/// </param>
/// <param name="smbProperties">
/// Optional SMB properties to set for the file.
/// </param>
/// <param name="filePermission">
/// Optional file permission to set for the file.
/// </param>
/// <param name="conditions">
/// Optional <see cref="ShareFileRequestConditions"/> to add conditions
/// on creating the file.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{StorageFileInfo}"/> describing the
/// state of the file.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
/// containing each failure instance.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
#pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
public virtual Response<ShareFileInfo> Create(
#pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
long maxSize,
ShareFileHttpHeaders httpHeaders,
Metadata metadata,
FileSmbProperties smbProperties,
string filePermission,
ShareFileRequestConditions conditions,
CancellationToken cancellationToken) =>
CreateInternal(
maxSize,
httpHeaders,
metadata,
smbProperties,
filePermission,
filePermissionFormat: default,
posixProperties: default,
conditions,
async: false,
cancellationToken)
.EnsureCompleted();
/// <summary>
/// Creates a new file or replaces an existing file.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/create-file">
/// Create File</see>.
/// </summary>
/// <remarks>
/// This method only initializes the file.
/// To add content, use <see cref="UploadRangeAsync(HttpRange, Stream, byte[], IProgress{long}, ShareFileRequestConditions, CancellationToken)"/>.
/// </remarks>
/// <param name="maxSize">
/// Required. Specifies the maximum size for the file in bytes. The max supported file size is 4 TiB.
/// </param>
/// <param name="httpHeaders">
/// Optional standard HTTP header properties that can be set for the file.
/// </param>
/// <param name="metadata">
/// Optional custom metadata to set for the file.
/// </param>
/// <param name="smbProperties">
/// Optional SMB properties to set for the file.
/// </param>
/// <param name="filePermission">
/// Optional file permission to set for the file.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{StorageFileInfo}"/> describing the
/// state of the file.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
/// containing each failure instance.
/// </remarks>
#pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual Response<ShareFileInfo> Create(
#pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
long maxSize,
ShareFileHttpHeaders httpHeaders,
Metadata metadata,
FileSmbProperties smbProperties,
string filePermission,
CancellationToken cancellationToken) =>
CreateInternal(
maxSize,
httpHeaders,
metadata,
smbProperties,
filePermission,
filePermissionFormat: default,
posixProperties: default,
conditions: default,
async: false,
cancellationToken)
.EnsureCompleted();
/// <summary>
/// Creates a new file or replaces an existing file.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/create-file">
/// Create File</see>.
/// </summary>
/// <remarks>
/// This method only initializes the file.
/// To add content, use <see cref="UploadRangeAsync(HttpRange, Stream, byte[], IProgress{long}, ShareFileRequestConditions, CancellationToken)"/>.
/// </remarks>
/// <param name="maxSize">
/// Required. Specifies the maximum size for the file in bytes. The max supported file size is 4 TiB.
/// </param>
/// <param name="httpHeaders">
/// Optional standard HTTP header properties that can be set for the file.
/// </param>
/// <param name="metadata">
/// Optional custom metadata to set for the file.
/// </param>
/// <param name="smbProperties">
/// Optional SMB properties to set for the file.
/// </param>
/// <param name="filePermission">
/// Optional file permission to set for the file.
/// </param>
/// <param name="conditions">
/// Optional <see cref="ShareFileRequestConditions"/> to add conditions
/// on creating the file.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{StorageFileInfo}"/> describing the
/// state of the file.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
/// containing each failure instance.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
#pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
public virtual async Task<Response<ShareFileInfo>> CreateAsync(
#pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
long maxSize,
ShareFileHttpHeaders httpHeaders,
Metadata metadata,
FileSmbProperties smbProperties,
string filePermission,
ShareFileRequestConditions conditions,
CancellationToken cancellationToken) =>
await CreateInternal(
maxSize,
httpHeaders,
metadata,
smbProperties,
filePermission,
filePermissionFormat: default,
posixProperties: default,
conditions,
async: true,
cancellationToken)
.ConfigureAwait(false);
/// <summary>
/// Creates a new file or replaces an existing file.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/create-file">
/// Create File</see>.
/// </summary>
/// <remarks>
/// This method only initializes the file.
/// To add content, use <see cref="UploadRangeAsync(HttpRange, Stream, byte[], IProgress{long}, ShareFileRequestConditions, CancellationToken)"/>.
/// </remarks>
/// <param name="maxSize">
/// Required. Specifies the maximum size for the file in bytes. The max supported file size is 4 TiB.
/// </param>
/// <param name="httpHeaders">
/// Optional standard HTTP header properties that can be set for the file.
/// </param>
/// <param name="metadata">
/// Optional custom metadata to set for the file.
/// </param>
/// <param name="smbProperties">
/// Optional SMB properties to set for the file.
/// </param>
/// <param name="filePermission">
/// Optional file permission to set for the file.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{StorageFileInfo}"/> describing the
/// state of the file.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
/// containing each failure instance.
/// </remarks>
#pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual async Task<Response<ShareFileInfo>> CreateAsync(
#pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
long maxSize,
ShareFileHttpHeaders httpHeaders,
Metadata metadata,
FileSmbProperties smbProperties,
string filePermission,
CancellationToken cancellationToken) =>
await CreateInternal(
maxSize,
httpHeaders,
metadata,
smbProperties,
filePermission,
filePermissionFormat: default,
posixProperties: default,
conditions: default,
async: true,
cancellationToken)
.ConfigureAwait(false);
/// <summary>
/// Creates a new file or replaces an existing file.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/create-file">
/// Create File</see>.
/// </summary>
/// <remarks>
/// This method only initializes the file.
/// To add content, use <see cref="UploadRangeAsync(HttpRange, Stream, byte[], IProgress{long}, ShareFileRequestConditions, CancellationToken)"/>.
/// </remarks>
/// <param name="maxSize">
/// Required. Specifies the maximum size for the file in bytes. The max supported file size is 4 TiB.
/// </param>
/// <param name="httpHeaders">
/// Optional standard HTTP header properties that can be set for the file.
/// </param>
/// <param name="metadata">
/// Optional custom metadata to set for the file.
/// </param>
/// <param name="smbProperties">
/// Optional SMB properties to set for the file.
/// </param>
/// <param name="filePermission">
/// Optional file permission to set on the file.
/// </param>
/// <param name="filePermissionFormat">
/// Optional file permission format.
/// </param>
/// <param name="posixProperties">
/// Optional NFS properties.
/// </param>
/// <param name="conditions">
/// Optional <see cref="ShareFileRequestConditions"/> to add conditions
/// on creating the file.
/// </param>
/// <param name="async">
/// Whether to invoke the operation asynchronously.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <param name="operationName">
/// Optional. To indicate if the name of the operation.
/// </param>
/// <returns>
/// A <see cref="Response{StorageFileInfo}"/> describing the
/// state of the file.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
/// containing each failure instance.
/// </remarks>
private async Task<Response<ShareFileInfo>> CreateInternal(
long maxSize,
ShareFileHttpHeaders httpHeaders,
Metadata metadata,
FileSmbProperties smbProperties,
string filePermission,
FilePermissionFormat? filePermissionFormat,
FilePosixProperties posixProperties,
ShareFileRequestConditions conditions,
bool async,
CancellationToken cancellationToken,
string operationName = default)
{
using (ClientConfiguration.Pipeline.BeginLoggingScope(nameof(ShareFileClient)))
{
ClientConfiguration.Pipeline.LogMethodEnter(
nameof(ShareFileClient),
message:
$"{nameof(Uri)}: {Uri}\n" +
$"{nameof(maxSize)}: {maxSize}\n" +
$"{nameof(httpHeaders)}: {httpHeaders}");
operationName ??= $"{nameof(ShareFileClient)}.{nameof(Create)}";
DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope(operationName);
try
{
scope.Start();
FileSmbProperties smbProps = smbProperties ?? new FileSmbProperties();
ShareExtensions.AssertValidFilePermissionAndKey(filePermission, smbProps.FilePermissionKey);
ResponseWithHeaders<FileCreateHeaders> response;
if (async)
{
response = await FileRestClient.CreateAsync(
fileContentLength: maxSize,
fileAttributes: smbProps.FileAttributes.ToAttributesString(),
fileCreationTime: smbProps.FileCreatedOn.ToFileDateTimeString(),
fileLastWriteTime: smbProps.FileLastWrittenOn.ToFileDateTimeString(),
fileChangeTime: smbProps.FileChangedOn.ToFileDateTimeString(),
owner: posixProperties?.Owner,
group: posixProperties?.Group,
fileMode: posixProperties?.FileMode?.ToOctalFileMode(),
nfsFileType: posixProperties?.FileType,
metadata: metadata,
filePermission: filePermission,
filePermissionFormat: filePermissionFormat,
filePermissionKey: smbProps.FilePermissionKey,
fileHttpHeaders: httpHeaders.ToFileHttpHeaders(),
shareFileRequestConditions: conditions,
cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
else
{
response = FileRestClient.Create(
fileContentLength: maxSize,
fileAttributes: smbProps.FileAttributes.ToAttributesString(),
fileCreationTime: smbProps.FileCreatedOn.ToFileDateTimeString(),
fileLastWriteTime: smbProps.FileLastWrittenOn.ToFileDateTimeString(),
fileChangeTime: smbProps.FileChangedOn.ToFileDateTimeString(),
owner: posixProperties?.Owner,
group: posixProperties?.Group,
fileMode: posixProperties?.FileMode?.ToOctalFileMode(),
nfsFileType: posixProperties?.FileType,
metadata: metadata,
filePermission: filePermission,
filePermissionFormat: filePermissionFormat,
filePermissionKey: smbProps.FilePermissionKey,
fileHttpHeaders: httpHeaders.ToFileHttpHeaders(),
shareFileRequestConditions: conditions,
cancellationToken: cancellationToken);
}
return Response.FromValue(
response.ToShareFileInfo(),
response.GetRawResponse());
}
catch (Exception ex)
{
ClientConfiguration.Pipeline.LogException(ex);
scope.Failed(ex);
throw;
}
finally
{
ClientConfiguration.Pipeline.LogMethodExit(nameof(ShareFileClient));
scope.Dispose();
}
}
}