Пример #1
0
        private async Task <PackageInfo> GetBestMatchPackageVersionsAsync(string registry, bool includePrerelease, string packageId, SemVer.Range range)
        {
            PackageOption option = new PackageOption
            {
                packageId         = packageId,
                includePrerelease = includePrerelease,
                registry          = registry
            };

            Console.WriteLine($"Try to find best match: {packageId}: {range.ToString()}");

            IEnumerable <string> versionValues = await GetPackageVersionAsync(option.packageId, option.registry, option.includePrerelease);

            IEnumerable <SemVer.Version> versions = versionValues?.Select(x => new SemVer.Version(x, true));

            if (versions == null)
            {
                return(null);
            }

            SemVer.Version bestMatchVersion = range.MaxSatisfying(versions);

            if (bestMatchVersion == null)
            {
                bestMatchVersion = versions.OrderByDescending(x => x).FirstOrDefault();
            }

            return(new PackageInfo {
                packageId = packageId, packageVersion = bestMatchVersion
            });
        }
Пример #2
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            PackageOption packageOption = Db.PackageOptions.Find(id);

            Db.PackageOptions.Remove(packageOption);
            Db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #3
0
 public ActionResult Edit([Bind(Include = "Id,Name")] PackageOption packageOption)
 {
     if (ModelState.IsValid)
     {
         Db.Entry(packageOption).State = EntityState.Modified;
         Db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(packageOption));
 }
Пример #4
0
        private async Task <PackageInfo> GetPackageInfoByStringAsync(string packageId, string packageVersionValue,
                                                                     bool preReleased, string repository)
        {
            PackageInfo package = null;

            // if packageVersionValue is null, get the newest version
            if (packageVersionValue == null || packageVersionValue == "")
            {
                PackageOption option = new PackageOption()
                {
                    packageId         = packageId,
                    includePrerelease = preReleased,
                    registry          = repository
                };
                IEnumerable <string> versionList = await GetPackageVersionAsync(option.packageId, option.registry, option.includePrerelease);

                if (versionList != null)
                {
                    packageVersionValue = versionList.ElementAt(0);
                }
                else
                {
                    return(null);
                }
            }
            SemVer.Version packageVersion = null;
            SemVer.Range   range          = null;
            if (SemVer.Version.TryParse(packageVersionValue, out packageVersion) == true)
            {
                // version
                Console.WriteLine($"Convet to version: {packageId}: {packageVersionValue}");
                package = new PackageInfo {
                    packageId = packageId, packageVersion = packageVersion
                };
            }
            else if (SemVer.Range.TryParse(packageVersionValue, out range))
            {
                // range
                Console.WriteLine($"Convet to range: {packageId}: {packageVersionValue}");
                package = await GetBestMatchPackageVersionsAsync(repository, preReleased, packageId, range);

                Console.WriteLine($"Find best match: {packageId}: {package?.packageVersion?.ToString()}");
            }
            else
            {
                // range of *
                Console.WriteLine($"Convet to range: {packageId}: {packageVersionValue}");
                range   = new SemVer.Range("*");
                package = await GetBestMatchPackageVersionsAsync(repository, preReleased, packageId, range);

                Console.WriteLine($"Find best match: {packageId}: {package?.packageVersion?.ToString()}");
            }
            return(package);
        }
Пример #5
0
        public ActionResult Create([Bind(Include = "Id,Name")] PackageOption packageOption)
        {
            if (ModelState.IsValid)
            {
                packageOption.Id = Guid.NewGuid();
                Db.PackageOptions.Add(packageOption);
                Db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(packageOption));
        }
        public bool RemoveFundPackage(PackageOption fundPckOpt)
        {
            PackageFund fundPckg = db.PackageFunds.Find(fundPckOpt);

            if (fundPckg != null)
            {
                db.PackageFunds.Remove(fundPckg);
                db.SaveChanges();
                return(true);
            }

            return(false);
        }
Пример #7
0
        // GET: PackageOption/Delete/5
        public ActionResult Delete(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PackageOption packageOption = Db.PackageOptions.Find(id);

            if (packageOption == null)
            {
                return(HttpNotFound());
            }
            return(View(packageOption));
        }
        public Package AddPackage(PackageOption PckOption)
        {
            Package package = new Package
            {
                Amount      = PckOption.Amount,
                Reward      = PckOption.Reward,
                Description = PckOption.Description,
                Project     = db.Projects.Find(PckOption.ProjectId)
            };

            db.Packages.Add(package);
            db.SaveChanges();
            return(package);
        }
Пример #9
0
        private void PopulateShipmentPriceDictionary()
        {
            var packageOptionLpS = new PackageOption
            {
                Provider = PackageProvider.LP,
                Size     = PackageSize.S
            };

            ShipmentPriceDictionary.Add(packageOptionLpS, 1.50M);

            var packageOptionLpM = new PackageOption
            {
                Provider = PackageProvider.LP,
                Size     = PackageSize.M
            };

            ShipmentPriceDictionary.Add(packageOptionLpM, 4.90M);

            var packageOptionLpL = new PackageOption
            {
                Provider = PackageProvider.LP,
                Size     = PackageSize.L
            };

            ShipmentPriceDictionary.Add(packageOptionLpL, 6.90M);

            var packageOptionMrS = new PackageOption
            {
                Provider = PackageProvider.MR,
                Size     = PackageSize.S
            };

            ShipmentPriceDictionary.Add(packageOptionMrS, 2M);

            var packageOptionMrM = new PackageOption
            {
                Provider = PackageProvider.MR,
                Size     = PackageSize.M
            };

            ShipmentPriceDictionary.Add(packageOptionMrM, 3M);

            var packageOptionMrL = new PackageOption
            {
                Provider = PackageProvider.MR,
                Size     = PackageSize.L
            };

            ShipmentPriceDictionary.Add(packageOptionMrL, 4M);
        }
