public CuratedPackage Execute(
            int curatedFeedKey,
            int packageRegistrationKey,
            bool included = true,
            bool automaticallyCurated = false,
            string notes = null)
        {
            var curatedFeed = GetService<ICuratedFeedByKeyQuery>().Execute(curatedFeedKey);
            if (curatedFeed == null)
            {
                throw new InvalidOperationException("The curated feed does not exist.");
            }

            var packageRegistration = GetService<IPackageRegistrationByKeyQuery>().Execute(packageRegistrationKey);
            if (packageRegistration == null)
            {
                throw new InvalidOperationException("The package ID to curate does not exist.");
            }

            var curatedPackage = new CuratedPackage
                {
                    PackageRegistrationKey = packageRegistration.Key,
                    Included = included,
                    AutomaticallyCurated = automaticallyCurated,
                    Notes = notes,
                };

            curatedFeed.Packages.Add(curatedPackage);

            Entities.SaveChanges();

            return curatedPackage;
        }
        public CuratedPackage Execute(
            int curatedFeedKey,
            int packageRegistrationKey,
            bool included             = true,
            bool automaticallyCurated = false,
            string notes = null)
        {
            var curatedFeed = GetService <ICuratedFeedByKeyQuery>().Execute(curatedFeedKey);

            if (curatedFeed == null)
            {
                throw new InvalidOperationException("The curated feed does not exist.");
            }

            var packageRegistration = GetService <IPackageRegistrationByKeyQuery>().Execute(packageRegistrationKey);

            if (packageRegistration == null)
            {
                throw new InvalidOperationException("The package ID to curate does not exist.");
            }

            var curatedPackage = new CuratedPackage
            {
                PackageRegistrationKey = packageRegistration.Key,
                Included             = included,
                AutomaticallyCurated = automaticallyCurated,
                Notes = notes,
            };

            curatedFeed.Packages.Add(curatedPackage);

            Entities.SaveChanges();

            return(curatedPackage);
        }
