当前位置: 首页>>代码示例>>C#>>正文


C# TemporaryFile.Dispose方法代码示例

本文整理汇总了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);
        }
开发者ID:D4rkTiger,项目名称:EFDocumentationGenerator,代码行数:12,代码来源:TemporaryFileTests.cs

示例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();
        }
开发者ID:TheJeremyGray,项目名称:FileWatcherService,代码行数:20,代码来源:EmailService.cs

示例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");
 }
开发者ID:constructor-igor,项目名称:NFile,代码行数:8,代码来源:TemporaryFileTests.cs

示例4: Dispose_FileCaught_ExpectedException

 public void Dispose_FileCaught_ExpectedException()
 {
     var temporaryFile = new TemporaryFile();
     using (new FileStream(temporaryFile.FileName, FileMode.Open))
     {
         temporaryFile.Dispose();
     }
 }
开发者ID:constructor-igor,项目名称:NFile,代码行数:8,代码来源:TemporaryFileTests.cs

示例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
        }
开发者ID:modulexcite,项目名称:0install-win,代码行数:30,代码来源:FetcherBase.cs


注:本文中的TemporaryFile.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。