<commit_before>﻿using System.Reactive.Disposables;
using Microsoft.FSharp.Control;
using Microsoft.FSharp.Core;
using System;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Paket.VisualStudio.Commands.PackageGui;
using Paket.VisualStudio.SolutionExplorer;

namespace Paket.VisualStudio.Commands
{
    public class AddPackageProcess
    {
        public static Task<string[]> SearchPackagesByName(string search, CancellationToken ct)
        {
            //TODO: this should probably return a success/failure type to indicate whether the search was successful.  (Like lack of internet, nuget down)
            return FSharpAsync.StartAsTask(
                NuGetV3.FindPackages(FSharpOption<Paket.Utils.Auth>.None, Constants.DefaultNugetStream, search, 1000),
                FSharpOption<TaskCreationOptions>.None,
                FSharpOption<CancellationToken>.Some(ct));
        }

        public static void ShowAddPackageDialog(string selectedFileName, string projectGuid = null)
        {
            var dependenciesFile = Paket.Dependencies.Locate(selectedFileName);

            var secondWindow = new AddPackage();

            //Create observable paket trace
            var paketTraceObs = Observable.Create<string>(observer =>
            {
                Paket.Logging.RegisterTraceFunction(observer.OnNext);
                return Disposable.Create(() =>
                {
                    Paket.Logging.RemoveTraceFunction(observer.OnNext);
                });
            });

            Action<NugetResult> addPackageToDependencies = result =>
            {
                var packageName = result.PackageName;

                if (projectGuid != null)
                {
                    var guid = Guid.Parse(projectGuid);
                    SolutionExplorerExtensions.UnloadProject(guid);
                    dependenciesFile.AddToProject(packageName, "", false, false, selectedFileName, true);
                    SolutionExplorerExtensions.ReloadProject(guid);
                }
                else
                    dependenciesFile.Add(packageName, "", false, false, false, true);
            };
            //TODO: Use interfaces?
            secondWindow.ViewModel = new AddPackageViewModel(SearchPackagesByName, addPackageToDependencies, paketTraceObs);
            secondWindow.ShowDialog();
        }
    }
}<commit_msg>Small inline<commit_after>﻿using System.Reactive.Disposables;
using Microsoft.FSharp.Control;
using Microsoft.FSharp.Core;
using System;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Paket.VisualStudio.Commands.PackageGui;
using Paket.VisualStudio.SolutionExplorer;

namespace Paket.VisualStudio.Commands
{
    public class AddPackageProcess
    {
        public static Task<string[]> SearchPackagesByName(string search, CancellationToken ct)
        {
            //TODO: this should probably return a success/failure type to indicate whether the search was successful.  (Like lack of internet, nuget down)
            return FSharpAsync.StartAsTask(
                NuGetV3.FindPackages(FSharpOption<Paket.Utils.Auth>.None, Constants.DefaultNugetStream, search, 1000),
                FSharpOption<TaskCreationOptions>.None,
                FSharpOption<CancellationToken>.Some(ct));
        }

        public static void ShowAddPackageDialog(string selectedFileName, string projectGuid = null)
        {
            var dependenciesFile = Paket.Dependencies.Locate(selectedFileName);

            var secondWindow = new AddPackage();

            //Create observable paket trace
            var paketTraceObs = Observable.Create<string>(observer =>
            {
                Paket.Logging.RegisterTraceFunction(observer.OnNext);
                return Disposable.Create(() =>
                {
                    Paket.Logging.RemoveTraceFunction(observer.OnNext);
                });
            });

            Action<NugetResult> addPackageToDependencies = result =>
            {
                if (projectGuid != null)
                {
                    var guid = Guid.Parse(projectGuid);
                    SolutionExplorerExtensions.UnloadProject(guid);
                    dependenciesFile.AddToProject(result.PackageName, "", false, false, selectedFileName, true);
                    SolutionExplorerExtensions.ReloadProject(guid);
                }
                else
                    dependenciesFile.Add(result.PackageName, "", false, false, false, true);
            };
            //TODO: Use interfaces?
            secondWindow.ViewModel = new AddPackageViewModel(SearchPackagesByName, addPackageToDependencies, paketTraceObs);
            secondWindow.ShowDialog();
        }
    }
}
{'fraction_non_alphanumeric': 0.08229684908789386, 'fraction_numerical': 0.0020729684908789387, 'mean_word_length': 2.251347708894879, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '974738', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1145, 'n_words': 240}