/// <summary>
        /// Attempt to retrieve a snapshot from the remote server.
        /// </summary>
        private void RetrieveSnapshot()
        {
            // Retrieve the snapshot
            ServerUpdateArgs args;
            try
            {
                CruiseServerSnapshot snapshot = null;
                try
                {
                    snapshot = client.GetCruiseServerSnapshot();
                }
                catch (NotImplementedException)
                {
                    // This is an older style server, try fudging the snapshot
                    snapshot = new CruiseServerSnapshot
                    {
                        ProjectStatuses = client.GetProjectStatus()
                    };
                }
                args = new ServerUpdateArgs(snapshot);
            }
            catch (Exception error)
            {
                args = new ServerUpdateArgs(error);
            }

            // Fire the update
            if (Update != null)
            {
                Update(this, args);
            }
        }
        /// <summary>
        /// Attempt to retrieve a snapshot from the remote server.
        /// </summary>
        private void RetrieveSnapshot()
        {
            // Retrieve the snapshot
            ServerUpdateArgs args;

            try
            {
                CruiseServerSnapshot snapshot = null;
                try
                {
                    snapshot = client.GetCruiseServerSnapshot();
                }
                catch (NotImplementedException)
                {
                    // This is an older style server, try fudging the snapshot
                    snapshot = new CruiseServerSnapshot
                    {
                        ProjectStatuses = client.GetProjectStatus()
                    };
                }
                args = new ServerUpdateArgs(snapshot);
            }
            catch (Exception error)
            {
                args = new ServerUpdateArgs(error);
            }

            // Fire the update
            if (Update != null)
            {
                Update(this, args);
            }
        }
 public void ConstructorSetsException()
 {
     var exception = new Exception();
     var args = new ServerUpdateArgs(exception);
     Assert.AreSame(exception, args.Exception);
 }
Ejemplo n.º 4
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);
            }
        }