Exemplo n.º 1
0
        /// <summary>
        /// Called when a build is completed.
        /// </summary>
        /// <param name="fSucceeded"><c>true</c> if no update actions failed.</param>
        /// <param name="fModified"><c>true</c> if any update action succeeded.</param>
        /// <param name="fCancelCommand"><c>true</c> if update actions were canceled.</param>
        /// <returns>
        /// If the method succeeds, it returns <c>S_OK</c>. If it fails, it returns an error code.
        /// </returns>
        int IVsUpdateSolutionEvents.UpdateSolution_Done(int fSucceeded, int fModified, int fCancelCommand)
        {
            if (fSucceeded != 0)
            {
                try
                {
                    ProjectTypeDef projectTypeDef = null;

                    if (dte.ActiveDocument != null && dte.ActiveDocument.ProjectItem != null && dte.ActiveDocument.ProjectItem.ContainingProject != null)
                    {
                        var containingProject = dte.ActiveDocument.ProjectItem.ContainingProject;

                        var projectFile = containingProject.FileName;
                        if (!string.IsNullOrEmpty(projectFile) && !projectTypeDefCache.TryGetValue(projectFile, out projectTypeDef))
                        {
                            XNamespace ns = "http://schemas.microsoft.com/developer/msbuild/2003";
                            var csProj = XDocument.Load(containingProject.FileName);
                            var strokesAchievementTypeNodes = csProj.Descendants(ns + "StrokesProjectType");
                            var strokesAchievementTypeNode = strokesAchievementTypeNodes.FirstOrDefault();
                            if (strokesAchievementTypeNode != null && strokesAchievementTypeNode.HasElements)
                            {
                                projectTypeDef = new ProjectTypeDef()
                                {
                                    IsAchievementProject = strokesAchievementTypeNode.Elements().Any(a => a.Name == ns + "Achievements" && a.Value == "true"),
                                    IsChallengeProject = strokesAchievementTypeNode.Elements().Any(a => a.Name == ns + "Challenges" && a.Value == "true")
                                };

                                projectTypeDefCache.Add(projectFile, projectTypeDef);
                            }
                        }
                    }

                    if (projectTypeDef == null)
                    {
                        projectTypeDef = new ProjectTypeDef(); // Assume default values (false, false);
                    }

                    // Return out if we're not compiling an achievement project.
                    if (!projectTypeDef.IsAchievementProject && !projectTypeDef.IsChallengeProject)
                    {
                        return VSConstants.S_OK;
                    }

                    // Get all .cs files in solution projects, that has changed since lastAchievementCheck
                    var changedFiles = FileTracker.GetFiles(dte.Solution);

                    // Update lastAchievementCheck
                    lastAchievementCheck = DateTime.Now;

                    // Construct build information
                    var buildInformation = new StaticAnalysisManifest();
                    buildInformation.CodeFiles = FileTracker.GetFiles(dte.Solution).ToArray();

                    var activeDocument = dte.ActiveDocument;
                    if (activeDocument != null)
                    {
                        var documentFile = activeDocument.FullName;

                        if (documentFile.EndsWith(".cs"))
                        {
                            buildInformation.ActiveFile = documentFile;

                            if (!changedFiles.Contains(documentFile))
                            {
                                // Always check active document.
                                changedFiles.Add(documentFile);
                            }

                            // Fill relevant values on StaticAnalysisManifest
                            var projectItem = activeDocument.ProjectItem.ContainingProject;
                            buildInformation.ActiveProject = projectItem.FileName;
                            buildInformation.ActiveProjectOutputDirectory = FileTracker.GetProjectOutputDirectory(projectItem);
                        }
                    }

                    buildInformation.ChangedFiles = changedFiles.ToArray();

                    // Validate build information
                    if (buildInformation.ActiveProject == null && buildInformation.ChangedFiles.Length == 0)
                    {
                        // Build information contains nothing - so we won't detect achievements
                        return VSConstants.S_OK;
                    }

                    // Lock builds while detection is occuring - this prevents parallel detection
                    isAchievementDetectionRunning = true;
                    _achievementService.PerformStaticAnalysis(buildInformation, true);
                }
                finally
                {
                    // Unlock builds
                    isAchievementDetectionRunning = false;
                }
            }

            return VSConstants.S_OK;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called when a build is completed.
        /// </summary>
        /// <param name="fSucceeded"><c>true</c> if no update actions failed.</param>
        /// <param name="fModified"><c>true</c> if any update action succeeded.</param>
        /// <param name="fCancelCommand"><c>true</c> if update actions were canceled.</param>
        /// <returns>
        /// If the method succeeds, it returns <c>S_OK</c>. If it fails, it returns an error code.
        /// </returns>
        int IVsUpdateSolutionEvents.UpdateSolution_Done(int fSucceeded, int fModified, int fCancelCommand)
        {
            if (fSucceeded != 0)
            {
                try
                {
                    ProjectTypeDef projectTypeDef = null;

                    if (dte.ActiveDocument != null && dte.ActiveDocument.ProjectItem != null && dte.ActiveDocument.ProjectItem.ContainingProject != null)
                    {
                        var containingProject = dte.ActiveDocument.ProjectItem.ContainingProject;

                        var projectFile = containingProject.FileName;
                        if (!string.IsNullOrEmpty(projectFile) && !projectTypeDefCache.TryGetValue(projectFile, out projectTypeDef))
                        {
                            XNamespace ns     = "http://schemas.microsoft.com/developer/msbuild/2003";
                            var        csProj = XDocument.Load(containingProject.FileName);
                            var        strokesAchievementTypeNodes = csProj.Descendants(ns + "StrokesProjectType");
                            var        strokesAchievementTypeNode  = strokesAchievementTypeNodes.FirstOrDefault();
                            if (strokesAchievementTypeNode != null && strokesAchievementTypeNode.HasElements)
                            {
                                projectTypeDef = new ProjectTypeDef()
                                {
                                    IsAchievementProject = strokesAchievementTypeNode.Elements().Any(a => a.Name == ns + "Achievements" && a.Value == "true"),
                                    IsChallengeProject   = strokesAchievementTypeNode.Elements().Any(a => a.Name == ns + "Challenges" && a.Value == "true")
                                };

                                projectTypeDefCache.Add(projectFile, projectTypeDef);
                            }
                        }
                    }

                    if (projectTypeDef == null)
                    {
                        projectTypeDef = new ProjectTypeDef(); // Assume default values (false, false);
                    }

                    // Return out if we're not compiling an achievement project.
                    if (!projectTypeDef.IsAchievementProject && !projectTypeDef.IsChallengeProject)
                    {
                        return(VSConstants.S_OK);
                    }

                    // Get all .cs files in solution projects, that has changed since lastAchievementCheck
                    var changedFiles = FileTracker.GetFiles(dte.Solution);

                    // Update lastAchievementCheck
                    lastAchievementCheck = DateTime.Now;

                    // Construct build information
                    var buildInformation = new BuildInformation();
                    buildInformation.CodeFiles = FileTracker.GetFiles(dte.Solution).ToArray();

                    var activeDocument = dte.ActiveDocument;
                    if (activeDocument != null)
                    {
                        var documentFile = activeDocument.FullName;

                        if (documentFile.EndsWith(".cs"))
                        {
                            buildInformation.ActiveFile = documentFile;

                            if (!changedFiles.Contains(documentFile))
                            {
                                // Always check active document.
                                changedFiles.Add(documentFile);
                            }

                            // Fill relevant values on buildInformation
                            var projectItem = activeDocument.ProjectItem.ContainingProject;
                            buildInformation.ActiveProject = projectItem.FileName;
                            buildInformation.ActiveProjectOutputDirectory = FileTracker.GetProjectOutputDirectory(projectItem);
                        }
                    }

                    buildInformation.ChangedFiles = changedFiles.ToArray();

                    // Validate build information
                    if (buildInformation.ActiveProject == null && buildInformation.ChangedFiles.Length == 0)
                    {
                        // Build information contains nothing - so we won't detect achievements
                        return(VSConstants.S_OK);
                    }

                    // Lock builds while detection is occuring - this prevents parallel detection
                    isAchievementDetectionRunning = true;

                    DetectionDispatcher.Dispatch(buildInformation);
                }
                finally
                {
                    // Unlock builds
                    isAchievementDetectionRunning = false;
                }
            }

            return(VSConstants.S_OK);
        }