public async Task RenderStylesheet()
        {
            var options  = new ResourceManagementOptions();
            var manifest = new ResourceManifest();

            manifest.DefineStyle("required").SetUrl("required.css")
            .SetDependencies("dependency");
            manifest.DefineStyle("dependency").SetUrl("dependency.css");
            manifest.DefineStyle("not-required").SetUrl("not-required.css");

            options.ResourceManifests.Add(manifest);

            var resourceManager = new ResourceManager(
                new OptionsWrapper <ResourceManagementOptions>(options),
                StubFileVersionProvider.Instance
                );

            resourceManager.RegisterLink(new LinkEntry {
                Rel = "icon", Href = "/favicon.ico"
            });                                                                                     // Should not be rendered

            // Require resource
            resourceManager.RegisterResource("stylesheet", "required");

            // Register custom style
            var customStyle = ".my-class { prop: value; }";

            resourceManager.RegisterStyle(new HtmlString($"<style>{customStyle}</style>"));

            using var sw = new StringWriter();
            resourceManager.RenderStylesheet(sw);
            var htmlBuilder = new HtmlContentBuilder();

            htmlBuilder.AppendHtml(sw.ToString());

            var document = await ParseHtmlAsync(htmlBuilder);

            var links = document
                        .QuerySelectorAll <IHtmlLinkElement>("link");
            var styles = document
                         .QuerySelectorAll <IHtmlStyleElement>("style");

            Assert.Equal(2, links.Count());
            Assert.Contains(links, link => link.Href == $"{basePath}/dependency.css");
            Assert.Contains(links, link => link.Href == $"{basePath}/required.css");
            Assert.Single(styles);
            Assert.Contains(styles, style => style.InnerHtml == customStyle);
            // Required stylesheet after its dependency
            Assert.Equal(DocumentPositions.Following, links.First(link => link.Href == $"{basePath}/dependency.css")
                         .CompareDocumentPosition(
                             links.First(link => link.Href == $"{basePath}/required.css")
                             )
                         );
            // Custom style after resources
            Assert.Equal(DocumentPositions.Following, links.First(link => link.Href == $"{basePath}/required.css")
                         .CompareDocumentPosition(
                             styles.First(style => style.InnerHtml == customStyle)
                             )
                         );
        }
