Example #1
0
        /// <summary>
        /// Overrides the OnPreRender method.
        /// </summary>
        protected override void OnPreRender(System.EventArgs e)
        {
            base.OnPreRender(e);

            if (this.AutoPostBack)
            {
                this.AutoPostBack      = false;
                this.text.AutoPostBack = true;
            }

            ResourceManager manager   = new ResourceManager(this.GetType());
            ResourceSet     resources = manager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true);

            if (!Page.IsClientScriptBlockRegistered("MetaBuilders.WebControls.ComboBox Library"))
            {
                if (UseReferenceLibrary)
                {
                    Page.RegisterClientScriptBlock("MetaBuilders.WebControls.ComboBox Library", "<script language=\"javascript\" src=\"" + ResolveUrl(ReferenceLibraryUrl.ToString()) + "\"></script>");
                }
                else
                {
                    String script = resources.GetString("ClientScript");
                    this.Page.RegisterClientScriptBlock("MetaBuilders.WebControls.ComboBox Library", script);
                }
            }

            String initScript = resources.GetString("InitScript");

            this.Page.RegisterStartupScript("MetaBuilders.WebControls.ComboBox Init", initScript);

            Page.RegisterArrayDeclaration("ComboBoxes", "'" + this.ClientID + "'");
        }
        public static void GetResourceSet_Strings(string key, string expectedValue)
        {
            var         manager = new ResourceManager("System.Resources.Tests.Resources.TestResx", typeof(ResourceManagerTests).GetTypeInfo().Assembly);
            var         culture = new CultureInfo("en-US");
            ResourceSet set     = manager.GetResourceSet(culture, true, true);

            Assert.Equal(expectedValue, set.GetString(key));
            Assert.Equal(expectedValue, set.GetObject(key));
            Assert.Equal(expectedValue, set.GetString(key));
        }
        public static void GetStringAfterDispose()
        {
            var         manager = new ResourceManager("System.Resources.Tests.Resources.TestResx", typeof(ResourceManagerTests).GetTypeInfo().Assembly);
            var         culture = new CultureInfo("en-US");
            ResourceSet set     = manager.GetResourceSet(culture, true, true);

            set.GetString("Any");
            ((IDisposable)set).Dispose();
            Assert.Throws <ObjectDisposedException> (() => set.GetString("Any"));
        }
Example #4
0
        private TzdbResourceData(ResourceSet source)
        {
            this.source = source;
            tzdbIdMap   = CheckKey(LoadDictionary(source, IdMapKey), IdMapKey);
            tzdbVersion = CheckKey(source.GetString(VersionKey), VersionKey);
            var windowsMappingVersion = CheckKey(source.GetString(WindowsToPosixMapVersionKey), WindowsToPosixMapVersionKey);
            var windowsMapping        = CheckKey(LoadDictionary(source, WindowsToPosixMapKey), WindowsToPosixMapKey);

            this.windowsMapping = WindowsZones.FromPrimaryMapping(windowsMappingVersion, windowsMapping);
        }
        public void GetString()
        {
            var rs = new ResourceSet(new SimpleResourceReader());

            Assert.Null(rs.GetString("DoesNotExist"));
            Assert.Null(rs.GetString("1"));

            Assert.Equal("message", rs.GetString("String"));
            Assert.Equal("message", rs.GetString("string", true));
        }
Example #6
0
 public static string trunkSCSCF()
 {
     using (ResourceSet ResSet = new ResourceSet(@".\ConnectResources.resources"))
     {
         return(ResSet.GetString("trunkSCSCF", true));
     }
 }
Example #7
0
 public static string ManualXmlInputDestination()
 {
     using (ResourceSet ResSet = new ResourceSet(@".\ConnectResources.resources"))
     {
         return(ResSet.GetString("ManualXmlInputDestination", true));
     }
 }
Example #8
0
 public static string imsScfAddr()
 {
     using (ResourceSet ResSet = new ResourceSet(@".\ConnectResources.resources"))
     {
         return(ResSet.GetString("imsScfAddr", true));
     }
 }
