Example #1
0
        private void OnBuildBegin(vsBuildScope Scope, vsBuildAction Action)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            switch (State)
            {
            case StateType.Idle:
                SetState(StateType.BuildingExternal);
                break;

            case StateType.Triggering:
                PrepareGathering();
                OutputLog.Log("Building...");
                SetState(StateType.Building);
                break;
            }
        }
Example #2
0
        public void Save()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (Filename != null && Settings != null)
            {
                try
                {
                    string jsonString = JsonConvert.SerializeObject(Settings, Formatting.Indented);
                    File.WriteAllText(Filename, jsonString);
                    SettingsChanged?.Invoke();
                }
                catch (Exception e)
                {
                    OutputLog.Error(e.Message);
                }
            }
        }
Example #3
0
        private void Load()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (Filename != null && File.Exists(Filename))
            {
                try
                {
                    string jsonString = File.ReadAllText(Filename);
                    Settings = JsonConvert.DeserializeObject <SolutionSettings>(jsonString);
                    SettingsChanged?.Invoke();
                }
                catch (Exception e)
                {
                    OutputLog.Error(e.Message);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
        /// <param name="progress">A provider for progress updates.</param>
        /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            // When initialized asynchronously, the current thread may be a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread.
            await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            OutputLog.Initialize(this);

            DocumentLifetimeManager.Initialize(this);
            SettingsManager.Instance.Initialize();
            CompilerData.Instance.Initialize(this, this);
            EditorUtils.Initialize(this, this);
            Profiler.Instance.Initialize(this);
            Timeline.CompilerTimeline.Instance.Initialize(this);

            EditorContext.Instance.Initialize(this);

            await CustomCommands.InitializeAsync(this);
        }
Example #5
0
        private async System.Threading.Tasks.Task TriggerClangGeneratorAsync()
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            if (!ValidateGenerator())
            {
                return;
            }

            OutputLog.Focus();
            OutputLog.Clear();
            Evaluator.Clear();

            SetState(StateType.Gathering);

            await GenerateClangScoreAsync();

            SetState(StateType.Idle);
        }
Example #6
0
        static private FolderSettings GetConfigurations(string rootPath)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            FolderSettings settings = null;

            string settingsFilename = rootPath + "CMakeSettings.json";

            if (File.Exists(settingsFilename))
            {
                try
                {
                    string jsonString = File.ReadAllText(settingsFilename);
                    settings = JsonConvert.DeserializeObject <FolderSettings>(jsonString);
                }
                catch (Exception e)
                {
                    OutputLog.Error(e.Message);
                }
            }

            return(settings);
        }
        private static void OnWatchedFileChanged(object source, FileSystemEventArgs e)
        {
            DateTime lastWriteTime = File.GetLastWriteTime(_fileWatcherFullPath);

            if ((lastWriteTime - _fileWatcherLastRead).Milliseconds > 100)
            {
                var fileInfo = new FileInfo(_fileWatcherFullPath);
                while (File.Exists(_fileWatcherFullPath) && IsFileLocked(fileInfo))
                {
                    //File is still locked, meaning the writing stream is still writing to the file,
                    // we need to wait until that process is done before trying to refresh it here.
                    System.Threading.Thread.Sleep(500);
                }

                ThreadHelper.JoinableTaskFactory.Run(async delegate {
                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                    OutputLog.Log("File change detected.");
                    FileWatchedChanged?.Invoke();
                });

                _fileWatcherLastRead = lastWriteTime;
            }
        }
Example #8
0
        private async System.Threading.Tasks.Task GatherAsync()
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            OutputLog.Focus();

            SetState(StateType.Gathering);

            DocumentLifetimeManager.UnWatchFile();

            string inputPath    = CompilerSource == Compiler.Clang ? FixPath(Evaluator.Evaluate(SettingsManager.Instance.Settings.ScoreGenerator.InputPath)) : "";
            string inputCommand = inputPath.Length > 0 ? " -i " + inputPath : "";

            string outputPath    = Evaluator.Evaluate(SettingsManager.Instance.Settings.ScoreGenerator.OutputPath);
            string outputCommand = outputPath.Length > 0 ? " -o " + outputPath : "";

            string detail   = " -d " + (int)OverviewDetail;
            string timeline = TimelinePacking == 0 ? " -nt" : " -tp " + TimelinePacking + " -td " + (int)TimelineDetail;

            string commandLine = GetPlatformFlag() + " -stop" + timeline + detail + inputCommand + outputCommand;

            CreateDirectory(Path.GetDirectoryName(outputPath));

            OutputLog.Log("Calling ScoreDataExtractor with " + commandLine);
            int exitCode = ExternalProcess.ExecuteSync(GetScoreExtractorToolPath(), commandLine);

            if (exitCode != 0)
            {
                DisplayError("Score Data Extractor process failed with code " + exitCode + ". Please check the output pane for more information.");
            }

            CompilerData.Instance.ForceLoadFromFilename(outputPath);
            EditorUtils.FocusOverviewWindow();

            OutputLog.Log("Score generation completed!");
            SetState(StateType.Idle);
        }