Example #2
0
        public void DeserializeSettings(string serialization, CombinatorResource resource)
        {
            if (String.IsNullOrEmpty(serialization))
            {
                return;
            }

            var settings = _serializer.XmlDeserialize <SerializableSettings>(serialization);

            if (settings.Url != null)
            {
                var resourceManifest = new ResourceManifest();
                resource.RequiredContext.Resource = resourceManifest.DefineResource(resource.Type.ToStringType(), settings.Url.ToString());
                resource.RequiredContext.Resource.SetUrlWithoutScheme(settings.Url);
                resource.IsOriginal = true;
            }

            if (resource.RequiredContext.Settings == null)
            {
                resource.RequiredContext.Settings = new RequireSettings();
            }
            var resourceSettings = resource.RequiredContext.Settings;

            resourceSettings.Culture    = settings.Culture;
            resourceSettings.Condition  = settings.Condition;
            resourceSettings.Attributes = settings.Attributes;
        }
        public void RemoveRequiredResourceDependency()
        {
            var options  = new ResourceManagementOptions();
            var manifest = new ResourceManifest();

            manifest.DefineResource("foo", "required");
            manifest.DefineResource("foo", "to-remove")
            .SetDependencies("dependency");
            manifest.DefineResource("foo", "dependency");
            manifest.DefineResource("foo", "not-required");

            options.ResourceManifests.Add(manifest);

            var resourceManager = new ResourceManager(
                new OptionsWrapper <ResourceManagementOptions>(options),
                StubFileVersionProvider.Instance
                );

            resourceManager.RegisterResource("foo", "required");
            resourceManager.RegisterResource("foo", "to-remove");

            resourceManager.NotRequired("foo", "to-remove");

            var requiredResources = resourceManager.GetRequiredResources("foo")
                                    .Select(ctx => ctx.Resource)
                                    .ToList();

            Assert.Contains(requiredResources, resource => resource.Name == "required");
            Assert.DoesNotContain(requiredResources, resource => resource.Name == "to-remove");
            Assert.DoesNotContain(requiredResources, resource => resource.Name == "dependency");
            Assert.DoesNotContain(requiredResources, resource => resource.Name == "not-required");
        }
        public void FindResourceFromManifestProviders()
        {
            var options  = new ResourceManagementOptions();
            var manifest = new ResourceManifest();

            manifest.DefineResource("foo", "bar1").SetAttribute("attr", "bar1");
            manifest.DefineResource("foo", "bar2").SetAttribute("attr", "bar2");
            manifest.DefineResource("foo", "bar3").SetAttribute("attr", "bar3");

            options.ResourceManifests.Add(manifest);

            var resourceManager = new ResourceManager(
                new OptionsWrapper <ResourceManagementOptions>(options),
                StubFileVersionProvider.Instance
                );

            var resourceDefinition = resourceManager.FindResource(new RequireSettings {
                Type = "foo", Name = "bar2"
            });

            Assert.NotNull(resourceDefinition);
            Assert.Equal("foo", resourceDefinition.Type);
            Assert.Equal("bar2", resourceDefinition.Name);
            Assert.Contains("bar2", ((IDictionary <string, string>)resourceDefinition.Attributes).Values);
            Assert.Contains("attr", ((IDictionary <string, string>)resourceDefinition.Attributes).Keys);
        }
        public void RequireFirstPositionedResourceWithDependencyToResourcePositionedLastShouldThrowException()
        {
            var options  = new ResourceManagementOptions();
            var manifest = new ResourceManifest();

            manifest.DefineResource("foo", "resource")
            .SetDependencies("last-resource");
            manifest.DefineResource("foo", "last-resource")
            .SetPosition(ResourcePosition.Last);
            manifest.DefineResource("foo", "first-resource")
            .SetPosition(ResourcePosition.First)
            .SetDependencies("resource");

            options.ResourceManifests.Add(manifest);

            var resourceManager = new ResourceManager(
                new OptionsWrapper <ResourceManagementOptions>(options),
                StubFileVersionProvider.Instance
                );

            resourceManager.RegisterResource("foo", "first-resource");
            resourceManager.RegisterResource("foo", "last-resource");

            var ex = Assert.Throws <InvalidOperationException>(() => resourceManager.GetRequiredResources("foo"));

            Assert.StartsWith("Invalid dependency position", ex.Message);
        }
        public void RequireCircularNestedDependencyShouldThrowException()
        {
            var options  = new ResourceManagementOptions();
            var manifest = new ResourceManifest();

            manifest.DefineResource("foo", "requires-dependency")
            .SetDependencies("dependency");
            manifest.DefineResource("foo", "requires-indirect-dependency")
            .SetDependencies("requires-dependency");
            manifest.DefineResource("foo", "dependency")
            .SetDependencies("requires-indirect-dependency");

            options.ResourceManifests.Add(manifest);

            var resourceManager = new ResourceManager(
                new OptionsWrapper <ResourceManagementOptions>(options),
                StubFileVersionProvider.Instance
                );

            resourceManager.RegisterResource("foo", "requires-indirect-dependency");
            resourceManager.RegisterResource("foo", "requires-dependency");

            var ex = Assert.Throws <InvalidOperationException>(() => resourceManager.GetRequiredResources("foo"));

            Assert.StartsWith("Circular dependency", ex.Message);
        }
        public void RequireFirstPositionedResourceThatDependsOnByDependencyResourceShouldRegisterDependencyFirst()
        {
            var options  = new ResourceManagementOptions();
            var manifest = new ResourceManifest();

            manifest.DefineResource("foo", "dependency");
            manifest.DefineResource("foo", "first-resource")
            .SetDependencies("dependency")
            .SetPosition(ResourcePosition.First);

            options.ResourceManifests.Add(manifest);

            var resourceManager = new ResourceManager(
                new OptionsWrapper <ResourceManagementOptions>(options),
                StubFileVersionProvider.Instance
                );

            resourceManager.RegisterResource("foo", "first-resource");

            var requiredResources = resourceManager.GetRequiredResources("foo")
                                    .Select(ctx => ctx.Resource)
                                    .ToList();

            // Ensure dependencies loaded
            Assert.True(requiredResources.Count == 2);

            // Ensure order
            var dependencyIndex    = requiredResources.FindIndex(resource => resource.Name == "dependency");
            var firstResourceIndex = requiredResources.FindIndex(resource => resource.Name == "first-resource");

            Assert.True(firstResourceIndex > dependencyIndex);
        }
Example #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        static ResourceManifest CreateManifestAsset(string path)
        {
            ResourceManifest manifest = ScriptableObject.CreateInstance <ResourceManifest>();

            AssetDatabase.CreateAsset(manifest, "Assets/" + path);
            return(manifest);
        }
Example #9
0
        static ResourceManagementOptionsConfiguration()
        {
            _manifest = new ResourceManifest();

            // See https://github.com/marella/material-icons for usage
            _manifest
            .DefineStyle("material-icons")
            .SetCdn("https://fonts.googleapis.com/icon?family=Material+Icons|Material+Icons+Outlined|Material+Icons+Two+Tone|Material+Icons+Round|Material+Icons+Sharp")
            .SetUrl("~/TheAdmin/fonts/material-icons/material-icons.min.css", "~/TheAdmin/fonts/material-icons/material-icons.css")
            .SetVersion("1.10.11");

            _manifest
            .DefineScript("admin")
            .SetDependencies("jQuery")
            .SetUrl("~/TheAdmin/js/TheAdmin.min.js", "~/TheAdmin/js/TheAdmin.js")
            .SetVersion("1.0.0");

            _manifest
            .DefineScript("admin-head")
            .SetUrl("~/TheAdmin/js/TheAdmin-header.min.js", "~/TheAdmin/js/TheAdmin-header.js")
            .SetVersion("1.0.0");

            _manifest
            .DefineStyle("admin")
            .SetUrl("~/TheAdmin/css/TheAdmin.min.css", "~/TheAdmin/css/TheAdmin.css")
            .SetVersion("1.0.0");
        }
