Implement plugin update identification by guid

This commit is contained in:
Eric Reed 2013-11-04 13:16:47 -05:00
parent 4bbe8acb5c
commit 764e2625bf
8 changed files with 70 additions and 22 deletions

View File

@ -15,7 +15,7 @@ namespace MediaBrowser.Api
/// Class GetPackage /// Class GetPackage
/// </summary> /// </summary>
[Route("/Packages/{Name}", "GET")] [Route("/Packages/{Name}", "GET")]
[Api(("Gets a package, by name"))] [Api(("Gets a package, by name or assembly guid"))]
public class GetPackage : IReturn<PackageInfo> public class GetPackage : IReturn<PackageInfo>
{ {
/// <summary> /// <summary>
@ -24,6 +24,13 @@ namespace MediaBrowser.Api
/// <value>The name.</value> /// <value>The name.</value>
[ApiMember(Name = "Name", Description = "The name of the package", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] [ApiMember(Name = "Name", Description = "The name of the package", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Name { get; set; } public string Name { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[ApiMember(Name = "AssemblyGuid", Description = "The guid of the associated assembly", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string AssemblyGuid { get; set; }
} }
/// <summary> /// <summary>
@ -76,6 +83,13 @@ namespace MediaBrowser.Api
[ApiMember(Name = "Name", Description = "Package name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")] [ApiMember(Name = "Name", Description = "Package name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string Name { get; set; } public string Name { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[ApiMember(Name = "AssemblyGuid", Description = "Guid of the associated assembly", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
public string AssemblyGuid { get; set; }
/// <summary> /// <summary>
/// Gets or sets the version. /// Gets or sets the version.
/// </summary> /// </summary>
@ -157,7 +171,8 @@ namespace MediaBrowser.Api
{ {
var packages = _installationManager.GetAvailablePackages(CancellationToken.None, applicationVersion: _appHost.ApplicationVersion).Result; var packages = _installationManager.GetAvailablePackages(CancellationToken.None, applicationVersion: _appHost.ApplicationVersion).Result;
var result = packages.FirstOrDefault(p => p.name.Equals(request.Name, StringComparison.OrdinalIgnoreCase)); var result = packages.FirstOrDefault(p => string.Equals(p.guid, request.AssemblyGuid ?? "none", StringComparison.OrdinalIgnoreCase))
?? packages.FirstOrDefault(p => p.name.Equals(request.Name, StringComparison.OrdinalIgnoreCase));
return ToOptimizedResult(result); return ToOptimizedResult(result);
} }
@ -194,8 +209,8 @@ namespace MediaBrowser.Api
public void Post(InstallPackage request) public void Post(InstallPackage request)
{ {
var package = string.IsNullOrEmpty(request.Version) ? var package = string.IsNullOrEmpty(request.Version) ?
_installationManager.GetLatestCompatibleVersion(request.Name, _appHost.ApplicationVersion, request.UpdateClass).Result : _installationManager.GetLatestCompatibleVersion(request.Name, request.AssemblyGuid, _appHost.ApplicationVersion, request.UpdateClass).Result :
_installationManager.GetPackage(request.Name, request.UpdateClass, Version.Parse(request.Version)).Result; _installationManager.GetPackage(request.Name, request.AssemblyGuid, request.UpdateClass, Version.Parse(request.Version)).Result;
if (package == null) if (package == null)
{ {

View File

@ -255,14 +255,16 @@ namespace MediaBrowser.Common.Implementations.Updates
/// Gets the package. /// Gets the package.
/// </summary> /// </summary>
/// <param name="name">The name.</param> /// <param name="name">The name.</param>
/// <param name="guid">The assembly guid</param>
/// <param name="classification">The classification.</param> /// <param name="classification">The classification.</param>
/// <param name="version">The version.</param> /// <param name="version">The version.</param>
/// <returns>Task{PackageVersionInfo}.</returns> /// <returns>Task{PackageVersionInfo}.</returns>
public async Task<PackageVersionInfo> GetPackage(string name, PackageVersionClass classification, Version version) public async Task<PackageVersionInfo> GetPackage(string name, string guid, PackageVersionClass classification, Version version)
{ {
var packages = await GetAvailablePackages(CancellationToken.None).ConfigureAwait(false); var packages = await GetAvailablePackages(CancellationToken.None).ConfigureAwait(false);
var package = packages.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase)); var package = packages.FirstOrDefault(p => string.Equals(p.guid, guid ?? "none", StringComparison.OrdinalIgnoreCase))
?? packages.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase));
if (package == null) if (package == null)
{ {
@ -276,14 +278,15 @@ namespace MediaBrowser.Common.Implementations.Updates
/// Gets the latest compatible version. /// Gets the latest compatible version.
/// </summary> /// </summary>
/// <param name="name">The name.</param> /// <param name="name">The name.</param>
/// <param name="guid">The assembly guid if this is a plug-in</param>
/// <param name="currentServerVersion">The current server version.</param> /// <param name="currentServerVersion">The current server version.</param>
/// <param name="classification">The classification.</param> /// <param name="classification">The classification.</param>
/// <returns>Task{PackageVersionInfo}.</returns> /// <returns>Task{PackageVersionInfo}.</returns>
public async Task<PackageVersionInfo> GetLatestCompatibleVersion(string name, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release) public async Task<PackageVersionInfo> GetLatestCompatibleVersion(string name, string guid, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release)
{ {
var packages = await GetAvailablePackages(CancellationToken.None).ConfigureAwait(false); var packages = await GetAvailablePackages(CancellationToken.None).ConfigureAwait(false);
return GetLatestCompatibleVersion(packages, name, currentServerVersion, classification); return GetLatestCompatibleVersion(packages, name, guid, currentServerVersion, classification);
} }
/// <summary> /// <summary>
@ -294,9 +297,10 @@ namespace MediaBrowser.Common.Implementations.Updates
/// <param name="currentServerVersion">The current server version.</param> /// <param name="currentServerVersion">The current server version.</param>
/// <param name="classification">The classification.</param> /// <param name="classification">The classification.</param>
/// <returns>PackageVersionInfo.</returns> /// <returns>PackageVersionInfo.</returns>
public PackageVersionInfo GetLatestCompatibleVersion(IEnumerable<PackageInfo> availablePackages, string name, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release) public PackageVersionInfo GetLatestCompatibleVersion(IEnumerable<PackageInfo> availablePackages, string name, string guid, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release)
{ {
var package = availablePackages.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase)); var package = availablePackages.FirstOrDefault(p => string.Equals(p.guid, guid ?? "none", StringComparison.OrdinalIgnoreCase))
?? availablePackages.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase));
if (package == null) if (package == null)
{ {
@ -331,14 +335,14 @@ namespace MediaBrowser.Common.Implementations.Updates
// Figure out what needs to be installed // Figure out what needs to be installed
var packages = plugins.Select(p => var packages = plugins.Select(p =>
{ {
var latestPluginInfo = GetLatestCompatibleVersion(catalog, p.Name, applicationVersion, p.Configuration.UpdateClass); var latestPluginInfo = GetLatestCompatibleVersion(catalog, p.Name, p.Id.ToString(), applicationVersion, p.Configuration.UpdateClass);
return latestPluginInfo != null && latestPluginInfo.version != null && latestPluginInfo.version > p.Version ? latestPluginInfo : null; return latestPluginInfo != null && latestPluginInfo.version != null && latestPluginInfo.version > p.Version ? latestPluginInfo : null;
}).Where(i => i != null).ToList(); }).Where(i => i != null).ToList();
return packages return packages
.Where(p => !string.IsNullOrWhiteSpace(p.sourceUrl) && !CompletedInstallations.Any(i => string.Equals(i.Name, p.name, StringComparison.OrdinalIgnoreCase))); .Where(p => !string.IsNullOrWhiteSpace(p.sourceUrl) && !CompletedInstallations.Any(i => string.Equals(i.AssemblyGuid, p.guid, StringComparison.OrdinalIgnoreCase)));
} }
/// <summary> /// <summary>
@ -365,6 +369,7 @@ namespace MediaBrowser.Common.Implementations.Updates
{ {
Id = Guid.NewGuid(), Id = Guid.NewGuid(),
Name = package.name, Name = package.name,
AssemblyGuid = package.guid,
UpdateClass = package.classification, UpdateClass = package.classification,
Version = package.versionStr Version = package.versionStr
}; };
@ -471,7 +476,8 @@ namespace MediaBrowser.Common.Implementations.Updates
if (!string.Equals(extension, ".zip", StringComparison.OrdinalIgnoreCase) && !string.Equals(extension, ".rar", StringComparison.OrdinalIgnoreCase) && !string.Equals(extension, ".7z", StringComparison.OrdinalIgnoreCase)) if (!string.Equals(extension, ".zip", StringComparison.OrdinalIgnoreCase) && !string.Equals(extension, ".rar", StringComparison.OrdinalIgnoreCase) && !string.Equals(extension, ".7z", StringComparison.OrdinalIgnoreCase))
{ {
// Set last update time if we were installed before // Set last update time if we were installed before
var plugin = _applicationHost.Plugins.FirstOrDefault(p => p.Name.Equals(package.name, StringComparison.OrdinalIgnoreCase)); var plugin = _applicationHost.Plugins.FirstOrDefault(p => string.Equals(p.Id.ToString(), package.guid, StringComparison.OrdinalIgnoreCase))
?? _applicationHost.Plugins.FirstOrDefault(p => p.Name.Equals(package.name, StringComparison.OrdinalIgnoreCase));
if (plugin != null) if (plugin != null)
{ {

View File

@ -63,29 +63,32 @@ namespace MediaBrowser.Common.Updates
/// Gets the package. /// Gets the package.
/// </summary> /// </summary>
/// <param name="name">The name.</param> /// <param name="name">The name.</param>
/// <param name="guid">The assembly guid</param>
/// <param name="classification">The classification.</param> /// <param name="classification">The classification.</param>
/// <param name="version">The version.</param> /// <param name="version">The version.</param>
/// <returns>Task{PackageVersionInfo}.</returns> /// <returns>Task{PackageVersionInfo}.</returns>
Task<PackageVersionInfo> GetPackage(string name, PackageVersionClass classification, Version version); Task<PackageVersionInfo> GetPackage(string name, string guid, PackageVersionClass classification, Version version);
/// <summary> /// <summary>
/// Gets the latest compatible version. /// Gets the latest compatible version.
/// </summary> /// </summary>
/// <param name="name">The name.</param> /// <param name="name">The name.</param>
/// <param name="guid">The assembly guid</param>
/// <param name="currentServerVersion">The current server version.</param> /// <param name="currentServerVersion">The current server version.</param>
/// <param name="classification">The classification.</param> /// <param name="classification">The classification.</param>
/// <returns>Task{PackageVersionInfo}.</returns> /// <returns>Task{PackageVersionInfo}.</returns>
Task<PackageVersionInfo> GetLatestCompatibleVersion(string name, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release); Task<PackageVersionInfo> GetLatestCompatibleVersion(string name, string guid, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release);
/// <summary> /// <summary>
/// Gets the latest compatible version. /// Gets the latest compatible version.
/// </summary> /// </summary>
/// <param name="availablePackages">The available packages.</param> /// <param name="availablePackages">The available packages.</param>
/// <param name="name">The name.</param> /// <param name="name">The name.</param>
/// <param name="guid">The assembly guid</param>
/// <param name="currentServerVersion">The current server version.</param> /// <param name="currentServerVersion">The current server version.</param>
/// <param name="classification">The classification.</param> /// <param name="classification">The classification.</param>
/// <returns>PackageVersionInfo.</returns> /// <returns>PackageVersionInfo.</returns>
PackageVersionInfo GetLatestCompatibleVersion(IEnumerable<PackageInfo> availablePackages, string name, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release); PackageVersionInfo GetLatestCompatibleVersion(IEnumerable<PackageInfo> availablePackages, string name, string guid, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release);
/// <summary> /// <summary>
/// Gets the available plugin updates. /// Gets the available plugin updates.

View File

@ -19,6 +19,12 @@ namespace MediaBrowser.Model.Updates
/// <value>The name.</value> /// <value>The name.</value>
public string Name { get; set; } public string Name { get; set; }
/// <summary>
/// Gets or sets the assembly guid.
/// </summary>
/// <value>The guid of the assembly.</value>
public string AssemblyGuid { get; set; }
/// <summary> /// <summary>
/// Gets or sets the version. /// Gets or sets the version.
/// </summary> /// </summary>

View File

@ -104,6 +104,13 @@ namespace MediaBrowser.Model.Updates
/// <value>The target system.</value> /// <value>The target system.</value>
public PackageTargetSystem targetSystem { get; set; } public PackageTargetSystem targetSystem { get; set; }
/// <summary>
/// The guid of the assembly associated with this package (if a plug-in).
/// This is used to identify the proper item for automatic updates.
/// </summary>
/// <value>The name.</value>
public string guid { get; set; }
/// <summary> /// <summary>
/// Gets or sets whether or not this package is registered. /// Gets or sets whether or not this package is registered.
/// </summary> /// </summary>

View File

@ -15,6 +15,12 @@ namespace MediaBrowser.Model.Updates
/// <value>The name.</value> /// <value>The name.</value>
public string name { get; set; } public string name { get; set; }
/// <summary>
/// Gets or sets the guid.
/// </summary>
/// <value>The guid.</value>
public string guid { get; set; }
/// <summary> /// <summary>
/// Gets or sets the version STR. /// Gets or sets the version STR.
/// </summary> /// </summary>

View File

@ -683,7 +683,7 @@ namespace MediaBrowser.ServerApplication
{ {
var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false); var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, Constants.MbServerPkgName, ApplicationVersion, var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, Constants.MbServerPkgName, null, ApplicationVersion,
ConfigurationManager.CommonConfiguration.SystemUpdateLevel); ConfigurationManager.CommonConfiguration.SystemUpdateLevel);
return version != null ? new CheckForUpdateResult { AvailableVersion = version.version, IsUpdateAvailable = version.version > ApplicationVersion, Package = version } : return version != null ? new CheckForUpdateResult { AvailableVersion = version.version, IsUpdateAvailable = version.version > ApplicationVersion, Package = version } :

View File

@ -730,7 +730,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
/** /**
* Installs or updates a new plugin * Installs or updates a new plugin
*/ */
self.installPlugin = function (name, updateClass, version) { self.installPlugin = function (name, guid, updateClass, version) {
if (!name) { if (!name) {
throw new Error("null name"); throw new Error("null name");
@ -741,7 +741,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
} }
var options = { var options = {
updateClass: updateClass updateClass: updateClass,
AssemblyGuid: guid
}; };
if (version) { if (version) {
@ -785,13 +786,17 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
/** /**
* Gets information about an installable package * Gets information about an installable package
*/ */
self.getPackageInfo = function (name) { self.getPackageInfo = function (name, guid) {
if (!name) { if (!name) {
throw new Error("null name"); throw new Error("null name");
} }
var url = self.getUrl("Packages/" + name); var options = {
AssemblyGuid: guid
};
var url = self.getUrl("Packages/" + name, options);
return self.ajax({ return self.ajax({
type: "GET", type: "GET",