using Oqtane.Models; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using Oqtane.Documentation; using Oqtane.Shared; using System.Net; namespace Oqtane.Services { /// /// Service to manage packages () /// public interface IPackageService { /// /// Returns a list of packages matching the given parameters /// /// /// Task> GetPackagesAsync(string type); /// /// Returns a list of packages matching the given parameters /// /// /// /// /// /// Task> GetPackagesAsync(string type, string search, string price, string package); /// /// Returns a list of packages matching the given parameters /// /// /// /// /// /// /// Task> GetPackagesAsync(string type, string search, string price, string package, string sort); /// /// Returns a list of packages based on installationid /// /// Task> GetPackageUpdatesAsync(string type); /// /// Returns a specific package /// /// /// /// Task GetPackageAsync(string packageId, string version, bool download); /// /// Downloads a specific package as .nupkg file /// /// /// /// /// Task DownloadPackageAsync(string packageId, string version); /// /// Installs all packages located in //TODO: 2dm where? /// /// Task InstallPackagesAsync(); } [PrivateApi("Don't show in the documentation, as everything should use the Interface")] public class PackageService : ServiceBase, IPackageService { public PackageService(HttpClient http, SiteState siteState) : base(http, siteState) { } private string Apiurl => CreateApiUrl("Package"); public async Task> GetPackagesAsync(string type) { return await GetPackagesAsync(type, "", "", ""); } public async Task> GetPackagesAsync(string type, string search, string price, string package) { return await GetPackagesAsync(type, search, price, package, ""); } public async Task> GetPackagesAsync(string type, string search, string price, string package, string sort) { return await GetJsonAsync>($"{Apiurl}?type={type}&search={WebUtility.UrlEncode(search)}&price={price}&package={package}&sort={sort}"); } public async Task> GetPackageUpdatesAsync(string type) { return await GetJsonAsync>($"{Apiurl}/updates/?type={type}"); } public async Task GetPackageAsync(string packageId, string version, bool download) { return await PostJsonAsync($"{Apiurl}?packageid={packageId}&version={version}&download={download}&install=false", null); } public async Task DownloadPackageAsync(string packageId, string version) { await PostAsync($"{Apiurl}?packageid={packageId}&version={version}&download=true&install=true"); } public async Task InstallPackagesAsync() { await GetJsonAsync>($"{Apiurl}/install"); } } }