Example #1
0
 /// <summary>
 /// Fires the <see cref="BuildQueueRemoved"/> event.
 /// </summary>
 /// <param name="buildQueue">The build queue that was added.</param>
 protected void FireBuildQueueRemoved(BuildQueue buildQueue)
 {
     if (BuildQueueRemoved != null)
     {
         var args = new BuildQueueChangedArgs(buildQueue);
         BuildQueueRemoved(this, args);
     }
 }
 /// <summary>
 /// Compare if two queues are the same.
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 public virtual bool Equals(BuildQueue obj)
 {
     if (obj == null)
     {
         return(false);
     }
     return(obj.Server.Equals(Server) &&
            (obj.Name == Name));
 }
 public void ServerReturnsUnderlyingServer()
 {
     var client = mocks.DynamicMock<CruiseServerClientBase>();
     var server = InitialiseServer();
     var status = new QueueSnapshot();
     var queue = new BuildQueue(client, server, status);
     mocks.ReplayAll();
     Assert.AreSame(server, queue.Server);
 }
 public void ConstructorDoesNotAllowNullClient()
 {
     try
     {
         var queue = new BuildQueue(null, null, null);
         Assert.Fail("ArgumentNullException was expected");
     }
     catch (ArgumentNullException) { }
 }
 public void ConstructorSetsBuildQueue()
 {
     var mocks = new MockRepository();
     var client = mocks.DynamicMock<CruiseServerClientBase>();
     var watcher = mocks.Stub<IServerWatcher>();
     var monitor = new Server(client, watcher);
     var queue = new BuildQueue(client, monitor, new QueueSnapshot());
     var args = new BuildQueueChangedArgs(queue);
     Assert.AreSame(queue, args.BuildQueue);
 }
 public void ConstructorDoesNotAllowNullServer()
 {
     var client = mocks.DynamicMock<CruiseServerClientBase>();
     mocks.ReplayAll();
     try
     {
         var queue = new BuildQueue(client, null, null);
         Assert.Fail("ArgumentNullException was expected");
     }
     catch (ArgumentNullException) { }
 }
Example #7
0
        /// <summary>
        /// Initialise a new build queue request.
        /// </summary>
        /// <param name="client">The underlying client.</param>
        /// <param name="buildQueue">The queue this project belongs to.</param>
        /// <param name="snapshot">The actual build queue request details.</param>
        public BuildQueueRequest(CruiseServerClientBase client, BuildQueue buildQueue, QueuedRequestSnapshot snapshot)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (buildQueue == null)
            {
                throw new ArgumentNullException("buildQueue");
            }
            if (snapshot == null)
            {
                throw new ArgumentNullException("snapshot");
            }

            this.client     = client;
            this.buildQueue = buildQueue;
            this.snapshot   = snapshot;
        }
Example #8
0
 /// <summary>
 /// Initialise a new <see cref="BuildQueueChangedArgs"/>.
 /// </summary>
 /// <param name="buildQueue">The build queue that changed.</param>
 public BuildQueueChangedArgs(BuildQueue buildQueue)
 {
     BuildQueue = buildQueue;
 }
 /// <summary>
 /// Compare if two queues are the same.
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 public virtual bool Equals(BuildQueue obj)
 {
     if (obj == null) return false;
     return obj.Server.Equals(Server) &&
         (obj.Name == Name);
 }
