Esempio n. 1
0
        /// <summary>
        /// Get the project snapshot for a project
        /// </summary>
        /// <param name="xDoc">the XDcoument to parse</param>
        public ProjectStatusSnapshot GetProjectStatusSnapshot(XDocument xDoc)
        {
            var firstElement  = xDoc.Descendants().First <XElement>(); // The first element in the document is named based on the type of project (freeStyleProject, mavenModuleSet, etc)
            var color         = (string)firstElement.Element("color");
            var lastBuildInfo = GetBuildInformation((string)firstElement.Element("lastBuild").Element("url"));
            var status        = lastBuildInfo.Building ? ItemBuildStatus.Running : EnumUtils.GetItemBuildStatus(color);

            var snapshot = new ProjectStatusSnapshot
            {
                Status         = status,
                Name           = (string)firstElement.Element("name"),
                TimeOfSnapshot = DateTime.Now,
                Description    = (string)firstElement.Element("description"),
                Error          = String.Empty           // Not sure what to do with this yet
            };

            // Set one or the other
            if (status == ItemBuildStatus.Running)
            {
                snapshot.TimeStarted = lastBuildInfo.Timestamp;
                snapshot.TimeOfEstimatedCompletion =
                    lastBuildInfo.Timestamp.AddMilliseconds(lastBuildInfo.EstimatedDuration);
            }
            else
            {
                snapshot.TimeCompleted = lastBuildInfo.Timestamp;
            }

            return(snapshot);
        }
Esempio n. 2
0
        /// <summary>
        /// Retrieves a snapshot of the current build status.
        /// </summary>
        /// <returns>The current build status of the project.</returns>
        public virtual ProjectStatusSnapshot RetrieveSnapshot()
        {
            ProjectStatusSnapshot snapshot = new ProjectStatusSnapshot();

            snapshot.Name   = projectName;
            snapshot.Status = ItemBuildStatus.Unknown;
            return(snapshot);
        }
Esempio n. 3
0
        public void TimeOfSnapshotCanBeSetAndRetrieved()
        {
            var snapshot = new ProjectStatusSnapshot();
            var time     = new DateTime(2010, 1, 2, 3, 4, 5);

            snapshot.TimeOfSnapshot = time;
            Assert.AreEqual(time, snapshot.TimeOfSnapshot);
        }
Esempio n. 4
0
        public void SnapshotCanBeSetAndRetrieved()
        {
            var request  = new StatusSnapshotResponse();
            var snapshot = new ProjectStatusSnapshot();

            request.Snapshot = snapshot;
            Assert.AreSame(snapshot, request.Snapshot);
        }
        public void TakeSnapshotReturnsAValidSnapshot()
        {
            var request  = GenerateProjectRequest("Project 1");
            var response = server.TakeStatusSnapshot(request);
            ProjectStatusSnapshot snapshot = response.Snapshot;

            Assert.IsNotNull(snapshot, "Snapshot not taken");
            Assert.AreEqual("Project 1", snapshot.Name, "Name not set");
        }
Esempio n. 6
0
        /// <summary>
        /// Simple method to convert a project status to JSON (since we're not using .NET 3.5).
        /// </summary>
        /// <param name="status">The status to convert.</param>
        /// <returns></returns>
        private string ConvertStatusToJson(ProjectStatusSnapshot status)
        {
            var jsonText = new StringBuilder();

            jsonText.Append("{");
            jsonText.AppendFormat("time:{0},", ToJsonDate(status.TimeOfSnapshot));
            AppendStatusDetails(status, jsonText);
            jsonText.Append("}");
            return(jsonText.ToString());
        }
 private void displayWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         ProjectStatusSnapshot newSnapshot = projectToMonitor.RetrieveSnapshot();
         snapshot = newSnapshot;
     }
     catch (Exception error)
     {
         currentError = error;
     }
 }
