コード例 #1
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            SettingHelper settingHelper        = new SettingHelper(_memoryCache);
            bool          adminSidebarCollapse = settingHelper.GetCachedSettingBoolValue(SettingKeys.AdminSidebar);

            TempData["sidebarCollapse"] = adminSidebarCollapse ? "is-open" : string.Empty;
            return(await Task.FromResult <IViewComponentResult>(Content(string.Empty)));
        }
コード例 #2
0
        private async Task MinifyAssets(string pageName)
        {
            string        role           = UsersRoles;
            SettingHelper settingHelper  = new SettingHelper(_cache);
            string        fileName       = role.Replace(" ", "_") + "_" + pageName;
            string        headerCSS      = "css_" + fileName;
            string        headerJS       = "jsHeader_" + fileName;
            string        footerJS       = "jsFooter_" + fileName;
            string        rootPath       = _env.WebRootPath;
            string        cssLink        = string.Empty;
            string        jsScriptHeader = string.Empty;
            string        jsScriptFooter = string.Empty;
            bool          optimizeAssets = settingHelper.GetCachedSettingBoolValue(SettingKeys.OptimizeAssets);

            if (optimizeAssets)
            {
                string           optimizecssFilePath   = ShorternPath(Path.Combine(FolderName.Optimize, headerCSS + cssExtension));
                string           optimizeJsTopFilePath = ShorternPath(Path.Combine(FolderName.Optimize, headerJS + jsExtension));
                string           optimizeJsFilePath    = ShorternPath(Path.Combine(FolderName.Optimize, footerJS + jsExtension));
                BundleController bundleController      = new BundleController();
                if (File.Exists(Path.Combine(_env.WebRootPath, optimizecssFilePath)))
                {
                    AssetCollection assetCollection = await bundleController.GetAssetCollection(pageName, role);

                    cssLink        = assetCollection.CssLink;
                    jsScriptHeader = assetCollection.JSHeaderLink;
                    jsScriptFooter = assetCollection.JSFooterLink;
                }
                else
                {
                    if (excessMode == ExcessModes.local)
                    {
                        DeleteFile(optimizecssFilePath);
                        DeleteFile(optimizeJsTopFilePath);
                        DeleteFile(optimizeJsFilePath);
                    }
                    if (!Directory.Exists(Path.Combine(rootPath, FolderName.Optimize)))
                    {
                        Directory.CreateDirectory(Path.Combine(rootPath, FolderName.Optimize));
                    }
                    AssetResult assetResult = await GetFileList(pageName, role);

                    Task <bool> bundlejsTop       = BundleAsset(optimizeJsTopFilePath, assetResult.JSHeader, AssetType.Js);
                    Task <bool> bundlejsFooterTop = BundleAsset(optimizeJsFilePath, assetResult.JSFooter, AssetType.Js);
                    Task <bool> bundleCss         = BundleAsset(optimizecssFilePath, assetResult.CSS, AssetType.Css);
                    await Task.WhenAll(bundlejsTop, bundlejsFooterTop, bundleCss);

                    jsScriptHeader  = assetResult.JsHeaderCDN;
                    jsScriptHeader += string.Format("<script  src='{0}'></script>", _hostURL + "/" + optimizeJsTopFilePath.Replace("\\", "/"));
                    jsScriptFooter  = assetResult.JsFooterTopCDN;
                    jsScriptFooter += string.Format("<script  src='{0}'></script>", _hostURL + "/" + optimizeJsFilePath.Replace("\\", "/"));
                    jsScriptFooter += assetResult.JsFooterBottomCDN;
                    cssLink         = assetResult.CssCDN;
                    cssLink        += string.Format("<link href='{0}' rel='stylesheet' type='text/css' />", _hostURL + "/" + optimizecssFilePath.Replace("\\", "/"));

                    AssetCollection assetCollection = new AssetCollection()
                    {
                        PageName     = pageName,
                        RoleName     = role,
                        CssLink      = cssLink,
                        JSHeaderLink = jsScriptHeader,
                        JSFooterLink = jsScriptFooter,
                        Name         = string.Empty
                    };
                    await bundleController.SaveAssetCollection(assetCollection);
                }
            }
            else
            {
                AssetResult assetCollection = await GetFileList(pageName, role);

                jsScriptHeader = assetCollection.JsHeaderCDN + CombineLinks(assetCollection.JSHeader, AssetType.Js);
                jsScriptFooter = assetCollection.JsFooterTopCDN + CombineLinks(assetCollection.JSFooter, AssetType.Js) + assetCollection.JsFooterBottomCDN;
                cssLink        = assetCollection.CssCDN + CombineLinks(assetCollection.CSS, AssetType.Css);
            }
            TempData["cssHeader"] = cssLink;
            TempData["jsHeader"]  = jsScriptHeader;
            TempData["jsFooter"]  = jsScriptFooter;
        }