Skip to content

Commit

Permalink
Removed not needed refresh of DataGrid on each propertychange
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKert committed Oct 10, 2017
1 parent 091d078 commit 69a0812
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 75 deletions.
49 changes: 1 addition & 48 deletions BuildVision.UI/Components/ControlView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,53 +63,6 @@ private void OnDataContextChanged(object sender, DependencyPropertyChangedEventA
_viewModel = (ControlViewModel)DataContext;
_viewModel.GridColumnsRef = Grid.Columns;
_viewModel.PropertyChanged += ViewModelOnPropertyChanged;
_viewModel.Model.SolutionItem.Projects.CollectionChanged += ProjectsOnCollectionChanged;
}

private void ProjectsOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
foreach (ProjectItem item in e.NewItems)
{
item.PropertyChanged += SolutionItemOnProjectPropertyChanged;
}
break;

case NotifyCollectionChangedAction.Reset:
var collection = (ICollection<ProjectItem>)sender;
if (collection.Count == 0)
break;

// Copy items for thread safety. Collection may be changed in other thread, while foreach works.
var items = new List<ProjectItem>(collection);
foreach (ProjectItem item in items)
{
item.PropertyChanged += SolutionItemOnProjectPropertyChanged;
}
break;

case NotifyCollectionChangedAction.Remove:
foreach (ProjectItem item in e.OldItems)
{
item.PropertyChanged -= SolutionItemOnProjectPropertyChanged;
}
break;
}
}

private void SolutionItemOnProjectPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (Grid.ItemsSource == null)
return;

if (e.PropertyName == _viewModel.GridSortDescription.Property
|| e.PropertyName == _viewModel.GridGroupPropertyName)
{
// Refresh grouping and sorting.
((ListCollectionView)Grid.ItemsSource).Refresh();
}
}

private void ViewModelOnPropertyChanged(object sender, PropertyChangedEventArgs e)
Expand Down Expand Up @@ -184,4 +137,4 @@ private void DataGridRowOnPreviewMouseLeftButtonDown(object sender, MouseButtonE
}
}
}
}
}
44 changes: 28 additions & 16 deletions BuildVision/Tool/Building/BuildContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace BuildVision.Tool.Building
{
public class BuildContext : IBuildInfo, IBuildDistributor
{
{
private const int BuildInProcessCountOfQuantumSleep = 5;
private const int BuildInProcessQuantumSleep = 50;
private const string CancelBuildCommand = "Build.Cancel";
Expand Down Expand Up @@ -416,6 +416,12 @@ private void BuildEvents_OnBuildProjectBegin(string project, string projectconfi
BuildingProjects.Add(currentProject);
}

var projectState = GetProjectState();
OnBuildProjectBegin(this, new BuildProjectEventArgs(currentProject, projectState, eventTime, null));
}

private ProjectState GetProjectState()
{
ProjectState projectState;
switch (BuildAction)
{
Expand All @@ -435,7 +441,7 @@ private void BuildEvents_OnBuildProjectBegin(string project, string projectconfi
throw new ArgumentOutOfRangeException();
}

OnBuildProjectBegin(this, new BuildProjectEventArgs(currentProject, projectState, eventTime, null));
return projectState;
}

private void BuildEvents_OnBuildProjectDone(string project, string projectconfig, string platform, string solutionconfig, bool success)
Expand All @@ -444,20 +450,7 @@ private void BuildEvents_OnBuildProjectDone(string project, string projectconfig
return;

var eventTime = DateTime.Now;

ProjectItem currentProject;
if (BuildScope == BuildScopes.BuildScopeBatch)
{
currentProject = FindProjectItemInProjectsByUniqueName(project, projectconfig, platform);
if (currentProject == null)
throw new InvalidOperationException();
}
else
{
currentProject = FindProjectItemInProjectsByUniqueName(project);
if (currentProject == null)
throw new InvalidOperationException();
}
var currentProject = GetCurrentProject(project, projectconfig, platform);

lock (_buildingProjectsLockObject)
{
Expand Down Expand Up @@ -509,6 +502,25 @@ private void BuildEvents_OnBuildProjectDone(string project, string projectconfig
OnBuildProjectDone(this, new BuildProjectEventArgs(currentProject, projectState, eventTime, buildedProject));
}

private ProjectItem GetCurrentProject(string project, string projectconfig, string platform)
{
ProjectItem currentProject;
if (BuildScope == BuildScopes.BuildScopeBatch)
{
currentProject = FindProjectItemInProjectsByUniqueName(project, projectconfig, platform);
if (currentProject == null)
throw new InvalidOperationException();
}
else
{
currentProject = FindProjectItemInProjectsByUniqueName(project);
if (currentProject == null)
throw new InvalidOperationException();
}

return currentProject;
}

private void BuildEvents_OnBuildBegin(vsBuildScope scope, vsBuildAction action)
{
if (action == vsBuildAction.vsBuildActionDeploy)
Expand Down
19 changes: 8 additions & 11 deletions BuildVision/Tool/Tool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,19 +409,16 @@ private void BuildEvents_OnBuildProcess()
{
try
{
Task.Run(() =>
{
var labelsSettings = _viewModel.ControlSettings.BuildMessagesSettings;
string msg = _origTextCurrentState + BuildMessages.GetBuildBeginExtraMessage(_buildContext, labelsSettings);
var labelsSettings = _viewModel.ControlSettings.BuildMessagesSettings;
string msg = _origTextCurrentState + BuildMessages.GetBuildBeginExtraMessage(_buildContext, labelsSettings);

_viewModel.TextCurrentState = msg;
OutputInStatusBar(msg, true);
//_dte.SuppressUI = false;
_viewModel.TextCurrentState = msg;
OutputInStatusBar(msg, true);
//_dte.SuppressUI = false;

var buildingProjects = _buildContext.BuildingProjects;
for (int i = 0; i < buildingProjects.Count; i++)
buildingProjects[i].RaiseBuildElapsedTimeChanged();
});
var buildingProjects = _buildContext.BuildingProjects;
for (int i = 0; i < buildingProjects.Count; i++)
buildingProjects[i].RaiseBuildElapsedTimeChanged();
}
catch (Exception ex)
{
Expand Down

0 comments on commit 69a0812

Please sign in to comment.