public ICollection <string> Search(int enviromentId, int applicationId) { var repos = db.DeploTasks .Where(x => x.EnviromentId == enviromentId && x.ApplicationId == applicationId) .Select(x => x.Repository) .Union(db.TemplatedTasks.Where(x => x.EnviromentId == enviromentId && x.ApplicationId == applicationId && x.Repository != null) .Select(x => x.Repository)) .ToList(); var package = db.DeploTasks .Where(x => x.EnviromentId == enviromentId && x.ApplicationId == applicationId) .Select(x => x.PackageName) .Union(db.TemplatedTasks.Where(x => x.EnviromentId == enviromentId && x.ApplicationId == applicationId && x.PackageName != null) .Select(x => x.PackageName)) .First(); return(PackageSearcher.Search(repos, package)); }
/// <summary> /// Clean a specific package removing all nmon necessary versions /// </summary> /// <param name="package">Package to remove</param> /// <param name="gallery">gallery to remove the package from</param> public static void CleanPackage(string package, string gallery) { using (var dc = new ReadContext()) { var allVersion = PackageSearcher.Search(new List <string> { gallery }, package).ToList().Select(x => x.Trim()).ToList(); var currentlyInstalledVersions = dc.DeploTasks.Where(x => x.PackageName == package && x.CurrentlyDeployedVersion != null).ToList().Select(x => x.CurrentlyDeployedVersion.Trim()).ToList(); var toDelete = allVersion.Where(x => !currentlyInstalledVersions.Contains(x)).ToList(); toDelete.RemoveRange(0, 10); foreach (var pack in toDelete) { RemovePackage(package, pack, gallery); } } }
public void WebHookLatest(int enviromentId, int applicationId, string secret) { var app = db.Applications.SingleOrDefault(x => x.Id == applicationId); if (app == null || app.Secret != Guid.Parse(secret)) { throw new UnauthorizedAccessException("Application secret invalid"); } var repos = db.DeploTasks .Where(x => x.EnviromentId == enviromentId && x.ApplicationId == applicationId) .Select(x => x.Repository) .ToList(); var package = db.DeploTasks .Where(x => x.EnviromentId == enviromentId && x.ApplicationId == applicationId) .Select(x => x.PackageName) .First(); var version = PackageSearcher.Search(repos, package).First(); using (var session = WebApiApplication.Store.OpenSession()) { var deploy = new Deployment() { EnviromentId = enviromentId, ApplicationId = applicationId, Status = Status.Queud, Version = version, UserId = new Guid().ToString() }; session.Save(deploy); session.Flush(); BackgroundJob.Enqueue(() => DeployJob.Execute(deploy.Id)); }; }