/// <summary>
        /// Checks if a snapshot has changed.
        /// </summary>
        /// <param name="queueSetSnapshotToCompare"></param>
        /// <returns></returns>
        public bool IsQueueSetSnapshotChanged(QueueSetSnapshot queueSetSnapshotToCompare)
        {
            if (queueSetSnapshotToCompare == null)
            {
                if (queueSetSnapshot == null)
                    return false;
                else
                    return true;
            }
            if (queueSetSnapshot == null)
                return true;
            if (queueSetSnapshotToCompare.Queues.Count != queueSetSnapshot.Queues.Count)
                return true;

            for (int queueIndex = 0; queueIndex < queueSetSnapshot.Queues.Count; queueIndex++)
            {
                QueueSnapshot queueSnapshot = queueSetSnapshot.Queues[queueIndex];
                QueueSnapshot queueSnapshotToCompare = queueSetSnapshotToCompare.Queues[queueIndex];
                if (queueSnapshotToCompare.QueueName != queueSnapshot.QueueName)
                    return true;
                if (queueSnapshotToCompare.Requests.Count != queueSnapshot.Requests.Count)
                    return true;

                for (int requestIndex = 0; requestIndex < queueSnapshot.Requests.Count; requestIndex++)
                {
                    QueuedRequestSnapshot request = queueSnapshot.Requests[requestIndex];
                    QueuedRequestSnapshot requestToCompare = queueSnapshotToCompare.Requests[requestIndex];
                    if (requestToCompare.ProjectName != request.ProjectName)
                        return true;
                    if (requestToCompare.Activity != request.Activity)
                        return true;
                }
            }
            return false;
        }
