public static string FileContent(this WebPageExecutingBase page, string fileVirtualPath, bool localize = true) { var pageFolder = HttpContext.Current.Server.MapPath(page.VirtualPath); var filePath = Path.Combine( Path.GetDirectoryName(pageFolder), fileVirtualPath); var result = File.ReadAllText(filePath); if (localize) { var regex = new Regex(@"@this.Localize\(""([^""]+)""\)"); result = regex.Replace(result, match => { if (match.Groups.Count > 1) { var localized = Localize(page, match.Groups[1].Value); return(localized); } else { return(match.Groups[0].Value); } }); } return(result); }
public static MvcHtmlString T(this WebPageExecutingBase view, string textName, params object[] formatterArguments) { var translated = GetLocalizedText(view.VirtualPath, textName); return(MvcHtmlString.Create(formatterArguments.Length == 0 ? translated : string.Format(translated, formatterArguments))); }
private static string GetBundlePathForAreaView(this WebPageExecutingBase view, string areaName) { var viewName = Path.GetFileNameWithoutExtension(view.VirtualPath); var bundleName = GetBundleNameForAreaView(view.VirtualPath, viewName, areaName); return(String.Format("{0}{1}{2}", ViewBundleRegistrar.BUNDLE_NAME_AREA_VIEW_PREFIX, areaName.ToLowerInvariant(), bundleName)); }
public static string AppVirtualPath(this WebPageExecutingBase page) { string path = page.Href("~/"); if (!path.EndsWith("/")) { path += "/"; } return(path); }
public static MvcHtmlString RenderCommonMetas(this HtmlHelper html, WebPageExecutingBase page, string keywordsResourceKey = "SeoKeywords", string descriptionResourceKey = "SeoDescription", string robotsContent = "index, follow") { var htmlText = @"{0}{1}{2}".FormatWith( html.RenderKeywords(page.Localize(keywordsResourceKey)), html.RenderDescription(page.Localize(descriptionResourceKey)), html.RenderRobots(robotsContent)); return(new MvcHtmlString(htmlText)); }
public static string Localize(this WebPageExecutingBase page, string resourceKey, string defaultValue = null) { #region Precompiled return(CompiledResources.GetResourceManager(page.VirtualPath).GetString(resourceKey)); #endregion #region Not precompiled var localResourceObject = HttpContext.GetLocalResourceObject(page.VirtualPath, resourceKey); if (localResourceObject != null) { return(localResourceObject.ToString()); } else { return(defaultValue ?? resourceKey); } #endregion }
public static void DisableInstrumentation(this WebPageExecutingBase page) { _isAvailableProperty.SetValue(_instrumentationService.GetValue(page), false); }
public static string Localize(this HtmlHelper html, WebPageExecutingBase page, string resourceKey, string defaultValue = null) { return(page.Localize(resourceKey, defaultValue)); }
public static Tdict Dictionary <Tdict>(this WebPageExecutingBase page, CultureInfo culture = null) where Tdict : DictionaryBase { return(CodeFirstManager.Current?.Modules?.DictionaryModule?.GetDictionary <Tdict>(culture)); }