當前位置: 首頁>>代碼示例>>C#>>正文


C# Progress.CompletedInstall方法代碼示例

本文整理匯總了C#中System.Progress.CompletedInstall方法的典型用法代碼示例。如果您正苦於以下問題:C# Progress.CompletedInstall方法的具體用法?C# Progress.CompletedInstall怎麽用?C# Progress.CompletedInstall使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Progress的用法示例。


在下文中一共展示了Progress.CompletedInstall方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: InstallAsync

        public async Task<DirectoryInfo> InstallAsync(Progress progress)
        {
            var fetcher = fetchers.FirstOrDefault(f => f.IsMatch(pkg));
            if (fetcher == null)
            {
                throw new NotSupportedException($"Could not fetch package '{pkg}'");
            }
            var tmpPkg = await fetcher.FetchAsync(pkg, progress);
            string hash = null;
            if (File.Exists(tmpPkg.FullPath))
            {
                // FullPath exists in most cases, but is absent for directory install
                hash = await FileSystem.GetSha1Async(tmpPkg.FullPath);
            }
            // Only check when Sha1 is specified in the package metadata
            if (!string.IsNullOrWhiteSpace(pkg.Sha1) &&
                !string.Equals(hash, pkg.Sha1, StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidDataException($"SHA1 hash of remote file {pkg.Location} did not match {pkg.Sha1}");
            }
            var version = pkg.ResolveVersion() ?? hash ?? "default";

            // Save package information to disk first
            Directory.CreateDirectory(pkgDir);
            Json.Save(pkg, Path.Combine(pkgDir, "pkg.json"), true);

            // TODO: replace hash with version resolution
            var installDir = Path.Combine(pkgDir, version);
            Directory.CreateDirectory(installDir);

            var extractor = extractors[pkg.Type].FirstOrDefault(e => e.IsMatch(tmpPkg));
            if (extractor == null)
            {
                throw new NotSupportedException($"Could not extract package '{pkg}'");
            }
            await extractor.ExtractAsync(tmpPkg, installDir, progress);
            progress.CompletedInstall();
            return new DirectoryInfo(installDir);
        }
開發者ID:mattolenik,項目名稱:winston,代碼行數:39,代碼來源:PackageClient.cs


注:本文中的System.Progress.CompletedInstall方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。