コード例 #1
0
        private void GetProjectFiles([CanBeNull] string projectName, [ItemNotNull][CanBeNull] EnvDTE.ProjectItems projectItems, [NotNull] IDictionary <string, DteProjectFile> items)
        {
            Contract.Requires(items != null);

            if (projectItems == null)
            {
                return;
            }

            try
            {
                var index = 1;

                // Must use forach here! See https://connect.microsoft.com/VisualStudio/feedback/details/1093318/resource-files-falsely-enumerated-as-part-of-project
                foreach (var projectItem in projectItems.OfType <EnvDTE.ProjectItem>())
                {
                    try
                    {
                        GetProjectFiles(projectName, projectItem, items);
                    }
                    catch
                    {
                        _tracer.TraceError("Error loading project item #{0} in project {1}.", index, projectName);
                    }

                    index += 1;
                }
            }
            catch
            {
                _tracer.TraceError("Error loading a project item in project {0}.", projectName);
            }
        }
コード例 #2
0
ファイル: vsgendataset.cs プロジェクト: GunterMueller/Ingres
        GetAllDataSetsInProjectItems(ArrayList list, EnvDTE.ProjectItems projectItems)
        {
            if (projectItems == null)
            {
                MessageBox.Show("Project.projectItems is null");
            }

            foreach (Object obj in projectItems)
            {
                EnvDTE.ProjectItem projItem = obj as EnvDTE.ProjectItem;

                if (projItem != null &&
                    projItem.Name != null &&
                    projItem.Name.Length > 0)
                {
                    // only add xsd files that use MSDataSetGenerator
                    string extension =                       // get the file extension
                                       GetProperty(projItem.Properties, "Extension");
                    if (ToLower(extension) != ".xsd")
                    {
                        continue;
                    }
                    string customTool =
                        GetProperty(projItem.Properties, "CustomTool");
                    if (ToLower(customTool) != "msdatasetgenerator")
                    {
                        continue;
                    }
                    list.Add(projItem);
                }
            }

            return(list);
        }          // GetAllDataSetsInProject
コード例 #3
0
        protected override async Task AddFileToProjectAsync(string path)
        {
            if (ExcludeFile(path))
            {
                return;
            }

            var folderPath = Path.GetDirectoryName(path);
            var fullPath   = FileSystemUtility.GetFullPath(ProjectFullPath, path);

            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            // Add the file to project or folder
            EnvDTEProjectItems container = await GetProjectItemsAsync(folderPath, createIfNotExists : true);

            if (container == null)
            {
                throw new ArgumentException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              Strings.Error_FailedToCreateParentFolder,
                              path,
                              ProjectName));
            }
            container.AddFromFileCopy(fullPath);

            NuGetProjectContext.Log(ProjectManagement.MessageLevel.Debug, Strings.Debug_AddedFileToProject, path, ProjectName);
        }
コード例 #4
0
        protected override void AddFileToProject(string path)
        {
            if (ExcludeFile(path))
            {
                return;
            }

            string folderPath = Path.GetDirectoryName(path);
            string fullPath   = FileSystemUtility.GetFullPath(EnvDTEProjectUtility.GetFullPath(EnvDTEProject), path);

            // Add the file to project or folder
            EnvDTEProjectItems container = EnvDTEProjectUtility.GetProjectItems(EnvDTEProject, folderPath, createIfNotExists: true);

            if (container == null)
            {
                throw new ArgumentException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              Strings.Error_FailedToCreateParentFolder,
                              path,
                              ProjectName));
            }
            AddFileToContainer(fullPath, folderPath, container);

            NuGetProjectContext.Log(MessageLevel.Debug, Strings.Debug_AddedFileToProject, path, ProjectName);
        }
コード例 #5
0
        protected override async Task AddFileToProjectAsync(string path)
        {
            Debug.Assert(ThreadHelper.CheckAccess());

            if (ExcludeFile(path))
            {
                return;
            }

            string folderPath = Path.GetDirectoryName(path);
            string fullPath   = FileSystemUtility.GetFullPath(ProjectFullPath, path);

            // Add the file to project or folder
            EnvDTEProjectItems container = await EnvDTEProjectUtility.GetProjectItemsAsync(EnvDTEProject, folderPath, createIfNotExists : true);

            if (container == null)
            {
                throw new ArgumentException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              Strings.Error_FailedToCreateParentFolder,
                              path,
                              ProjectName));
            }
            AddFileToContainer(fullPath, folderPath, container);

            NuGetProjectContext.Log(ProjectManagement.MessageLevel.Debug, Strings.Debug_AddedFileToProject, path, ProjectName);
        }
