/// <summary> /// Creates an PythonProject. /// </summary> protected override IProject CreateProject(string targetProjectDirectory, IProject sourceProject) { // Add IronPython reference. PythonProject targetProject = (PythonProject)base.CreateProject(targetProjectDirectory, sourceProject); IProjectItemListProvider targetProjectItems = targetProject as IProjectItemListProvider; targetProjectItems.AddProjectItem(CreateIronPythonReference(targetProject)); return(targetProject); }
protected virtual void CopyItems(IProject sourceProject, IProject targetProject, IProgressMonitor monitor) { if (sourceProject == null) { throw new ArgumentNullException("sourceProject"); } if (targetProject == null) { throw new ArgumentNullException("targetProject"); } IProjectItemListProvider targetProjectItems = targetProject as IProjectItemListProvider; if (targetProjectItems == null) { throw new ArgumentNullException("targetProjectItems"); } ICollection <ProjectItem> sourceItems = sourceProject.Items; double totalWork = 0; foreach (ProjectItem item in sourceItems) { totalWork += GetRequiredWork(item); } foreach (ProjectItem item in sourceItems) { FileProjectItem fileItem = item as FileProjectItem; if (fileItem != null && FileUtility.IsBaseDirectory(sourceProject.Directory, fileItem.FileName)) { FileProjectItem targetItem = new FileProjectItem(targetProject, fileItem.ItemType); fileItem.CopyMetadataTo(targetItem); targetItem.Include = fileItem.Include; if (File.Exists(fileItem.FileName)) { if (!Directory.Exists(Path.GetDirectoryName(targetItem.FileName))) { Directory.CreateDirectory(Path.GetDirectoryName(targetItem.FileName)); } try { ConvertFile(fileItem, targetItem); } catch (Exception ex) { throw new ConversionException("Error converting " + fileItem.FileName, ex); } } targetProjectItems.AddProjectItem(targetItem); } else { targetProjectItems.AddProjectItem(item.CloneFor(targetProject)); } monitor.CancellationToken.ThrowIfCancellationRequested(); monitor.Progress += GetRequiredWork(item) / totalWork; } }
protected override IProject CreateProject(string targetProjectDirectory, IProject sourceProject) { VBNetProject project = (VBNetProject)base.CreateProject(targetProjectDirectory, sourceProject); IProjectItemListProvider provider = (IProjectItemListProvider)project; foreach (string import in defaultImports) { provider.AddProjectItem(new ImportProjectItem(project, import)); } return(project); }
/// <summary> /// Adds a project item to the project, raising the ProjectItemAdded event. /// Make sure you call project.Save() after adding new items! /// </summary> public static void AddProjectItem(IProject project, ProjectItem item) { if (project == null) { throw new ArgumentNullException("project"); } if (item == null) { throw new ArgumentNullException("item"); } IProjectItemListProvider provider = project as IProjectItemListProvider; if (provider != null) { provider.AddProjectItem(item); OnProjectItemAdded(new ProjectItemEventArgs(project, item)); } }
protected override IProject CreateProject(string targetProjectDirectory, IProject sourceProject) { CSharpProject project = (CSharpProject)base.CreateProject(targetProjectDirectory, sourceProject); IProjectItemListProvider provider = (IProjectItemListProvider)project; provider.AddProjectItem(new ReferenceProjectItem(project, "Microsoft.VisualBasic")); FileProjectItem fileItem = new FileProjectItem(project, ItemType.Compile, "MyNamespaceSupportForCSharp.cs"); provider.AddProjectItem(fileItem); try { File.WriteAllText(fileItem.FileName, CSharpMyNamespaceBuilder.BuildMyNamespaceCode((CompilableProject)sourceProject)); } catch (Exception ex) { conversionLog.AppendLine(ex.ToString()); } return(project); }
static void FileServiceFileRemoved(object sender, FileEventArgs e) { if (OpenSolution == null) { return; } string fileName = e.FileName; foreach (ISolutionFolderContainer container in OpenSolution.SolutionFolderContainers) { for (int i = 0; i < container.SolutionItems.Items.Count;) { SolutionItem item = container.SolutionItems.Items[i]; if (FileUtility.IsBaseDirectory(fileName, Path.Combine(OpenSolution.Directory, item.Name))) { container.SolutionItems.Items.RemoveAt(i); } else { ++i; } } } foreach (IProject project in OpenSolution.Projects) { if (FileUtility.IsBaseDirectory(project.Directory, fileName)) { IProjectItemListProvider provider = project as IProjectItemListProvider; if (provider != null) { foreach (ProjectItem item in Linq.ToArray(provider.Items)) { if (FileUtility.IsBaseDirectory(fileName, item.FileName)) { provider.RemoveProjectItem(item); OnProjectItemRemoved(new ProjectItemEventArgs(project, item)); } } } } } }
protected virtual void CopyItems(IProject sourceProject, IProject targetProject) { if (sourceProject == null) { throw new ArgumentNullException("sourceProject"); } if (targetProject == null) { throw new ArgumentNullException("targetProject"); } IProjectItemListProvider targetProjectItems = targetProject as IProjectItemListProvider; if (targetProjectItems == null) { throw new ArgumentNullException("targetProjectItems"); } foreach (ProjectItem item in sourceProject.Items) { FileProjectItem fileItem = item as FileProjectItem; if (fileItem != null && FileUtility.IsBaseDirectory(sourceProject.Directory, fileItem.FileName)) { FileProjectItem targetItem = new FileProjectItem(targetProject, fileItem.ItemType); fileItem.CopyMetadataTo(targetItem); targetItem.Include = fileItem.Include; if (File.Exists(fileItem.FileName)) { if (!Directory.Exists(Path.GetDirectoryName(targetItem.FileName))) { Directory.CreateDirectory(Path.GetDirectoryName(targetItem.FileName)); } ConvertFile(fileItem, targetItem); } targetProjectItems.AddProjectItem(targetItem); } else { targetProjectItems.AddProjectItem(item.CloneFor(targetProject)); } } }