Exemplo n.º 1
0
        /// <summary>
        /// Get the value passed in to the specified command line argument key.
        /// </summary>
        public async Task<string> TryGetCommandLineArgumentAsync(string key)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsAppCommandLine acl = await VS.Services.GetAppCommandLineAsync();
            acl.GetOption(key, out _, out string value);

            return value;
        }
        /// <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>
        protected override async System.Threading.Tasks.Task InitializeAsync(System.Threading.CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress);

            // When initialized asynchronously, we *may* be on a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread.
            // Otherwise, remove the switch to the UI thread if you don't need it.
            await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            IVisualStudioServiceProvider serviceProvider = new VisualStudioServiceProvider(this);

            this.messageManager = new VisualStudioMessageManager();
            this.iOWrapper      = new IOWrapper();
            this.projectConfigurationManager = new ProjectConfigurationManager(this.messageManager);
            this.vsPackageWrapper            = new VsPackageWrapper();
            this.projectManager   = new ProjectManager(serviceProvider, iOWrapper, vsPackageWrapper, messageManager, projectConfigurationManager);
            this.authManager      = new AuthenticationManager(messageManager, projectManager);
            this.arasDataProvider = new ArasDataProvider(authManager, messageManager);
            this.dialogFactory    = new DialogFactory(authManager, arasDataProvider, serviceProvider, iOWrapper, messageManager);
            ICodeFormatter codeFormatter = new VisualStudioCodeFormatter(this.projectManager);

            this.codeProviderFactory = new CodeProviderFactory(codeFormatter, messageManager, iOWrapper);
            this.globalConfiguration = new GlobalConfiguration(iOWrapper);
            this.projectUpdater      = new ProjectUpdater(this.iOWrapper);
            this.eventListener       = new EventListener(projectManager, projectUpdater, projectConfigurationManager, iOWrapper);
            this.openContextParser   = new OpenContextParser();
            this.methodOpener        = new MethodOpener(projectManager, dialogFactory, openContextParser, messageManager);

            Commands.OpenFromArasCmd.Initialize(projectManager, authManager, dialogFactory, projectConfigurationManager, codeProviderFactory, messageManager);
            Commands.OpenFromPackageCmd.Initialize(projectManager, authManager, dialogFactory, projectConfigurationManager, codeProviderFactory, messageManager);
            Commands.CreateMethodCmd.Initialize(projectManager, authManager, dialogFactory, projectConfigurationManager, codeProviderFactory, globalConfiguration, messageManager);
            Commands.SaveToArasCmd.Initialize(projectManager, authManager, dialogFactory, projectConfigurationManager, codeProviderFactory, messageManager);
            Commands.SaveToPackageCmd.Initialize(projectManager, authManager, dialogFactory, projectConfigurationManager, codeProviderFactory, messageManager);
            Commands.UpdateMethodCmd.Initialize(projectManager, authManager, dialogFactory, projectConfigurationManager, codeProviderFactory, messageManager);
            Commands.ConnectionInfoCmd.Initialize(projectManager, authManager, dialogFactory, projectConfigurationManager, messageManager);
            Commands.CreateCodeItemCmd.Initialize(projectManager, dialogFactory, projectConfigurationManager, codeProviderFactory, messageManager);
            Commands.RefreshConfigCmd.Initialize(projectManager, dialogFactory, projectConfigurationManager, messageManager);
            Commands.DebugMethodCmd.Initialize(projectManager, authManager, dialogFactory, projectConfigurationManager, codeProviderFactory, messageManager);
            Commands.MoveToCmd.Initialize(projectManager, dialogFactory, projectConfigurationManager, codeProviderFactory, messageManager);
            Commands.ImportOpenInVSActionCmd.Initialize(projectManager, authManager, dialogFactory, projectConfigurationManager, codeProviderFactory, messageManager);

            this.eventListener.StartListening();

            IVsAppCommandLine cmdLine = await GetServiceAsync(typeof(SVsAppCommandLine)) as IVsAppCommandLine;

            ErrorHandler.ThrowOnFailure(cmdLine.GetOption(OpenInVSConstants.ProtocolName, out int isPresent, out string openMethodRequest));
            if (isPresent == 1)
            {
                methodOpener.OpenMethodFromAras(openMethodRequest);
            }
        }