Example #10
0
        public static async Task InsertOrUpdateItem(ResourceManifest resource)
        {
            var item = await SDKProperty.SQLiteConn.FindAsync <DB.ResourceManifest>(resource.MD5);

            if (item != null && !string.IsNullOrEmpty(item.MD5))
            {
                item.State = resource.State;
                await SDKProperty.SQLiteConn.UpdateAsync(item);
            }
            else
            {
                item       = new DB.ResourceManifest();
                item.MD5   = resource.MD5;
                item.Size  = resource.Size;
                item.State = resource.State;

                try
                {
                    await SDKProperty.SQLiteConn.InsertAsync(item);
                }
                catch (Exception ex)
                {
                    SDKClient.logger.Error($"消息处理异常:error:{ex.Message},stack:{ex.StackTrace};\r\n");
                }
            }
        }
        public void BuildManifests(ResourceManifestBuilder builder)
        {
            ResourceManifest manifest = builder.Add();

            //easyui全部控件样式
            manifest.DefineStyle("Easyui").SetUrl("default/easyui.css");
            //自定义的主样式
            manifest.DefineStyle("MainSty").SetUrl("Styles.css").SetDependencies("Easyui");
            //凭证样式
            manifest.DefineStyle("voucher").SetUrl("voucher.css").SetDependencies("MainSty");

            //easyui库
            manifest.DefineScript("Easyui").SetUrl("jquery.easyui.min.js").SetDependencies("jQuery");
            //easyui中文化
            manifest.DefineScript("Easyui.cn").SetUrl("easyui-lang-zh_CN.js").SetDependencies("Easyui");
            //easyui验证方法扩展
            manifest.DefineScript("Easyui.Extend").SetUrl("easyui.extend.js").SetDependencies("Easyui");

            //企业信息相关脚本
            manifest.DefineScript("Company.App").SetUrl("App/Company.App.js").SetDependencies("Easyui.cn", "Easyui.Extend");

            //科目设置
            manifest.DefineScript("Subject.App").SetUrl("App/Subject.App.js").SetDependencies("Easyui.cn", "Easyui.Extend");

            //凭证录入、查询
            manifest.DefineScript("Voucher.App").SetUrl("App/Voucher.App.js").SetDependencies("Easyui.cn", "Easyui.Extend");
        }
        static ResourceManagerBenchmark()
        {
            var options = new ResourceManagementOptions();

            var manifest1 = new ResourceManifest();

            manifest1.DefineStyle("some1").SetDependencies("dependency1").SetUrl("file://some1.txt").SetVersion("1.0.0");
            options.ResourceManifests.Add(manifest1);

            var manifest2 = new ResourceManifest();

            manifest2.DefineStyle("some2").SetDependencies("dependency2").SetUrl("file://some2.txt").SetVersion("1.0.0");
            options.ResourceManifests.Add(manifest2);

            var dependency1 = new ResourceManifest();

            dependency1.DefineStyle("dependency1").SetUrl("file://dependency1.txt").SetVersion("1.0.0");
            options.ResourceManifests.Add(dependency1);

            var dependency2 = new ResourceManifest();

            dependency2.DefineStyle("dependency2").SetUrl("file://dependency2.txt").SetVersion("1.0.0");
            options.ResourceManifests.Add(dependency2);

            _options = new OptionsWrapper <ResourceManagementOptions>(options);
        }