Пример #10
0
        public Package CreatePackage(PackageOption packOption)
        {
            Project project = db.Projects.Find(packOption.ProjectId);

            Package package = new Package
            {
                Amount      = packOption.Amount,
                Reward      = packOption.Reward,
                Description = packOption.Description,
                Project     = project
            };

            db.Packages.Add(package);
            db.SaveChanges();

            return(package);
        }
Пример #11
0
        private CurriculumRequirement GetModule(TimeTableDbContext db, TimeTable.Data.Curriculum curriculum, CieCourse scheduleCourse)
        {
            var pck = curriculum.Packages.FirstOrDefault();

            if (curriculum.ShortName.Equals("WI") && pck != null)
            {
                pck = curriculum.Packages.SingleOrDefault(x => x.Name.Equals("Wahlpflicht"));
            }

            if (pck == null)
            {
                pck      = new CurriculumPackage();
                pck.Name = "Studium";
                curriculum.Packages.Add(pck);
                db.CurriculumPackages.Add(pck);
            }

            var option = pck.Options.FirstOrDefault();

            if (option == null)
            {
                option         = new PackageOption();
                option.Name    = "Gesamt";
                option.Package = pck;
                db.PackageOptions.Add(option);
            }

            var module =
                option.Requirements.FirstOrDefault(x => x.Name.ToLower().Equals(scheduleCourse.name.ToLower()));

            if (module == null)
            {
                module           = new CurriculumRequirement();
                module.Name      = scheduleCourse.name;
                module.ECTS      = scheduleCourse.ects;
                module.USCredits = scheduleCourse.usCredits;
                module.SWS       = scheduleCourse.semesterWeekHours;

                option.Requirements.Add(module);
            }

            db.SaveChanges();

            return(module);
        }
Пример #12
0
        /// <summary>
        /// Iterates through the dependencies provided in the lock file and matches
        /// against items found in the directories listed in the configuration file.
        /// For each matched item, the passed delegate is executed.
        /// </summary>
        ///
        /// <exception cref="SwitcherFileNotFoundException"/>
        ///
        /// <exception cref="FileNotFoundException"/>
        ///
        /// <exception cref="ArgumentException">
        protected virtual void IterateAndExecute(IEnumerable <ProjectReference> references, Action <ProjectReference, LockFileTargetLibrary, string> func)
        {
            MessageHelper.Clear();

            ReadOnlyDictionary <string, string> items = PackageOption.GetIncludeItems(Type);

            foreach (ProjectReference reference in references)
            {
                foreach (LockFileTargetLibrary library in PackageHelper.GetProjectTarget(reference).Libraries)
                {
                    if (items.TryGetValue(library.Name, out string absolutePath))
                    {
                        func(reference, library, absolutePath);
                    }
                }

                reference.Save();
            }
        }
Пример #13
0
        private decimal GetShipmentPrice(Transaction transaction)
        {
            var shipmentPrice = new decimal();

            var packageOption = new PackageOption
            {
                Size     = transaction.Package.Size,
                Provider = transaction.Package.Provider
            };

            if (ShipmentPriceDictionary.ContainsKey(packageOption))
            {
                shipmentPrice = ShipmentPriceDictionary[packageOption];
            }
            else
            {
                var message = string.Format("Shipment price dictionary does not contain key {0}", packageOption);
                throw new KeyNotFoundException(message);
            }

            return(shipmentPrice);
        }
Пример #14
0
        public ActionResult CreateFromCourse(ModuleCreateViewModel model)
        {
            var course = Db.Activities.OfType <Course>().SingleOrDefault(x => x.Id == model.Course.Id);
            var curr   = Db.Curricula.SingleOrDefault(x => x.Id == model.Curriculum.Id);

            var pck = curr.Packages.SingleOrDefault(x => x.Name.Equals("Gesamt"));

            if (pck == null)
            {
                pck = new CurriculumPackage
                {
                    Curriculum = curr,
                    Name       = "Gesamt",
                };

                Db.CurriculumPackages.Add(pck);
                Db.SaveChanges();
            }

            var option = pck.Options.SingleOrDefault(x => x.Name.Equals("Standard"));

            if (option == null)
            {
                option = new PackageOption
                {
                    Package = pck,
                    Name    = "Standard"
                };

                Db.PackageOptions.Add(option);
                Db.SaveChanges();
            }


            // Doppelte ausschließen
            var isExisting = option.Requirements.Any(x =>
                                                     x.Name.Equals(model.Name) || x.ShortName.Equals(model.ShortName) ||
                                                     x.CatalogId.Equals(model.CatalogId));

            if (isExisting)
            {
                ModelState.AddModelError("", "Modul existiert bereits");

                // Modell wieder vervollständigen
                model.Course     = course;
                model.Curriculum = curr;
                model.MV         = GetMyMembership();

                return(View(model));
            }


            var module = new CurriculumRequirement
            {
                Name             = model.Name,
                ShortName        = model.ShortName,
                CatalogId        = model.CatalogId,
                ECTS             = model.Ects,
                SWS              = model.Sws,
                USCredits        = model.UsCredits,
                LecturerInCharge = GetMyMembership(),
                Option           = option,
            };

            Db.Requirements.Add(module);

            var nexus = new CourseModuleNexus
            {
                Course      = course,
                Requirement = module
            };

            Db.CourseNexus.Add(nexus);

            Db.SaveChanges();


            return(RedirectToAction("Admin", "Course", new { id = course.Id }));
        }
Пример #15
0
        public int AddPackage([FromBody] PackageOption pckgOption)
        {
            Package package = packageMngr.AddPackage(pckgOption);

            return(package.Id);
        }