本文整理汇总了C#中IPackageManager.GetInstalledPackages方法的典型用法代码示例。如果您正苦于以下问题:C# IPackageManager.GetInstalledPackages方法的具体用法?C# IPackageManager.GetInstalledPackages怎么用?C# IPackageManager.GetInstalledPackages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPackageManager
的用法示例。
在下文中一共展示了IPackageManager.GetInstalledPackages方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
/// <summary>
/// Executes this action.
/// </summary>
/// <param name="pkgmgr">package manager instance</param>
public void Execute(IPackageManager pkgmgr)
{
Security.DemandNTAdmin();
List<Atom> atomlst = Atom.ParseAll(_atomlst.ToArray()).ToList();
List<Atom> allselected = new List<Atom>();
List<Atom> allprotected = new List<Atom>();
List<Atom> allomitted = new List<Atom>();
foreach (Atom atom in atomlst) {
Atom[] instatoms = pkgmgr.FindPackages(atom);
if (instatoms.Length == 0)
throw new PackageNotFoundException(atom.ToString());
allselected.AddRange(instatoms);
}
allprotected = allselected
.Where(i => pkgmgr.IsProtected(i))
.ToList();
foreach (Atom a in allprotected)
allselected.Remove(a);
allomitted = pkgmgr.GetInstalledPackages()
.Where(i => allselected.Where(
s => s.PackageName == i.PackageName).Count() > 0)
.Where(i => allselected.Where(
s => s.PackageName == i.PackageName &&
s.Version == i.Version).Count() == 0)
.ToList();
string[] allpackages = allselected
.Select(i => i.PackageName)
.Union(allprotected.Select(i => i.PackageName))
.Union(allomitted.Select(i => i.PackageName))
.OrderBy(i => i)
.ToArray();
foreach (string pkg in allpackages) {
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("\n {0}", pkg);
Console.ResetColor();
string[] pkgselected = allselected
.Where(i => i.PackageName == pkg)
.OrderBy(i => i.Version)
.Select(i => i.Version.ToString())
.ToArray();
string[] pkgprotected = allprotected
.Where(i => i.PackageName == pkg)
.OrderBy(i => i.Version)
.Select(i => i.Version.ToString())
.ToArray();
string[] pkgomitted = allomitted
.Where(i => i.PackageName == pkg)
.OrderBy(i => i.Version)
.Select(i => i.Version.ToString())
.ToArray();
Console.Write(" selected: ");
if (pkgselected.Length > 0) {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(String.Join(" ", pkgselected));
Console.ResetColor();
} else
Console.WriteLine("none");
Console.Write(" protected: ");
if (pkgprotected.Length > 0) {
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(String.Join(" ", pkgprotected));
Console.ResetColor();
} else
Console.WriteLine("none");
Console.Write(" omitted: ");
if (pkgomitted.Length > 0) {
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(String.Join(" ", pkgomitted));
Console.ResetColor();
} else
Console.WriteLine("none");
}
Console.WriteLine(
"\nAll selected packages: {0}",
String.Join(" ", allselected.Select(i => i.ToString())));
Console.Write("\n>>> ");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Selected");
Console.ResetColor();
Console.WriteLine(" packages are scheduled for removal.");
Console.Write(">>> ");
//.........这里部分代码省略.........