support for commercial modules, themes, translations

This commit is contained in:
Shaun Walker 2021-08-16 09:46:02 -04:00
parent ffe724b32d
commit ffcc229c78
14 changed files with 57 additions and 51 deletions

View File

@ -77,7 +77,11 @@ else
<td>
<h3 style="display: inline;"><a href="@context.ProductUrl" target="_new">@context.Name</a></h3>&nbsp;&nbsp;by:&nbsp;&nbsp;<strong><a href="@context.OwnerUrl" target="new">@context.Owner</a></strong><br />
@(context.Description.Length > 400 ? (context.Description.Substring(0, 400) + "...") : context.Description)<br />
<strong>@(String.Format("{0:n0}", context.Downloads))</strong> @SharedLocalizer["Search.Downloads"]&nbsp;&nbsp;|&nbsp;&nbsp; @SharedLocalizer["Search.Released"]: <strong>@context.ReleaseDate.ToString("MMM dd, yyyy")</strong>&nbsp;&nbsp;|&nbsp;&nbsp;@SharedLocalizer["Search.Version"]: <strong>@context.Version</strong>&nbsp;&nbsp;|&nbsp;&nbsp;@SharedLocalizer["Search.Source"]: <strong>@context.PackageUrl</strong>
<strong>@(String.Format("{0:n0}", context.Downloads))</strong> @SharedLocalizer["Search.Downloads"]&nbsp;&nbsp;|&nbsp;&nbsp;
@SharedLocalizer["Search.Released"]: <strong>@context.ReleaseDate.ToString("MMM dd, yyyy")</strong>&nbsp;&nbsp;|&nbsp;&nbsp;
@SharedLocalizer["Search.Version"]: <strong>@context.Version</strong>&nbsp;&nbsp;|&nbsp;&nbsp;
@SharedLocalizer["Search.Source"]: <strong>@context.PackageUrl</strong>&nbsp;&nbsp;|&nbsp;&nbsp;
@SharedLocalizer["Search.Price"]: <strong>@((context.Price == 0) ? "FREE" : context.Price.ToString("$#,##0.00") )</strong>
</td>
<td style="vertical-align: middle;">
<button type="button" class="btn btn-primary" @onclick=@(async () => await GetLanguage(context.PackageId, context.Version))>@SharedLocalizer["Download"]</button>
@ -184,7 +188,7 @@ else
private async Task LoadTranslations()
{
_packages = await PackageService.GetPackagesAsync("translation", _search, _price);
_packages = await PackageService.GetPackagesAsync("translation", _search, _price, "");
}
private async void PriceChanged(ChangeEventArgs e)

View File

