示例#1
0
 private void RebuildIndex(bool shouldClean, bool force)
 {
     // Fire and forget. When new package is installed, we are not just adding this package to the index,
     // but instead we attempt full sync. Full sync in this case would only sync new packages that don't
     // exist in the index which should be fast. The reason for full sync is that when there are several
     // instances of VS and each tries to update index at the same tiime, only one would succeed, other
     // would notive that index is locked and skip this operation. Thus if all VS instances attempt full
     // sync at least one of them would do it and add all new packages to the index.
     _indexBuildTask = _indexBuilder.BuildAsync(shouldClean: shouldClean, newOnly: _indexBuilder.Index.IndexExists && !force,
                                                cancellationToken: _indexFactory.GetCancellationToken());
 }
        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);
            }
        }
示例#3
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);
            }
        }
        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);
            }
        }