public static TestRunnerOptions FromDteProperties(EnvDTE.Properties properties)
 {
     return new TestRunnerOptions
     {
         DetectMemoryLeaks = (bool) properties.Item("DetectMemoryLeaks").Value
     };
 }
示例#2
0
        /// <summary>
        /// Find all .cs files in the project, including sub-folders.
        /// </summary>
        private void findFiles(EnvDTE.ProjectItems projectItems, HashSet<FileInfo> files)
        {
            // We look through the items...
            int numProjectItems = Utils.call(() => (projectItems.Count));
            for (int i = 1; i <= numProjectItems; ++i)
            {
                EnvDTE.ProjectItem projectItem = Utils.call(() => (projectItems.Item(i)));

                // We get the full-path...
                EnvDTE.Properties dteProperties = Utils.call(() => (projectItem.Properties));
                Dictionary<string, object> properties = getProperties(dteProperties);
                string fullPath = getStringProperty(properties, "FullPath");
                int copyToOutputFolder = getIntProperty(properties, "CopyToOutputDirectory");

                // We check if it is a file (it could be a folder instead)...
                if (File.Exists(fullPath) == true)
                {
                    // We add it to the list of files...
                    FileInfo fileInfo = new FileInfo();
                    fileInfo.AbsolutePath = fullPath;
                    fileInfo.RelativePath = Utils.makeRelativePath(m_projectInfo.RootFolderAbsolute, fullPath);
                    fileInfo.CopyToOutputFolder = (copyToOutputFolder != 0);
                    files.Add(fileInfo);
                }

                // We see if the item itself has sub-items...
                EnvDTE.ProjectItems subItems = Utils.call(() => (projectItem.ProjectItems));
                if (subItems != null)
                {
                    findFiles(subItems, files);
                }

                // We see if this item has a sub-project...
                EnvDTE.Project subProject = Utils.call(() => (projectItem.SubProject));
                if (subProject != null)
                {
                    EnvDTE.ProjectItems subProjectItems = Utils.call(() => (subProject.ProjectItems));
                    findFiles(subProjectItems, files);
                }
            }
        }
示例#3
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;
        }
示例#4
0
 /// <summary>
 /// Parses projects in the collection of projects passed in.
 /// </summary>
 private void parseProjects(EnvDTE.Projects projects)
 {
     // We parse each project in the collection.
     // Note that this may end up recursing back into this function,
     // as there may be projects nested in other projects...
     int numProjects = Utils.call(() => (projects.Count));
     for (int i = 1; i <= numProjects; ++i)
     {
         EnvDTE.Project project = Utils.call(() => (projects.Item(i)));
         parseProject(project);
     }
 }
