protected override string ParsePath() { using (Stream source = OpenStream()) { XcstCompiler compiler = CompilerFactory.CreateCompiler(); ConfigureCompiler(compiler); _result = compiler.Compile(source, baseUri: this.PhysicalPath); return(_result.Language); } }
static (CompileResult result, string packageName) GenerateCode(Uri packageUri, string testName, string testNamespace) { XcstCompiler compiler = CreateCompiler(); compiler.TargetNamespace = testNamespace; compiler.TargetClass = testName; compiler.UsePackageBase = testNamespace; compiler.SetTargetBaseTypes(typeof(TestBase)); CompileResult result = compiler.Compile(packageUri); return(result, compiler.TargetNamespace + "." + compiler.TargetClass); }
void Run(TextWriter output) { var startUri = new Uri(_projectUri, "."); var compilerFact = new XcstCompilerFactory { EnableExtensions = true, ProcessXInclude = true }; // Enable "application" extension compilerFact.RegisterExtension(new Xcst.Web.Extension.ExtensionLoader { ApplicationUri = startUri, GenerateLinkTo = true, //GenerateHref = true, AnnotateVirtualPath = true }); XcstCompiler compiler = compilerFact.CreateCompiler(); compiler.PackageFileDirectory = startUri.LocalPath; compiler.PackageFileExtension = _fileExt; compiler.IndentChars = " "; XDocument projectDoc = XDocument.Load(_projectUri.LocalPath); string rootNamespace = RootNamespace(projectDoc, _projectUri.LocalPath); string nullable = Nullable(projectDoc); if (nullable != null) { compiler.NullableAnnotate = true; compiler.NullableContext = nullable; } AddProjectDependencies(projectDoc, compiler); WriteAutogeneratedComment(output); compiler.CompilationUnitHandler = href => output; foreach (string file in Directory.EnumerateFiles(startUri.LocalPath, "*." + _fileExt, SearchOption.AllDirectories)) { var fileUri = new Uri(file, UriKind.Absolute); string fileName = Path.GetFileName(file); string fileBaseName = Path.GetFileNameWithoutExtension(file); // Ignore files starting with underscore if (fileName[0] == '_') { continue; } // Treat files ending with 'Package' as library packages; other files as pages // An alternative would be to use different file extensions for library packages and pages bool isPage = _pageEnable && !fileBaseName.EndsWith("Package"); compiler.TargetNamespace = FileNamespace(fileUri, startUri, rootNamespace); if (isPage) { compiler.TargetClass = "_Page_" + CleanIdentifier(fileBaseName); if (_pageBaseType != null) { compiler.TargetBaseTypes = new[] { _pageBaseType }; } } else { compiler.TargetClass = CleanIdentifier(fileBaseName); compiler.TargetBaseTypes = null; } Xcst.Web.Extension.ExtensionLoader.SetPage(compiler, isPage); try { compiler.Compile(fileUri); } catch (CompileException ex) { VisualStudioErrorLog(ex); throw; } } }