public void SetUpFixture()
		{
			RubyMSBuildEngineHelper.InitMSBuildEngine();

			List<ProjectBindingDescriptor> bindings = new List<ProjectBindingDescriptor>();
			using (TextReader reader = RubyBindingAddInFile.ReadAddInFile()) {
				AddIn addin = AddIn.Load(reader, String.Empty);
				bindings.Add(new ProjectBindingDescriptor(AddInHelper.GetCodon(addin, "/SharpDevelop/Workbench/ProjectBindings", "Ruby")));
			}
			ProjectBindingService.SetBindings(bindings);
			
			convertProjectCommand = new DerivedConvertProjectToRubyProjectCommand();
			parseInfo = new ParseInformation(new DefaultCompilationUnit(new DefaultProjectContent()));
			convertProjectCommand.ParseInfo = parseInfo;
			convertProjectCommand.FileServiceDefaultEncoding = Encoding.Unicode;
			
			sourceProject = new MockProject();
			sourceProject.Directory = @"d:\projects\test";
			source = new FileProjectItem(sourceProject, ItemType.Compile, @"src\Program.cs");
			targetProject = (RubyProject)convertProjectCommand.CallCreateProject(@"d:\projects\test\converted", sourceProject);
			target = new FileProjectItem(targetProject, source.ItemType, source.Include);
			source.CopyMetadataTo(target);
			
			textFileSource = new FileProjectItem(sourceProject, ItemType.None, @"src\readme.txt");
			textFileTarget = new FileProjectItem(targetProject, textFileSource.ItemType, textFileSource.Include);
			textFileSource.CopyMetadataTo(textFileTarget);
			
			convertProjectCommand.AddParseableFileContent(source.FileName, sourceCode);
			
			convertProjectCommand.CallConvertFile(source, target);
			convertProjectCommand.CallConvertFile(textFileSource, textFileTarget);
		}
		public void SetUpFixture()
		{
			PythonMSBuildEngineHelper.InitMSBuildEngine();

			List<ProjectBindingDescriptor> bindings = new List<ProjectBindingDescriptor>();
			using (TextReader reader = PythonBindingAddInFile.ReadAddInFile()) {
				AddIn addin = AddIn.Load(reader, String.Empty);
				bindings.Add(new ProjectBindingDescriptor(AddInHelper.GetCodon(addin, "/SharpDevelop/Workbench/ProjectBindings", "Python")));
			}
			ProjectBindingService.SetBindings(bindings);
			
			convertProjectCommand = new DerivedConvertProjectToPythonProjectCommand();
			convertProjectCommand.FileServiceDefaultEncoding = Encoding.Unicode;
			
			sourceProject = new MockProject();
			sourceProject.Directory = @"d:\projects\test";
			source = new FileProjectItem(sourceProject, ItemType.Compile, @"src\Program.cs");
			targetProject = (PythonProject)convertProjectCommand.CallCreateProject(@"d:\projects\test\converted", sourceProject);
			target = new FileProjectItem(targetProject, source.ItemType, source.Include);
			source.CopyMetadataTo(target);
			
			textFileSource = new FileProjectItem(sourceProject, ItemType.None, @"src\readme.txt");
			textFileTarget = new FileProjectItem(targetProject, textFileSource.ItemType, textFileSource.Include);
			textFileSource.CopyMetadataTo(textFileTarget);
			
			foreach (ProjectItem item in targetProject.Items) {
				ReferenceProjectItem reference = item as ReferenceProjectItem;
				if ((reference != null) && (reference.Name == "IronPython")) {
					ironPythonReference = reference;
					break;
				}
			}
			
			convertProjectCommand.AddParseableFileContent(source.FileName, sourceCode);
			
			convertProjectCommand.CallConvertFile(source, target);
			convertProjectCommand.CallConvertFile(textFileSource, textFileTarget);
		}
		public void SetUpFixture()
		{
			PythonMSBuildEngineHelper.InitMSBuildEngine();

			List<ProjectBindingDescriptor> bindings = new List<ProjectBindingDescriptor>();
			using (TextReader reader = PythonBindingAddInFile.ReadAddInFile()) {
				AddIn addin = AddIn.Load(reader, String.Empty);
				bindings.Add(new ProjectBindingDescriptor(AddInHelper.GetCodon(addin, "/SharpDevelop/Workbench/ProjectBindings", "Python")));
			}
			ProjectBindingService.SetBindings(bindings);
			
			// Set up IProjectContent so the ConvertProjectToPythonProjectCommand can
			// locate the startup object and determine it's filename.
			
			mockProjectContent = new ICSharpCode.Scripting.Tests.Utils.MockProjectContent();
			MockClass mainClass = new MockClass(mockProjectContent, startupObject);
			mainClass.CompilationUnit.FileName = @"d:\projects\test\src\Main2.cs";
			mockProjectContent.SetClassToReturnFromGetClass(startupObject, mainClass);
			
			convertProjectCommand = new DerivedConvertProjectToPythonProjectCommand();
			convertProjectCommand.ProjectContent = mockProjectContent;
			convertProjectCommand.FileServiceDefaultEncoding = Encoding.Unicode;
			
			Solution solution = new Solution(new MockProjectChangeWatcher());
			sourceProject = new MSBuildBasedProject(
				new ProjectCreateInformation() {
					Solution = solution,
					OutputProjectFileName = @"d:\projects\test\source.csproj",
					ProjectName = "source"
				});
			sourceProject.Parent = solution;
			sourceProject.SetProperty(null, null, "StartupObject", startupObject, PropertyStorageLocations.Base, true);
			mainFile = new FileProjectItem(sourceProject, ItemType.Compile, @"src\Main.cs");
			targetProject = (PythonProject)convertProjectCommand.CallCreateProject(@"d:\projects\test\converted", sourceProject);
			convertProjectCommand.CallCopyProperties(sourceProject, targetProject);
			targetMainFile = new FileProjectItem(targetProject, mainFile.ItemType, mainFile.Include);
			mainFile.CopyMetadataTo(targetMainFile);
			
			main2File = new FileProjectItem(sourceProject, ItemType.Compile, @"src\Main2.cs");
			targetMain2File = new FileProjectItem(targetProject, main2File.ItemType, main2File.Include);
			main2File.CopyMetadataTo(targetMain2File);
			
			convertProjectCommand.AddParseableFileContent(mainFile.FileName, mainSource);
			convertProjectCommand.AddParseableFileContent(main2File.FileName, main2Source);
			
			convertProjectCommand.CallConvertFile(mainFile, targetMainFile);
			convertProjectCommand.CallConvertFile(main2File, targetMain2File);
		}
