private void AddProjectResources(ProjectSettings project) { var list = new List<string>(); foreach (var s in project.Resources) { if (s.Contains('*') || s.Contains('?')) { var wc = WildcardFactory.BuildWildcards(s); foreach (var r in _resources.Where(e => wc.IsMatch(e.Key)).Select(e => e.Key)) { list.Add(r); } } else { list.Add(s); } } foreach (var s in list) { SetResourcesIncluded(new[] { s }); if (s.EndsWith(".css")) { // TODO: deuglify Converter.AddCSS(new string[] { s }); } } }
private static ProjectSettings LoadXml(string filepath) { var directory = Path.GetDirectoryName(filepath); var doc = new XmlDocument(); using (var reader = XmlReader.Create(filepath)) { doc.Load(reader); } var settings = new ProjectSettings(directory); var ptype = settings.GetType(); foreach (var e in doc.DocumentElement.ChildNodes.OfType<XmlElement>()) { var pi = ptype.GetProperty(e.LocalName); if (null == pi) { throw new Exception("property '" + e.LocalName + "' is not defined."); } var value = e.InnerText.Trim(); if (pi.Name == "FrameworkDirectory") { value = MakeAbsolutePath(directory, value); } if (pi.Name == "ModelType") { settings.ModelType = CreateModelType(value); } else if (pi.PropertyType.IsArray) { var a0 = (string[])(pi.GetValue(settings) ?? new string[0]); string[] a1; if (pi.Name == "AdditionalScripts") { var add = value .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(s => s.Trim()); a1 = a0.Union(add).ToArray(); } else { a1 = a0.Union(new string[] { value }).ToArray(); } pi.SetValue(settings, a1); } else if (pi.PropertyType == typeof(string)) { pi.SetValue(settings, value); } else { throw new Exception("property '" + e.LocalName + "' type not supported."); } } return settings; }
/// <summary>Loads project items from the settings.</summary> /// <param name="project"></param> private void LoadProjectItems(ProjectSettings project) { var isframework = project is FrameworkSettings; Trace("load directory '{0}' ...", project.ProjectDirectory); // additional assemblies if (null != project.AdditionalAssemblies) { foreach (var name in project.AdditionalAssemblies) { Converter.LoadAssembly(name); } } // path to source Converter.SetSourceDirectory(project.SourceDirectory); // projects if (null != project.Projects) { foreach (var csproject in project.Projects) { Trace(" add source project '{0}' ...", csproject); Converter.AddProject(csproject); } } if(null != project.SourceFiles) { foreach(var csfile in project.SourceFiles) { var path = csfile; if(!Path.IsPathRooted(path)) { path = Path.GetFullPath(Path.Combine(project.SourceDirectory, path)); } Trace(" add source file '{0}' ...", path); Converter.AddSourceFile(path); } } // script includes AddScripts(project.FrameworkScripts, ScriptOptions.Framework); AddScripts(project.ScriptsBefore, ScriptOptions.Before); AddScripts(project.ScriptsAfter, ScriptOptions.After); // CSS if(null != project.Resources) { AddProjectResources(project); } // external scripts if(null != project.ExternalScripts) { foreach(var e in project.ExternalScripts) { Converter.AddScript(e); } } }