Example #9
0
 public static string userIFC()
 {
     using (ResourceSet ResSet = new ResourceSet(@".\ConnectResources.resources"))
     {
         return(ResSet.GetString("userIFC", true));
     }
 }
        public Merlin32KeywordsHelper()
        {
            // Read the resources for opcodes, all of them...
            ResourceSet rsOpcodes = VSMerlin32.Resources.opcodes.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true);
            // Read the resources for directives too, all of them...
            ResourceSet rsDirectives = VSMerlin32.Resources.directives.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true);
            // Read the resources for datadefines too, all of them...
            ResourceSet rsData = VSMerlin32.Resources.data.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true);

            _Merlin32KeywordsQuickInfo = new Dictionary <string, string>();
            foreach (Merlin32Opcodes token in Enum.GetValues(typeof(Merlin32Opcodes)))
            {
                // _Merlin32OpcodesQuickInfo[token.ToString()] = token.ToString();
                _Merlin32KeywordsQuickInfo[token.ToString()] = rsOpcodes.GetString(token.ToString());
            }
            foreach (Merlin32Directives token in Enum.GetValues(typeof(Merlin32Directives)))
            {
                _Merlin32KeywordsQuickInfo[token.ToString()] = rsDirectives.GetString(token.ToString());
            }
            foreach (Merlin32DataDefines token in Enum.GetValues(typeof(Merlin32DataDefines)))
            {
                _Merlin32KeywordsQuickInfo[token.ToString()] = rsData.GetString(token.ToString());
            }

            /*
             * _Merlin32OpcodesQuickInfo[Merlin32Opcodes.ORG.ToString()] = VSMerlin32.strings.ORG;
             */
        }
Example #11
0
        /// <summary>
        /// Gets a string from an owning type by name and for culture (defaults if not found)
        /// </summary>
        public static string GetString(string resName, Type owningType, CultureInfo ci)
        {
            ResourceManager rm = new ResourceManager(owningType);
            ResourceSet     x  = rm.GetResourceSet(ci, true, true);

            return(x.GetString(resName));
        }
Example #12
0
 public static string stpIndex()
 {
     using (ResourceSet ResSet = new ResourceSet(@".\ConnectResources.resources"))
     {
         return(ResSet.GetString("stpIndex", true));
     }
 }
Example #13
0
 public static string UrlPGW()
 {
     using (ResourceSet ResSet = new ResourceSet(@".\ConnectResources.resources"))
     {
         return(ResSet.GetString("urlpgw", true));
     }
 }
Example #14
0
 public static string agcf()
 {
     using (ResourceSet ResSet = new ResourceSet(@".\ConnectResources.resources"))
     {
         return(ResSet.GetString("agcf", true));
     }
 }
Example #15
0
        public static string GetString(string resID)
        {
            try
            {
                if (_rs == null)
                {
                    ChangeResourceSet(CultureManager.UICulture);
                }

                if (_rs != null)
                {
                    string value = _rs.GetString(resID);
                    if (value == null)
                    {
                        value = "#" + resID;
                    }
                    return(value);
                }
                return("NULL");
            }
            catch (Exception e)
            {
                throw new UIException(string.Format("{0}.{1}: {2}", "ResourceReader", (new StackTrace()).GetFrame(0).GetMethod().Name, e.Message));
            }
        }
Example #16
0
        public void Resources_HasAllTranslations()
        {
            IEnumerable <Language> languages     = GlobalizationProviderFactory.CreateProvider().Languages;
            IEnumerable <Type>     resourceTypes = Assembly
                                                   .Load("MvcTemplate.Resources")
                                                   .GetTypes()
                                                   .Where(type => type.Namespace.StartsWith("MvcTemplate.Resources."));

            foreach (Type type in resourceTypes)
            {
                ResourceManager      manager      = new ResourceManager(type);
                IEnumerable <String> resourceKeys = new String[0];

                foreach (Language language in languages)
                {
                    ResourceSet set = manager.GetResourceSet(language.Culture, true, true);
                    resourceKeys = resourceKeys.Union(set.Cast <DictionaryEntry>().Select(resource => resource.Key.ToString()));
                    resourceKeys = resourceKeys.Distinct();
                }

                foreach (Language language in languages)
                {
                    ResourceSet set = manager.GetResourceSet(language.Culture, true, true);
                    foreach (String key in resourceKeys)
                    {
                        Assert.True(!String.IsNullOrEmpty(set.GetString(key)),
                                    String.Format("{0}, does not have translation for '{1}' in {2} language.",
                                                  type.FullName, key, language.Culture.EnglishName));
                    }
                }
            }
        }
        public object GetResource(string name, bool ignoreCase, bool isString, bool asSafe, bool cloneValue)
        {
            ResXResourceSet resx     = resxResourceSet;
            ResourceSet     compiled = compiledResourceSet;

            if (resx == null || compiled == null)
            {
                Throw.ObjectDisposedException();
            }

            object result = resx.GetResourceInternal(name, ignoreCase, isString, asSafe, cloneValue);

            if (result != null)
            {
                return(result);
            }

            // if the null result is because it is explicitly stored, hiding the compiled value
            if (resx.ContainsResource(name, ignoreCase))
            {
                return(null);
            }

            return(isString ? compiled.GetString(name, ignoreCase) : compiled.GetObject(name, ignoreCase));
        }