Example #13
0
        static ResourceManagerBenchmark()
        {
            var manifest1 = new ResourceManifest();

            manifest1.DefineStyle("some1").SetDependencies("dependency1").SetUrl("file://some1.txt").SetVersion("1.0.0");

            var manifest2 = new ResourceManifest();

            manifest2.DefineStyle("some2").SetDependencies("dependency2").SetUrl("file://some2.txt").SetVersion("1.0.0");

            var dependency1 = new ResourceManifest();

            dependency1.DefineStyle("dependency1").SetUrl("file://dependency1.txt").SetVersion("1.0.0");

            var dependency2 = new ResourceManifest();

            dependency2.DefineStyle("dependency2").SetUrl("file://dependency2.txt").SetVersion("1.0.0");

            _resourceManifestState = new ResourceManifestState
            {
                ResourceManifests = new List <ResourceManifest>
                {
                    manifest1, manifest2, dependency1, dependency2
                }
            };
        }
        static ResourceManagementOptionsConfiguration()
        {
            manifest = new ResourceManifest();

            manifest
            .DefineScript("ZachsBlogTheme-vendor-jQuery")
            .SetUrl("~/ZachsBlogTheme/vendor/jquery/jquery.min.js", "~/ZachsBlogTheme/vendor/jquery/jquery.js")
            .SetCdn("https://code.jquery.com/jquery-3.4.1.min.js", "https://code.jquery.com/jquery-3.4.1.js")
            .SetCdnIntegrity("sha384-vk5WoKIaW/vJyUAd9n/wmopsmNhiy+L2Z+SBxGYnUkunIxVxAv/UtMOhba/xskxh", "sha384-mlceH9HlqLp7GMKHrj5Ara1+LvdTZVMx4S1U43/NxCvAkzIo8WJ0FE7duLel3wVo")
            .SetVersion("3.4.1");

            manifest
            .DefineScript("ZachsBlogTheme-vendor-jQuery.slim")
            .SetUrl("~/ZachsBlogTheme/vendor/jquery/jquery.slim.min.js", "~/ZachsBlogTheme/vendor/jquery/jquery.slim.js")
            .SetCdn("https://code.jquery.com/jquery-3.4.1.slim.min.js", "https://code.jquery.com/jquery-3.4.1.slim.js")
            .SetCdnIntegrity("sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n", "sha384-teRaFq/YbXOM/9FZ1qTavgUgTagWUPsk6xapwcjkrkBHoWvKdZZuAeV8hhaykl+G")
            .SetVersion("3.4.1");

            manifest
            .DefineScript("ZachsBlogTheme-vendor-bootstrap")
            .SetDependencies("ZachsBlogTheme-vendor-jQuery")
            .SetUrl("~/ZachsBlogTheme/vendor/bootstrap/js/bootstrap.min.js", "~/ZachsBlogTheme/vendor/bootstrap/js/bootstrap.js")
            .SetCdn("https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js", "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.js")
            .SetCdnIntegrity("sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM", "sha384-rkSGcquOAzh5YMplX4tcXMuXXwmdF/9eRLkw/gNZG+1zYutPej7fxyVLiOgfoDgi")
            .SetVersion("4.3.1");

            manifest
            .DefineScript("ZachsBlogTheme-vendor-bootstrap-bundle")
            .SetDependencies("ZachsBlogTheme-vendor-jQuery")
            .SetUrl("~/ZachsBlogTheme/vendor/bootstrap/js/bootstrap.bundle.min.js", "~/ZachsBlogTheme/vendor/bootstrap/js/bootstrap.bundle.js")
            .SetCdn("https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js", "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.js")
            .SetCdnIntegrity("sha384-xrRywqdh3PHs8keKZN+8zzc5TX0GRTLCcmivcbNJWm2rs5C8PRhcEn3czEjhAO9o", "sha384-szbKYgPl66wivXHlSpJF+CKDAVckMVnlGrP25Sndhe+PwOBcXV9LlFh4MUpRhjIB")
            .SetVersion("4.3.1");

            manifest
            .DefineStyle("ZachsBlogTheme-vendor-bootstrap")
            .SetUrl("~/ZachsBlogTheme/vendor/bootstrap/css/bootstrap.min.css", "~/ZachsBlogTheme/vendor/bootstrap/css/bootstrap.css")
            .SetCdn("https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css", "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.css")
            .SetCdnIntegrity("sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T", "sha384-t4IGnnWtvYimgcRMiXD2ZD04g28Is9vYsVaHo5LcWWJkoQGmMwGg+QS0mYlhbVv3")
            .SetVersion("4.3.1");

            manifest
            .DefineStyle("ZachsBlogTheme-bootstrap-oc")
            .SetUrl("~/ZachsBlogTheme/css/bootstrap-oc.min.css", "~/ZachsBlogTheme/css/bootstrap-oc.css")
            .SetVersion("1.0.0");

            manifest
            .DefineStyle("ZachsBlogTheme-vendor-font-awesome")
            .SetUrl("~/ZachsBlogTheme/vendor/fontawesome-free/css/all.min.css", "~/ZachsBlogTheme/vendor/fontawesome-free/css/all.css")
            .SetCdn("https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/all.min.css", "https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/all.css")
            .SetCdnIntegrity("sha384-rtJEYb85SiYWgfpCr0jn174XgJTn4rptSOQsMroFBPQSGLdOC5IbubP6lJ35qoM9", "sha384-Ex0vLvgbKZTFlqEetkjk2iUgM+H5udpQKFKjBoGFwPaHRGhiWyVI6jLz/3fBm5ht")
            .SetVersion("5.10.2");

            manifest
            .DefineScript("ZachsBlogTheme-vendor-font-awesome")
            .SetCdn("https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/js/all.min.js", "https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/js/all.js")
            .SetCdnIntegrity("sha384-QMu+Y+eu45Nfr9fmFOlw8EqjiUreChmoQ7k7C1pFNO8hEbGv9yzsszTmz+RzwyCh", "sha384-7/I8Wc+TVwiZpEjE4qTV6M27LYR5Dus6yPGzQZowRtgh+0gDW9BNR9GmII1/YwmG")
            .SetVersion("5.10.2");
        }
Example #15
0
        static ResourceManagementOptionsConfiguration()
        {
            _manifest = new ResourceManifest();

            _manifest
            .DefineStyle("SamwiseTheme-bootstrap-oc")
            .SetUrl("~/SamwiseTheme/css/bootstrap-oc.min.css", "~/SamwiseTheme/css/bootstrap-oc.css")
            .SetVersion("1.0.0");
        }
