This commit is contained in:
tidusjar 2016-08-25 22:53:05 +01:00
commit 7db336e202
19 changed files with 229 additions and 89 deletions

View file

@ -24,6 +24,9 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using Newtonsoft.Json;
namespace PlexRequests.Core.SettingModels
{
public sealed class PlexSettings : ExternalSettings
@ -36,5 +39,6 @@ namespace PlexRequests.Core.SettingModels
public bool EnableTvEpisodeSearching { get; set; }
public string PlexAuthToken { get; set; }
public string MachineIdentifier { get; set; }
}
}

View file

@ -26,6 +26,7 @@
#endregion
using System;
using System.Linq;
using System.Text.RegularExpressions;
using Mono.Data.Sqlite;
@ -66,6 +67,11 @@ namespace PlexRequests.Core
{
MigrateToVersion1900();
}
if(version > 1899 && version <= 1910)
{
MigrateToVersion1910();
}
}
return Db.DbConnection().ConnectionString;
@ -244,5 +250,30 @@ namespace PlexRequests.Core
Log.Error(e);
}
}
/// <summary>
/// Migrates to version1910.
/// </summary>
public void MigrateToVersion1910()
{
try
{
// Get the new machine Identifier
var settings = new SettingsServiceV2<PlexSettings>(new SettingsJsonRepository(Db, new MemoryCacheProvider()));
var plex = settings.GetSettings();
if (!string.IsNullOrEmpty(plex.PlexAuthToken))
{
var api = new PlexApi(new ApiRequest());
var server = api.GetServer(plex.PlexAuthToken); // Get the server info
plex.MachineIdentifier = server.Server.FirstOrDefault(x => x.AccessToken == plex.PlexAuthToken)?.MachineIdentifier;
settings.SaveSettings(plex); // Save the new settings
}
}
catch (Exception e)
{
Log.Error(e);
}
}
}
}