本文整理汇总了C#中TemporaryFile.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# TemporaryFile.Dispose方法的具体用法?C# TemporaryFile.Dispose怎么用?C# TemporaryFile.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TemporaryFile
的用法示例。
在下文中一共展示了TemporaryFile.Dispose方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_Dispose
public void Test_Dispose()
{
// Arrange.
var temp = new TemporaryFile().Touch();
// Act.
temp.Dispose();
temp.File.Refresh();
// Assert.
Assert.False(temp.File.Exists);
}
示例2: EmailWebServiceWithAttachment
public void EmailWebServiceWithAttachment(string To, string From, string Subject, string Body, byte[] Attachment, string AttachmentName)
{
SmtpClient smtpclient = new SmtpClient { Host = smtpServer };
MailMessage message = GetMailMessage(To, From, Subject, Body);
TemporaryFile tempFile = new TemporaryFile("", AttachmentName);
FileStream objfilestream = new FileStream(tempFile.FilePath, FileMode.Create, FileAccess.ReadWrite);
using (BinaryWriter writer = new BinaryWriter(objfilestream))
{
writer.Write(Attachment);
}
Attachment a = new Attachment(tempFile.FilePath);
message.Attachments.Add(a);
smtpclient.Send(message);
a.Dispose();
tempFile.Dispose();
smtpclient.Dispose();
}
示例3: FileName_AfterDispose_GenerateObjectDisposedException
public void FileName_AfterDispose_GenerateObjectDisposedException()
{
var temporaryFile = new TemporaryFile();
Assert.That(temporaryFile.FileName, Is.Not.Null);
temporaryFile.Dispose();
string fileName = temporaryFile.FileName;
Assert.Fail("expected exception ObjectDisposedException");
}
示例4: Dispose_FileCaught_ExpectedException
public void Dispose_FileCaught_ExpectedException()
{
var temporaryFile = new TemporaryFile();
using (new FileStream(temporaryFile.FileName, FileMode.Open))
{
temporaryFile.Dispose();
}
}
示例5: Download
/// <summary>
/// Downloads a <see cref="DownloadRetrievalMethod"/> to a temporary file.
/// </summary>
/// <param name="retrievalMethod">The file to download.</param>
/// <param name="tag">The <see cref="ITask.Tag"/> to set for the download process.</param>
/// <returns>The downloaded temporary file.</returns>
/// <exception cref="OperationCanceledException">A download was canceled from another thread.</exception>
/// <exception cref="WebException">A file could not be downloaded from the internet.</exception>
/// <exception cref="IOException">A downloaded file could not be written to the disk or.</exception>
/// <exception cref="UnauthorizedAccessException">Write access to <see cref="IStore"/> is not permitted.</exception>
protected virtual TemporaryFile Download([NotNull] DownloadRetrievalMethod retrievalMethod, [CanBeNull] object tag = null)
{
#region Sanity checks
if (retrievalMethod == null) throw new ArgumentNullException("retrievalMethod");
#endregion
var tempFile = new TemporaryFile("0install-fetcher");
try
{
Handler.RunTask(new DownloadFile(retrievalMethod.Href, tempFile, retrievalMethod.DownloadSize) {Tag = tag});
return tempFile;
}
#region Error handling
catch
{
tempFile.Dispose();
throw;
}
#endregion
}