Exemplo n.º 1
0
        private void BuildEvents_OnBuildProjectBegin(object sender, BuildProjectEventArgs e)
        {
            try
            {
                ProjectItem currentProject = e.ProjectItem;
                currentProject.State           = e.ProjectState;
                currentProject.BuildFinishTime = null;
                currentProject.BuildStartTime  = e.EventTime;

                _viewModel.OnBuildProjectBegin();
                if (_buildContext.BuildScope == vsBuildScope.vsBuildScopeSolution &&
                    (_buildContext.BuildAction == vsBuildAction.vsBuildActionBuild ||
                     _buildContext.BuildAction == vsBuildAction.vsBuildActionRebuildAll))
                {
                    currentProject.BuildOrder = _viewModel.BuildProgressViewModel.CurrentQueuePosOfBuildingProject;
                }

                if (!_viewModel.ProjectsList.Contains(currentProject))
                {
                    _viewModel.ProjectsList.Add(currentProject);
                }

                _viewModel.CurrentProject = currentProject;
            }
            catch (Exception ex)
            {
                ex.TraceUnknownException();
            }
        }
 public BuildProjectEventArgs(
     ProjectItem projectItem, 
     ProjectState projectState, 
     DateTime eventTime, 
     BuildedProject buildedProjectInfo)
 {
     ProjectItem = projectItem;
     ProjectState = projectState;
     EventTime = eventTime;
     BuildedProjectInfo = buildedProjectInfo;
 }
Exemplo n.º 3
0
        private bool GetProjectItem(BuildProjectContextEntry projectEntry, out ProjectItem projectItem)
        {
            projectItem = projectEntry.ProjectItem;
            if (projectItem != null)
            {
                return(true);
            }

            string projectFile = projectEntry.FileName;

            if (SolutionProjectsExtensions.ProjectIsHidden(projectFile))
            {
                return(false);
            }

            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);
                projectItem = _findProjectItem(projectDefinition, FindProjectProperty.FullNameProjectDefinition);
                if (projectItem == null)
                {
                    TraceManager.Trace(
                        string.Format("Project Item not found by: FullName='{0}', Configuration='{1}, Platform='{2}'.",
                                      projectDefinition.FullName,
                                      projectDefinition.Configuration,
                                      projectDefinition.Platform),
                        EventLogEntryType.Warning);
                    return(false);
                }
            }
            else
            {
                projectItem = _findProjectItem(projectFile, FindProjectProperty.FullName);
                if (projectItem == null)
                {
                    TraceManager.Trace(
                        string.Format("Project Item not found by FullName='{0}'.", projectFile),
                        EventLogEntryType.Warning);
                    return(false);
                }
            }

            projectEntry.ProjectItem = projectItem;
            return(true);
        }
Exemplo n.º 4
0
        private void BuildEvents_OnBuildProjectDone(object sender, BuildProjectEventArgs e)
        {
            if (e.ProjectState == ProjectState.BuildError && _viewModel.ControlSettings.GeneralSettings.StopBuildAfterFirstError)
            {
                _buildDistributor.CancelBuild();
            }

            try
            {
                ProjectItem currentProject = e.ProjectItem;
                currentProject.State           = e.ProjectState;
                currentProject.BuildFinishTime = DateTime.Now;
                currentProject.UpdatePostBuildProperties(e.BuildedProjectInfo);

                if (!_viewModel.ProjectsList.Contains(currentProject))
                {
                    _viewModel.ProjectsList.Add(currentProject);
                }

                var buildInfo = (BuildInfo)sender;
                if (ReferenceEquals(_viewModel.CurrentProject, e.ProjectItem) && buildInfo.BuildingProjects.Any())
                {
                    _viewModel.CurrentProject = buildInfo.BuildingProjects.Last();
                }
            }
            catch (Exception ex)
            {
                ex.TraceUnknownException();
            }

            _viewModel.UpdateIndicators(_dte, _buildContext);

            try
            {
                _viewModel.OnBuildProjectDone(e.BuildedProjectInfo);
            }
            catch (Exception ex)
            {
                ex.TraceUnknownException();
            }
        }
Exemplo n.º 5
0
        public void UpdateProjects()
        {
            _projects.Clear();

            Solution solution = _storageSolution;
            if (solution == null)
                return;

            IList<Project> dteProjects;
            try
            {
                dteProjects = solution.GetProjects();
            }
            catch (Exception ex)
            {
                ex.TraceUnknownException();
                return;
            }

            var projectItems = new List<ProjectItem>(dteProjects.Count);
            foreach (Project project in dteProjects)
            {
                try
                {
                    var projectItem = new ProjectItem(project);
                    projectItems.Add(projectItem);
                }
                catch (Exception ex)
                {
                    ex.TraceUnknownException();
                }
            }

            _projects.AddRange(projectItems);
        }