コード例 #6
0
        private void GetSubProjects(string projectName, EnvDTE.ProjectItems projectItems, IList <EnvDTE.Project> items)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();

            if (projectItems == null)
            {
                return;
            }

            try
            {
                var index = 1;

                foreach (var projectItem in projectItems.OfType <EnvDTE.ProjectItem>())
                {
                    try
                    {
                        GetSubProjects(projectName, projectItem, items);
                    }
                    catch
                    {
                        _tracer.TraceError("Error loading project item #{0} in project {1}.", index, projectName ?? "unknown");
                    }

                    index += 1;
                }
            }
            catch
            {
                _tracer.TraceError("Error loading a project item in project {0}.", projectName ?? "unknown");
            }
        }
コード例 #7
0
        /// <summary>
        /// If we didn't find the project item at the top level, then we look one more level down.
        /// In VS files can have other nested files like foo.aspx and foo.aspx.cs or web.config and web.debug.config.
        /// These are actually top level files in the file system but are represented as nested project items in VS.
        /// </summary>
        private static bool TryGetNestedFile(EnvDTE.ProjectItems envDTEProjectItems, string name, out EnvDTE.ProjectItem envDTEProjectItem)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            string parentFileName;

            if (!KnownNestedFiles.TryGetValue(name, out parentFileName))
            {
                parentFileName = Path.GetFileNameWithoutExtension(name);
            }

            // If it's not one of the known nested files then we're going to look up prefixes backwards
            // i.e. if we're looking for foo.aspx.cs then we look for foo.aspx then foo.aspx.cs as a nested file
            var parentEnvDTEProjectItem = GetProjectItem(envDTEProjectItems, parentFileName, FileKinds);

            if (parentEnvDTEProjectItem != null)
            {
                // Now try to find the nested file
                envDTEProjectItem = GetProjectItem(parentEnvDTEProjectItem.ProjectItems, name, FileKinds);
            }
            else
            {
                envDTEProjectItem = null;
            }

            return(envDTEProjectItem != null);
        }
コード例 #8
0
        /// <summary>
        /// Helper function to recursively trigger the NUPlixLoader tool
        /// </summary>
        private static void RunCustomTool(EnvDTE.ProjectItems items, EnvDTE.ProjectItem ignoreItem, ProcessProjectItem itemProcessor)
        {
                        #if VerifyUIThread
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
                        #endif

            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);
                }
            }
        }
コード例 #9
0
        private JObject AddProjectItems([ItemNotNull][CanBeNull] EnvDTE.ProjectItems projectItems, [NotNull] JObject jProject)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();

            if (projectItems == null)
            {
                return(jProject);
            }

            try
            {
                var index = 1;

                foreach (var projectItem in projectItems.OfType <EnvDTE.ProjectItem>().OrderBy(item => item.Name))
                {
                    try
                    {
                        AddProjectItems(projectItem, jProject);
                    }
                    catch
                    {
                        _tracer.TraceWarning("Can't load project item #{0}", index);
                    }

                    index += 1;
                }
            }
            catch
            {
                _tracer.TraceWarning("Can't load a project item.");
            }

            return(jProject);
        }
