Exemple #1
0
        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;
            }
        }
Exemple #2
0
        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);
        }
        /// <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 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);
        }
Exemple #5
0
        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));
                }
            }
        }
        /// <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));
            }
        }