예제 #4
0
        /// <summary>
        /// Copies or moves a file to this directory.
        /// </summary>
        /// <param name="fileName">The name of the file to copy or move.</param>
        /// <param name="performMove">true to move the file, false to copy it.</param>
        /// <param name="keepDependency">true to copy the DependentUpon value of the file to the target if possible, false to discard the DependentUpon value.</param>
        public void CopyFileHere(string fileName, bool performMove, bool keepDependency)
        {
            string shortFileName  = Path.GetFileName(fileName);
            string copiedFileName = Path.Combine(Directory, shortFileName);

            if (FileUtility.IsEqualFileName(fileName, copiedFileName))
            {
                return;
            }
            bool wasFileReplacement = false;

            if (File.Exists(copiedFileName))
            {
                if (!FileService.FireFileReplacing(copiedFileName, false))
                {
                    return;
                }
                if (AddExistingItemsToProject.ShowReplaceExistingFileDialog(null, copiedFileName, false) == AddExistingItemsToProject.ReplaceExistingFile.Yes)
                {
                    wasFileReplacement = true;
                    IViewContent viewContent = FileService.GetOpenFile(copiedFileName);
                    if (viewContent != null)
                    {
                        viewContent.WorkbenchWindow.CloseWindow(true);
                    }
                }
                else
                {
                    // don't replace file
                    return;
                }
            }

            FileProjectItem newItem       = AddExistingItemsToProject.CopyFile(fileName, this, true);
            IProject        sourceProject = Solution.FindProjectContainingFile(fileName);

            if (sourceProject != null)
            {
                string sourceDirectory         = Path.GetDirectoryName(fileName);
                bool   dependendElementsCopied = false;
                foreach (ProjectItem item in sourceProject.Items)
                {
                    FileProjectItem fileItem = item as FileProjectItem;
                    if (fileItem == null)
                    {
                        continue;
                    }
                    if (newItem != null && FileUtility.IsEqualFileName(fileItem.FileName, fileName))
                    {
                        fileItem.CopyMetadataTo(newItem);
                        if (!keepDependency)
                        {
                            // Prevent the DependentUpon from being copied
                            // because the referenced file is now in a different directory.
                            newItem.DependentUpon = String.Empty;
                        }
                    }
                    if (!string.Equals(fileItem.DependentUpon, shortFileName, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    string itemPath = Path.Combine(sourceProject.Directory, fileItem.VirtualName);
                    if (!FileUtility.IsEqualFileName(sourceDirectory, Path.GetDirectoryName(itemPath)))
                    {
                        continue;
                    }
                    // this file is dependend on the file being copied/moved: copy it, too
                    CopyFileHere(itemPath, performMove, true);
                    dependendElementsCopied = true;
                }
                if (dependendElementsCopied)
                {
                    RecreateSubNodes();
                }
            }
            if (performMove)
            {
                foreach (OpenedFile file in FileService.OpenedFiles)
                {
                    if (file.FileName != null &&
                        FileUtility.IsEqualFileName(file.FileName, fileName))
                    {
                        file.FileName = new FileName(copiedFileName);
                    }
                }
                FileService.RemoveFile(fileName, false);
            }
            if (wasFileReplacement)
            {
                FileService.FireFileReplaced(copiedFileName, false);
            }
        }
예제 #5
0
        public void CopyFileHere(string fileName, bool performMove)
        {
            string shortFileName  = Path.GetFileName(fileName);
            string copiedFileName = Path.Combine(Directory, shortFileName);

            if (FileUtility.IsEqualFileName(fileName, copiedFileName))
            {
                return;
            }
            bool wasFileReplacement = false;

            if (File.Exists(copiedFileName))
            {
                if (!FileService.FireFileReplacing(copiedFileName, false))
                {
                    return;
                }
                if (AddExistingItemsToProject.ShowReplaceExistingFileDialog(null, copiedFileName, false) == AddExistingItemsToProject.ReplaceExistingFile.Yes)
                {
                    wasFileReplacement = true;
                }
                else
                {
                    // don't replace file
                    return;
                }
            }

            FileProjectItem newItem       = AddExistingItemsToProject.CopyFile(fileName, this, true);
            IProject        sourceProject = Solution.FindProjectContainingFile(fileName);

            if (sourceProject != null)
            {
                string sourceDirectory         = Path.GetDirectoryName(fileName);
                bool   dependendElementsCopied = false;
                foreach (ProjectItem item in sourceProject.Items)
                {
                    FileProjectItem fileItem = item as FileProjectItem;
                    if (fileItem == null)
                    {
                        continue;
                    }
                    if (newItem != null && FileUtility.IsEqualFileName(fileItem.FileName, fileName))
                    {
                        fileItem.CopyMetadataTo(newItem);
                    }
                    if (!string.Equals(fileItem.DependentUpon, shortFileName, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    string itemPath = Path.Combine(sourceProject.Directory, fileItem.VirtualName);
                    if (!FileUtility.IsEqualFileName(sourceDirectory, Path.GetDirectoryName(itemPath)))
                    {
                        continue;
                    }
                    // this file is dependend on the file being copied/moved: copy it, too
                    CopyFileHere(itemPath, performMove);
                    dependendElementsCopied = true;
                }
                if (dependendElementsCopied)
                {
                    RecreateSubNodes();
                }
            }
            if (performMove)
            {
                foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection)
                {
                    if (content.FileName != null &&
                        FileUtility.IsEqualFileName(content.FileName, fileName))
                    {
                        content.FileName  = copiedFileName;
                        content.TitleName = shortFileName;
                    }
                }
                FileService.RemoveFile(fileName, false);
            }
            if (wasFileReplacement)
            {
                FileService.FireFileReplaced(copiedFileName, false);
            }
        }