public int OnAfterOpenProject(IVsHierarchy pHierarchy, int fAdded)
        {
            var project = pHierarchy.ToProject();

            if (!project.IsGaugeProject())
            {
                return(VSConstants.S_OK);
            }

            var slugifiedName = project.SlugifiedName();

            if (GaugeService.Instance.ContainsApiConnectionFor(slugifiedName))
            {
                return(VSConstants.S_OK);
            }

            try
            {
                StatusBarLogger.Log($"Initializing Gauge daemon for Project: {project.Name}");
                GaugeService.Instance.RegisterGaugeProject(project, _gaugeDaemonOptions.MinPortRange,
                                                           _gaugeDaemonOptions.MaxPortRange);
                StatusBarLogger.Log($"Initializing Gauge Project Cache: {project.Name}");
                ProjectFactory.Initialize(project);
            }
            catch (Exception ex)
            {
                OutputPaneLogger.Error($"Failed to start Gauge Daemon: {ex}");
                return(VSConstants.S_FALSE);
            }

            return(VSConstants.S_OK);
        }
        public int OnBeforeCloseProject(IVsHierarchy pHierarchy, int fRemoved)
        {
            var project       = pHierarchy.ToProject();
            var slugifiedName = project.SlugifiedName();

            StatusBarLogger.Log($"Clearing Gauge Project Cache: {project.Name}");
            ProjectFactory.Delete(project.SlugifiedName());
            GaugeService.Instance.KillChildProcess(slugifiedName);
            GaugeService.Reset();
            return(VSConstants.S_OK);
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InliningAnalyzerCommands"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        private async Task InitializeAsync()
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var dte2 = (DTE2)Package.GetGlobalService(typeof(SDTE));

            _serviceProvider = new ServiceProvider(dte2 as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);

            var container = await _package.GetServiceAsync(typeof(Microsoft.VisualStudio.ComponentModelHost.SComponentModel)) as Microsoft.VisualStudio.ComponentModelHost.IComponentModel;

            container.DefaultCompositionService.SatisfyImportsOnce(this);

            _outputLogger    = new OutputWindowLogger(_package);
            _statusBarLogger = new StatusBarLogger(_package);

            OleMenuCommandService commandService = await _package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (commandService != null)
            {
                OleMenuCommand startMenuItem = new OleMenuCommand(StartMenuItemCallback, new CommandID(CommandSet, StartCommandId));
                startMenuItem.BeforeQueryStatus += OnBeforeQueryStatusProject;
                startMenuItem.Enabled            = dte2.Solution.IsOpen;
                commandService.AddCommand(startMenuItem);

                OleMenuCommand startForAssemblyMenuItem = new OleMenuCommand(StartForAssemblyMenuItemCallback, new CommandID(CommandSet, StartForAssemblyCommandId));
                startForAssemblyMenuItem.BeforeQueryStatus += OnBeforeQueryStatusEnabled;
                startForAssemblyMenuItem.Enabled            = dte2.Solution.IsOpen;
                commandService.AddCommand(startForAssemblyMenuItem);

                OleMenuCommand menuItem = new OleMenuCommand(ToggleMenuItemCallback, new CommandID(CommandSet, ToggleCommandId));
                menuItem.BeforeQueryStatus += OnBeforeQueryStatusToggle;
                menuItem.Enabled            = dte2.Solution.IsOpen;
                commandService.AddCommand(menuItem);

                OleMenuCommand optionsMenuItem = new OleMenuCommand(OpenOptionsCallback, new CommandID(CommandSet, OpenOptionsCommandId));
                commandService.AddCommand(optionsMenuItem);

                OleMenuCommand contextMenuItem = new OleMenuCommand(StartForScopeMenuItemCallback, new CommandID(CommandSetContextMenu, StartForScopeCommandId));
                contextMenuItem.BeforeQueryStatus += OnBeforeQueryStatusEnabled;
                contextMenuItem.Enabled            = dte2.Solution.IsOpen;
                commandService.AddCommand(contextMenuItem);
            }
        }