Exemplo n.º 3
0
        // Microsoft.TeamFoundation.Build.Client.GitHelper
        public static IEnumerable <GitRepository> GetGitRepositories()
        {
            List <GitRepository> result      = new List <GitRepository>();
            const string         registryKey = @"Software\Microsoft\VisualStudio\{0}\TeamFoundation\GitSourceControl\Repositories\";
            var    dte = CheckoutAndBuild2Package.GetGlobalService <DTE2>();
            string rootSuffix;

            IVsAppCommandLine vsAppCommandLine = CheckoutAndBuild2Package.GetGlobalService <IVsAppCommandLine>();
            int pos;

            vsAppCommandLine.GetOption("rootsuffix", out pos, out rootSuffix);

            string currentStudioInfo = dte.Version + rootSuffix;

            using (var repoKey = Registry.CurrentUser.OpenSubKey(string.Format(registryKey, currentStudioInfo)))
            {
                if (repoKey != null)
                {
                    foreach (string subKeyName in repoKey.GetSubKeyNames())
                    {
                        using (var detailKey = repoKey.OpenSubKey(subKeyName))
                        {
                            if (detailKey != null)
                            {
                                var name = detailKey.GetValue("Name");
                                var path = detailKey.GetValue("Path");
                                if (name != null && path != null)
                                {
                                    var info = new GitRepository(name.ToString(), path.ToString());
                                    if (!result.Contains(info))
                                    {
                                        result.Add(info);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Checks if the toolbox needs to be initialized, and if so, calls <see cref="ModelingPackage.SetupDynamicToolbox"/>.
        /// </summary>
        private void InitializeToolbox()
        {
#if ALWAYS_REFRESH_EXP_TOOLBOX
            IVsAppCommandLine vsAppCommandLine = (IVsAppCommandLine)base.GetService(typeof(IVsAppCommandLine));
            int    present;
            string optionValue;
            if (vsAppCommandLine == null || ErrorHandler.Failed(vsAppCommandLine.GetOption("RootSuffix", out present, out optionValue)) || !Convert.ToBoolean(present))
            {
                // If we can't obtain the IVsAppCommandLine service, or our call to it fails, or no root suffix was specified, try looking at our registry root.
                IVsShell vsShell = (IVsShell)base.GetService(typeof(SVsShell));
                object   registryRootObject;
                if (vsShell == null || ErrorHandler.Failed(vsShell.GetProperty((int)__VSSPROPID.VSSPROPID_VirtualRegistryRoot, out registryRootObject)) || ((string)registryRootObject).EndsWith("EXP", StringComparison.OrdinalIgnoreCase))
                {
                    // If we can't get the registry root, or if it says we are running in the experimental hive, call SetupDynamicToolbox.
                    base.SetupDynamicToolbox();
                }
                else
                {
#endif // ALWAYS_REFRESH_EXP_TOOLBOX
            RegistryKey userRegistryRoot    = null;
            RegistryKey packageRegistryRoot = null;
            RegistryKey toolboxRevisionsKey = null;
            IDictionary <string, ToolboxProviderInfo> providers = GetToolboxProviderInfoMap();
            bool refreshRequired = false;
            try
            {
                userRegistryRoot = this.UserRegistryRoot;
                // Note that we could do this twice, once to verify in read mode and a second time to write the
                // values back out, but it isn't work the extra hassle to do this twice simply to avoid a write
                // permission check on a user registry key.
                packageRegistryRoot = userRegistryRoot.OpenSubKey(REGISTRYROOT_PACKAGE_USER, RegistryKeyPermissionCheck.ReadWriteSubTree);
                bool hadRegistryRoot = packageRegistryRoot != null;
                bool hadRevisionsKey = false;

                // If the toolbox has the correct values for all domain models that provide toolbox items,
                // then we don't do anything.
                if (hadRegistryRoot)
                {
                    // Remove obsolete data
                    packageRegistryRoot.DeleteValue(REGISTRYVALUE_TOOLBOXREVISION_OBSOLETESINGLEVALUE, false);

                    // Get new key information
                    toolboxRevisionsKey = packageRegistryRoot.OpenSubKey(REGISTRYKEY_TOOLBOXREVISIONS, RegistryKeyPermissionCheck.ReadWriteSubTree);
                    hadRevisionsKey     = toolboxRevisionsKey != null;
                }
                else
                {
                    packageRegistryRoot = userRegistryRoot.CreateSubKey(REGISTRYROOT_PACKAGE_USER, RegistryKeyPermissionCheck.ReadWriteSubTree);
                }
                if (!hadRevisionsKey)
                {
                    toolboxRevisionsKey = packageRegistryRoot.CreateSubKey(REGISTRYKEY_TOOLBOXREVISIONS, RegistryKeyPermissionCheck.ReadWriteSubTree);
                }

                string[] valueNames = hadRevisionsKey ? toolboxRevisionsKey.GetValueNames() : null;
                int      matchIndex;
                int      hitCount = 0;
                foreach (KeyValuePair <string, ToolboxProviderInfo> providerInfo in providers)
                {
                    int    assemblyRevision = providerInfo.Value.ExpectedRevisionNumber;
                    string typeFullName     = providerInfo.Key;
                    if (hadRevisionsKey && -1 != (matchIndex = Array.IndexOf <string>(valueNames, typeFullName)))
                    {
                        string valueName = valueNames[matchIndex];
                        valueNames[matchIndex] = null;
                        ++hitCount;
                        if (assemblyRevision != 0)
                        {
                            int?revision = toolboxRevisionsKey.GetValue(valueName, null) as int?;
                            if (revision.HasValue)
                            {
                                if (assemblyRevision != revision.Value)
                                {
                                    refreshRequired = true;
                                    toolboxRevisionsKey.SetValue(valueName, assemblyRevision, RegistryValueKind.DWord);
                                }
                            }
                            else
                            {
                                // Wrong value kind, delete and readd the value
                                refreshRequired = true;
                                toolboxRevisionsKey.DeleteValue(valueName);
                                toolboxRevisionsKey.SetValue(valueName, assemblyRevision, RegistryValueKind.DWord);
                            }
                        }
                        else
                        {
                            refreshRequired = true;
                            toolboxRevisionsKey.DeleteValue(valueName);
                        }
                    }
                    else
                    {
                        refreshRequired = true;
                        if (assemblyRevision != 0)
                        {
                            toolboxRevisionsKey.SetValue(typeFullName, assemblyRevision, RegistryValueKind.DWord);
                        }
                    }
                }
                if (hadRevisionsKey && hitCount != valueNames.Length)
                {
                    refreshRequired = true;
                    for (int i = 0; i < valueNames.Length; ++i)
                    {
                        string removeValue = valueNames[i];
                        if (removeValue != null)
                        {
                            toolboxRevisionsKey.DeleteValue(removeValue, false);
                        }
                    }
                }
            }
            catch (System.Security.SecurityException ex)
            {
                Debug.Fail("A security exception occurred while trying to write the current toolbox format revision number to the user registry. " +
                           "You can safely continue execution of the program.", ex.ToString());
                // Swallow the exception, since it won't actually cause a problem. The next time the package is loaded, we'll just initialize the toolbox again.
            }
            finally
            {
                if (userRegistryRoot != null)
                {
                    if (packageRegistryRoot != null)
                    {
                        if (toolboxRevisionsKey != null)
                        {
                            toolboxRevisionsKey.Close();
                        }
                        packageRegistryRoot.Close();
                    }
                    userRegistryRoot.Close();
                }
            }

            if (refreshRequired)
            {
                // Since the toolbox has either not been set up before, or is from an older or newer revision, call SetupDynamicToolbox.
                // This might not be necessary if it is from a newer revision, but we do it anyway to be safe.
                base.SetupDynamicToolbox();
            }
#if ALWAYS_REFRESH_EXP_TOOLBOX
        }
    }
    else if (!string.IsNullOrEmpty(optionValue))
    {
        // If any non-empty root suffix was specified as a command line parameter, call SetupDynamicToolbox.
        base.SetupDynamicToolbox();
    }
#endif // ALWAYS_REFRESH_EXP_TOOLBOX
        }