protected void btnImport_Click(object sender, EventArgs e) { #if OnlineDemo this.ErrorDisplay.ShowError(WebUtils.LRes("FeatureDisabled")); return; #endif DbResXConverter Converter = new DbResXConverter(Context.Request.PhysicalApplicationPath); bool res = false; if (DbResourceConfiguration.Current.ResxExportProjectType == GlobalizationResxExportProjectTypes.WebForms) { res = Converter.ImportWebResources(); } else { res = Converter.ImportWinResources(Server.MapPath("~/")); } if (res) { ErrorDisplay.ShowMessage(WebUtils.LRes("ResourceImportComplete")); } else { ErrorDisplay.ShowError(WebUtils.LRes("ResourceImportFailed")); } lstResourceIds.ClearSelection(); lstResourceSet.ClearSelection(); GetResourceSet(); }
public bool ImportResxResources(string inputBasePath = null) { #if OnlineDemo throw new ApplicationException(WebUtils.GRes("FeatureDisabled")); #endif if (string.IsNullOrEmpty(inputBasePath)) inputBasePath = DbResourceConfiguration.Current.ResxBaseFolder; if (inputBasePath.Contains("~")) inputBasePath = Request.MapPath(inputBasePath,basePath: Host.ContentRootPath); inputBasePath = DbResourceUtils.NormalizePath(inputBasePath); DbResXConverter converter = new DbResXConverter(inputBasePath); bool res = false; if (DbResourceConfiguration.Current.ResxExportProjectType == GlobalizationResxExportProjectTypes.WebForms) res = converter.ImportWebResources(inputBasePath); else res = converter.ImportWinResources(inputBasePath); if (!res) new ApplicationException(DbIRes.T("ResourceImportFailed", STR_RESOURCESET)); return true; }
protected void btnExportResources_Click(object sender, EventArgs e) { #if OnlineDemo this.ErrorDisplay.ShowError(WebUtils.LRes("FeatureDisabled")); return; #endif DbResXConverter Exporter = new DbResXConverter(Context.Request.PhysicalApplicationPath); if (DbResourceConfiguration.Current.ResxExportProjectType == GlobalizationResxExportProjectTypes.WebForms) { if (!Exporter.GenerateLocalWebResourceResXFiles()) { ErrorDisplay.ShowError(WebUtils.LRes("ResourceGenerationFailed")); return; } if (!Exporter.GenerateGlobalWebResourceResXFiles()) { ErrorDisplay.ShowError(WebUtils.LRes("ResourceGenerationFailed")); return; } } else { if (!Exporter.GenerateResXFiles()) { ErrorDisplay.ShowError(WebUtils.LRes("ResourceGenerationFailed")); return; } } ErrorDisplay.ShowMessage(WebUtils.LRes("ResourceGenerationComplete")); }
public bool ImportResxResources(string inputBasePath = null) { #if OnlineDemo throw new WestwindException("Feature disabled"); #endif if (string.IsNullOrEmpty(inputBasePath)) { inputBasePath = configuration.ResxBaseFolder; } if (inputBasePath.Contains("~")) { inputBasePath = hostingEnvironment.MapPath(inputBasePath); } var converter = new DbResXConverter(configuration, inputBasePath); var res = false; res = converter.ImportWinResources(inputBasePath); if (!res) { throw new WestwindException("Resource import failed"); } return(true); }
public bool ExportResxResources([FromBody] dynamic parms) { #if OnlineDemo throw new ApplicationException(WebUtils.GRes("FeatureDisabled")); #endif // Post: {outputBasePath: "~\Properties", resourceSets: ["rs1","rs2"] } string outputBasePath = parms["outputBasePath"]; string[] resourceSets = null; JArray t = parms["resourceSets"] as JArray; if (t != null) { resourceSets = t.ToObject<string[]>(); if (resourceSets != null && resourceSets.Length == 1 && string.IsNullOrEmpty(resourceSets[0])) resourceSets = null; } if (string.IsNullOrEmpty(outputBasePath)) outputBasePath = DbResourceConfiguration.Current.ResxBaseFolder; if (outputBasePath.StartsWith("~")) outputBasePath = Request.MapPath(outputBasePath, basePath: Host.ContentRootPath ); outputBasePath = FileUtils.NormalizePath(outputBasePath); DbResXConverter exporter = new DbResXConverter(outputBasePath); // if resourceSets is null all resources are generated if (!exporter.GenerateResXFiles(resourceSets)) throw new ApplicationException(DbIRes.T("ResourceGenerationFailed", STR_RESOURCESET)); return true; }
public void GetResXResourcesTest() { DbResXConverter converter = new DbResXConverter(null); Dictionary <string, object> items = converter.GetResXResourcesNormalizedForLocale(@"C:\projects2008\Westwind.GlobalizationWeb\App_GlobalResources\resources", "de-de"); this.WriteResourceDictionary(items, "ResX Resources"); }
public void GetResXResourcesTest() { string path = @"c:\temp\resources"; DbResXConverter converter = new DbResXConverter(path); Dictionary<string, object> items = converter.GetResXResourcesNormalizedForLocale(@"C:\Temp\Westwind.Globalizations\Westwind.Globalization.Sample\LocalizationAdmin\App_LocalResources\LocalizationAdmin.aspx", "de-de"); WriteResourceDictionary(items,"ResX Resources"); }
public void GetResXResourcesTest() { string path = @"c:\temp\resources"; DbResXConverter converter = new DbResXConverter(configuration, path); Dictionary <string, object> items = converter.GetResXResourcesNormalizedForLocale(@"C:\Temp\Westwind.Globalizations\Westwind.Globalization.Sample\LocalizationAdmin\App_LocalResources\LocalizationAdmin.aspx", "de-de"); WriteResourceDictionary(items, "ResX Resources"); }
public bool ExportResxResources(dynamic parms) { #if OnlineDemo throw new ApplicationException(WebUtils.GRes("FeatureDisabled")); #endif // Post: {outputBasePath: "~\Properties", resourceSets: ["rs1","rs2"] } string outputBasePath = parms["outputBasePath"]; string[] resourceSets = null; JArray t = parms["resourceSets"] as JArray; if (t != null) { resourceSets = t.ToObject <string[]>(); if (resourceSets != null && resourceSets.Length == 1 && string.IsNullOrEmpty(resourceSets[0])) { resourceSets = null; } } if (string.IsNullOrEmpty(outputBasePath)) { outputBasePath = DbResourceConfiguration.Current.ResxBaseFolder; } else if (outputBasePath.StartsWith("~")) { outputBasePath = Context.Server.MapPath(outputBasePath); } outputBasePath = outputBasePath.Replace("/", "\\").Replace("\\\\", "\\"); DbResXConverter exporter = new DbResXConverter(outputBasePath); if (DbResourceConfiguration.Current.ResxExportProjectType == GlobalizationResxExportProjectTypes.WebForms) { if (!exporter.GenerateLocalWebResourceResXFiles()) { throw new ApplicationException(WebUtils.GRes(STR_RESOURCESET, "ResourceGenerationFailed")); } if (!exporter.GenerateGlobalWebResourceResXFiles()) { throw new ApplicationException(WebUtils.GRes(STR_RESOURCESET, "ResourceGenerationFailed")); } } else { // if resourceSets is null all resources are generated if (!exporter.GenerateResXFiles(resourceSets)) { throw new ApplicationException(WebUtils.GRes(STR_RESOURCESET, "ResourceGenerationFailed")); } } return(true); }
public void ImportResxResources() { bool result = false; //var manager = Activator.CreateInstance(DbResourceConfiguration.Current.DbResourceDataManagerType) as IDbResourceDataManager; //result = manager.CreateLocalizationTable("Localizations"); //Assert.IsTrue(result, manager.ErrorMessage); string physicalPath = Path.GetFullPath(@"..\..\..\Westwind.Globalization.Sample"); DbResXConverter converter = new DbResXConverter(physicalPath); result = converter.ImportWebResources(); Assert.IsTrue(result, converter.ErrorMessage); }
public void ImportResxResources() { bool result = false; //var manager = Activator.CreateInstance(DbResourceConfiguration.Current.DbResourceDataManagerType) as IDbResourceDataManager; //result = manager.CreateLocalizationTable("Localizations"); //Assert.True(result, manager.ErrorMessage); string physicalPath = Path.GetFullPath(@"..\..\..\Westwind.Globalization.Sample"); DbResXConverter converter = new DbResXConverter(configuration, physicalPath); result = converter.ImportWinResources(physicalPath); Assert.True(result, converter.ErrorMessage); }
public bool ExportResxResources(string outputBasePath = null) { #if OnlineDemo throw new ApplicationException(WebUtils.GRes("FeatureDisabled")); #endif if (string.IsNullOrEmpty(outputBasePath)) { outputBasePath = DbResourceConfiguration.Current.ResxBaseFolder; } else if (outputBasePath.StartsWith("~")) { outputBasePath = Context.Server.MapPath(outputBasePath); } outputBasePath = outputBasePath.Replace("/", "\\").Replace("\\\\", "\\"); DbResXConverter exporter = new DbResXConverter(outputBasePath); if (DbResourceConfiguration.Current.ResxExportProjectType == GlobalizationResxExportProjectTypes.WebForms) { if (!exporter.GenerateLocalWebResourceResXFiles()) { throw new ApplicationException(WebUtils.GRes(STR_RESOURCESET, "ResourceGenerationFailed")); } if (!exporter.GenerateGlobalWebResourceResXFiles()) { throw new ApplicationException(WebUtils.GRes(STR_RESOURCESET, "ResourceGenerationFailed")); } } else { if (!exporter.GenerateResXFiles()) { throw new ApplicationException(WebUtils.GRes(STR_RESOURCESET, "ResourceGenerationFailed")); } } return(true); }
public bool ExportResxResources([FromBody] dynamic parms) { #if OnlineDemo throw new WestwindException("Feature disabled"); #endif // Post: {outputBasePath: "~\Properties", resourceSets: ["rs1","rs2"] } string outputBasePath = parms["outputBasePath"]; string[] resourceSets = null; var t = parms["resourceSets"] as JArray; if (t != null) { resourceSets = t.ToObject <string[]>(); if (resourceSets != null && resourceSets.Length == 1 && string.IsNullOrEmpty(resourceSets[0])) { resourceSets = null; } } if (string.IsNullOrEmpty(outputBasePath)) { outputBasePath = configuration.ResxBaseFolder; } if (outputBasePath.StartsWith("~")) { outputBasePath = hostingEnvironment.MapPath(outputBasePath); } var exporter = new DbResXConverter(configuration, outputBasePath); // if resourceSets is null all resources are generated if (!exporter.GenerateResXFiles(resourceSets)) { throw new WestwindException("Resource generation failed"); } return(true); }
public bool ImportResxResources(string inputBasePath = null) { #if OnlineDemo throw new ApplicationException(WebUtils.GRes("FeatureDisabled")); #endif if (string.IsNullOrEmpty(inputBasePath)) { inputBasePath = DbResourceConfiguration.Current.ResxBaseFolder; } if (inputBasePath.Contains("~")) { inputBasePath = Context.Server.MapPath(inputBasePath); } inputBasePath = inputBasePath.Replace("/", "\\").Replace("\\\\", "\\"); DbResXConverter converter = new DbResXConverter(inputBasePath); bool res = false; if (DbResourceConfiguration.Current.ResxExportProjectType == GlobalizationResxExportProjectTypes.WebForms) { res = converter.ImportWebResources(inputBasePath); } else { res = converter.ImportWinResources(inputBasePath); } if (!res) { new ApplicationException(WebUtils.GRes(STR_RESOURCESET, "ResourceImportFailed")); } return(true); }
public string GetJavaScript(string varname, string resourceSet, string localeId, string resourceType, string resourceMode) { // varname is embedded into script so validate to avoid script injection // it's gotta be a valid C# and valid JavaScript name var match = Regex.Match(varname, @"^[\w|\d|_|$|@|\.]*$"); if (match.Length < 1 || match.Groups[0].Value != varname) { throw new WestwindException("Invalid variable name passed."); } if (string.IsNullOrEmpty(resourceSet)) { throw new WestwindException("Invalid ResourceSet specified."); } // pick current UI Culture if (localeId == "auto") { localeId = Thread.CurrentThread.CurrentUICulture.IetfLanguageTag; } Dictionary <string, object> resDict = null; if (string.IsNullOrEmpty(resourceType) || resourceType == "auto") { resourceType = "resdb"; } var basePath = hostingEnvironment.MapPath(configuration.ResxBaseFolder); var converter = new DbResXConverter(configuration, basePath); if (resourceType.ToLower() == "resdb") { // use existing/cached resource manager if previously used // so database is accessed only on first hit var resManager = DbRes.GetResourceManager(resourceSet); resDict = converter.GetResourcesNormalizedForLocale(resManager, localeId); //resDict = manager.GetResourceSetNormalizedForLocaleId(localeId, resourceSet); if (resDict == null || resDict.Keys.Count < 1) { // try resx instead var resxPath = converter.FormatResourceSetPath(resourceSet); resDict = converter.GetResXResourcesNormalizedForLocale(resxPath, localeId); } } else // Resx Resources { resDict = converter.GetCompiledResourcesNormalizedForLocale(resourceSet, configuration.ResourceBaseNamespace, localeId); if (resDict == null) { // check for .resx disk resources var resxPath = converter.FormatResourceSetPath(resourceSet); resDict = converter.GetResXResourcesNormalizedForLocale(resxPath, localeId); } else { resDict = resDict.OrderBy(kv => kv.Key).ToDictionary(k => k.Key, v => v.Value); } } if (resourceMode == "0") { resDict = resDict.Where(res => !res.Key.Contains('.') && res.Value is string) .ToDictionary(dict => dict.Key, dict => dict.Value); } else { resDict = resDict.Where(res => res.Value is string) .ToDictionary(dict => dict.Key, dict => dict.Value); } var javaScript = SerializeResourceDictionary(resDict, varname); return(javaScript); }
public ActionResult ProcessRequest() { var Request = HttpContext.Request; string resourceSet = Request.Query["ResourceSet"]; string localeId = Request.Query["LocaleId"]; if (string.IsNullOrEmpty(localeId)) { localeId = "auto"; } string resourceMode = Request.Query["ResourceMode"]; if (string.IsNullOrEmpty(resourceMode)) { resourceMode = "Resx"; // Resx/ResDb/Auto } string varname = Request.Query["VarName"]; if (string.IsNullOrEmpty(varname)) { varname = "resources"; } // varname is embedded into script so validate to avoid script injection // it's gotta be a valid C# and valid JavaScript name Match match = Regex.Match(varname, @"^[\w|\d|_|$|@|\.]*$"); if (match.Length < 1 || match.Groups[0].Value != varname) { SendErrorResponse("Invalid variable name passed."); } if (string.IsNullOrEmpty(resourceSet)) { SendErrorResponse("Invalid ResourceSet specified."); } // pick current UI Culture if (localeId == "auto") { try { // Use ASP.NET Core RequestLocalization Mapping var cultureProvider = HttpContext.Features.Get <IRequestCultureFeature>(); if (cultureProvider != null) { localeId = cultureProvider.RequestCulture.UICulture.IetfLanguageTag; } else { localeId = Thread.CurrentThread.CurrentUICulture.IetfLanguageTag; } } catch { localeId = Thread.CurrentThread.CurrentUICulture.IetfLanguageTag; } } Dictionary <string, object> resDict = null; resourceMode = string.IsNullOrEmpty(resourceMode) ? "auto" : resourceMode.ToLower(); ResourceAccessMode mode = ResourceAccessMode.Resx; if (resourceMode == "resdb") { mode = ResourceAccessMode.DbResourceManager; } else if (resourceMode == "auto") { mode = DbResourceConfiguration.Current.ResourceAccessMode; } if (mode == ResourceAccessMode.DbResourceManager) { var resManager = DbResourceDataManager.CreateDbResourceDataManager( Config.DbResourceDataManagerType); resDict = resManager.GetResourceSetNormalizedForLocaleId(localeId, resourceSet); if (resDict == null || resDict.Count == 0) { mode = ResourceAccessMode.Resx; // try Resx resources from disk instead } } if (mode != ResourceAccessMode.DbResourceManager) // Resx Resources loaded from disk { string basePath = Request.MapPath(DbResourceConfiguration.Current.ResxBaseFolder, basePath: Host.ContentRootPath); DbResXConverter converter = new DbResXConverter(basePath); resDict = converter.GetCompiledResourcesNormalizedForLocale(resourceSet, DbResourceConfiguration.Current.ResourceBaseNamespace, localeId); if (resDict == null) { // check for .resx disk resources string resxPath = converter.FormatResourceSetPath(resourceSet); resDict = converter.GetResXResourcesNormalizedForLocale(resxPath, localeId); } else { resDict = resDict.OrderBy(kv => kv.Key).ToDictionary(k => k.Key, v => v.Value); } } // return all resource strings resDict = resDict.Where(res => res.Value is string) .ToDictionary(dict => dict.Key, dict => dict.Value); string javaScript = SerializeResourceDictionary(resDict, varname); #if NETFULL // client cache if (!HttpContext.Current.IsDebuggingEnabled) { Response.ExpiresAbsolute = DateTime.UtcNow.AddDays(1); Response.AppendHeader("Accept-Ranges", "bytes"); Response.AppendHeader("Vary", "Accept-Encoding"); Response.Cache.SetETag("\"" + javaScript.GetHashCode().ToString("x") + "\""); Response.Cache.SetLastModified(DateTime.UtcNow); // OutputCache settings HttpCachePolicy cache = Response.Cache; cache.VaryByParams["ResourceSet"] = true; cache.VaryByParams["LocaleId"] = true; cache.VaryByParams["ResoureType"] = true; cache.VaryByParams["IncludeControls"] = true; cache.VaryByParams["VarName"] = true; cache.VaryByParams["ResourceMode"] = true; //cache.SetOmitVaryStar(true); DateTime now = DateTime.Now; cache.SetCacheability(HttpCacheability.Public); cache.SetExpires(now + TimeSpan.FromDays(1)); cache.SetValidUntilExpires(true); cache.SetLastModified(now); } #endif return(SendTextOutput(javaScript, "text/javascript; charset=utf-8")); }
public bool ImportResxResources(string inputBasePath = null) { #if OnlineDemo throw new ApplicationException(WebUtils.GRes("FeatureDisabled")); #endif if (string.IsNullOrEmpty(inputBasePath)) inputBasePath = DbResourceConfiguration.Current.ResxBaseFolder; if (inputBasePath.Contains("~")) inputBasePath = Context.Server.MapPath(inputBasePath); inputBasePath = inputBasePath.Replace("/", "\\").Replace("\\\\", "\\"); DbResXConverter converter = new DbResXConverter(inputBasePath); bool res = false; if (DbResourceConfiguration.Current.ResxExportProjectType == GlobalizationResxExportProjectTypes.WebForms) res = converter.ImportWebResources(inputBasePath); else res = converter.ImportWinResources(inputBasePath); if (!res) new ApplicationException(WebUtils.GRes(STR_RESOURCESET, "ResourceImportFailed")); return true; }
public bool ExportResxResources(dynamic parms) { #if OnlineDemo throw new ApplicationException(WebUtils.GRes("FeatureDisabled")); #endif // Post: {outputBasePath: "~\Properties", resourceSets: ["rs1","rs2"] } string outputBasePath = parms["outputBasePath"] ; string[] resourceSets = null; JArray t = parms["resourceSets"] as JArray; if (t != null) { resourceSets = t.ToObject<string[]>(); if (resourceSets != null && resourceSets.Length == 1 && string.IsNullOrEmpty(resourceSets[0])) resourceSets = null; } if (string.IsNullOrEmpty(outputBasePath)) outputBasePath = DbResourceConfiguration.Current.ResxBaseFolder; else if (outputBasePath.StartsWith("~")) outputBasePath = Context.Server.MapPath(outputBasePath); outputBasePath = outputBasePath.Replace("/", "\\").Replace("\\\\", "\\"); DbResXConverter exporter = new DbResXConverter(outputBasePath); if (DbResourceConfiguration.Current.ResxExportProjectType == GlobalizationResxExportProjectTypes.WebForms) { if (!exporter.GenerateLocalWebResourceResXFiles()) throw new ApplicationException(WebUtils.GRes(STR_RESOURCESET, "ResourceGenerationFailed")); if (!exporter.GenerateGlobalWebResourceResXFiles()) throw new ApplicationException(WebUtils.GRes(STR_RESOURCESET, "ResourceGenerationFailed")); } else { // if resourceSets is null all resources are generated if (!exporter.GenerateResXFiles(resourceSets)) throw new ApplicationException(WebUtils.GRes(STR_RESOURCESET, "ResourceGenerationFailed")); } return true; }
public bool ExportResxResources(string outputBasePath = null) { #if OnlineDemo throw new ApplicationException(WebUtils.GRes("FeatureDisabled")); #endif if (string.IsNullOrEmpty(outputBasePath)) outputBasePath = DbResourceConfiguration.Current.ResxBaseFolder; else if(outputBasePath.StartsWith("~")) outputBasePath = Context.Server.MapPath(outputBasePath); outputBasePath = outputBasePath.Replace("/", "\\").Replace("\\\\", "\\"); DbResXConverter exporter = new DbResXConverter(outputBasePath); if (DbResourceConfiguration.Current.ResxExportProjectType == GlobalizationResxExportProjectTypes.WebForms) { if (!exporter.GenerateLocalWebResourceResXFiles()) throw new ApplicationException(WebUtils.GRes(STR_RESOURCESET, "ResourceGenerationFailed")); if (!exporter.GenerateGlobalWebResourceResXFiles()) throw new ApplicationException(WebUtils.GRes(STR_RESOURCESET, "ResourceGenerationFailed")); } else { if (!exporter.GenerateResXFiles()) throw new ApplicationException(WebUtils.GRes(STR_RESOURCESET, "ResourceGenerationFailed")); } return true; }
public void WriteResxFromDbResources() { DbResXConverter converter = new DbResXConverter(configuration, @"c:\temp\resources"); Assert.True(converter.GenerateResXFiles(), converter.ErrorMessage); }
public void WriteResxFromDbResources() { DbResXConverter converter = new DbResXConverter(@"c:\temp\resources"); Assert.IsTrue(converter.GenerateResXFiles(), converter.ErrorMessage); }
public void GetResXResourcesTest() { DbResXConverter converter = new DbResXConverter(null); Dictionary<string,object> items = converter.GetResXResourcesNormalizedForLocale(@"C:\projects2008\Westwind.GlobalizationWeb\App_GlobalResources\resources","de-de"); this.WriteResourceDictionary(items,"ResX Resources"); }