private void ProcessAction(ILocalPackageIndexBuilder builder, Arguments arguments, bool commandMode)
        {
            LocalPackageIndexBuilderResult result = null;

            switch (arguments.Action)
            {
            case PackageIndexManagerAction.Build:
                result = builder.BuildAsync().Result;
                break;

            case PackageIndexManagerAction.Rebuild:
                result = builder.Rebuild();
                break;

            case PackageIndexManagerAction.Clean:
                result = builder.Clean();
                break;

            case PackageIndexManagerAction.Add:
                if (!string.IsNullOrEmpty(arguments.Package))
                {
                    result = builder.AddPackage(arguments.Package, arguments.Force);
                }
                else
                {
                    _consoleUI.WriteNormalLine(Resources.PackageIsMissingToAdd);
                }
                break;

            case PackageIndexManagerAction.Remove:
                if (!string.IsNullOrEmpty(arguments.Package))
                {
                    result = builder.RemovePackage(arguments.Package);
                }
                else
                {
                    _consoleUI.WriteNormalLine(Resources.PackageIsMissingToRemove);
                }
                break;

            case PackageIndexManagerAction.Query:
                if (!string.IsNullOrEmpty(arguments.Type))
                {
                    DoQuery(() => { return(builder.Index.GetTypes(arguments.Type).Select(x => (object)x).ToList()); });
                }
                else if (!string.IsNullOrEmpty(arguments.Package))
                {
                    DoQuery(() => { return(builder.Index.GetPackages(arguments.Package).Select(x => (object)x).ToList()); });
                }
                else
                {
                    _consoleUI.WriteNormalLine(Resources.PackageOrTypeIsMissing);
                }
                break;

            default:
                _consoleUI.WriteNormalLine(Resources.ActionUnrecognized);
                return;
            }

            if (result != null)
            {
                _consoleUI.WriteHighlitedLine(string.Format(Resources.TimeElapsed, result.TimeElapsed));
                _consoleUI.WriteNormalLine(string.Empty);
            }
        }
Пример #2
0
        private void ProcessAction(ILocalPackageIndexBuilder builder, Arguments arguments, bool commandMode)
        {
            LocalPackageIndexBuilderResult result = null;

            switch (arguments.Action)
            {
            case PackageIndexManagerAction.Build:
                result = builder.BuildAsync(shouldClean: false, newOnly: false, cancellationToken: CancellationToken.None).Result;
                break;

            case PackageIndexManagerAction.Rebuild:
                result = builder.Rebuild();
                break;

            case PackageIndexManagerAction.Clean:
                result = builder.Clean();
                break;

            case PackageIndexManagerAction.Add:
                if (!string.IsNullOrEmpty(arguments.Package))
                {
                    result = builder.AddPackage(arguments.Package, arguments.Force);
                }
                else
                {
                    _consoleUI.WriteNormalLine(Resources.PackageIsMissingToAdd);
                }
                break;

            case PackageIndexManagerAction.Remove:
                if (!string.IsNullOrEmpty(arguments.Package))
                {
                    result = builder.RemovePackage(packageName: arguments.Package, force: false);
                }
                else
                {
                    _consoleUI.WriteNormalLine(Resources.PackageIsMissingToRemove);
                }
                break;

            case PackageIndexManagerAction.Query:
                if (!string.IsNullOrEmpty(arguments.Type))
                {
                    DoQuery(() => { return(builder.Index.GetTypes(arguments.Type).Select(x => (object)x).ToList()); });
                }
                else if (!string.IsNullOrEmpty(arguments.Package))
                {
                    DoQuery(() => { return(builder.Index.GetPackages(arguments.Package).Select(x => (object)x).ToList()); });
                }
                else if (!string.IsNullOrEmpty(arguments.Namespace))
                {
                    DoQuery(() => { return(builder.Index.GetNamespaces(arguments.Namespace).Select(x => (object)x).ToList()); });
                }
                else if (!string.IsNullOrEmpty(arguments.Extension))
                {
                    DoQuery(() => { return(builder.Index.GetExtensions(arguments.Extension).Select(x => (object)x).ToList()); });
                }
                else
                {
                    _consoleUI.WriteNormalLine(Resources.PackageOrTypeIsMissing);
                }
                break;

            case PackageIndexManagerAction.Dump:
                var dumpFile = arguments.DumpFile;
                if (string.IsNullOrEmpty(dumpFile))
                {
                    dumpFile = "IndexDump.csv";
                }

                DumpIndex(builder, dumpFile);
                break;

            default:
                _consoleUI.WriteNormalLine(Resources.ActionUnrecognized);
                return;
            }

            if (result != null)
            {
                _consoleUI.WriteHighlitedLine(string.Format(Resources.TimeElapsed, result.TimeElapsed));
                _consoleUI.WriteNormalLine(string.Empty);
            }
        }