Beispiel #1
0
        private void CreateDefaultSettingsPage(string baseUrl)
        {
            var defaultSettings = new PlexRequestSettings
            {
                RequireTvShowApproval = true,
                RequireMovieApproval  = true,
                SearchForMovies       = true,
                SearchForTvShows      = true,
                BaseUrl             = baseUrl ?? string.Empty,
                CollectAnalyticData = true,
            };
            var s = new SettingsServiceV2 <PlexRequestSettings>(new SettingsJsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider()));

            s.SaveSettings(defaultSettings);


            var cron      = (Quartz.Impl.Triggers.CronTriggerImpl)CronScheduleBuilder.WeeklyOnDayAndHourAndMinute(DayOfWeek.Friday, 7, 0).Build();
            var scheduled = new ScheduledJobsSettings
            {
                PlexAvailabilityChecker  = 60,
                SickRageCacher           = 60,
                SonarrCacher             = 60,
                CouchPotatoCacher        = 60,
                StoreBackup              = 24,
                StoreCleanup             = 24,
                UserRequestLimitResetter = 12,
                PlexEpisodeCacher        = 12,
                RecentlyAddedCron        = cron.CronExpressionString, // Weekly CRON at 7 am on Mondays
            };

            var scheduledSettings = new SettingsServiceV2 <ScheduledJobsSettings>(new SettingsJsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider()));

            scheduledSettings.SaveSettings(scheduled);
        }
Beispiel #2
0
        private void CreateDefaultSettingsPage(string baseUrl)
        {
            var defaultSettings = new PlexRequestSettings
            {
                RequireTvShowApproval = true,
                RequireMovieApproval  = true,
                SearchForMovies       = true,
                SearchForTvShows      = true,
                BaseUrl             = baseUrl ?? string.Empty,
                CollectAnalyticData = true,
            };
            var s = new SettingsServiceV2 <PlexRequestSettings>(new SettingsJsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider()));

            s.SaveSettings(defaultSettings);
        }
Beispiel #3
0
        /// <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);
            }
        }
Beispiel #4
0
 private void CacheCouchPotatoQualityProfiles(MemoryCacheProvider cacheProvider)
 {
     try
     {
         Log.Info("Executing GetSettings call to CouchPotato for quality profiles");
         var cpSettingsService = new SettingsServiceV2 <CouchPotatoSettings>(new SettingsJsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider()));
         var cpSettings        = cpSettingsService.GetSettings();
         if (cpSettings.Enabled)
         {
             Log.Info("Begin executing GetProfiles call to CouchPotato for quality profiles");
             CouchPotatoApi cpApi    = new CouchPotatoApi();
             var            profiles = cpApi.GetProfiles(cpSettings.FullUri, cpSettings.ApiKey);
             cacheProvider.Set(CacheKeys.CouchPotatoQualityProfiles, profiles);
             Log.Info("Finished executing GetProfiles call to CouchPotato for quality profiles");
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex, "Failed to cache CouchPotato quality profiles!");
     }
 }
Beispiel #5
0
 private void CacheSonarrQualityProfiles(MemoryCacheProvider cacheProvider)
 {
     try
     {
         Log.Info("Executing GetSettings call to Sonarr for quality profiles");
         var sonarrSettingsService = new SettingsServiceV2 <SonarrSettings>(new SettingsJsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider()));
         var sonarrSettings        = sonarrSettingsService.GetSettings();
         if (sonarrSettings.Enabled)
         {
             Log.Info("Begin executing GetProfiles call to Sonarr for quality profiles");
             SonarrApi sonarrApi = new SonarrApi();
             var       profiles  = sonarrApi.GetProfiles(sonarrSettings.ApiKey, sonarrSettings.FullUri);
             cacheProvider.Set(CacheKeys.SonarrQualityProfiles, profiles);
             Log.Info("Finished executing GetProfiles call to Sonarr for quality profiles");
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex, "Failed to cache Sonarr quality profiles!");
     }
 }
Beispiel #6
0
        /// <summary>
        /// Migrates to version 1.8.
        /// <para>This includes updating the admin account to have all roles.</para>
        /// <para>Set the log level to info</para>
        /// </summary>
        private void MigrateToVersion1800()
        {
            try
            {
                var userMapper = new UserMapper(new UserRepository <UsersModel>(Db, new MemoryCacheProvider()));
                var users      = userMapper.GetUsers();

                foreach (var u in users)
                {
                    var claims = new[] { UserClaims.User, UserClaims.Admin, UserClaims.PowerUser };
                    u.Claims = ByteConverterHelper.ReturnBytes(claims);

                    userMapper.EditUser(u);
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw;
            }

            try
            {
                var settingsService = new SettingsServiceV2 <LogSettings>(new SettingsJsonRepository(Db, new MemoryCacheProvider()));
                var logSettings     = settingsService.GetSettings();
                logSettings.Level = LogLevel.Info.Ordinal;
                settingsService.SaveSettings(logSettings);

                LoggingHelper.ReconfigureLogLevel(LogLevel.FromOrdinal(logSettings.Level));
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Migrates to version 1.9.
        /// Move the Plex auth token to the new field.
        /// Reconfigure the log level
        /// Set the wizard flag to true if we already have settings
        /// </summary>
        public void MigrateToVersion1900()
        {
            // Need to change the Plex Token location
            var authSettings = new SettingsServiceV2 <AuthenticationSettings>(new SettingsJsonRepository(Db, new MemoryCacheProvider()));
            var auth         = authSettings.GetSettings();
            var plexSettings = new SettingsServiceV2 <PlexSettings>(new SettingsJsonRepository(Db, new MemoryCacheProvider()));

            if (auth != null)
            {
                //If we have an authToken we do not need to go through the setup
                if (!string.IsNullOrEmpty(auth.OldPlexAuthToken))
                {
                    var prServuce = new SettingsServiceV2 <PlexRequestSettings>(new SettingsJsonRepository(Db, new MemoryCacheProvider()));
                    var settings  = prServuce.GetSettings();
                    settings.Wizard = true;
                    prServuce.SaveSettings(settings);
                }

                // Clear out the old token and save it to the new field
                var currentSettings = plexSettings.GetSettings();
                if (!string.IsNullOrEmpty(auth.OldPlexAuthToken))
                {
                    currentSettings.PlexAuthToken = auth.OldPlexAuthToken;
                    plexSettings.SaveSettings(currentSettings);

                    // Clear out the old value
                    auth.OldPlexAuthToken = string.Empty;
                    authSettings.SaveSettings(auth);
                }
            }


            // Set the log level
            try
            {
                var settingsService = new SettingsServiceV2 <LogSettings>(new SettingsJsonRepository(Db, new MemoryCacheProvider()));
                var logSettings     = settingsService.GetSettings();
                logSettings.Level = LogLevel.Error.Ordinal;
                settingsService.SaveSettings(logSettings);

                LoggingHelper.ReconfigureLogLevel(LogLevel.FromOrdinal(logSettings.Level));
            }
            catch (Exception e)
            {
                Log.Error(e);
            }


            // Enable analytics;
            try
            {
                var prSettings = new SettingsServiceV2 <PlexRequestSettings>(new SettingsJsonRepository(Db, new MemoryCacheProvider()));
                var settings   = prSettings.GetSettings();
                settings.CollectAnalyticData = true;
                var updated = prSettings.SaveSettings(settings);
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }