示例#1
0
        static void Main(string[] args)
        {
            ObjectFactory.Configure(a =>
            {
                a.For <IAchievementRepository>().Singleton().Use <AppDataXmlCompletedAchievementsRepository>();
            });
            var fullChain = true;

            var cultureToTest = "ru-RU"; // Set to "ru-RU" to enable russian. Set to "nl" for dutch

            // Comment the following line to use operating system default culture.
            //Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureToTest);

            if (!fullChain)
            {
                using (IParser parser = ParserFactory.CreateParser(System.IO.Path.GetFullPath("TestFile.cs")))
                {
                    parser.Parse();

                    // Allows retrieving comments, preprocessor directives, etc. (stuff that isn't part of the syntax)
                    var specials = parser.Lexer.SpecialTracker.RetrieveSpecials();

                    // Retrieves the root node of the result AST
                    var result = parser.CompilationUnit;

                    if (parser.Errors.Count > 0)
                    {
                        MessageBox.Show(parser.Errors.ErrorOutput, "Parse errors");
                    }

                    result.AcceptVisitor(new AchievementVisitor(), null);
                }

                System.Console.Read();
            }
            else
            {
                AchievementContext.AchievementsUnlocked += AchievementContext_AchievementsUnlocked;
                GuiInitializer.Initialize();

                var achievementDescriptorRepository = ObjectFactory.GetInstance <IAchievementRepository>();
                achievementDescriptorRepository.LoadFromAssembly(typeof(AnonymousObjectAchievement).Assembly);
                achievementDescriptorRepository.ResetAchievements();

                DetectionDispatcher.DetectionCompleted += DetectionDispatcher_DetectionCompleted;
                var file = System.IO.Path.GetFullPath("TestFile.cs");
                DetectionDispatcher.Dispatch(new BuildInformation()
                {
                    ActiveFile   = file,
                    ChangedFiles = new string[] { file },
                    CodeFiles    = new string[] { file }
                });

                System.Console.Read();
            }
        }
示例#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);
        }