Example #10
0
        /// <summary>
        /// Update the status based on the latest snapshot.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void OnWatcherUpdate(object sender, ServerUpdateArgs e)
        {
            var newProjects   = new List <Project>();
            var oldProjects   = new List <Project>();
            var newQueues     = new List <BuildQueue>();
            var oldQueues     = new List <BuildQueue>();
            var projectValues = new Dictionary <Project, ProjectStatus>();
            var queueValues   = new Dictionary <BuildQueue, QueueSnapshot>();

            syncLock.AcquireWriterLock(10000);
            try
            {
                Exception = e.Exception;
                if (e.Exception == null)
                {
                    // Check for any project differences
                    var oldProjectNames = new List <string>(projects.Keys);
                    foreach (var project in e.Snapshot.ProjectStatuses)
                    {
                        // Check if this project has already been loaded
                        var projectName = project.Name;
                        if (oldProjectNames.Contains(projectName))
                        {
                            projectValues.Add(projects[projectName], project);
                            oldProjectNames.Remove(projectName);
                        }
                        else
                        {
                            // Otherwise this is a new project
                            var newProject = new Project(client, this, project);
                            newProjects.Add(newProject);
                        }
                    }

                    // Check for any queue differences
                    var oldQueueNames = new List <string>(buildQueues.Keys);
                    foreach (var queue in e.Snapshot.QueueSetSnapshot.Queues)
                    {
                        // Check if this queue has already been loaded
                        var queueName = queue.QueueName;
                        if (oldQueueNames.Contains(queueName))
                        {
                            queueValues.Add(buildQueues[queueName], queue);
                            oldQueueNames.Remove(queueName);
                        }
                        else
                        {
                            // Otherwise this is a new queue
                            var newQueue = new BuildQueue(client, this, queue);
                            newQueues.Add(newQueue);
                        }
                    }

                    // Store the old projects and queues
                    foreach (var project in oldProjectNames)
                    {
                        oldProjects.Add(projects[project]);
                    }
                    foreach (var queue in oldQueueNames)
                    {
                        oldQueues.Add(buildQueues[queue]);
                    }

                    // Perform the actual update
                    foreach (var project in oldProjectNames)
                    {
                        projects.Remove(project);
                    }
                    foreach (var queue in oldQueueNames)
                    {
                        buildQueues.Remove(queue);
                    }
                    foreach (var project in newProjects)
                    {
                        projects.Add(project.Name, project);
                    }
                    foreach (var queue in newQueues)
                    {
                        buildQueues.Add(queue.Name, queue);
                    }
                }
            }
            finally
            {
                syncLock.ReleaseWriterLock();
            }

            // Update all the projects and queues
            foreach (var value in projectValues)
            {
                value.Key.Update(value.Value);
            }
            foreach (var value in queueValues)
            {
                value.Key.Update(value.Value);
            }

            // Tell any listeners about any changes
            foreach (var project in newProjects)
            {
                FireProjectAdded(project);
            }
            foreach (var queue in newQueues)
            {
                FireBuildQueueAdded(queue);
            }
            foreach (var project in oldProjects)
            {
                FireProjectRemoved(project);
            }
            foreach (var queue in oldQueues)
            {
                FireBuildQueueRemoved(queue);
            }
        }
 public void RequestsReturnsRequestsFromStatus()
 {
     var client = mocks.DynamicMock<CruiseServerClientBase>();
     var server = InitialiseServer();
     var status = new QueueSnapshot
     {
         Requests = {
                 new QueuedRequestSnapshot{
                     ProjectName = "Project 1"
                 }
             }
     };
     var queue = new BuildQueue(client, server, status);
     mocks.ReplayAll();
 }
 public void NameReturnsQueueNameFromSnapshot()
 {
     var client = mocks.DynamicMock<CruiseServerClientBase>();
     var server = InitialiseServer();
     var status = new QueueSnapshot { QueueName = "Test BuildQueue" };
     var queue = new BuildQueue(client, server, status);
     mocks.ReplayAll();
     Assert.AreEqual(status.QueueName, queue.Name);
 }
        public void UpdateFiresPropertyChangedWhenMessageIsRemoved()
        {
            mocks = new MockRepository();
            var client = mocks.DynamicMock<CruiseServerClientBase>();
            var server = InitialiseServer();
            var status = new QueueSnapshot
            {
                Requests = {
                        new QueuedRequestSnapshot{
                            ProjectName = "Project 1"
                        },
                        new QueuedRequestSnapshot{
                            ProjectName = "Project 2"
                        }
                    }
            };
            var queue = new BuildQueue(client, server, status);
            mocks.ReplayAll();
            var eventFired = false;
            queue.Update(status);

            var newStatus = new QueueSnapshot
            {
                Requests = {
                        new QueuedRequestSnapshot{
                            ProjectName = "Project 2"
                        }
                    }
            };
            queue.BuildQueueRequestRemoved += (o, e) =>
            {
                eventFired = true;
            };
            queue.Update(newStatus);
            Assert.IsTrue(eventFired, "BuildQueueRequestRemoved for Requests change not fired");
        }
 public void UpdateValidatesArguments()
 {
     var client = mocks.DynamicMock<CruiseServerClientBase>();
     var server = InitialiseServer();
     var status = new QueueSnapshot { QueueName = "Testing" };
     var queue = new BuildQueue(client, server, status);
     mocks.ReplayAll();
     try
     {
         queue.Update(null);
         Assert.Fail("ArgumentNullException was expected");
     }
     catch (ArgumentNullException) { }
 }