private void BuildEvents_OnBuildDone()
        {
            if (BuildAction == BuildActions.BuildActionDeploy)
            {
                return;
            }

            if (CurrentBuildState != BuildState.InProgress)
            {
                // Start command (F5), when Build is not required.
                return;
            }

            _buildProcessCancellationToken.Cancel();

            BuildedSolution  = BuildingSolution;
            BuildingSolution = null;

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

            BuildFinishTime   = DateTime.Now;
            CurrentBuildState = BuildState.Done;

            OnBuildDone(this, EventArgs.Empty);
        }
        private void BuildEvents_OnBuildProjectBegin(string project, string projectconfig, string platform, string solutionconfig)
        {
            if (BuildAction == BuildActions.BuildActionDeploy)
            {
                return;
            }

            var eventTime = DateTime.Now;

            ProjectItem currentProject;

            if (BuildScope == BuildScopes.BuildScopeBatch)
            {
                currentProject = FindProjectItemInProjectsByUniqueName(project, projectconfig, platform);
                if (currentProject == null)
                {
                    currentProject = AddProjectToVisibleProjectsByUniqueName(project, projectconfig, platform);
                }
            }
            else
            {
                currentProject = FindProjectItemInProjectsByUniqueName(project);
                if (currentProject == null)
                {
                    currentProject = AddProjectToVisibleProjectsByUniqueName(project);
                }
            }

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

            ProjectState projectState;

            switch (BuildAction)
            {
            case BuildActions.BuildActionBuild:
            case BuildActions.BuildActionRebuildAll:
                projectState = ProjectState.Building;
                break;

            case BuildActions.BuildActionClean:
                projectState = ProjectState.Cleaning;
                break;

            case BuildActions.BuildActionDeploy:
                throw new InvalidOperationException("vsBuildActionDeploy not supported");

            default:
                throw new ArgumentOutOfRangeException();
            }

            OnBuildProjectBegin(this, new BuildProjectEventArgs(currentProject, projectState, eventTime, null));
        }
Exemple #3
0
        /// <summary>
        /// A method called to notify the the tool window that an individual project build is done.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="projectConfig">The project config.</param>
        /// <param name="platform">The platform.</param>
        /// <param name="solutionConfig">The solution config.</param>
        /// <param name="success">True if project build was successful, otherwise false.</param>
        internal void NotifyBuildProjConfigDone(string project, string projectConfig, string platform, string solutionConfig, bool success)
        {
            if (!success)
            {
                _viewModel.HasBuildFailed = true;
            }

            ++NumberOfProjectsBuilt;
            BuildingProjects.Remove(project);
            Caption = GetToolWindowCaption();
            _viewModel.ProgressPercentage = ProgressPercentage;
        }
Exemple #4
0
        /// <summary>
        /// Gets the build progress tool window caption to be displayed.
        /// </summary>
        /// <returns>The string to be displayed as the tool window caption.</returns>
        private string GetToolWindowCaption()
        {
            var    projectNames = BuildingProjects.Select(x => $"\"{ExtractProjectName(x)}\"").ToList();
            string buildString  = GetBuildTypeString(BuildScope, BuildAction);

            string progressString = string.Empty;

            if (NumberOfProjectsToBeBuilt > 0)
            {
                string projectsString = NumberOfProjectsToBeBuilt.ToString(CultureInfo.CurrentUICulture);
                string completeString = NumberOfProjectsBuilt.ToString(CultureInfo.CurrentUICulture).PadLeft(projectsString.Length);

                progressString = $" {completeString} of {projectsString}";
            }

            return($"{DefaultCaption}{progressString}: {buildString} {string.Join(", ", projectNames)}...");
        }
        /// <summary>
        /// Gets the build progress tool window caption to be displayed.
        /// </summary>
        /// <returns>The string to be displayed as the tool window caption.</returns>
        private string GetToolWindowCaption()
        {
            var    projectNames = BuildingProjects.Select(x => string.Format("\"{0}\"", ExtractProjectName(x))).ToList();
            string buildString  = GetBuildTypeString(BuildScope, BuildAction);

            string progressString = string.Empty;

            if (NumberOfProjectsToBeBuilt > 0)
            {
                string projectsString = NumberOfProjectsToBeBuilt.ToString(CultureInfo.CurrentUICulture);
                string completeString = NumberOfProjectsBuilt.ToString(CultureInfo.CurrentUICulture).PadLeft(projectsString.Length);

                progressString = string.Format(" {0} of {1}", completeString, projectsString);
            }

            return(string.Format("{0}{1}: {2} {3}...",
                                 DefaultCaption, progressString, buildString, string.Join(", ", projectNames)));
        }
        private void BuildEvents_OnBuildProjectBegin(string project, string projectconfig, string platform, string solutionconfig)
        {
            if (BuildAction == BuildActions.BuildActionDeploy)
            {
                return;
            }

            var eventTime = DateTime.Now;

            ProjectItem currentProject;

            if (BuildScope == BuildScopes.BuildScopeBatch)
            {
                currentProject = FindProjectItemInProjectsByUniqueName(project, projectconfig, platform);
                if (currentProject == null)
                {
                    currentProject = AddProjectToVisibleProjectsByUniqueName(project, projectconfig, platform);
                }
            }
            else
            {
                currentProject = FindProjectItemInProjectsByUniqueName(project);
                if (currentProject == null)
                {
                    currentProject = AddProjectToVisibleProjectsByUniqueName(project);
                }
            }

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

            var projectState = GetProjectState();

            OnBuildProjectBegin(this, new BuildProjectEventArgs(currentProject, projectState, eventTime, null));
        }
