示例#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);
        }
示例#2
0
        private static string AddModuleLangPack(string langjs, string lang)
        {
            var sb = new System.Text.StringBuilder();

            sb.AppendLine(langjs);

            foreach (var item in VirtualResources.GetFiles(AppSettings.ModulePath, "*config.json", SearchOption.AllDirectories))
            {
                try
                {
                    var moduleName = Path.GetDirectoryName(item);
                    moduleName = Path.GetFileName(moduleName).ToLower();
                    var json = VirtualResources.ReadAllText(item);
                    var dic  = JsonHelper.DeserializeJObject(json)["langs"][lang]
                               .ToObject <Dictionary <string, string> >()
                               .Where(w => !string.IsNullOrEmpty(w.Value));
                    if (dic == null || dic.Count() == 0)
                    {
                        continue;
                    }
                    var properties = string.Join(",", dic.Select(s => $"'{s.Key}':'{s.Value}'"));

                    sb.AppendLine($@"
(function(){{
    Kooboo.text[""{moduleName}""]={{{properties}}}
}})();
");
                }
                catch (Exception)
                {
                }
            }

            return(sb.ToString());
        }
示例#3
0
 private static void LoadModuleLangPack(Dictionary <string, string> values, string langCode)
 {
     foreach (var item in VirtualResources.GetFiles(AppSettings.ModulePath, "*config.json", SearchOption.AllDirectories))
     {
         try
         {
             var json = VirtualResources.ReadAllText(item);
             var dic  = JsonHelper.DeserializeJObject(json)?["langs"]?[langCode]?.ToObject <Dictionary <string, string> >();
             if (dic == null)
             {
                 continue;
             }
             foreach (var kv in dic)
             {
                 if (!values.ContainsKey(kv.Key) && !string.IsNullOrEmpty(kv.Value))
                 {
                     values[kv.Key] = kv.Value;
                 }
             }
         }
         catch (Exception)
         {
         }
     }
 }
        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);
        }
示例#5
0
        public void GetFilesTest()
        {
            VirtualResources.Setup(a =>
            {
                a.LoadZip("test.zip");
            });

            var files = VirtualResources.GetFiles("test/js");

            Assert.AreEqual(files.Count(), 1);
        }
示例#6
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);
        }