Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
nag5000 committed Apr 12, 2015
2 parents 0a3f0b8 + cda2ff4 commit ad6855b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 28 deletions.
33 changes: 26 additions & 7 deletions Source/Tool/Building/BuildContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
Expand All @@ -21,7 +22,8 @@ public class BuildContext : BuildInfo, IBuildDistributor
{
private readonly IPackageContext _packageContext;
private readonly FindProjectItemDelegate _findProjectItem;
private readonly List<ProjectItem> _buildingProjects = new List<ProjectItem>();
private readonly List<ProjectItem> _buildingProjects;
private readonly object _buildingProjectsLockObject;

/* ReSharper disable PrivateFieldCanBeConvertedToLocalVariable
*
Expand Down Expand Up @@ -95,7 +97,7 @@ public override BuildedProjectsCollection BuildedProjects
get { return _buildedProjects; }
}

public override IEnumerable<ProjectItem> BuildingProjects
public override IReadOnlyList<ProjectItem> BuildingProjects
{
get { return _buildingProjects; }
}
Expand Down Expand Up @@ -149,6 +151,8 @@ public void CancelBuild()
public BuildContext(IPackageContext packageContext, FindProjectItemDelegate findProjectItem)
{
_buildedProjects = new BuildedProjectsCollection();
_buildingProjects = new List<ProjectItem>();
_buildingProjectsLockObject = ((ICollection)_buildingProjects).SyncRoot;

_packageContext = packageContext;
_findProjectItem = findProjectItem;
Expand Down Expand Up @@ -280,6 +284,7 @@ private bool GetProjectItem(BuildProjectContextEntry projectEntry, out ProjectIt
IDictionary<string, string> projectProperties = projectEntry.Properties;
if (projectProperties.ContainsKey("Configuration") && projectProperties.ContainsKey("Platform"))
{
// TODO: Use find by FullNameProjectDefinition for the Batch Build only.
string projectConfiguration = projectProperties["Configuration"];
string projectPlatform = projectProperties["Platform"];
var projectDefinition = new FullNameProjectDefinition(projectFile, projectConfiguration, projectPlatform);
Expand Down Expand Up @@ -378,7 +383,10 @@ private void BuildEvents_OnBuildProjectBegin(
throw new InvalidOperationException();
}

_buildingProjects.Add(currentProject);
lock (_buildingProjectsLockObject)
{
_buildingProjects.Add(currentProject);
}

ProjectState projectState;
switch (_buildAction)
Expand Down Expand Up @@ -425,9 +433,12 @@ private void BuildEvents_OnBuildProjectDone(string project, string projectconfig
throw new InvalidOperationException();
}

_buildingProjects.Remove(currentProject);
lock (_buildingProjectsLockObject)
{
_buildingProjects.Remove(currentProject);
}

var buildedProject = _buildedProjects[currentProject];
BuildedProject buildedProject = _buildedProjects[currentProject];
buildedProject.Success = success;

ProjectState projectState;
Expand Down Expand Up @@ -536,8 +547,12 @@ private void BuildEvents_OnBuildBegin(vsBuildScope scope, vsBuildAction action)

_buildCancelled = false;
_buildCancelledInternally = false;
_buildingProjects.Clear();

_buildedProjects.Clear();
lock (_buildingProjectsLockObject)
{
_buildingProjects.Clear();
}

_buildedSolution = null;
_buildingSolution = new BuildedSolution(_packageContext.GetDTE().Solution);
Expand Down Expand Up @@ -588,7 +603,11 @@ private void BuildEvents_OnBuildDone()

_buildedSolution = _buildingSolution;
_buildingSolution = null;
_buildingProjects.Clear();

lock (_buildingProjectsLockObject)
{
_buildingProjects.Clear();
}

_buildFinishTime = DateTime.Now;
_currentState = BuildState.Done;
Expand Down
2 changes: 1 addition & 1 deletion Source/Tool/Building/BuildInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class BuildInfo

public abstract BuildedProjectsCollection BuildedProjects { get; }

public abstract IEnumerable<ProjectItem> BuildingProjects { get; }
public abstract IReadOnlyList<ProjectItem> BuildingProjects { get; }

public abstract BuildedSolution BuildedSolution { get; }

Expand Down
16 changes: 2 additions & 14 deletions Source/Tool/Building/BuildedProjectsCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace AlekseyNagovitsyn.BuildVision.Tool.Building
{
// TODO: thread-safety.
public class BuildedProjectsCollection : List<BuildedProject>
{
public int BuildSuccessCount
Expand All @@ -30,7 +31,7 @@ public BuildedProject this[ProjectItem pi]
{
get
{
var proj = this.FirstOrDefault(p => p.UniqueName == pi.UniqueName && p.Configuration == pi.Configuration && p.Platform == pi.Platform);
var proj = Find(p => p.UniqueName == pi.UniqueName && p.Configuration == pi.Configuration && p.Platform == pi.Platform);
if (proj == null)
{
proj = new BuildedProject(pi.UniqueName, pi.FullName, pi.Configuration, pi.Platform);
Expand All @@ -40,18 +41,5 @@ public BuildedProject this[ProjectItem pi]
return proj;
}
}

/// <summary>
/// Get <see cref="BuildedProject"/> by <see cref="ProjectItem.UniqueName"/>.
/// If not exists, returns <c>null</c>.
/// </summary>
public BuildedProject this[string uniqueName]
{
get
{
var proj = this.FirstOrDefault(p => p.UniqueName == uniqueName);
return proj;
}
}
}
}
14 changes: 10 additions & 4 deletions Source/Tool/Models/ProjectItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ public DateTime? BuildStartTime
{
_buildStartTime = value;
OnPropertyChanged("BuildStartTime");
OnPropertyChanged("BuildStartTime2");
OnPropertyChanged("BuildElapsedTime");
}
}
Expand All @@ -238,7 +237,6 @@ public DateTime? BuildFinishTime
{
_buildFinishTime = value;
OnPropertyChanged("BuildFinishTime");
OnPropertyChanged("BuildFinishTime2");
OnPropertyChanged("BuildElapsedTime");
}
}
Expand All @@ -250,10 +248,13 @@ public TimeSpan? BuildElapsedTime
{
get
{
if (BuildStartTime == null || BuildFinishTime == null)
if (_buildStartTime == null)
return null;

return BuildFinishTime.Value.Subtract(BuildStartTime.Value);
if (_buildFinishTime == null)
return DateTime.Now.Subtract(_buildStartTime.Value);

return _buildFinishTime.Value.Subtract(_buildStartTime.Value);
}
}

Expand Down Expand Up @@ -447,6 +448,11 @@ public void UpdatePostBuildProperties(BuildedProject buildedProjectInfo)
ErrorsBox = buildedProjectInfo.ErrorsBox;
}

public void RaiseBuildElapsedTimeChanged()
{
OnPropertyChanged("BuildElapsedTime");
}

private void UpdateProperties()
{
Project project = _storageProject;
Expand Down
12 changes: 10 additions & 2 deletions Source/Tool/Tool.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;

Expand Down Expand Up @@ -31,6 +33,7 @@ public class Tool
private readonly SolutionEvents _solutionEvents;

private bool _buildErrorIsNavigated;
private string _origTextCurrentState;

public Tool(
IPackageContext packageContext,
Expand Down Expand Up @@ -215,8 +218,6 @@ private void OutputInStatusBar(string str, bool freeze)
_dteStatusBar.FreezeOutput(1);
}

private string _origTextCurrentState;

private void BuildEvents_OnBuildProcess()
{
try
Expand All @@ -227,6 +228,13 @@ private void BuildEvents_OnBuildProcess()
_viewModel.TextCurrentState = msg;
OutputInStatusBar(msg, true);
//_dte.SuppressUI = false;

IReadOnlyList<ProjectItem> buildingProjects = _buildContext.BuildingProjects;
lock (((ICollection)buildingProjects).SyncRoot)
{
for (int i = 0; i < buildingProjects.Count; i++)
buildingProjects[i].RaiseBuildElapsedTimeChanged();
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit ad6855b

Please sign in to comment.