Co-Authored-By: Taloth <Taloth@users.noreply.github.com>pull/5839/head
parent
c892b827af
commit
553a8f2a0a
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using Dapper;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Converters
|
||||
{
|
||||
public class SystemVersionConverter : SqlMapper.TypeHandler<Version>
|
||||
{
|
||||
public override Version Parse(object value)
|
||||
{
|
||||
if (value is string version)
|
||||
{
|
||||
return Version.Parse((string)value);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void SetValue(IDbDataParameter parameter, Version value)
|
||||
{
|
||||
parameter.Value = value.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using FluentMigrator;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(189)]
|
||||
public class add_update_history : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void LogDbUpgrade()
|
||||
{
|
||||
Create.TableForModel("UpdateHistory")
|
||||
.WithColumn("Date").AsDateTime().NotNullable().Indexed()
|
||||
.WithColumn("Version").AsString().NotNullable()
|
||||
.WithColumn("EventType").AsInt32().NotNullable();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using NzbDrone.Common.Messaging;
|
||||
|
||||
namespace NzbDrone.Core.Update.History.Events
|
||||
{
|
||||
public class UpdateInstalledEvent : IEvent
|
||||
{
|
||||
public Version PreviousVerison { get; set; }
|
||||
public Version NewVersion { get; set; }
|
||||
|
||||
public UpdateInstalledEvent(Version previousVersion, Version newVersion)
|
||||
{
|
||||
PreviousVerison = previousVersion;
|
||||
NewVersion = newVersion;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
||||
namespace NzbDrone.Core.Update.History
|
||||
{
|
||||
public interface IUpdateHistoryRepository : IBasicRepository<UpdateHistory>
|
||||
{
|
||||
UpdateHistory LastInstalled();
|
||||
UpdateHistory PreviouslyInstalled();
|
||||
List<UpdateHistory> InstalledSince(DateTime dateTime);
|
||||
}
|
||||
|
||||
public class UpdateHistoryRepository : BasicRepository<UpdateHistory>, IUpdateHistoryRepository
|
||||
{
|
||||
public UpdateHistoryRepository(ILogDatabase logDatabase, IEventAggregator eventAggregator)
|
||||
: base(logDatabase, eventAggregator)
|
||||
{
|
||||
}
|
||||
|
||||
public UpdateHistory LastInstalled()
|
||||
{
|
||||
var history = Query(x => x.EventType == UpdateHistoryEventType.Installed)
|
||||
.OrderBy(v => v.Date)
|
||||
.Take(1)
|
||||
.FirstOrDefault();
|
||||
|
||||
return history;
|
||||
}
|
||||
|
||||
public UpdateHistory PreviouslyInstalled()
|
||||
{
|
||||
var history = Query(x => x.EventType == UpdateHistoryEventType.Installed)
|
||||
.OrderBy(v => v.Date)
|
||||
.Skip(1)
|
||||
.Take(1)
|
||||
.FirstOrDefault();
|
||||
|
||||
return history;
|
||||
}
|
||||
|
||||
public List<UpdateHistory> InstalledSince(DateTime dateTime)
|
||||
{
|
||||
var history = Query(v => v.EventType == UpdateHistoryEventType.Installed && v.Date >= dateTime)
|
||||
.OrderBy(v => v.Date)
|
||||
.ToList();
|
||||
|
||||
return history;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue