Example #1
0
 public static TemplateSource FromFile(string filePath, string discoveryPath)
 {
     FileInfo fileInfo = new FileInfo(filePath);
     if(!fileInfo.Exists)
     {
         throw new TemplateSourceException(string.Format("Template file '{0}' does not exists",filePath));
     }
     TemplateSource source = new TemplateSource ();
     source.DiscoveryPath = discoveryPath;
     source.ReferenceFilePath = filePath;
     source.SourceStream = File.OpenRead (filePath);
     source.TemplateFileExtension = fileInfo.Extension;
     return source;
 }
Example #2
0
 public static TemplateSource FromResource(Assembly targetAssembly, string fullyQualifiedResourcePath, string discoveryPath)
 {
     Stream resourceStream = targetAssembly.GetManifestResourceStream (fullyQualifiedResourcePath);
     if (resourceStream == null)
     {
         throw new TemplateSourceException (string.Format ("Invalid resource '{0}' in assembly '{1}'", fullyQualifiedResourcePath, targetAssembly.FullName));
     }
     FileInfo fileInfo = new FileInfo(fullyQualifiedResourcePath);
     TemplateSource source = new TemplateSource ();
     source.DiscoveryPath = discoveryPath;
     source.ReferenceFilePath = fullyQualifiedResourcePath;
     source.SourceStream = resourceStream;
     source.TemplateFileExtension = fileInfo.Extension;
     return source;
 }
        public static TemplateSource FromFile(string filePath, string discoveryPath)
        {
            FileInfo fileInfo = new FileInfo(filePath);

            if (!fileInfo.Exists)
            {
                throw new TemplateSourceException(string.Format("Template file '{0}' does not exists", filePath));
            }
            TemplateSource source = new TemplateSource();

            source.DiscoveryPath         = discoveryPath;
            source.ReferenceFilePath     = filePath;
            source.SourceStream          = File.OpenRead(filePath);
            source.TemplateFileExtension = fileInfo.Extension;
            return(source);
        }
        public static TemplateSource FromResource(Assembly targetAssembly, string fullyQualifiedResourcePath, string discoveryPath)
        {
            Stream resourceStream = targetAssembly.GetManifestResourceStream(fullyQualifiedResourcePath);

            if (resourceStream == null)
            {
                throw new TemplateSourceException(string.Format("Invalid resource '{0}' in assembly '{1}'", fullyQualifiedResourcePath, targetAssembly.FullName));
            }
            FileInfo       fileInfo = new FileInfo(fullyQualifiedResourcePath);
            TemplateSource source   = new TemplateSource();

            source.DiscoveryPath         = discoveryPath;
            source.ReferenceFilePath     = fullyQualifiedResourcePath;
            source.SourceStream          = resourceStream;
            source.TemplateFileExtension = fileInfo.Extension;
            return(source);
        }
        public TemplatesCompilationResult AddEmbeddedTemplates(Assembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            List <TemplateSource> sources = new List <TemplateSource> ();

            foreach (var resourceName in assembly.GetManifestResourceNames())
            {
                FileInfo fileInfo = new FileInfo(resourceName);

                TemplateSource source = TemplateSource.FromResource(assembly, resourceName, fileInfo.Name.Replace(fileInfo.Extension, string.Empty));
                sources.Add(source);
            }
            return(this.Compile(sources.ToArray()));
        }