Example #16
0
        public ResourceDefinition(ResourceManifest manifest, string type, string name)
        {
            Manifest = manifest;
            Type = type;
            Name = name;

            TagName = _resourceTypeTagNames.ContainsKey(Type) ? _resourceTypeTagNames[Type] : "meta";
            FilePathAttributeName = _filePathAttributes.ContainsKey(TagName) ? _filePathAttributes[TagName] : null;
            TagRenderMode = _fileTagRenderModes.ContainsKey(TagName) ? _fileTagRenderModes[TagName] : TagRenderMode.Normal;
        }
        public async Task RenderFootScript()
        {
            var options  = new ResourceManagementOptions();
            var manifest = new ResourceManifest();

            manifest.DefineScript("required").SetUrl("required.js")
            .SetDependencies("dependency");
            manifest.DefineScript("dependency").SetUrl("dependency.js");
            manifest.DefineScript("not-required").SetUrl("not-required.js");

            options.ResourceManifests.Add(manifest);

            var resourceManager = new ResourceManager(
                new OptionsWrapper <ResourceManagementOptions>(options),
                StubFileVersionProvider.Instance
                );

            // Require resource
            resourceManager.RegisterResource("script", "required").AtFoot();

            // Register custom script
            var customScript = "doSomeAction();";

            resourceManager.RegisterFootScript(new HtmlString($"<script>{customScript}</script>"));

            using var sw = new StringWriter();
            resourceManager.RenderFootScript(sw);
            var htmlBuilder = new HtmlContentBuilder();

            htmlBuilder.AppendHtml(sw.ToString());

            var document = await ParseHtmlAsync(htmlBuilder);

            var scripts = document
                          .QuerySelectorAll <IHtmlScriptElement>("script");

            Assert.Equal(3, scripts.Count());
            Assert.Contains(scripts, script => script.Source == "dependency.js");
            Assert.Contains(scripts, script => script.Source == "required.js");
            Assert.Contains(scripts, script => script.Text == customScript);
            // Required script after its dependency
            Assert.Equal(DocumentPositions.Following, scripts.First(script => script.Source == "dependency.js")
                         .CompareDocumentPosition(
                             scripts.First(script => script.Source == "required.js")
                             )
                         );
            // Custom script after resources
            Assert.Equal(DocumentPositions.Following, scripts.First(script => script.Source == "required.js")
                         .CompareDocumentPosition(
                             scripts.First(script => script.Text == customScript)
                             )
                         );
        }
Example #18
0
        public void FillRequiredContext(string name, string url, string culture = "", string condition = "", Dictionary <string, string> attributes = null)
        {
            var requiredContext  = new ResourceRequiredContext();
            var resourceManifest = new ResourceManifest();

            requiredContext.Resource = resourceManifest.DefineResource(Type.ToStringType(), name);
            requiredContext.Resource.SetUrl(url);
            requiredContext.Settings            = new RequireSettings();
            requiredContext.Settings.Culture    = culture;
            requiredContext.Settings.Condition  = condition;
            requiredContext.Settings.Attributes = attributes != null ? new Dictionary <string, string>(attributes) : new Dictionary <string, string>();
            RequiredContext = requiredContext;
        }
Example #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="manifestPath"></param>
        /// <param name="assetPath"></param>
        /// <param name="safetyChecks"></param>
        static void RecordAsset(string manifestPath, string path, string file, Type type, UnityEngine.Object obj, Dictionary <string, ResourceManifest> map, List <ResourceManifest> list, bool safetyChecks)
        {
            //We use this for the manifest rather than 'file' because
            //we can't determine the other one at runtime due to the use
            //of AssetDatabase. This only requires the object's name.
            string manifestName = ResourceManifest.GetManifestName(obj.name);


            //obtain the manifest that stores all resources with this name
            ResourceManifest manifest = null;

            map.TryGetValue(manifestName, out manifest);
            if (manifest == null)
            {
                try { manifest = CreateManifestAsset(manifestPath + manifestName + ".asset"); }
#pragma warning disable 0168
                catch (Exception e)
                {
                    Debug.Log("<color=red>Failed to create asset: " + manifestName + "</color>");
                    return;
                }
#pragma warning restore 0168
                if (manifest == null)
                {
                    Debug.Log("<color=red>Failed to create asset: " + manifestName + "</color>");
                    return;
                }
                map.Add(manifestName, manifest);
                list.Add(manifest);
            }

            //are we going to look for repeat paths to
            //different resources of the same type? (slow but safe)
            string fullPath = path + file;

            if (safetyChecks)
            {
                if (SafetyCheck(manifest, fullPath, type))
                {
                    manifest.AddResource(obj, fullPath);
                }
                else
                {
                    Debug.Log("<color=red>WARNING:</color>There are multiple resources of the type '" + type.Name + "' that are being compiled to the path 'Resources/" + fullPath + "'.\nThe manifest cannot determine which object this path should point to so only the first occurance has been stored.\nPlease ensure all resources of the same type and at the same directory level relative to 'Resources/' have unique names.");
                }
            }
            else
            {
                manifest.AddResource(obj, fullPath);
            }
        }