Example #18
0
 public static string passSPG()
 {
     using (ResourceSet ResSet = new ResourceSet(@".\ConnectResources.resources"))
     {
         return(Program.Base64Encode(ResSet.GetString("spgPass", true), false));
     }
 }
        private ResourceSet GetResourceSet(CultureInfo culture, bool custom)
        {
            ResourceSet resource;
            String      resourceKey = GetResourceKey(culture, custom);

            lock (_resourceLock) {
                // if the resource data for this culture has not yet been loaded, load it
                if (!ResourceData.TryGetValue(resourceKey, out resource))
                {
                    // set the filename according to the cuture
                    String filename = "resources.";
                    if (custom)
                    {
                        filename += "custom.";
                    }
                    if (!culture.Equals(CultureInfo.InvariantCulture))
                    {
                        filename += culture.Name.ToLowerInvariant() + ".";
                    }
                    filename += "txt";
                    filename  = Path.Combine(_resourcePath, filename);

                    // load the resource set and add it into the resource table
                    resource = new ResourceSet(_resourceReaderFactory(filename));

                    // Note (arnec): We call GetString to force the lazy loading of the resource stream, thereby making
                    // GetString(), at least theoretically, thread-safe for subsequent calls.
                    resource.GetString("", true);
                    ResourceData.Add(resourceKey, resource);
                }
            }
            return(resource);
        }
Example #20
0
 public static string defaultRealm()
 {
     using (ResourceSet ResSet = new ResourceSet(@".\ConnectResources.resources"))
     {
         return(ResSet.GetString("defaultRealm", true));
     }
 }
Example #21
0
        private static string GetLoadStringFromCall(MethodReference mr)
        {
            MethodDefinition md = mr.Resolve();

            if ((md == null) || !IsResource(md))
            {
                return(null);
            }

            string resourceName = GetResourceNameFromResourceGetter(md);

            if (resourceName == null)
            {
                return(null);
            }

            AssemblyDefinition ad = md.GetAssembly();
            string             resourceClassName = md.DeclaringType.GetFullName() + ".resources";
            EmbeddedResource   resource          = GetEmbeddedResource(ad, resourceClassName);

            if (resource == null)
            {
                return(null);
            }

            using (MemoryStream ms = new MemoryStream(resource.GetResourceData()))
                using (ResourceSet resourceSet = new ResourceSet(ms)) {
                    return(resourceSet.GetString(resourceName));
                }
        }
        /// <summary>
        /// Retrieve string resource according to the string name.
        /// </summary>
        /// <param name="resourceKey">string name</param>
        /// <returns>the value of <c>name</c> if successful,
        ///  <c>name</c>, otherwise.
        /// </returns>
        public string GetString(string resourceKey)
        {
            string resourceValue = "";

            try
            {
                resourceValue = resourceManager.GetString(resourceKey);
                if (resourceValue == null)
                {
                    // if the resource not exist, retrieve the default value
                    ResourceSet resourceSet =
                        resourceManager.GetResourceSet(new CultureInfo("en"), true, false);
                    resourceValue = resourceSet.GetString(resourceKey);
                }
            }
            catch (System.Exception)
            {
                resourceValue = resourceKey;
            }
            finally
            {
                if (resourceValue == null || resourceValue == "")
                {
                    resourceValue = resourceKey;
                }
            }
            return(resourceValue);
        }
Example #23
0
            public override string GetString(string name, bool ignoreCase)
            {
                var result = (string)null;

                try
                {
                    var dic = GetResources();
                    dic.TryGetValue(name, out result);
                }
                catch (Exception err)
                {
                    log.ErrorFormat("Can not get resource from {0} for {1}: GetString({2}), {3}", filename, culture, name, err);
                }

                if (invariant != null && result == null)
                {
                    result = invariant.GetString(name, ignoreCase);
                }

                if (WhiteLableEnabled)
                {
                    result = WhiteLabelHelper.ReplaceLogo(name, result);
                }

                return(result);
            }
Example #24
0
        /// <summary>
        /// Retrieves the text entry with the specified key from the assembly containing the provided relative type.
        /// </summary>
        /// <param name="relativeType">An object type in the assembly containing the language file.</param>
        /// <param name="key">The key of the language entry.</param>
        /// <returns>The text matching the provided key from the assembly that contains the relative type.</returns>
        public static string GetText(Type relativeType, string key)
        {
            if (relativeType == null)
            {
                throw new ArgumentNullException("relativeType");
            }

            if (key == null || key == String.Empty)
            {
                throw new ArgumentNullException("key");
            }

            ResourceSet resources = GetResourceSet(relativeType, key);

            if (resources == null)
            {
                throw new Exception("No resource set found for key '" + key + "'.");
            }

            string output = resources.GetString(key);

            if (output == null || output == String.Empty)
            {
                throw new ArgumentException("No language entries found with the key '" + key + "'.");
            }

            return(output);
        }
