Exemplo n.º 1
0
        private ProjectItem GetDirectoryItem(string target)
        {
            DTE         dte               = GetDTE();
            Array       projects          = dte?.ActiveSolutionProjects as Array;
            Project     currentProject    = projects?.GetValue(0) as Project;
            ProjectItem targetProjectItem = null;

            if (currentProject != null)
            {
                string rootDirectory = Path.GetDirectoryName(currentProject.FullName);
                Directory.CreateDirectory(Path.Combine(rootDirectory, target));

                Queue <string> paths           = new Queue <string>(target.Split('\\'));
                ProjectItems   currentItemList = currentProject.ProjectItems;
                bool           found           = false;

                while (paths.Any())
                {
                    string path = paths.Dequeue();

                    for (int index = 1; index <= currentItemList.Count; ++index)
                    {
                        if (currentItemList.Item(index).Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFolder)
                        {
                            if (!paths.Any())
                            {
                                targetProjectItem = currentItemList.Item(index);
                            }
                            else
                            {
                                currentItemList = currentItemList.Item(index).ProjectItems;
                            }

                            found = true;

                            break;
                        }
                    }

                    if (!found)
                    {
                        ProjectItem newItem = currentItemList.AddFolder(path);

                        if (!paths.Any())
                        {
                            targetProjectItem = newItem;
                        }
                        else
                        {
                            currentItemList = newItem.ProjectItems;
                        }
                    }
                }
            }

            return(targetProjectItem);
        }
Exemplo n.º 2
0
        public void Item_GetProjectItemByName_ReturnsFileInsideProject()
        {
            CreateProjectItems();
            msbuildProject.AddFile("Program.cs");

            var    projectItem     = projectItems.Item("Program.cs") as DTE.ProjectItem;
            string projectItemName = projectItem.Name;

            Assert.AreEqual("Program.cs", projectItemName);
        }
Exemplo n.º 3
0
 /// <summary>
 /// نام يك آيتم پروژه را در ليست آيتم ها پيدا ميكند
 /// </summary>
 /// <param name="pitems">آيتم هاي پروژه</param>
 /// <param name="itemName">نام آيتم</param>
 /// <returns></returns>
 private ProjectItem GetProjectItemInItemsByName(ProjectItems pitems, string itemName)
 {
     for (int n = 1; n <= pitems.Count; n++)
     {
         if (pitems.Item(n).Name == itemName)
         {
             return(pitems.Item(n));
         }
     }
     return(null);
 }
Exemplo n.º 4
0
 public void AddFromFile(string fileName,string itemName)
 {
     string folderName = GetFolderName();
     GetCurrentProject();
     viewsFolder = curProject.ProjectItems; ;//default ViewsFolder is  the root of the project
     SearchFolder(folderName, viewsFolder);//find the real folder the new view must be inserted to
     viewsFolder.AddFromTemplate(fileName, itemName);
     int i = 1;
     for (; i < viewsFolder.Count; i++)
         if (viewsFolder.Item(i).Name == itemName)
             break;
     //EnvDTE.Constants.vsViewKindCode = {7651A701-06E5-11D1-8EBD-00A0C90F26EA}
     viewsFolder.Item(i).Open("{7651A701-06E5-11D1-8EBD-00A0C90F26EA}").Visible = true;
 }
Exemplo n.º 5
0
        public void ProjectItems_ProjectHasOneFileInsideSrcDirectory_ReturnsOneFileForSrcDirectory()
        {
            CreateProjectItems();
            msbuildProject.AddFile(@"src\program.cs");

            var directoryItem         = projectItems.Item("src");
            var directoryProjectItems = directoryItem.ProjectItems;
            var files = new List <DTE.ProjectItem>(directoryProjectItems);

            string[] expectedFiles = new string[] {
                "program.cs"
            };

            ProjectItemCollectionAssert.AreEqual(expectedFiles, files);
        }
        private void ChangeFileAdd(ProjectItems projectItems, ChangeFileAdd changeFile)
        {
            for (var i = 1; i <= projectItems.Count; i++)
            {
                var item = projectItems.Item(i);
                if (item.Name != changeFile.Name)
                {
                    continue;
                }

                var path = item.Properties.Item("FullPath").Value;

                if (changeFile.EndOfFile == true)
                {
                    using (var streamwriter = File.AppendText(path))
                    {
                        streamwriter.WriteLine(changeFile.Data);
                        streamwriter.Flush();
                        streamwriter.Close();
                    }
                    continue;
                }

                Log.Debug($"{nameof(ChangeFileAdd)} - Operation not supported");
            }
        }
