using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Threading.Tasks; using Avalonia.Controls; namespace CrossLangDevStudio.Models; public interface IPackageManager { Task InstallPackageAsync(string name, CrossLangVersion version); string Filter { get; } void UninstallPackage(string name); IEnumerable GetInstalledPackages(); } public static class PackageManagerExtensions { public static string Summarize(this string txt) { var lines = txt.Replace("\r", "").Split('\n'); bool needsthreedots = false; if (lines.Length > 1) needsthreedots = true; if (lines.Length == 0) return ""; if (lines[0].Length > 120) { needsthreedots = true; lines[0] = lines[0].Substring(0, 120); } if (needsthreedots) return $"{lines[0]}..."; return lines[0]; } public static bool IsPackageInstalled(this IPackageManager pm, string name) { foreach (var item in pm.GetInstalledPackages()) { if (item.Name == name) return true; } return false; } public static async Task InstallPackageAsync(this IPackageManager pm, CrossLangDependency dep) { await pm.InstallPackageAsync(dep.Name, dep.Version); } }