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


C# TemporaryDirectory.Dispose方法代码示例

本文整理汇总了C#中TemporaryDirectory.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# TemporaryDirectory.Dispose方法的具体用法?C# TemporaryDirectory.Dispose怎么用?C# TemporaryDirectory.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TemporaryDirectory的用法示例。


在下文中一共展示了TemporaryDirectory.Dispose方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Download

        /// <summary>
        /// Downloads the installer from the web to a temporary file.
        /// </summary>
        /// <param name="url">The URL of the file to download.</param>
        /// <param name="handler">A callback object used when the the user is to be informed about progress.</param>
        /// <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.</exception>
        /// <exception cref="UnauthorizedAccessException">An operation failed due to insufficient rights.</exception>
        /// <remarks>Use either this or <see cref="SetLocal"/>.</remarks>
        public void Download([NotNull] Uri url, [NotNull] ITaskHandler handler)
        {
            _url = url;

            _tempDir?.Dispose();
            _tempDir = new TemporaryDirectory("0publish");

            try
            {
                _localPath = Path.Combine(_tempDir, url.GetLocalFileName());
                handler.RunTask(new DownloadFile(url, _localPath));
            }
                #region Error handling
            catch (Exception)
            {
                _tempDir.Dispose();
                _tempDir = null;
                _url = null;
                _localPath = null;
                throw;
            }
            #endregion
        }
开发者ID:0install,项目名称:0install-win,代码行数:32,代码来源:InstallerCapture.cs

示例2: LocalApply

        public static TemporaryDirectory LocalApply([NotNull] this DownloadRetrievalMethod retrievalMethod, string localPath, [NotNull] ITaskHandler handler, [CanBeNull] ICommandExecutor executor = null)
        {
            #region Sanity checks
            if (retrievalMethod == null) throw new ArgumentNullException("retrievalMethod");
            if (string.IsNullOrEmpty(localPath)) throw new ArgumentNullException("localPath");
            if (handler == null) throw new ArgumentNullException("handler");
            #endregion

            if (executor == null) executor = new SimpleCommandExecutor();

            // Set local file size
            long newSize = new FileInfo(localPath).Length;
            if (retrievalMethod.Size != newSize)
                executor.Execute(new SetValueCommand<long>(() => retrievalMethod.Size, value => retrievalMethod.Size = value, newSize));

            var extractionDir = new TemporaryDirectory("0publish");
            try
            {
                new PerTypeDispatcher<DownloadRetrievalMethod>(ignoreMissing: true)
                {
                    // ReSharper disable AccessToDisposedClosure
                    (Archive archive) =>
                    {
                        // Guess MIME types now because the file ending is not known later
                        if (string.IsNullOrEmpty(archive.MimeType))
                        {
                            string mimeType = Archive.GuessMimeType(localPath);
                            executor.Execute(new SetValueCommand<string>(() => archive.MimeType, value => archive.MimeType = value, mimeType));
                        }

                        archive.Apply(localPath, extractionDir, handler);
                    },
                    (SingleFile file) =>
                    {
                        // Guess file name based on local path
                        if (string.IsNullOrEmpty(file.Destination))
                        {
                            string destination = Path.GetFileName(localPath);
                            executor.Execute(new SetValueCommand<string>(() => file.Destination, value => file.Destination = value, destination));
                        }

                        file.Apply(localPath, extractionDir, handler);
                    }
                    // ReSharper restore AccessToDisposedClosure
                }.Dispatch(retrievalMethod);
            }
                #region Error handling
            catch
            {
                extractionDir.Dispose();
                throw;
            }
            #endregion

            return extractionDir;
        }
开发者ID:modulexcite,项目名称:0install-win,代码行数:56,代码来源:RetrievalMethodUtils.cs

示例3: Apply

        public static TemporaryDirectory Apply([NotNull] this Recipe recipe, [NotNull, ItemNotNull] IEnumerable<TemporaryFile> downloadedFiles, [NotNull] ITaskHandler handler, [CanBeNull] object tag = null)
        {
            #region Sanity checks
            if (recipe == null) throw new ArgumentNullException("recipe");
            if (downloadedFiles == null) throw new ArgumentNullException("downloadedFiles");
            if (handler == null) throw new ArgumentNullException("handler");
            #endregion

            if (recipe.UnknownElements != null && recipe.UnknownElements.Length != 0)
                throw new NotSupportedException(string.Format(Resources.UnknownRecipeStepType, recipe.UnknownElements[0].Name));

            var workingDir = new TemporaryDirectory("0install-recipe");

            try
            {
                IEnumerator<TemporaryFile> downloadedEnum = downloadedFiles.GetEnumerator();
                // ReSharper disable AccessToDisposedClosure
                new PerTypeDispatcher<IRecipeStep>(ignoreMissing: false)
                {
                    (Archive step) =>
                    {
                        downloadedEnum.MoveNext();
                        if (downloadedEnum.Current == null) throw new ArgumentException(Resources.RecipeFileNotDownloaded, "downloadedFiles");
                        step.Apply(downloadedEnum.Current, workingDir, handler, tag);
                    },
                    (SingleFile step) =>
                    {
                        downloadedEnum.MoveNext();
                        if (downloadedEnum.Current == null) throw new ArgumentException(Resources.RecipeFileNotDownloaded, "downloadedFiles");
                        step.Apply(downloadedEnum.Current, workingDir, handler, tag);
                    },
                    (RemoveStep step) => step.Apply(workingDir),
                    (RenameStep step) => step.Apply(workingDir)
                }.Dispatch(recipe.Steps);
                // ReSharper restore AccessToDisposedClosure
                return workingDir;
            }
                #region Error handling
            catch
            {
                workingDir.Dispose();
                throw;
            }
            #endregion
        }
开发者ID:modulexcite,项目名称:0install-win,代码行数:45,代码来源:RecipeUtils.cs

示例4: DownloadAndApply

        public static TemporaryDirectory DownloadAndApply([NotNull] this DownloadRetrievalMethod retrievalMethod, [NotNull] ITaskHandler handler, [CanBeNull] ICommandExecutor executor = null)
        {
            #region Sanity checks
            if (retrievalMethod == null) throw new ArgumentNullException("retrievalMethod");
            if (handler == null) throw new ArgumentNullException("handler");
            #endregion

            using (var downloadedFile = retrievalMethod.Download(handler, executor))
            {
                var extractionDir = new TemporaryDirectory("0publish");
                try
                {
                    new PerTypeDispatcher<DownloadRetrievalMethod>(ignoreMissing: false)
                    {
                        // ReSharper disable AccessToDisposedClosure
                        (Archive archive) => archive.Apply(downloadedFile, extractionDir, handler),
                        (SingleFile file) => file.Apply(downloadedFile, extractionDir, handler)
                        // ReSharper restore AccessToDisposedClosure
                    }.Dispatch(retrievalMethod);
                }
                    #region Error handling
                catch
                {
                    extractionDir.Dispose();
                    throw;
                }
                #endregion

                return extractionDir;
            }
        }
开发者ID:modulexcite,项目名称:0install-win,代码行数:31,代码来源:RetrievalMethodUtils.cs


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