public static AdornmentOptions GetAdornmentOptions(ContractOptionsPage options) { var result = AdornmentOptions.None; if (options == null) { return(result); } if (options.SmartFormatting) { result = result | AdornmentOptions.SmartFormatting; } if (options.SyntaxColoring) { result = result | AdornmentOptions.SyntaxColoring; } if (options.CollapseMetadataContracts) { result = result | AdornmentOptions.CollapseWithRegion; } return(result); }
/// <summary> /// Registers this component and hooks this up for solution events. /// </summary> protected override void Initialize() { Logger.PublicEntry(() => { base.Initialize(); //Grab the options page this.vsOptionsPage = GetDialogPage(typeof(ContractOptionsPage)) as ContractOptionsPage; if (VSOptionsPage == null) { //If we can't get our options page, just use the default options this.vsOptionsPage = new ContractOptionsPage(); Logger.WriteAlways("Error: Options page 'Code Contracts Editor Extensions' could not be found!"); } Logger.EnableLogging = VSOptionsPage.Logging; #if LEADERBOARD //Tell leaderboard our startup options LeaderBoard.LeaderBoardAPI.SendLeaderBoardFeatureUse(VSOptionsPage.Options.GetId() | (int)LeaderBoardMasks.CodeContractsHelperId); #endif QueueWorkItem(() => { _outputPane = GetOutputPane(VSConstants.SID_SVsGeneralOutputWindowPane, "Code Contracts Editor Extensions"); }); //TODO: Is this the best place for this code? if (Logger.EnableLogging) { try { if (!String.IsNullOrEmpty(VSOptionsPage.OutputPath) && Directory.Exists(VSOptionsPage.OutputPath)) { _processIdUsedByStreamWriter = System.Diagnostics.Process.GetCurrentProcess().Id; _outputStream = File.CreateText(Path.Combine(VSOptionsPage.OutputPath, String.Format("ContractsHelperLog_{0}.txt", _processIdUsedByStreamWriter))); _outputStream.WriteLine("Log for Code Contracts Visual Studio Extension. Start time: " + _startTime); } else { //TODO: Failed to get output path! } } catch #if DEBUG (Exception exn) { //TODO: What to do on shipping? System.Windows.MessageBox.Show(@"An exception was thrown while trying to create a log file. Please send a picture of this stack trace to " + CrashMailRecepients + "\nException: " + exn, "Sorry!", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information, System.Windows.MessageBoxResult.OK, System.Windows.MessageBoxOptions.None); #else { #endif _outputStream = null; } } #region Register this component IOleComponentManager componentManager = (IOleComponentManager)this.GetService(typeof(SOleComponentManager)); if (_componentID == 0 && componentManager != null) { OLECRINFO[] crinfo = new OLECRINFO[1]; crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO)); crinfo[0].grfcrf = (uint)_OLECRF.olecrfNeedIdleTime | (uint)_OLECRF.olecrfNeedPeriodicIdleTime; crinfo[0].grfcadvf = (uint)_OLECADVF.olecadvfModal | (uint)_OLECADVF.olecadvfRedrawOff | (uint)_OLECADVF.olecadvfWarningsOff; crinfo[0].uIdleTimeInterval = 1000; ErrorHandler.ThrowOnFailure(componentManager.FRegisterComponent(this, crinfo, out _componentID)); } #endregion #region Hook up solution events // Attach to solution events var solution = GetService(typeof(SVsSolution)) as IVsSolution; if (solution != null) { uint solutionEventsCookie; solution.AdviseSolutionEvents(this, out solutionEventsCookie); } // Attach to build events var buildManager = GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager; if (buildManager != null) { uint buildManagerCookie; // TODO: add dispose and unregister buildManager.AdviseUpdateSolutionEvents(this, out buildManagerCookie); } _dte = GetService <DTE>(); #endregion }, "Initialize"); }