Exemplo n.º 7
0
        private void duplicateFiles(ProjectItems projItems)
        {
            ProjectItem projItem;

            for (int i = 1; i <= projItems.Count; i++)
            {
                projItem = projItems.Item(i);
                Debug.Write(projItem.Name + "  " + projItem.Kind);
                try
                {
                    if (projItem.ProjectItems.Count > 0)
                    {
                        duplicateFiles(projItem.ProjectItems);
                    }
                    else if (selectedProjectItems.Contains(projItem))
                    {
                        selectedProjectItems.Remove(projItem);
                        String newPath = copyFile(projItem);
                        if (newPath != null)
                        {
                            try
                            {
                                lastAdded = projItems.AddFromFile(newPath);
                            }
                            catch (Exception) { }
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
        }
Exemplo n.º 8
0
        ProjectItems GetItemCollection(string fileName)
        {
            string       relPath = ExtendedPath.GetRelativePath(this.projPath, fileName);
            var          dteProj = project.DteProject();
            ProjectItems result  = dteProj.ProjectItems;

            if (relPath.IndexOf(":\\") > -1)
            {
                return(result);
            }
            string[] splittedName = relPath.Split(new char[] { '\\' });
            for (int i = 0; i < splittedName.Length - 1; i++)
            {
                string      name = splittedName[i];
                ProjectItem pi   = result.Item(name);
                if (pi != null)
                {
                    result = pi.ProjectItems;
                }
                else
                {
                    break;
                }
            }
            return(result);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Exposes <see cref="ProjectItem"/>s as enumerable given their container.
 /// </summary>
 /// <remarks>
 /// This has to be a separate function, because the only way the API provides
 /// to access them is by index, and that's very inconvenient to use with LINQ.
 /// </remarks>
 public static IEnumerable <ProjectItem> GetItems(ProjectItems items)
 {
     for (short j = 1; j <= items.Count; j++)
     {
         yield return(items.Item(j));
     }
 }
Exemplo n.º 10
0
        private void AnalyzeProjectItems(ProjectItems projItems, out bool reachedTreshold)
        {
            var currentOptions = OptionsProviderRegistry.CurrentOptions;

            reachedTreshold = false;
            for (int i = 1; i <= projItems.Count; i++)
            {
                ProjectItem     item     = projItems.Item(i);
                var             filename = GetFileName(item);
                IncludeFileType fileType = GetFileType(filename);

                if (fileType == IncludeFileType.Folder) // folder
                {
                    AnalyzeProjectItems(item.ProjectItems, out reachedTreshold);
                }
                else if ((currentOptions.BuildFileTypes & fileType) > 0 &&
                         item.FileCount == 1 &&
                         !IsNodeSkipped(item))
                {
                    ClearErrors(filename);
                    AnalyzeFile(filename, out reachedTreshold);
                }

                if (reachedTreshold)
                {
                    break;
                }
            }
        }
Exemplo n.º 11
0
 private void GetProjectsFromSolutionFolder(ProjectItems items, List <Project> projectList)
 {
     for (int i = 1; i <= items.Count; i++)
     {
         ProjectItem o = items.Item(i);
         if (o.Object is SolutionFolder)
         {
             GetProjectsFromSolutionFolder(o.ProjectItems, projectList);
         }
         else if (o.Object is Project)
         {
             Project proj = (Project)o.Object;
             if (proj.Kind == ProjectKinds.vsProjectKindSolutionFolder)
             {
                 GetProjectsFromSolutionFolder(proj.ProjectItems, projectList);
             }
             else
             {
                 CheckAndAddProject(proj, projectList);
             }
         }
         else if (o is Project)
         {
             CheckAndAddProject((Project)o, projectList);
         }
     }
 }
Exemplo n.º 12
0
 private static void CopyProjectItems(ProjectItems sourceItems, ProjectItems targetItems)
 {
     foreach (ProjectItem projectItem in sourceItems)
     {
         ProjectItem tempItem = null;
         try
         {
             tempItem = targetItems.Item(projectItem.Name);
         }
         catch (ArgumentException)
         {
             if (projectItem.Kind == "{6BB5F8EF-4483-11D3-8BCF-00C04F8EC28C}")
             {
                 if (projectItem.Name != "Properties")
                 {
                     tempItem = targetItems.AddFolder(projectItem.Name);
                 }
             }
             else if (projectItem.Name != "packages.config")
             {
                 tempItem = targetItems.AddFromFile(projectItem.Properties.Item("LocalPath").Value as string);
             }
         }
         if (tempItem != null)
         {
             CopyProjectItems(projectItem.ProjectItems, tempItem.ProjectItems);
         }
     }
 }
Exemplo n.º 13
0
 public static ProjectItem FindProjectItemByFileName(ProjectItems projectItems, string relativePathAndName)
 {
     for (var ii = 1; ii <= projectItems.Count; ii++)
     {
         var projectItem = projectItems.Item(ii);
         if (projectItem != null)
         {
             if (projectItem.Kind == Constants.vsProjectItemKindPhysicalFolder)
             {
                 var p = FindProjectItemByFileName(projectItem.ProjectItems, relativePathAndName);
                 if (p != null)
                 {
                     return(p);
                 }
             }
             else
             {
                 var fileName = projectItem.FileNames[0];
                 if (fileName.ToLower() == relativePathAndName.ToLower())
                 {
                     return(projectItem);
                 }
             }
         }
     }
     return(null);
 }
Exemplo n.º 14
0
        /// <summary>
        /// Open code editor window and set the cursor at the start of particular class or structure.
        /// Returns 'true' if editor opened, otherwise 'false'.
        /// </summary>
        public static bool Activate(IList <Project> projects, IClassFinder classFinder, IStructFinder structFinder, IFunctionFinder functionFinder)
        {
            // nothing to do:
            if ((classFinder == null && structFinder == null) || projects == null || projects.Count == 0)
            {
                return(false);
            }

            foreach (Project prj in projects)
            {
                ProjectItems pi = prj.ProjectItems;

                for (int i = 1; i < pi.Count; i++)
                {
                    ProjectItem f = pi.Item(i);

                    if (InternalEnumeration(f, classFinder, structFinder, functionFinder))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        private ProjectItem IncludeExistingFolder(string folderName, ProjectItems collection)
        {
            IVsHierarchy targetHierarchy = TargetProject.GetVsHierarchy(_solution);

            if (targetHierarchy is IVsProject targetIVsProject)
            {
                string folderAbsolutePath;
                if (collection.Parent is ProjectItem parentProjectItem)
                {
                    folderAbsolutePath = Path.Combine(parentProjectItem.Properties.GetValue("FullPath", string.Empty), folderName);
                }
                else
                {
                    folderAbsolutePath = Path.Combine(Path.GetDirectoryName(TargetProject.FullName), folderName);
                }
                string containerFolderRelativePath = GetPathRelativeToProject(TargetProject, Path.GetDirectoryName(folderAbsolutePath));

                uint          containerFolderId = _hierarchyHelper.GetItemId(targetHierarchy, containerFolderRelativePath);
                VSADDRESULT[] result            = new VSADDRESULT[1];

                int hr = targetIVsProject.AddItem(containerFolderId,
                                                  VSADDITEMOPERATION.VSADDITEMOP_OPENFILE,
                                                  string.Empty,                 //No file name because it's a directory
                                                  1,                            // Has to correspond to #items below...
                                                  new[] { folderAbsolutePath }, // Full path to item
                                                  IntPtr.Zero,                  // Don't show window
                                                  result);                      // Result array...
                ErrorHandler.ThrowOnFailure(hr);
                _logger.Log(string.Format(CultureInfo.CurrentCulture, Resources.IncludingExistingFolderInProject,
                                          GetPathRelativeToProject(TargetProject, folderAbsolutePath), TargetProject.Name));
            }
            return(collection.Item(folderName));
        }
 private static void DoActionForItems(ProjectItems projectItems, TargetAction action, CleanupOptions cleanupOptions)
 {
     for (int subItemIndex = 1; subItemIndex <= projectItems.Count; subItemIndex++)
     {
         var subItem = projectItems.Item(subItemIndex);
         ActionCSharpOnProjectItem.Action(subItem, action, cleanupOptions);
     }
 }
Exemplo n.º 17
0
 static private void ParseProjectItems(IServiceProvider serviceProvider, ProjectItems projectItems)
 {
     for (int i = 1, n = projectItems.Count; i <= n; ++i)
     {
         var projectItem = projectItems.Item(i);
         ParseProjectItem(serviceProvider, projectItem);
     }
 }
Exemplo n.º 18
0
 private static void DoActionForItems(ProjectItems projectItems, TargetAction action, CodeCleanerType[] type)
 {
     for (int subItemIndex = 1; subItemIndex <= projectItems.Count; subItemIndex++)
     {
         var subItem = projectItems.Item(subItemIndex);
         ActionCSharpOnProjectItem.Action(subItem, action, type);
     }
 }
Exemplo n.º 19
0
        public void AddFromFile(string fileName,string itemName)
        {
            int rootLen = projectDir.Length;
            string folderName = viewsFolderName.Substring(rootLen + 1, viewsFolderName.Length - rootLen - 1);
            int index = GetActiveProject();
            if (index > 0)
            {
                viewsFolder = dte.Solution.Projects.Item(index).ProjectItems; ;//default ViewsFolder is  the root of the project
                SearchFolder(folderName, viewsFolder);//find the real folder the new view must be inserted to
                viewsFolder.AddFromTemplate(fileName, itemName);
                int i = 1;
                for (; i < viewsFolder.Count; i++)
                    if (viewsFolder.Item(i).Name == itemName)
                        break;
                //EnvDTE.Constants.vsViewKindCode = {7651A701-06E5-11D1-8EBD-00A0C90F26EA}
                viewsFolder.Item(i).Open("{7651A701-06E5-11D1-8EBD-00A0C90F26EA}").Visible = true;

            }
        }
Exemplo n.º 20
0
        public void AddFromFile(string fileName, string itemName)
        {
            string folderName = GetFolderName();

            GetCurrentProject();
            viewsFolder = curProject.ProjectItems;; //default ViewsFolder is  the root of the project
            SearchFolder(folderName, viewsFolder);  //find the real folder the new view must be inserted to
            viewsFolder.AddFromTemplate(fileName, itemName);
            int i = 1;

            for (; i < viewsFolder.Count; i++)
            {
                if (viewsFolder.Item(i).Name == itemName)
                {
                    break;
                }
            }
            //EnvDTE.Constants.vsViewKindCode = {7651A701-06E5-11D1-8EBD-00A0C90F26EA}
            viewsFolder.Item(i).Open("{7651A701-06E5-11D1-8EBD-00A0C90F26EA}").Visible = true;
        }
Exemplo n.º 21
0
        private List <IProjectItemModel> MapProjectItems(ProjectItems projectItems)
        {
            var result = new List <IProjectItemModel>();

            for (int i = 1; i < projectItems.Count; i++)
            {
                result.Add(new ProjectItemModel(projectItems.Item(i)));
            }

            return(result);
        }
Exemplo n.º 22
0
        public IEnumerator <IDteProjectItem> GetEnumerator()
        {
            var items = new List <IDteProjectItem>();

            for (var i = 1; i < _projectItems.Count + 1; i++)
            {
                var item = _projectItems.Item(i);
                items.Add(new DteProjectItem(item));
            }
            return(items.GetEnumerator());
        }
Exemplo n.º 23
0
        public void AddNewItem(string templateName, string name, string extension, string destinationPath)
        {
            var project = GetSelectedProject <IVsHierarchy>()?.GetDTEProject();

            if (project != null)
            {
                DTE dte      = VsAppShell.Current.GetGlobalService <DTE>();
                var solution = (Solution2)dte.Solution;

                // Construct name of the compressed template
                templateName = Path.ChangeExtension(templateName, "vstemplate");
                var templatePath = Path.Combine(GetProjectItemTemplatesFolder(), Path.GetFileNameWithoutExtension(templateName), templateName);

                // Given path to the project or a folder in it, generate unique file name
                var fileName = GetUniqueFileName(destinationPath, name, extension);

                // Locate folder in the project
                var projectFolder = Path.GetDirectoryName(project.FullName);
                if (destinationPath.StartsWithIgnoreCase(projectFolder))
                {
                    ProjectItems projectItems = project.ProjectItems;

                    if (destinationPath.Length > projectFolder.Length)
                    {
                        var relativePath = destinationPath.Substring(projectFolder.Length + 1);

                        // Go into folders and find project item to insert the file in
                        while (relativePath.Length > 0)
                        {
                            int    index = relativePath.IndexOf('\\');
                            string folder;
                            if (index >= 0)
                            {
                                folder       = relativePath.Substring(0, index);
                                relativePath = relativePath.Substring(index + 1);
                            }
                            else
                            {
                                folder       = relativePath;
                                relativePath = string.Empty;
                            }
                            try {
                                var item = projectItems.Item(folder);
                                projectItems = item.ProjectItems;
                            } catch (COMException) {
                                return;
                            }
                        }
                    }
                    projectItems?.AddFromTemplate(templatePath, Path.GetFileName(fileName));
                }
            }
        }
Exemplo n.º 24
0
        public void AddFromFile(string fileName, string itemName)
        {
            int    rootLen    = projectDir.Length;
            string folderName = viewsFolderName.Substring(rootLen + 1, viewsFolderName.Length - rootLen - 1);
            int    index      = GetActiveProject();

            if (index > 0)
            {
                viewsFolder = dte.Solution.Projects.Item(index).ProjectItems;; //default ViewsFolder is  the root of the project
                SearchFolder(folderName, viewsFolder);                         //find the real folder the new view must be inserted to
                viewsFolder.AddFromTemplate(fileName, itemName);
                int i = 1;
                for (; i < viewsFolder.Count; i++)
                {
                    if (viewsFolder.Item(i).Name == itemName)
                    {
                        break;
                    }
                }
                //EnvDTE.Constants.vsViewKindCode = {7651A701-06E5-11D1-8EBD-00A0C90F26EA}
                viewsFolder.Item(i).Open("{7651A701-06E5-11D1-8EBD-00A0C90F26EA}").Visible = true;
            }
        }
Exemplo n.º 25
0
        private static ProjectItem GetProjectItem(ProjectItems projectItems, string name, string kind)
        {
            try {
                ProjectItem projectItem = projectItems.Item(name);
                if (kind.Equals(projectItem.Kind, StringComparison.OrdinalIgnoreCase))
                {
                    return(projectItem);
                }
            }
            catch {
            }

            return(null);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Determines whether project item exists
        /// </summary>
        /// <param name="items">The items.</param>
        /// <param name="itemName">Name of the item.</param>
        /// <returns>
        ///   <c>true</c> if project item exists ; otherwise, <c>false</c>.
        /// </returns>
        internal static bool IsProjectItemExist(ProjectItems items, string itemName)
        {
            for (int i = 1; i <= items.Count; i++)
            {
                ProjectItem projItem     = items.Item(i);
                string      projItemName = projItem.Name;
                if (projItemName.ToUpper(CultureInfo.InvariantCulture) == itemName.ToUpper(CultureInfo.InvariantCulture))
                {
                    return(true);
                }
            }

            return(false);
        }
        public bool IsMethodExist(string methodName)
        {
            string       fileNameWithoutExtension = Path.GetFileNameWithoutExtension(methodName);
            ProjectItem  folder;
            ProjectItems serverMethodFolderItems = ServerMethodFolderItems;

            if (serverMethodFolderItems.Exists(fileNameWithoutExtension))
            {
                folder = serverMethodFolderItems.Item(fileNameWithoutExtension);
                string methodNameWithExtension = !Path.HasExtension(methodName) ? methodName + ".cs" : methodName;
                return(folder.ProjectItems.Exists(methodNameWithExtension));
            }

            return(false);
        }
Exemplo n.º 28
0
        protected ProjectItem FindProjectItem(ProjectItems Items, string Name)
        {
            ProjectItem item = null;

            for (int i = 1; i <= Items.Count; i++)
            {
                ProjectItem item2 = Items.Item(i);
                if (item2.Name == Name)
                {
                    item = item2;
                    break;
                }
            }
            return(item);
        }
        private IEnumerable <ProjectItemWrapper> EnumerateProjectItems(ProjectItems items)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (items != null)
            {
                for (int i = 1; i <= items.Count; i++)
                {
                    var itm = items.Item(i);

                    foreach (var res in EnumerateProjectItems(itm.ProjectItems))
                    {
                        yield return(res);
                    }

                    try
                    {
                        var itmGuid = Guid.Parse(itm.Kind);
                        if (itmGuid.Equals(ProjectVirtualFolderGuid) ||
                            itmGuid.Equals(ProjectFolderGuid))
                        {
                            continue;
                        }
                    }
                    catch (Exception)
                    {
                        // itm.Kind may throw an exception with certain node types like WixExtension (COMException)
                    }

                    for (short j = 0; itm != null && j < itm.FileCount; j++)
                    {
                        bool bSkip = false;
                        foreach (var ending in FileEndingsToSkip)
                        {
                            if (itm.FileNames[1] == null || itm.FileNames[1].EndsWith(ending))
                            {
                                bSkip = true;
                                break;
                            }
                        }

                        if (!bSkip)
                        {
                            yield return(new ProjectItemWrapper(itm));
                        }
                    }
                }
            }
        }
Exemplo n.º 30
0
        internal static ProjectItem FindProjectItem(ProjectItems projectItems, string lookupName)
        {
            int count = projectItems.Count;

            for (int i = 1; i <= count; i++)
            {
                ProjectItem projectItem = projectItems.Item(i);

                if (string.Equals(lookupName, projectItem.Name, StringComparison.OrdinalIgnoreCase))
                {
                    return(projectItem);
                }
            }

            return(null);
        }
Exemplo n.º 31
0
        internal static ProjectItem FindProjectItem(ProjectItems projectItems, string lookupName)
        {
            int count = projectItems.Count;

            for (int i = 1; i <= count; i++)
            {
                ProjectItem projectItem = projectItems.Item(i);

                if (string.Equals(lookupName, projectItem.Name, StringComparison.OrdinalIgnoreCase))
                {
                    return projectItem;
                }
            }

            return null;
        }
Exemplo n.º 32
0
 /// <summary>
 /// 通过名字查找项目中的项
 /// </summary>
 /// <param name="items"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 private static ProjectItem FindItem(ProjectItems items, string name)
 {
     for (int i = 1; i <= items.Count; i++)
     {
         try
         {
             ProjectItem item = items.Item(i);
             if (name == item.Name)
             {
                 return(item);
             }
         }
         catch { }
     }
     return(null);
 }
Exemplo n.º 33
0
        private static ProjectItem GetProjectItem(this ProjectItems projectItems, string name, IEnumerable <string> allowedItemKinds)
        {
            try
            {
                ProjectItem projectItem = projectItems.Item(name);
                if (projectItem != null && allowedItemKinds.Contains(projectItem.Kind, StringComparer.OrdinalIgnoreCase))
                {
                    return(projectItem);
                }
            }
            catch
            {
            }

            return(null);
        }
Exemplo n.º 34
0
        /// <summary>
        /// Create a new item in the project
        /// </summary>
        /// <param name="parent">the parent collection for the new item</param>
        /// <param name="templateName"></param>
        /// <param name="language"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static ProjectItem AddNewItemFromVsTemplate(ProjectItems parent, string templateName, string language, string name)
        {
            if (parent == null)
                throw new ArgumentException("project");
            if (name == null)
                throw new ArgumentException("name");

            DTE dte = (DTE)VsIdeTestHostContext.ServiceProvider.GetService(typeof(DTE));

            Solution2 sol = dte.Solution as Solution2;

            string filename = sol.GetProjectItemTemplate(templateName, language);

            parent.AddFromTemplate(filename, name);

            return parent.Item(name);
        }
Exemplo n.º 35
0
 public void CompileChildren(ProjectItems elementProjectItems, List <IReflektorCodeFile> document, string filterName = null)
 {
     for (int k = 1; k <= elementProjectItems.Count; ++k)
     {
         var elementProjectItem = elementProjectItems.Item(k);
         var childItems         = elementProjectItem.ProjectItems;
         if (childItems.Count > 0)
         {
             CompileChildren(childItems, document, filterName);
         }
         else if (elementProjectItem.Name == $"{filterName}.cs" || (String.IsNullOrEmpty(filterName) && elementProjectItem.Name.EndsWith(".cs")))
         {
             var className = elementProjectItem.Name.Replace(".cs", "");
             var fullPath  = elementProjectItem.FileNames[0];
             document.Add(new ReflektorCodeFile(className, fullPath, _reflektorProject, elementProjectItem));
         }
     }
 }
        private ProjectItem IncludeExistingFolder(string folderName, ProjectItems collection)
        {
            IVsHierarchy targetHierarchy = TargetProject.GetVsHierarchy(solution);
            IVsProject targetIVsProject = targetHierarchy as IVsProject;
            if (targetIVsProject != null)
            {
                string folderAbsolutePath;
                ProjectItem parentProjectItem = collection.Parent as ProjectItem;
                if (parentProjectItem != null)
                {
                    folderAbsolutePath = Path.Combine(parentProjectItem.Properties.GetValue("FullPath", string.Empty), folderName);
                }
                else
                {
                    folderAbsolutePath = Path.Combine(Path.GetDirectoryName(TargetProject.FullName), folderName);
                }
                string containerFolderRelativePath = GetPathRelativeToProject(TargetProject, Path.GetDirectoryName(folderAbsolutePath));

                uint containerFolderId = hierarchyHelper.GetItemId(targetHierarchy, containerFolderRelativePath);
                VSADDRESULT[] result = new VSADDRESULT[1];

                int hr = targetIVsProject.AddItem(containerFolderId,
                                                  VSADDITEMOPERATION.VSADDITEMOP_OPENFILE,
                                                  string.Empty, //No file name because it's a directory
                                                  1, // Has to correspond to #items below...
                                                  new[] { folderAbsolutePath }, // Full path to item
                                                  IntPtr.Zero, // Don't show window
                                                  result); // Result array...
                ErrorHandler.ThrowOnFailure(hr);
                logger.Log(string.Format(CultureInfo.CurrentCulture, Resources.IncludingExistingFolderInProject, GetPathRelativeToProject(TargetProject, folderAbsolutePath), TargetProject.Name));
            }
            return collection.Item(folderName);
        }
Exemplo n.º 37
0
 public static ProjectItem FindProjectItemByFileName(ProjectItems projectItems, string relativePathAndName)
 {
     for (var ii = 1; ii <= projectItems.Count; ii++)
     {
         var projectItem = projectItems.Item(ii);
         if (projectItem != null)
         {
             if (projectItem.Kind == Constants.vsProjectItemKindPhysicalFolder)
             {
                 var p = FindProjectItemByFileName(projectItem.ProjectItems, relativePathAndName);
                 if (p != null) return p;
             }
             else
             {
                 var fileName = projectItem.FileNames[0];
                 if (fileName.ToLower() == relativePathAndName.ToLower())
                 {
                     return projectItem;
                 }
             }
         }
     }
     return null;
 }
Exemplo n.º 38
0
        private ArrayList GetItem(ProjectItems prj, string prjName)
        {
            ArrayList result = new ArrayList();

            try
            {
                for(int iProjectItem = 0; iProjectItem < prj.Count; iProjectItem++)
                {
                    ProjectItem prjItem = prj.Item(iProjectItem+1);

                    Property ob = null;
                    for(int i = 0; i < prjItem.Properties.Count; i++)
                    {
                        Property p = prjItem.Properties.Item(i+1);
                        if (p.Name == "SubType")
                        {
                            ob = p;
                            break;
                        }
                    }

                    if (ob != null)
                    {
                        int img = -1;
                        int add = 0;
                        if (_onlyOpenned)
                            if (prjItem.Document == null) continue;

                        if (prjItem.Document != null)
                            add = 4;
                        if (ob.Value.ToString() == "Code")
                            img = 0 + add;
                        if (ob.Value.ToString() == "Form")
                            img = 1 + add;
                        if (ob.Value.ToString() == "UserControl")
                            img = 2 + add;
                        if (ob.Value.ToString() == "Component")
                            img = 3 + add;

                        //if (img == -1)
                            //continue;

                        result.Add(new ListItemData(prjItem.Name, img, prjName, prjItem));
                    }

                    if (prjItem.ProjectItems != null)
                    {
                        result.AddRange(GetItem(prjItem.ProjectItems, prjName + "\\" + prjItem.Name));
                    }
                }
            }
            catch
            {
                //System.Diagnostics.Trace.WriteLine(e.Message, "AS VS Expert: GetItem");
            }

            return result;
        }
Exemplo n.º 39
0
 private void duplicateFiles(ProjectItems projItems)
 {
     ProjectItem projItem;
     for (int i = 1; i <= projItems.Count; i++)
     {
         projItem = projItems.Item(i);
         Debug.Write(projItem.Name + "  " + projItem.Kind);
         try
         {
             if (projItem.ProjectItems.Count > 0)
             {
                 duplicateFiles(projItem.ProjectItems);
             }
             else if (selectedProjectItems.Contains(projItem))
             {
                 selectedProjectItems.Remove(projItem);
                 String newPath = copyFile(projItem);
                 if (newPath != null)
                 {
                     try
                     {
                         lastAdded = projItems.AddFromFile(newPath);
                     }
                     catch (Exception) { }
                 }
             }
         }
         catch (Exception)
         {
         }
     }
 }
Exemplo n.º 40
0
        /// <summary>
        /// Removes the files and folders.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        /// <param name="targetProjectType">Type of the target project.</param>
        /// <param name="levels">The number of levels to walk down the chain. If <c>-1</c>, it will handle all levels.</param>
        /// <param name="fileFilter">An enumerable of files that should be handled with care, can be <c>null</c>.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="source" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="target" /> is <c>null</c>.</exception>
        private void RemoveFilesAndFolders(ProjectItems source, ProjectItems target, ProjectType targetProjectType, int levels, IEnumerable<string> fileFilter)
        {
            Argument.IsNotNull("source", source);
            Argument.IsNotNull("target", target);

            if (fileFilter == null)
            {
                fileFilter = new string[] { };
            }

            string targetParentName = target.Parent.GetObjectName();

            Log.Debug("Removing files and folders from target '{0}'", targetParentName);

            if (levels == 0)
            {
                return;
            }

            levels--;

            // Yep, this is right, we start at 1... :(
            for (int i = 1; i < target.Count + 1; i++)
            {
                var targetItem = target.Item(i);

                if (ShouldSkipRemovingOfItem(source.ContainingProject, targetItem, targetProjectType))
                {
                    Log.Debug("Skipping item '{0}' because it is ignored by a rule for target project {1}", targetItem.GetObjectName(), targetProjectType);
                    continue;
                }

                var existingSourceItem = (from sourceItem in source.Cast<ProjectItem>() where string.Equals(targetItem.Name, sourceItem.Name, StringComparison.InvariantCultureIgnoreCase) select sourceItem).FirstOrDefault();

                if (existingSourceItem != null && !fileFilter.Any(x => string.Equals(x, targetItem.GetNameRelativeToRoot(), StringComparison.InvariantCultureIgnoreCase)))
                {
                    // Check if the item should be removed (when the item should not be added as linked file, then we should remove it)
                    if (!ShouldSkipAddingOfItem(existingSourceItem, targetProjectType))
                    {
                        RemoveFilesAndFolders(existingSourceItem.ProjectItems, targetItem.ProjectItems, targetProjectType, levels, fileFilter);
                        continue;
                    }

                    Log.Debug("Found linked file '{0}' that is now ignored by a rule, removing it", targetItem.FileNames[0]);
                }

                // Get it once, we don't want to retrieve this several times
                var relatedProjects = source.ContainingProject.GetRelatedProjects(false);

                if (targetItem.IsFolder())
                {
                    RemoveNestedItems(targetItem.ProjectItems, relatedProjects);

                    if (targetItem.ProjectItems.Count == 0)
                    {
                        Log.Debug("Removing folder '{0}' because it no longer contains items", targetItem.Name);

                        targetItem.Remove();
                        i--;
                    }
                }
                else
                {
                    // If this is a linked file and not an actual file in another related project, remove it
                    if (targetItem.IsLinkedFile() && !targetItem.IsActualFileInAnyRelatedProject(relatedProjects))
                    {
                        Log.Debug("Removing file '{0}' because it is a linked file to the root project", targetItem.FileNames[0]);

                        targetItem.Remove();
                        i--;
                    }
                }
            }

            Log.Debug("Removed files and folders from target '{0}'", targetParentName);
        }
Exemplo n.º 41
0
        /// <summary>
        /// Removes the nested items of an item of which the soure does not exists.
        /// </summary>
        /// <param name="projectItems">The project items.</param>
        /// <param name="relatedProjects">The related projects.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="projectItems" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="relatedProjects" /> is <c>null</c>.</exception>
        private void RemoveNestedItems(ProjectItems projectItems, Project[] relatedProjects)
        {
            Argument.IsNotNull("projectItems", projectItems);
            Argument.IsNotNull("relatedProjects", relatedProjects);

            for (int i = 1; i < projectItems.Count + 1; i++)
            {
                ProjectItem folderItem = projectItems.Item(i);
                if (folderItem.IsFolder())
                {
                    RemoveNestedItems(folderItem.ProjectItems, relatedProjects);

                    if (folderItem.ProjectItems.Count == 0)
                    {
                        Log.Debug("Removing folder '{0}' because it no longer contains items", folderItem.Name);

                        folderItem.Remove();
                        i--;
                    }
                }
                else
                {
                    // If this is a linked file and not an actual file in another related project, remove it
                    if (folderItem.IsLinkedFile() && !folderItem.IsActualFileInAnyRelatedProject(relatedProjects))
                    {
                        folderItem.Remove();
                        i--;
                    }
                }
            }
        }
        /// <summary>
        /// Updates the model.
        /// </summary>
        /// <param name="projectItems">The project items.</param>
        /// <param name="fw">The fw.</param>
        public static void UpdateModel(
            ProjectItems projectItems,
            ITestFramework fw)
        {
            for (var i = 1; i < projectItems.Count - 1; i++)
            {
                var projectItem = projectItems.Item(i);

                if (projectItem.Name.EndsWith(
                    ".log",
                    StringComparison.OrdinalIgnoreCase)) continue;

                var testClass =
                    (from tc in fw.Classes
                     where tc.Name == projectItem.Name.Replace(".cs", "")
                     select tc).FirstOrDefault();

                if (testClass == null)
                {
                    //todo: dump code to log....
                    continue;
                }

                string fileContent;
                using (var sr = new StreamReader(projectItem.FileNames[0]))
                {
                    fileContent = sr.ReadToEnd();
                }

                var usingMatches = s_usingRegex.Matches(fileContent);
                for (var j = 0; j < usingMatches.Count; j++)
                {
                    var match = usingMatches[j];
                    if (!testClass.UsingStatements.Contains(match.Value))
                    {
                        testClass.UsingStatements.Add(match.Value);
                    }
                }

                var matches = s_codeRegex.Matches(fileContent);
                for (var j = 0; j < matches.Count; j++)
                {
                    var match = matches[j];

                    if (!match.Success) continue;

                    var testName = match.Groups["testname"].Value;
                    var testAttributes = match.Groups["attributes"].Value;
                    var testImplementation = match.Groups["code"].Value;

                    var test =
                        (from t in testClass.Tests
                         where t.Name == testName
                         select t).FirstOrDefault();

                    if (test == null)
                    {
                        //todo: dump code to log....
                        continue;
                    }

                    test.Attributes = testAttributes;
                    test.Implementation = testImplementation;
                }
            }
        }
        private IEnumerable<ProjectItemWrapper> EnumerateProjectItems(ProjectItems items)
        {
            if (items != null)
            {
                for (int i = 1; i <= items.Count; i++)
                {
                    var itm = items.Item(i);
                    var itmGuid = Guid.Parse(itm.Kind);

                    foreach (var res in EnumerateProjectItems(itm.ProjectItems))
                    {
                        yield return res;
                    }

                    if (itmGuid.Equals(ProjectVirtualFolderGuid)
                        || itmGuid.Equals(ProjectFolderGuid))
                    {
                        continue;
                    }

                    for (short j = 0; itm != null && j < itm.FileCount; j++)
                    {
                        bool bSkip = false;
                        foreach (var ending in FileEndingsToSkip)
                        {
                            if (itm.FileNames[1] == null || itm.FileNames[1].EndsWith(ending))
                            {
                                bSkip = true;
                                break;
                            }
                        }

                        if (!bSkip)
                        {
                            yield return new ProjectItemWrapper(itm);
                        }
                    }
                }
            }
        }
Exemplo n.º 44
0
        /// <summary>
        /// Create a new item in the project
        /// </summary>
        /// <param name="project">the project collection for the new item</param>
        /// <param name="templateName"></param>
        /// <param name="language"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public ProjectItem AddNewItemFromVsTemplate(ProjectItems project, string templateName, string language, string name)
        {
            if (project == null)
                throw new ArgumentException(nameof(project));
            if (name == null)
                throw new ArgumentException(nameof(name));

            var dte = (DTE)VsIdeTestHostContext.ServiceProvider.GetService(typeof(DTE));

            var sol = (Solution2) dte.Solution;

            var filename = sol.GetProjectItemTemplate(templateName, language);

            project.AddFromTemplate(filename, name);

            return project.Item(name);
        }
Exemplo n.º 45
0
            private static ProjectItems GetSqlFileItems(string groupFolderName, ProjectItems scheduledTasksProjectItems)
            {
                ProjectItems groupFolderFileItems;
                ProjectItem groupFolder = GetGroupFolder(groupFolderName, scheduledTasksProjectItems.Item("sql").ProjectItems);

                groupFolderFileItems = groupFolder.ProjectItems;

                return groupFolderFileItems;
            }
Exemplo n.º 46
0
            private static ProjectItem GetGroupFolder(string groupFolderName, ProjectItems ProjectItems)
            {
                ProjectItem groupFolder = ProjectItems.Item(groupFolderName);

                if (groupFolder == null)
                    throw new Exception(string.Empty);

                return groupFolder;
            }