Esempio n. 3
0
        public CuratedPackage Execute(
            CuratedFeed curatedFeed,
            PackageRegistration packageRegistration,
            bool included             = false,
            bool automaticallyCurated = false,
            string notes       = null,
            bool commitChanges = true)
        {
            if (curatedFeed == null)
            {
                throw new ArgumentNullException("curatedFeed");
            }

            if (packageRegistration == null)
            {
                throw new ArgumentNullException("packageRegistration");
            }

            var curatedPackage = new CuratedPackage
            {
                PackageRegistrationKey = packageRegistration.Key,
                Included             = included,
                AutomaticallyCurated = automaticallyCurated,
                Notes = notes,
            };

            curatedFeed.Packages.Add(curatedPackage);

            if (commitChanges)
            {
                Entities.SaveChanges();
            }

            return(curatedPackage);
        }
        public CuratedPackage Execute(
            CuratedFeed curatedFeed, 
            PackageRegistration packageRegistration, 
            bool included = false, 
            bool automaticallyCurated = false,
            string notes = null,
            bool commitChanges = true)
        {
            if (curatedFeed == null)
            {
                throw new ArgumentNullException("curatedFeed");
            }

            if (packageRegistration == null)
            {
                throw new ArgumentNullException("packageRegistration");
            }

            var curatedPackage = new CuratedPackage
            {
                PackageRegistrationKey = packageRegistration.Key,
                Included = included,
                AutomaticallyCurated = automaticallyCurated,
                Notes = notes,
            };

            curatedFeed.Packages.Add(curatedPackage);

            if (commitChanges)
            {
                Entities.SaveChanges();
            }

            return curatedPackage;
        }
        public CuratedPackage CreatedCuratedPackage(
            CuratedFeed curatedFeed,
            PackageRegistration packageRegistration,
            bool included             = false,
            bool automaticallyCurated = false,
            string notes       = null,
            bool commitChanges = true)
        {
            if (curatedFeed == null)
            {
                throw new ArgumentNullException(nameof(curatedFeed));
            }

            if (packageRegistration == null)
            {
                throw new ArgumentNullException(nameof(packageRegistration));
            }

            var curatedPackage = curatedFeed.Packages
                                 .SingleOrDefault(cp => cp.PackageRegistrationKey == packageRegistration.Key);

            if (curatedPackage == null)
            {
                curatedPackage = new CuratedPackage
                {
                    PackageRegistration  = packageRegistration,
                    Included             = included,
                    AutomaticallyCurated = automaticallyCurated,
                    Notes = notes,
                };

                curatedFeed.Packages.Add(curatedPackage);
            }

            if (commitChanges)
            {
                CuratedFeedRepository.CommitChanges();
            }

            return(curatedPackage);
        }
        public CuratedPackage CreatedCuratedPackage(
            CuratedFeed curatedFeed,
            PackageRegistration packageRegistration,
            bool included = false,
            bool automaticallyCurated = false,
            string notes = null,
            bool commitChanges = true)
        {
            if (curatedFeed == null)
            {
                throw new ArgumentNullException("curatedFeed");
            }

            if (packageRegistration == null)
            {
                throw new ArgumentNullException("packageRegistration");
            }

            var curatedPackage = curatedFeed.Packages
                .SingleOrDefault(cp => cp.PackageRegistrationKey == packageRegistration.Key);

            if (curatedPackage == null)
            {
                curatedPackage = new CuratedPackage
                {
                    PackageRegistration = packageRegistration,
                    Included = included,
                    AutomaticallyCurated = automaticallyCurated,
                    Notes = notes,
                };

                curatedFeed.Packages.Add(curatedPackage);
            }

            if (commitChanges)
            {
                CuratedFeedRepository.CommitChanges();
            }

            return curatedPackage;
        }
        public CuratedPackage CreatedCuratedPackage(
            CuratedFeed curatedFeed,
            Package package,
            bool included = false,
            bool automaticallyCurated = false,
            string notes = null,
            bool commitChanges = true)
        {
            if (curatedFeed == null)
            {
                throw new ArgumentNullException("curatedFeed");
            }

            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            var curatedPackageRegistration = curatedFeed.Packages
                .SingleOrDefault(cp => cp.PackageRegistrationKey == package.PackageRegistration.Key);

            var isFirstPackageInRegistration = false;
            if (curatedPackageRegistration == null)
            {
                curatedPackageRegistration = new CuratedPackage
                {
                    PackageRegistration = package.PackageRegistration,
                    PackageRegistrationKey = package.PackageRegistrationKey,
                    Included = included,
                    AutomaticallyCurated = automaticallyCurated,
                    Notes = notes,
                };

                curatedFeed.Packages.Add(curatedPackageRegistration);
                isFirstPackageInRegistration = true;
            }

            if (!curatedPackageRegistration.CuratedPackageVersions.Any(p => p.PackageKey == package.Key))
            {
                var curatedPackageVersion = new CuratedPackageVersion
                {
                    CuratedFeed = curatedFeed,
                    CuratedFeedKey = curatedFeed.Key,
                    PackageRegistration = package.PackageRegistration,
                    PackageRegistrationKey = package.PackageRegistrationKey,
                    Package = package,
                    PackageKey = package.Key,
                };

                // Make sure we set IsLatest + IsLatestStable for the first package, because
                // UpdateIsLatest won't be able to see this registration if we don't commit.
                // If it's the first package in the registration, then it's definitely the
                // latest. It's the latest stable package only if it's not a pre-release.
                if (isFirstPackageInRegistration)
                {
                    curatedPackageVersion.IsLatest = true;
                    curatedPackageVersion.IsLatestStable = !package.IsPrerelease;
                }

                curatedPackageRegistration.CuratedPackageVersions.Add(curatedPackageVersion);
            }

            if (commitChanges)
            {
                CuratedFeedRepository.CommitChanges();
            }

            return curatedPackageRegistration;
        }
        public CuratedPackage CreatedCuratedPackage(
            CuratedFeed curatedFeed,
            Package package,
            bool included             = false,
            bool automaticallyCurated = false,
            string notes       = null,
            bool commitChanges = true)
        {
            if (curatedFeed == null)
            {
                throw new ArgumentNullException("curatedFeed");
            }

            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            var curatedPackageRegistration = curatedFeed.Packages
                                             .SingleOrDefault(cp => cp.PackageRegistrationKey == package.PackageRegistration.Key);

            var isFirstPackageInRegistration = false;

            if (curatedPackageRegistration == null)
            {
                curatedPackageRegistration = new CuratedPackage
                {
                    PackageRegistration    = package.PackageRegistration,
                    PackageRegistrationKey = package.PackageRegistrationKey,
                    Included             = included,
                    AutomaticallyCurated = automaticallyCurated,
                    Notes = notes,
                };

                curatedFeed.Packages.Add(curatedPackageRegistration);
                isFirstPackageInRegistration = true;
            }

            if (!curatedPackageRegistration.CuratedPackageVersions.Any(p => p.PackageKey == package.Key))
            {
                var curatedPackageVersion = new CuratedPackageVersion
                {
                    CuratedFeed            = curatedFeed,
                    CuratedFeedKey         = curatedFeed.Key,
                    PackageRegistration    = package.PackageRegistration,
                    PackageRegistrationKey = package.PackageRegistrationKey,
                    Package    = package,
                    PackageKey = package.Key,
                };

                // Make sure we set IsLatest + IsLatestStable for the first package, because
                // UpdateIsLatest won't be able to see this registration if we don't commit.
                // If it's the first package in the registration, then it's definitely the
                // latest. It's the latest stable package only if it's not a pre-release.
                if (isFirstPackageInRegistration)
                {
                    curatedPackageVersion.IsLatest       = true;
                    curatedPackageVersion.IsLatestStable = !package.IsPrerelease;
                }

                curatedPackageRegistration.CuratedPackageVersions.Add(curatedPackageVersion);
            }

            if (commitChanges)
            {
                CuratedFeedRepository.CommitChanges();
            }

            return(curatedPackageRegistration);
        }