public XsltView(XsltTemplate viewTemplate, XsltViewData viewData, string ajaxDeclaration, HttpContextBase httpContext) { this.viewTemplate = viewTemplate; this.viewData = viewData; this.ajaxDeclaration = ajaxDeclaration; construct = new XmlResponseBuilder(httpContext); InitializeConstruct(); xslTransformer = viewTemplate.XslTransformer; }
protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath) { if(!(controllerContext.Controller.ViewData.Model is XsltViewData)) { throw new ArgumentException("the view data object should be of type XsltViewData"); } var viewTemplate = new XsltTemplate(VirtualPathProvider, viewPath); var view = new XsltView(viewTemplate, controllerContext.Controller.ViewData.Model as XsltViewData, string.Empty, controllerContext.HttpContext); return view; }
private static void BuildCode(BuildOptions options, DataReader reader) { Console.WriteLine(); Console.WriteLine("*** Build Code Begin ***"); DateTime startTime = DateTime.Now; XmlDocument doc = new XmlDocument(); XmlNode rootNode = doc.CreateElement("Root"); XmlAttribute attr; attr = doc.CreateAttribute("Output"); string output = options.config.OutputCode.Path; output = Path.GetFullPath(output); attr.Value = output; rootNode.Attributes.Append(attr); IDictionary <string, object> configFormatValues = new HierarchyDictionary <string, object>(); foreach (var tableInfo in reader.DataTableInfos) { // WorkbookItem item = reader.tableNameToWorkbook[tableInfo.Name]; XmlNode typeNode = doc.CreateElement("Type"); attr = doc.CreateAttribute("Name"); attr.Value = reader.TableNameToTypeName(tableInfo.Name); typeNode.Attributes.Append(attr); attr = doc.CreateAttribute("Type"); if ((tableInfo.Flags & DataTableFlags.Struct) == DataTableFlags.Struct) { attr.Value = "Struct"; } else if ((tableInfo.Flags & DataTableFlags.Enum) == DataTableFlags.Enum) { attr.Value = "Enum"; } else { attr.Value = "Class"; } typeNode.Attributes.Append(attr); attr = doc.CreateAttribute("Namespace"); attr.Value = options.config.OutputCode.Namespace; typeNode.Attributes.Append(attr); if (!((tableInfo.Flags & DataTableFlags.Enum) == DataTableFlags.Enum)) { foreach (var col in tableInfo.Columns) { XmlNode fieldNode = doc.CreateElement("Field"); attr = doc.CreateAttribute("Name"); attr.Value = col.Name; fieldNode.Attributes.Append(attr); attr = doc.CreateAttribute("Type"); if (col.DataType != null) { attr.Value = col.DataType.FullName; } else { attr.Value = reader.TableNameToTypeName(col.DataTypeName); } fieldNode.Attributes.Append(attr); attr = doc.CreateAttribute("Description"); attr.Value = ReplaceSafeChar(col.Description); fieldNode.Attributes.Append(attr); attr = doc.CreateAttribute("Key"); attr.Value = col.IsKey.ToString(); fieldNode.Attributes.Append(attr); typeNode.AppendChild(fieldNode); } } else { var colName = tableInfo.GetColumn("Name"); var colValue = tableInfo.GetColumn("Value"); foreach (EnumValue row in reader.LoadDataObjects(tableInfo.Name, typeof(EnumValue))) { XmlNode fieldNode = doc.CreateElement("Enum"); attr = doc.CreateAttribute("Name"); attr.Value = row.Name; fieldNode.Attributes.Append(attr); attr = doc.CreateAttribute("Type"); attr.Value = colName.DataType.FullName; fieldNode.Attributes.Append(attr); if (!string.IsNullOrEmpty(row.Description)) { attr = doc.CreateAttribute("Description"); attr.Value = ReplaceSafeChar(row.Description); fieldNode.Attributes.Append(attr); } attr = doc.CreateAttribute("Value"); attr.Value = reader.ChangeType(row.Value, colValue.DataType).ToStringOrNulll(); fieldNode.Attributes.Append(attr); typeNode.AppendChild(fieldNode); } } rootNode.AppendChild(typeNode); } doc.AppendChild(rootNode); //string tplPath = config.Base.ExportCodeTpl; //if (!Path.IsPathRooted(tplPath)) // tplPath = Path.Combine(baseDir, tplPath); bool isOutputDll = false; string outputCodeFile; if (Path.GetExtension(output).ToLower() == ".dll") { isOutputDll = true; outputCodeFile = Path.Combine("Temp/gen/Data", Path.GetFileNameWithoutExtension(output) + ".cs"); outputCodeFile = Path.GetFullPath(outputCodeFile); } else { outputCodeFile = output; } XsltTemplate tpl = new XsltTemplate(); tpl.Variables["OutputPath"] = outputCodeFile; var ass = typeof(DataReader).Assembly; var tplSteam = ass.GetManifestResourceStream("Build.Data.Template.code_tpl.xslt"); if (tplSteam == null) { throw new Exception("not exists " + "BuildData.Template.code_tpl.xslt"); } using (StreamReader sr = new StreamReader(tplSteam)) { string xslXml = sr.ReadToEnd(); tpl.LoadXslXml(xslXml); string[] codeFiles = tpl.Transform(doc); if (isOutputDll) { CompilerCode(output, codeFiles); } } var usedTime = (DateTime.Now - startTime).TotalSeconds; Console.WriteLine("*** Build Code End. time:{0:0.#}s ***", usedTime); }
public void XsltTemplate_DependsOn_VirtualPathProvider() { var template = new XsltTemplate(null, view); }
public void CreateTransformer() { var template = new XsltTemplate(virtualPathProvider, "~/Views/MyController/MyView.xslt"); Assert.IsNotNull(template.XslTransformer); }