Exemplo n.º 2
0
 private static void WriteQueueSetSnapshot(XmlWriter xmlWriter, QueueSetSnapshot queueSet)
 {
     foreach (QueueSnapshot queue in queueSet.Queues)
     {
         WriteQueueSnapshot(xmlWriter, queue);
     }
 }
        public void CorrectAssignmentOfConstructorArguments()
        {
            ProjectStatus[] projectStatuses = new ProjectStatus[0];
            QueueSetSnapshot queueSetSnapshot = new QueueSetSnapshot();

            CruiseServerSnapshot cruiseServerSnapshot = new CruiseServerSnapshot(projectStatuses, queueSetSnapshot);

            Assert.AreSame(projectStatuses, cruiseServerSnapshot.ProjectStatuses);
            Assert.AreSame(queueSetSnapshot, cruiseServerSnapshot.QueueSetSnapshot);
        }
        private CruiseServerSnapshot CreateEmptyQueuesSnapshot()
		{
            QueueSetSnapshot queueSetSnapshot = new QueueSetSnapshot();

			QueueSnapshot queueSnapshot1 = new QueueSnapshot("Queue1");
			queueSetSnapshot.Queues.Add(queueSnapshot1);

			QueueSnapshot queueSnapshot2 = new QueueSnapshot("Queue2");
			queueSetSnapshot.Queues.Add(queueSnapshot2);

            return new CruiseServerSnapshot(null, queueSetSnapshot);
        }
 public void ToStringSerialisesAllValues()
 {
     QueueSnapshot queueSnapshot = new QueueSnapshot("queue1");
     queueSnapshot.Requests.Add(new QueuedRequestSnapshot("test project", ProjectActivity.Pending));
     QueueSetSnapshot queueSetSnapshot = new QueueSetSnapshot();
     queueSetSnapshot.Queues.Add(queueSnapshot);
     ProjectStatus projectStatus = new ProjectStatus("test project", IntegrationStatus.Success, DateTime.Now);
     CruiseServerSnapshot snapshot = new CruiseServerSnapshot(
         new ProjectStatus[] { projectStatus },
         queueSetSnapshot);
     SnapshotResponse response = new SnapshotResponse();
     response.ErrorMessages.Add(new ErrorMessage("Error 1"));
     response.ErrorMessages.Add(new ErrorMessage("Error 2"));
     response.RequestIdentifier = "request";
     response.Result = ResponseResult.Success;
     response.Timestamp = DateTime.Now;
     response.Snapshot = snapshot;
     string actual = response.ToString();
     string expected = string.Format(System.Globalization.CultureInfo.CurrentCulture,"<snapshotResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
         "timestamp=\"{2:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\" identifier=\"{0}\" result=\"{1}\">" +
         "<error>Error 1</error>" +
         "<error>Error 2</error>" +
         "<snapshot>" +
             "<projects>" +
                 "<projectStatus showForceBuildButton=\"true\" showStartStopButton=\"true\" serverName=\"{6}\" status=\"Running\" buildStatus=\"Success\" name=\"test project\" " +
                     "queuePriority=\"0\" lastBuildDate=\"{3:yyyy-MM-ddTHH:mm:ss.FFFFFFF}\" nextBuildTime=\"{4:yyyy-MM-ddTHH:mm:ss.FFFFFFF}\">" +
                     "<activity type=\"Sleeping\" />" +
                     "<parameters />" +
                 "</projectStatus>" + 
             "</projects>" +
             "<queueSet>" +
                 "<queue name=\"queue1\">" +
                     "<queueRequest projectName=\"test project\" time=\"{5:yyyy-MM-ddTHH:mm:ss.FFFFFFF}\">" +
                         "<activity type=\"Pending\" />" +
                     "</queueRequest>" + 
                 "</queue>" +
             "</queueSet>" + 
         "</snapshot>" + 
         "</snapshotResponse>",
         response.RequestIdentifier,
         response.Result,
         response.Timestamp,
         projectStatus.LastBuildDate,
         projectStatus.NextBuildTime,
         DateTime.MinValue,
         Environment.MachineName);
     Assert.AreEqual(expected, actual);
 }
	    private QueueSetSnapshot ConvertDashboardQueues(DashboardQueue[] dashboardQueues)
        {
            QueueSetSnapshot queueSetSnapshot = new QueueSetSnapshot();
            if (dashboardQueues != null)
            {
                foreach (DashboardQueue dashboardQueue in dashboardQueues)
                {
                    QueueSnapshot queueSnapshot = new QueueSnapshot(dashboardQueue.Name);
                    if (dashboardQueue.Requests != null)
                    {
                        foreach (DashboardQueuedRequest dashboardQueuedRequest in dashboardQueue.Requests)
                        {
                            QueuedRequestSnapshot queuedRequestSnapshot = new QueuedRequestSnapshot(
                                dashboardQueuedRequest.ProjectName,
                                new ProjectActivity(dashboardQueuedRequest.Activity));
                            queueSnapshot.Requests.Add(queuedRequestSnapshot);
                        }
                    }
                    queueSetSnapshot.Queues.Add(queueSnapshot);
                }
            }
            return queueSetSnapshot;
        }
 /// <summary>
 /// Initialise a new populated <see cref="CruiseServerSnapshot"/>.
 /// </summary>
 /// <param name="projectStatuses"></param>
 /// <param name="queueSetSnapshot"></param>
 public CruiseServerSnapshot(ProjectStatus[] projectStatuses, QueueSetSnapshot queueSetSnapshot)
 {
     this.projectStatuses = projectStatuses;
     this.queueSetSnapshot = queueSetSnapshot;
 }
 /// <summary>
 /// Initialise a new blank <see cref="CruiseServerSnapshot"/>.
 /// </summary>
 public CruiseServerSnapshot()
 {
     projectStatuses = new ProjectStatus[0];
     queueSetSnapshot = new QueueSetSnapshot();
 }