コード例 #10
0
        private void FormatSolutionRecursive(EnvDTE.ProjectItems projectItems)
        {
            if (projectItems != null && projectItems.Count > 0)
            {
                try
                {
                    foreach (EnvDTE.ProjectItem item in projectItems)
                    {
                        if (item != null)
                        {
                            if (item.Kind == VSConstants.ItemTypeGuid.PhysicalFile_string &&
                                item.FileCodeModel != null)
                            {
                                FormatDocument(item);
                            }

                            var children = item.ProjectItems;

                            if (children == null && item.SubProject != null)
                            {
                                // Required while testing in Visual Studio 2013 against a GIT-sourced solution.
                                children = item.SubProject.ProjectItems;
                            }

                            FormatSolutionRecursive(children);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Failed to iterate items in project.  Error: " + ex, packageTitle);
                }
            }
        }
コード例 #11
0
        private static void BuildStructure(EnvDTE.ProjectItems projectItems, string[] levels, int currentLevel)
        {
            if (currentLevel == levels.Length)
            {
                return;
            }

            var folderName  = levels[currentLevel];
            var toBeCreated = true;

            EnvDTE.ProjectItem newProjectItem = null;
            foreach (EnvDTE.ProjectItem pi in projectItems)
            {
                if (pi.Name == folderName && pi.Kind == KIND_FOLDER)
                {
                    newProjectItem = pi;
                    toBeCreated    = false;
                    break;
                }
            }
            if (toBeCreated)
            {
                newProjectItem = projectItems.AddFolder(folderName, KIND_FOLDER);
            }
            BuildStructure(newProjectItem.ProjectItems, levels, currentLevel + 1);
        }
コード例 #12
0
        private IEnumerable <string> CollectFileNamesRecursively(EnvDTE.ProjectItems items)
        {
            if (items != null)
            {
                foreach (EnvDTE.ProjectItem item in items)
                {
                    //if (!(item is OAFileItem || item is OAFolderItem))
                    //	continue;

                    for (short i = 1; i <= item.FileCount; ++i)
                    {
                        var path = item.get_FileNames(i);
                        if (!Path.GetExtension(path).Equals(".dll", StringComparison.OrdinalIgnoreCase) && File.Exists(path))
                        {
                            yield return(item.get_FileNames(i));
                        }
                    }
                    //yield return fileItem..Name;
                    foreach (var s in CollectFileNamesRecursively(item.ProjectItems))
                    {
                        yield return(s);
                    }
                }
            }
        }
コード例 #13
0
        /// <summary>
        /// Parses the project passed in.
        /// </summary>
        private void parseProject(EnvDTE.Project project)
        {
            // We get the project name...
            string projectName = Utils.call(() => (project.Name));

            // We check if the project is loaded in the solution
            if (Utils.call(() => project.Object) == null && Utils.call(() => project.UniqueName) != "<MiscFiles>")
            {
                Log.log("Warning: " + projectName + " is currently unloaded in the solution! No conversion performed");
                return;
            }

            // We check if this project is a kind we know how to convert...
            string      strProjectType = Utils.call(() => (project.Kind));
            ProjectType eProjectType   = convertProjectTypeToEnum(strProjectType);

            switch (eProjectType)
            {
            // It's a C++ project...
            case ProjectType.CPP_PROJECT:
            {
                // We get the Visual Studio project, parse it and store the
                // parsed project in our collection of results...
                VCProject         vcProject = Utils.call(() => (project.Object as VCProject));
                ProjectParser_CPP parser    = new ProjectParser_CPP(vcProject, m_parsedSolution.RootFolderAbsolute);

                ProjectParser_ForCUDA cudaparser = new ProjectParser_ForCUDA(project.FileName, project.Name);

                // Remove cuda file.
                foreach (var info in cudaparser.Project.CompileInfos)
                {
                    parser.Project.removeFile(info.File);
                }

                m_parsedSolution.addProjectInfo(projectName, parser.Project);
                m_parsedSolution.addCudaProjectInfo(projectName, cudaparser.Project);
            }
            break;

                // Not support...
#if false
            // It's a C# project...
            case ProjectType.CSHARP_PROJECT:
            {
                // We get the Visual Studio project, parse it and store the
                // parsed project in our collection of results...
                VSProject2           vsProject = Utils.call(() => (project.Object as VSProject2));
                ProjectParser_CSharp parser    = new ProjectParser_CSharp(vsProject, m_parsedSolution.RootFolderAbsolute);
                m_parsedSolution.addProjectInfo(projectName, parser.Project);
            }
            break;
#endif
            }

            // We parse the project's items, to check whether there are any nested
            // projects...
            EnvDTE.ProjectItems projectItems = Utils.call(() => (project.ProjectItems));
            parseProjectItems(projectItems);
        }
コード例 #14
0
        // 'parentItem' can be either a Project or ProjectItem
        private static EnvDTEProjectItem GetOrCreateFolder(
            EnvDTEProject envDTEProject,
            object parentItem,
            string fullPath,
            string folderRelativePath,
            string folderName,
            bool createIfNotExists)
        {
            if (parentItem == null)
            {
                return(null);
            }

            EnvDTEProjectItem subFolder;

            EnvDTEProjectItems envDTEProjectItems = GetProjectItems(parentItem);

            if (TryGetFolder(envDTEProjectItems, folderName, out subFolder))
            {
                // Get the sub folder
                return(subFolder);
            }
            else if (createIfNotExists)
            {
                // The JS Metro project system has a bug whereby calling AddFolder() to an existing folder that
                // does not belong to the project will throw. To work around that, we have to manually include
                // it into our project.
                if (IsJavaScriptProject(envDTEProject) && Directory.Exists(fullPath))
                {
                    bool succeeded = IncludeExistingFolderToProject(envDTEProject, folderRelativePath);
                    if (succeeded)
                    {
                        // IMPORTANT: after including the folder into project, we need to get
                        // a new EnvDTEProjecItems snapshot from the parent item. Otherwise, reusing
                        // the old snapshot from above won't have access to the added folder.
                        envDTEProjectItems = GetProjectItems(parentItem);
                        if (TryGetFolder(envDTEProjectItems, folderName, out subFolder))
                        {
                            // Get the sub folder
                            return(subFolder);
                        }
                    }
                    return(null);
                }

                try
                {
                    return(envDTEProjectItems.AddFromDirectory(fullPath));
                }
                catch (NotImplementedException)
                {
                    // This is the case for F#'s project system, we can't add from directory so we fall back
                    // to this impl
                    return(envDTEProjectItems.AddFolder(folderName));
                }
            }

            return(null);
        }
コード例 #15
0
        private static bool TryGetFolder(EnvDTE.ProjectItems envDTEProjectItems, string name, out EnvDTE.ProjectItem envDTEProjectItem)
        {
            Debug.Assert(ThreadHelper.CheckAccess());

            envDTEProjectItem = GetProjectItem(envDTEProjectItems, name, FolderKinds);

            return(envDTEProjectItem != null);
        }
コード例 #16
0
        private static bool TryGetFolder(EnvDTE.ProjectItems envDTEProjectItems, string name, out EnvDTE.ProjectItem envDTEProjectItem)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            envDTEProjectItem = GetProjectItem(envDTEProjectItems, name, FolderKinds);

            return(envDTEProjectItem != null);
        }
コード例 #17
0
ファイル: Helper.cs プロジェクト: gaelgael5/galileo
 public static IEnumerable <EnvDTE.ProjectItem> GetFiles(EnvDTE.ProjectItems source)
 {
     foreach (EnvDTE.ProjectItem item2 in source)
     {
         foreach (var item3 in GetFiles(item2))
         {
             yield return(item3);
         }
     }
 }
コード例 #18
0
        static IEnumerable <EnvDTE.ProjectItem> TraverseProjectItems(EnvDTE.ProjectItems projectItems)
        {
            foreach (EnvDTE.ProjectItem projectItem in projectItems)
            {
                yield return(projectItem);

                foreach (EnvDTE.ProjectItem childProjectItem in TraverseProjectItems(projectItem.ProjectItems))
                {
                    yield return(childProjectItem);
                }
            }
        }
コード例 #19
0
        private EnvDTE.ProjectItem FindItemByName(EnvDTE.ProjectItems projectItems, string name)
        {
            foreach (EnvDTE.ProjectItem item in projectItems)
            {
                if (item.Name == name)
                {
                    return(item);
                }
            }

            return(null);
        }
コード例 #20
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.ProductTitle,
                    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);
        }
