コード例 #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="appHost"></param>
        public void Register(IAppHost appHost)
        {
            var inMemoryProvider = new RecursiveInMemoryVirtualPathProvider(appHost);
            // Create a "Views" directory for dumping all our discovered views in
            var viewsDir = new InMemoryVirtualDirectory(inMemoryProvider, inMemoryProvider.rootDirectory)
            {
                DirName = "Views",
                files = new List<InMemoryVirtualFile>(),
                dirs = new List<InMemoryVirtualDirectory>()
            };
            inMemoryProvider.rootDirectory.dirs.Add(viewsDir);

            foreach (var asm in _assemblies)
            {
                foreach (string resource in asm.GetManifestResourceNames())
                {
                        // Get just the file name. Internally, ServiceStack dumps all these in a giant "/Views" directory anyway, so let's just do that.
                        string path = string.Join(".", resource.Split('.').Reverse().Take(2).Reverse());
                        viewsDir.AddFile(path, new StreamReader(asm.GetManifestResourceStream(resource)).ReadToEnd());
                }
            }

            var razorPlugin = new RazorFormat
            {
                VirtualPathProvider = inMemoryProvider,
                EnableLiveReload = false
            };

            appHost.LoadPlugin(razorPlugin);
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EmbeddedResourceVirtualPathProvider"/> class.
 /// </summary>
 /// <param name="appHost"></param>
 public EmbeddedResourceVirtualPathProvider(IAppHost appHost) : base(appHost)
 {
     _root = new InMemoryVirtualDirectory(this)
     {
         FlattenFileEnumeration = false
     };
     _assemblies = new List <Assembly>();
 }
コード例 #3
0
        /// <summary>
        /// Populates the root directory from embedded resources.
        /// </summary>
        public void PopulateFromEmbeddedResources()
        {
            _root = new InMemoryVirtualDirectory(this)
            {
                FlattenFileEnumeration = false
            };
            foreach (var assembly in _assemblies)
            {
                string baseName = assembly.GetName().Name + ".";

                foreach (var resource in assembly.GetManifestResourceNames())
                {
                    // Most embedded resources will start with the assembly name (e.g. Foo.txt in Bar.dll will be named Bar.Foo.txt by default)
                    // Strip that assembly name off if it's set
                    string relativeName = resource;
                    if (relativeName.StartsWith(baseName))
                    {
                        relativeName = relativeName.Remove(0, baseName.Length);
                    }

                    string   fileName;
                    string[] directoryStructure;
                    // Figure out which portion of the path represents the file name, and what directory structure it's in (if any)
                    InferFileNameAndDirectoryPath(relativeName, out fileName, out directoryStructure);

                    // Loop over the directory structure to figure out which directory this file is supposed to go in
                    InMemoryVirtualDirectory destinationDirectory = _root;
                    foreach (var directory in directoryStructure)
                    {
                        var nextLevel = (InMemoryVirtualDirectory)destinationDirectory.GetDirectory(directory);
                        // If our expected directory doesn't exist, add it
                        if (nextLevel == null)
                        {
                            nextLevel = new InMemoryVirtualDirectory(this, destinationDirectory)
                            {
                                FlattenFileEnumeration = false, DirName = directory
                            };
                            destinationDirectory.dirs.Add(nextLevel);
                        }
                        destinationDirectory = nextLevel;
                    }
                    var file = new StreamBasedVirtualFile(this, destinationDirectory, assembly.GetManifestResourceStream(resource), fileName, DateTime.Now);

                    // Give people the opportunity to exclude this file
                    if (FileExcluder != null && FileExcluder(file))
                    {
                        continue;
                    }

                    destinationDirectory.files.Add(file);
                }
            }
        }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EmbeddedResourceVirtualPathProvider"/> class.
 /// </summary>
 /// <param name="appHost"></param>
 public EmbeddedResourceVirtualPathProvider(IAppHost appHost) : base(appHost)
 {
     _root = new InMemoryVirtualDirectory(this){FlattenFileEnumeration = false};
     _assemblies = new List<Assembly>();
 }
コード例 #5
0
        /// <summary>
        /// Populates the root directory from embedded resources.
        /// </summary>
        public void PopulateFromEmbeddedResources()
        {
            _root = new InMemoryVirtualDirectory(this) { FlattenFileEnumeration = false };
            foreach (var assembly in _assemblies)
            {
                string baseName = assembly.GetName().Name + ".";

                foreach (var resource in assembly.GetManifestResourceNames())
                {
                    // Most embedded resources will start with the assembly name (e.g. Foo.txt in Bar.dll will be named Bar.Foo.txt by default)
                    // Strip that assembly name off if it's set
                    string relativeName = resource;
                    if (relativeName.StartsWith(baseName))
                    {
                        relativeName = relativeName.Remove(0, baseName.Length);
                    }

                    string fileName;
                    string[] directoryStructure;
                    // Figure out which portion of the path represents the file name, and what directory structure it's in (if any)
                    InferFileNameAndDirectoryPath(relativeName, out fileName, out directoryStructure);

                    // Loop over the directory structure to figure out which directory this file is supposed to go in
                    InMemoryVirtualDirectory destinationDirectory = _root;
                    foreach (var directory in directoryStructure)
                    {
                        var nextLevel = (InMemoryVirtualDirectory) destinationDirectory.GetDirectory(directory);
                        // If our expected directory doesn't exist, add it
                        if (nextLevel == null)
                        {
                            nextLevel = new InMemoryVirtualDirectory(this, destinationDirectory) {FlattenFileEnumeration = false, DirName = directory};
                            destinationDirectory.dirs.Add(nextLevel);
                        }
                        destinationDirectory = nextLevel;
                    }
                    var file = new StreamBasedVirtualFile(this, destinationDirectory, assembly.GetManifestResourceStream(resource), fileName, DateTime.Now);

                    // Give people the opportunity to exclude this file
                    if (FileExcluder != null && FileExcluder(file))
                    {
                        continue;
                    }

                    destinationDirectory.files.Add(file);
                }
            }
        }