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


C# IPackageManager.GetInstalledPackages方法代码示例

本文整理汇总了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(">>> ");
//.........这里部分代码省略.........
开发者ID:rcarz,项目名称:fusion,代码行数:101,代码来源:UnmergeAction.cs


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