mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
fixing update for vnext.
This commit is contained in:
parent
2001e5f502
commit
80c996c216
@ -7,11 +7,13 @@
|
||||
using NzbDrone.Api.Mapping;
|
||||
using NzbDrone.Api.RootFolders;
|
||||
using NzbDrone.Api.Series;
|
||||
using NzbDrone.Api.Update;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
using NzbDrone.Core.Update;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Api.Test.MappingTests
|
||||
@ -28,6 +30,7 @@ public class ResourceMappingFixture : TestBase
|
||||
[TestCase(typeof(ParsedEpisodeInfo), typeof(ReleaseResource))]
|
||||
[TestCase(typeof(DownloadDecision), typeof(ReleaseResource))]
|
||||
[TestCase(typeof(Core.History.History), typeof(HistoryResource))]
|
||||
[TestCase(typeof(UpdatePackage), typeof(UpdateResource))]
|
||||
public void matching_fields(Type modelType, Type resourceType)
|
||||
{
|
||||
MappingValidation.ValidateMapping(modelType, resourceType);
|
||||
|
@ -4,8 +4,7 @@
|
||||
using NzbDrone.Api.Episodes;
|
||||
using NzbDrone.Api.History;
|
||||
using NzbDrone.Api.Missing;
|
||||
using NzbDrone.Api.QualityProfiles;
|
||||
using NzbDrone.Api.QualityType;
|
||||
using NzbDrone.Api.Qualities;
|
||||
using NzbDrone.Api.Resolvers;
|
||||
using NzbDrone.Api.Series;
|
||||
using NzbDrone.Core.Datastore;
|
||||
@ -20,11 +19,11 @@ public static class AutomapperBootstraper
|
||||
public static void InitializeAutomapper()
|
||||
{
|
||||
//QualityProfiles
|
||||
Mapper.CreateMap<QualityProfile, QualityProfileModel>()
|
||||
Mapper.CreateMap<QualityProfile, QualityProfileResource>()
|
||||
.ForMember(dest => dest.Qualities,
|
||||
opt => opt.ResolveUsing<AllowedToQualitiesResolver>().FromMember(src => src.Allowed));
|
||||
|
||||
Mapper.CreateMap<QualityProfileModel, QualityProfile>()
|
||||
Mapper.CreateMap<QualityProfileResource, QualityProfile>()
|
||||
.ForMember(dest => dest.Allowed,
|
||||
opt => opt.ResolveUsing<QualitiesToAllowedResolver>().FromMember(src => src.Qualities));
|
||||
|
||||
|
@ -135,10 +135,10 @@
|
||||
<Compile Include="Exceptions\InvalidApiKeyException.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="NzbDroneApiModule.cs" />
|
||||
<Compile Include="QualityProfiles\QualityProfileModel.cs" />
|
||||
<Compile Include="QualityProfiles\QualityProfilesModule.cs" />
|
||||
<Compile Include="QualityType\QualitySizeResource.cs" />
|
||||
<Compile Include="QualityType\QualitySizeModule.cs" />
|
||||
<Compile Include="Qualities\QualityProfileResource.cs" />
|
||||
<Compile Include="Qualities\QualityProfilesModule.cs" />
|
||||
<Compile Include="Qualities\QualitySizeResource.cs" />
|
||||
<Compile Include="Qualities\QualitySizeModule.cs" />
|
||||
<Compile Include="Extensions\RequestExtensions.cs" />
|
||||
<Compile Include="Resolvers\AllowedToQualitiesResolver.cs" />
|
||||
<Compile Include="Resolvers\QualitiesToAllowedResolver.cs" />
|
||||
@ -149,6 +149,7 @@
|
||||
<Compile Include="SignalR\SignalrDependencyResolver.cs" />
|
||||
<Compile Include="SignalR\NzbDronePersistentConnection.cs" />
|
||||
<Compile Include="TinyIoCNancyBootstrapper.cs" />
|
||||
<Compile Include="Update\UpdateModule.cs" />
|
||||
<Compile Include="Validation\IdValidationRule.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -1,11 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Api.QualityProfiles
|
||||
namespace NzbDrone.Api.Qualities
|
||||
{
|
||||
public class QualityProfileModel
|
||||
public class QualityProfileResource
|
||||
{
|
||||
public Int32 Id { get; set; }
|
||||
public String Name { get; set; }
|
@ -4,7 +4,7 @@
|
||||
using NzbDrone.Api.Extensions;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
namespace NzbDrone.Api.QualityProfiles
|
||||
namespace NzbDrone.Api.Qualities
|
||||
{
|
||||
public class QualityProfilesModule : NzbDroneApiModule
|
||||
{
|
||||
@ -23,19 +23,19 @@ public QualityProfilesModule(QualityProfileService qualityProvider)
|
||||
private Response OnGet()
|
||||
{
|
||||
var profiles = _qualityProvider.All();
|
||||
return Mapper.Map<List<QualityProfile>, List<QualityProfileModel>>(profiles).AsResponse();
|
||||
return Mapper.Map<List<QualityProfile>, List<QualityProfileResource>>(profiles).AsResponse();
|
||||
}
|
||||
|
||||
private Response OnGet(int id)
|
||||
{
|
||||
var profile = _qualityProvider.Get(id);
|
||||
return Mapper.Map<QualityProfile, QualityProfileModel>(profile).AsResponse();
|
||||
return Mapper.Map<QualityProfile, QualityProfileResource>(profile).AsResponse();
|
||||
}
|
||||
|
||||
private Response OnPost()
|
||||
{
|
||||
var request = Request.Body.FromJson<QualityProfileModel>();
|
||||
var profile = Mapper.Map<QualityProfileModel, QualityProfile>(request);
|
||||
var request = Request.Body.FromJson<QualityProfileResource>();
|
||||
var profile = Mapper.Map<QualityProfileResource, QualityProfile>(request);
|
||||
request.Id = _qualityProvider.Add(profile).Id;
|
||||
|
||||
return request.AsResponse();
|
||||
@ -44,8 +44,8 @@ private Response OnPost()
|
||||
//Update
|
||||
private Response OnPut()
|
||||
{
|
||||
var request = Request.Body.FromJson<QualityProfileModel>();
|
||||
var profile = Mapper.Map<QualityProfileModel, QualityProfile>(request);
|
||||
var request = Request.Body.FromJson<QualityProfileResource>();
|
||||
var profile = Mapper.Map<QualityProfileResource, QualityProfile>(request);
|
||||
_qualityProvider.Update(profile);
|
||||
|
||||
return request.AsResponse();
|
@ -5,7 +5,7 @@
|
||||
using NzbDrone.Api.Extensions;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
namespace NzbDrone.Api.QualityType
|
||||
namespace NzbDrone.Api.Qualities
|
||||
{
|
||||
public class QualitySizeModule : NzbDroneApiModule
|
||||
{
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using NzbDrone.Api.REST;
|
||||
|
||||
namespace NzbDrone.Api.QualityType
|
||||
namespace NzbDrone.Api.Qualities
|
||||
{
|
||||
public class QualitySizeResource : RestResource
|
||||
{
|
@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using NzbDrone.Api.QualityProfiles;
|
||||
using NzbDrone.Api.Qualities;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
namespace NzbDrone.Api.Resolvers
|
||||
|
@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using NzbDrone.Api.QualityProfiles;
|
||||
|
||||
namespace NzbDrone.Api.Resolvers
|
||||
{
|
||||
|
@ -3,7 +3,7 @@
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using AutoMapper;
|
||||
using NzbDrone.Api.QualityProfiles;
|
||||
using NzbDrone.Api.Qualities;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
namespace NzbDrone.Api.Resolvers
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using AutoMapper;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
|
39
NzbDrone.Api/Update/UpdateModule.cs
Normal file
39
NzbDrone.Api/Update/UpdateModule.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Api.REST;
|
||||
using NzbDrone.Core.Update;
|
||||
using NzbDrone.Api.Mapping;
|
||||
|
||||
namespace NzbDrone.Api.Update
|
||||
{
|
||||
public class UpdateModule : NzbDroneRestModule<UpdateResource>
|
||||
{
|
||||
private readonly IUpdateService _updateService;
|
||||
|
||||
public UpdateModule(IUpdateService updateService)
|
||||
{
|
||||
_updateService = updateService;
|
||||
GetResourceAll = GetAvailableUpdate;
|
||||
}
|
||||
|
||||
private List<UpdateResource> GetAvailableUpdate()
|
||||
{
|
||||
var update = _updateService.AvailableUpdate();
|
||||
var response = new List<UpdateResource>();
|
||||
|
||||
if (update != null)
|
||||
{
|
||||
response.Add(update.InjectTo<UpdateResource>());
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateResource : RestResource
|
||||
{
|
||||
public Version Version { get; set; }
|
||||
public String FileName { get; set; }
|
||||
public String Url { get; set; }
|
||||
}
|
||||
}
|
@ -107,12 +107,6 @@ public void GetUpdateClientExePath()
|
||||
GetEnvironmentProvider().GetUpdateClientExePath().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone.Update.exe");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetSandboxLogFolder()
|
||||
{
|
||||
GetEnvironmentProvider().GetSandboxLogFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\UpdateLogs\");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUpdateLogFolder()
|
||||
{
|
||||
|
@ -0,0 +1,26 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.LayoutRenderers;
|
||||
|
||||
namespace NzbDrone.Common.Instrumentation
|
||||
{
|
||||
[ThreadAgnostic]
|
||||
[LayoutRenderer("appLog")]
|
||||
public class ApplicationLogLayoutRenderer : LayoutRenderer
|
||||
{
|
||||
private readonly string _appData;
|
||||
|
||||
public ApplicationLogLayoutRenderer()
|
||||
{
|
||||
_appData = Path.Combine(new EnvironmentProvider().GetLogFolder(), "nzbdrone.txt");
|
||||
|
||||
}
|
||||
|
||||
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
|
||||
{
|
||||
builder.Append(_appData);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.LayoutRenderers;
|
||||
|
||||
namespace NzbDrone.Common.Instrumentation
|
||||
{
|
||||
[ThreadAgnostic]
|
||||
[LayoutRenderer("dirSeparator")]
|
||||
public class DirSeparatorLayoutRenderer : LayoutRenderer
|
||||
{
|
||||
|
||||
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
|
||||
{
|
||||
builder.Append(Path.DirectorySeparatorChar);
|
||||
}
|
||||
}
|
||||
}
|
27
NzbDrone.Common/Instrumentation/UpdateLogLayoutRenderer.cs
Normal file
27
NzbDrone.Common/Instrumentation/UpdateLogLayoutRenderer.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.LayoutRenderers;
|
||||
|
||||
namespace NzbDrone.Common.Instrumentation
|
||||
{
|
||||
[ThreadAgnostic]
|
||||
[LayoutRenderer("updateLog")]
|
||||
public class UpdateLogLayoutRenderer : LayoutRenderer
|
||||
{
|
||||
private readonly string _appData;
|
||||
|
||||
public UpdateLogLayoutRenderer()
|
||||
{
|
||||
_appData = Path.Combine(new EnvironmentProvider().GetUpdateLogFolder(), DateTime.Now.ToString("yy.MM.d-HH.mm"));
|
||||
|
||||
}
|
||||
|
||||
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
|
||||
{
|
||||
builder.Append(_appData);
|
||||
}
|
||||
}
|
||||
}
|
@ -11,11 +11,11 @@ namespace NzbDrone.Common.Instrumentation
|
||||
[LayoutRenderer("version")]
|
||||
public class VersionLayoutRenderer : LayoutRenderer
|
||||
{
|
||||
private static readonly string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
private static readonly string Version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
|
||||
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
|
||||
{
|
||||
builder.Append(version);
|
||||
builder.Append(Version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -107,6 +107,9 @@
|
||||
<Compile Include="EnsureThat\Resources\ExceptionMessages.Designer.cs" />
|
||||
<Compile Include="EnsureThat\StringExtensions.cs" />
|
||||
<Compile Include="EnsureThat\TypeParam.cs" />
|
||||
<Compile Include="Instrumentation\ApplicationLogLayoutRenderer.cs" />
|
||||
<Compile Include="Instrumentation\DirSeparatorLayoutRenderer.cs" />
|
||||
<Compile Include="Instrumentation\UpdateLogLayoutRenderer.cs" />
|
||||
<Compile Include="Serializer\Json.cs" />
|
||||
<Compile Include="Messaging\CommandCompletedEvent.cs" />
|
||||
<Compile Include="Messaging\CommandStartedEvent.cs" />
|
||||
|
@ -5,7 +5,6 @@ namespace NzbDrone.Common
|
||||
{
|
||||
public static class PathExtensions
|
||||
{
|
||||
private static readonly string APP_DATA = "App_Data" + Path.DirectorySeparatorChar;
|
||||
private static readonly string APP_CONFIG_FILE = "config.xml";
|
||||
private static readonly string NZBDRONE_DB = "nzbdrone.db";
|
||||
private static readonly string BACKUP_ZIP_FILE = "NzbDrone_Backup.zip";
|
||||
@ -57,12 +56,17 @@ public static string GetActualCasing(this string filename)
|
||||
|
||||
public static string GetAppDataPath(this IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.WorkingDirectory, APP_DATA);
|
||||
return environmentProvider.WorkingDirectory;
|
||||
}
|
||||
|
||||
public static string GetLogFolder(this IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetAppDataPath(), "logs");
|
||||
}
|
||||
|
||||
public static string GetConfigPath(this IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.WorkingDirectory, APP_CONFIG_FILE);
|
||||
return Path.Combine(environmentProvider.GetAppDataPath(), APP_CONFIG_FILE);
|
||||
}
|
||||
|
||||
public static string GetMediaCoverPath(this IEnvironmentProvider environmentProvider)
|
||||
@ -72,7 +76,7 @@ public static string GetMediaCoverPath(this IEnvironmentProvider environmentProv
|
||||
|
||||
public static string GetUpdateLogFolder(this IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.WorkingDirectory, UPDATE_LOG_FOLDER_NAME);
|
||||
return Path.Combine(environmentProvider.GetAppDataPath(), UPDATE_LOG_FOLDER_NAME);
|
||||
}
|
||||
|
||||
public static string GetUpdateSandboxFolder(this IEnvironmentProvider environmentProvider)
|
||||
@ -100,11 +104,6 @@ public static string GetUpdateClientExePath(this IEnvironmentProvider environmen
|
||||
return Path.Combine(environmentProvider.GetUpdateSandboxFolder(), UPDATE_CLIENT_EXE);
|
||||
}
|
||||
|
||||
public static string GetSandboxLogFolder(this IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetUpdateSandboxFolder(), UPDATE_LOG_FOLDER_NAME);
|
||||
}
|
||||
|
||||
public static string GetConfigBackupFile(this IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetAppDataPath(), BACKUP_ZIP_FILE);
|
||||
|
@ -32,6 +32,7 @@ public static bool IsSimpleType(this Type type)
|
||||
|| type.IsEnum
|
||||
|| type == typeof(string)
|
||||
|| type == typeof(DateTime)
|
||||
|| type == typeof(Version)
|
||||
|| type == typeof(Decimal);
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Update;
|
||||
|
||||
namespace NzbDrone.Core.Test.UpdateTests
|
||||
{
|
||||
|
@ -167,7 +167,7 @@ public string XbmcPassword
|
||||
|
||||
public string UpdateUrl
|
||||
{
|
||||
get { return GetValue("UpdateUrl", "http://update.nzbdrone.com/_release/"); }
|
||||
get { return GetValue("UpdateUrl", "http://update.nzbdrone.com/vnext/"); }
|
||||
set { SetValue("UpdateUrl", value); }
|
||||
}
|
||||
|
||||
|
@ -45,10 +45,7 @@ private void ExecuteCommands()
|
||||
{
|
||||
try
|
||||
{
|
||||
var commandType = Type.GetType(task.TypeName);
|
||||
var command = (ICommand)Activator.CreateInstance(commandType);
|
||||
|
||||
_messageAggregator.PublishCommand(command);
|
||||
_messageAggregator.PublishCommand(task.TypeName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -7,6 +7,7 @@
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using NzbDrone.Core.MediaFiles.Commands;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Update.Commands;
|
||||
|
||||
namespace NzbDrone.Core.Jobs
|
||||
{
|
||||
@ -39,7 +40,8 @@ public void Handle(ApplicationStartedEvent message)
|
||||
new ScheduledTask{ Interval = 25, TypeName = typeof(RssSyncCommand).FullName},
|
||||
new ScheduledTask{ Interval = 12*60, TypeName = typeof(UpdateXemMappings).FullName},
|
||||
new ScheduledTask{ Interval = 6*60, TypeName = typeof(DiskScanCommand).FullName},
|
||||
new ScheduledTask{ Interval = 1, TypeName = typeof(DownloadedEpisodesScanCommand).FullName}
|
||||
new ScheduledTask{ Interval = 1, TypeName = typeof(DownloadedEpisodesScanCommand).FullName},
|
||||
new ScheduledTask{ Interval = 15, TypeName = typeof(ApplicationUpdateCommand).FullName}
|
||||
};
|
||||
|
||||
var currentTasks = _scheduledTaskRepository.All();
|
||||
|
@ -7,106 +7,125 @@
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Update;
|
||||
using NzbDrone.Core.Update.Commands;
|
||||
|
||||
namespace NzbDrone.Core.Update
|
||||
{
|
||||
public interface IUpdateService
|
||||
public interface IUpdateService : IExecute<ApplicationUpdateCommand>
|
||||
{
|
||||
Dictionary<DateTime, string> GetUpdateLogFiles();
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateService : IUpdateService, IExecute<ApplicationUpdateCommand>
|
||||
{
|
||||
private readonly IUpdatePackageProvider _updatePackageProvider;
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IHttpProvider _httpProvider;
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly ArchiveProvider _archiveProvider;
|
||||
private readonly IProcessProvider _processProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
|
||||
public UpdateService(IUpdatePackageProvider updatePackageProvider, IEnvironmentProvider environmentProvider, IDiskProvider diskProvider,
|
||||
IHttpProvider httpProvider, IConfigFileProvider configFileProvider, ArchiveProvider archiveProvider, IProcessProvider processProvider, Logger logger)
|
||||
{
|
||||
_updatePackageProvider = updatePackageProvider;
|
||||
_environmentProvider = environmentProvider;
|
||||
_diskProvider = diskProvider;
|
||||
_httpProvider = httpProvider;
|
||||
_configFileProvider = configFileProvider;
|
||||
_archiveProvider = archiveProvider;
|
||||
_processProvider = processProvider;
|
||||
_logger = logger;
|
||||
UpdatePackage AvailableUpdate();
|
||||
}
|
||||
|
||||
|
||||
private void InstallUpdate(UpdatePackage updatePackage)
|
||||
public class UpdateService : IUpdateService
|
||||
{
|
||||
var packageDestination = Path.Combine(_environmentProvider.GetUpdateSandboxFolder(), updatePackage.FileName);
|
||||
private readonly IUpdatePackageProvider _updatePackageProvider;
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
|
||||
if (_diskProvider.FolderExists(_environmentProvider.GetUpdateSandboxFolder()))
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IHttpProvider _httpProvider;
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly ArchiveProvider _archiveProvider;
|
||||
private readonly IProcessProvider _processProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
|
||||
public UpdateService(IUpdatePackageProvider updatePackageProvider, IEnvironmentProvider environmentProvider,
|
||||
IDiskProvider diskProvider,
|
||||
IHttpProvider httpProvider, IConfigFileProvider configFileProvider,
|
||||
ArchiveProvider archiveProvider, IProcessProvider processProvider, Logger logger)
|
||||
{
|
||||
_logger.Info("Deleting old update files");
|
||||
_diskProvider.DeleteFolder(_environmentProvider.GetUpdateSandboxFolder(), true);
|
||||
_updatePackageProvider = updatePackageProvider;
|
||||
_environmentProvider = environmentProvider;
|
||||
_diskProvider = diskProvider;
|
||||
_httpProvider = httpProvider;
|
||||
_configFileProvider = configFileProvider;
|
||||
_archiveProvider = archiveProvider;
|
||||
_processProvider = processProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
_logger.Info("Downloading update package from [{0}] to [{1}]", updatePackage.Url, packageDestination);
|
||||
_httpProvider.DownloadFile(updatePackage.Url, packageDestination);
|
||||
_logger.Info("Download completed for update package from [{0}]", updatePackage.FileName);
|
||||
|
||||
_logger.Info("Extracting Update package");
|
||||
_archiveProvider.ExtractArchive(packageDestination, _environmentProvider.GetUpdateSandboxFolder());
|
||||
_logger.Info("Update package extracted successfully");
|
||||
|
||||
_logger.Info("Preparing client");
|
||||
_diskProvider.MoveDirectory(_environmentProvider.GetUpdateClientFolder(), _environmentProvider.GetUpdateSandboxFolder());
|
||||
|
||||
|
||||
_logger.Info("Starting update client");
|
||||
var startInfo = new ProcessStartInfo
|
||||
private void InstallUpdate(UpdatePackage updatePackage)
|
||||
{
|
||||
FileName = _environmentProvider.GetUpdateClientExePath(),
|
||||
Arguments = string.Format("{0} {1}", _processProvider.GetCurrentProcess().Id, _configFileProvider.Guid)
|
||||
};
|
||||
var updateSandboxFolder = _environmentProvider.GetUpdateSandboxFolder();
|
||||
|
||||
var process = _processProvider.Start(startInfo);
|
||||
var packageDestination = Path.Combine(updateSandboxFolder, updatePackage.FileName);
|
||||
|
||||
_processProvider.WaitForExit(process);
|
||||
}
|
||||
|
||||
public Dictionary<DateTime, string> GetUpdateLogFiles()
|
||||
{
|
||||
var list = new Dictionary<DateTime, string>();
|
||||
|
||||
if (_diskProvider.FolderExists(_environmentProvider.GetUpdateLogFolder()))
|
||||
{
|
||||
var provider = CultureInfo.InvariantCulture;
|
||||
var files = _diskProvider.GetFiles(_environmentProvider.GetUpdateLogFolder(), SearchOption.TopDirectoryOnly).ToList();
|
||||
|
||||
foreach (var file in files.Select(c => new FileInfo(c)).OrderByDescending(c => c.Name))
|
||||
if (_diskProvider.FolderExists(updateSandboxFolder))
|
||||
{
|
||||
list.Add(DateTime.ParseExact(file.Name.Replace(file.Extension, string.Empty), "yyyy.MM.dd-H-mm", provider), file.FullName);
|
||||
_logger.Info("Deleting old update files");
|
||||
_diskProvider.DeleteFolder(updateSandboxFolder, true);
|
||||
}
|
||||
|
||||
_logger.Info("Downloading update package from [{0}] to [{1}]", updatePackage.Url, packageDestination);
|
||||
_httpProvider.DownloadFile(updatePackage.Url, packageDestination);
|
||||
_logger.Info("Download completed for update package from [{0}]", updatePackage.FileName);
|
||||
|
||||
_logger.Info("Extracting Update package");
|
||||
_archiveProvider.ExtractArchive(packageDestination, updateSandboxFolder);
|
||||
_logger.Info("Update package extracted successfully");
|
||||
|
||||
_logger.Info("Preparing client");
|
||||
_diskProvider.MoveDirectory(_environmentProvider.GetUpdateClientFolder(),
|
||||
updateSandboxFolder);
|
||||
|
||||
|
||||
_logger.Info("Starting update client");
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = _environmentProvider.GetUpdateClientExePath(),
|
||||
Arguments = string.Format("{0} {1}", _processProvider.GetCurrentProcess().Id, _configFileProvider.Guid)
|
||||
};
|
||||
|
||||
var process = _processProvider.Start(startInfo);
|
||||
|
||||
_processProvider.WaitForExit(process);
|
||||
}
|
||||
|
||||
public Dictionary<DateTime, string> GetUpdateLogFiles()
|
||||
{
|
||||
var list = new Dictionary<DateTime, string>();
|
||||
|
||||
if (_diskProvider.FolderExists(_environmentProvider.GetUpdateLogFolder()))
|
||||
{
|
||||
var provider = CultureInfo.InvariantCulture;
|
||||
var files =
|
||||
_diskProvider.GetFiles(_environmentProvider.GetUpdateLogFolder(), SearchOption.TopDirectoryOnly)
|
||||
.ToList();
|
||||
|
||||
foreach (var file in files.Select(c => new FileInfo(c)).OrderByDescending(c => c.Name))
|
||||
{
|
||||
list.Add(
|
||||
DateTime.ParseExact(file.Name.Replace(file.Extension, string.Empty), "yyyy.MM.dd-H-mm", provider),
|
||||
file.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public UpdatePackage AvailableUpdate()
|
||||
{
|
||||
var latestAvailable = _updatePackageProvider.GetLatestUpdate();
|
||||
|
||||
if (latestAvailable == null || latestAvailable.Version <= _environmentProvider.Version)
|
||||
{
|
||||
_logger.Debug("No update available.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return latestAvailable;
|
||||
}
|
||||
|
||||
public void Execute(ApplicationUpdateCommand message)
|
||||
{
|
||||
var latestAvailable = AvailableUpdate();
|
||||
|
||||
if (latestAvailable != null)
|
||||
{
|
||||
InstallUpdate(latestAvailable);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public void Execute(ApplicationUpdateCommand message)
|
||||
{
|
||||
var latestAvailable = _updatePackageProvider.GetLatestUpdate();
|
||||
|
||||
if (latestAvailable == null || latestAvailable.Version <= _environmentProvider.Version)
|
||||
{
|
||||
_logger.Debug("No update available.");
|
||||
return;
|
||||
}
|
||||
|
||||
InstallUpdate(latestAvailable);
|
||||
}
|
||||
}
|
@ -1,11 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<extensions>
|
||||
<add assembly="NzbDrone.Common"/>
|
||||
</extensions>
|
||||
<targets>
|
||||
<target xsi:type="ColoredConsole" name="consoleLogger" layout="[${level}] ${logger}: ${message} ${onexception:inner=${newline}${newline}${exception:format=ToString}${newline}}"/>
|
||||
<target xsi:type="File" name="fileLogger" fileName="${date:format=yyyy.MM.dd-H-mm}.txt" autoFlush="true" keepFileOpen="false"
|
||||
concurrentWrites="false" concurrentWriteAttemptDelay="50" concurrentWriteAttempts ="10"
|
||||
layout="${date:format=yy-M-d HH\:mm\:ss.f}|${logger}}|${level}|${message}|${exception:format=ToString}"/>
|
||||
<target xsi:type="File" name="fileLogger" fileName="${updateLog}" autoFlush="true" keepFileOpen="false"
|
||||
concurrentWrites="false" concurrentWriteAttemptDelay="50" concurrentWriteAttempts ="10"
|
||||
layout="${date:format=yy-M-d HH\:mm\:ss.f}|${level}|${logger}|${message}${onexception:inner=${newline}${newline}${exception:format=ToString}${newline}}"/>
|
||||
</targets>
|
||||
<rules>
|
||||
<logger name="*" minlevel="Debug" writeTo="consoleLogger"/>
|
||||
|
@ -37,28 +37,10 @@ public static void Main(string[] args)
|
||||
logger.FatalException("An error has occurred while applying update package.", e);
|
||||
}
|
||||
|
||||
TransferUpdateLogs();
|
||||
}
|
||||
|
||||
private static void TransferUpdateLogs()
|
||||
{
|
||||
try
|
||||
{
|
||||
var environmentProvider = _container.Resolve<IEnvironmentProvider>();
|
||||
var diskProvider = _container.Resolve<IDiskProvider>();
|
||||
logger.Info("Copying log files to application directory.");
|
||||
diskProvider.CopyDirectory(environmentProvider.GetSandboxLogFolder(), environmentProvider.GetUpdateLogFolder());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.FatalException("Can't copy upgrade log files to target folder", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Start(string[] args)
|
||||
{
|
||||
VerfityArguments(args);
|
||||
int processId = ParseProcessId(args);
|
||||
|
||||
var exeFileInfo = new FileInfo(_processProvider.GetProcessById(processId).StartPath);
|
||||
@ -79,13 +61,5 @@ private int ParseProcessId(string[] args)
|
||||
logger.Debug("NzbDrone processId:{0}", id);
|
||||
return id;
|
||||
}
|
||||
|
||||
private void VerfityArguments(string[] args)
|
||||
{
|
||||
if (args == null || args.Length != 2)
|
||||
throw new ArgumentException("Wrong number of parameters were passed in.");
|
||||
|
||||
logger.Debug("Arguments verified. [{0}] , [{1}]", args[0], args[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ namespace NzbDrone.Update
|
||||
{
|
||||
public class UpdateContainerBuilder : ContainerBuilderBase
|
||||
{
|
||||
public UpdateContainerBuilder()
|
||||
private UpdateContainerBuilder()
|
||||
: base("NzbDrone.Update", "NzbDrone.Common")
|
||||
{
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Update;
|
||||
using NzbDrone.Core.Update.Commands;
|
||||
|
||||
namespace NzbDrone
|
||||
{
|
||||
@ -42,6 +44,14 @@ public static void Main(string[] args)
|
||||
}
|
||||
|
||||
var container = MainAppContainerBuilder.BuildContainer();
|
||||
try
|
||||
{
|
||||
container.Resolve<IUpdateService>().Execute(new ApplicationUpdateCommand());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.ErrorException("Application update failed.", e);
|
||||
}
|
||||
|
||||
container.Resolve<Router>().Route(args);
|
||||
}
|
||||
|
@ -4,9 +4,8 @@
|
||||
autoReload="true"
|
||||
internalLogLevel="Info"
|
||||
throwExceptions="true"
|
||||
internalLogToConsole="false"
|
||||
internalLogToConsoleError="true"
|
||||
internalLogFile="nlog.txt">
|
||||
internalLogToConsole="true"
|
||||
internalLogToConsoleError="true">
|
||||
<extensions>
|
||||
<add assembly="NzbDrone.Core"/>
|
||||
<add assembly="NzbDrone.Common"/>
|
||||
@ -19,14 +18,14 @@
|
||||
<layout>${exception:format=ToString}</layout>
|
||||
</parameter>
|
||||
</target>
|
||||
<target xsi:type="File" name="rollingFileLogger" fileName="nzbdrone.log.txt" autoFlush="true" keepFileOpen="false"
|
||||
<target xsi:type="File" name="rollingFileLogger" fileName="${appLog}" autoFlush="true" keepFileOpen="false"
|
||||
concurrentWrites="false" concurrentWriteAttemptDelay="50" concurrentWriteAttempts ="10"
|
||||
archiveAboveSize="1024000" maxArchiveFiles="5" enableFileDelete="true" archiveNumbering ="Rolling"
|
||||
layout="${date:format=yy-M-d HH\:mm\:ss.f}|${logger}}|${level}|${message}|${exception:format=ToString}"/>
|
||||
layout="${date:format=yy-M-d HH\:mm\:ss.f}|${level}|${logger}|${message}${onexception:inner=${newline}${newline}${exception:format=ToString}${newline}}"/>
|
||||
</targets>
|
||||
<rules>
|
||||
<logger name="*" minlevel="Trace" writeTo="consoleLogger"/>
|
||||
<logger name="*" minlevel="Off" writeTo="udpTarget"/>
|
||||
<logger name="*" minlevel="Warn" writeTo="rollingFileLogger"/>
|
||||
<logger name="*" minlevel="Debug" writeTo="rollingFileLogger"/>
|
||||
</rules>
|
||||
</nlog>
|
10
build.ps1
10
build.ps1
@ -77,15 +77,9 @@ Function Nunit()
|
||||
Function RunGrunt()
|
||||
{
|
||||
$gruntPath = [environment]::getfolderpath("applicationdata") + '\npm\node_modules\grunt-cli\bin\grunt'
|
||||
|
||||
if(!(Test-Path $gruntPath))
|
||||
{
|
||||
Invoke-Expression 'npm install grunt-cli -g'
|
||||
}
|
||||
|
||||
Invoke-Expression 'npm install'
|
||||
Invoke-Expression 'npm install'
|
||||
|
||||
Invoke-Expression ('node ' + $gruntPath + ' package')
|
||||
Invoke-Expression ('node ' + $gruntPath + ' package')
|
||||
}
|
||||
|
||||
Build
|
||||
|
Loading…
Reference in New Issue
Block a user