/// <summary> /// Given a set of tag registrations for user controls, attempt to connect those tag registrations to actual /// .NET class types in the main website assembly. This will update the Typename field for each TagRegistration /// where a matching class type is found; or if no matching class type is found, this will throw an exception. /// </summary> /// <param name="compileContext">The context in which errors should be reported.</param> /// <param name="tagRegistrations">The set of user-control registrations to resolve to real class types.</param> /// <param name="assemblies">The full set of preloaded assemblies.</param> /// <param name="assemblyDirectory">The directory where the main website DLL can be found.</param> /// <param name="rootPath">The real disk path to the root of the website's virtual directory.</param> /// <param name="currentDirectory">The current directory (for resolving relative paths).</param> public static void ResolveUserControls(ICompileContext compileContext, IEnumerable <TagRegistration> tagRegistrations, ReferencedAssembliesContext assemblies, string rootPath, string currentDirectory) { foreach (TagRegistration tagRegistration in tagRegistrations.Where(t => t.Kind == TagRegistrationKind.SingleUserControl)) { compileContext.Verbose("Registering user control <{0}:{1}> as \"{2}\".", tagRegistration.TagPrefix, tagRegistration.TagName, tagRegistration.SourceFilename); compileContext.VerboseNesting++; string filename = VistualPathUtils.ResolveWebsitePath(compileContext, tagRegistration.SourceFilename, rootPath, currentDirectory); MarkupReader userControlReader = new MarkupReader(); // todo: how to handle references to user controls not found within rootpath? Tag userControlMainDirective = userControlReader.ReadMainDirective(compileContext, filename, assemblies, rootPath); if (string.IsNullOrEmpty(userControlMainDirective.TagName) && string.Compare(userControlMainDirective.TagName, "control", StringComparison.InvariantCultureIgnoreCase) != 0) { throw new RedesignerException("Cannot register user control \"{0}\": Its main <% ... %> directive does not start with the \"Control\" keyword. Is this actually a user control?", tagRegistration.SourceFilename); } string inheritsAttribute = userControlMainDirective["inherits"]; if (string.IsNullOrEmpty(inheritsAttribute)) { throw new RedesignerException("Cannot register user control \"{0}\": Its main <% Control ... %> directive is missing the required Inherits=\"...\" attribute.", tagRegistration.SourceFilename); } tagRegistration.Typename = inheritsAttribute; compileContext.Verbose("User control registered as type \"{0}\".", inheritsAttribute); compileContext.VerboseNesting--; } }
public void ReaderTest1() { var proteinDictionary = MockRepository.GenerateStub<IProteinDictionary>(); proteinDictionary.Stub(x => x.GetProteinOrDownload(0)).IgnoreArguments().Return(new Protein()); var markupReader = new MarkupReader(_prefs, proteinDictionary); var slots = markupReader.Read("..\\..\\TestFiles\\SlotSummary1.xml"); Assert.AreEqual(9, slots.Count()); }
public void ReaderTest1() { var proteinDictionary = MockRepository.GenerateStub <IProteinDictionary>(); proteinDictionary.Stub(x => x.GetProteinOrDownload(0)).IgnoreArguments().Return(new Protein()); var markupReader = new MarkupReader(_prefs, proteinDictionary); var slots = markupReader.Read("..\\..\\TestFiles\\SlotSummary1.xml"); Assert.AreEqual(9, slots.Count()); }
/// <summary> /// Generate a replacement .designer.cs file for the given markup file, overwriting the existing /// .designer.cs file if there is one. /// </summary> public static bool GenerateDesignerForFilename(ICompileContext compileContext, string filename, IEnumerable <TagRegistration> tagRegistrations, AssemblyLoader assemblies, string assemblyDirectory, string rootPath) { string designer; string designerFilename = filename + ".designer.cs"; // Load the markup from the .aspx or .ascx file. MarkupReader markup = new MarkupReader(); MarkupInfo markupInfo; try { markupInfo = markup.LoadMarkup(compileContext, filename, tagRegistrations, assemblies, assemblyDirectory, rootPath); } catch (Exception e) { compileContext.Error("{0}: Failed to load markup file:\r\n{1}", filename, e.Message); compileContext.Verbose("Stopping file processing due to exception. Stack trace:\r\n{0}", e.StackTrace); return(false); } // If we're not inheriting a real class, there's no reason for a designer file to exist. if (markupInfo.ClassType == null) { compileContext.Verbose("Skipping generating designer file because markup does not have an Inherits=\"...\" attribute.", filename); return(true); } // Generate the output text for the new .designer.cs file. try { DesignerWriter designerWriter = new DesignerWriter(); designer = designerWriter.CreateDesigner(compileContext, markupInfo); } catch (Exception e) { compileContext.Error("{0}: Cannot regenerate designer file:\r\n{1}", filename, e.Message); compileContext.Verbose("Stopping file processing due to exception. Stack trace:\r\n{0}", e.StackTrace); return(false); } // Save the output .designer.cs file to disk. try { File.WriteAllText(designerFilename, designer, Encoding.UTF8); } catch (Exception e) { compileContext.Error("{0}: Cannot open designer file for writing:\r\n{1}", designerFilename, e.Message); compileContext.Verbose("Stopping file processing due to exception. Stack trace:\r\n{0}", e.StackTrace); return(false); } return(true); }
private void ensure_gresource_to_file_map() { // map gresource paths to real file names if (gresource_to_file_map != null) { return; } gresource_to_file_map = new Dictionary <string, string>(); foreach (var gresource in context.gresources) { if (!File.Exists(gresource)) { Report.error(null, "GResources file `%s' does not exist".printf(gresource)); continue; } MarkupReader reader = new MarkupReader(gresource); int state = 0; string prefix = null; string alias = null; MarkupTokenType current_token = reader.read_token(); while (current_token != MarkupTokenType.EOF) { if (current_token == MarkupTokenType.START_ELEMENT && reader.name == "gresource") { prefix = reader.get_attribute("prefix"); } else if (current_token == MarkupTokenType.START_ELEMENT && reader.name == "file") { alias = reader.get_attribute("alias"); state = 1; } else if (state == 1 && current_token == MarkupTokenType.TEXT) { var name = reader.content; var filename = context.get_gresource_path(gresource, name); if (alias != null) { gresource_to_file_map[Path.build_filename(prefix, alias)] = filename; } gresource_to_file_map[Path.build_filename(prefix, name)] = filename; state = 0; } current_token = reader.read_token(); } } }
/// <summary> /// Verify the current .designer.cs file for the given markup file. /// </summary> /// <returns>True if the file passes inspection, false if it fails.</returns> public static bool VerifyDesignerForFilename(ICompileContext compileContext, string filename, IEnumerable <TagRegistration> tagRegistrations, AssemblyLoader assemblies, string assemblyDirectory, string rootPath) { DesignerInfo designerInfo; string designerFilename = filename + ".designer.cs"; // Load the markup from the .aspx or .ascx file. MarkupReader markup = new MarkupReader(); MarkupInfo markupInfo; try { markupInfo = markup.LoadMarkup(compileContext, filename, tagRegistrations, assemblies, assemblyDirectory, rootPath); } catch (Exception e) { compileContext.Error("{0}: Failed to load markup file:\r\n{1}", filename, e.Message); compileContext.Verbose("Stopping file processing due to exception. Stack trace:\r\n{0}", e.StackTrace); return(false); } if (markupInfo.ClassType == null) { compileContext.Verbose("Skipping verification of .designer file, because markup has no Inherits=\"...\" attribute and therefore has no .designer file.", filename); return(true); } compileContext.Verbose(string.Empty); // Read and parse the current .designer.cs file. try { DesignerReader designerReader = new DesignerReader(); designerInfo = designerReader.LoadDesignerFile(compileContext, designerFilename); } catch (Exception e) { compileContext.Error("{0}: Cannot load designer file:\r\n{1}", filename, e.Message); compileContext.Verbose("Stopping file processing due to exception. Stack trace:\r\n{0}", e.StackTrace); return(false); } compileContext.Verbose(string.Empty); // And finally compare the expectations of the markup against the reality of the .designer.cs file. return(CompareMarkupInfoToDesignerInfo(compileContext, filename, markupInfo, designerInfo)); }
private void process_current_ui_resource(string ui_resource, CodeNode node) { /* Scan a single gtkbuilder file for signal handlers in <object> elements, * and save an handler string -> Vala.Signal mapping for each of them */ ensure_cclass_to_vala_map(); ensure_gresource_to_file_map(); current_handler_to_signal_map = null; current_child_to_class_map = null; var ui_file = gresource_to_file_map[ui_resource]; if (ui_file == null || !File.Exists(ui_file)) { node.error = true; Report.error(node.source_reference, "UI resource not found: `%s'. Please make sure to specify the proper GResources xml files with --gresources and alternative search locations with --gresourcesdir.".printf(ui_resource)); return; } current_handler_to_signal_map = new Dictionary <string, Signal>(); current_child_to_class_map = new Dictionary <string, Class>(); MarkupReader reader = new MarkupReader(ui_file); Class current_class = null; bool template_tag_found = false; MarkupTokenType current_token = reader.read_token(); while (current_token != MarkupTokenType.EOF) { if (current_token == MarkupTokenType.START_ELEMENT && (reader.name == "template" || reader.name == "object")) { if (reader.name == "template") { template_tag_found = true; } var class_name = reader.get_attribute("class"); if (class_name != null) { current_class = cclass_to_vala_map[class_name]; var child_name = reader.get_attribute("id"); if (child_name != null) { current_child_to_class_map[child_name] = current_class; } } } else if (current_class != null && current_token == MarkupTokenType.START_ELEMENT && reader.name == "signal") { var signal_name = reader.get_attribute("name"); var handler_name = reader.get_attribute("handler"); if (current_class != null) { if (signal_name == null || handler_name == null) { Report.error(node.source_reference, "Invalid signal in ui file `%s'".printf(ui_file)); current_token = reader.read_token(); continue; } var sep_idx = signal_name.IndexOf("::"); if (sep_idx >= 0) { // detailed signal, we don't care about the detail signal_name = signal_name.Substring(0, sep_idx); } var sig = SemanticAnalyzer.symbol_lookup_inherited(current_class, signal_name.Replace("-", "_")) as Signal; if (sig != null) { current_handler_to_signal_map[handler_name] = sig; } } } current_token = reader.read_token(); } if (!template_tag_found) { Report.error(node.source_reference, "ui resource `%s' does not describe a valid composite template".printf(ui_resource)); } }
public async System.Threading.Tasks.Task <byte[]> GenerateDesignerFile(ProjectItem projectItem, string contents, string outputAssemblyPath) { // get list of referenced assemblies. var project = projectItem.ContainingProject; var unconfiguredProject = project.GetUnconfiguredProject(); var lockService = unconfiguredProject.ProjectService.Services.ProjectLockService; var configuredProject = await unconfiguredProject.GetSuggestedConfiguredProjectAsync(); List <ITaskItem> assemblyReferenceItems; // need to gather the referenced assemblies. using (var access = await lockService.WriteLockAsync()) { Microsoft.Build.Evaluation.Project msBuildProject = await access.GetProjectAsync(configuredProject); // party on it, respecting the type of lock you've acquired. var assemblyReferenceGatherer = new AssemblyReferenceGatherer(); assemblyReferenceItems = assemblyReferenceGatherer.GetAssemblyReferences(msBuildProject.Xml).ToList(); } var projDir = project.GetProjectPath(); var referencedAssemblies = new ReferencedAssembliesContext(assemblyReferenceItems, outputAssemblyPath); string currentDir = System.IO.Path.GetDirectoryName(project.FullName); string websiteRootPath = currentDir; // todo - this could point to a dnn website we are targeting? List <TagRegistration> tagRegistrations = referencedAssemblies.StandardTagRegistrations.ToList(); UserControlTagRegistrationResolver.ResolveUserControls(this, tagRegistrations, referencedAssemblies, websiteRootPath, currentDir); Verbose("Begin processing \"{0}\"...", projectItem.Name); Verbose(""); VerboseNesting++; BeginFile(projectItem.Name); //bool succeeded = GenerateDesignerForFilename(document.FullName, tagRegistrations, referencedAssemblies, websiteRootPath); bool succeeded = false; // var filename = document.FullName; string designer = null; // string designerFilename = filename + ".designer.cs"; // Load the markup from the .aspx or .ascx file. MarkupReader markup = new MarkupReader(); MarkupInfo markupInfo = null; try { markupInfo = markup.LoadMarkup(this, tagRegistrations, referencedAssemblies, websiteRootPath, contents, projectItem.Name); } catch (Exception e) { Error("{0}: Failed to load markup file:\r\n{1}", projectItem.Name, e.Message); Verbose("Stopping file processing due to exception. Stack trace:\r\n{0}", e.StackTrace); succeeded = false; return(null); } // If we're not inheriting a real class, there's no reason for a designer file to exist. if (string.IsNullOrWhiteSpace(markupInfo.InheritsClassName)) { Verbose("Skipping generating designer file because markup does not have an Inherits=\"...\" attribute.", projectItem.Name); succeeded = true; return(null); } // Generate the output text for the new .designer.cs file. try { DesignerWriter designerWriter = new DesignerWriter(); designer = designerWriter.CreateDesigner(this, markupInfo); } catch (Exception e) { Error("{0}: Cannot regenerate designer file:\r\n{1}", projectItem.Name, e.Message); Verbose("Stopping file processing due to exception. Stack trace:\r\n{0}", e.StackTrace); succeeded = false; return(null); } // Save the output .designer.cs file to disk. var utfBytes = Encoding.UTF8.GetBytes(designer); EndFile(projectItem.Name, succeeded); VerboseNesting--; Verbose(""); Verbose("End processing \"{0}\".", projectItem.Name); return(utfBytes); }