示例#5
0
        /// <summary>
        /// Parses a collection of project-items checking for sub-projects.
        /// </summary><remarks>
        /// Project items can be things like files and folders, or sub-projects.
        /// So when we parse a project, we need to drill into the items as there
        /// may be projects nested inside folders etc.
        /// </remarks>
        private void parseProjectItems(EnvDTE.ProjectItems projectItems)
        {
            // We look through the items...
            int numProjectItems = Utils.call(() => (projectItems.Count));
            for (int i = 1; i <= numProjectItems; ++i)
            {
                EnvDTE.ProjectItem projectItem = Utils.call(() => (projectItems.Item(i)));

                // We see if the item itself has sub-items...
                EnvDTE.ProjectItems subItems = Utils.call(() => (projectItem.ProjectItems));
                if (subItems != null)
                {
                    parseProjectItems(subItems);
                }

                // We see if this item has a sub-project...
                EnvDTE.Project subProject = Utils.call(() => (projectItem.SubProject));
                if (subProject != null)
                {
                    parseProject(subProject);
                }
            }
        }
        private EnvDTE.CodeElement GetAttributeArgumentForCodeModelEvent(CodeModelEvent codeModelEvent, EnvDTE.CodeElements parentAttributeArguments, object parentElement)
        {
            if (parentAttributeArguments == null)
            {
                return null;
            }

            CodeModelService.GetAttributeArgumentParentAndIndex(codeModelEvent.Node, out var attributeNode, out var ordinal);

            if (codeModelEvent.Type == CodeModelEventType.Remove)
            {
                var parentCodeElement = ComAggregate.TryGetManagedObject<CodeAttribute>(parentElement);
                if (parentCodeElement != null)
                {
                    return (EnvDTE.CodeElement)CodeAttributeArgument.Create(this.State, parentCodeElement, ordinal);
                }
            }
            else
            {
                return parentAttributeArguments.Item(ordinal + 1); // Needs to be 1-based to call back into code model
            }

            return null;
        }
        private EnvDTE.CodeElement GetParameterElementForCodeModelEvent(CodeModelEvent codeModelEvent, EnvDTE.CodeElements parentParameters, object parentElement)
        {
            if (parentParameters == null)
            {
                return null;
            }

            var parameterName = this.CodeModelService.GetName(codeModelEvent.Node);

            if (codeModelEvent.Type == CodeModelEventType.Remove)
            {
                var parentCodeElement = ComAggregate.TryGetManagedObject<AbstractCodeMember>(parentElement);
                if (parentCodeElement != null)
                {
                    return (EnvDTE.CodeElement)CodeParameter.Create(this.State, parentCodeElement, parameterName);
                }
            }
            else
            {
                return parentParameters.Item(parameterName);
            }

            return null;
        }
		private static bool HasProperty(EnvDTE.Properties properties, string name)
		{
			try
			{
				return (((properties.Item(name) != null) && (properties.Item(name).Value != null)) && !string.IsNullOrEmpty(properties.Item(name).Value.ToString()));
			}
			catch
			{
				return false;
			}
		}
示例#9
0
        private string ResolveAppNameCollisionWithUser(EnvDTE.ProjectItems items, string name, out bool cancel) {
            while (true) {
                try {
                    if (items.Item(name) == null) {
                        break;
                    }
                } catch (ArgumentException) {
                    break;
                }

                var td = new TaskDialog(new ServiceProvider(GetSite())) {
                    Title = Resources.PythonToolsForVisualStudio,
                    MainInstruction = string.Format(Resources.DjangoAppAlreadyExistsTitle, name),
                    Content = string.Format(Resources.DjangoAppAlreadyExistsInstruction, name),
                    AllowCancellation = true
                };
                var cont = new TaskDialogButton(
                    Resources.DjangoAppAlreadyExistsCreateAnyway,
                    Resources.DjangoAppAlreadyExistsCreateAnywaySubtitle
                );
                var retry = new TaskDialogButton(Resources.SelectAnotherName);
                td.Buttons.Add(cont);
                td.Buttons.Add(retry);
                td.Buttons.Add(TaskDialogButton.Cancel);

                var clicked = td.ShowModal();
                if (clicked == cont) {
                    break;
                } else if (clicked == retry) {
                    name = GetNewAppNameFromUser(name);
                    if (string.IsNullOrEmpty(name)) {
                        cancel = true;
                        return null;
                    }
                } else {
                    cancel = true;
                    return null;
                }
            }

            cancel = false;
            return name;
        }
示例#10
0
 public static object GetPropertyValue(EnvDTE.Properties properties, string name)
 {
     return properties.Item(name).Value;
 }
示例#11
0
 /// <summary>
 /// Gets default namespace from properties (obtained from a Project or ProjectItem).
 /// </summary>
 /// <param name="properties">Properties from where to get the Default Namespace.</param>
 /// <returns></returns>
 public static string GetDefaultNamespaceFromProperties(EnvDTE.Properties properties)
 {
     return properties.Item(Resources.Properties_DefaultNamespace).Value.ToString();
 }
        /// <summary>
        /// Helper function to get the text from a project item
        /// </summary>
        private static string GetPropertyValue(EnvDTE.Properties source, string name)
        {
            if (source == null || string.IsNullOrEmpty(name))
                return string.Empty;

            EnvDTE.Property property = source.Item(name);
            return property != null ? property.Value.ToString() : String.Empty;
        }