Example #1
0
        private List <Assembly> LoadDlls()
        {
            var  dlls           = new List <Assembly>();
            bool isNetFramework = false;  // = RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework");

#if NET461
            {
                isNetFramework = true;
            }
#endif

            foreach (var folder in extensionFolders)
            {
                if (!Directory.Exists(folder))
                {
                    continue;
                }

                var allsubdlls = VirtualResources.GetFiles(folder, "*.dll", SearchOption.AllDirectories);

                foreach (var filename in allsubdlls)
                {
#if DEBUG
                    if (isNetFramework && File.Exists("ignoremodules.txt"))
                    {
                        var modules = File.ReadAllText("ignoremodules.txt")
                                      .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
                                      .Select(s =>
                        {
                            var module = s.ToUpper().Trim();
                            if (module.EndsWith(".ZIP"))
                            {
                                module = module.Substring(0, module.Length - 4);
                            }
                            return(module);
                        });

                        if (modules.Any(a => filename.Contains(a)))
                        {
                            continue;
                        }
                    }
#endif

                    try
                    {
                        var otherAssembly = Assembly.Load(VirtualResources.ReadAllBytes(filename));

                        if (otherAssembly != null)
                        {
                            dlls.Add(otherAssembly);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            return(dlls);
        }
        private List <Assembly> LoadDlls()
        {
            var dlls = new List <Assembly>();

            foreach (var folder in extensionFolders)
            {
                if (!Directory.Exists(folder))
                {
                    continue;
                }

                var allsubdlls = VirtualResources.GetFiles(folder, "*.dll", SearchOption.AllDirectories);

                foreach (var filename in allsubdlls)
                {
                    try
                    {
                        var otherAssembly = Assembly.Load(VirtualResources.ReadAllBytes(filename));

                        if (otherAssembly != null)
                        {
                            dlls.Add(otherAssembly);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            return(dlls);
        }
Example #3
0
        public void ReadAllBytesTest()
        {
            VirtualResources.Setup(a =>
            {
                a.LoadZip("test.zip");
            });

            var result = VirtualResources.ReadAllBytes("test/TestPage.html");

            Assert.IsTrue(result.Length > 0);
        }
Example #4
0
        public static RenderRespnose RenderJsLangFile(string FullFileName, RenderContext context)
        {
            var values = Kooboo.Data.Cache.MultiLingualRender.GetJs(context);

            if (values == null)
            {
                var bytes = VirtualResources.ReadAllBytes(FullFileName);

                values = Kooboo.Data.Cache.MultiLingualRender.SetGetJs(context, bytes);
            }

            return(new RenderRespnose()
            {
                BinaryBytes = values, ContentType = "application/javascript"
            });
        }
        private static byte[] GetBinary(RenderContext context, RenderOption option, string RelativeUrl, string FullFileName)
        {
            if (option.EnableMultilingual && RelativeUrl.ToLower().EndsWith(option.MultilingualJsFile))
            {
                Guid   key   = Lib.Security.Hash.ComputeGuidIgnoreCase(RelativeUrl);
                byte[] bytes = null;
#if DEBUG
                {
                    bytes = VirtualResources.ReadAllBytes(FullFileName);
                    key   = Lib.Security.Hash.ComputeGuid(bytes);
                }
#endif
                var values = Kooboo.Data.Cache.MultiLingualRender.GetJs(context);
                if (values == null)
                {
                    if (bytes == null)
                    {
                        bytes = VirtualResources.ReadAllBytes(FullFileName);
                    }
                    values = Kooboo.Data.Cache.MultiLingualRender.SetGetJs(context, bytes);
                }
                return(values);
            }
            else
            {
                byte[] result = null;
#if DEBUG
                {
                    result = VirtualResources.ReadAllBytes(FullFileName);
                }
#endif
                if (result == null)
                {
                    Guid key = Kooboo.Lib.Security.Hash.ComputeGuidIgnoreCase(RelativeUrl);
                    result = Kooboo.Data.Cache.RenderCache.GetBinary(key);
                    if (result == null)
                    {
                        result = VirtualResources.ReadAllBytes(FullFileName);
                        Kooboo.Data.Cache.RenderCache.SetBinary(key, result);
                    }
                }
                return(result);
            }
        }
Example #6
0
        public Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            var assemblyName = new AssemblyName(args.Name);
            var name         = assemblyName.Name;

            var assembly = Assemblies.Find(a =>
            {
                return(assemblyName.Name == a.GetName().Name);
            });

            if (assembly != null)
            {
                return(assembly);
            }

            var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
            var path          = extensionFolders.Union(new[] { baseDirectory }).Select(folder =>
            {
                var dllpath = Path.Combine(folder, string.Format("{0}.dll", name));
                if (VirtualResources.FileExists(dllpath))
                {
                    return(dllpath);
                }

                return(string.Empty);
            }).FirstOrDefault(f => f.Length > 0);

            if (!string.IsNullOrEmpty(path))
            {
                assembly = Assembly.Load(VirtualResources.ReadAllBytes(path));
                lock (_lockObj)
                {
                    if (!Assemblies.Exists(a => a.FullName == assemblyName.FullName))
                    {
                        Assemblies.Add(assembly);
                    }
                }
                return(assembly);
            }

            return(null);
        }
Example #7
0
        private static byte[] GetBinary(RenderContext context, SpaRenderOption option, string RelativeUrl, string FullFileName)
        {
            byte[] result = null;
#if DEBUG
            {
                result = VirtualResources.ReadAllBytes(FullFileName);
            }
#endif
            if (result == null)
            {
                Guid key = Kooboo.Lib.Security.Hash.ComputeGuidIgnoreCase(RelativeUrl);
                result = Kooboo.Data.Cache.RenderCache.GetBinary(key);
                if (result == null)
                {
                    result = VirtualResources.ReadAllBytes(FullFileName);
                    Kooboo.Data.Cache.RenderCache.SetBinary(key, result);
                }
            }
            return(result);
        }
Example #8
0
        private List <Assembly> LoadDlls()
        {
            var dlls           = new List <Assembly>();
            var isNetFramework = RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework");

            foreach (var folder in extensionFolders)
            {
                if (!Directory.Exists(folder))
                {
                    continue;
                }

                var allsubdlls = VirtualResources.GetFiles(folder, "*.dll", SearchOption.AllDirectories);

                foreach (var filename in allsubdlls)
                {
                    try
                    {
                        var otherAssembly            = Assembly.Load(VirtualResources.ReadAllBytes(filename));
                        var targetFrameworkAttribute = otherAssembly?.CustomAttributes?.FirstOrDefault(f => f.AttributeType == typeof(TargetFrameworkAttribute));
                        var netVersion = targetFrameworkAttribute?.ConstructorArguments?.FirstOrDefault().Value;

                        if (isNetFramework && netVersion != null && netVersion.ToString().StartsWith(".NETCoreApp"))
                        {
                            continue;
                        }

                        if (otherAssembly != null)
                        {
                            dlls.Add(otherAssembly);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            return(dlls);
        }