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


C# IPackageManager.FindPackages方法代码示例

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


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

示例1: Execute

        /// <summary>
        /// Executes this action.
        /// </summary>
        /// <param name="pkgmgr">package manager instance</param>
        public void Execute(IPackageManager pkgmgr)
        {
            MergeWorker mw = new MergeWorker(pkgmgr);

            AbstractTree tree = LocalRepository.Read();
            List<IDistribution> mergeset = new List<IDistribution>();
            List<Atom> atomset = new List<Atom>();

            _numpkgs = 0;
            _dloadsz = 0;
            _hardmask = new List<Atom>();
            _kwmask = new List<Tuple<Atom, string[]>>();

            try {
                /* expand world */
                if (_atomlst.Contains("world")) {
                    atomset.AddRange(pkgmgr.WorldSet);
                    _atomlst.Remove("world");
                }

                atomset.AddRange(Atom.ParseAll(_atomlst.ToArray()));

                foreach (Atom atom in atomset) {
                    /* first find all installed packages matching the given atom */
                    Atom[] instarr = pkgmgr.FindPackages(atom).ToArray();

                    /* then find unique installed packages, and slotted packages with the
                       highest version number */
                    Atom[] latestinst = instarr
                        .Where(i => instarr.Where(n => n.PackageName == i.PackageName).Count() == 1 ||
                                    instarr.Where(n => n.PackageName == i.PackageName)
                                           .Max(n => n.Version.ToString()) == i.Version.ToString())
                        .ToArray();
                    if (latestinst.Length > 1)
                        throw new AmbiguousMatchException(atom.ToString());

                    try {
                        /* if we're not updating, no version or slot was specified, and there's a version
                         * already installed then select the installed version */
                        IDistribution dist =
                            (!_options.update && !atom.HasVersion && atom.Slot == 0 && latestinst.Length > 0) ?
                                tree.Lookup(latestinst[0]) :
                                tree.Lookup(atom);
                        mergeset.Add(dist);
                    } catch (PackageNotFoundException ex) {
                        /* we can ignore this exception if we're updating */
                        if (!_options.update)
                            throw ex;
                    }
                }
            } catch (AmbiguousMatchException ex) {
                SearchAction sa = new SearchAction(ex.Atom);
                sa.Options = new Options() { exact = true };
                sa.Execute(pkgmgr);

                throw ex;
            }

            MergeOptions mopts = 0;

            if (_options.pretend)
                mopts |= MergeOptions.Pretend;
            if (_options.oneshot)
                mopts |= MergeOptions.OneShot;
            if (_options.noreplace || _options.update)
                mopts |= MergeOptions.NoReplace;
            if (_options.emptytree)
                mopts |= MergeOptions.EmptyTree;
            if (_options.fetchonly)
                mopts |= MergeOptions.FetchOnly;
            if (_options.deep)
                mopts |= MergeOptions.Deep;

            try {
                if (mopts.HasFlag(MergeOptions.Pretend)) {
                    mw.OnPretendMerge += this.MergeWorker_OnPretendMerge;
                    Console.WriteLine("\nThese are the packages that would be merged, in order:\n");
                } else {
                    mw.OnRealMerge += this.MergeWorker_OnRealMerge;
                    mw.OnParallelFetch += this.MergeWorker_OnParallelFetch;
                    mw.OnInstall += this.MergeWorker_OnInstall;
                    mw.OnAutoClean += this.MergeWorker_OnAutoClean;

                    Security.DemandNTAdmin();
                }

                mw.Merge(mergeset.ToArray(), mopts);

                if (mopts.HasFlag(MergeOptions.Pretend)) {
                    if (_repolst.Count > 0) {
                        Console.WriteLine("\nRepositories:");
                        for (int i = 0; i < _repolst.Count; i++) {
                            Console.ForegroundColor = ConsoleColor.Cyan;
                            Console.Write(" [{0}] ", i);
                            Console.ResetColor();
                            Console.Write("{0}\n", _repolst[i]);
//.........这里部分代码省略.........
开发者ID:rcarz,项目名称:fusion,代码行数:101,代码来源:MergeAction.cs

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