Exemple #1
0
        protected virtual void ConfigureCompiler(XcstCompiler compiler)
        {
            compiler.PackageTypeResolver  = typeName => BuildManager.GetType(typeName, throwOnError: false);
            compiler.PackageFileDirectory = HostingEnvironment.MapPath("~/App_Code");
            compiler.PackageFileExtension = FileExtension;
            compiler.UseLineDirective     = true;
            compiler.TargetVisibility     = CodeVisibility.Public;

            if (this.IsFileInCodeDir)
            {
                compiler.NamedPackage = true;
            }
            else
            {
                compiler.SetTargetBaseTypes(this.PageType);
                compiler.TargetNamespace = this.GeneratedTypeNamespace;
                compiler.TargetClass     = this.GeneratedTypeName;

                compiler.ModuleResolver = (_moduleResolver = new LoggingResolver(new XmlUrlResolver()));

                Xcst.Web.Extension.ExtensionLoader.SetPage(compiler, true);
            }

            Xcst.Web.Extension.ExtensionLoader.SetApplicationUri(compiler, _applicationUri);
            Xcst.Web.Extension.ExtensionLoader.SetGenerateHref(compiler, true);
        }
Exemple #2
0
        public static void SetPage(XcstCompiler compiler, bool page)
        {
            if (compiler is null)
            {
                throw new ArgumentNullException(nameof(compiler));
            }

            compiler.SetParameter(XmlNamespaces.XcstApplication, "page", page);
        }
Exemple #3
0
        public static void SetDefaultModelDynamic(XcstCompiler compiler, bool defaultModelDynamic)
        {
            if (compiler is null)
            {
                throw new ArgumentNullException(nameof(compiler));
            }

            compiler.SetParameter(XmlNamespaces.XcstApplication, "default-model-dynamic", defaultModelDynamic);
        }
Exemple #4
0
        public static void SetGenerateLinkTo(XcstCompiler compiler, bool generateLinkTo)
        {
            if (compiler is null)
            {
                throw new ArgumentNullException(nameof(compiler));
            }

            compiler.SetParameter(XmlNamespaces.XcstApplication, "generate-linkto", generateLinkTo);
        }
Exemple #5
0
        public static void SetAnnotateVirtualPath(XcstCompiler compiler, bool annotateVirtualPath)
        {
            if (compiler is null)
            {
                throw new ArgumentNullException(nameof(compiler));
            }

            compiler.SetParameter(XmlNamespaces.XcstApplication, "annotate-virtual-path", annotateVirtualPath);
        }
Exemple #6
0
        public static void SetApplicationUri(XcstCompiler compiler, Uri?applicationUri)
        {
            if (compiler is null)
            {
                throw new ArgumentNullException(nameof(compiler));
            }

            compiler.SetParameter(XmlNamespaces.XcstApplication, "application-uri", applicationUri);
        }
Exemple #7
0
        public static XcstCompiler CreateCompiler()
        {
            XcstCompiler compiler = _compilerFactory.CreateCompiler();

            compiler.UseLineDirective    = true;
            compiler.PackageTypeResolver = n => Assembly.GetExecutingAssembly().GetType(n);

            return(compiler);
        }
Exemple #8
0
        protected override string ParsePath()
        {
            using (Stream source = OpenStream()) {
                XcstCompiler compiler = CompilerFactory.CreateCompiler();

                ConfigureCompiler(compiler);

                _result = compiler.Compile(source, baseUri: this.PhysicalPath);

                return(_result.Language);
            }
        }
Exemple #9
0
        protected override void ConfigureCompiler(XcstCompiler compiler)
        {
            base.ConfigureCompiler(compiler);

            if (this.IsFileInCodeDir)
            {
                compiler.SetParameter(XmlNamespaces.XcstApplication, "page-type", this.PageType);
            }
            else
            {
                Xcst.Web.Extension.ExtensionLoader.SetDefaultModelDynamic(compiler, true);
            }
        }
Exemple #10
0
        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);
        }
Exemple #11
0
        // Adding project dependencies as package libraries enables referencing packages from other projects
        void AddProjectDependencies(XDocument projectDoc, XcstCompiler compiler)
        {
            XNamespace xmlns = projectDoc.Root.Name.Namespace;

            foreach (XElement projRef in projectDoc.Root.Elements(xmlns + "ItemGroup").Elements(xmlns + "ProjectReference"))
            {
                string refPath = projRef.Attribute("Include").Value;
                string refDll  = ReferenceAssemblyPath(refPath);

                if (File.Exists(refDll))
                {
                    compiler.AddPackageLibrary(refDll);
                }
            }
        }
Exemple #12
0
        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;
                }
            }
        }