Example #20
0
        public void DefineAspNetMvc(ResourceManifest manifest, string kety, string currentVersion, params string[] previousVersions)
        {
            var versions = new List <string>(previousVersions)
            {
                currentVersion
            };

            foreach (var version in versions)
            {
                manifest.DefineScript("kendo.aspnetmvc")
                .SetUrl(VersionPath(version, "kendo.aspnetmvc.min.js"))
                .SetDependencies(keyPrefix);
            }
        }
        static ResourceManagementOptionsConfiguration()
        {
            _manifest = new ResourceManifest();

            _manifest
            .DefineScript("monaco-liquid-intellisense")
            .SetUrl("~/OrchardCore.Liquid/monaco/liquid-intellisense.js")
            .SetDependencies("monaco")
            .SetVersion("1.0.0");

            _manifest
            .DefineScript("liquid-intellisense")
            .SetDependencies("monaco-liquid-intellisense")
            .SetUrl("~/OrchardCore.Liquid/Scripts/liquid-intellisense.js");
        }
Example #22
0
        /// <summary>
        /// Helper method that attempts to store the object as a string to a runtime
        /// resource that can be loaded with <see cref="Resources.Load()"/>. Only
        /// types that are supported by the resource manifest system will be considered.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="info"></param>
        /// <param name="context"></param>
        /// <returns><c>true</c> if the object was added to the SerializationInfo as a rsource string, <c>false</c> otherwise.</returns>
        protected static bool SerializeAsResource(object obj, SerializationInfo info, StreamingContext context)
        {
            if (obj == null)
            {
                return(false);
            }
            var sc = context.Context as XmlSerializer.SerializeContext;


            //let's see if this is a unity resource that can be stored as just a string
            Type objType = obj.GetType();

            for (int i = 0; i < Constants.ResourceTypes.Length; i++)
            {
                if (objType == Constants.ResourceTypes[i])
                {
                    UnityEngine.Object uo = obj as UnityEngine.Object;

                    //before we check the manifests, see if this object exists in the BuiltinResources list
                    int uId = SerializerBase.UnityResources.Resources.IndexOf(uo);
                    if (uId >= 0)
                    {
                        //we have a unity, builtin resource, we need to serialize a slightly different way.
                        sc.Element.SetAttribute("BuiltinId", uId.ToString());
                    }

                    //try to serialize this as a runtime
                    //resource path if it exists in a manifest
                    string manifestFile = "Manifests/" + ResourceManifest.GetManifestName(uo.name);

                    var manifest = Resources.Load(manifestFile, typeof(ResourceManifest)) as ResourceManifest;
                    if (manifest != null)
                    {
                        string path = manifest.GetPathToResource(uo);
                        if (!string.IsNullOrEmpty(path))
                        {
                            //Make it an attribute rather than a node.
                            //That way we can identify if it was serialized
                            //in-place or not during deserialization.
                            sc.Element.SetAttribute("ResourcePath", path);
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Example #23
0
        /// <summary>
        /// Helper method to perform a safety check that ensures us we won't accidentally
        /// create two resources of the same type with the same name that result in the same
        /// path when the Resources folders are compiled for a runtime player.
        /// </summary>
        /// <param name="manifest"></param>
        /// <param name="path"></param>
        /// <returns><c>false if the 'Resources' relative path already exists within the manifest</c></returns>
        static bool SafetyCheck(ResourceManifest manifest, string path, Type type)
        {
            foreach (string val in manifest.AllPaths())
            {
                if (path == val)
                {
                    //TODO: We need a faster way of doing this. Large projects
                    //will suffer a lot in this section, I suspect.
                    //THIS CAN BE SUPER SLOW
                    if (manifest.GetResourceFromPath(path, type) != null)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        static ResourceManagementOptionsConfiguration()
        {
            _manifest = new ResourceManifest();

            _manifest
            .DefineScript("leaflet")
            .SetUrl("/OrchardCore.Spatial/Scripts/leaflet/leaflet.js", "/OrchardCore.Spatial/Scripts/leaflet/leaflet-src.js")
            .SetCdn("https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.min.js", "https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet-src.js")
            .SetCdnIntegrity("sha384-vdvDM6Rl/coCrMsKwhal4uc9MUUFNrYa+cxp+nJQHy3TvozEpVKVexz/NTbE5VSO", "sha384-mc6rNK5V0bzWGJ1EUEAR2o+a/oH6qaVl+NCF63Et+mVpGnlSnyVSBhSP/wp4ir+O")
            .SetVersion("1.7.1");

            _manifest
            .DefineStyle("leaflet")
            .SetUrl("/OrchardCore.Spatial/Styles/leaflet.min.css", "/OrchardCore.Spatial/Styles/leaflet.css")
            .SetCdn("https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.min.css", "https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.css")
            .SetCdnIntegrity("sha384-d7pQbIswLsqVbYoAoHHlzPt+fmjkMwiXW/fvtIgK2r1u1bZXvGzL9HICUg4DKSgO", "sha384-VzLXTJGPSyTLX6d96AxgkKvE/LRb7ECGyTxuwtpjHnVWVZs2gp5RDjeM/tgBnVdM")
            .SetVersion("1.7.1");
        }
        static ResourceManagementOptionsConfiguration()
        {
            _manifest = new ResourceManifest();

            _manifest
            .DefineScript("jsplumb")
            .SetDependencies("jQuery")
            .SetUrl("~/OrchardCore.Workflows/Scripts/jsplumb.min.js", "~/OrchardCore.Workflows/Scripts/jsplumb.js")
            .SetCdn("https://cdnjs.cloudflare.com/ajax/libs/jsPlumb/2.15.5/js/jsplumb.min.js", "https://cdnjs.cloudflare.com/ajax/libs/jsPlumb/2.15.5/js/jsplumb.js")
            .SetCdnIntegrity("sha384-vJ4MOlEjImsRl4La5sTXZ1UBtJ8uOOqxl2+0gdjRB7oVF6AvTVZ3woqYbTJb7vaf", "sha384-6qcVETlKUuSEc/QpsceL6BNiyEMBFSPE/uyfdRUvEfao8/K9lynY+r8nd/mwLGGh")
            .SetVersion("2.15.5");

            _manifest
            .DefineStyle("jsplumbtoolkit-defaults")
            .SetUrl("~/OrchardCore.Workflows/Styles/jsplumbtoolkit-defaults.min.css", "~/OrchardCore.Workflows/Styles/jsplumbtoolkit-defaults.css")
            .SetCdn("https://cdnjs.cloudflare.com/ajax/libs/jsPlumb/2.15.5/css/jsplumbtoolkit-defaults.min.css", "https://cdnjs.cloudflare.com/ajax/libs/jsPlumb/2.15.5/css/jsplumbtoolkit-defaults.css")
            .SetCdnIntegrity("sha384-4TTNOHwtAFYbq+UTSu/7Fj0xnqOabg7FYr9DkNtEKnmIx/YaACNiwhd2XZfO0A/u", "sha384-Q0wOomiqdBpz2z6/yYA8b3gc8A9t7z7QjD14d1WABvXVHbRYBu/IGOv3SOR57anB")
            .SetVersion("2.15.5");
        }
Example #26
0
        public RenderFragment RenderLink()
        {
            void Fragment(RenderTreeBuilder builder)
            {
                int seq = -1;

                builder.OpenComponent <TriggerWrapper>(++seq);
                builder.AddAttribute(++seq, "Trigger", _update);

                if (Manifests != null)
                {
                    builder.AddAttribute(++seq, "ChildContent", (RenderFragment)(builder2 => builder2.AddContent(
                                                                                     ++seq,
                                                                                     ResourceManifest.RenderStylesheets(
                                                                                         Manifests,
                                                                                         new Dictionary <string, string>
                    {
                        { "ThemeVariant", Variant ! },
                    }
                                                                                         ))));
                }
Example #27
0
        public void DefineCultureSet(ResourceManifest manifest, string version)
        {
            string cultureKey  = string.Format(KeyFormat, "kendo.culture", "site");
            string messagesKey = string.Format(KeyFormat, "kendo.messages", "site");

            string siteCultureFilePath  = string.Format("cultures/kendo.culture.{0}.min.js", this.kendoThemeService.SiteCulture());
            string siteMessagesFilePath = string.Format("messages/kendo.messages.{0}.min.js", this.kendoThemeService.SiteCulture());

            manifest.DefineScript(cultureKey)
            .SetUrl(VersionPath(version, siteCultureFilePath))
            .SetDependencies(keyPrefix)
            .SetVersion(version);

            manifest.DefineScript(messagesKey)
            .SetUrl(VersionPath(version, siteMessagesFilePath))
            .SetDependencies(keyPrefix)
            .SetVersion(version);

            foreach (var culture in cultureSets)
            {
                string key      = string.Format(KeyFormat, "kendo.culture", culture);
                string filePath = string.Format("cultures/{0}.min.js", key);

                manifest.DefineScript(key)
                .SetUrl(VersionPath(version, filePath))
                .SetDependencies(keyPrefix)
                .SetVersion(version);
            }

            foreach (var culture in cultureSets)
            {
                string key      = string.Format(KeyFormat, "kendo.messages", culture);
                string filePath = string.Format("messages/{0}.min.js", key);

                manifest.DefineScript(key)
                .SetUrl(VersionPath(version, filePath))
                .SetDependencies(keyPrefix)
                .SetVersion(version);
            }
        }
        public async Task RenderLocalScript()
        {
            var options  = new ResourceManagementOptions();
            var manifest = new ResourceManifest();

            manifest.DefineScript("required").SetUrl("required.js")
            .SetDependencies("dependency");
            manifest.DefineScript("dependency").SetUrl("dependency.js");
            manifest.DefineScript("not-required").SetUrl("not-required.js");

            options.ResourceManifests.Add(manifest);

            var resourceManager = new ResourceManager(
                new OptionsWrapper <ResourceManagementOptions>(options),
                StubFileVersionProvider.Instance
                );

            var requireSetting = resourceManager.RegisterResource("script", "required");

            using var sw = new StringWriter();
            resourceManager.RenderLocalScript(requireSetting, sw);
            var htmlBuilder = new HtmlContentBuilder();

            htmlBuilder.AppendHtml(sw.ToString());


            var document = await ParseHtmlAsync(htmlBuilder);

            var scripts = document
                          .QuerySelectorAll <IHtmlScriptElement>("script");

            Assert.Equal(2, scripts.Count());
            Assert.Contains(scripts, script => script.Source == "dependency.js");
            Assert.Contains(scripts, script => script.Source == "required.js");
            Assert.Equal(DocumentPositions.Following, scripts.First(script => script.Source == "dependency.js")
                         .CompareDocumentPosition(
                             scripts.First(script => script.Source == "required.js")
                             )
                         );
        }
Example #29
0
        static ResourceManagementOptionsConfiguration()
        {
            _manifest = new ResourceManifest();

            _manifest
            .DefineScript("vuejs")
            .SetUrl("~/VuetifyTheme/Scripts/vue.min.js", "~/VuetifyTheme/Scripts/vue.js")
            .SetCdn("https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js", "https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js")
            .SetCdnIntegrity("sha384-ULpZhk1pvhc/UK5ktA9kwb2guy9ovNSTyxPNHANnA35YjBQgdwI+AhLkixDvdlw4", "sha384-t1tHLsbM7bYMJCXlhr0//00jSs7ZhsAhxgm191xFsyzvieTMCbUWKMhFg9I6ci8q")
            .SetVersion("2.6.14");

            _manifest
            .DefineStyle("vuetify-theme")
            .SetDependencies("vuejs")
            .SetUrl("~/VuetifyTheme/dist/vuetify-theme.css", "~/VuetifyTheme/dist/vuetify-theme.css")
            .SetVersion("1.0.0");
            _manifest
            .DefineScript("vuetify-theme")
            .SetDependencies("vuejs")
            .SetUrl("~/VuetifyTheme/dist/vuetify-theme.umd.min.js", "~/VuetifyTheme/dist/vuetify-theme.umd.js")
            .SetVersion("1.0.0");
        }
Example #30
0
        private static void RemoveResourceOnManifest(string res_id)
        {
            string           pak          = resourcePakMap[res_id];
            ResourceManifest res_manifest = resourceManifestMap[res_id];

            switch (res_manifest)
            {
            case ImageManifest _:
                manifest.Content[pak].Images.Remove(res_id);
                break;

            case ShaderManifest _:
                manifest.Content[pak].Shaders.Remove(res_id);
                break;

            case FontManifest _:
                manifest.Content[pak].Fonts.Remove(res_id);
                break;

            case EffectManifest _:
                manifest.Content[pak].Effects.Remove(res_id);
                break;

            case SongManifest _:
                manifest.Content[pak].Songs.Remove(res_id);
                break;

            case TextFileManifest _:
                manifest.Content[pak].TextFiles.Remove(res_id);
                break;
            }

            SaveContentManifest();

            FillContentMapsFromCurrentManifest();
        }
Example #31
0
        public void FillRequiredContext(string name, string url, string culture = "", string condition = "", Dictionary <string, string> attributes = null, IDictionary <string, string> tagAttributes = null)
        {
            var requiredContext  = new ResourceRequiredContext();
            var resourceManifest = new ResourceManifest();

            requiredContext.Resource = resourceManifest.DefineResource(Type.ToStringType(), name);
            if (!string.IsNullOrEmpty(url))
            {
                requiredContext.Resource.SetUrl(url);
            }
            requiredContext.Settings = new RequireSettings
            {
                Name       = name,
                Culture    = culture,
                Condition  = condition,
                Attributes = attributes != null ? new Dictionary <string, string>(attributes) : new Dictionary <string, string>()
            };
            RequiredContext = requiredContext;

            if (tagAttributes != null)
            {
                requiredContext.Resource.TagBuilder.MergeAttributes(tagAttributes);
            }
        }
 public ResourceManifest Add(ResourceManifest manifest)
 {
     ResourceManifests.Add(manifest);
     return manifest;
 }
Example #33
0
 public void prepareResourceList(StoredVessel sv)
 {
     if(resourceTransferList.Count > 0) return;
     foreach(var r in sv.resources.resourcesNames)
     {
         if(hangarResources.ResourceCapacity(r) == 0) continue;
         ResourceManifest rm = new ResourceManifest();
         rm.name          = r;
         rm.amount        = sv.resources.ResourceAmount(r);
         rm.capacity      = sv.resources.ResourceCapacity(r);
         rm.offset        = rm.amount;
         rm.host_amount   = hangarResources.ResourceAmount(r);
         rm.host_capacity = hangarResources.ResourceCapacity(r);
         rm.pool          = rm.host_amount + rm.offset;
         rm.minAmount     = Math.Max(0, rm.pool-rm.host_capacity);
         rm.maxAmount     = Math.Min(rm.pool, rm.capacity);
         resourceTransferList.Add(rm);
     }
 }