コード例 #21
0
 static EnvDTE.ProjectItem FindProjectItemOrNull(string name, EnvDTE.ProjectItems parentCollection)
 {
     foreach (EnvDTE.ProjectItem projectItem in GetFilesIncludingSubFiles(parentCollection))
     {
         string projectItemName = projectItem.Name;
         if (projectItemName.ToLower() == name.ToLower())
         {
             return(projectItem);
         }
     }
     return(null);
 }
コード例 #22
0
        public static bool TryGetFile(EnvDTEProjectItems envDTEProjectItems, string name, out EnvDTEProjectItem envDTEProjectItem)
        {
            envDTEProjectItem = GetProjectItem(envDTEProjectItems, name, FileKinds);

            if (envDTEProjectItem == null)
            {
                // Try to get the nested project item
                return(TryGetNestedFile(envDTEProjectItems, name, out envDTEProjectItem));
            }

            return(envDTEProjectItem != null);
        }
コード例 #23
0
        private IEnumerable <EnvDTE.ProjectItem> GetProjectItems(EnvDTE.ProjectItems projectItems)
        {
            List <EnvDTE.ProjectItem> result = new List <EnvDTE.ProjectItem>();

            int itemCount = TryHelper.Run(() => projectItems.Count);

            for (int i = 0; i < itemCount; i++)
            {
                result.Add(TryHelper.Run(() => projectItems.Item(i + 1)));
            }

            return(result);
        }
コード例 #24
0
        private static bool TryGetFile(EnvDTE.ProjectItems envDTEProjectItems, string name, out EnvDTE.ProjectItem envDTEProjectItem)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            envDTEProjectItem = GetProjectItem(envDTEProjectItems, name, FileKinds);

            if (envDTEProjectItem == null)
            {
                // Try to get the nested project item
                return(TryGetNestedFile(envDTEProjectItems, name, out envDTEProjectItem));
            }

            return(envDTEProjectItem != null);
        }
