private EnvDTE.Property SetValue()
        {
            try
            {
                property = properties.Item(Name);
                undefine = true;
                return property;
            }
            catch (Exception)
            {
                undefine = false;
            }

            return null;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts the collection of properties passed in into a map
        /// of string -> object.
        /// </summary>
        private Dictionary <string, object> getProperties(EnvDTE.Properties dteProperties)
        {
            Dictionary <string, object> results = new Dictionary <string, object>();

            // Some properties do not seem to have valid values. These are
            // the main ones we have trouble with, so we will ignore them and
            // not try to retrieve their values...
            HashSet <string> slowProperties = new HashSet <string> {
                "WebServer", "ServerExtensionsVersion", "OfflineURL", "WebServerVersion", "WebAccessMethod", "ActiveFileSharePath", "AspnetVersion", "FileSharePath"
            };

            // We loop through the properties...
            int numProperties = Utils.call(() => (dteProperties.Count));

            for (int i = 1; i <= numProperties; ++i)
            {
                try
                {
                    EnvDTE.Property dteProperty  = Utils.call(() => (dteProperties.Item(i)));
                    string          propertyName = Utils.call(() => (dteProperty.Name));
                    if (slowProperties.Contains(propertyName) == true)
                    {
                        // This is one of the properties to ignore...
                        continue;
                    }

                    object propertyValue = Utils.call(() => (dteProperty.Value));
                    results[propertyName] = propertyValue;
                }
                catch (Exception)
                {
                    // Some of the properties don't seem to have valid values.
                    // I'm not really sure why this is. But we silently catch
                    // the exception, as they don't seem to be the properties
                    // we need anyway.
                }
            }

            return(results);
        }
Ejemplo n.º 3
0
        public void Refresh()
        {
            //EnvDTE.Properties props = Common.Instance.DTE.get_Properties(@"VSQuickNavigationPackage", "Settings");
            try
            {
                EnvDTE.Properties props = Common.Instance.DTE2.Properties["QuickNavigation", "Settings"];

                string exts;
                //EnvDTE.Property prop = Utils.DteHelper.GetProperty(props, "ListedExtensions");
                EnvDTE.Property prop = props.Item("");
                if (Utils.DteHelper.GetPropertyString(props, "ListedExtensions", out exts))
                {
                    ListedExtensionsString = exts;
                }
                else
                {
                    ListedExtensions = DefaultListedExtensions;
                }
            }
            catch (Exception)
            { }
        }
Ejemplo n.º 4
0
        public int GetFileCodeModel(object pProj, object pProjectItem, out object ppCodeModel)
        {
            ppCodeModel = null;

            EnvDTE.ProjectItem projectItem = pProjectItem as EnvDTE.ProjectItem;
            if (null == projectItem)
            {
                throw new System.ArgumentException();
            }

            EnvDTE.Property prop = projectItem.Properties.Item("FullPath");
            if (null == prop)
            {
                throw new System.InvalidOperationException();
            }

            string itemPath = prop.Value as string;

            if (string.IsNullOrEmpty(itemPath))
            {
                throw new System.InvalidOperationException();
            }

            foreach (NemerleSourceFileInfo sourceInfo in files.Values)
            {
                if (0 == string.Compare(sourceInfo.Name, itemPath, StringComparison.OrdinalIgnoreCase))
                {
                    ppCodeModel = (object)sourceInfo.FileCodeModel;
                    break;
                }
            }

            if (ppCodeModel == null)
            {
                throw new System.InvalidOperationException();
            }

            return(VSConstants.S_OK);
        }
Ejemplo n.º 5
0
        public static T GetPropertyValue <T>(EnvDTEProject envDTEProject, string propertyName)
        {
            Debug.Assert(envDTEProject != null);
            if (envDTEProject.Properties == null)
            {
                // this happens in unit tests
                return(default(T));
            }

            try
            {
                EnvDTEProperty property = envDTEProject.Properties.Item(propertyName);
                if (property != null)
                {
                    // REVIEW: Should this cast or convert?
                    return((T)property.Value);
                }
            }
            catch (ArgumentException)
            {
            }
            return(default(T));
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Helper function to recursively trigger the NUPlixLoader tool
 /// </summary>
 private static void RunCustomTool(EnvDTE.ProjectItems items, EnvDTE.ProjectItem ignoreItem, ProcessProjectItem itemProcessor)
 {
     foreach (EnvDTE.ProjectItem testItem in items)
     {
         if (!object.ReferenceEquals(testItem, ignoreItem))
         {
             EnvDTE.Property prop = null;
             try
             {
                 prop = testItem.Properties.Item("CustomTool");
             }
             catch (ArgumentException)
             {
                 // Swallow
             }
             if (prop != null && 0 == string.Compare((string)prop.Value, CustomToolName, true, CultureInfo.InvariantCulture))
             {
                 itemProcessor(testItem);
             }
             RunCustomTool(testItem.ProjectItems, ignoreItem, itemProcessor);
         }
     }
 }
Ejemplo n.º 7
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            //string targetDirectory = new FileInfo(this._project.FullName).DirectoryName;

            BizTalkOperations operations = new BizTalkOperations(this.txtDTAServerName.Text, this.txtMgmtDBName.Text);
            TrackingDatabase  dta        = new TrackingDatabase(this.txtDTAServerName.Text,
                                                                this.txtDTADBName.Text);

            if (this.dgMessages.SelectedRows.Count > 0)
            {
                foreach (DataGridViewRow row in this.dgMessages.SelectedRows)
                {
                    IBaseMessage btsMessage            = operations.GetTrackedMessage((Guid)row.Cells["InstanceID"].Value, dta);
                    MultipartMessageDefinition tempMsg = MultipartMessageManager.GenerateFromMessage(btsMessage);

                    string destPath = System.IO.Path.Combine(this._targetFolder,
                                                             String.Format("{0}-{1}-{2}.xml",
                                                                           row.Cells["EventType"].Value,
                                                                           row.Cells["PortName"].Value,
                                                                           row.Cells["InstanceID"].Value));
                    MultipartMessageSerializer.Serialize(tempMsg).Save(destPath);

                    if (this._project != null)
                    {
                        EnvDTE.ProjectItem item = this._project.ProjectItems.AddFromFile(destPath);

                        EnvDTE.Property prop = item.Properties.Item("BuildAction");
                        prop.Value = 2;
                    }
                }
                this.Close();
            }
            else
            {
                MessageBox.Show("Please select one or more messages to generate.", "No message selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Ejemplo n.º 8
0
                #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread
        private bool TrySetBuildActionWithProjectItem(EnvDTE.ProjectItem suppressionFileDteItem, string buildActionToSet)
        {
            if (suppressionFileDteItem == null)
            {
                return(false);
            }

            try
            {
                EnvDTE.Property buildActionProperty = suppressionFileDteItem.Properties.Item("ItemType");

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

                buildActionProperty.Value = buildActionToSet;
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 9
0
        private void setProjLocationChk_CheckedChanged(object sender, EventArgs e)
        {
            if (P4VsProvider.CurrentScm != null)
            {
                string        root = P4VsProvider.CurrentScm.Connection.WorkspaceRoot;
                P4ScmProvider scm  = P4VsProvider.CurrentScm;

                try
                {
                    EnvDTE.Property prop = null;
                    EnvDTE.DTE      dte2;
                    dte2 = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));

                    if (dte2 != null)
                    {
                        EnvDTE.Properties generalPnS = dte2.get_Properties("Environment", "ProjectsAndSolution");
                        foreach (EnvDTE.Property temp in generalPnS)
                        {
                            prop = temp;
                            if (prop.Name == "ProjectsLocation")
                            {
                                if (Directory.Exists(root))
                                {
                                    prop.Value = root;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    string msg = ex.Message;
                    MessageBox.Show(msg, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 10
0
        public async Task <ExecutionResult> Execute(IReplWindow window, string arguments)
        {
            string projectPath  = string.Empty;
            string npmArguments = arguments.Trim(' ', '\t');

            // Parse project name/directory in square brackets
            if (npmArguments.StartsWith("[", StringComparison.Ordinal))
            {
                var match = Regex.Match(npmArguments, @"(?:[[]\s*\""?\s*)(.*?)(?:\s*\""?\s*[]]\s*)");
                projectPath  = match.Groups[1].Value;
                npmArguments = npmArguments.Substring(match.Length);
            }

            // Include spaces on either side of npm arguments so that we can more simply detect arguments
            // at beginning and end of string (e.g. '--global')
            npmArguments = string.Format(CultureInfo.InvariantCulture, " {0} ", npmArguments);

            // Prevent running `npm init` without the `-y` flag since it will freeze the repl window,
            // waiting for user input that will never come.
            if (npmArguments.Contains(" init ") && !(npmArguments.Contains(" -y ") || npmArguments.Contains(" --yes ")))
            {
                window.WriteError(SR.GetString(SR.ReplWindowNpmInitNoYesFlagWarning));
                return(ExecutionResult.Failure);
            }

            var solution = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution;
            IEnumerable <IVsProject> loadedProjects = solution.EnumerateLoadedProjects(onlyNodeProjects: false);

            var projectNameToDirectoryDictionary = new Dictionary <string, Tuple <string, IVsHierarchy> >(StringComparer.OrdinalIgnoreCase);

            foreach (IVsProject project in loadedProjects)
            {
                var    hierarchy = (IVsHierarchy)project;
                object extObject;

                var projectResult = hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out extObject);
                if (!ErrorHandler.Succeeded(projectResult))
                {
                    continue;
                }

                EnvDTE.Project dteProject = extObject as EnvDTE.Project;
                if (dteProject == null)
                {
                    continue;
                }

                string projectName = dteProject.Name;
                if (string.IsNullOrEmpty(projectName))
                {
                    continue;
                }

                // Try checking the `ProjectHome` property first
                EnvDTE.Properties properties = dteProject.Properties;
                if (dteProject.Properties != null)
                {
                    EnvDTE.Property projectHome = null;
                    try {
                        projectHome = properties.Item("ProjectHome");
                    } catch (ArgumentException) {
                        // noop
                    }

                    if (projectHome != null)
                    {
                        var projectHomeDirectory = projectHome.Value as string;
                        if (!string.IsNullOrEmpty(projectHomeDirectory))
                        {
                            projectNameToDirectoryDictionary.Add(projectName, Tuple.Create(projectHomeDirectory, hierarchy));
                            continue;
                        }
                    }
                }

                // Otherwise, fall back to using fullname
                string projectDirectory = string.IsNullOrEmpty(dteProject.FullName) ? null : Path.GetDirectoryName(dteProject.FullName);
                if (!string.IsNullOrEmpty(projectDirectory))
                {
                    projectNameToDirectoryDictionary.Add(projectName, Tuple.Create(projectDirectory, hierarchy));
                }
            }

            Tuple <string, IVsHierarchy> projectInfo;

            if (string.IsNullOrEmpty(projectPath) && projectNameToDirectoryDictionary.Count == 1)
            {
                projectInfo = projectNameToDirectoryDictionary.Values.First();
            }
            else
            {
                projectNameToDirectoryDictionary.TryGetValue(projectPath, out projectInfo);
            }

            NodejsProjectNode nodejsProject = null;

            if (projectInfo != null)
            {
                projectPath = projectInfo.Item1;
                if (projectInfo.Item2 != null)
                {
                    nodejsProject = projectInfo.Item2.GetProject().GetNodejsProject();
                }
            }

            bool isGlobalCommand = false;

            if (string.IsNullOrWhiteSpace(npmArguments) ||
                npmArguments.Contains(" -g ") || npmArguments.Contains(" --global "))
            {
                projectPath     = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
                isGlobalCommand = true;
            }

            // In case someone copies filename
            string projectDirectoryPath = File.Exists(projectPath) ? Path.GetDirectoryName(projectPath) : projectPath;

            if (!isGlobalCommand && !Directory.Exists(projectDirectoryPath))
            {
                window.WriteError("Please specify a valid Node.js project or project directory. If your solution contains multiple projects, specify a target project using .npm [ProjectName or ProjectDir] <npm arguments> For example: .npm [MyApp] list");
                return(ExecutionResult.Failure);
            }

            string npmPath;

            try {
                npmPath = NpmHelpers.GetPathToNpm(
                    nodejsProject != null ?
                    Nodejs.GetAbsoluteNodeExePath(
                        nodejsProject.ProjectHome,
                        nodejsProject.GetProjectProperty(NodeProjectProperty.NodeExePath))
                        : null);
            } catch (NpmNotFoundException) {
                Nodejs.ShowNodejsNotInstalled();
                return(ExecutionResult.Failure);
            }

            var npmReplRedirector = new NpmReplRedirector(window);

            await ExecuteNpmCommandAsync(
                npmReplRedirector,
                npmPath,
                projectDirectoryPath,
                new[] { npmArguments },
                null);

            if (npmReplRedirector.HasErrors)
            {
                window.WriteError(SR.GetString(SR.NpmReplCommandCompletedWithErrors, arguments));
            }
            else
            {
                window.WriteLine(SR.GetString(SR.NpmSuccessfullyCompleted, arguments));
            }

            if (nodejsProject != null)
            {
                await nodejsProject.CheckForLongPaths(npmArguments);
            }

            return(ExecutionResult.Success);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Searches the solution or project for a contained project with a given path.
        /// </summary>
        /// <param name="project">Project node to start the search from, or null to search the solution.</param>
        /// <param name="projectFilePath">Path of the project to be located.</param>
        /// <returns>Found project object, or null if the project was not found.</returns>
        private bool InitReferencedProjectFromProjectItems(System.Collections.IEnumerable /* of project or project items */ inners)
        {
            foreach (object obj in inners)
            {
                EnvDTE.Project prj = obj as EnvDTE.Project;
                if (prj == null)
                {
                    EnvDTE.ProjectItem pi = obj as EnvDTE.ProjectItem;
                    if (pi == null)
                    {
                        continue;
                    }
                    prj = pi.SubProject;
                }
                if (prj == null)
                {
                    continue;
                }

                if (string.Compare(EnvDTE.Constants.vsProjectKindSolutionItems, prj.Kind, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    if (InitReferencedProjectFromProjectItems(prj.ProjectItems))
                    {
                        return(true);
                    }
                    else
                    {
                        continue;
                    }
                }

                //Skip this project if it is an umodeled project (unloaded)
                if (string.Compare(EnvDTE.Constants.vsProjectKindUnmodeled, prj.Kind, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    continue;
                }

                // Skip if has no properties (e.g. "miscellaneous files")
                if (prj.Properties == null)
                {
                    continue;
                }

                // do things differently for C++
                try
                {
                    if (!vcProjectEngineLoaded)
                    {
                        vcProjectEngine       = Assembly.Load("Microsoft.VisualStudio.VCProjectEngine, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
                        vcProjectEngineLoaded = true;
                    }
                }
                catch (FileNotFoundException)
                {
                    // Couldn't load C++ assembly because it doesn't exist.
                    // Continue trying as normal project.
                    vcProjectEngine       = null;
                    vcProjectEngineLoaded = true;
                }
                if (vcProjectEngine != null)
                {
                    Type vcProjectType = vcProjectEngine.GetType("Microsoft.VisualStudio.VCProjectEngine.VCProject", false);
                    if (vcProjectType != null)
                    {
                        if (vcProjectType.IsInstanceOfType(prj.Object))
                        {
                            PropertyInfo vcProjectFileProperty = vcProjectType.GetProperty("ProjectFile", typeof(string));
                            string       projectFilePath       = (string)vcProjectFileProperty.GetValue(prj.Object, null);
                            if (NativeMethods.IsSamePath(projectFilePath, this.referencedProjectFullPath))
                            {
                                this.referencedProject = prj;
                                return(true);
                            }
                            continue;
                        }
                    }
                }


                // Get the full path of the current project.
                EnvDTE.Property pathProperty = null;
                try
                {
                    pathProperty = prj.Properties.Item("FullPath");
                    if (null == pathProperty)
                    {
                        // The full path should alway be availabe, but if this is not the
                        // case then we have to skip it.
                        continue;
                    }
                }
                catch (ArgumentException)
                {
                    continue;
                }
                string          prjPath          = pathProperty.Value.ToString();
                EnvDTE.Property fileNameProperty = null;
                // Get the name of the project file.
                try
                {
                    fileNameProperty = prj.Properties.Item("FileName");
                    if (null == fileNameProperty)
                    {
                        // Again, this should never be the case, but we handle it anyway.
                        continue;
                    }
                }
                catch (ArgumentException)
                {
                    continue;
                }
                prjPath = System.IO.Path.Combine(prjPath, fileNameProperty.Value.ToString());

                // If the full path of this project is the same as the one of this
                // reference, then we have found the right project.
                if (NativeMethods.IsSamePath(prjPath, referencedProjectFullPath))
                {
                    this.referencedProject = prj;
                    return(true);
                }
            }
            return(false);
        }
        private string GetReferencedProjectOutputPath()
        {
            // Make sure that the referenced project implements the automation object.
            if (null == this.ReferencedProject)
            {
                return(null);
            }

            // Get the configuration manager from the project.
            EnvDTE.ConfigurationManager confManager = this.ReferencedProject.ConfigurationManager;
            if (null == confManager)
            {
                return(null);
            }


            // Get the active configuration.
            EnvDTE.Configuration config = null;
            try
            {
                config = confManager.ActiveConfiguration;
            }
            catch (ArgumentException)
            {
                // 4951: exeception happens sometimes when ToolBox queries references on worker thread
                // (apparently hitting a race or bad state of referenced project's ConfigurationManager)
                return(null);
            }
            if (null == config)
            {
                return(null);
            }

            // Get the output path for the current configuration.
            string outputPath = null;

            try
            {
                EnvDTE.Property outputPathProperty = config.Properties.Item("OutputPath");
                if (null == outputPathProperty)
                {
                    return(null);
                }
                outputPath = outputPathProperty.Value.ToString();
            }
            catch (System.Runtime.InteropServices.COMException)
            {
                // just catch the exception and return null, which means the user will see an empty 'FullPath' field of a ProjectReference property.
                return(null);
            }

            // Ususally the output path is relative to the project path, but it is possible
            // to set it as an absolute path. If it is not absolute, then evaluate its value
            // based on the project directory.
            if (!System.IO.Path.IsPathRooted(outputPath))
            {
                string projectDir = System.IO.Path.GetDirectoryName(referencedProjectFullPath);
                outputPath = System.IO.Path.Combine(projectDir, outputPath);
            }

            // Now get the name of the assembly from the project.
            // Some project system throw if the property does not exist. We expect an ArgumentException.
            string assemblyName = null;

            try
            {
                assemblyName = this.ReferencedProject.Properties.Item("OutputFileName").Value.ToString();
            }
            catch (ArgumentException)
            {
            }
            catch (NullReferenceException)
            {
            }

            if (null == assemblyName)
            {
                try
                {
                    var group = config.OutputGroups.Item("Built");
                    var files = (object[])group.FileNames;
                    if (files.Length > 0)
                    {
                        assemblyName = (string)files[0];
                    }
                }
                catch (InvalidCastException)
                {
                    return(null);
                }
                catch (ArgumentException)
                {
                    return(null);
                }
                catch (NullReferenceException)
                {
                    return(null);
                }
            }
            // build the full path adding the name of the assembly to the output path.
            outputPath = System.IO.Path.Combine(outputPath, assemblyName);

            return(outputPath);
        }
 internal ProjectProperty(EnvDTE.Project project, EnvDTE.Property property)
 {
     this.project  = project;
     this.property = property;
 }
        private void InitReferencedProject(IVsSolution solution)
        {
            IVsHierarchy hier;
            var          hr = solution.GetProjectOfGuid(ref referencedProjectGuid, out hier);

            if (!ErrorHandler.Succeeded(hr))
            {
                return; // check if project is missing or non-loaded!
            }
            object obj;

            hr = hier.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out obj);
            ErrorHandler.ThrowOnFailure(hr);

            EnvDTE.Project prj = obj as EnvDTE.Project;
            if (prj == null)
            {
                return;
            }

            // Skip if has no properties (e.g. "miscellaneous files")
            if (prj.Properties == null)
            {
                return;
            }

            // do things differently for C++
            try
            {
                bool isVCProject;
                bool itMatches;
                CheckVCProjectMatchesPath(prj.Object, this.referencedProjectFullPath, out isVCProject, out itMatches);
                if (itMatches)
                {
                    this.referencedProject = prj;
                    return;
                }
                if (isVCProject)
                {
                    return;
                }
            }
            catch (System.IO.FileNotFoundException)
            {
                // ignore it - VC might not be installed
            }

            // Get the full path of the current project.
            EnvDTE.Property pathProperty = null;
            try
            {
                pathProperty = prj.Properties.Item("FullPath");
                if (null == pathProperty)
                {
                    // The full path should alway be availabe, but if this is not the
                    // case then we have to skip it.
                    return;
                }
            }
            catch (ArgumentException)
            {
                return;
            }
            string prjPath = pathProperty.Value.ToString();

            EnvDTE.Property fileNameProperty = null;
            // Get the name of the project file.
            try
            {
                fileNameProperty = prj.Properties.Item("FileName");
                if (null == fileNameProperty)
                {
                    // Again, this should never be the case, but we handle it anyway.
                    return;
                }
            }
            catch (ArgumentException)
            {
                return;
            }
            prjPath = System.IO.Path.Combine(prjPath, fileNameProperty.Value.ToString());

            // If the full path of this project is the same as the one of this
            // reference, then we have found the right project.
            if (NativeMethods.IsSamePath(prjPath, referencedProjectFullPath))
            {
                this.referencedProject = prj;
            }
        }
Ejemplo n.º 15
0
        private EnvDTE.Project FindProjectByPath(IEnumerable <EnvDTE.Project> projects)
        {
            foreach (EnvDTE.Project prj in projects)
            {
                //Skip this project if it is an umodeled project (unloaded)
                if (string.Compare(EnvDTE.Constants.vsProjectKindUnmodeled, prj.Kind, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    continue;
                }

                //SolutionFolder

                if (string.Compare(EnvDTE.Constants.vsProjectKindSolutionItems, prj.Kind, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    var subProjects = new List <EnvDTE.Project>();

                    foreach (EnvDTE.ProjectItem item in prj.ProjectItems)
                    {
                        try
                        {
                            EnvDTE.Project subProject = item.SubProject as EnvDTE.Project;

                            if (subProject != null)
                            {
                                subProjects.Add(subProject);
                            }
                        }
                        catch { }
                    }

                    if (subProjects.Count > 0)
                    {
                        var result = FindProjectByPath(subProjects);

                        if (result != null)
                        {
                            return(result);
                        }
                    }
                }

                // Get the full path of the current project.
                EnvDTE.Property pathProperty = GetProperty(prj, "FullPath");

                if (pathProperty == null)
                {
                    var fullName = prj.FullName;

                    if (NativeMethods.IsSamePath(fullName, referencedProjectFullPath))
                    {
                        return(prj);
                    }

                    // The full path should alway be availabe, but if this is not the
                    // case then we have to skip it.
                    continue;
                }

                string prjPath = pathProperty.Value.ToString();


                // Get the name of the project file.
                EnvDTE.Property fileNameProperty = GetProperty(prj, "FileName");

                if (fileNameProperty == null)
                {
                    // Again, this should never be the case, but we handle it anyway.
                    continue;
                }

                prjPath = System.IO.Path.Combine(prjPath, fileNameProperty.Value.ToString());

                // If the full path of this project is the same as the one of this
                // reference, then we have found the right project.
                if (NativeMethods.IsSamePath(prjPath, referencedProjectFullPath))
                {
                    return(prj);
                }
            }

            return(null);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Searches the solution or project for a contained project with a given path.
        /// </summary>
        /// <param name="project">Project node to start the search from, or null to search the solution.</param>
        /// <param name="projectFilePath">Path of the project to be located.</param>
        /// <returns>Found project object, or null if the project was not found.</returns>
        private EnvDTE.Project FindProject(EnvDTE.Project project, string projectFilePath)
        {
            if (project == null)
            {
                // Search for the project in the collection of the projects in the
                // current solution.
                EnvDTE.DTE dte = (EnvDTE.DTE) this.ProjectMgr.GetService(typeof(EnvDTE.DTE));
                if ((null == dte) || (null == dte.Solution))
                {
                    return(null);
                }

                foreach (EnvDTE.Project prj in dte.Solution.Projects)
                {
                    //Skip this project if it is an umodeled project (unloaded)
                    if (!String.Equals(EnvDTE.Constants.vsProjectKindUnmodeled, prj.Kind, StringComparison.OrdinalIgnoreCase))
                    {
                        EnvDTE.Project foundProject = FindProject(prj, projectFilePath);
                        if (foundProject != null)
                        {
                            return(foundProject);
                        }
                    }
                }
            }
            else
            {
                if (String.Equals(EnvDTE.Constants.vsProjectKindSolutionItems, project.Kind, StringComparison.OrdinalIgnoreCase))
                {
                    // This is a solution folder -- look for child projects.
                    foreach (EnvDTE.ProjectItem projectItem in project.ProjectItems)
                    {
                        EnvDTE.Project subProject = projectItem.SubProject;
                        if (subProject != null)
                        {
                            EnvDTE.Project foundProject = FindProject(subProject, projectFilePath);
                            if (foundProject != null)
                            {
                                return(foundProject);
                            }
                        }
                    }
                }
                else
                {
                    // Get the full path of the current project.
                    EnvDTE.Property pathProperty = null;
                    try
                    {
                        pathProperty = project.Properties.Item("FullPath");
                    }
                    catch (ArgumentException)
                    {
                    }

                    if (null == pathProperty)
                    {
                        // The full path should alway be availabe, but if this is not the
                        // case then we have to skip it.
                        return(null);
                    }

                    // Compare the project path to the path we're searching for.
                    string projectPath = Path.Combine(pathProperty.Value.ToString(), project.FileName);
                    if (NativeMethods.IsSamePath(projectPath, projectFilePath))
                    {
                        return(project);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 17
0
        // Used to open a connection to a Perforce depot
        public void OpenConnection(string Port, string User, string Workspace)
        {
#if DB_DEBUG
            P4VsOutputWindow.AppendMessage(string.Format("Opening connection, CurrentScm scm ID:{0}",
                                                         CurrentScm != null?CurrentScm.__Id:-1));
#endif

            P4ScmProvider scm = new P4ScmProvider(SccService);
            scm.LoadingSolution = !string.IsNullOrEmpty(SccService.LoadingControlledSolutionLocation);

#if DB_DEBUG
            P4VsOutputWindow.AppendMessage(string.Format("Opening connection, new scm ID:{0}", scm.__Id));
#endif
            bool noUi = InCommandLineMode() || (Port != null) && (User != null) && (Workspace != null);

            // trigger the connection dialog
            scm.Connection.Connect(Port, User, Workspace, noUi, null);
            if (scm.Connected)
            {
#if DB_DEBUG
                P4VsOutputWindow.AppendMessage(string.Format("Opening connection user clicked OK, new scm ID:{0}", scm.__Id));
#endif
                if (SccService.ScmProvider != null)
                {
                    BroadcastNewConnection(null);
                    SccService.Dispose();
                    SccService.ScmProvider = null;
                }
                SccService.ScmProvider = scm;

                createActiveChangelists(SccService);

                if (string.IsNullOrEmpty(SccService.ScmProvider.SolutionFile))
                {
                    string solutionFile = GetSolutionFileName();
                    if (string.IsNullOrEmpty(solutionFile) == false)
                    {
                        SccService.ScmProvider.SolutionFile = GetSolutionFileName();

                        if (Preferences.LocalSettings.GetBool("TagSolutionProjectFiles", false))
                        {
                            // Need to tag sln file if tagging is enabled, so mark dirty props so
                            // it'll get tagged
                            SolutionHasDirtyProps = true;
                        }
                    }

                    if (!SccService.IsProjectControlled(null))
                    {
                        SccService.OnAfterOpenSolution(null, 0);
                    }
                }
                Cursor oldCursor = Cursor.Current;
                try
                {
                    Cursor.Current = Cursors.WaitCursor;

                    // now refresh the selected nodes' glyphs
                    if (Preferences.LocalSettings.GetBool("LazyLoadStatus", false) == false)
                    {
                        Glyphs.RefreshNodesGlyphs(null, null);
                    }
                }
                finally
                {
                    Cursor.Current = oldCursor;
                }

                BroadcastNewConnection(SccService.ScmProvider);

                MRUList recentConnections = (MRUList)Preferences.LocalSettings["RecentConnections"];
                currentConnectionDropDownComboChoice = recentConnections[0].ToString();

                SuppressConnection            = true;
                LastConnectionInfo            = new ConnectionData();
                LastConnectionInfo.ServerPort = SccService.ScmProvider.Connection.Port;
                LastConnectionInfo.UserName   = SccService.ScmProvider.Connection.User;
                LastConnectionInfo.Workspace  = SccService.ScmProvider.Connection.Workspace;

#if _DBB_DEBUG
                // How to set a setting for the ide (Generally from tool/options dialog)
                // The category and page values are listed on MSDN at:
                // http://msdn.microsoft.com/en-us/library/ms165643(v=vs.100).aspx
                // The category and pages no longer follow the layout in the options dialog,
                // they seem to still follow the old layout fro VS 2003. There's a general
                // discussion on MSDN about properties here:
                // http://msdn.microsoft.com/en-us/library/ms165641(v=vs.100).aspx
                // and:
                // http://msdn.microsoft.com/en-us/library/awdwz11a(v=vs.100).aspx
                // The Property object is documented here:
                // http://msdn.microsoft.com/en-us/library/envdte.property(v=vs.100).aspx
                // The Properties interface is documented here:
                // http://msdn.microsoft.com/en-us/library/envdte.properties(v=vs.100).aspx
                try
                {
                    EnvDTE.DTE dte2;
                    dte2 = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
                    EnvDTE.Properties generalPnS = dte2.DTE.Properties["Environment", "ProjectsAndSolution"];

                    EnvDTE.Property prop2 = generalPnS.Item("ProjectsLocation");
                    string          val   = prop2.Value as string;

                    //dynamic v2 = val + "\\temp";
                    prop2.Value = val;

                    val = prop2.Value as string;
                }
                catch (Exception ex)
                {
                    string msg = ex.Message;
                    MessageBox.Show(msg, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
#endif
                // How to set a setting for the ide (Generally from tool/options dialog)
                // The category and page values are listed on MSDN at:
                // http://msdn.microsoft.com/en-us/library/ms165643(v=vs.100).aspx
                // The category and pages no longer follow the layout in the options dialog,
                // they seem to still follow the old layout fro VS 2003. There's a general
                // discussion on MSDN about properties here:
                // http://msdn.microsoft.com/en-us/library/ms165641(v=vs.100).aspx
                // and:
                // http://msdn.microsoft.com/en-us/library/awdwz11a(v=vs.100).aspx
                // The Property object is documented here:
                // http://msdn.microsoft.com/en-us/library/envdte.property(v=vs.100).aspx
                // The Properties interface is documented here:
                // http://msdn.microsoft.com/en-us/library/envdte.properties(v=vs.100).aspx

                if (Preferences.LocalSettings.GetBool("SetProjectFileLocation", true) &&
                    !string.IsNullOrEmpty(scm.Connection.WorkspaceRoot))
                {
                    try
                    {
                        EnvDTE.Property prop = null;
                        EnvDTE.DTE      dte2;
                        dte2 = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));

                        EnvDTE.Properties generalPnS = dte2.get_Properties("Environment", "ProjectsAndSolution");
                        foreach (EnvDTE.Property temp in generalPnS)
                        {
                            prop = temp;
                            if (prop.Name == "ProjectsLocation")
                            {
                                if (Directory.Exists(scm.Connection.WorkspaceRoot))
                                {
                                    prop.Value = scm.Connection.WorkspaceRoot.Replace("/", "\\");
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        string msg = ex.Message;
                        MessageBox.Show(msg, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
#if DB_DEBUG
            P4VsOutputWindow.AppendMessage(string.Format("Leaving open connection, CurrentScm scm ID:{0}",
                                                         CurrentScm != null ? CurrentScm.__Id : -1));
#endif
        }
Ejemplo n.º 18
0
        private EnvDTE.Project FindReferencedProject(System.Collections.IEnumerable projects)
        {
            EnvDTE.Project refProject = null;

            // Search for the project in the collection of the projects in the current solution.
            foreach (EnvDTE.Project prj in projects)
            {
                //Skip this project if it is an umodeled project (unloaded)
                if (string.Compare(EnvDTE.Constants.vsProjectKindUnmodeled, prj.Kind, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    continue;
                }

                // Recursively iterate solution folder for the project.
                if (string.Compare(EnvDTE.Constants.vsProjectKindSolutionItems, prj.Kind, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    var containedProjects = GetContainerProjects(prj);

                    refProject = FindReferencedProject(containedProjects);
                    if (refProject != null)
                    {
                        return(refProject);
                    }
                }

                // Get the full path of the current project.
                EnvDTE.Property pathProperty = null;
                try
                {
                    if (prj.Properties == null)
                    {
                        continue;
                    }

                    pathProperty = prj.Properties.Item("FullPath");
                    if (null == pathProperty)
                    {
                        // The full path should alway be availabe, but if this is not the
                        // case then we have to skip it.
                        continue;
                    }
                }
                catch (ArgumentException)
                {
                    continue;
                }
                string          prjPath          = pathProperty.Value.ToString();
                EnvDTE.Property fileNameProperty = null;
                // Get the name of the project file.
                try
                {
                    fileNameProperty = prj.Properties.Item("FileName");
                    if (null == fileNameProperty)
                    {
                        // Again, this should never be the case, but we handle it anyway.
                        continue;
                    }
                }
                catch (ArgumentException)
                {
                    continue;
                }
                prjPath = System.IO.Path.Combine(prjPath, fileNameProperty.Value.ToString());

                // If the full path of this project is the same as the one of this
                // reference, then we have found the right project.
                if (NativeMethods.IsSamePath(prjPath, referencedProjectFullPath))
                {
                    refProject = prj;
                    break;
                }
            }
            return(refProject);
        }