@ -129,7 +129,7 @@
private async Task LoadModuleDefinitions()
{
var moduledefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync(PageState.Site.SiteId);
_packages = await PackageService.GetPackagesAsync("module", _search, _price);
_packages = await PackageService.GetPackagesAsync("module", _search, _price, "");
if (_packages != null)
{

View File

@ -70,7 +70,7 @@ else
private bool UpgradeAvailable(string packagename, string version)
{
var upgradeavailable = false;
if (_packages != null)
if (!string.IsNullOrEmpty(packagename) && _packages != null)
{
var package = _packages.Where(item => item.PackageId == packagename).FirstOrDefault();
if (package != null)

View File

@ -34,7 +34,11 @@
<td>
<h3 style="display: inline;"><a href="@context.ProductUrl" target="_new">@context.Name</a></h3>&nbsp;&nbsp;@SharedLocalizer["Search.By"]:&nbsp;&nbsp;<strong><a href="@context.OwnerUrl" target="new">@context.Owner</a></strong><br />
@(context.Description.Length > 400 ? (context.Description.Substring(0, 400) + "...") : context.Description)<br />
<strong>@(String.Format("{0:n0}", context.Downloads))</strong> @SharedLocalizer["Search.Downloads"]&nbsp;&nbsp;|&nbsp;&nbsp; @SharedLocalizer["Search.Released"]: <strong>@context.ReleaseDate.ToString("MMM dd, yyyy")</strong>&nbsp;&nbsp;|&nbsp;&nbsp;@SharedLocalizer["Search.Version"]: <strong>@context.Version</strong>&nbsp;&nbsp;|&nbsp;&nbsp;@SharedLocalizer["Search.Source"]: <strong>@context.PackageUrl</strong>
<strong>@(String.Format("{0:n0}", context.Downloads))</strong> @SharedLocalizer["Search.Downloads"]&nbsp;&nbsp;|&nbsp;&nbsp;
@SharedLocalizer["Search.Released"]: <strong>@context.ReleaseDate.ToString("MMM dd, yyyy")</strong>&nbsp;&nbsp;|&nbsp;&nbsp;
@SharedLocalizer["Search.Version"]: <strong>@context.Version</strong>&nbsp;&nbsp;|&nbsp;&nbsp;
@SharedLocalizer["Search.Source"]: <strong>@context.PackageUrl</strong>&nbsp;&nbsp;|&nbsp;&nbsp;
@SharedLocalizer["Search.Price"]: <strong>@((context.Price == 0) ? "FREE" : context.Price.ToString("$#,##0.00") )</strong>
</td>
<td style="vertical-align: middle;">
<button type="button" class="btn btn-primary" @onclick=@(async () => await GetPackage(context.PackageId, context.Version))>@SharedLocalizer["Download"]</button>
@ -126,7 +130,7 @@
private async Task LoadThemes()
{
var themes = await ThemeService.GetThemesAsync();
_packages = await PackageService.GetPackagesAsync("theme", _search, _price);
_packages = await PackageService.GetPackagesAsync("theme", _search, _price, "");
if (_packages != null)
{

View File

@ -72,7 +72,7 @@ else
private bool UpgradeAvailable(string packagename, string version)
{
var upgradeavailable = false;
if (_packages != null)
if (!string.IsNullOrEmpty(packagename) && _packages != null)
{
var package = _packages.Where(item => item.PackageId == packagename).FirstOrDefault();
if (package != null)

View File

@ -44,7 +44,7 @@
{
try
{
List<Package> packages = await PackageService.GetPackagesAsync("framework");
List<Package> packages = await PackageService.GetPackagesAsync("framework", "", "", "");
if (packages != null)
{
_package = packages.Where(item => item.PackageId.StartsWith(Constants.PackageId)).FirstOrDefault();

View File

@ -7,7 +7,7 @@ namespace Oqtane.Services
public interface IPackageService
{
Task<List<Package>> GetPackagesAsync(string type);
Task<List<Package>> GetPackagesAsync(string type, string search, string price);
Task<List<Package>> GetPackagesAsync(string type, string search, string price, string package);
Task<Package> GetPackageAsync(string packageId, string version);
Task DownloadPackageAsync(string packageId, string version, string folder);
Task InstallPackagesAsync();

View File

@ -22,12 +22,12 @@ namespace Oqtane.Services
public async Task<List<Package>> GetPackagesAsync(string type)
{
return await GetPackagesAsync(type, "", "");
return await GetPackagesAsync(type, "", "", "");
}
public async Task<List<Package>> GetPackagesAsync(string type, string search, string price)
public async Task<List<Package>> GetPackagesAsync(string type, string search, string price, string package)
{
return await GetJsonAsync<List<Package>>($"{Apiurl}?type={type}&search={WebUtility.UrlEncode(search)}&price={price}");
return await GetJsonAsync<List<Package>>($"{Apiurl}?type={type}&search={WebUtility.UrlEncode(search)}&price={price}&package={package}");
}
public async Task<Package> GetPackageAsync(string packageId, string version)

View File

@ -32,10 +32,10 @@ namespace Oqtane.Controllers
_logger = logger;
}
// GET: api/<controller>?type=x&search=y&license=z
// GET: api/<controller>?type=x&search=y&price=z&package=a
[HttpGet]
[Authorize(Roles = RoleNames.Host)]
public async Task<IEnumerable<Package>> Get(string type, string search, string price)
public async Task<IEnumerable<Package>> Get(string type, string search, string price, string package)
{
// get packages
List<Package> packages = new List<Package>();
@ -45,7 +45,7 @@ namespace Oqtane.Controllers
{
client.DefaultRequestHeaders.Add("Referer", HttpContext.Request.Scheme + "://" + HttpContext.Request.Host.Value);
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(Constants.PackageId, Constants.Version));
packages = await GetJson<List<Package>>(client, Constants.PackageRegistryUrl + $"/api/registry/packages/?id={_configManager.GetInstallationId()}&type={type.ToLower()}&version={Constants.Version}&search={search}&price={price}");
packages = await GetJson<List<Package>>(client, Constants.PackageRegistryUrl + $"/api/registry/packages/?id={_configManager.GetInstallationId()}&type={type.ToLower()}&version={Constants.Version}&search={search}&price={price}&package={package}");
}
}
return packages;

View File

@ -186,41 +186,45 @@ namespace Oqtane.Infrastructure
public bool UninstallPackage(string PackageName)
{
// get manifest with highest version
string packagename = "";
string[] packages = Directory.GetFiles(Path.Combine(_environment.ContentRootPath, "Packages"), PackageName + "*.log");
if (packages.Length > 0)
if (!string.IsNullOrEmpty(PackageName))
{
packagename = packages[packages.Length - 1]; // use highest version
}
if (!string.IsNullOrEmpty(packagename))
{
// use manifest to clean up file resources
List<string> assets = JsonSerializer.Deserialize<List<string>>(File.ReadAllText(packagename));
assets.Reverse();
foreach (string asset in assets)
// get manifest with highest version
string packagename = "";
string[] packages = Directory.GetFiles(Path.Combine(_environment.ContentRootPath, "Packages"), PackageName + "*.log");
if (packages.Length > 0)
{
// legacy support for assets that were stored as absolute paths
string filepath = asset.StartsWith("\\") ? Path.Combine(_environment.ContentRootPath, asset.Substring(1)) : asset;
if (File.Exists(filepath))
packagename = packages[packages.Length - 1]; // use highest version
}
if (!string.IsNullOrEmpty(packagename))
{
// use manifest to clean up file resources
List<string> assets = JsonSerializer.Deserialize<List<string>>(File.ReadAllText(packagename));
assets.Reverse();
foreach (string asset in assets)
{
File.Delete(filepath);
if (!Directory.EnumerateFiles(Path.GetDirectoryName(filepath)).Any())
// legacy support for assets that were stored as absolute paths
string filepath = asset.StartsWith("\\") ? Path.Combine(_environment.ContentRootPath, asset.Substring(1)) : asset;
if (File.Exists(filepath))
{
Directory.Delete(Path.GetDirectoryName(filepath));
File.Delete(filepath);
if (!Directory.EnumerateFiles(Path.GetDirectoryName(filepath)).Any())
{
Directory.Delete(Path.GetDirectoryName(filepath));
}
}
}
}
// clean up package asset manifests
foreach(string asset in packages)
{
File.Delete(asset);
}
// clean up package asset manifests
foreach (string asset in packages)
{
File.Delete(asset);
}
return true;
return true;
}
}
return false;
}

View File

@ -241,10 +241,6 @@ namespace Oqtane.Repository
moduledefinition.ModuleDefinitionName = qualifiedModuleType;
moduledefinition.ControlTypeTemplate = modulecontroltype.Namespace + "." + Constants.ActionToken + ", " + modulecontroltype.Assembly.GetName().Name;
moduledefinition.AssemblyName = assembly.GetName().Name;
if (string.IsNullOrEmpty(moduledefinition.PackageName))
{
moduledefinition.PackageName = Utilities.GetTypeName(moduledefinition.ModuleDefinitionName);
}
if (string.IsNullOrEmpty(moduledefinition.Categories))
{

View File

@ -101,10 +101,6 @@ namespace Oqtane.Repository
theme.Themes = new List<ThemeControl>();
theme.Containers = new List<ThemeControl>();
theme.AssemblyName = assembly.FullName.Split(",")[0];
if (string.IsNullOrEmpty(theme.PackageName))
{
theme.PackageName = Utilities.GetTypeName(theme.ThemeName);
}
Debug.WriteLine($"Oqtane Info: Registering Theme {theme.ThemeName}");
themes.Add(theme);

View File

@ -12,7 +12,8 @@ namespace [Owner].[Module]
Version = "1.0.0",
ServerManagerType = "[ServerManagerType]",
ReleaseVersions = "1.0.0",
Dependencies = "[Owner].[Module].Shared.Oqtane"
Dependencies = "[Owner].[Module].Shared.Oqtane",
PackageName = "[Owner].[Module]"
};
}
}

View File

@ -8,7 +8,8 @@ namespace [Owner].[Theme]
public Theme Theme => new Theme
{
Name = "[Theme]",
Version = "1.0.0"
Version = "1.0.0",
PackageName = "[Owner].[Theme]"
};
}