public void SetUpFixture() { WixProject p = WixBindingTestsHelper.CreateEmptyWixProject(); projectDirectory = p.Directory; p.Name = "MySetup"; FileProjectItem item = new FileProjectItem(p, ItemType.Compile); item.Include = "Setup.wxs"; string docFileName = item.FileName; ProjectService.AddProjectItem(p, item); item = new FileProjectItem(p, ItemType.Compile); item.Include = "InvalidXml.wxs"; ProjectService.AddProjectItem(p, item); item = new FileProjectItem(p, ItemType.Compile); item.Include = "MissingFile.wxs"; ProjectService.AddProjectItem(p, item); item = new FileProjectItem(p, ItemType.Compile); item.Include = "Fragment.wxs"; ProjectService.AddProjectItem(p, item); WixDocument doc = new WixDocument(p); doc.FileName = docFileName; doc.LoadXml(GetMainWixXml()); binaries = new WixBinaries(doc, this); }
protected override void ConvertFile(FileProjectItem sourceItem, FileProjectItem targetItem) { FixExtensionOfExtraProperties(targetItem, ".cs", ".boo"); FixExtensionOfExtraProperties(targetItem, ".vb", ".boo"); string ext = Path.GetExtension(sourceItem.FileName); if (".cs".Equals(ext, StringComparison.OrdinalIgnoreCase) || ".vb".Equals(ext, StringComparison.OrdinalIgnoreCase)) { Module module; IList<ICSharpCode.NRefactory.ISpecial> specials; CompileUnit compileUnit = new CompileUnit(); using (StringReader r = new StringReader(ParserService.GetParseableFileContent(sourceItem.FileName))) { module = Parser.ParseModule(compileUnit, r, ConvertBuffer.ApplySettings(sourceItem.VirtualName, errors, warnings), out specials); } if (module == null) { conversionLog.AppendLine("Could not parse '" + sourceItem.FileName + "', see error list for details."); base.ConvertFile(sourceItem, targetItem); } else { using (StringWriter w = new StringWriter()) { BooPrinterVisitorWithComments printer = new BooPrinterVisitorWithComments(specials, w); printer.OnModule(module); printer.Finish(); targetItem.Include = Path.ChangeExtension(targetItem.Include, ".boo"); File.WriteAllText(targetItem.FileName, w.ToString()); } } } else { base.ConvertFile(sourceItem, targetItem); } }
public override void FixtureSetUp() { base.FixtureSetUp(); // Set up the project. MSBuildBasedProject project = WebReferenceTestHelper.CreateTestProject("C#"); project.FileName = FileName.Create("c:\\projects\\test\\foo.csproj"); // Web references item. WebReferencesProjectItem webReferencesItem = new WebReferencesProjectItem(project); webReferencesItem.Include = "Web References\\"; ProjectService.AddProjectItem(project, webReferencesItem); // Web reference url. WebReferenceUrl webReferenceUrl = new WebReferenceUrl(project); webReferenceUrl.Include = "http://localhost/test.asmx"; webReferenceUrl.UpdateFromURL = "http://localhost/test.asmx"; webReferenceUrl.RelPath = "Web References\\localhost"; ProjectService.AddProjectItem(project, webReferenceUrl); FileProjectItem discoFileItem = new FileProjectItem(project, ItemType.None); discoFileItem.Include = "Web References\\localhost\\test.disco"; ProjectService.AddProjectItem(project, discoFileItem); FileProjectItem wsdlFileItem = new FileProjectItem(project, ItemType.None); wsdlFileItem.Include = "Web References\\localhost\\test.wsdl"; ProjectService.AddProjectItem(project, wsdlFileItem); // Proxy FileProjectItem proxyItem = new FileProjectItem(project, ItemType.Compile); proxyItem.Include = "Web References\\localhost\\Reference.cs"; proxyItem.DependentUpon = "Reference.map"; ProjectService.AddProjectItem(project, proxyItem); // Reference map. FileProjectItem mapItem = new FileProjectItem(project, ItemType.None); mapItem.Include = "Web References\\localhost\\Reference.map"; ProjectService.AddProjectItem(project, mapItem); // System.Web.Services reference. ReferenceProjectItem webServicesReferenceItem = new ReferenceProjectItem(project, "System.Web.Services"); ProjectService.AddProjectItem(project, webServicesReferenceItem); // Set up the web reference. DiscoveryClientProtocol protocol = new DiscoveryClientProtocol(); DiscoveryDocumentReference discoveryRef = new DiscoveryDocumentReference(); discoveryRef.Url = "http://localhost/new.asmx"; protocol.References.Add(discoveryRef); ContractReference contractRef = new ContractReference(); contractRef.Url = "http://localhost/new.asmx?wsdl"; contractRef.ClientProtocol = new DiscoveryClientProtocol(); ServiceDescription desc = new ServiceDescription(); contractRef.ClientProtocol.Documents.Add(contractRef.Url, desc); protocol.References.Add(contractRef); WebReferenceTestHelper.InitializeProjectBindings(); var webReference = new Gui.WebReference(project, "http://localhost/new.asmx", "localhost", "ProxyNamespace", protocol); changes = webReference.GetChanges(project); }
public void GenerateCode(FileProjectItem item, CustomToolContext context) { context.RunAsync( ()=> { string fileName = item.FileName; var projectNode = item.Project; SpecFlowProject specFlowProject = CreateSpecFlowProjectFrom(projectNode); var specFlowGenerator = new SpecFlowGenerator(specFlowProject); string outputFile = context.GetOutputFileName(item, ".feature"); var specFlowFeatureFile = specFlowProject.GetOrCreateFeatureFile(fileName); var fileContents = File.ReadAllText(fileName); string outputFileContents; using(var reader = new StringReader(fileContents)) { using (var writer = new StringWriter(new StringBuilder())) { specFlowGenerator.GenerateTestFile(specFlowFeatureFile, projectNode.LanguageProperties.CodeDomProvider, reader, writer); outputFileContents = writer.ToString(); } } File.WriteAllText(outputFile, outputFileContents); WorkbenchSingleton.SafeThreadCall( () => context.EnsureOutputFileIsInProject(item, outputFile)); }); }
public void SetUpFixture() { project = WebReferenceTestHelper.CreateTestProject("C#"); project.FileName = FileName.Create("C:\\projects\\test\\foo.csproj"); protocol = new DiscoveryClientProtocol(); DiscoveryDocumentReference discoveryRef = new DiscoveryDocumentReference(); discoveryRef.Url = updateFromUrl; protocol.References.Add(discoveryRef); ContractReference contractRef = new ContractReference(); contractRef.Url = "http://localhost/test.asmx?wsdl"; contractRef.ClientProtocol = new DiscoveryClientProtocol(); ServiceDescription desc = new ServiceDescription(); contractRef.ClientProtocol.Documents.Add(contractRef.Url, desc); protocol.References.Add(contractRef); WebReferenceTestHelper.InitializeProjectBindings(); webReference = new SD.WebReference(project, updateFromUrl, name, proxyNamespace, protocol); webReferenceUrl = webReference.WebReferenceUrl; discoFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost\\test.disco", ItemType.None); referenceMapFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost\\Reference.map", ItemType.None); wsdlFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost\\test.wsdl", ItemType.None); proxyFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost\\Reference.cs", ItemType.Compile); webReferencesProjectItem = (WebReferencesProjectItem)WebReferenceTestHelper.GetProjectItem(webReference.Items, "Web References\\", ItemType.WebReferences); webServicesReferenceProjectItem = (ReferenceProjectItem)WebReferenceTestHelper.GetProjectItem(webReference.Items, ItemType.Reference); }
public void GenerateCode(FileProjectItem item, CustomToolContext context) { LanguageOption languageToGenerateCode = LanguageOption.GenerateCSharpCode; if (item.Project.Language != "C#") languageToGenerateCode = LanguageOption.GenerateVBCode; XDocument edmxDocument = XDocument.Load(item.FileName); XElement conceptualModelsElement = EDMXIO.ReadSection(edmxDocument, EDMXIO.EDMXSection.CSDL); if (conceptualModelsElement == null) throw new ArgumentException("Input file is not a valid EDMX file."); XDocument csdlDocument = new XDocument(new XDeclaration("1.0", "utf-8", null), conceptualModelsElement.Element(XName.Get("Schema", csdlNamespace.NamespaceName))); string tempFileName = IO.GetTempFilenameWithExtension("csdl"); csdlDocument.Save(tempFileName); string outputFileName = context.GetOutputFileName(item, "Designer"); EntityCodeGenerator entityCodeGenerator = new EntityCodeGenerator(languageToGenerateCode); IList<EdmSchemaError> edmSchemaErrors = entityCodeGenerator.GenerateCode(tempFileName, outputFileName); File.Delete(tempFileName); context.EnsureOutputFileIsInProject(item, outputFileName); }
public ProjectItem(Project project, FileProjectItem projectItem) { this.projectItem = projectItem; this.ContainingProject = project; this.ProjectItems = new DirectoryProjectItems(this); CreateProperties(); }
public void SetUpFixture() { WixProject p = WixBindingTestsHelper.CreateEmptyWixProject(); FileProjectItem item = new FileProjectItem(p, ItemType.None); item.Include = "readme.txt"; ProjectService.AddProjectItem(p, item); ReferenceProjectItem referenceItem = new ReferenceProjectItem(p); referenceItem.Include = "System.Windows.Forms"; ProjectService.AddProjectItem(p, referenceItem); item = new FileProjectItem(p, ItemType.Compile); item.Include = "setup.wxs"; ProjectService.AddProjectItem(p, item); item = new FileProjectItem(p, ItemType.Compile); item.Include = "test.wxi"; ProjectService.AddProjectItem(p, item); item = new FileProjectItem(p, ItemType.Compile); item.Include = "dialogs.wxs"; ProjectService.AddProjectItem(p, item); wixFileProjectItemCount = 0; foreach (FileProjectItem fileItem in p.WixSourceFiles) { wixFileProjectItemCount++; } wixSetupFile = p.WixSourceFiles[0]; wixDialogsFile = p.WixSourceFiles[1]; }
bool IsInProjectRootFolder(FileProjectItem item) { if (item.IsLink) { return !HasDirectoryInPath(item.VirtualName); } return !HasDirectoryInPath(item.Include); }
public FileProjectItem AddFileToProject(string fileName) { var projectItem = new FileProjectItem(this, ItemType.Compile); projectItem.FileName = fileName; ProjectService.AddProjectItem(this, projectItem); return projectItem; }
public TextTemplatingFilePreprocessor( ITextTemplatingHost host, FileProjectItem templateFile, ITextTemplatingCustomToolContext context) : base(host, templateFile, context) { }
global::EnvDTE.ProjectItems CreateProjectItems(FileProjectItem projectItem) { if (projectItem.ItemType == ItemType.Folder) { return new DirectoryProjectItems(this); } return new FileProjectItems(this); }
public static void AreEqual(FileProjectItem expectedFileItem, FileProjectItem actualFileItem) { string[] expectedFileItemStrings = GetFileProjectItemAsString(expectedFileItem); string[] actualFileItemStrings = GetFileProjectItemAsString(actualFileItem); Assert.AreEqual(expectedFileItemStrings, actualFileItemStrings); }
public void SetUpFixture() { BitmapFileNamesRequested.Clear(); CreatedComponents.Clear(); WixProject p = WixBindingTestsHelper.CreateEmptyWixProject(); projectDirectory = p.Directory; p.Name = "MySetup"; FileProjectItem item = new FileProjectItem(p, ItemType.Compile); item.Include = "Setup.wxs"; string docFileName = item.FileName; ProjectService.AddProjectItem(p, item); item = new FileProjectItem(p, ItemType.Compile); item.Include = "Fragment.wxs"; ProjectService.AddProjectItem(p, item); WixDocument doc = new WixDocument(p, this); doc.FileName = docFileName; doc.LoadXml(GetMainWixXml()); WixDialog wixDialog = doc.GetDialog("WelcomeDialog", this); using (Form dialog = wixDialog.CreateDialog(this)) { PictureBox pictureBox = (PictureBox)dialog.Controls[0]; hasImage = (pictureBox.Image != null); } }
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 static MvcProjectFile CreateMvcProjectMasterPageFile(FileProjectItem fileProjectItem) { if (IsMasterPageFile(fileProjectItem)) { return new MvcProjectFile(fileProjectItem); } return null; }
void AddServiceReferenceFileToProject(ServiceReferenceFileName fileName) { var projectItem = new FileProjectItem(project, ItemType.Compile); projectItem.FileName = fileName.Path; projectItem.DependentUpon = "Reference.svcmap"; AddProjectItemToProject(projectItem); }
public static MvcProjectFile CreateMvcProjectRazorFile(FileProjectItem fileProjectItem) { if (IsRazorFile(fileProjectItem)) { return new MvcProjectFile(fileProjectItem); } return null; }
public static bool IsMasterPageFile(FileProjectItem fileProjectItem) { if (fileProjectItem != null) { return IsMasterPageFileName(fileProjectItem.FileName); } return false; }
MvcProjectFile CreateProjectFile(string fullPath) { var projectItem = new FileProjectItem(project, ItemType.Compile); projectItem.FileName = FileName.Create(fullPath); file = new MvcProjectFile(projectItem); return file; }
protected virtual ITextTemplatingFilePreprocessor CreateTextTemplatingFilePreprocessor( FileProjectItem templateFile, CustomToolContext context) { var host = CreateTextTemplatingHost(context.Project); var textTemplatingCustomToolContext = new TextTemplatingCustomToolContext(context); return new TextTemplatingFilePreprocessor(host, templateFile, textTemplatingCustomToolContext); }
public ProjectItem(Project project, FileProjectItem projectItem) { this.projectItem = projectItem; this.containingProject = project; this.ProjectItems = CreateProjectItems(projectItem); CreateProperties(); Kind = GetKindFromFileProjectItemType(); }
void CreateProjectItemProperties() { project = new TestableDTEProject(); msbuildProject = project.TestableProject; msbuildFileProjectItem = new SD.FileProjectItem(msbuildProject, SD.ItemType.Compile); projectItem = new ProjectItem(project, msbuildFileProjectItem); properties = projectItem.Properties; }
ProjectItem ConvertDirectoryToProjectItem(FileProjectItem fileItem) { string subDirectoryName = GetFirstSubDirectoryName(fileItem.Include); if (IsDirectoryInsideProject(subDirectoryName)) { return CreateDirectoryProjectItemIfDirectoryNotAlreadyIncluded(subDirectoryName); } return null; }
void CreateProjectItemProperties() { project = new TestableDTEProject(); msbuildProject = project.TestableProject; msbuildFileProjectItem = new SD.FileProjectItem(msbuildProject, SD.ItemType.Compile); projectItem = new ProjectItem(project, msbuildFileProjectItem); properties = (Properties)projectItem.Properties; }
ProjectItem CreateDirectoryProjectItemIfDirectoryNotAlreadyIncluded(FileProjectItem fileItem) { string directory = fileItem.Include; if (!IsDirectoryIncludedAlready(directory)) { AddIncludedDirectory(directory); return new ProjectItem(project, fileItem); } return null; }
XElement GetModelSchema(FileProjectItem item) { XDocument edmxDocument = XDocument.Load(item.FileName); XElement conceptualModelsElement = EDMXIO.ReadSection(edmxDocument, EDMXIO.EDMXSection.CSDL); if (conceptualModelsElement == null) throw new ArgumentException("Input file is not a valid EDMX file."); return conceptualModelsElement.Element(XName.Get("Schema", csdlNamespace.NamespaceName)); }
public TextTemplatingFileProcessor( ITextTemplatingHost host, FileProjectItem templateFile, ITextTemplatingCustomToolContext context) { this.host = host; this.templateFile = templateFile; this.context = context; }
protected override ITextTemplatingFileGenerator CreateTextTemplatingFileGenerator( FileProjectItem projectFile, CustomToolContext context) { ProjectFilePassedToCreateTextTemplatingFileGenerator = projectFile; ContextPassedToCreateTextTemplatingFileGenerator = context; return FakeTextTemplatingFileGenerator; }
internal ProjectItem FindProjectItem(string fileName) { SD.FileProjectItem item = MSBuildProject.FindFile(fileName); if (item != null) { return(new ProjectItem(this, item)); } return(null); }
internal static ProjectItem FindByFileName(IProject project, string fileName) { SD.FileProjectItem item = project.FindFile(new FileName(fileName)); if (item != null) { return(new ProjectItem(new Project(project as MSBuildBasedProject), item)); } return(null); }
public FileCodeModel2( Project project, FileProjectItem projectItem, IDocumentNamespaceCreator namespaceCreator) { this.project = project; this.projectItem = projectItem; this.namespaceCreator = namespaceCreator; }
public FileProjectItem EnsureOutputFileIsInProject(FileProjectItem baseItem, string outputFileName) { BaseItemPassedToEnsureOutputFileIsInProject = baseItem; OutputFileNamePassedToEnsureOutputFileIsInProject = outputFileName; IsOutputFileNamePassedToEnsureOutputFileIsInProject = true; return EnsureOutputFileIsInProjectReturnValue; }
void CreateProjectItemProperties() { project = new TestableDTEProject(); msbuildProject = project.TestableProject; msbuildFileProjectItem = new SD.FileProjectItem(msbuildProject, SD.ItemType.Compile); projectItem = new ProjectItem(project, msbuildFileProjectItem); properties = (ICSharpCode.PackageManagement.EnvDTE.Properties)projectItem.Properties; IWorkbench workbench = MockRepository.GenerateStub <IWorkbench>(); ICSharpCode.SharpDevelop.SD.Services.AddService(typeof(IWorkbench), workbench); }
static string GetFullVirtualName(FileProjectItem item) { if (Path.IsPathRooted(item.VirtualName)) { return(item.VirtualName); } else if (item.Project != null) { return(Path.Combine(item.Project.Directory, item.VirtualName)); } return(item.VirtualName); }
public static IEnumerable <string> GetCompatibleCustomToolNames(FileProjectItem item) { string fileName = item.FileName; foreach (CustomToolDescriptor desc in customToolList) { if (desc.CanRunOnFile(fileName)) { yield return(desc.Name); } } }
public override void Run() { FileNode node = Owner as FileNode; if (node != null) { FileProjectItem item = node.ProjectItem as FileProjectItem; if (item != null) { CustomToolsService.RunCustomTool(item, true); } } }
protected override Control CreateDropDownControl(ITypeDescriptorContext context, IWindowsFormsEditorService editorService) { FileProjectItem item = context.Instance as FileProjectItem; if (item != null && item.Project != null) { return(new DropDownEditorListBox(editorService, GetNames(item.Project.AvailableFileItemTypes))); } else { return(new DropDownEditorListBox(editorService, GetNames(ItemType.DefaultFileItems))); } }
protected override Control CreateDropDownControl(ITypeDescriptorContext context, IWindowsFormsEditorService editorService) { FileProjectItem item = context.Instance as FileProjectItem; if (item != null) { return(new DropDownEditorListBox(editorService, CustomToolsService.GetCompatibleCustomToolNames(item))); } else { return(new DropDownEditorListBox(editorService, CustomToolsService.GetCustomToolNames())); } }
FileProjectItem AddFileToProject(string fileName) { var projectItem = new FileProjectItem(project, ICSharpCode.SharpDevelop.Project.ItemType.Compile); project .Stub(p => p.FindFile(new FileName(fileName))) .Return(projectItem); project .Stub(p => p.SyncRoot) .Return(new object()); return(projectItem); }
public override void SetValue(object component, object value) { ProjectItem p = (ProjectItem)component; p.SetEvaluatedMetadata(Name, (string)value); p.InformSetValue(this, component, value); if (runCustomTool) { FileProjectItem fpi = p as FileProjectItem; if (fpi != null) { CustomToolsService.RunCustomTool(fpi, false); } } }
public void ProjectItem_ProjectContentHasProject_ReturnsProjectItemThatUsesProjectFileItem() { CreateProjectContent(); TestableProject project = AddProjectToProjectContent(); string fileName = @"d:\projects\MyProject\test.cs"; SDProject.FileProjectItem fileProjectItem = AddFileToProjectAndProjectContent(project, fileName); CreateClass("Class1"); CreateCodeType(); global::EnvDTE.ProjectItem item = codeType.ProjectItem; Assert.AreEqual("test.cs", item.Name); }
public override DragDropEffects GetDragDropEffect(IDataObject dataObject, DragDropEffects proposedEffect) { if (dataObject.GetDataPresent(typeof(FileNode))) { FileNode fileNode = (FileNode)dataObject.GetData(typeof(FileNode)); if (!FileUtility.IsEqualFileName(Directory, fileNode.FileName) && !FileUtility.IsEqualFileName(Directory, Path.GetDirectoryName(fileNode.FileName))) { if (Project != fileNode.Project) { return(DragDropEffects.Copy); } return(proposedEffect); } else { // Dragging a dependent file onto its parent directory // removes the dependency. FileProjectItem fpi = fileNode.ProjectItem as FileProjectItem; if (fpi != null && !String.IsNullOrEmpty(fpi.DependentUpon)) { return(DragDropEffects.Move); } } } if (dataObject.GetDataPresent(typeof(DirectoryNode))) { DirectoryNode directoryNode = (DirectoryNode)dataObject.GetData(typeof(DirectoryNode)); if (FileUtility.IsBaseDirectory(directoryNode.Directory, Directory)) { return(DragDropEffects.None); } if (!FileUtility.IsEqualFileName(Directory, directoryNode.Directory) && !FileUtility.IsEqualFileName(Directory, Path.GetDirectoryName(directoryNode.Directory))) { if (Project != directoryNode.Project) { return(DragDropEffects.Copy); } return(proposedEffect); } } if (dataObject.GetDataPresent(DataFormats.FileDrop)) { return(DragDropEffects.Copy); } return(DragDropEffects.None); }
public FileProjectItem EnsureOutputFileIsInProject(FileProjectItem baseItem, string outputFileName) { WorkbenchSingleton.AssertMainThread(); FileProjectItem outputItem = project.FindFile(outputFileName); if (outputItem == null) { outputItem = new FileProjectItem(project, ItemType.Compile); outputItem.FileName = outputFileName; outputItem.DependentUpon = Path.GetFileName(baseItem.FileName); ProjectService.AddProjectItem(project, outputItem); project.Save(); ProjectBrowserPad.Instance.ProjectBrowserControl.RefreshView(); } return(outputItem); }
public void GetProjectItems_BuildSingleProjectWithOneFileMatchingCustomToolRunConfiguration_ProjectItemReturnedWhenFileNameCaseIsDifferent() { CreateProject(@"d:\MyProject\MyProject.csproj"); FileProjectItem projectItem = AddFileToProject("template.tt"); EnableCustomToolRunForProject(); ConfigureCustomToolFileNamesForProject("TEMPLATE.TT"); CreateBeforeBuildCustomToolProjectItems(); List <FileProjectItem> projectItems = GetProjectItems(); FileProjectItem[] expectedProjectItems = new FileProjectItem[] { projectItem }; CollectionAssert.AreEqual(expectedProjectItems, projectItems); }
// protected override void Initialize() // { // base.Initialize(); // } public override void AfterLabelEdit(string newName) { if (newName == null) { return; } if (!FileService.CheckDirectoryEntryName(newName)) { return; } string oldFileName = FileName; if (oldFileName != null) { string newFileName = Path.Combine(Path.GetDirectoryName(oldFileName), newName); if (FileService.RenameFile(oldFileName, newFileName, false)) { Text = newName; this.fileName = newFileName; string oldPrefix = Path.GetFileNameWithoutExtension(oldFileName) + "."; string newPrefix = Path.GetFileNameWithoutExtension(newFileName) + "."; foreach (TreeNode node in Nodes) { FileNode fileNode = node as FileNode; if (fileNode != null) { FileProjectItem fileItem = fileNode.ProjectItem as FileProjectItem; if (fileItem != null && string.Equals(fileItem.DependentUpon, Path.GetFileName(oldFileName), StringComparison.OrdinalIgnoreCase)) { fileItem.DependentUpon = newName; } if (fileNode.Text.StartsWith(oldPrefix)) { fileNode.AfterLabelEdit(newPrefix + fileNode.Text.Substring(oldPrefix.Length)); } } else { LoggingService.Warn("FileNode.AfterLabelEdit. Child is not a FileNode."); } } Project.Save(); } } }
public void GetProjectItems_SolutionContainingOneProjectWithMatchingCustomToolFileName_ReturnsOneProjectItem() { IProject project = CreateProject(@"d:\MyProject\MyProject.csproj"); FileProjectItem projectItem = AddFileToProject("template.tt"); EnableCustomToolRunForProject(); ConfigureCustomToolFileNamesForProject("TEMPLATE.TT"); CreateSolution(project); CreateBeforeBuildCustomToolProjectItemsUsingSolution(); List <FileProjectItem> projectItems = GetProjectItems(); FileProjectItem[] expectedProjectItems = new FileProjectItem[] { projectItem }; CollectionAssert.AreEqual(expectedProjectItems, projectItems); }
public void GetProjectItems_BuildSingleProjectWithOneFileMatchingCustomToolRunConfiguration_OtherNonMatchingProjectItemsNotReturned() { CreateProject(@"d:\MyProject\MyProject.csproj"); FileProjectItem projectItem = AddFileToProject("template.t4"); AddFileToProject("test.cs"); EnableCustomToolRunForProject(); ConfigureCustomToolFileNamesForProject("template.t4"); CreateBeforeBuildCustomToolProjectItems(); List <FileProjectItem> projectItems = GetProjectItems(); FileProjectItem[] expectedProjectItems = new FileProjectItem[] { projectItem }; CollectionAssert.AreEqual(expectedProjectItems, projectItems); }
public void WriteCodeDomToFile(FileProjectItem baseItem, string outputFileName, CodeCompileUnit ccu) { SD.MainThread.VerifyAccess(); string codeOutput; using (StringWriter writer = new StringWriter()) { project.GenerateCodeFromCodeDom(ccu, writer); codeOutput = writer.ToString(); } FileUtility.ObservedSave(delegate(FileName fileName) { File.WriteAllText(fileName, codeOutput, Encoding.UTF8); }, FileName.Create(outputFileName), FileErrorPolicy.Inform); EnsureOutputFileIsInProject(baseItem, outputFileName); SD.ParserService.ParseAsync(FileName.Create(outputFileName), new StringTextSource(codeOutput)).FireAndForget(); }
public void WriteCodeDomToFile(FileProjectItem baseItem, string outputFileName, CodeCompileUnit ccu) { WorkbenchSingleton.AssertMainThread(); CodeDomProvider provider = project.LanguageProperties.CodeDomProvider; CodeGeneratorOptions options = new CodeDOMGeneratorUtility().CreateCodeGeneratorOptions; if (project.LanguageProperties == LanguageProperties.VBNet) { // the root namespace is implicit in VB foreach (CodeNamespace ns in ccu.Namespaces) { if (string.Equals(ns.Name, project.RootNamespace, StringComparison.OrdinalIgnoreCase)) { ns.Name = string.Empty; } else if (ns.Name.StartsWith(project.RootNamespace + ".", StringComparison.OrdinalIgnoreCase)) { ns.Name = ns.Name.Substring(project.RootNamespace.Length + 1); } } } string codeOutput; using (StringWriter writer = new StringWriter()) { if (provider == null) { writer.WriteLine("No CodeDom provider was found for this language."); } else { provider.GenerateCodeFromCompileUnit(ccu, writer, options); } codeOutput = writer.ToString(); } FileUtility.ObservedSave(delegate(string fileName) { File.WriteAllText(fileName, codeOutput, Encoding.UTF8); }, outputFileName, FileErrorPolicy.Inform); EnsureOutputFileIsInProject(baseItem, outputFileName); ParserService.BeginParse(outputFileName, new StringTextBuffer(codeOutput)); }
static void OnFileSaved(object sender, FileNameEventArgs e) { IProject project = SD.ProjectService.FindProjectContainingFile(e.FileName); if (project == null) { return; } FileProjectItem item = project.FindFile(e.FileName); if (item == null) { return; } if (!string.IsNullOrEmpty(item.CustomTool)) { RunCustomTool(item, false); } }
public void GetProjectItems_SolutionContainingTwoProjectsBothWithFilesAndMatchingCustomToolFileNameInFirstProject_ReturnsOneProjectItem() { IProject project1 = CreateProject(@"d:\MyProject\FirstProject.csproj"); FileProjectItem projectItem = AddFileToProject("template.tt"); EnableCustomToolRunForProject(); ConfigureCustomToolFileNamesForProject("TEMPLATE.TT"); IProject project2 = CreateProject(@"d:\MyProject\SecondProject.csproj"); AddFileToProject("test.cs"); CreateSolution(project1, project2); CreateBeforeBuildCustomToolProjectItemsUsingSolution(); List <FileProjectItem> projectItems = GetProjectItems(); FileProjectItem[] expectedProjectItems = new FileProjectItem[] { projectItem }; CollectionAssert.AreEqual(expectedProjectItems, projectItems); }
/// <summary> /// Returns the project item for a specific file; or null if the file is not found in the project. /// This member is thread-safe. /// </summary> /// <param name="fileName">The <b>fully qualified</b> file name of the file</param> public FileProjectItem FindFile(FileName fileName) { lock (SyncRoot) { if (findFileCache == null) { findFileCache = new Dictionary <string, FileProjectItem>(StringComparer.OrdinalIgnoreCase); foreach (ProjectItem item in this.Items) { FileProjectItem fileItem = item as FileProjectItem; if (fileItem != null) { findFileCache[item.FileName] = fileItem; } } } FileProjectItem outputItem; findFileCache.TryGetValue(fileName, out outputItem); return(outputItem); } }
public FileProjectItem EnsureOutputFileIsInProject(FileProjectItem baseItem, string outputFileName, bool isPrimaryOutput) { if (baseItem == null) { throw new ArgumentNullException("baseItem"); } if (baseItem.Project != project) { throw new ArgumentException("baseItem is not from project this CustomToolContext belongs to"); } SD.MainThread.VerifyAccess(); bool saveProject = false; if (isPrimaryOutput) { if (baseItem.GetEvaluatedMetadata("LastGenOutput") != Path.GetFileName(outputFileName)) { saveProject = true; baseItem.SetEvaluatedMetadata("LastGenOutput", Path.GetFileName(outputFileName)); } } FileProjectItem outputItem = project.FindFile(FileName.Create(outputFileName)); if (outputItem == null) { outputItem = new FileProjectItem(project, ItemType.Compile); outputItem.FileName = FileName.Create(outputFileName); outputItem.DependentUpon = Path.GetFileName(baseItem.FileName); outputItem.SetEvaluatedMetadata("AutoGen", "True"); ProjectService.AddProjectItem(project, outputItem); FileService.FireFileCreated(outputFileName, false); saveProject = true; ProjectBrowserPad.RefreshViewAsync(); } if (saveProject) { project.Save(); } return(outputItem); }
public IProject FindProjectContainingFile(FileName fileName) { if (fileName == null) { throw new ArgumentNullException("fileName"); } IProject currentProject = this.CurrentProject; if (currentProject != null && currentProject.IsFileInProject(fileName)) { return(currentProject); } ISolution solution = this.CurrentSolution; if (solution == null) { return(null); } // Try all project's in the solution. IProject linkedProject = null; foreach (IProject project in solution.Projects) { FileProjectItem file = project.FindFile(fileName); if (file != null) { if (file.IsLink) { linkedProject = project; } else { return(project); // prefer projects with non-links over projects with links } } } return(linkedProject); }
/// <summary> /// Returns the project item for a specific file; or null if the file is not found in the project. /// This member is thread-safe. /// </summary> /// <param name="fileName">The <b>fully qualified</b> file name of the file</param> public FileProjectItem FindFile(string fileName) { lock (SyncRoot) { if (findFileCache == null) { findFileCache = new Dictionary <string, FileProjectItem>(StringComparer.InvariantCultureIgnoreCase); foreach (ProjectItem item in this.Items) { FileProjectItem fileItem = item as FileProjectItem; if (fileItem != null) { findFileCache[item.FileName] = fileItem; } } } try { fileName = Path.GetFullPath(fileName); } catch {} FileProjectItem outputItem; findFileCache.TryGetValue(fileName, out outputItem); return(outputItem); } }
public string GetOutputFileName(FileProjectItem baseItem, string additionalExtension) { if (baseItem == null) { throw new ArgumentNullException("baseItem"); } if (baseItem.Project != project) { throw new ArgumentException("baseItem is not from project this CustomToolContext belongs to"); } string newExtension = null; if (project.LanguageProperties.CodeDomProvider != null) { newExtension = project.LanguageProperties.CodeDomProvider.FileExtension; } if (string.IsNullOrEmpty(newExtension)) { if (string.IsNullOrEmpty(additionalExtension)) { newExtension = ".unknown"; } else { newExtension = additionalExtension; additionalExtension = ""; } } if (!newExtension.StartsWith(".")) { newExtension = "." + newExtension; } return(Path.ChangeExtension(baseItem.FileName, additionalExtension + newExtension)); }
/// <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); } }