<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using GoCommando;
using GoCommando.Api;
using GoCommando.Attributes;
using NuGetPackageVisualizer.NuGetService;

namespace NuGetPackageVisualizer
{
    public class Program : ICommando
    {
        [NamedArgument("folder", "l")]
        [Description("Path for a folder containing packages.config file(s).")]
        [Example("-folder:\"c:\\my projects\\proj\"")]
        public string Folder { get; set; }

        [NamedArgument("recursive", "r", Default = "true")]
        [Description("If set together with folder, a recursive search for packages.config files are made from the specified folder. Default: true.")]
        [Example("-recursive:false")]
        public bool Recursive { get; set; }

        [NamedArgument("file", "f")]
        [Description("Path to a packages.config file.")]
        [Example("-file:\"c:\\my projects\\proj\\packages.config\"")]
        public string File { get; set; }

        [NamedArgument("outputtype", "ot", Default = "dgml")]
        [Description("Sets the type of the output file. The following file types are supported: dgml, graphviz.")]
        [Example("-outputtype:dgml")]
        public string OutputType { get; set; }

        [NamedArgument("output", "o")]
        [Description("Path to the generated DGML file. Default: \"packages.dgml\" or \"packages.dot\".")]
        [Example("-output:.\\packages.dgml")]
        public string Output { get; set; }

        public static void Main(string[] args)
        {
            Console.WriteLine("============================");
            Console.WriteLine("= NuGet Package Visualizer =");
            Console.WriteLine("============================");
            Go.Run<Program>(args);
        }

        public void Run()
        {
            if (!Valid())
            {
                Console.WriteLine("Invoke with -? for detailed help.");
                return;
            }

            var packageFiles = GetFiles();
            var packages = GeneratePackages(packageFiles);
            GenerateFile(packages);
        }

        private IEnumerable<string> GetFiles()
        {
            var packageFiles = new List<string>();
            if (!string.IsNullOrWhiteSpace(File))
                packageFiles.Add(File);
            else
                packageFiles.AddRange(DirSearch(Folder));

            return packageFiles;
        }

        private List<PackageViewModel> GeneratePackages(IEnumerable<string> packageFiles)
        {
            var packages = new List<PackageViewModel>();
            var feedContext = new FeedContext_x0060_1(new Uri("http://nuget.org/api/v2/"))
                {
                    IgnoreMissingProperties = true
                };
            foreach (var file in packageFiles)
            {
                var packagesConfig = XDocument.Load(file);

                foreach (var package in packagesConfig.Descendants("package"))
                {
                    var id = package.Attribute("id").Value;
                    var version = package.Attribute("version").Value;
                    var remotePackage = feedContext.Packages.Where(x => x.Id == id && x.IsLatestVersion).FirstOrDefault();
                    if (remotePackage == null) continue;
                    if (packages.Any(p => p.NugetId == id && p.LocalVersion == version)) continue;
                    packages.Add(new PackageViewModel
                    {
                        RemoteVersion = remotePackage.Version,
                        LocalVersion = version,
                        NugetId = id,
                        Id = Guid.NewGuid().ToString(),<commit_msg>No longer look at pre releases when determining if running on the most recent version of a nuget package<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using GoCommando;
using GoCommando.Api;
using GoCommando.Attributes;
using NuGetPackageVisualizer.NuGetService;

namespace NuGetPackageVisualizer
{
    public class Program : ICommando
    {
        [NamedArgument("folder", "l")]
        [Description("Path for a folder containing packages.config file(s).")]
        [Example("-folder:\"c:\\my projects\\proj\"")]
        public string Folder { get; set; }

        [NamedArgument("recursive", "r", Default = "true")]
        [Description("If set together with folder, a recursive search for packages.config files are made from the specified folder. Default: true.")]
        [Example("-recursive:false")]
        public bool Recursive { get; set; }

        [NamedArgument("file", "f")]
        [Description("Path to a packages.config file.")]
        [Example("-file:\"c:\\my projects\\proj\\packages.config\"")]
        public string File { get; set; }

        [NamedArgument("outputtype", "ot", Default = "dgml")]
        [Description("Sets the type of the output file. The following file types are supported: dgml, graphviz.")]
        [Example("-outputtype:dgml")]
        public string OutputType { get; set; }

        [NamedArgument("output", "o")]
        [Description("Path to the generated DGML file. Default: \"packages.dgml\" or \"packages.dot\".")]
        [Example("-output:.\\packages.dgml")]
        public string Output { get; set; }

        public static void Main(string[] args)
        {
            Console.WriteLine("============================");
            Console.WriteLine("= NuGet Package Visualizer =");
            Console.WriteLine("============================");
            Go.Run<Program>(args);
        }

        public void Run()
        {
            if (!Valid())
            {
                Console.WriteLine("Invoke with -? for detailed help.");
                return;
            }

            var packageFiles = GetFiles();
            var packages = GeneratePackages(packageFiles);
            GenerateFile(packages);
        }

        private IEnumerable<string> GetFiles()
        {
            var packageFiles = new List<string>();
            if (!string.IsNullOrWhiteSpace(File))
                packageFiles.Add(File);
            else
                packageFiles.AddRange(DirSearch(Folder));

            return packageFiles;
        }

        private List<PackageViewModel> GeneratePackages(IEnumerable<string> packageFiles)
        {
            var packages = new List<PackageViewModel>();
            var feedContext = new FeedContext_x0060_1(new Uri("http://nuget.org/api/v2/"))
                {
                    IgnoreMissingProperties = true
                };
            foreach (var file in packageFiles)
            {
                var packagesConfig = XDocument.Load(file);

                foreach (var package in packagesConfig.Descendants("package"))
                {
                    var id = package.Attribute("id").Value;
                    var version = package.Attribute("version").Value;
                    var remotePackage = feedContext.Packages.Where(x => x.Id == id && x.IsLatestVersion && !x.IsPrerelease).FirstOrDefault();
                    if (remotePackage == null) continue;
                    if (packages.Any(p => p.NugetId == id && p.LocalVersion == version)) continue;
                    packages.Add(new PackageViewModel
                    {
                        RemoteVersion = remotePackage.Version,
                        LocalVersion = version,
                        NugetId = id,
                        Id = Guid.NewGuid().ToString(),
{'fraction_non_alphanumeric': 0.1297568710359408, 'fraction_numerical': 0.0015856236786469344, 'mean_word_length': 1.998811410459588, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, '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': '1482065', 'n_tokens_mistral': 1904, 'n_tokens_neox': 1810, 'n_words': 480}