本文整理汇总了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);
}