Esempio n. 4
0
#pragma warning restore CS0649

        /// <summary>
        /// Initializes a new instance of the <see cref="InliningAnalyzerCommands"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        private InliningAnalyzerCommands(Package package)
        {
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            var dte2      = (DTE2)Package.GetGlobalService(typeof(SDTE));
            var sp        = new ServiceProvider(dte2 as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
            var container = sp.GetService(typeof(Microsoft.VisualStudio.ComponentModelHost.SComponentModel)) as Microsoft.VisualStudio.ComponentModelHost.IComponentModel;

            container.DefaultCompositionService.SatisfyImportsOnce(this);

            _package         = package;
            _outputLogger    = new OutputWindowLogger(package);
            _statusBarLogger = new StatusBarLogger(package);

            OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (commandService != null)
            {
                OleMenuCommand startMenuItem = new OleMenuCommand(StartMenuItemCallback, new CommandID(CommandSet, StartCommandId));
                startMenuItem.BeforeQueryStatus += OnBeforeQueryStatusStart;
                startMenuItem.Enabled            = dte2.Solution.IsOpen;
                commandService.AddCommand(startMenuItem);

                OleMenuCommand menuItem = new OleMenuCommand(ToggleMenuItemCallback, new CommandID(CommandSet, ToggleCommandId));
                menuItem.BeforeQueryStatus += OnBeforeQueryStatusToggle;
                menuItem.Enabled            = dte2.Solution.IsOpen;
                commandService.AddCommand(menuItem);

                OleMenuCommand optionsMenuItem = new OleMenuCommand(OpenOptionsCallback, new CommandID(CommandSet, OpenOptionsCommandId));
                commandService.AddCommand(optionsMenuItem);

                OleMenuCommand contextMenuItem = new OleMenuCommand(StartForScopeMenuItemCallback, new CommandID(CommandSetContextMenu, StartForScopeCommandId));
                contextMenuItem.Enabled = dte2.Solution.IsOpen;
                commandService.AddCommand(contextMenuItem);
            }
        }
        public bool TryGenerateMethodStub(string selectedClass, ITextSnapshotLine containingLine,
                                          out CodeClass targetClass, out CodeFunction implementationFunction)
        {
            targetClass            = null;
            implementationFunction = null;
            try
            {
                targetClass = _project.FindOrCreateClass(selectedClass);
            }
            catch (ArgumentException ex)
            {
                StatusBarLogger.Log(ex.Message);
                return(false);
            }

            if (targetClass == null)
            {
                return(false);
            }

            EnsureGaugeImport(targetClass);

            var functionName  = _step.Text.ToMethodIdentifier();
            var functionCount = _project.GetFunctionsForClass(targetClass)
                                .Count(element => string.CompareOrdinal(element.Name, functionName) == 0);

            functionName = functionCount == 0 ? functionName : functionName + functionCount;

            try
            {
                implementationFunction = targetClass.AddFunction(functionName,
                                                                 vsCMFunction.vsCMFunctionFunction, vsCMTypeRef.vsCMTypeRefVoid, -1,
                                                                 vsCMAccess.vsCMAccessPublic, null);

                var parameterList = _step.Parameters;
                parameterList.Reverse();

                if (_step.HasInlineTable)
                {
                    implementationFunction.AddParameter("table", typeof(Table).Name);
                    parameterList.RemoveAt(0);
                }

                foreach (var parameter in parameterList)
                {
                    if (IsSpecialParameter(parameter))
                    {
                        AddSpecialParam(implementationFunction, parameter);
                    }
                    else
                    {
                        var newName = GenerateNewParameterIdentifier(implementationFunction, parameter);
                        implementationFunction.AddParameter(newName, vsCMTypeRef.vsCMTypeRefString);
                    }
                }

                AddStepAttribute(implementationFunction, _step.Text);
            }
            catch
            {
                if (implementationFunction != null)
                {
                    targetClass.RemoveMember(implementationFunction);
                }
                return(false);
            }
            finally
            {
                targetClass.ProjectItem.Save();
            }
            return(true);
        }