本文整理汇总了C#中Microsoft.WindowsAzure.Storage.File.CloudFile类的典型用法代码示例。如果您正苦于以下问题:C# CloudFile类的具体用法?C# CloudFile怎么用?C# CloudFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CloudFile类属于Microsoft.WindowsAzure.Storage.File命名空间,在下文中一共展示了CloudFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CloudFileWriter
internal CloudFileWriter(
TransferScheduler scheduler,
SyncTransferController controller,
CancellationToken cancellationToken)
: base(scheduler, controller, cancellationToken)
{
this.cloudFile = this.TransferJob.Destination.AzureFile;
}
示例2: DownloadTextAsync
public static async Task<string> DownloadTextAsync(CloudFile file, Encoding encoding, AccessCondition accessCondition = null, FileRequestOptions options = null, OperationContext operationContext = null)
{
using (MemoryStream stream = new MemoryStream())
{
await file.DownloadToStreamAsync(stream, accessCondition, options, operationContext);
return encoding.GetString(stream.ToArray(), 0, (int)stream.Length);
}
}
示例3: AzureFileLocation
/// <summary>
/// Initializes a new instance of the <see cref="AzureFileLocation"/> class.
/// </summary>
/// <param name="azureFile">CloudFile instance as a location in a transfer job.
/// It could be a source, a destination.</param>
public AzureFileLocation(CloudFile azureFile)
{
if (null == azureFile)
{
throw new ArgumentNullException("azureFile");
}
this.AzureFile = azureFile;
}
示例4: CloudFileReader
public CloudFileReader(
TransferScheduler scheduler,
SyncTransferController controller,
CancellationToken cancellationToken)
:base(scheduler, controller, cancellationToken)
{
this.file = this.SharedTransferData.TransferJob.Source.AzureFile;
Debug.Assert(null != this.file, "Initializing a CloudFileReader, the source location should be a CloudFile instance.");
}
示例5: WaitForCopyAsync
public static async Task WaitForCopyAsync(CloudFile file)
{
bool copyInProgress = true;
while (copyInProgress)
{
await Task.Delay(1000);
await file.FetchAttributesAsync();
copyInProgress = (file.CopyState.Status == CopyStatus.Pending);
}
}
示例6: WaitForCopyTask
public static void WaitForCopyTask(CloudFile file)
{
bool copyInProgress = true;
while (copyInProgress)
{
Thread.Sleep(1000);
file.FetchAttributesAsync().Wait();
copyInProgress = (file.CopyState.Status == CopyStatus.Pending);
}
}
示例7: UploadTextAsync
public static async Task UploadTextAsync(CloudFile file, string text, Encoding encoding, AccessCondition accessCondition = null, FileRequestOptions options = null, OperationContext operationContext = null)
{
byte[] textAsBytes = encoding.GetBytes(text);
using (MemoryStream stream = new MemoryStream())
{
stream.Write(textAsBytes, 0, textAsBytes.Length);
stream.Seek(0, SeekOrigin.Begin);
file.ServiceClient.DefaultRequestOptions.ParallelOperationThreadCount = 2;
await file.UploadFromStreamAsync(stream, accessCondition, options, operationContext);
}
}
示例8: AssertAreEqual
public static void AssertAreEqual(CloudFile expected, CloudFile actual)
{
if (expected == null)
{
Assert.IsNull(actual);
}
else
{
Assert.IsNotNull(actual);
Assert.AreEqual(expected.Uri, actual.Uri);
Assert.AreEqual(expected.StorageUri, actual.StorageUri);
AssertAreEqual(expected.Properties, actual.Properties);
}
}
示例9: StopCopyFile
/// <summary>
/// Stop copy operation by CloudBlob object
/// </summary>
/// <param name="blob">CloudBlob object</param>
/// <param name="copyId">Copy id</param>
private async Task StopCopyFile(long taskId, IStorageFileManagement localChannel, CloudFile file, string copyId)
{
FileRequestOptions requestOptions = RequestOptions;
//Set no retry to resolve the 409 conflict exception
requestOptions.RetryPolicy = new NoRetry();
string abortCopyId = string.Empty;
if (string.IsNullOrEmpty(copyId) || Force)
{
//Make sure we use the correct copy id to abort
//Use default retry policy for FetchBlobAttributes
FileRequestOptions options = RequestOptions;
await localChannel.FetchFileAttributesAsync(file, null, options, OperationContext, CmdletCancellationToken);
if (file.CopyState == null || string.IsNullOrEmpty(file.CopyState.CopyId))
{
ArgumentException e = new ArgumentException(String.Format(Resources.FileCopyTaskNotFound, file.Uri.ToString()));
OutputStream.WriteError(taskId, e);
}
else
{
abortCopyId = file.CopyState.CopyId;
}
if (!Force)
{
string confirmation = String.Format(Resources.ConfirmAbortFileCopyOperation, file.Uri.ToString(), abortCopyId);
if (!await OutputStream.ConfirmAsync(confirmation))
{
string cancelMessage = String.Format(Resources.StopCopyOperationCancelled, file.Uri.ToString());
OutputStream.WriteVerbose(taskId, cancelMessage);
}
}
}
else
{
abortCopyId = copyId;
}
await localChannel.AbortCopyAsync(file, abortCopyId, null, requestOptions, OperationContext, CmdletCancellationToken);
string message = String.Format(Resources.StopCopyFileSuccessfully, file.Uri.ToString());
OutputStream.WriteObject(taskId, message);
}
示例10: FileReadStreamBase
/// <summary>
/// Initializes a new instance of the <see cref="FileReadStreamBase"/> class.
/// </summary>
/// <param name="file">File reference to read from</param>
/// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the access conditions for the file. If <c>null</c>, no condition is used.</param>
/// <param name="options">An <see cref="FileRequestOptions"/> object that specifies additional options for the request.</param>
/// <param name="operationContext">An <see cref="OperationContext"/> object for tracking the current operation.</param>
protected FileReadStreamBase(CloudFile file, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext)
{
if (options.UseTransactionalMD5.Value)
{
CommonUtility.AssertInBounds("StreamMinimumReadSizeInBytes", file.StreamMinimumReadSizeInBytes, 1, Constants.MaxRangeGetContentMD5Size);
}
this.file = file;
this.fileProperties = new FileProperties(file.Properties);
this.currentOffset = 0;
this.streamMinimumReadSizeInBytes = this.file.StreamMinimumReadSizeInBytes;
this.internalBuffer = new MultiBufferMemoryStream(file.ServiceClient.BufferManager);
this.accessCondition = accessCondition;
this.options = options;
this.operationContext = operationContext;
this.fileMD5 = (this.options.DisableContentMD5Validation.Value || string.IsNullOrEmpty(this.fileProperties.ContentMD5)) ? null : new MD5Wrapper();
this.lastException = null;
}
示例11: SetFile
internal static void SetFile(ref SerializableCloudFile fileSerialization, CloudFile value)
{
if (null == fileSerialization
&& null == value)
{
return;
}
if (null != fileSerialization)
{
fileSerialization.File = value;
}
else
{
fileSerialization = new SerializableCloudFile()
{
File = value
};
}
}
示例12: FileWriteStreamBase
/// <summary>
/// Initializes a new instance of the FileWriteStreamBase class for a file.
/// </summary>
/// <param name="file">File reference to write to.</param>
/// <param name="fileSize">Size of the file.</param>
/// <param name="createNew">Use <c>true</c> if the file is newly created, <c>false</c> otherwise.</param>
/// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the access conditions for the file. If <c>null</c>, no condition is used.</param>
/// <param name="options">An <see cref="FileRequestOptions"/> object that specifies additional options for the request.</param>
/// <param name="operationContext">An <see cref="OperationContext"/> object for tracking the current operation.</param>
protected FileWriteStreamBase(CloudFile file, long fileSize, bool createNew, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext)
: base()
{
this.internalBuffer = new MultiBufferMemoryStream(file.ServiceClient.BufferManager);
this.currentOffset = 0;
this.accessCondition = accessCondition;
this.options = options;
this.operationContext = operationContext;
this.noPendingWritesEvent = new CounterEvent();
this.fileMD5 = this.options.StoreFileContentMD5.Value ? new MD5Wrapper() : null;
this.rangeMD5 = this.options.UseTransactionalMD5.Value ? new MD5Wrapper() : null;
this.parallelOperationSemaphore = new AsyncSemaphore(options.ParallelOperationThreadCount.Value);
this.lastException = null;
this.committed = false;
this.disposed = false;
this.currentFileOffset = 0;
this.file = file;
this.fileSize = fileSize;
this.streamWriteSizeInBytes = file.StreamWriteSizeInBytes;
this.newFile = createNew;
}
示例13: GetFileSASToken
private static string GetFileSASToken(CloudFile file)
{
if (null == file.ServiceClient.Credentials
|| file.ServiceClient.Credentials.IsAnonymous)
{
return string.Empty;
}
else if (file.ServiceClient.Credentials.IsSAS)
{
return file.ServiceClient.Credentials.SASToken;
}
// SAS life time is at least 10 minutes.
TimeSpan sasLifeTime = TimeSpan.FromMinutes(CopySASLifeTimeInMinutes);
SharedAccessFilePolicy policy = new SharedAccessFilePolicy()
{
SharedAccessExpiryTime = DateTime.Now.Add(sasLifeTime),
Permissions = SharedAccessFilePermissions.Read,
};
return file.GetSharedAccessSignature(policy);
}
示例14: StartCopyAsync
public virtual Task<string> StartCopyAsync(CloudFile source, AccessCondition sourceAccessCondition, AccessCondition destAccessCondition, BlobRequestOptions options, OperationContext operationContext)
{
return this.StartCopyAsync(source, sourceAccessCondition, destAccessCondition, options, operationContext, CancellationToken.None);
}
示例15: BeginStartCopy
public virtual ICancellableAsyncResult BeginStartCopy(CloudFile source, AccessCondition sourceAccessCondition, AccessCondition destAccessCondition, BlobRequestOptions options, OperationContext operationContext, AsyncCallback callback, object state)
{
return this.BeginStartCopy(CloudFile.SourceFileToUri(source), sourceAccessCondition, destAccessCondition, options, operationContext, callback, state);
}