Exemplo n.º 9
0
 /// <summary>
 /// Filters a list of queues and only returns the queues for the projects that a user is allowed to view.
 /// </summary>
 /// <param name="sessionToken">The session token to use in filtering.</param>
 /// <param name="filteredProjects">The already filtered projects.</param>
 /// <param name="queueSet">The set of queues to filter.</param>
 /// <returns>The filtered set.</returns>
 private QueueSetSnapshot FilterQueues(string sessionToken, ProjectStatus[] filteredProjects, QueueSetSnapshot queueSet)
 {
     var allowedQueues = new QueueSetSnapshot();
     var userName = securityManager.GetUserName(sessionToken);
     var defaultIsAllowed = (securityManager.GetDefaultRight(SecurityPermission.ViewProject) == SecurityRight.Allow);
     foreach (QueueSnapshot queue in queueSet.Queues)
     {
         if (filteredProjects.Select(x => x.Queue).Contains(queue.QueueName))
             allowedQueues.Queues.Add(queue);
     }
     return allowedQueues;
 }
        private CruiseServerSnapshot BuildCruiseServerSnapshot()
        {
            List<ProjectStatus> projectStatus = new List<ProjectStatus>();

            CheckProjectStatusCache();

            _projectListCache.ForEach(project =>
                {
                    lock (_statusCacheLock)
                    {
                        if (!_projectStatusCache.ContainsKey(project.ProjectName))
                        {
                            _projectStatusCache.Add(project.ProjectName, _manager.GetProjectStatus(project.ProjectName));
                            _projectStatusLastUpdate.Add(project.ProjectName, DateTime.Now);
                        }

                        if (!_lastQueuedBuildsCheck.ContainsKey(project.ProjectName) || _lastQueuedBuildsCheck[project.ProjectName].AddSeconds(CHECK_QUEUED_BUILDS_TIMEOUT_SECONDS) < DateTime.Now)
                        {
                            if (!IsBuildDefinitionTracked(project.ProjectName))
                            {
                                if (AttachToNextBuild(project.ProjectName))
                                {
                                    if (!_lastQueuedBuildsCheck.ContainsKey(project.ProjectName))
                                    {
                                        _lastQueuedBuildsCheck.Add(project.ProjectName, DateTime.Now);
                                    }
                                    else
                                    {
                                        _lastQueuedBuildsCheck[project.ProjectName] = DateTime.Now;
                                    }
                                }
                            }
                        }
                    }

                    projectStatus.Add(_projectStatusCache[project.ProjectName]);
                });

            CheckBuildQueueCache();
            lock (_statusCacheLock)
            {
                if (_buildQueue == null)
                {
                    _buildQueue = new QueueSetSnapshot();
                }

                if (_buildQueue.Queues.Count <= 0)
                {
                    IBuildController[] controllers = _manager.GetBuildControllers();
                    
                    for (int i = 0; i < controllers.Length; i++)
                    {
                        IQueuedBuild[] builds = _manager.GetBuildQueue(controllers[i]);
                        QueueSnapshot queue = new QueueSnapshot(controllers[i].Name);
                        _buildQueue.Queues.Add(queue);

                        if (builds.Length > 0)
                        {
                            for (int j = 0; j < builds.Length; j++)
                            {
                                queue.Requests.Add(new QueuedRequestSnapshot(builds[j].BuildDefinition.Name, TFSServerManager.GetProjectActivity(builds[j].Status), builds[j].QueueTime));
                            }
                        }
                    }

                    _lastBuildQueueCheck = DateTime.Now;
                }
            }

            return new CruiseServerSnapshot(projectStatus.ToArray(), _buildQueue);
        }
		private CruiseServerSnapshot CreateCruiseServerSnapshot()
		{
		    ProjectStatus[] projectStatuses = new ProjectStatus[]
		        {
		            new ProjectStatus("HelloWorld", "category", ProjectActivity.Sleeping, IntegrationStatus.Success,
		                              ProjectIntegratorState.Running,
		                              "http://blah", LastBuildTime, "build_8", "build_7",
		                              NextBuildTime,"", "", 0, new List<ParameterBase>())
		        };
            QueueSetSnapshot snapshot = new QueueSetSnapshot();
            snapshot.Queues.Add(new QueueSnapshot("Queue1"));
            snapshot.Queues[0].Requests.Add(new QueuedRequestSnapshot("HelloWorld", ProjectActivity.CheckingModifications));

            return new CruiseServerSnapshot(projectStatuses, snapshot);
		}
 public void ConstructorWorks()
 {
     var snapshot = new QueueSetSnapshot();
     Assert.IsNotNull(snapshot.Queues);
     Assert.IsEmpty(snapshot.Queues);
 }
Exemplo n.º 13
0
 private QueueSetSnapshot BuildQueueSetSnapshot()
 {
     QueueSetSnapshot queueSetSnapshot = new QueueSetSnapshot();
     foreach (IIntegrationQueue queue in queueSet.Values)
     {
         if (queue != null)
         {
             queueSetSnapshot.Queues.Add(BuildQueueSnapshot(queue));
         }
     }
     return queueSetSnapshot;
 }
 public void Setup()
 {
     snapshot1 = new QueueSetSnapshot();
     snapshot2 = new QueueSetSnapshot();
 }
 private void AssertQueueSetChanged(bool result, QueueSetSnapshot firstSnapshot, QueueSetSnapshot secondSnapshot)
 {
     CruiseServerSnapshot cruiseServerSnapshot1 = new CruiseServerSnapshot(null, firstSnapshot);
     CruiseServerSnapshot cruiseServerSnapshot2 = new CruiseServerSnapshot(null, secondSnapshot);
     Assert.AreEqual(result, cruiseServerSnapshot1.IsQueueSetSnapshotChanged(cruiseServerSnapshot2.QueueSetSnapshot));
 }