Exemple #7
0
 /// <summary>
 /// A method called to notify the tool window that an individual project build has begun.
 /// </summary>
 /// <param name="project">The project.</param>
 /// <param name="projectConfig">The project config.</param>
 /// <param name="platform">The platform.</param>
 /// <param name="solutionConfig">The solution config.</param>
 internal void NotifyBuildProjConfigBegin(string project, string projectConfig, string platform, string solutionConfig)
 {
     BuildingProjects.Add(project);
     Caption = GetToolWindowCaption();
     _viewModel.ProgressPercentage = ProgressPercentage;
 }
        private void BuildEvents_OnBuildBegin(vsBuildScope scope, vsBuildAction action)
        {
            if (action == vsBuildAction.vsBuildActionDeploy)
            {
                return;
            }

            RegisterLogger();

            CurrentBuildState = BuildState.InProgress;

            BuildStartTime  = DateTime.Now;
            BuildFinishTime = null;
            BuildAction     = (BuildActions)action;

            switch (scope)
            {
            case vsBuildScope.vsBuildScopeSolution:
            case vsBuildScope.vsBuildScopeBatch:
            case vsBuildScope.vsBuildScopeProject:
                BuildScope = (BuildScopes)scope;
                break;

            case 0:
                // Scope may be 0 in case of Clean solution, then Start (F5).
                BuildScope = (BuildScopes)vsBuildScope.vsBuildScopeSolution;
                break;

            default:
                throw new ArgumentOutOfRangeException("scope");
            }

            if (scope == vsBuildScope.vsBuildScopeProject)
            {
                var projContext = _activeProjectContext;
                switch (projContext.Type)
                {
                case vsWindowType.vsWindowTypeSolutionExplorer:
                    ////var solutionExplorer = (UIHierarchy)dte.Windows.Item(Constants.vsext_wk_SProjectWindow).Object;
                    var solutionExplorer = (UIHierarchy)projContext.Object;
                    var items            = (Array)solutionExplorer.SelectedItems;
                    switch (items.Length)
                    {
                    case 0:
                        TraceManager.TraceError("Unable to get target projects in Solution Explorer (vsBuildScope.vsBuildScopeProject)");
                        BuildScopeProject = null;
                        break;

                    case 1:
                        var item = (UIHierarchyItem)items.GetValue(0);

                        var hierachyProjectItem = new ProjectItem();
                        ViewModelHelper.UpdateProperties((Project)item.Object, hierachyProjectItem);
                        BuildScopeProject = hierachyProjectItem;
                        break;

                    default:
                        BuildScopeProject = null;
                        break;
                    }
                    break;

                case vsWindowType.vsWindowTypeDocument:
                    var projectItem = new ProjectItem();
                    ViewModelHelper.UpdateProperties(projContext.Project, projectItem);
                    BuildScopeProject = projectItem;
                    break;

                default:
                    throw new InvalidOperationException("Unsupported type of active project context for vsBuildScope.vsBuildScopeProject.");
                }
            }

            _buildCancelled           = false;
            _buildCancelledInternally = false;

            BuildedProjects.Clear();
            lock (_buildingProjectsLockObject)
            {
                BuildingProjects.Clear();
            }

            BuildedSolution = null;
            var solution = _packageContext.GetDTE().Solution;

            BuildingSolution = new BuildedSolution(solution.FullName, solution.FileName);

            OnBuildBegin(this, EventArgs.Empty);

            _buildProcessCancellationToken = new CancellationTokenSource();
            Task.Factory.StartNew(BuildEvents_BuildInProcess, _buildProcessCancellationToken.Token, _buildProcessCancellationToken.Token);
        }
        private void BuildEvents_OnBuildProjectDone(string project, string projectconfig, string platform, string solutionconfig, bool success)
        {
            if (BuildAction == BuildActions.BuildActionDeploy)
            {
                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();
                }
            }

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

            BuildedProject buildedProject = BuildedProjects[currentProject];

            buildedProject.Success = success;

            ProjectState projectState;

            switch (BuildAction)
            {
            case BuildActions.BuildActionBuild:
            case BuildActions.BuildActionRebuildAll:
                if (success)
                {
                    bool upToDate = (_buildLogger != null && _buildLogger.Projects != null &&
                                     !_buildLogger.Projects.Exists(t => t.FileName == buildedProject.FileName));
                    if (upToDate)
                    {
                        // Because ErrorBox will be empty if project is UpToDate.
                        buildedProject.ErrorsBox = currentProject.ErrorsBox;
                    }

                    projectState = upToDate ? ProjectState.UpToDate : ProjectState.BuildDone;
                }
                else
                {
                    bool canceled = (_buildCancelled && buildedProject.ErrorsBox.ErrorsCount == 0);
                    projectState = canceled ? ProjectState.BuildCancelled : ProjectState.BuildError;
                }
                break;

            case BuildActions.BuildActionClean:
                projectState = success ? ProjectState.CleanDone : ProjectState.CleanError;
                break;

            case BuildActions.BuildActionDeploy:
                throw new InvalidOperationException("vsBuildActionDeploy not supported");

            default:
                throw new ArgumentOutOfRangeException();
            }

            OnBuildProjectDone(this, new BuildProjectEventArgs(currentProject, projectState, eventTime, buildedProject));
        }
        private void BuildEvents_OnBuildBegin(vsBuildScope scope, vsBuildAction action)
        {
            if (action == vsBuildAction.vsBuildActionDeploy)
            {
                return;
            }

            RegisterLogger();

            CurrentBuildState = BuildState.InProgress;

            BuildStartTime  = DateTime.Now;
            BuildFinishTime = null;
            BuildAction     = (BuildActions)action;

            switch (scope)
            {
            case vsBuildScope.vsBuildScopeSolution:
            case vsBuildScope.vsBuildScopeBatch:
            case vsBuildScope.vsBuildScopeProject:
                BuildScope = (BuildScopes)scope;
                break;

            case 0:
                // Scope may be 0 in case of Clean solution, then Start (F5).
                BuildScope = (BuildScopes)vsBuildScope.vsBuildScopeSolution;
                break;

            default:
                throw new ArgumentOutOfRangeException("scope");
            }

            if (scope == vsBuildScope.vsBuildScopeProject)
            {
                var selectedProjects = _packageContext.GetDTE().ActiveSolutionProjects as object[];
                if (selectedProjects?.Length == 1)
                {
                    var projectItem = new ProjectItem();
                    ViewModelHelper.UpdateProperties((Project)selectedProjects[0], projectItem);
                    BuildScopeProject = projectItem;
                }
            }

            _buildCancelled           = false;
            _buildCancelledInternally = false;

            BuildedProjects.Clear();
            lock (_buildingProjectsLockObject)
            {
                BuildingProjects.Clear();
            }

            BuildedSolution = null;
            var solution = _packageContext.GetDTE().Solution;

            BuildingSolution = new BuildedSolution(solution.FullName, solution.FileName);

            OnBuildBegin(this, EventArgs.Empty);

            _buildProcessCancellationToken = new CancellationTokenSource();
            Task.Factory.StartNew(BuildEvents_BuildInProcess, _buildProcessCancellationToken.Token, _buildProcessCancellationToken.Token);
        }
        private void BuildEvents_OnBuildProjectDone(string project, string projectconfig, string platform, string solutionconfig, bool success)
        {
            if (BuildAction == BuildActions.BuildActionDeploy)
            {
                return;
            }

            var eventTime      = DateTime.Now;
            var currentProject = GetCurrentProject(project, projectconfig, platform);

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

            BuildedProject buildedProject = BuildedProjects[currentProject];

            buildedProject.Success = success;

            ProjectState projectState;

            switch (BuildAction)
            {
            case BuildActions.BuildActionBuild:
            case BuildActions.BuildActionRebuildAll:
                if (success)
                {
                    if (_viewModel.ControlSettings.GeneralSettings.ShowWarningSignForBuilds && buildedProject.ErrorsBox.WarningsCount > 0)
                    {
                        projectState = ProjectState.BuildWarning;
                    }
                    else
                    {
                        bool upToDate = (_buildLogger != null && _buildLogger.Projects != null &&
                                         !_buildLogger.Projects.Exists(t => t.FileName == buildedProject.FileName));
                        if (upToDate)
                        {
                            // Because ErrorBox will be empty if project is UpToDate.
                            buildedProject.ErrorsBox = currentProject.ErrorsBox;
                        }
                        projectState = upToDate ? ProjectState.UpToDate : ProjectState.BuildDone;
                    }
                }
                else
                {
                    bool canceled = (_buildCancelled && buildedProject.ErrorsBox.ErrorsCount == 0);
                    projectState = canceled ? ProjectState.BuildCancelled : ProjectState.BuildError;
                }
                break;

            case BuildActions.BuildActionClean:
                projectState = success ? ProjectState.CleanDone : ProjectState.CleanError;
                break;

            case BuildActions.BuildActionDeploy:
                throw new InvalidOperationException("vsBuildActionDeploy not supported");

            default:
                throw new ArgumentOutOfRangeException(nameof(BuildAction));
            }

            buildedProject.ProjectState = projectState;
            OnBuildProjectDone(this, new BuildProjectEventArgs(currentProject, projectState, eventTime, buildedProject));
        }