public void then_exception_is_thrown()
        {
            var callerWithoutResource = new TestAttribute();

            this.Invoking(_ =>
                          AssemblyResourceReader.ReadString(callerWithoutResource, "ResourceFile.txt"))
            .Should().Throw <Exception>();
        }
 public override void Act()
 {
     using (var stream = AssemblyResourceReader.ReadStream(this, "ResourceFile.txt"))
     {
         using (var streamReader = new StreamReader(stream))
         {
             _content = streamReader.ReadToEnd();
         }
     }
 }
示例#3
0
 public MailerHelper()
 {
     AppointmentHtmlBody = new AssemblyResourceReader(HttpContext.Current.ApplicationInstance.GetType().BaseType.Assembly)
                           .ReadResourceAsString("Areas.HealthDemo.Resources.NewAppoint.html");
     AppointmentHtmlBody2 = new AssemblyResourceReader(HttpContext.Current.ApplicationInstance.GetType().BaseType.Assembly)
                            .ReadResourceAsString("Areas.HealthDemo.Resources.NewAppoint2.html");
     FileHtmlBody = new AssemblyResourceReader(HttpContext.Current.ApplicationInstance.GetType().BaseType.Assembly)
                    .ReadResourceAsString("Areas.HealthDemo.Resources.NewFilePage.html");
     CMERegHtmlBody = new AssemblyResourceReader(HttpContext.Current.ApplicationInstance.GetType().BaseType.Assembly)
                      .ReadResourceAsString("Areas.HealthDemo.Resources.CMEReg.html");
 }
示例#4
0
        private Dictionary <string, byte[]> FindIncludedBlazorModuleFiles(Assembly asm)
        {
            var generatedVpp = new Dictionary <string, byte[]>();

            var libraries    = FindIncludedBlazorModules(asm);
            var allResources = asm.GetManifestResourceNames();

            foreach (var libraryName in libraries)
            {
                string cssMerged    = string.Empty;
                var    cssSearch    = libraryName + ".dist.css.";
                var    cssResources = allResources.Where(r => r.Contains(cssSearch));
                foreach (var resource in cssResources)
                {
                    cssMerged += Environment.NewLine;
                    cssMerged += $"/* {resource} */";
                    cssMerged += Environment.NewLine;
                    cssMerged += AssemblyResourceReader.ReadString(asm, resource);
                }
                var appCss = libraryName + "/dist/_framework/app.css";
                generatedVpp.Add(appCss, Encoding.UTF8.GetBytes(cssMerged));

                var binSearch = libraryName + ".dist._framework._bin.";
                var heuristicallyFoundResources = allResources.Where(r => r.Contains(binSearch));

                string prefix = null;
                foreach (var resourcesToInclude in heuristicallyFoundResources)
                {
                    var at = resourcesToInclude.IndexOf(binSearch, StringComparison.OrdinalIgnoreCase);
                    prefix = resourcesToInclude.Substring(0, at - 1);

                    var pathRight        = resourcesToInclude.Substring(at + binSearch.Length);
                    var fullPath         = libraryName + "/dist/_framework/_bin/" + pathRight;
                    var resourceContents = AssemblyResourceReader.ReadBinary(asm, resourcesToInclude);
                    generatedVpp.Add(fullPath, resourceContents);
                }

                var monoJs             = libraryName + "/dist/_framework/wasm/mono.js";
                var monoWasm           = libraryName + "/dist/_framework/wasm/mono.wasm";
                var blazor_boot        = libraryName + "/dist/_framework/blazor.boot.json";
                var blazor_server      = libraryName + "/dist/_framework/blazor.server.js";
                var blazor_webassembly = libraryName + "/dist/_framework/blazor.webassembly.js";

                foreach (var resourceToInclude in new[]
                         { monoJs, monoWasm, blazor_boot, blazor_server, blazor_webassembly })
                {
                    generatedVpp.Add(resourceToInclude, AssemblyResourceReader.ReadBinary(asm, prefix + "." + resourceToInclude.Replace("/", ".")));
                }
            }

            return(generatedVpp);
        }
示例#5
0
        public void Add(Assembly assembly, string projectSourcePath = null)
        {
            dependentAssemblies.Add(assembly);
            var prefix       = EmbeddedResourcePathFactory.CreateVppAsmDirectoryPathForViews(assembly);
            var assemblyName = assembly.GetName().Name;

            foreach (var resourcePath in assembly.GetManifestResourceNames().Where(r => r.StartsWith(assemblyName)))
            {
                var resourcePathWithoutAsm = resourcePath.Substring(assemblyName.Length + 1);
                var content = AssemblyResourceReader.ReadString(assembly, resourcePath);
                _.Add(prefix + "/" + resourcePathWithoutAsm, content);
            }
        }
示例#6
0
        protected void Application_Start(object sender, EventArgs e)
        {
            var vpp    = EmbeddedResourceVirtualPathProviderStart.Start();
            var blazor = new BlazorModuleBuilder();

            var tooling = (typeof(BackendSiteTooling.Class1)).Assembly;

            blazor.HostBlazorModule(tooling);


            var loadingHtml = AssemblyResourceReader.ReadString(tooling, "BackendSiteTooling.Boot.loading.html");

            BootPage.RegisterHtml(loadingHtml);
        }
示例#7
0
        public IReadOnlyCollection <string> FindIncludedBlazorModules(Assembly asm)
        {
            List <string> allLibraries = new List <string>();

            var resources = asm.GetManifestResourceNames();
            var booters   = resources.Where(x => x.EndsWith(".blazor.boot.json", StringComparison.OrdinalIgnoreCase));

            foreach (var bootFile in booters)
            {
                var contents    = AssemblyResourceReader.ReadString(asm, bootFile);
                var jObject     = JObject.Parse(contents);
                var libraryName = jObject["main"].ToString();

                if (libraryName.EndsWith(".dll"))
                {
                    libraryName = libraryName.Substring(0, libraryName.Length - 4);
                    allLibraries.Add(libraryName);
                }
            }

            return(allLibraries);
        }
 public void then_exception_is_thrown()
 {
     this.Invoking(_ => AssemblyResourceReader.ReadString(this, "UnexistingResource"))
     .Should().Throw <Exception>();
 }
 public void then_exception_occurs()
 {
     this.Invoking(_ => AssemblyResourceReader.Search("UnexistingResource.resx"))
     .Should().Throw <Exception>();
 }
 public void then_resource_is_read_successfully()
 {
     AssemblyResourceReader.ReadString(this, "ResourceFile.txt")
     .Should().Be("Resource content.");
 }
 public override void Act()
 {
     _stream = AssemblyResourceReader.ReadStream(this, "UnexistingResourceFile.txt");
 }
 public void then_with_parent_namespaces_resource_is_found()
 {
     AssemblyResourceReader.ReadString(this, "ResourceFile.txt", true)
     .Should().Be("Resource content.");
 }
        public void then_by_default_resource_is_not_found()
        {
            var action = new Action(() => AssemblyResourceReader.ReadString(this, "ResourceFile.txt"));

            action.Should().Throw <Exception>();
        }
示例#14
0
 public void then_resource_is_found()
 {
     AssemblyResourceReader.Search("ResourceFile.txt")
     .Should().Be("Resource content.");
 }