<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using NuGet;
using NuGetPackageExplorer.Types;

namespace PackageExplorerViewModel
{
    public class PluginManagerViewModel : INotifyPropertyChanged, IComparer<PluginInfo>
    {
        private readonly IPackageChooser _packageChooser;
        private readonly IPackageDownloader _packageDownloader;
        private readonly IPluginManager _pluginManager;
        private readonly IUIServices _uiServices;
        private SortedCollection<PluginInfo> _plugins;

        public PluginManagerViewModel(
            IPluginManager pluginManager,
            IUIServices uiServices,
            IPackageChooser packageChooser,
            IPackageDownloader packageDownloader)
        {
            if (pluginManager == null)
            {
                throw new ArgumentNullException("pluginManager");
            }

            if (packageChooser == null)
            {
                throw new ArgumentNullException("packageChooser");
            }

            if (uiServices == null)
            {
                throw new ArgumentNullException("uiServices");
            }

            if (packageDownloader == null)
            {
                throw new ArgumentNullException("packageDownloader");
            }

            _pluginManager = pluginManager;
            _uiServices = uiServices;
            _packageChooser = packageChooser;
            _packageDownloader = packageDownloader;

            DeleteCommand = new RelayCommand<PluginInfo>(DeleteCommandExecute, DeleteCommandCanExecute);
            AddCommand = new RelayCommand<string>(AddCommandExecute);
        }

        public ICollection<PluginInfo> Plugins
        {
            get
            {
                if (_plugins == null)
                {
                    _plugins = new SortedCollection<PluginInfo>(_pluginManager.Plugins, this);
                }
                return _plugins;
            }
        }

        public RelayCommand<PluginInfo> DeleteCommand { get; private set; }

        public RelayCommand<string> AddCommand { get; private set; }

        #region IComparer<PluginInfo> Members

        public int Compare(PluginInfo x, PluginInfo y)
        {
            int result = String.Compare(x.Id, y.Id, StringComparison.CurrentCultureIgnoreCase);
            if (result != 0)
            {
                return result;
            }

            return x.Version.CompareTo(y.Version);
        }

        #endregion

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        #endregion

        private void AddCommandExecute(string parameter)
        {
            if (parameter == "Local")
            {
                AddLocalPlugin();
            }
            else if (parameter == "Remote")
            {
                AddFeedPlugin();
            }
        }

        private void AddFeedPlugin()
        {
            PackageInfo selectedPackageInfo = _packageChooser.SelectPluginPackage();
            if (selectedPackageInfo != null)<commit_msg>before opening package chooser dialog for plugins manager, check network status.<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net.NetworkInformation;
using NuGet;
using NuGetPackageExplorer.Types;

namespace PackageExplorerViewModel
{
    public class PluginManagerViewModel : INotifyPropertyChanged, IComparer<PluginInfo>
    {
        private readonly IPackageChooser _packageChooser;
        private readonly IPackageDownloader _packageDownloader;
        private readonly IPluginManager _pluginManager;
        private readonly IUIServices _uiServices;
        private SortedCollection<PluginInfo> _plugins;

        public PluginManagerViewModel(
            IPluginManager pluginManager,
            IUIServices uiServices,
            IPackageChooser packageChooser,
            IPackageDownloader packageDownloader)
        {
            if (pluginManager == null)
            {
                throw new ArgumentNullException("pluginManager");
            }

            if (packageChooser == null)
            {
                throw new ArgumentNullException("packageChooser");
            }

            if (uiServices == null)
            {
                throw new ArgumentNullException("uiServices");
            }

            if (packageDownloader == null)
            {
                throw new ArgumentNullException("packageDownloader");
            }

            _pluginManager = pluginManager;
            _uiServices = uiServices;
            _packageChooser = packageChooser;
            _packageDownloader = packageDownloader;

            DeleteCommand = new RelayCommand<PluginInfo>(DeleteCommandExecute, DeleteCommandCanExecute);
            AddCommand = new RelayCommand<string>(AddCommandExecute);
        }

        public ICollection<PluginInfo> Plugins
        {
            get
            {
                if (_plugins == null)
                {
                    _plugins = new SortedCollection<PluginInfo>(_pluginManager.Plugins, this);
                }
                return _plugins;
            }
        }

        public RelayCommand<PluginInfo> DeleteCommand { get; private set; }

        public RelayCommand<string> AddCommand { get; private set; }

        #region IComparer<PluginInfo> Members

        public int Compare(PluginInfo x, PluginInfo y)
        {
            int result = String.Compare(x.Id, y.Id, StringComparison.CurrentCultureIgnoreCase);
            if (result != 0)
            {
                return result;
            }

            return x.Version.CompareTo(y.Version);
        }

        #endregion

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        #endregion

        private void AddCommandExecute(string parameter)
        {
            if (parameter == "Local")
            {
                AddLocalPlugin();
            }
            else if (parameter == "Remote")
            {
                AddFeedPlugin();
            }
        }

        private void AddFeedPlugin()
        {
            if (!NetworkInterface.GetIsNetworkAvailable())
            {
                _uiServices.Show(Resources.NoNetworkConnection, MessageLevel.Warning);
                return;
            }

            PackageInfo selectedPackageInfo = _packageChooser.SelectPluginPackage();
            if (selectedPackageInfo != null)
{'fraction_non_alphanumeric': 0.06597906870923707, 'fraction_numerical': 0.0003033520400424693, 'mean_word_length': 1.8300429184549356, 'pattern_counts': {'":': 0, '<': 21, '<?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': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6070685', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1463, 'n_words': 342}