コード例 #25
0
        /// <summary>
        /// This function returns the currently-active project object, provided that it is a valid
        /// project. Validity is defined as:
        /// - It's open
        /// - All items in the project are stored off of the root directory where the
        /// project itself is located
        /// </summary>
        private EnvDTE.Project GetValidProject(string strName)
        {
            EnvDTE.Project CurrentProj = null;

            if (strName == EnvDTE.Constants.vsMiscFilesProjectUniqueName)
            {
                // Copying the Misc Files project doesn't make any sense...
                return(null);
            }

            try
            {
                EnvDTE.Projects     CurrentProjs = null;
                EnvDTE.ProjectItems Items        = null;
                int    nLastIndex;
                string strProjectRootPath;

                CurrentProjs = m_application.Solution.Projects;
                CurrentProj  = CurrentProjs.Item(strName);
                if (CurrentProj == null)
                {
                    return(null);
                }
                strProjectRootPath = CurrentProj.FileName;

                nLastIndex = strProjectRootPath.LastIndexOf('\\');
                if (nLastIndex == -1)
                {
                    nLastIndex = strProjectRootPath.LastIndexOf('/');
                    if (nLastIndex == -1)
                    {
                        return(null);
                    }
                }
                strProjectRootPath = strProjectRootPath.Substring(0, nLastIndex + 1);                 // Just keep the 'path\' of 'path\name'
                strProjectRootPath = strProjectRootPath.ToUpper();

                Items = CurrentProj.ProjectItems;
                if (!ValidProjectItems(Items, strProjectRootPath))
                {
                    return(null);
                }
            }
            catch (Exception /*e*/)
            {
                return(null);
            }

            return(CurrentProj);
        }
コード例 #26
0
        private static bool TryGetFile(EnvDTE.ProjectItems envDTEProjectItems, string name, out EnvDTE.ProjectItem envDTEProjectItem)
        {
            Debug.Assert(ThreadHelper.CheckAccess());

            envDTEProjectItem = GetProjectItem(envDTEProjectItems, name, FileKinds);

            if (envDTEProjectItem == null)
            {
                // Try to get the nested project item
                return(TryGetNestedFile(envDTEProjectItems, name, out envDTEProjectItem));
            }

            return(envDTEProjectItem != null);
        }
コード例 #27
0
        static string ListProjectItems(EnvDTE.ProjectItems projectItems, int level)
        {
            string result = "";

            foreach (EnvDTE.ProjectItem projectItem in projectItems)
            {
                result += projectItem.Name + " {" + projectItem.Properties.Item("FullPath").Value.ToString() + "}" + " (" + level.ToString() + ")" + Environment.NewLine;
                if (projectItem.ProjectItems != null)
                {
                    result += ListProjectItems(projectItem.ProjectItems, level + 1);
                }
            }
            return(result);
        }
コード例 #28
0
 GetGeneratedFiles(EnvDTE.ProjectItems items, ref Dictionary <String, List <String> > generated)
 {
     foreach (EnvDTE.ProjectItem item in items)
     {
         if (IsProjectItemFile(item) && IsSliceFileName(item.Name))
         {
             generated[item.FileNames[1]] = GetGeneratedFiles(item.ContainingProject, item.FileNames[1]);
         }
         else if (IsProjectItemFolder(item) || IsProjectItemFilter(item))
         {
             GetGeneratedFiles(item.ProjectItems, ref generated);
         }
     }
 }
コード例 #29
0
 static bool DeleteFileInProject(EnvDTE.Project project, string fileName)
 {
     EnvDTE.ProjectItems projectItems = project.ProjectItems;
     try
     {
         projectItems.Item(fileName).Delete();
         return(true);
     }
     catch (Exception ex)
     {
         DisplayMessageBoxOnUIThread(string.Format("Unable to delete '{0}'.", fileName) + Environment.NewLine + Environment.NewLine + ex.ToString());
         return(false);
     }
 }
コード例 #30
0
 private static void NavigateProjectItems(EnvDTE.ProjectItems nativeProjectItems, List <EnvDTE.Project> nativeProjects)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     if (nativeProjectItems == null)
     {
         return;
     }
     foreach (EnvDTE.ProjectItem nativeProjectItem in nativeProjectItems)
     {
         if (nativeProjectItem.SubProject != null)
         {
             NavigateProject(nativeProjectItem.SubProject, nativeProjects);
         }
     }
 }