private static void AddEntry(ConfiguredFiles configuredFiles, SourceFile sourceFile)
 {
     if (sourceFile != null)
     {
         List <SourceFile> sourceFileList = new List <SourceFile>
         {
             sourceFile
         };
         AddEntry(configuredFiles, sourceFileList);
     }
 }
        private static void AddEntry(ConfiguredFiles configuredFiles, List <SourceFile> sourceFileList)
        {
            foreach (SourceFile newSourceFile in sourceFileList)
            {
                if (newSourceFile == null)
                {
                    continue;
                }

                for (int index = 0; index < configuredFiles.Files.Count; index++)
                {
                    if (newSourceFile.FileName.CompareTo(configuredFiles.Files[index].FileName) == 0 &&
                        newSourceFile.FilePath.CompareTo(configuredFiles.Files[index].FilePath) == 0)
                    {
                        // file already exists in list
                        return;
                    }
                }


                configuredFiles.Files.Add(newSourceFile);
            }
        }
        private async Task <List <ConfiguredFiles> > GetActiveSelectionsAsync()
        {
            Dictionary <Project, ConfiguredFiles> confMap = new Dictionary <Project, ConfiguredFiles>();

            foreach (SelectedItem selItem in _dte.SelectedItems)
            {
                Project project = null;
                if (project == null && selItem.ProjectItem != null)
                {
                    project = selItem.ProjectItem.ContainingProject;
                }

                if (project == null)
                {
                    project = selItem.Project;
                }

                if (project == null || !IsVisualCppProject(project.Kind))
                {
                    continue;
                }

                Configuration configuration = await GetConfigurationAsync(project);

                if (!confMap.ContainsKey(project))
                {
                    // create new Map key entry for project
                    ConfiguredFiles configuredFiles = new ConfiguredFiles();
                    confMap.Add(project, configuredFiles);
                    configuredFiles.Files         = new List <SourceFile>();
                    configuredFiles.Configuration = configuration;
                }

                ConfiguredFiles currentConfiguredFiles = confMap[project];

                if (currentConfiguredFiles == null)
                {
                    continue;
                }

                if (selItem.ProjectItem == null)
                {
                    // project selected
                    List <SourceFile> projectSourceFileList = await GetProjectFilesAsync(project, configuration);

                    foreach (SourceFile _ in projectSourceFileList)
                    {
                        AddEntry(currentConfiguredFiles, projectSourceFileList);
                    }
                }
                else
                {
                    dynamic projectItem = selItem.ProjectItem.Object;

                    if (IsCppFile(projectItem))
                    {
                        dynamic file = selItem.ProjectItem.Object;

                        // non project selected
                        if (file != null)
                        {
                            project.Save();
                            // document selected
                            SourceFile sourceFile = await CreateSourceFileAsync(file.FullPath, configuration, project);

                            AddEntry(currentConfiguredFiles, sourceFile);
                        }
                    }
                }
            }

            List <ConfiguredFiles> configuredFilesList = new List <ConfiguredFiles>();

            foreach (ConfiguredFiles configuredFiles in confMap.Values)
            {
                if (configuredFiles.Files.Any())
                {
                    configuredFilesList.Add(configuredFiles);
                }
            }

            return(configuredFilesList);
        }