private static object GetProjectItemParentViaReflection(ProjectItem projectItem)
        {
            try
            {
                object projectItemParentViaReflection;

                if (TryGetProjectItemParentViaReflection(projectItem, out projectItemParentViaReflection))
                {
                    return(projectItemParentViaReflection);
                }
            }
            catch (Exception exception)
            {
                //We catch everything as a multitude of Exceptions can be thrown if the projectItem.Object is not structured as we assume
                OutputWindowHandler.WriteMessage(
                    string.Format(
                        "Exception got thrown when searching for the LicenseHeaderFile on ProjectItem of Type '{0}' with the name '{1}'. " + "Exception: {2}",
                        projectItem.GetType().FullName,
                        projectItem.Name,
                        exception));
            }

            OutputWindowHandler.WriteMessage(
                string.Format(
                    "Could not find .licenseheaderfile for {0}." +
                    "This is probably due to a custom project type." +
                    "Please report the issue and include the type of your project in the description.",
                    projectItem.Name));

            return(null);
        }
Esempio n. 2
0
        public void Run(object solutionObject)
        {
            Solution solution = solutionObject as Solution;

            if (solution == null)
            {
                return;
            }

            try
            {
                _solutionLevelCommand.Execute(solution);
            }
            catch (Exception exception)
            {
                MessageBoxHelper.Information(
                    string.Format(
                        "The command '{0}' failed with the exception '{1}'. See Visual Studio Output Window for Details.",
                        _solutionLevelCommand.GetCommandName(),
                        exception.Message));
                OutputWindowHandler.WriteMessage(exception.ToString());
            }

            ThreadDone?.Invoke(this, EventArgs.Empty);
        }
        public static bool ExecuteCommandIfExists(string command, DTE2 dte)
        {
            if (dte.Commands.Cast <Command>().Any(dtecommand => dtecommand.Name == command))
            {
                try
                {
                    dte.ExecuteCommand(command);
                    OutputWindowHandler.WriteMessage("Command executed");
                }
                catch (COMException e)
                {
                    if (command == "ReSharper_Suspend")
                    {
                        OutputWindowHandler.WriteMessage("Excecution of '" + command +
                                                         "' failed. Maybe ReSharper is already suspended? \n " + e.ToString());
                    }
                    else
                    {
                        //Command may be found but cannot be executed
                        OutputWindowHandler.WriteMessage("Excecution of '" + command + "' failed. \n " + e.ToString());
                    }
                    return(false);
                }
                return(true);
            }

            return(false);
        }
        protected void LoadRegistryValuesBefore_3_0_0(DialogPage dialogPage = null)
        {
            using (var key = GetOldRegistryKey())
            {
                foreach (var property in GetVisibleProperties())
                {
                    var converter     = GetPropertyConverterOrDefault(property);
                    var registryValue = GetRegistryValue(key, property.Name);

                    if (registryValue != null)
                    {
                        try
                        {
                            property.SetValue(
                                dialogPage ?? AutomationObject,
                                DeserializeValue(converter, registryValue));
                        }
                        catch (Exception)
                        {
                            OutputWindowHandler.WriteMessage($"Could not restore registry value for {property.Name}");
                        }
                    }
                }
            }
        }
        private string GetProperFileNameCapitalization(FileInfo fileInfo)
        {
            try
            {
                return(Path.GetFileName(PathUtility.GetProperFilePathCapitalization(fileInfo)));
            }
            catch (Exception e)
            {
                OutputWindowHandler.WriteMessage("Could not get proper file name capitalization.");
                OutputWindowHandler.WriteMessage("Falling back to name as we receive it from 'FileInfo'.");
                OutputWindowHandler.WriteMessage(e.ToString());

                //Use the FileName in the same capitalization as we got it
                return(fileInfo.Name);
            }
        }
Esempio n. 6
0
        private static object GetProjectItemParent(ProjectItem projectItem)
        {
            object projectItemParent = null;

            //Folder Items in Custom Projects behave different than their ComObject counterparts.
            if (projectItem.GetType().FullName == "Microsoft.VisualStudioTools.Project.Automation.OAFolderItem")
            {
                try
                {
                    if (projectItem.Object == null)
                    {
                        OutputWindowHandler.WriteMessage(
                            string.Format(
                                "Property 'Object' of the FolderItem of Type {0} is null. Can't find LicenseHeaderFile.",
                                projectItem.GetType().FullName));
                    }
                    else
                    {
                        var parentProperty = projectItem.Object.GetType().GetProperty("Parent").GetValue(projectItem.Object, null);
                        var parentUrl      = parentProperty.GetType().GetProperty("Url").GetValue(parentProperty, null) as string;
                        projectItemParent = projectItem.DTE.Solution.FindProjectItem(parentUrl);

                        //If the ProjectItemParent could not be found by "FindProjectItem" this means we are a Folder at TopLevel and only the ContainingProject is above us
                        if (projectItemParent == null)
                        {
                            projectItemParent = projectItem.ContainingProject;
                        }
                    }
                }
                catch (Exception exception)
                {
                    //We catch everything as a multitude of Execptions can be thrown if the projectItem.Object is not structured as we assume
                    OutputWindowHandler.WriteMessage(
                        string.Format(
                            "Exception got thrown when searching for the LicenseHeaderFile on FolderItem of Type '{0}'. Exception: {1}",
                            projectItem.GetType().FullName,
                            exception));
                }
            }
            else
            {
                projectItemParent = projectItem.Collection.Parent;
            }

            return(projectItemParent);
        }
Esempio n. 7
0
        private static void TryLookupNow()
        {
            try
            {
                _displayName      = UserPrincipal.Current.DisplayName;
                _lookupSuccessful = true;
            }
            catch (Exception e)
            {
                string OutputMessage = string.Format(Resources.UserInfo_LookupFailure_Information, e).Replace(@"\n", "\n");

                if (e is FileNotFoundException)
                {
                    OutputMessage = string.Format(Resources.UserInfo_LookupFailure_FileNotFoundException_Information).Replace(@"\n", "\n");
                }

                OutputWindowHandler.WriteMessage(OutputMessage);
                _displayName      = Resources.UserInfo_UnknownDisplayNameString;
                _lookupSuccessful = false;
            }
        }