<commit_before>﻿using HotChocolatey.Utility;
using NuGet;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

namespace HotChocolatey.Model
{
    public class ChocoExecutor
    {
        private readonly PackageRepo repo;
        private readonly NuGetExecutor nuGetExecutor;

        public List<Package> LocalPackages { get; } = new List<Package>();

        public ChocoExecutor(PackageRepo repo, NuGetExecutor nuGetExecutor)
        {
            this.repo = repo;
            this.nuGetExecutor = nuGetExecutor;
        }

        public async Task Update()
        {
            LocalPackages.Clear();
            repo.ClearLocalVersions();
            await UpdateLocal();
            await UpdateOutdated();
            await UpdateNuGetInfo();
        }

        public async Task Install(Package package, SemanticVersion specificVersion, Action<string> outputLineCallback)
        {
            Log.Info($"{nameof(Install)}: {package.Id} version:{specificVersion}");

            var version = specificVersion != null ? $" --version={specificVersion}" : string.Empty;
            var result = await Execute($"install -r -y {package.Id} {version}", outputLineCallback);

            if (!result)
            {
                Log.Error($"{nameof(Install)} failed for the following package: {package.Id}");
            }
        }

        public async Task Uninstall(Package package, Action<string> outputLineCallback)
        {
            Log.Info($"{nameof(Uninstall)}: {package.Id}");

            var result = await Execute($"uninstall -r -y {package.Id}", outputLineCallback);

            if (!result)
            {
                Log.Error($"{nameof(Uninstall)} failed for the following package: {package.Id}");
            }
        }

        public async Task Upgrade(Package package, SemanticVersion specificVersion, Action<string> outputLineCallback)
        {
            Log.Info($"{nameof(Upgrade)}: {package.Id} version:{specificVersion}");

            var version = specificVersion != null ? $" --version={specificVersion}" : string.Empty;
            var result = await Execute($"upgrade -r -y {package.Id} {version}", outputLineCallback);

            if (!result)
            {
                Log.Error($"{nameof(Upgrade)} failed for the following package: {package.Id}");
            }
        }

        private async Task UpdateLocal()
        {
            await Execute("list -r -l", UpdateLocalPackage);
        }

        private void UpdateLocalPackage(string chocoOutput)
        {
            var tmp = chocoOutput.Split('|');
            var p = repo.GetPackage(tmp[0]);
            p.InstalledVersion = new SemanticVersion(tmp[1]);
            LocalPackages.Add(p);
        }

        private async Task UpdateOutdated()
        {
            await Execute("outdated -r", UpdateOutdatedFlag);
        }

        private void UpdateOutdatedFlag(string chocoOutput)<commit_msg>Fix: version seperator issue<commit_after>﻿using HotChocolatey.Utility;
using NuGet;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

namespace HotChocolatey.Model
{
    public class ChocoExecutor
    {
        private readonly PackageRepo repo;
        private readonly NuGetExecutor nuGetExecutor;

        public List<Package> LocalPackages { get; } = new List<Package>();

        public ChocoExecutor(PackageRepo repo, NuGetExecutor nuGetExecutor)
        {
            this.repo = repo;
            this.nuGetExecutor = nuGetExecutor;
        }

        public async Task Update()
        {
            LocalPackages.Clear();
            repo.ClearLocalVersions();
            await UpdateLocal();
            await UpdateOutdated();
            await UpdateNuGetInfo();
        }

        public async Task Install(Package package, SemanticVersion specificVersion, Action<string> outputLineCallback)
        {
            Log.Info($"{nameof(Install)}: {package.Id} version:{specificVersion}");

            var version = specificVersion != null ? $" --version={specificVersion}" : string.Empty;
            var result = await Execute($"install -r -y {package.Id} {version}", outputLineCallback);

            if (!result)
            {
                Log.Error($"{nameof(Install)} failed for the following package: {package.Id}");
            }
        }

        public async Task Uninstall(Package package, Action<string> outputLineCallback)
        {
            Log.Info($"{nameof(Uninstall)}: {package.Id}");

            var result = await Execute($"uninstall -r -y {package.Id}", outputLineCallback);

            if (!result)
            {
                Log.Error($"{nameof(Uninstall)} failed for the following package: {package.Id}");
            }
        }

        public async Task Upgrade(Package package, SemanticVersion specificVersion, Action<string> outputLineCallback)
        {
            Log.Info($"{nameof(Upgrade)}: {package.Id} version:{specificVersion}");

            var version = specificVersion != null ? $" --version={specificVersion}" : string.Empty;
            var result = await Execute($"upgrade -r -y {package.Id} {version}", outputLineCallback);

            if (!result)
            {
                Log.Error($"{nameof(Upgrade)} failed for the following package: {package.Id}");
            }
        }

        private async Task UpdateLocal()
        {
            await Execute("list -r -l", UpdateLocalPackage);
        }

        private void UpdateLocalPackage(string chocoOutput)
        {
            var tmp = chocoOutput.Split(' ');
            var p = repo.GetPackage(tmp[0]);
            p.InstalledVersion = new SemanticVersion(tmp[1]);
            LocalPackages.Add(p);
        }

        private async Task UpdateOutdated()
        {
            await Execute("outdated -r", UpdateOutdatedFlag);
        }

        private void UpdateOutdatedFlag(string chocoOutput)
{'fraction_non_alphanumeric': 0.10935155859309885, 'fraction_numerical': 0.0006667777962993832, 'mean_word_length': 2.203416978109984, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '5090853', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1533, 'n_words': 376}