Example #25
0
        /// <summary>
        /// Retrieves the resource set containing the specified key from the provided assembly.
        /// </summary>
        /// <param name="assembly">The assembly containing the target resource set.</param>
        /// <param name="key">The key of the target entry.</param>
        /// <returns>The resource set from the provided assembly containing the provided key.</returns>
        public static ResourceSet GetResourceSetFromAssembly(Assembly assembly, string key)
        {
            string[] resourceNames = assembly.GetManifestResourceNames();

            ResourceSet resources = null;

            foreach (string resourceName in resourceNames)
            {
                string text = String.Empty;

                using (Stream stream = assembly.GetManifestResourceStream(resourceName))
                {
                    resources = new ResourceSet(stream);

                    stream.Close();
                }

                text = resources.GetString(key);

                if (ResourceSetMatches(resources, key))
                {
                    return(resources);
                }
            }

            return(resources);
        }
Example #26
0
 private String GetString(String key)
 {
     if (_customizerSet == null)
     {
         return(null);
     }
     return(_customizerSet.GetString(key));
 }
Example #27
0
        /// <summary>
        /// 获取语言化字符串
        /// </summary>
        /// <param name="key">原文键</param>
        /// <param name="culture">区域</param>
        /// <returns>语言化字符串</returns>
        public static string GetCultureString(this string key, string culture = "zh-CN")
        {
            if (resourceSet != null)
            {
                var res = resourceSet.GetString(key);
                return(string.IsNullOrEmpty(res) ? key : res);
            }

            lock ("CultureHelper")
            {
                if (resourceSet != null)
                {
                    var res = resourceSet.GetString(key);
                    return(string.IsNullOrEmpty(res) ? key : res);
                }

                if (HttpContext.Current == null)
                {
                    return(key);
                }

                var vPath = string.Format(Config.GetString("lang_path_format"), culture);
                var fPath = MachineHelper.MapPath(vPath);

                if (!File.Exists(fPath))
                {
                    fPath = MachineHelper.MapPath(Config.GetString("lang_default_path"));
                }

                if (!File.Exists(fPath))
                {
                    return(key);
                }

                // using (var set = new ResourceSet(fPath))
                // {
                //     //CacheHelper.SetCache(vPath, set);
                //     var res = set.GetString(key);
                //     return string.IsNullOrEmpty(res) ? key : res;
                // }
                resourceSet = new ResourceSet(fPath);
            }
            var res2 = resourceSet.GetString(key);

            return(string.IsNullOrEmpty(res2) ? key : res2);
        }
Example #28
0
        public static string urlSPG()
        {
            //return Properties.Resources.ResourceManager.GetString("urlSPG");

            using (ResourceSet ResSet = new ResourceSet(@".\ConnectResources.resources"))
            {
                return(ResSet.GetString("urlSPG", true));
            }
        }
Example #29
0
        /// <summary>
        /// Checks whether the provided resource set contains an entry matching the provided key.
        /// </summary>
        /// <param name="resources"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static bool ResourceSetMatches(ResourceSet resources, string key)
        {
            if (resources == null)
            {
                return(false);
            }

            string output = resources.GetString(key);

            return(output != null && output != String.Empty);
        }
Example #30
0
        public bool VerifyResourcesForErrorCode(CultureInfo culture)
        {
            if (culture == null)
            {
                throw new ArgumentNullException(nameof(culture));
            }

            bool isValid = true;

            // If specified culture is English, read from the default resource due to file name difference for default culture
            ResourceSet resourceSet = ErrorCode.ResourceManager
                                      .GetResourceSet(culture, true, culture.EnglishName.StartsWith("en", StringComparison.InvariantCultureIgnoreCase));

            if (resourceSet == null)
            {
                isValid = false;
                WriteLine($"Localization for {culture.EnglishName} culture is not available", LogErrorSeverity.Warning);
            }
            else
            {
                var errorCodes = Enum.GetNames(typeof(HideezErrorCode));

                foreach (DictionaryEntry entry in resourceSet)
                {
                    if (!errorCodes.Contains(entry.Key.ToString()))
                    {
                        isValid = false;
                        WriteLine($"No error code found for: " +
                                  $"{entry.Key.ToString()}, culture: {culture.EnglishName}", LogErrorSeverity.Warning);
                    }
                }

                foreach (var errCode in errorCodes)
                {
                    string str = resourceSet.GetString(errCode);

                    if (str == null)
                    {
                        isValid = false;
                        WriteLine($"No localization for error code: " +
                                  $"{errCode}, culture: {culture.EnglishName}", LogErrorSeverity.Warning);
                    }
                    else if (string.IsNullOrWhiteSpace(str))
                    {
                        isValid = false;
                        WriteLine($"Localization is empty for: " +
                                  $"{errCode}, culture: {culture.EnglishName}", LogErrorSeverity.Warning);
                    }
                }
            }

            return(isValid);
        }