Пример #1
0
        /// <summary>
        /// Generates the Database resources for a given form
        /// </summary>
        /// <param name="ParentControl"></param>
        /// <param name="ResourcePrefix"></param>
        public void AddResourceToResourceFile(Control ParentControl, string ResourcePrefix, string ResourceSet)
        {
            if (ResourcePrefix == null)
            {
                ResourcePrefix = "Resource1";
            }

            if (ResourceSet == null)
            {
                ResourceSet = this.Context.Request.ApplicationPath + this.Parent.TemplateControl.AppRelativeVirtualPath.Replace("~", "");
            }


            DbResourceDataManager Data = new DbResourceDataManager();

            List <LocalizableProperty> ResourceList = this.GetAllLocalizableControls(ParentControl);

            foreach (LocalizableProperty Resource in ResourceList)
            {
                string ResourceKey = Resource.ControlId + ResourcePrefix + "." + Resource.Property;

                if (!Data.ResourceExists(ResourceKey, "", ResourceSet))
                {
                    Data.AddResource(ResourceKey, Resource.Value, "", ResourceSet, null);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// The main method to retrieve a specific resource key. The provider
        /// internally handles resource fallback based on the ResourceSet implementation.
        /// </summary>
        /// <param name="resourceKey"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        object IResourceProvider.GetObject(string resourceKey, CultureInfo culture)
        {
            object value = ResourceManager.GetObject(resourceKey, culture);

            // If the value is still null and we're at the invariant culture
            // let's add a marker that the value is missing
            // this also allows the pre-compiler to work and never return null
            if (value == null && (culture == null || culture == CultureInfo.InvariantCulture))
            {
                // No entry there
                value = resourceKey;

                if (DbResourceConfiguration.Current.AddMissingResources)
                {
                    lock (_SyncLock)
                    {
                        value = ResourceManager.GetObject(resourceKey, culture);
                        if (value == null)
                        {
                            // Add invariant resource
                            DbResourceDataManager data = new DbResourceDataManager();
                            if (!data.ResourceExists(resourceKey, "", _className))
                            {
                                data.AddResource(resourceKey, resourceKey, "", _className, null);
                            }

                            value = resourceKey;
                        }
                    }
                }
            }

            return(value);
        }
Пример #3
0
        /// <summary>
        /// Internal lookup method that handles retrieving a resource
        /// by its resource id and culture. Realistically this method
        /// is always called with the culture being null or empty
        /// but the routine handles resource fallback in case the
        /// code is manually called.
        /// </summary>
        /// <param name="resourceKey"></param>
        /// <param name="cultureName"></param>
        /// <returns></returns>
        object GetObjectInternal(string resourceKey, string cultureName)
        {
            IDictionary resources = GetResourceCache(cultureName);

            object value = null;

            if (resources == null)
            {
                value = null;
            }
            else
            {
                value = resources[resourceKey];
            }

            // If we're at a specific culture (en-Us) and there's no value fall back
            // to the generic culture (en)
            if (value == null && cultureName.Length > 3)
            {
                // try again with the 2 letter locale
                return(GetObjectInternal(resourceKey, cultureName.Substring(0, 2)));
            }

            // If the value is still null get the invariant value
            if (value == null)
            {
                resources = GetResourceCache("");
                if (resources == null)
                {
                    value = null;
                }
                else
                {
                    value = resources[resourceKey];
                }
            }

            // If the value is still null and we're at the invariant culture
            // let's add a marker that the value is missing
            // this also allows the pre-compiler to work and never return null
            if (value == null)
            {
                // No entry there
                value = resourceKey;

                // DEPENDENCY HERE (#2): using DbResourceConfiguration and DbResourceDataManager to optionally
                //                           add missing resource keys

                // Add a key in the repository at least for the Invariant culture
                // Something's referencing but nothing's there
                if (DbResourceConfiguration.Current.AddMissingResources)
                {
                    lock (_SyncLock)
                    {
                        if (resources[resourceKey] == null)
                        {
                            var data = new DbResourceDataManager();
                            if (!data.ResourceExists(resourceKey, "", _ResourceSetName))
                            {
                                data.AddResource(resourceKey, resourceKey, "",
                                                 _ResourceSetName, null);
                            }

                            // add to current invariant resource set
                            resources.Add(resourceKey, resourceKey);
                        }
                    }
                }
            }

            return(value);
        }