private void ExecuteSearch(CompletionContext context, string searchTerm)
 {
     ThreadPool.QueueUserWorkItem(state =>
     {
         DteHelper.ExecuteCommand("Edit.CompleteWord");
     });
 }
Esempio n. 2
0
        public static void ShowAddPackageDialog(string selectedFileName, string projectGuid = null)
        {
            Paket.Dependencies dependenciesFile = null;

            try
            {
                dependenciesFile = Dependencies.Locate(selectedFileName);
            }
            catch (Exception)
            {
                var dir = new System.IO.FileInfo(SolutionExplorerExtensions.GetSolutionFileName()).Directory.FullName;
                PaketLauncher.LaunchPaket(dir, "init",
                                          (send, args) => PaketOutputPane.OutputPane.OutputStringThreadSafe(args.Data + "\n"));
                dependenciesFile = Dependencies.Locate(selectedFileName);
            }

            var secondWindow = new AddPackage();

            //Create observable paket trace
            var paketTraceObs = Observable.Create <Logging.Trace>(observer =>
            {
                [email protected](x => observer.OnNext(x));
                return(Disposable.Create(() =>
                {
                }));
            });

            Action <NugetResult> addPackageToDependencies = result =>
            {
                if (projectGuid != null)
                {
                    var guid = Guid.Parse(projectGuid);
                    DteHelper.ExecuteCommand("File.SaveAll");
                    SolutionExplorerExtensions.UnloadProject(guid);
                    PaketLauncher.LaunchPaket(SolutionExplorerExtensions.GetSolutionDirectory(), "add " + result.PackageName + " --project " + selectedFileName,
                                              (send, args) => PaketOutputPane.OutputPane.OutputStringThreadSafe(args.Data + "\n"));
                    SolutionExplorerExtensions.ReloadProject(guid);
                }
                else
                {
                    PaketLauncher.LaunchPaket(SolutionExplorerExtensions.GetSolutionDirectory(), "add " + result.PackageName,
                                              (send, args) => PaketOutputPane.OutputPane.OutputStringThreadSafe(args.Data + "\n"));
                }
            };

            Func <string, IObservable <string> > searchNuGet =
                searchText => Observable.Create <string>(obs =>
            {
                var disposable = new CancellationDisposable();

                dependenciesFile
                .SearchPackagesByName(
                    searchText,
                    FSharpOption <CancellationToken> .Some(disposable.Token),
                    FSharpOption <int> .None)
                .Subscribe(obs);

                return(disposable);
            });

            //TODO: Use interfaces?
            secondWindow.ViewModel = new AddPackageViewModel(searchNuGet, addPackageToDependencies, paketTraceObs);
            secondWindow.ShowDialog();
        }