Ejemplo n.º 1
0
 private async Task UpdateExistingProfile(SonarrReleaseProfile profileToUpdate, FilteredProfileData profile,
                                          List <int> tagIds)
 {
     Log.Debug("Update existing profile with id {ProfileId}", profileToUpdate.Id);
     SetupProfileRequestObject(profileToUpdate, profile, tagIds);
     await _api.UpdateReleaseProfile(profileToUpdate);
 }
Ejemplo n.º 2
0
    public void Filter_ExcludeOptional_HasNoOptionalItems()
    {
        var config = new ReleaseProfileConfig();

        config.Filter.IncludeOptional = false;

        var profileData = new ProfileData
        {
            Ignored = new List <string> {
                "ignored1"
            },
            Required = new List <string> {
                "required1"
            },
            Preferred = new Dictionary <int, List <string> >
            {
                { 100, new List <string> {
                      "preferred1"
                  } }
            },
            Optional = new ProfileDataOptional
            {
                Ignored = new List <string> {
                    "ignored2"
                },
                Required = new List <string> {
                    "required2"
                },
                Preferred = new Dictionary <int, List <string> >
                {
                    { 200, new List <string> {
                          "preferred2"
                      } },
                    { 100, new List <string> {
                          "preferred3"
                      } }
                }
            }
        };

        var filtered = new FilteredProfileData(profileData, config);

        filtered.Should().BeEquivalentTo(new
        {
            Ignored = new List <string> {
                "ignored1"
            },
            Required = new List <string> {
                "required1"
            },
            Preferred = new Dictionary <int, List <string> >
            {
                { 100, new List <string> {
                      "preferred1"
                  } }
            }
        });
    }
Ejemplo n.º 3
0
    private async Task CreateNewProfile(string title, FilteredProfileData profile, List <int> tagIds)
    {
        var newProfile = new SonarrReleaseProfile
        {
            Name    = title,
            Enabled = true
        };

        SetupProfileRequestObject(newProfile, profile, tagIds);
        await _api.CreateReleaseProfile(newProfile);
    }
Ejemplo n.º 4
0
    private async Task ProcessReleaseProfiles(IDictionary <string, ProfileData> profiles,
                                              ReleaseProfileConfig config)
    {
        await DoVersionEnforcement();

        List <int> tagIds = new();

        // If tags were provided, ensure they exist. Tags that do not exist are added first, so that we
        // may specify them with the release profile request payload.
        if (config.Tags.Count > 0)
        {
            var sonarrTags = await _api.GetTags();
            await CreateMissingTags(sonarrTags, config.Tags);

            tagIds = sonarrTags.Where(t => config.Tags.Any(ct => ct.EqualsIgnoreCase(t.Label)))
                     .Select(t => t.Id)
                     .ToList();
        }

        // Obtain all of the existing release profiles first. If any were previously created by our program
        // here, we favor replacing those instead of creating new ones, which would just be mostly duplicates
        // (but with some differences, since there have likely been updates since the last run).
        var existingProfiles = await _api.GetReleaseProfiles();

        foreach (var(name, profileData) in profiles)
        {
            var filteredProfileData = new FilteredProfileData(profileData, config);
            var title           = BuildProfileTitle(config.Type, name);
            var profileToUpdate = GetProfileToUpdate(existingProfiles, title);
            if (profileToUpdate != null)
            {
                Log.Information("Update existing profile: {ProfileName}", title);
                await UpdateExistingProfile(profileToUpdate, filteredProfileData, tagIds);
            }
            else
            {
                Log.Information("Create new profile: {ProfileName}", title);
                await CreateNewProfile(title, filteredProfileData, tagIds);
            }
        }
    }
Ejemplo n.º 5
0
    private static void SetupProfileRequestObject(SonarrReleaseProfile profileToUpdate, FilteredProfileData profile,
                                                  List <int> tagIds)
    {
        profileToUpdate.Preferred = profile.Preferred
                                    .SelectMany(kvp => kvp.Value.Select(term => new SonarrPreferredTerm(kvp.Key, term)))
                                    .ToList();

        profileToUpdate.Ignored  = profile.Ignored.ToList();  //string.Join(',', profile.Ignored);
        profileToUpdate.Required = profile.Required.ToList(); //string.Join(',', profile.Required);

        // Null means the guide didn't specify a value for this, so we leave the existing setting intact.
        if (profile.IncludePreferredWhenRenaming != null)
        {
            profileToUpdate.IncludePreferredWhenRenaming = profile.IncludePreferredWhenRenaming.Value;
        }

        profileToUpdate.Tags = tagIds;
    }