Esempio n. 8
0
 /// <summary>
 /// Retrieves a snapshot of the current build status.
 /// </summary>
 /// <returns>The current build status of the project.</returns>
 public virtual ProjectStatusSnapshot RetrieveSnapshot()
 {
     // TODO: Replace this try-catch block with a mechanism to detect whether the remote server allows this functionality
     try
     {
         ProjectStatusSnapshot snapshot = cruiseProjectManager.RetrieveSnapshot();
         return(snapshot);
     }
     catch (NotImplementedException)
     {
         return(new ProjectStatusSnapshot());
     }
 }
        private ItemStatus InitialiseSnapshot()
        {
            var snapShot = new ProjectStatusSnapshot
            {
                Name           = "TestProject",
                TimeStarted    = DateTime.Parse("2010-01-01T12:00:00.00000+00:00", CultureInfo.InvariantCulture).ToUniversalTime(),
                TimeCompleted  = DateTime.Parse("2010-01-01T12:01:00.00000+00:00", CultureInfo.InvariantCulture).ToUniversalTime(),
                TimeOfSnapshot = DateTime.Parse("2010-01-01T12:01:00.00000+00:00", CultureInfo.InvariantCulture).ToUniversalTime(),
                Status         = ItemBuildStatus.CompletedSuccess
            };
            var idField = typeof(ItemStatus)
                          .GetField("identifier", BindingFlags.NonPublic | BindingFlags.Instance);

            idField.SetValue(snapShot, new Guid("8A3C688E-ABCD-44d9-B15C-B1339BBD776D"));
            return(snapShot);
        }
Esempio n. 10
0
 /// <summary>
 /// Retrieves the current snapshot of the status.
 /// </summary>
 /// <returns>The current status snapshot.</returns>
 public ProjectStatusSnapshot RetrieveCurrentStatus()
 {
     if (statusSnapshot == null)
     {
         lock (snapshotLock)
         {
             if (statusSnapshot == null)
             {
                 client.ProcessSingleAction(p =>
                 {
                     statusSnapshot = client.TakeStatusSnapshot(p.Name);
                 }, InnerProject);
             }
         }
     }
     return(statusSnapshot);
 }
Esempio n. 11
0
        private ProjectStatusSnapshot GenerateSnapshot()
        {
            var snapshot = new ProjectStatusSnapshot
            {
                Description   = "Root level",
                Name          = "root",
                Status        = ItemBuildStatus.CompletedSuccess,
                TimeStarted   = new DateTime(2010, 1, 2, 3, 4, 5),
                TimeCompleted = new DateTime(2010, 1, 2, 3, 4, 6)
            };

            snapshot.AddChild(new ItemStatus
            {
                Name   = "child",
                Status = ItemBuildStatus.Cancelled
            });
            return(snapshot);
        }
Esempio n. 12
0
        /// <summary>
        /// Updates the details on a project.
        /// </summary>
        /// <param name="value">The new project details.</param>
        public void Update(ProjectStatus value)
        {
            // Validate the arguments
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            // Find all the changed properties
            var changes = new List <string>();

            if (project.Activity != value.Activity)
            {
                changes.Add("Activity");
            }
            if (project.BuildStage != value.BuildStage)
            {
                changes.Add("BuildStage");
            }
            if (project.BuildStatus != value.BuildStatus)
            {
                changes.Add("BuildStatus");
            }
            if (project.Category != value.Category)
            {
                changes.Add("Category");
            }
            if (project.Description != value.Description)
            {
                changes.Add("Description");
            }
            if (project.LastBuildDate != value.LastBuildDate)
            {
                changes.Add("LastBuildDate");
            }
            if (project.LastBuildLabel != value.LastBuildLabel)
            {
                changes.Add("LastBuildLabel");
            }
            if (project.LastSuccessfulBuildLabel != value.LastSuccessfulBuildLabel)
            {
                changes.Add("LastSuccessfulBuildLabel");
            }
            if (project.NextBuildTime != value.NextBuildTime)
            {
                changes.Add("NextBuildTime");
            }
            if (project.Queue != value.Queue)
            {
                changes.Add("Queue");
            }
            if (project.QueuePriority != value.QueuePriority)
            {
                changes.Add("QueuePriority");
            }
            if (project.Status != value.Status)
            {
                changes.Add("Status");
            }
            if (project.WebURL != value.WebURL)
            {
                changes.Add("WebURL");
            }
            if (project.Messages.Length != value.Messages.Length)
            {
                changes.Add("Messages");
            }
            else
            {
                var messageChanged = false;
                for (var loop = 0; loop < project.Messages.Length; loop++)
                {
                    messageChanged = (project.Messages[loop].Text != value.Messages[loop].Text);
                    if (messageChanged)
                    {
                        break;
                    }
                }
                if (messageChanged)
                {
                    changes.Add("Messages");
                }
            }

            // Update the builds
            LoadBuilds(value);

            // Make the actual change
            project        = value;
            statusSnapshot = null;

            // Fire any change notifications
            foreach (var change in changes)
            {
                FirePropertyChanged(change);
            }
            FireUpdated();
        }