Exemplo n.º 6
0
        private static string GetBuildDoneMajorMessage(
            SolutionItem solutionItem,
            BuildInfo buildInfo,
            BuildMessagesSettings labelsSettings)
        {
            if (buildInfo == null)
            {
                return(Resources.BuildDoneText_BuildNotStarted);
            }

            var buildAction = buildInfo.BuildAction;
            var buildScope  = buildInfo.BuildScope;

            if (buildInfo.BuildFinishTime == null)
            {
                throw new InvalidOperationException();
            }

            string timeString;

            try
            {
                timeString = buildInfo.BuildFinishTime.Value.ToString(labelsSettings.DateTimeFormat);
            }
            catch (FormatException)
            {
                timeString = Resources.InvalidTimeStringFormat;
            }

            if (buildAction == null || buildScope == null)
            {
                return(string.Format(Resources.BuildDoneText_NotSupported_BuildActionOrScopeIsNull_CompletedAtTemplate, timeString)); //? WTF???
            }
            string unitName;

            switch (buildScope.Value)
            {
            case vsBuildScope.vsBuildScopeSolution:
                unitName = Resources.BuildScopeSolution_UnitName;
                if (labelsSettings.ShowSolutionName)
                {
                    unitName += string.Format(Resources.BuildScopeSolution_SolutionNameTemplate, solutionItem.Name);
                }
                break;

            case vsBuildScope.vsBuildScopeBatch:
                unitName = Resources.BuildScopeBatch_UnitName;
                break;

            case vsBuildScope.vsBuildScopeProject:
                unitName = Resources.BuildScopeProject_UnitName;
                if (labelsSettings.ShowProjectName)
                {
                    // Skip dependent projects. The last project in the list is the target project.
                    string      uniqProjName = buildInfo.BuildedProjects[buildInfo.BuildedProjects.Count - 1].UniqueName;
                    ProjectItem projItem     = solutionItem.Projects.FirstOrDefault(item => item.UniqueName == uniqProjName);
                    Debug.Assert(projItem != null);

                    unitName += string.Format(Resources.BuildScopeProject_ProjectNameTemplate, projItem.Name);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            string actionName;
            string resultName;

            GetBuildDoneActionAndResultStrings(solutionItem, buildInfo, out actionName, out resultName);

            string mainString;

            switch (labelsSettings.MajorMessageFormat)
            {
            case BuildMajorMessageFormat.Entire:
                mainString = string.Format(Resources.BuildDoneStateLabelTemplate_Default, actionName, unitName, resultName, timeString);
                break;

            case BuildMajorMessageFormat.Unnamed:
                mainString = string.Format(Resources.BuildDoneStateLabelTemplate_ShortForm, actionName, resultName, timeString);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            string resultMainString = string.Format(labelsSettings.BuildDoneMajorMessageStringFormat, mainString);

            return(resultMainString);
        }
        public ProjectItem FindProjectItem(object property, FindProjectProperty findProjectProperty, bool createIfNotFound = true)
        {
            ProjectItem        found;
            List <ProjectItem> projList = ProjectsList.ToList();

            switch (findProjectProperty)
            {
            case FindProjectProperty.UniqueName:
                var uniqueName = (string)property;
                found = projList.Find(item => item.UniqueName == uniqueName);
                break;

            case FindProjectProperty.FullName:
                var fullName = (string)property;
                found = projList.Find(item => item.FullName == fullName);
                break;

            case FindProjectProperty.ProjectObject:
                found = projList.Find(item => ReferenceEquals(item.StorageProject, property));
                break;

            case FindProjectProperty.UniqueNameProjectDefinition:
            {
                var projDef = (UniqueNameProjectDefinition)property;
                found = projList.Find(item => item.UniqueName == projDef.UniqueName &&
                                      item.Configuration == projDef.Configuration &&
                                      PlatformsIsEquals(item.Platform, projDef.Platform));
            }
            break;

            case FindProjectProperty.FullNameProjectDefinition:
            {
                var projDef = (FullNameProjectDefinition)property;
                found = projList.Find(item => item.FullName == projDef.FullName &&
                                      item.Configuration == projDef.Configuration &&
                                      PlatformsIsEquals(item.Platform, projDef.Platform));
            }
            break;

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

            if (found != null)
            {
                return(found);
            }

            Project proj;

            switch (findProjectProperty)
            {
            case FindProjectProperty.UniqueName:
                var uniqueName = (string)property;
                proj = SolutionItem.StorageSolution.GetProject(item => item.UniqueName == uniqueName);
                break;

            case FindProjectProperty.FullName:
                var fullName = (string)property;
                proj = SolutionItem.StorageSolution.GetProject(item => item.FullName == fullName);
                break;

            case FindProjectProperty.ProjectObject:
                proj = SolutionItem.StorageSolution.GetProject(item => ReferenceEquals(item, property));
                break;

            case FindProjectProperty.UniqueNameProjectDefinition:
            {
                var projDef = (UniqueNameProjectDefinition)property;
                proj = SolutionItem.StorageSolution.GetProject(item => item.UniqueName == projDef.UniqueName &&
                                                               item.ConfigurationManager.ActiveConfiguration.ConfigurationName == projDef.Configuration &&
                                                               PlatformsIsEquals(item.ConfigurationManager.ActiveConfiguration.PlatformName, projDef.Platform));
            }
            break;

            case FindProjectProperty.FullNameProjectDefinition:
            {
                var projDef = (FullNameProjectDefinition)property;
                proj = SolutionItem.StorageSolution.GetProject(item => item.FullName == projDef.FullName &&
                                                               item.ConfigurationManager.ActiveConfiguration.ConfigurationName == projDef.Configuration &&
                                                               PlatformsIsEquals(item.ConfigurationManager.ActiveConfiguration.PlatformName, projDef.Platform));
            }
            break;

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

            if (proj == null)
            {
                return(null);
            }

            var newProjItem = new ProjectItem(proj);

            ProjectsList.Add(newProjItem);
            return(newProjItem);
        }
Exemplo n.º 8
0
        public ProjectItem FindProjectItem(object property, FindProjectProperty findProjectProperty, bool createIfNotFound = true)
        {
            ProjectItem found;
            List<ProjectItem> projList = ProjectsList.ToList();
            switch (findProjectProperty)
            {
                case FindProjectProperty.UniqueName:
                    var uniqueName = (string)property;
                    found = projList.Find(item => item.UniqueName == uniqueName);
                    break;

                case FindProjectProperty.FullName:
                    var fullName = (string)property;
                    found = projList.Find(item => item.FullName == fullName);
                    break;

                case FindProjectProperty.ProjectObject:
                    found = projList.Find(item => ReferenceEquals(item.StorageProject, property));
                    break;

                case FindProjectProperty.UniqueNameProjectDefinition:
                    {
                        var projDef = (UniqueNameProjectDefinition)property;
                        found = projList.Find(item => item.UniqueName == projDef.UniqueName
                                                      && item.Configuration == projDef.Configuration
                                                      && PlatformsIsEquals(item.Platform, projDef.Platform));
                    }
                    break;

                case FindProjectProperty.FullNameProjectDefinition:
                    {
                        var projDef = (FullNameProjectDefinition)property;
                        found = projList.Find(item => item.FullName == projDef.FullName
                                                      && item.Configuration == projDef.Configuration
                                                      && PlatformsIsEquals(item.Platform, projDef.Platform));
                    }
                    break;

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

            if (found != null)
                return found;

            Project proj;
            switch (findProjectProperty)
            {
                case FindProjectProperty.UniqueName:
                    var uniqueName = (string)property;
                    proj = SolutionItem.StorageSolution.GetProject(item => item.UniqueName == uniqueName);
                    break;

                case FindProjectProperty.FullName:
                    var fullName = (string)property;
                    proj = SolutionItem.StorageSolution.GetProject(item => item.FullName == fullName);
                    break;

                case FindProjectProperty.ProjectObject:
                    proj = SolutionItem.StorageSolution.GetProject(item => ReferenceEquals(item, property));
                    break;

                case FindProjectProperty.UniqueNameProjectDefinition:
                    {
                        var projDef = (UniqueNameProjectDefinition)property;
                        proj = SolutionItem.StorageSolution.GetProject(item => item.UniqueName == projDef.UniqueName
                                                                && item.ConfigurationManager.ActiveConfiguration.ConfigurationName == projDef.Configuration
                                                                && PlatformsIsEquals(item.ConfigurationManager.ActiveConfiguration.PlatformName, projDef.Platform));
                    }
                    break;

                case FindProjectProperty.FullNameProjectDefinition:
                    {
                        var projDef = (FullNameProjectDefinition)property;
                        proj = SolutionItem.StorageSolution.GetProject(item => item.FullName == projDef.FullName
                                                                && item.ConfigurationManager.ActiveConfiguration.ConfigurationName == projDef.Configuration
                                                                && PlatformsIsEquals(item.ConfigurationManager.ActiveConfiguration.PlatformName, projDef.Platform));
                    }
                    break;

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

            if (proj == null)
                return null;

            var newProjItem = new ProjectItem(proj);
            ProjectsList.Add(newProjItem);
            return newProjItem;
        }
Exemplo n.º 9
0
        private bool GetProjectItem(BuildProjectContextEntry projectEntry, out ProjectItem projectItem)
        {
            projectItem = projectEntry.ProjectItem;
            if (projectItem != null)
                return true;

            string projectFile = projectEntry.FileName;
            if (SolutionProjectsExtensions.ProjectIsHidden(projectFile))
                return false;

            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);
                projectItem = _findProjectItem(projectDefinition, FindProjectProperty.FullNameProjectDefinition);
                if (projectItem == null)
                {
                    TraceManager.Trace(
                        string.Format("Project Item not found by: FullName='{0}', Configuration='{1}, Platform='{2}'.", 
                            projectDefinition.FullName, 
                            projectDefinition.Configuration, 
                            projectDefinition.Platform),
                        EventLogEntryType.Warning);
                    return false;
                }
            }
            else
            {
                projectItem = _findProjectItem(projectFile, FindProjectProperty.FullName);
                if (projectItem == null)
                {
                    TraceManager.Trace(
                        string.Format("Project Item not found by FullName='{0}'.", projectFile),
                        EventLogEntryType.Warning);
                    return false;
                }
            }

            projectEntry.ProjectItem = projectItem;
            return true;
        }