/// <summary> /// Gets the string Resource associated with the resourceKeyName provided from the resource file designated. /// </summary> /// <param name="resxFileName">Name of the .resx file.</param> /// <param name="resourceKeyName">The key name of the string value we want.</param> /// <returns></returns> /// <exception cref="System.ArgumentException">ResourceFileName does not refer to a .resx file of Type string.</exception> public static string GetString(ResourceFileName resxFileName, string resourceKeyName) { ResourceManager rm = GetManager(resxFileName); if (!rm.ResourceSetType.Equals(typeof(string))) { throw new ArgumentException(); // IMPROVE with error message } return rm.GetString(resourceKeyName); }
/// <summary> /// Gets the string Resource associated with the resourceKeyName provided from the resource file designated. /// </summary> /// <param name="resxFileName">Name of the .resx file.</param> /// <param name="resourceKeyName">The key name of the string value we want.</param> /// <returns></returns> /// <exception cref="System.ArgumentException">ResourceFileName does not refer to a .resx file of Type string.</exception> public static string GetString(ResourceFileName resxFileName, string resourceKeyName) { ResourceManager rm = GetManager(resxFileName); if (!rm.ResourceSetType.Equals(typeof(string))) { string callingMethodName = new StackTrace().GetFrame(1).GetMethod().Name; throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, ErrorMessages.ResourceNotString, resxFileName, callingMethodName)); } return rm.GetString(resourceKeyName); }
/// <summary> /// Gets the string Resource associated with the resourceKeyName provided from the resource file designated. /// </summary> /// <param name="resxFileName">Name of the .resx file.</param> /// <param name="resourceKeyName">The key name of the string value we want.</param> /// <returns></returns> /// <exception cref="System.ArgumentException">ResourceFileName does not refer to a .resx file of Type string.</exception> public static string GetString(ResourceFileName resxFileName, string resourceKeyName) { ResourceManager rm = GetManager(resxFileName); if (!rm.ResourceSetType.Equals(typeof(string))) { throw new ArgumentException(); // IMPROVE with error message } return(rm.GetString(resourceKeyName)); }
private Stream GetResourceStreamAccordingLocale(List <string> path, ResourceFileName fileName, string language, bool isSharedBranch = false) { if (!string.IsNullOrWhiteSpace(language) && (path.Count <= _mockRequest.TestScenarioList.Count - 2 || isSharedBranch)) { var pathWithLang = path.ToList(); pathWithLang.Add(language); var stream = GetResourceStreamWithHash(pathWithLang, fileName); if (stream != null) { return(stream); } } return(GetResourceStreamWithHash(path, fileName)); }
/// <summary> /// Gets the <c>ResourceManager</c> referred to by <c>ResourceFileName</c>. /// </summary> /// <param name="resxFileName">Name of the .resx file.</param> /// <returns></returns> /// <exception cref="System.ArgumentOutOfRangeException"></exception> public static ResourceManager GetManager(ResourceFileName resxFileName) { if (!Enum.IsDefined(typeof(ResourceFileName), resxFileName)) { // Circular ref w/Enums<> throw new ArgumentOutOfRangeException(); // Circular ref w/Inject() // IMPROVE with error message } ResourceManager rm = null; if (!resourceMgrs.ContainsKey(resxFileName)) { rm = resourceMgrs[resxFileName]; } else { string resMgrAccessName = rootResourceNamespace + "." + Enum.GetName(typeof(ResourceFileName), resxFileName); rm = new ResourceManager(resMgrAccessName, Assembly.GetExecutingAssembly()); resourceMgrs.Add(resxFileName, rm); // string ns = Assembly.GetEntryAssembly().GetType("NeedsFullyQualifiedName", true, true).Namespace; } return rm; }
/// <summary> /// Gets the <c>ResourceManager</c> referred to by <c>ResourceFileName</c>. /// </summary> /// <param name="resxFileName">Name of the .resx file.</param> /// <returns></returns> /// <exception cref="System.ArgumentOutOfRangeException"></exception> public static ResourceManager GetManager(ResourceFileName resxFileName) { if (!Enum.IsDefined(typeof(ResourceFileName), resxFileName)) { // Circular ref w/Enums<> string callingMethodName = new StackTrace().GetFrame(1).GetMethod().Name; throw new ArgumentOutOfRangeException(String.Format(CultureInfo.InvariantCulture, ErrorMessages.UndefinedEnum, resxFileName, callingMethodName)); // Circular ref w/Inject() } ResourceManager rm = null; if (!resourceMgrs.ContainsKey(resxFileName)) { rm = resourceMgrs[resxFileName]; } else { string resMgrAccessName = rootResourceNamespace + "." + Enum.GetName(typeof(ResourceFileName), resxFileName); rm = new ResourceManager(resMgrAccessName, Assembly.GetExecutingAssembly()); resourceMgrs.Add(resxFileName, rm); // string ns = Assembly.GetEntryAssembly().GetType("NeedsFullyQualifiedName", true, true).Namespace; } return rm; }
private Stream ToStream(ResourceFileName fileName) { var testScenarios = _mockRequest.TestScenarioList; testScenarios.Add(_mockRequest.TestName); var i = 0; do { var stream = GetResourceStreamAccordingLocale(testScenarios.Take(testScenarios.Count - i++).ToList(), fileName, _mockRequest.Language); if (stream != null) { return(stream); } } while (i < testScenarios.Count); return(GetResourceStreamFromSharedFolders(fileName) ?? GetResourceStreamAccordingLocale(testScenarios.Take(0).ToList(), fileName, _mockRequest.Language)); }
private Stream GetResourceStreamFromSharedFolders(ResourceFileName fileName) { var sharedFoldersPath = _mockRequest.SharedFoldersList; if (sharedFoldersPath == null || !sharedFoldersPath.Any()) { return(null); } var i = 0; do { var stream = GetResourceStreamAccordingLocale(sharedFoldersPath.Take(sharedFoldersPath.Count - i++).ToList(), fileName, _mockRequest.Language, true); if (stream != null) { return(stream); } } while (i <= sharedFoldersPath.Count); return(null); }
/// <summary> /// Gets the <c>ResourceManager</c> referred to by <c>ResourceFileName</c>. /// </summary> /// <param name="resxFileName">Name of the .resx file.</param> /// <returns></returns> /// <exception cref="System.ArgumentOutOfRangeException"></exception> public static ResourceManager GetManager(ResourceFileName resxFileName) { if (!Enum.IsDefined(typeof(ResourceFileName), resxFileName)) // Circular ref w/Enums<> { throw new ArgumentOutOfRangeException(); // Circular ref w/Inject() // IMPROVE with error message } ResourceManager rm = null; if (!resourceMgrs.ContainsKey(resxFileName)) { rm = resourceMgrs[resxFileName]; } else { string resMgrAccessName = rootResourceNamespace + "." + Enum.GetName(typeof(ResourceFileName), resxFileName); rm = new ResourceManager(resMgrAccessName, Assembly.GetExecutingAssembly()); resourceMgrs.Add(resxFileName, rm); // string ns = Assembly.GetEntryAssembly().GetType("NeedsFullyQualifiedName", true, true).Namespace; } return(rm); }
private Stream GetResourceStreamWithHash(IReadOnlyCollection <string> path, ResourceFileName fileName) { return(_resourceStream.Stream(path.Concat(new[] { fileName.ToString(true) }).ToArray()) ?? _resourceStream.Stream(path.Concat(new[] { fileName.ToString(false) }).ToArray())); }