Пример #1
0
        public ActionResult Schedule(int id, int environmentid)
        {
            Environment environment = this.Entities.Environment
                                      .Include("Properties")
                                      .First(e => e.Id == environmentid);

            if (environment.GetBoolProperty("AllowTestDeployment"))
            {
                this.CheckPermission(UserRoleAction.ReleasePublishTest);
            }
            else
            {
                this.CheckPermission(UserRoleAction.ReleasePublishLive);
            }

            Package package = this.Entities.Package.First(p => p.Id == id);

            Publication publication = new Publication();

            publication.CreatedDate   = DateTime.UtcNow;
            publication.EnvironmentId = environmentid;
            publication.PackageId     = id;
            publication.State         = PublicationState.Queued;

            this.Entities.Publication.Add(publication);
            this.Entities.SaveChanges();

            return(this.RedirectToAction("VersionPackages", "Bundles", new { id = package.BundleVersionId }));
        }
Пример #2
0
        public ActionResult Approve(int id, int environmentid)
        {
            Package package = this.Entities.Package
                              .Include("ApprovedOnEnvironments")
                              .First(p => p.Id == id);

            Environment environment = this.Entities.Environment.First(e => e.Id == environmentid);

            if (!environment.GetBoolProperty("AllowTestDeployment", false))
            {
                this.CheckPermission(UserRoleAction.ReleaseApprove);
            }

            if (package.ApprovedOnEnvironments.Any(a => a.Environment == environment))
            {
                return(this.RedirectToAction("Details", new { id }));
            }

            PackageApprovedOnEnvironment onEnvironment = new PackageApprovedOnEnvironment();

            onEnvironment.Package          = package;
            onEnvironment.Environment      = environment;
            onEnvironment.ApprovedDate     = DateTime.UtcNow;
            onEnvironment.ApprovedByUserId = this.ActiveUser.Id;

            this.Entities.PackageApprovedOnEnvironment.Add(onEnvironment);
            this.Entities.SaveChanges();

            return(this.RedirectToAction("Details", new { id }));
        }
Пример #3
0
        public ActionResult Reject(int id, int environmentid)
        {
            Package package = this.Entities.Package
                              .Include("ApprovedOnEnvironments.ApprovedBy")
                              .First(p => p.Id == id);

            Environment environment = this.Entities.Environment.First(e => e.Id == environmentid);

            if (!environment.GetBoolProperty("AllowTestDeployment", false))
            {
                this.CheckPermission(UserRoleAction.ReleaseApprove);
            }

            PackageApprovedOnEnvironment packageApprovedOnEnvironment = package.ApprovedOnEnvironments.FirstOrDefault(a => a.Environment == environment);

            if (packageApprovedOnEnvironment == null)
            {
                return(this.RedirectToAction("Details", new { id }));
            }

            this.Entities.PackageApprovedOnEnvironment.Remove(packageApprovedOnEnvironment);
            this.Entities.SaveChanges();

            return(this.RedirectToAction("Details", new { id }));
        }
        private object GetBundleVersionInfo(BundleVersion bundleVersion)
        {
            BundleState bundleState = this.taskRunner.GetBundleState(bundleVersion.Id);

            double elapsedSecs = 0;
            double totalSecs   = 0;

            if (bundleState == BundleState.Deploying)
            {
                Publication publication = this.Entities.Publication.Where(p => p.State == PublicationState.InProgress && p.Package.BundleVersionId == bundleVersion.Id).OrderByDescending(p => p.CreatedDate).FirstOrDefault();

                if (publication != null)
                {
                    Environment environment = this.Entities.Environment.Include("PreviousEnvironment").FirstOrDefault(e => e.Id == publication.EnvironmentId);

                    elapsedSecs = (DateTime.UtcNow - publication.CreatedDate).TotalSeconds;
                    totalSecs   = bundleVersion.GetDoubleProperty("LastDeploymentDuration-e" + publication.EnvironmentId);

                    if (Math.Abs(totalSecs) < 1 && environment != null && environment.PreviousEnvironment.Count > 0)
                    {
                        totalSecs = bundleVersion.GetDoubleProperty("LastDeploymentDuration-e" + environment.PreviousEnvironment.First().Id);
                    }
                }
            }

            if (bundleState == BundleState.Packaging)
            {
                Package thisPackage     = this.Entities.Package.Where(p => p.BundleVersionId == bundleVersion.Id && p.PackageDate == null).OrderByDescending(p => p.CreatedDate).FirstOrDefault();
                Package previousPackage = this.Entities.Package.Where(p => p.BundleVersionId == bundleVersion.Id && p.PackageDate != null).OrderByDescending(p => p.CreatedDate).FirstOrDefault();

                if (thisPackage != null && previousPackage != null && previousPackage.PackageDate.HasValue)
                {
                    elapsedSecs = (DateTime.UtcNow - thisPackage.CreatedDate).TotalSeconds;
                    totalSecs   = (previousPackage.PackageDate.Value - previousPackage.CreatedDate).TotalSeconds;
                }
            }

            if (bundleState == BundleState.Building)
            {
                totalSecs = bundleVersion.GetDoubleProperty("LastBuildDuration");

                if (totalSecs > 0)
                {
                    elapsedSecs = (DateTime.UtcNow - bundleVersion.GetDateTimeProperty("LastBuildStartDate", DateTime.UtcNow)).TotalSeconds;
                }
            }

            return(new
            {
                id = bundleVersion.Id,
                elapsedSecs = (int)elapsedSecs,
                totalSecs = (int)totalSecs,
                state = bundleState.ToString(),
                projects = bundleVersion.ProjectVersions.Select(this.GetProjectVersionInfo).ToList()
            });
        }