Пример #1
0
        /// <summary>
        /// Uses an open database connection to recurse 
        /// looking for the resource.
        /// Retrieves a resource entry based on the 
        /// specified culture and resource 
        /// key. The resource type is based on this instance of the
        /// StringResourceDALC as passed to the constructor.
        /// Resource fallback follows the same mechanism 
        /// of the .NET 
        /// ResourceManager. Ultimately falling back to the 
        /// default resource
        /// specified in this class.
        /// </summary>
        /// <param name="culture">The culture to search with.</param>
        /// <param name="resourceKey">The resource key to find.</param>
        /// <returns>If found, the resource string is returned. 
        /// Otherwise an empty string is returned.</returns>
        private string GetResourceByCultureAndKeyInternal(CultureInfo culture, string resourceKey)
        {
            if (string.IsNullOrEmpty(culture.Name))
                culture = CultureInfo.CurrentUICulture;

            // we should only get one back, but just in case, we'll iterate reader results
            var resources = new DbFunctions().GetResourceValue(_resourcePage, culture.Name, resourceKey);

            // we should only get 1 back, this is just to verify the tables aren't incorrect
            if (resources == null || string.IsNullOrEmpty(resources.Value))
            {
                // is this already fallback location?
                if (culture.Name == this._defaultResourceCulture)
                {
                    // if we can't get a resource return an empty string
                    return string.Empty;
                }

                // try to get parent culture
                culture = culture.Parent;
                if (string.IsNullOrEmpty(culture.Name))
                {
                    // there isn't a parent culture, change to neutral
                    culture = new CultureInfo(this._defaultResourceCulture);
                } 
                return this.GetResourceByCultureAndKeyInternal(culture, resourceKey);
            }

            return resources.Value;
        }
Пример #2
0
        public void ExportFromDatabase(string exportPath)
        {
            var allRecords = new DbFunctions(_connectionString).GetAllResources();

            foreach (ResourceRecord record in allRecords)
            {
                using (ResXResourceWriter writer = new ResXResourceWriter(GetExportPath(exportPath, record)))
                {
                    writer.AddResource(record.Key, record.Value);
                }
            }
        }
Пример #3
0
        public ListDictionary GetResourcesByCulture(CultureInfo culture)
        {
            // make sure we have a default culture at least
            if (culture == null || culture.Name.Length == 0)
            {
                culture = new CultureInfo(this._defaultResourceCulture);
            }

            // create the dictionary
            ListDictionary resourceDictionary = new ListDictionary();

            // gather resource and create the dictionary
            var resources = new DbFunctions().GetResourcesForPage(culture.Name, _resourcePage);
            resources.ForEach(r => resourceDictionary.Add(r.Key, r.Value));

            return resourceDictionary;
        }