Ejemplo n.º 1
0
        private static void ProcessDeployments(IEnumerable <DashboardItemResource> deploymentsOfInterest, IEnumerable <DashboardEnvironmentResource> environments, IEnumerable <DashboardProjectResource> projects)
        {
            foreach (var deploymentItem in deploymentsOfInterest)
            {
                IEnumerable <DashboardEnvironmentResource> dashboardEnvironmentResources = environments as DashboardEnvironmentResource[] ?? environments.ToArray();
                var environment = dashboardEnvironmentResources.FirstOrDefault(x => x.Id == deploymentItem.EnvironmentId);

                IEnumerable <DashboardProjectResource> dashboardProjectResources = projects as DashboardProjectResource[] ?? projects.ToArray();
                var project = dashboardProjectResources.FirstOrDefault(x => x.Id == deploymentItem.ProjectId);

                var deployment = Deployment.Of(project.Name, environment.Name)
                                 .HasState(deploymentItem.State.ToString());


                var cachedInstance = DeploymentCache.GetDeployment(deployment);
                if (cachedInstance == null)
                {
                    DeploymentCache.Cache(deployment);
                    continue;
                }

                var notificationSpecs = notificationFactory.GetNotificationCriteria(project, environment);

                foreach (var notificationSpec in notificationSpecs.Where(notificationSpec => notificationSpec.IsSatisfiedBy(deployment)))
                {
                    Notifier.Notify(deployment);
                }

                if (cachedInstance.HasChangedState(deployment.State))
                {
                    DeploymentCache.Cache(deployment);
                }
            }
        }