Example #9
0
        private async System.Threading.Tasks.Task GenerateClangScoreAsync()
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            if (CompilerSource != Compiler.Clang)
            {
                return;
            }

            //Stop watching as the data extractor might modify the watched file
            DocumentLifetimeManager.UnWatchFile();

            //Process Data
            string inputPath  = FixPath(Evaluator.Evaluate(SettingsManager.Instance.Settings.ScoreGenerator.InputPath));
            string outputPath = Evaluator.Evaluate(SettingsManager.Instance.Settings.ScoreGenerator.OutputPath);

            CreateDirectory(Path.GetDirectoryName(outputPath));

            string detail   = " -d " + (int)OverviewDetail;
            string timeline = TimelinePacking == 0 ? " -nt" : " -tp " + TimelinePacking + " -td " + (int)TimelineDetail;

            string commandLine = "-clang -extract" + timeline + detail + " -i " + inputPath + " -o " + outputPath;

            OutputLog.Log("Calling ScoreDataExtractor with " + commandLine);
            int exitCode = await ExternalProcess.ExecuteAsync(GetScoreExtractorToolPath(), commandLine);

            if (exitCode != 0)
            {
                DisplayError("Compile Score Data Extractor process failed with code " + exitCode + ". Please check the output pane for more information.");
            }

            CompilerData.Instance.ForceLoadFromFilename(outputPath);
            EditorUtils.FocusOverviewWindow();

            OutputLog.Log("Score generation completed!");
        }
Example #10
0
        private void LoadSeverities(string fullPath)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            UnitsCollection.Clear();
            Totals.Clear();
            ClearDatasets();

            if (File.Exists(fullPath))
            {
                var watch = System.Diagnostics.Stopwatch.StartNew();

                FileStream fileStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                using (BinaryReader reader = new BinaryReader(fileStream))
                {
                    // Read version
                    uint thisVersion = reader.ReadUInt32();
                    if (thisVersion == VERSION)
                    {
                        // Read Header
                        Timeline.CompilerTimeline.Instance.TimelinePacking = reader.ReadUInt32();

                        // Read Units
                        uint unitsLength = reader.ReadUInt32();
                        var  unitList    = new List <UnitValue>((int)unitsLength);
                        for (uint i = 0; i < unitsLength; ++i)
                        {
                            ReadCompileUnit(reader, unitList, i);
                        }

                        UnitsCollection = new List <UnitValue>(unitList);

                        //Read Datasets
                        for (int i = 0; i < (int)CompileThresholds.Gather; ++i)
                        {
                            uint dataLength = reader.ReadUInt32();
                            var  thislist   = new List <CompileValue>((int)dataLength);
                            for (uint k = 0; k < dataLength; ++k)
                            {
                                ReadCompileValue(reader, thislist);
                            }
                            Datasets[i].collection = new List <CompileValue>(thislist);
                        }
                    }
                    else
                    {
                        OutputLog.Error("Version mismatch! Expected " + VERSION + " - Found " + thisVersion + " - Please export again with matching Data Exporter");
                    }
                }

                fileStream.Close();

                //Post process on read data
                PostProcessLoadedData();

                watch.Stop();
                const long TicksPerMicrosecond = (TimeSpan.TicksPerMillisecond / 1000);
                ulong      microseconds        = (ulong)(watch.ElapsedTicks / TicksPerMicrosecond);
                OutputLog.Log("Score file processed in " + Common.UIConverters.GetTimeStr(microseconds));
            }

            RecomputeSeverities();

            ScoreDataChanged?.Invoke();
        }