Пример #1
0
        public async Task <IActionResult> PutOrderTb(int id, OrderTb orderTb)
        {
            if (id != orderTb.OrderId)
            {
                return(BadRequest());
            }

            _context.Entry(orderTb).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderTbExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task Execute(IJobExecutionContext job)
        {
            try
            {
                var settings = await _lidarrSettings.GetSettingsAsync();

                if (settings.Enabled)
                {
                    try
                    {
                        var artists = await _lidarrApi.GetArtists(settings.ApiKey, settings.FullUri);

                        if (artists != null && artists.Any())
                        {
                            // Let's remove the old cached data
                            using (var tran = await _ctx.Database.BeginTransactionAsync())
                            {
                                await _ctx.Database.ExecuteSqlCommandAsync("DELETE FROM LidarrArtistCache");

                                tran.Commit();
                            }

                            var artistCache = new List <LidarrArtistCache>();
                            foreach (var a in artists)
                            {
                                if (a.id > 0)
                                {
                                    artistCache.Add(new LidarrArtistCache
                                    {
                                        ArtistId        = a.id,
                                        ArtistName      = a.artistName,
                                        ForeignArtistId = a.foreignArtistId,
                                        Monitored       = a.monitored
                                    });
                                }
                            }

                            using (var tran = await _ctx.Database.BeginTransactionAsync())
                            {
                                await _ctx.LidarrArtistCache.AddRangeAsync(artistCache);

                                await _ctx.SaveChangesAsync();

                                tran.Commit();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(LoggingEvents.Cacher, ex, "Failed caching queued items from Lidarr");
                    }

                    await _albumSync.CacheContent();
                }
            }
            catch (Exception)
            {
                _logger.LogInformation(LoggingEvents.LidarrArtistCache, "Lidarr is not setup, cannot cache Artist");
            }
        }
Пример #3
0
        public async Task Execute(IJobExecutionContext job)
        {
            await SemaphoreSlim.WaitAsync();

            try
            {
                var settings = await RadarrSettings.GetSettingsAsync();

                if (settings.Enabled)
                {
                    try
                    {
                        var movies = await RadarrApi.GetMovies(settings.ApiKey, settings.FullUri);

                        if (movies != null)
                        {
                            var strat = _ctx.Database.CreateExecutionStrategy();
                            await strat.ExecuteAsync(async() =>
                            {
                                // Let's remove the old cached data
                                using (var tran = await _ctx.Database.BeginTransactionAsync())
                                {
                                    await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM RadarrCache");
                                    tran.Commit();
                                }
                            });

                            var movieIds = new List <RadarrCache>();
                            foreach (var m in movies)
                            {
                                if (m.monitored || m.hasFile)
                                {
                                    if (m.tmdbId > 0)
                                    {
                                        movieIds.Add(new RadarrCache
                                        {
                                            TheMovieDbId = m.tmdbId,
                                            HasFile      = m.hasFile
                                        });
                                    }
                                    else
                                    {
                                        Logger.LogError("TMDBId is not > 0 for movie {0}", m.title);
                                    }
                                }
                            }
                            strat = _ctx.Database.CreateExecutionStrategy();
                            await strat.ExecuteAsync(async() =>
                            {
                                using (var tran = await _ctx.Database.BeginTransactionAsync())
                                {
                                    await _ctx.RadarrCache.AddRangeAsync(movieIds);

                                    await _ctx.SaveChangesAsync();
                                    tran.Commit();
                                }
                            });
                        }

                        await OmbiQuartz.TriggerJob(nameof(IArrAvailabilityChecker), "DVR");
                    }
                    catch (System.Exception ex)
                    {
                        Logger.LogError(LoggingEvents.Cacher, ex, "Failed caching queued items from Radarr");
                    }
                }
            }
            catch (Exception)
            {
                Logger.LogInformation(LoggingEvents.RadarrCacher, "Radarr is not setup, cannot cache episodes");
            }
            finally
            {
                SemaphoreSlim.Release();
            }
        }
Пример #4
0
        public async Task Execute(IJobExecutionContext ctx)
        {
            try
            {
                var settings = await _lidarrSettings.GetSettingsAsync();

                if (settings.Enabled)
                {
                    await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
                    .SendAsync(NotificationHub.NotificationEvent, "Lidarr Album Sync Started");

                    try
                    {
                        var albums = await _lidarrApi.GetAllAlbums(settings.ApiKey, settings.FullUri);

                        if (albums != null && albums.Any())
                        {
                            var strat = _ctx.Database.CreateExecutionStrategy();
                            await strat.ExecuteAsync(async() =>
                            {
                                // Let's remove the old cached data
                                using (var tran = await _ctx.Database.BeginTransactionAsync())
                                {
                                    await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM LidarrAlbumCache");
                                    tran.Commit();
                                }
                            });

                            var albumCache = new List <LidarrAlbumCache>();
                            foreach (var a in albums)
                            {
                                if (a.id > 0)
                                {
                                    albumCache.Add(new LidarrAlbumCache
                                    {
                                        ArtistId        = a.artistId,
                                        ForeignAlbumId  = a.foreignAlbumId,
                                        ReleaseDate     = a.releaseDate,
                                        TrackCount      = a.currentRelease?.trackCount ?? 0,
                                        Monitored       = a.monitored,
                                        Title           = a.title,
                                        PercentOfTracks = a.statistics?.percentOfEpisodes ?? 0m,
                                        AddedAt         = DateTime.Now,
                                    });
                                }
                            }
                            strat = _ctx.Database.CreateExecutionStrategy();
                            await strat.ExecuteAsync(async() =>
                            {
                                using (var tran = await _ctx.Database.BeginTransactionAsync())
                                {
                                    await _ctx.LidarrAlbumCache.AddRangeAsync(albumCache);

                                    await _ctx.SaveChangesAsync();
                                    tran.Commit();
                                }
                            });
                        }
                    }
                    catch (System.Exception ex)
                    {
                        await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
                        .SendAsync(NotificationHub.NotificationEvent, "Lidarr Album Sync Failed");

                        _logger.LogError(LoggingEvents.Cacher, ex, "Failed caching queued items from Lidarr Album");
                    }

                    await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
                    .SendAsync(NotificationHub.NotificationEvent, "Lidarr Album Sync Finished");

                    await OmbiQuartz.TriggerJob(nameof(ILidarrAvailabilityChecker), "DVR");
                }
            }
            catch (Exception)
            {
                _logger.LogInformation(LoggingEvents.LidarrArtistCache, "Lidarr is not setup, cannot cache Album");
            }
        }
Пример #5
0
        public async Task Execute(IJobExecutionContext job)
        {
            var settings = await _settings.GetSettingsAsync();

            if (!settings.Enabled)
            {
                return;
            }

            try
            {
                _log.LogInformation(LoggingEvents.CouchPotatoCacher, "Getting all active movies from CP");
                var movies = await _api.GetMovies(settings.FullUri, settings.ApiKey, new[] { "active" });

                if (movies != null)
                {
                    // Let's remove the old cached data
                    using (var tran = await _ctx.Database.BeginTransactionAsync())
                    {
                        await _ctx.Database.ExecuteSqlCommandAsync("DELETE FROM CouchPotatoCache");

                        tran.Commit();
                    }

                    // Save
                    var movieIds = new List <CouchPotatoCache>();
                    foreach (var m in movies.movies)
                    {
                        if (m.info == null)
                        {
                            _log.LogInformation("Movie {0} does nto have a tmdbid", m.title);
                            continue;
                        }
                        if (m.info.tmdb_id > 0)
                        {
                            movieIds.Add(new CouchPotatoCache {
                                TheMovieDbId = m.info.tmdb_id
                            });
                        }
                        else
                        {
                            _log.LogError("TMDBId is not > 0 for movie {0}", m.title);
                        }
                    }

                    using (var tran = await _ctx.Database.BeginTransactionAsync())
                    {
                        await _ctx.CouchPotatoCache.AddRangeAsync(movieIds);

                        await _ctx.SaveChangesAsync();

                        tran.Commit();
                    }
                }
            }
            catch (Exception e)
            {
                _log.LogError(LoggingEvents.CouchPotatoCacher, e, "error when trying to get movies from CP");
                throw;
            }
        }
Пример #6
0
        public async Task CacheContent()
        {
            try
            {
                var settings = await _lidarrSettings.GetSettingsAsync();

                if (settings.Enabled)
                {
                    try
                    {
                        var albums = await _lidarrApi.GetAllAlbums(settings.ApiKey, settings.FullUri);

                        if (albums != null && albums.Any())
                        {
                            // Let's remove the old cached data
                            using (var tran = await _ctx.Database.BeginTransactionAsync())
                            {
                                await _ctx.Database.ExecuteSqlCommandAsync("DELETE FROM LidarrAlbumCache");

                                tran.Commit();
                            }

                            var albumCache = new List <LidarrAlbumCache>();
                            foreach (var a in albums)
                            {
                                if (a.id > 0)
                                {
                                    albumCache.Add(new LidarrAlbumCache
                                    {
                                        ArtistId        = a.artistId,
                                        ForeignAlbumId  = a.foreignAlbumId,
                                        ReleaseDate     = a.releaseDate,
                                        TrackCount      = a.currentRelease?.trackCount ?? 0,
                                        Monitored       = a.monitored,
                                        Title           = a.title,
                                        PercentOfTracks = a.statistics?.percentOfEpisodes ?? 0m,
                                        AddedAt         = DateTime.Now,
                                    });
                                }
                            }

                            using (var tran = await _ctx.Database.BeginTransactionAsync())
                            {
                                await _ctx.LidarrAlbumCache.AddRangeAsync(albumCache);

                                await _ctx.SaveChangesAsync();

                                tran.Commit();
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        _logger.LogError(LoggingEvents.Cacher, ex, "Failed caching queued items from Lidarr Album");
                    }

                    await _availability.Start();
                }
            }
            catch (Exception)
            {
                _logger.LogInformation(LoggingEvents.LidarrArtistCache, "Lidarr is not setup, cannot cache Album");
            }
        }
Пример #7
0
        public async Task Execute(IJobExecutionContext job)
        {
            try
            {
                var settings = await _settings.GetSettingsAsync();

                if (!settings.Enabled)
                {
                    return;
                }

                var shows = await _api.GetShows(settings.ApiKey, settings.FullUri);

                if (shows != null)
                {
                    var srShows = shows.data.Values;
                    var ids     = srShows.Select(x => x.tvdbid);
                    var strat   = _ctx.Database.CreateExecutionStrategy();
                    await strat.ExecuteAsync(async() =>
                    {
                        using (var tran = await _ctx.Database.BeginTransactionAsync())
                        {
                            await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SickRageCache");
                            tran.Commit();
                        }
                    });

                    var entites = ids.Select(id => new SickRageCache {
                        TvDbId = id
                    }).ToList();

                    await _ctx.SickRageCache.AddRangeAsync(entites);

                    var episodesToAdd = new List <SickRageEpisodeCache>();
                    await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SickRageEpisodeCache");

                    foreach (var s in srShows)
                    {
                        var seasons = await _api.GetSeasonList(s.tvdbid, settings.ApiKey, settings.FullUri);

                        foreach (var season in seasons.data)
                        {
                            var episodes =
                                await _api.GetEpisodesForSeason(s.tvdbid, season, settings.ApiKey, settings.FullUri);

                            var monitoredEpisodes = episodes.data.Where(x => x.Value.status.Equals(SickRageStatus.Wanted));

                            episodesToAdd.AddRange(monitoredEpisodes.Select(episode => new SickRageEpisodeCache
                            {
                                EpisodeNumber = episode.Key,
                                SeasonNumber  = season,
                                TvDbId        = s.tvdbid
                            }));
                        }
                    }
                    strat = _ctx.Database.CreateExecutionStrategy();
                    await strat.ExecuteAsync(async() =>
                    {
                        using (var tran = await _ctx.Database.BeginTransactionAsync())
                        {
                            await _ctx.SickRageEpisodeCache.AddRangeAsync(episodesToAdd);
                            await _ctx.SaveChangesAsync();
                            tran.Commit();
                        }
                    });
                }
            }
            catch (Exception e)
            {
                _log.LogError(LoggingEvents.SickRageCacher, e, "Exception when trying to cache SickRage");
            }
        }
Пример #8
0
        public async Task Execute(IJobExecutionContext job)
        {
            try
            {
                var settings = await _lidarrSettings.GetSettingsAsync();

                if (settings.Enabled)
                {
                    await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
                    .SendAsync(NotificationHub.NotificationEvent, "Lidarr Artist Sync Started");

                    try
                    {
                        var artists = await _lidarrApi.GetArtists(settings.ApiKey, settings.FullUri);

                        if (artists != null && artists.Any())
                        {
                            var strat = _ctx.Database.CreateExecutionStrategy();
                            await strat.ExecuteAsync(async() =>
                            {
                                // Let's remove the old cached data
                                using (var tran = await _ctx.Database.BeginTransactionAsync())
                                {
                                    await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM LidarrArtistCache");
                                    tran.Commit();
                                }
                            });

                            var artistCache = new List <LidarrArtistCache>();
                            foreach (var a in artists)
                            {
                                if (a.id > 0)
                                {
                                    artistCache.Add(new LidarrArtistCache
                                    {
                                        ArtistId        = a.id,
                                        ArtistName      = a.artistName,
                                        ForeignArtistId = a.foreignArtistId,
                                        Monitored       = a.monitored
                                    });
                                }
                            }
                            strat = _ctx.Database.CreateExecutionStrategy();
                            await strat.ExecuteAsync(async() =>
                            {
                                using (var tran = await _ctx.Database.BeginTransactionAsync())
                                {
                                    await _ctx.LidarrArtistCache.AddRangeAsync(artistCache);

                                    await _ctx.SaveChangesAsync();
                                    tran.Commit();
                                }
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
                        .SendAsync(NotificationHub.NotificationEvent, "Lidarr Artist Sync Failed");

                        _logger.LogError(LoggingEvents.Cacher, ex, "Failed caching queued items from Lidarr");
                    }

                    await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
                    .SendAsync(NotificationHub.NotificationEvent, "Lidarr Artist Sync Finished");

                    await OmbiQuartz.TriggerJob(nameof(ILidarrAlbumSync), "DVR");
                }
            }
            catch (Exception)
            {
                _logger.LogInformation(LoggingEvents.LidarrArtistCache, "Lidarr is not setup, cannot cache Artist");
            }
        }
Пример #9
0
        public async Task Execute(IJobExecutionContext job)
        {
            try
            {
                var settings = await _settings.GetSettingsAsync();

                if (!settings.Enabled)
                {
                    return;
                }
                var series = await _api.GetSeries(settings.ApiKey, settings.FullUri);

                if (series != null)
                {
                    var sonarrSeries = series as ImmutableHashSet <SonarrSeries> ?? series.ToImmutableHashSet();
                    var ids          = sonarrSeries.Select(x => x.tvdbId);
                    using (var tran = await _ctx.Database.BeginTransactionAsync())
                    {
                        await _ctx.Database.ExecuteSqlCommandAsync("DELETE FROM SonarrCache");

                        tran.Commit();
                    }

                    var entites = ids.Select(id => new SonarrCache {
                        TvDbId = id
                    }).ToImmutableHashSet();

                    await _ctx.SonarrCache.AddRangeAsync(entites);

                    entites.Clear();
                    using (var tran = await _ctx.Database.BeginTransactionAsync())
                    {
                        await _ctx.Database.ExecuteSqlCommandAsync("DELETE FROM SonarrEpisodeCache");

                        tran.Commit();
                    }

                    foreach (var s in sonarrSeries)
                    {
                        if (!s.monitored)
                        {
                            continue;
                        }
                        _log.LogDebug("Syncing series: {0}", s.title);
                        var episodes = await _api.GetEpisodes(s.id, settings.ApiKey, settings.FullUri);

                        var monitoredEpisodes = episodes.Where(x => x.monitored || x.hasFile);

                        // Add to DB
                        _log.LogDebug("We have the episodes, adding to db transaction");
                        using (var tran = await _ctx.Database.BeginTransactionAsync())
                        {
                            await _ctx.SonarrEpisodeCache.AddRangeAsync(monitoredEpisodes.Select(episode =>
                                                                                                 new SonarrEpisodeCache
                            {
                                EpisodeNumber = episode.episodeNumber,
                                SeasonNumber  = episode.seasonNumber,
                                TvDbId        = s.tvdbId,
                                HasFile       = episode.hasFile
                            }));

                            _log.LogDebug("Commiting the transaction");
                            await _ctx.SaveChangesAsync();

                            tran.Commit();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _log.LogError(LoggingEvents.SonarrCacher, e, "Exception when trying to cache Sonarr");
            }
        }
Пример #10
0
        public async Task Execute(IJobExecutionContext job)
        {
            try
            {
                var settings = await _settings.GetSettingsAsync();

                if (!settings.Enabled)
                {
                    return;
                }
                var series = await _api.GetSeries(settings.ApiKey, settings.FullUri);

                if (series != null)
                {
                    var sonarrSeries = series as ImmutableHashSet <SonarrSeries> ?? series.ToImmutableHashSet();
                    var ids          = sonarrSeries.Select(x => x.tvdbId);
                    var strat        = _ctx.Database.CreateExecutionStrategy();
                    await strat.ExecuteAsync(async() =>
                    {
                        using (var tran = await _ctx.Database.BeginTransactionAsync())
                        {
                            await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SonarrCache");
                            tran.Commit();
                        }
                    });

                    var existingSeries = await _ctx.SonarrCache.Select(x => x.TvDbId).ToListAsync();

                    //var entites = ids.Except(existingSeries).Select(id => new SonarrCache { TvDbId = id }).ToImmutableHashSet();
                    var entites = ids.Select(id => new SonarrCache {
                        TvDbId = id
                    }).ToImmutableHashSet();

                    await _ctx.SonarrCache.AddRangeAsync(entites);

                    entites.Clear();
                    strat = _ctx.Database.CreateExecutionStrategy();
                    await strat.ExecuteAsync(async() =>
                    {
                        using (var tran = await _ctx.Database.BeginTransactionAsync())
                        {
                            await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SonarrEpisodeCache");
                            tran.Commit();
                        }
                    });

                    foreach (var s in sonarrSeries)
                    {
                        if (!s.monitored || s.episodeFileCount == 0) // We have files
                        {
                            continue;
                        }

                        _log.LogDebug("Syncing series: {0}", s.title);
                        var episodes = await _api.GetEpisodes(s.id, settings.ApiKey, settings.FullUri);

                        var monitoredEpisodes = episodes.Where(x => x.monitored || x.hasFile);

                        //var allExistingEpisodes = await _ctx.SonarrEpisodeCache.Where(x => x.TvDbId == s.tvdbId).ToListAsync();
                        // Add to DB
                        _log.LogDebug("We have the episodes, adding to db transaction");
                        var episodesToAdd = monitoredEpisodes.Select(episode =>
                                                                     new SonarrEpisodeCache
                        {
                            EpisodeNumber = episode.episodeNumber,
                            SeasonNumber  = episode.seasonNumber,
                            TvDbId        = s.tvdbId,
                            HasFile       = episode.hasFile
                        });
                        //var episodesToAdd = new List<SonarrEpisodeCache>();

                        //foreach (var monitored in monitoredEpisodes)
                        //{
                        //    var existing = allExistingEpisodes.FirstOrDefault(x => x.SeasonNumber == monitored.seasonNumber && x.EpisodeNumber == monitored.episodeNumber);
                        //    if (existing == null)
                        //    {
                        //        // Just add a new one
                        //        episodesToAdd.Add(new SonarrEpisodeCache
                        //        {
                        //            EpisodeNumber = monitored.episodeNumber,
                        //            SeasonNumber = monitored.seasonNumber,
                        //            TvDbId = s.tvdbId,
                        //            HasFile = monitored.hasFile
                        //        });
                        //    }
                        //    else
                        //    {
                        //        // Do we need to update the availability?
                        //        if (monitored.hasFile != existing.HasFile)
                        //        {
                        //            existing.HasFile = monitored.hasFile;
                        //        }
                        //    }

                        //}
                        strat = _ctx.Database.CreateExecutionStrategy();
                        await strat.ExecuteAsync(async() =>
                        {
                            using (var tran = await _ctx.Database.BeginTransactionAsync())
                            {
                                await _ctx.SonarrEpisodeCache.AddRangeAsync(episodesToAdd);
                                _log.LogDebug("Commiting the transaction");
                                await _ctx.SaveChangesAsync();
                                tran.Commit();
                            }
                        });
                    }
                }

                await OmbiQuartz.TriggerJob(nameof(IArrAvailabilityChecker), "DVR");
            }
            catch (Exception e)
            {
                _log.LogError(LoggingEvents.SonarrCacher, e, "Exception when trying to cache Sonarr");
            }
        }