save appVersion with device record

This commit is contained in:
Luke Pulverenti
2015-03-14 21:42:09 -04:00
parent cde1df51ec
commit 99c991f001
17 changed files with 213 additions and 68 deletions

View File

@@ -32,12 +32,12 @@ namespace MediaBrowser.Server.Implementations.Sync
});
}
public DeviceProfile GetDeviceProfile(SyncTarget target, string quality)
public DeviceProfile GetDeviceProfile(SyncTarget target, string profile, string quality)
{
var caps = _deviceManager.GetCapabilities(target.Id);
var profile = caps == null || caps.DeviceProfile == null ? new DeviceProfile() : caps.DeviceProfile;
var maxBitrate = profile.MaxStaticBitrate;
var deviceProfile = caps == null || caps.DeviceProfile == null ? new DeviceProfile() : caps.DeviceProfile;
var maxBitrate = deviceProfile.MaxStaticBitrate;
if (maxBitrate.HasValue)
{
@@ -50,10 +50,10 @@ namespace MediaBrowser.Server.Implementations.Sync
maxBitrate = Convert.ToInt32(maxBitrate.Value * .5);
}
profile.MaxStaticBitrate = maxBitrate;
deviceProfile.MaxStaticBitrate = maxBitrate;
}
return profile;
return deviceProfile;
}
public string Name
@@ -101,5 +101,10 @@ namespace MediaBrowser.Server.Implementations.Sync
}
};
}
public IEnumerable<SyncQualityOption> GetProfileOptions(SyncTarget target)
{
return new List<SyncQualityOption>();
}
}
}

View File

@@ -10,9 +10,10 @@ namespace MediaBrowser.Server.Implementations.Sync
/// Gets the device profile.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="profile">The profile.</param>
/// <param name="quality">The quality.</param>
/// <returns>DeviceProfile.</returns>
DeviceProfile GetDeviceProfile(SyncTarget target, string quality);
DeviceProfile GetDeviceProfile(SyncTarget target, string profile, string quality);
/// <summary>
/// Gets the quality options.
@@ -20,5 +21,12 @@ namespace MediaBrowser.Server.Implementations.Sync
/// <param name="target">The target.</param>
/// <returns>IEnumerable&lt;SyncQualityOption&gt;.</returns>
IEnumerable<SyncQualityOption> GetQualityOptions(SyncTarget target);
/// <summary>
/// Gets the profile options.
/// </summary>
/// <param name="target">The target.</param>
/// <returns>IEnumerable&lt;SyncQualityOption&gt;.</returns>
IEnumerable<SyncQualityOption> GetProfileOptions(SyncTarget target);
}
}

View File

@@ -982,7 +982,7 @@ namespace MediaBrowser.Server.Implementations.Sync
public AudioOptions GetAudioOptions(SyncJobItem jobItem, SyncJob job)
{
var profile = GetDeviceProfile(jobItem.TargetId, null);
var profile = GetDeviceProfile(jobItem.TargetId, null, null);
return new AudioOptions
{
@@ -992,7 +992,7 @@ namespace MediaBrowser.Server.Implementations.Sync
public VideoOptions GetVideoOptions(SyncJobItem jobItem, SyncJob job)
{
var profile = GetDeviceProfile(jobItem.TargetId, job.Quality);
var profile = GetDeviceProfile(jobItem.TargetId, job.Profile, job.Quality);
return new VideoOptions
{
@@ -1000,7 +1000,7 @@ namespace MediaBrowser.Server.Implementations.Sync
};
}
public DeviceProfile GetDeviceProfile(string targetId, string quality)
private DeviceProfile GetDeviceProfile(string targetId, string profile, string quality)
{
foreach (var provider in _providers)
{
@@ -1008,7 +1008,7 @@ namespace MediaBrowser.Server.Implementations.Sync
{
if (string.Equals(target.Id, targetId, StringComparison.OrdinalIgnoreCase))
{
return GetDeviceProfile(provider, target, quality);
return GetDeviceProfile(provider, target, profile, quality);
}
}
}
@@ -1016,22 +1016,22 @@ namespace MediaBrowser.Server.Implementations.Sync
return null;
}
private DeviceProfile GetDeviceProfile(ISyncProvider provider, SyncTarget target, string quality)
private DeviceProfile GetDeviceProfile(ISyncProvider provider, SyncTarget target, string profile, string quality)
{
var hasProfile = provider as IHasSyncQuality;
if (hasProfile != null)
{
return hasProfile.GetDeviceProfile(target, quality);
return hasProfile.GetDeviceProfile(target, profile, quality);
}
return GetDefaultProfile(quality);
return GetDeviceProfile(profile, quality);
}
private DeviceProfile GetDefaultProfile(string quality)
private DeviceProfile GetDeviceProfile(string profile, string quality)
{
var profile = new CloudSyncProfile(true, false);
var maxBitrate = profile.MaxStaticBitrate;
var deviceProfile = new CloudSyncProfile(true, false);
var maxBitrate = deviceProfile.MaxStaticBitrate;
if (maxBitrate.HasValue)
{
@@ -1044,10 +1044,10 @@ namespace MediaBrowser.Server.Implementations.Sync
maxBitrate = Convert.ToInt32(maxBitrate.Value * .5);
}
profile.MaxStaticBitrate = maxBitrate;
deviceProfile.MaxStaticBitrate = maxBitrate;
}
return profile;
return deviceProfile;
}
public IEnumerable<SyncQualityOption> GetQualityOptions(string targetId)
@@ -1100,5 +1100,40 @@ namespace MediaBrowser.Server.Implementations.Sync
}
};
}
public IEnumerable<SyncQualityOption> GetProfileOptions(string targetId)
{
foreach (var provider in _providers)
{
foreach (var target in GetSyncTargets(provider))
{
if (string.Equals(target.Id, targetId, StringComparison.OrdinalIgnoreCase))
{
return GetProfileOptions(provider, target);
}
}
}
return new List<SyncQualityOption>();
}
private IEnumerable<SyncQualityOption> GetProfileOptions(ISyncProvider provider, SyncTarget target)
{
var hasQuality = provider as IHasSyncQuality;
if (hasQuality != null)
{
return hasQuality.GetProfileOptions(target);
}
var list = new List<SyncQualityOption>();
list.Add(new SyncQualityOption
{
Name = SyncQuality.Low.ToString(),
Id = SyncQuality.Low.ToString()
});
return list;
}
}
}

View File

@@ -1,4 +1,5 @@
using MediaBrowser.Controller;
using System.Text;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Sync;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Logging;
@@ -50,7 +51,7 @@ namespace MediaBrowser.Server.Implementations.Sync
string[] queries = {
"create table if not exists SyncJobs (Id GUID PRIMARY KEY, TargetId TEXT NOT NULL, Name TEXT NOT NULL, Quality TEXT, Status TEXT NOT NULL, Progress FLOAT, UserId TEXT NOT NULL, ItemIds TEXT NOT NULL, Category TEXT, ParentId TEXT, UnwatchedOnly BIT, ItemLimit INT, SyncNewContent BIT, DateCreated DateTime, DateLastModified DateTime, ItemCount int)",
"create table if not exists SyncJobs (Id GUID PRIMARY KEY, TargetId TEXT NOT NULL, Name TEXT NOT NULL, Profile TEXT, Quality TEXT, Status TEXT NOT NULL, Progress FLOAT, UserId TEXT NOT NULL, ItemIds TEXT NOT NULL, Category TEXT, ParentId TEXT, UnwatchedOnly BIT, ItemLimit INT, SyncNewContent BIT, DateCreated DateTime, DateLastModified DateTime, ItemCount int)",
"create index if not exists idx_SyncJobs on SyncJobs(Id)",
"create table if not exists SyncJobItems (Id GUID PRIMARY KEY, ItemId TEXT, ItemName TEXT, MediaSourceId TEXT, JobId TEXT, TemporaryPath TEXT, OutputPath TEXT, Status TEXT, TargetId TEXT, DateCreated DateTime, Progress FLOAT, AdditionalFiles TEXT, MediaSource TEXT, IsMarkedForRemoval BIT, JobItemIndex INT)",
@@ -64,6 +65,8 @@ namespace MediaBrowser.Server.Implementations.Sync
_connection.RunQueries(queries, _logger);
_connection.AddColumn(_logger, "SyncJobs", "Profile", "TEXT");
PrepareStatements();
}
@@ -81,11 +84,12 @@ namespace MediaBrowser.Server.Implementations.Sync
// _insertJobCommand
_insertJobCommand = _connection.CreateCommand();
_insertJobCommand.CommandText = "insert into SyncJobs (Id, TargetId, Name, Quality, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount) values (@Id, @TargetId, @Name, @Quality, @Status, @Progress, @UserId, @ItemIds, @Category, @ParentId, @UnwatchedOnly, @ItemLimit, @SyncNewContent, @DateCreated, @DateLastModified, @ItemCount)";
_insertJobCommand.CommandText = "insert into SyncJobs (Id, TargetId, Name, Profile, Quality, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount) values (@Id, @TargetId, @Name, @Profile, @Quality, @Status, @Progress, @UserId, @ItemIds, @Category, @ParentId, @UnwatchedOnly, @ItemLimit, @SyncNewContent, @DateCreated, @DateLastModified, @ItemCount)";
_insertJobCommand.Parameters.Add(_insertJobCommand, "@Id");
_insertJobCommand.Parameters.Add(_insertJobCommand, "@TargetId");
_insertJobCommand.Parameters.Add(_insertJobCommand, "@Name");
_insertJobCommand.Parameters.Add(_insertJobCommand, "@Profile");
_insertJobCommand.Parameters.Add(_insertJobCommand, "@Quality");
_insertJobCommand.Parameters.Add(_insertJobCommand, "@Status");
_insertJobCommand.Parameters.Add(_insertJobCommand, "@Progress");
@@ -102,11 +106,12 @@ namespace MediaBrowser.Server.Implementations.Sync
// _updateJobCommand
_updateJobCommand = _connection.CreateCommand();
_updateJobCommand.CommandText = "update SyncJobs set TargetId=@TargetId,Name=@Name,Quality=@Quality,Status=@Status,Progress=@Progress,UserId=@UserId,ItemIds=@ItemIds,Category=@Category,ParentId=@ParentId,UnwatchedOnly=@UnwatchedOnly,ItemLimit=@ItemLimit,SyncNewContent=@SyncNewContent,DateCreated=@DateCreated,DateLastModified=@DateLastModified,ItemCount=@ItemCount where Id=@ID";
_updateJobCommand.CommandText = "update SyncJobs set TargetId=@TargetId,Name=@Name,Profile=@Profile,Quality=@Quality,Status=@Status,Progress=@Progress,UserId=@UserId,ItemIds=@ItemIds,Category=@Category,ParentId=@ParentId,UnwatchedOnly=@UnwatchedOnly,ItemLimit=@ItemLimit,SyncNewContent=@SyncNewContent,DateCreated=@DateCreated,DateLastModified=@DateLastModified,ItemCount=@ItemCount where Id=@ID";
_updateJobCommand.Parameters.Add(_updateJobCommand, "@Id");
_updateJobCommand.Parameters.Add(_updateJobCommand, "@TargetId");
_updateJobCommand.Parameters.Add(_updateJobCommand, "@Name");
_updateJobCommand.Parameters.Add(_updateJobCommand, "@Profile");
_updateJobCommand.Parameters.Add(_updateJobCommand, "@Quality");
_updateJobCommand.Parameters.Add(_updateJobCommand, "@Status");
_updateJobCommand.Parameters.Add(_updateJobCommand, "@Progress");
@@ -162,7 +167,7 @@ namespace MediaBrowser.Server.Implementations.Sync
_updateJobItemCommand.Parameters.Add(_updateJobItemCommand, "@JobItemIndex");
}
private const string BaseJobSelectText = "select Id, TargetId, Name, Quality, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount from SyncJobs";
private const string BaseJobSelectText = "select Id, TargetId, Name, Profile, Quality, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount from SyncJobs";
private const string BaseJobItemSelectText = "select Id, ItemId, ItemName, MediaSourceId, JobId, TemporaryPath, OutputPath, Status, TargetId, DateCreated, Progress, AdditionalFiles, MediaSource, IsMarkedForRemoval, JobItemIndex from SyncJobItems";
public SyncJob GetJob(string id)
@@ -210,54 +215,59 @@ namespace MediaBrowser.Server.Implementations.Sync
if (!reader.IsDBNull(3))
{
info.Quality = reader.GetString(3);
info.Profile = reader.GetString(3);
}
if (!reader.IsDBNull(4))
{
info.Status = (SyncJobStatus)Enum.Parse(typeof(SyncJobStatus), reader.GetString(4), true);
info.Quality = reader.GetString(4);
}
if (!reader.IsDBNull(5))
{
info.Progress = reader.GetDouble(5);
info.Status = (SyncJobStatus)Enum.Parse(typeof(SyncJobStatus), reader.GetString(5), true);
}
if (!reader.IsDBNull(6))
{
info.UserId = reader.GetString(6);
info.Progress = reader.GetDouble(6);
}
if (!reader.IsDBNull(7))
{
info.RequestedItemIds = reader.GetString(7).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
info.UserId = reader.GetString(7);
}
if (!reader.IsDBNull(8))
{
info.Category = (SyncCategory)Enum.Parse(typeof(SyncCategory), reader.GetString(8), true);
info.RequestedItemIds = reader.GetString(8).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
}
if (!reader.IsDBNull(9))
{
info.ParentId = reader.GetString(9);
info.Category = (SyncCategory)Enum.Parse(typeof(SyncCategory), reader.GetString(9), true);
}
if (!reader.IsDBNull(10))
{
info.UnwatchedOnly = reader.GetBoolean(10);
info.ParentId = reader.GetString(10);
}
if (!reader.IsDBNull(11))
{
info.ItemLimit = reader.GetInt32(11);
info.UnwatchedOnly = reader.GetBoolean(11);
}
info.SyncNewContent = reader.GetBoolean(12);
if (!reader.IsDBNull(12))
{
info.ItemLimit = reader.GetInt32(12);
}
info.DateCreated = reader.GetDateTime(13).ToUniversalTime();
info.DateLastModified = reader.GetDateTime(14).ToUniversalTime();
info.ItemCount = reader.GetInt32(15);
info.SyncNewContent = reader.GetBoolean(13);
info.DateCreated = reader.GetDateTime(14).ToUniversalTime();
info.DateLastModified = reader.GetDateTime(15).ToUniversalTime();
info.ItemCount = reader.GetInt32(16);
return info;
}
@@ -294,6 +304,7 @@ namespace MediaBrowser.Server.Implementations.Sync
cmd.GetParameter(index++).Value = new Guid(job.Id);
cmd.GetParameter(index++).Value = job.TargetId;
cmd.GetParameter(index++).Value = job.Name;
cmd.GetParameter(index++).Value = job.Profile;
cmd.GetParameter(index++).Value = job.Quality;
cmd.GetParameter(index++).Value = job.Status.ToString();
cmd.GetParameter(index++).Value = job.Progress;