/// <summary>
        /// Generates a clone of this snapshot.
        /// </summary>
        /// <returns></returns>
        public new ProjectStatusSnapshot Clone()
        {
            ProjectStatusSnapshot clone = new ProjectStatusSnapshot();

            CopyTo(clone);
            return(clone);
        }
 /// <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;
 }
 public void SnapshotCanBeSetAndRetrieved()
 {
     var request = new StatusSnapshotResponse();
     var snapshot = new ProjectStatusSnapshot();
     request.Snapshot = snapshot;
     Assert.AreSame(snapshot, request.Snapshot);
 }
 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);
 }
 /// <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;
     }
 }
 /// <summary>
 /// Takes a status snapshot of a project.
 /// </summary>
 /// <param name="request"></param>
 /// <returns>The snapshot of the current status.</returns>
 public virtual StatusSnapshotResponse TakeStatusSnapshot(ProjectRequest request)
 {
     ProjectStatusSnapshot snapshot = null;
     StatusSnapshotResponse response = new StatusSnapshotResponse(RunProjectRequest(request,
         SecurityPermission.ViewProject,
         null,
         delegate
         {
             IProjectIntegrator integrator = GetIntegrator(request.ProjectName);
             if (integrator != null)
             {
                 // First see if the project has its own associated generator
                 if (integrator.Project is IStatusSnapshotGenerator)
                 {
                     snapshot = (integrator.Project as IStatusSnapshotGenerator).GenerateSnapshot()
                         as ProjectStatusSnapshot;
                 }
                 else
                 {
                     // Otherwise generate an overview snapshot (details will not be available)
                     ProjectStatus status = integrator.Project.CreateProjectStatus(integrator);
                     snapshot = new ProjectStatusSnapshot();
                     snapshot.Name = integrator.Project.Name;
                     if (status.Activity.IsBuilding())
                     {
                         snapshot.Status = ItemBuildStatus.Running;
                     }
                     else if (status.Activity.IsPending())
                     {
                         snapshot.Status = ItemBuildStatus.Pending;
                     }
                     else if (status.Activity.IsSleeping())
                     {
                         switch (status.BuildStatus)
                         {
                             case IntegrationStatus.Success:
                                 snapshot.Status = ItemBuildStatus.CompletedSuccess;
                                 break;
                             case IntegrationStatus.Exception:
                             case IntegrationStatus.Failure:
                                 snapshot.Status = ItemBuildStatus.CompletedSuccess;
                                 break;
                         }
                     }
                 }
             }
             else
             {
                 throw new NoSuchProjectException(request.ProjectName);
             }
         }));
     response.Snapshot = snapshot;
     return response;
 }
 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;
 }
Exemple #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Project"/> class.
        /// </summary>
        public Project()
        {
            integrationResultManager = new IntegrationResultManager(this);
            integratable = new IntegrationRunner(integrationResultManager, this, quietPeriod);
            this.PrebuildTasks = new ITask[0];
            this.CryptoFunctions = new DefaultCryptoFunctions();

            // Generates the initial snapshot
            currentProjectStatus = new ProjectStatusSnapshot();
            PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                switch (e.PropertyName)
                {
                    case "Name":
                        lock (currentProjectStatus)
                        {
                            currentProjectStatus.Name = Name;
                        }
                        break;
                    case "Description":
                        lock (currentProjectStatus)
                        {
                            currentProjectStatus.Description = Description;
                        }
                        break;
                }
            };
        }
        public ProjectStatusSnapshot GetProjectStatusSnapshot(string projectName)
        {
            IBuildDetailSpec querySpec = TfsBuildServer.CreateBuildDetailSpec(
                                            Settings.TeamProject,
                                            projectName);
            querySpec.MaxBuildsPerDefinition = MAX_BUILDS_TO_QUERY;
            querySpec.QueryOrder = BuildQueryOrder.FinishTimeDescending;

            IBuildQueryResult queryResult = TfsBuildServer.QueryBuilds(querySpec);
            if (queryResult != null)
            {
                IBuildDetail[] buildDetails = queryResult.Builds;
                if (buildDetails.Length > 0)
                {
                    IBuildDetail successfulBuild = GetLastSuccessfulBuild(buildDetails);
                    IBuildDetail currentBuild = GetLastNonStoppedBuild(buildDetails);

                    ProjectStatusSnapshot tmpStatus = new ProjectStatusSnapshot()
                    {
                        Description = GetProjectCategory(projectName),
                        Error = (currentBuild.Status == BuildStatus.Failed || currentBuild.Status == BuildStatus.Failed) ? GetBuildStage(currentBuild) : String.Empty,
                        Name = projectName,
                        Status = GetItemBuildStatus(currentBuild.Status),
                        TimeCompleted = currentBuild.FinishTime,
                        TimeOfSnapshot = DateTime.Now,
                        TimeStarted = currentBuild.StartTime
                    };

                    return tmpStatus;

                }
            }

            return new ProjectStatusSnapshot() { Name = projectName, Status = ItemBuildStatus.Unknown };
        }
 /// <summary>
 /// Generates a clone of this snapshot.
 /// </summary>
 /// <returns></returns>
 public new ProjectStatusSnapshot Clone()
 {
     ProjectStatusSnapshot clone = new ProjectStatusSnapshot();
     CopyTo(clone);
     return clone;
 }
 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;
 }
        /// <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;
        }