public void AddReference(object sender, Gtk.ToggledArgs e) { Gtk.TreeIter iter; store.GetIterFromString(out iter, e.Path); ReferenceType rt = (ReferenceType)store.GetValue(iter, ColType); string fullName = (string)store.GetValue(iter, ColFullName); if ((bool)store.GetValue(iter, ColSelected) == false) { store.SetValue(iter, ColSelected, true); switch (rt) { case ReferenceType.Package: selectDialog.AddReference(ProjectReference.CreateAssemblyReference((SystemAssembly)store.GetValue(iter, ColAssembly))); break; case ReferenceType.Assembly: selectDialog.AddReference(ProjectReference.CreateAssemblyFileReference(fullName)); break; case ReferenceType.Project: selectDialog.AddReference(ProjectReference.CreateProjectReference(fullName)); break; } } else { store.SetValue(iter, ColSelected, false); selectDialog.RemoveReference(rt, fullName); } }
protected async Task <TextEditorExtensionTestCase> SetupTestCase(string input, int cursorPosition = -1, bool wrap = false) { await Composition.CompositionManager.InitializeAsync(); var data = GetContentData(); var content = new TestViewContent { ContentName = data.FileName, Text = input, }; content.Data.MimeType = data.MimeType; if (cursorPosition != -1) { content.CursorPosition = cursorPosition; } var tww = new TestWorkbenchWindow { ViewContent = content, }; var project = Services.ProjectService.CreateDotNetProject(data.Language); project.Name = Path.GetFileNameWithoutExtension(data.ProjectFileName); project.FileName = data.ProjectFileName; project.Files.Add(new ProjectFile(content.ContentName, BuildAction.Compile)); foreach (var reference in data.References) { project.References.Add(ProjectReference.CreateAssemblyReference(reference)); } var solution = new Solution(); solution.AddConfiguration("", true); solution.DefaultSolutionFolder.AddItem(project); content.Project = project; if (wrap && !IdeApp.IsInitialized) { IdeApp.Initialize(new ProgressMonitor()); } Document doc = wrap ? IdeApp.Workbench.WrapDocument(tww) : new Document(tww); doc.SetProject(project); using (var monitor = new ProgressMonitor()) await TypeSystemService.Load(solution, monitor); foreach (var ext in GetEditorExtensions()) { ext.Initialize(doc.Editor, doc); content.Contents.Add(ext); } await doc.UpdateParseDocument(); return(new TextEditorExtensionTestCase(doc, content, tww, data, wrap)); }
static async Task <CreateEditorResult> CreateEditor(string text, string extension) { string editorText; TestViewContent sev; string parsedText; int cursorPosition = text.IndexOf('$'); int endPos = text.IndexOf('$', cursorPosition + 1); if (endPos == -1) { parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1); } else { parsedText = text.Substring(0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring(endPos + 1); editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1); cursorPosition = endPos - 1; } var project = Services.ProjectService.CreateDotNetProject("C#"); project.References.Add(ProjectReference.CreateAssemblyReference("System")); project.References.Add(ProjectReference.CreateAssemblyReference("System.Web")); project.FileName = UnitTests.TestBase.GetTempFile(".csproj"); string file = UnitTests.TestBase.GetTempFile(extension); project.AddFile(file); sev = new TestViewContent(); sev.Project = project; sev.ContentName = file; sev.Text = editorText; sev.CursorPosition = cursorPosition; var tww = new TestWorkbenchWindow(); tww.ViewContent = sev; var doc = new TestDocument(tww); doc.Editor.FileName = sev.ContentName; var parser = new WebFormsParser(); var options = new ParseOptions { Project = project, FileName = sev.ContentName, Content = new StringTextSource(parsedText) }; var parsedDoc = await parser.Parse(options, default(CancellationToken)) as WebFormsParsedDocument; doc.HiddenParsedDocument = parsedDoc; return(new CreateEditorResult { Extension = new WebFormsTestingEditorExtension(doc), EditorText = editorText, ViewContent = sev }); }
public async Task <ProjectFile> AddFileToProject(SolutionFolderItem policyParent, Project project, string language, string directory, string name) { generatedFile = await SaveFile(policyParent, project, language, directory, name); if (generatedFile != null) { string buildAction = this.buildAction ?? project.GetDefaultBuildAction(generatedFile); ProjectFile projectFile = project.AddFile(generatedFile, buildAction); if (!string.IsNullOrEmpty(dependsOn)) { var model = CombinedTagModel.GetTagModel(ProjectTagModel, policyParent, project, language, name, generatedFile); string parsedDepName = StringParserService.Parse(dependsOn, model); if (projectFile.DependsOn != parsedDepName) { projectFile.DependsOn = parsedDepName; } } if (!string.IsNullOrEmpty(customTool)) { projectFile.Generator = customTool; } if (!string.IsNullOrEmpty(customToolNamespace)) { var model = CombinedTagModel.GetTagModel(ProjectTagModel, policyParent, project, language, name, generatedFile); projectFile.CustomToolNamespace = StringParserService.Parse(customToolNamespace, model); } if (!string.IsNullOrEmpty(subType)) { projectFile.ContentType = subType; } DotNetProject netProject = project as DotNetProject; if (netProject != null) { // Add required references foreach (string aref in references) { string res = netProject.AssemblyContext.GetAssemblyFullName(aref, netProject.TargetFramework); res = netProject.AssemblyContext.GetAssemblyNameForVersion(res, netProject.TargetFramework); if (!ContainsReference(netProject, res)) { netProject.References.Add(ProjectReference.CreateAssemblyReference(aref)); } } } return(projectFile); } else { return(null); } }
static async Task <CreateEditorResult> CreateEditor(string text, string extension) { string editorText; TestViewContent sev; string parsedText; int cursorPosition = text.IndexOf('$'); int endPos = text.IndexOf('$', cursorPosition + 1); if (endPos == -1) { parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1); } else { parsedText = text.Substring(0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring(endPos + 1); editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1); cursorPosition = endPos - 1; } var project = Services.ProjectService.CreateDotNetProject("C#"); project.References.Add(ProjectReference.CreateAssemblyReference("System")); project.References.Add(ProjectReference.CreateAssemblyReference("System.Web")); project.FileName = UnitTests.TestBase.GetTempFile(".csproj"); string file = UnitTests.TestBase.GetTempFile(extension); project.AddFile(file); sev = new TestViewContent(); await sev.Initialize(new FileDescriptor (file, null, project), null); sev.Text = editorText; sev.CursorPosition = cursorPosition; var parser = new WebFormsParser(); var options = new ParseOptions { Project = project, FileName = file, Content = new StringTextSource(parsedText) }; sev.Editor.FileName = sev.FilePath; var parsedDoc = await parser.Parse(options, default(CancellationToken)) as WebFormsParsedDocument; var documentContext = sev.GetContent <RoslynDocumentContext> (); documentContext.SetParsedDocument(parsedDoc); return(new CreateEditorResult { Extension = new WebFormsTestingEditorExtension(sev.Editor, documentContext), EditorText = editorText, ViewContent = sev }); }
protected async Task <TextEditorExtensionTestCase> SetupTestCase(string input, int cursorPosition = -1, bool wrap = false) { await Runtime.GetService <CompositionManager> (); var data = GetContentData(); var content = new TestViewContent(); await content.Initialize(new FileDescriptor (data.FileName, null, null)); content.Text = input; content.Editor.MimeType = data.MimeType; if (cursorPosition != -1) { content.CursorPosition = cursorPosition; } var project = Services.ProjectService.CreateDotNetProject(data.Language); project.Name = Path.GetFileNameWithoutExtension(data.ProjectFileName); project.FileName = data.ProjectFileName; project.Files.Add(new ProjectFile(content.FilePath, BuildAction.Compile)); foreach (var reference in data.References) { project.References.Add(ProjectReference.CreateAssemblyReference(reference)); } var solution = new Solution(); solution.AddConfiguration("", true); solution.DefaultSolutionFolder.AddItem(project); content.Owner = project; using (var monitor = new ProgressMonitor()) await IdeApp.TypeSystemService.Load(solution, monitor); var testCase = await TextEditorExtensionTestCase.Create(content, data, wrap); var doc = testCase.Document; foreach (var ext in GetEditorExtensions()) { ext.Initialize(doc.Editor, doc.DocumentContext); content.AddContent(ext); } await doc.DocumentContext.UpdateParseDocument(); return(testCase); }
static void OnReferenceRemoved(object o, ProjectReferenceEventArgs args) { if (updating || !IsGtkReference(args.ProjectReference)) { return; } DotNetProject dnp = args.Project as DotNetProject; if (MessageService.Confirm(GettextCatalog.GetString("The Gtk# User Interface designer will be disabled by removing the gtk-sharp reference."), new AlertButton(GettextCatalog.GetString("Disable Designer")))) { dnp.ExtendedProperties ["GtkReferenceExists"] = false; GtkDesignInfo.DisableProject(dnp); } else { dnp.References.Add(ProjectReference.CreateAssemblyReference(args.ProjectReference.StoredReference)); } }
Task EnsureAnalysisDocumentIsOpen() { if (analysisDocument != null) { Microsoft.CodeAnalysis.Document doc; try { doc = RoslynWorkspace.CurrentSolution.GetDocument(analysisDocument); if (doc == null && RoslynWorkspace.CurrentSolution.ContainsAdditionalDocument(analysisDocument)) { return(Task.CompletedTask); } } catch (Exception) { doc = null; } if (doc != null) { return(Task.CompletedTask); } } if (Editor == null) { UnsubscribeAnalysisDocument(); return(Task.CompletedTask); } if (Project != null && !IsUnreferencedSharedProject(Project)) { lock (analysisDocumentLock) { UnsubscribeRoslynWorkspace(); RoslynWorkspace = TypeSystemService.GetWorkspace(this.Project.ParentSolution); if (RoslynWorkspace == null) // Solution not loaded yet { return(Task.CompletedTask); } SubscribeRoslynWorkspace(); analysisDocument = FileName != null?TypeSystemService.GetDocumentId(this.Project, this.FileName) : null; if (analysisDocument != null && !RoslynWorkspace.CurrentSolution.ContainsAdditionalDocument(analysisDocument) && !RoslynWorkspace.IsDocumentOpen(analysisDocument)) { TypeSystemService.InformDocumentOpen(analysisDocument, Editor, this); OnAnalysisDocumentChanged(EventArgs.Empty); } return(Task.CompletedTask); } } lock (adhocProjectLock) { var token = analysisDocumentSrc.Token; if (adhocProject != null || IsInProjectSettingLoadingProcess) { return(Task.CompletedTask); } if (Editor != null) { var node = TypeSystemService.GetTypeSystemParserNode(Editor.MimeType, BuildAction.Compile); if (Editor.MimeType == "text/x-csharp" || node?.Parser.CanGenerateAnalysisDocument(Editor.MimeType, BuildAction.Compile, new string[0]) == true) { var newProject = Services.ProjectService.CreateDotNetProject("C#"); this.adhocProject = newProject; newProject.Name = "InvisibleProject"; newProject.References.Add(ProjectReference.CreateAssemblyReference("mscorlib")); newProject.References.Add(ProjectReference.CreateAssemblyReference("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")); newProject.References.Add(ProjectReference.CreateAssemblyReference("System.Core")); // Use a different name for each project, otherwise the msbuild builder will complain about duplicate projects. newProject.FileName = "adhoc_" + (++adhocProjectCount) + ".csproj"; if (!Window.ViewContent.IsUntitled) { adHocFile = Editor.FileName; } else { adHocFile = (Platform.IsWindows ? "C:\\" : "/") + Window.ViewContent.UntitledName + ".cs"; } newProject.Files.Add(new ProjectFile(adHocFile, BuildAction.Compile)); adhocSolution = new Solution(); adhocSolution.AddConfiguration("", true); adhocSolution.DefaultSolutionFolder.AddItem(newProject); return(TypeSystemService.Load(adhocSolution, new ProgressMonitor(), token, false).ContinueWith(task => { if (token.IsCancellationRequested) { return; } UnsubscribeRoslynWorkspace(); RoslynWorkspace = task.Result.FirstOrDefault(); // 1 solution loaded ->1 workspace as result SubscribeRoslynWorkspace(); analysisDocument = RoslynWorkspace.CurrentSolution.Projects.First().DocumentIds.First(); TypeSystemService.InformDocumentOpen(RoslynWorkspace, analysisDocument, Editor, this); OnAnalysisDocumentChanged(EventArgs.Empty); })); } } } return(Task.CompletedTask); }
Task EnsureAnalysisDocumentIsOpen() { if (analysisDocument != null) { Microsoft.CodeAnalysis.Document doc; try { doc = RoslynWorkspace.CurrentSolution.GetDocument(analysisDocument); } catch (Exception) { doc = null; } if (doc != null) { return(SpecializedTasks.EmptyTask); } } if (Editor == null) { UnsubscibeAnalysisdocument(); return(SpecializedTasks.EmptyTask); } if (Project != null && Editor.MimeType == "text/x-csharp" && !IsUnreferencedSharedProject(Project)) { UnsubscribeRoslynWorkspace(); RoslynWorkspace = TypeSystemService.GetWorkspace(this.Project.ParentSolution); SubscribeRoslynWorkspace(); analysisDocument = TypeSystemService.GetDocumentId(this.Project, this.FileName); if (analysisDocument != null) { TypeSystemService.InformDocumentOpen(analysisDocument, Editor); } } else { CancelEnsureAnalysisDocumentIsOpen(); lock (adhocProjectLock) { var token = analysisDocumentSrc.Token; if (adhocProject != null) { return(SpecializedTasks.EmptyTask); } if (Editor != null && Editor.MimeType == "text/x-csharp") { var newProject = Services.ProjectService.CreateDotNetProject("C#"); this.adhocProject = newProject; newProject.Name = "InvisibleProject"; newProject.References.Add(ProjectReference.CreateAssemblyReference("mscorlib")); newProject.References.Add(ProjectReference.CreateAssemblyReference("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")); newProject.References.Add(ProjectReference.CreateAssemblyReference("System.Core")); newProject.FileName = "test.csproj"; if (!Window.ViewContent.IsUntitled) { adHocFile = Editor.FileName; } else { adHocFile = (Platform.IsWindows ? "C:\\" : "/") + Window.ViewContent.UntitledName + ".cs"; } newProject.Files.Add(new ProjectFile(adHocFile, BuildAction.Compile)); adhocSolution = new Solution(); adhocSolution.AddConfiguration("", true); adhocSolution.DefaultSolutionFolder.AddItem(newProject); return(TypeSystemService.Load(adhocSolution, new ProgressMonitor(), token).ContinueWith(task => { if (token.IsCancellationRequested) { return; } UnsubscribeRoslynWorkspace(); RoslynWorkspace = task.Result.FirstOrDefault(); // 1 solution loaded ->1 workspace as result SubscribeRoslynWorkspace(); analysisDocument = TypeSystemService.GetDocumentId(RoslynWorkspace, newProject, adHocFile); TypeSystemService.InformDocumentOpen(RoslynWorkspace, analysisDocument, Editor); })); } } } return(SpecializedTasks.EmptyTask); }
ProjectReference CreateGacReference(string name) { return(ProjectReference.CreateAssemblyReference(name)); }
bool Update(string assm_version) { if (assm_version == null) { throw new ArgumentException(assm_version); } bool changed = false; updating = true; bool gdk = false, gtk = false, posix = false; foreach (ProjectReference r in new List <ProjectReference> (project.References)) { if (r.ReferenceType != ReferenceType.Package) { continue; } string name = GetReferenceName(r); if (name == "gdk-sharp") { gdk = true; } if (name == "gtk-sharp") { gtk = true; } else if (name == "Mono.Posix") { posix = true; } // Is a gtk-sharp-2.0 assembly? if (Array.IndexOf(gnome_assemblies, name) == -1) { continue; } string sr = r.StoredReference; string version = sr.Substring(sr.IndexOf(",") + 1).Trim(); if (version != assm_version) { project.References.Remove(r); if (name == "gnome-sharp" && assm_version == "Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f") { project.References.Add(ProjectReference.CreateAssemblyReference(name + ", Version=2.24.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f")); } else { project.References.Add(ProjectReference.CreateAssemblyReference(name + ", " + assm_version)); } changed = true; } } if (!gtk) { project.References.Add(ProjectReference.CreateAssemblyReference("gtk-sharp" + ", " + assm_version)); project.ExtendedProperties ["GtkReferenceExists"] = true; changed = true; } if (!GtkDesignInfo.HasDesignedObjects(project)) { return(changed); } GtkDesignInfo info = GtkDesignInfo.FromProject(project); if (!gdk) { project.References.Add(ProjectReference.CreateAssemblyReference("gdk-sharp" + ", " + assm_version)); changed = true; } if (!posix && info.GenerateGettext && info.GettextClass == "Mono.Unix.Catalog") { // Add a reference to Mono.Posix. Use the version for the selected project's runtime version. string aname = project.AssemblyContext.FindInstalledAssembly("Mono.Posix, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756", null, project.TargetFramework); if (aname != null) { aname = project.AssemblyContext.GetAssemblyNameForVersion(aname, project.TargetFramework); if (aname != null) { project.References.Add(ProjectReference.CreateAssemblyReference(aname)); changed = true; } } } updating = false; return(changed); }
public virtual async Task GenerateFiles(DotNetProject project, string namspace, string referenceName) { //make sure we have a valid value for the namespace if (string.IsNullOrEmpty(namspace)) { namspace = project.GetDefaultNamespace(null); } // Create the base directory if it does not exists FilePath basePath = GetReferencePath(project, referenceName).CanonicalPath; if (!Directory.Exists(basePath)) { Directory.CreateDirectory(basePath); } // Remove old files from the service directory var toRemove = new List <ProjectFile>(project.Files.GetFilesInPath(basePath)); foreach (ProjectFile f in toRemove) { project.Files.Remove(f); } // Generate the wsdl, disco and map files string mapSpec = await GenerateDescriptionFiles(project, basePath); // Generate the proxy class string proxySpec = await CreateProxyFile(project, basePath, namspace + "." + referenceName, "Reference"); ProjectFile mapFile = project.Files.GetFile(mapSpec); if (mapFile == null) { mapFile = new ProjectFile(mapSpec) { BuildAction = BuildAction.None, Subtype = Subtype.Code, Generator = ProxyGenerator }; project.Files.Add(mapFile); } else { FileService.NotifyFileChanged(mapSpec); } ProjectFile proxyFile = project.Files.GetFile(proxySpec); if (proxyFile == null) { proxyFile = new ProjectFile(proxySpec) { BuildAction = BuildAction.Compile, Subtype = Subtype.Code, DependsOn = mapFile.FilePath }; project.Files.Add(proxyFile); } else { FileService.NotifyFileChanged(proxySpec); } mapFile.LastGenOutput = proxyFile.FilePath.FileName; item = new WebReferenceItem(engine, project, referenceName, basePath, mapFile); // Add references to the project if they do not exist ProjectReference packageRef; foreach (string refName in GetAssemblyReferences()) { string targetName = project.TargetRuntime.AssemblyContext.GetAssemblyNameForVersion(refName, null, project.TargetFramework); //FIXME: warn when we could not find a matching target assembly if (targetName != null) { packageRef = ProjectReference.CreateAssemblyReference(targetName); if (!project.References.Contains(packageRef)) { project.References.Add(packageRef); } } } WebReferencesService.NotifyWebReferencesChanged(project); }
public static void AddGacReference(FakeDotNetProject project, string referenceName) { var reference = ProjectReference.CreateAssemblyReference(referenceName); project.References.Add(reference); }