コード例 #1
0
        public override void Run()
        {
            conversionLog = new StringBuilder();
            string translatedTitle = ResourceService.GetString("ICSharpCode.SharpDevelop.Commands.Convert.ProjectConverter");

            conversionLog.AppendLine(translatedTitle);
            conversionLog.Append('=', translatedTitle.Length);
            conversionLog.AppendLine();
            conversionLog.AppendLine();
            MSBuildBasedProject sourceProject = ProjectService.CurrentProject as MSBuildBasedProject;
            string targetProjectDirectory     = sourceProject.Directory + ".ConvertedTo" + TargetLanguageName;

            if (Directory.Exists(targetProjectDirectory))
            {
                MessageService.ShowMessageFormatted(translatedTitle, "${res:ICSharpCode.SharpDevelop.Commands.Convert.TargetAlreadyExists}", targetProjectDirectory);
                return;
            }
            conversionLog.Append(ResourceService.GetString("ICSharpCode.SharpDevelop.Commands.Convert.SourceDirectory")).Append(": ");
            conversionLog.AppendLine(sourceProject.Directory);
            conversionLog.Append(ResourceService.GetString("ICSharpCode.SharpDevelop.Commands.Convert.TargetDirectory")).Append(": ");
            conversionLog.AppendLine(targetProjectDirectory);

            Directory.CreateDirectory(targetProjectDirectory);
            IProject targetProject = CreateProject(targetProjectDirectory, sourceProject);

            CopyProperties(sourceProject, targetProject);
            conversionLog.AppendLine();
            CopyItems(sourceProject, targetProject);
            conversionLog.AppendLine();
            AfterConversion(targetProject);
            conversionLog.AppendLine(ResourceService.GetString("ICSharpCode.SharpDevelop.Commands.Convert.ConversionComplete"));
            targetProject.Save();
            targetProject.Dispose();
            TreeNode node = ProjectBrowserPad.Instance.SelectedNode;

            if (node == null)
            {
                node = ProjectBrowserPad.Instance.SolutionNode;
            }
            while (node != null)
            {
                if (node is ISolutionFolderNode)
                {
                    AddExitingProjectToSolution.AddProject((ISolutionFolderNode)node, targetProject.FileName);
                    ProjectService.SaveSolution();
                    break;
                }
                node = node.Parent;
            }
            ICSharpCode.SharpDevelop.Gui.IWorkbenchWindow newFileWindow;
            newFileWindow = FileService.NewFile(ResourceService.GetString("ICSharpCode.SharpDevelop.Commands.Convert.ConversionResults"), "Text", conversionLog.ToString());
            if (newFileWindow != null)
            {
                newFileWindow.ViewContent.IsDirty = false;
            }
        }
コード例 #2
0
        void PerformConversion(string translatedTitle, MSBuildBasedProject sourceProject, string targetProjectDirectory)
        {
            IProject targetProject;

            using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog(translatedTitle, "Converting", true)) {
                Directory.CreateDirectory(targetProjectDirectory);
                targetProject = CreateProject(targetProjectDirectory, sourceProject);
                CopyProperties(sourceProject, targetProject);
                conversionLog.AppendLine();
                CopyItems(sourceProject, targetProject, monitor);
                monitor.CancellationToken.ThrowIfCancellationRequested();
                conversionLog.AppendLine();
                AfterConversion(targetProject);
                conversionLog.AppendLine(ResourceService.GetString("ICSharpCode.SharpDevelop.Commands.Convert.ConversionComplete"));
                targetProject.Save();
                targetProject.Dispose();
            }

            TreeNode node = ProjectBrowserPad.Instance.SelectedNode;

            if (node == null)
            {
                node = ProjectBrowserPad.Instance.SolutionNode;
            }
            while (node != null)
            {
                if (node is ISolutionFolderNode)
                {
                    AddExitingProjectToSolution.AddProject((ISolutionFolderNode)node, targetProject.FileName);
                    ProjectService.SaveSolution();
                    break;
                }
                node = node.Parent;
            }
            IViewContent newFileWindow;

            newFileWindow = FileService.NewFile(ResourceService.GetString("ICSharpCode.SharpDevelop.Commands.Convert.ConversionResults"), conversionLog.ToString());
            if (newFileWindow != null)
            {
                newFileWindow.PrimaryFile.IsDirty = false;
            }
        }