コード例 #1
0
        // Constructs a Resource Manager for files beginning with
        // baseName in the directory specified by resourceDir
        // or in the current directory.  This Assembly-ignorant constructor is
        // mostly useful for testing your own ResourceSet implementation.
        //
        // A good example of a baseName might be "Strings".  BaseName
        // should not end in ".resources".
        //
        // Note: System.Windows.Forms uses this method at design time.
        //
        private ResourceManager(string baseName, string resourceDir, Type usingResourceSet)
        {
            if (null == baseName)
            {
                throw new ArgumentNullException(nameof(baseName));
            }
            if (null == resourceDir)
            {
                throw new ArgumentNullException(nameof(resourceDir));
            }

            BaseNameField = baseName;

            moduleDir        = resourceDir;
            _userResourceSet = usingResourceSet;
#pragma warning disable 618
            ResourceSets = new Hashtable(); // for backward compatibility
#pragma warning restore 618
            _resourceSets          = new Dictionary <string, ResourceSet>();
            _lastUsedResourceCache = new CultureNameResourceSetPair();
            UseManifest            = false;

            ResourceManagerMediator mediator = new ResourceManagerMediator(this);
            resourceGroveler = new FileBasedResourceGroveler(mediator);
        }
コード例 #2
0
        protected ResourceManager()
        {
            _lastUsedResourceCache = new CultureNameResourceSetPair();
            ResourceManagerMediator mediator = new ResourceManagerMediator(this);

            resourceGroveler = new ManifestBasedResourceGroveler(mediator);
        }
コード例 #3
0
        // Trying to unify code as much as possible, even though having to do a
        // security check in each constructor prevents it.
        private void CommonAssemblyInit()
        {
            // Now we can use the managed resources even when using PRI's to support the APIs GetObject, GetStream...etc.
            UseManifest = true;

            _resourceSets          = new Dictionary <string, ResourceSet>();
            _lastUsedResourceCache = new CultureNameResourceSetPair();

            _fallbackLoc = UltimateResourceFallbackLocation.MainAssembly;

            ResourceManagerMediator mediator = new ResourceManagerMediator(this);

            resourceGroveler = new ManifestBasedResourceGroveler(mediator);

            _neutralResourcesCulture = ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(MainAssembly, ref _fallbackLoc);
        }
コード例 #4
0
        // Tells the ResourceManager to call Close on all ResourceSets and
        // release all resources.  This will shrink your working set by
        // potentially a substantial amount in a running application.  Any
        // future resource lookups on this ResourceManager will be as
        // expensive as the very first lookup, since it will need to search
        // for files and load resources again.
        //
        // This may be useful in some complex threading scenarios, where
        // creating a new ResourceManager isn't quite the correct behavior.
        public virtual void ReleaseAllResources()
        {
            Dictionary <string, ResourceSet> localResourceSets = _resourceSets;

            // If any calls to Close throw, at least leave ourselves in a
            // consistent state.
            _resourceSets          = new Dictionary <string, ResourceSet>();
            _lastUsedResourceCache = new CultureNameResourceSetPair();

            lock (localResourceSets)
            {
                foreach ((_, ResourceSet resourceSet) in localResourceSets)
                {
                    resourceSet.Close();
                }
            }
        }
コード例 #5
0
        // Trying to unify code as much as possible, even though having to do a
        // security check in each constructor prevents it.
        private void CommonAssemblyInit()
        {
#if FEATURE_APPX || ENABLE_WINRT
            SetUapConfiguration();
#endif

            // Now we can use the managed resources even when using PRI's to support the APIs GetObject, GetStream...etc.
            _useManifest = true;

            _resourceSets          = new Dictionary <string, ResourceSet>();
            _lastUsedResourceCache = new CultureNameResourceSetPair();

            ResourceManagerMediator mediator = new ResourceManagerMediator(this);
            _resourceGroveler = new ManifestBasedResourceGroveler(mediator);

            _neutralResourcesCulture = ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(MainAssembly, out _fallbackLoc);
        }
コード例 #6
0
        // Constructs a Resource Manager for files beginning with
        // baseName in the directory specified by resourceDir
        // or in the current directory.  This Assembly-ignorant constructor is
        // mostly useful for testing your own ResourceSet implementation.
        //
        // A good example of a baseName might be "Strings".  BaseName
        // should not end in ".resources".
        //
        // Note: System.Windows.Forms uses this method at design time.
        //
        private ResourceManager(string baseName, string resourceDir, Type usingResourceSet)
        {
            if (null == baseName)
            {
                throw new ArgumentNullException(nameof(baseName));
            }
            if (null == resourceDir)
            {
                throw new ArgumentNullException(nameof(resourceDir));
            }

            BaseNameField = baseName;

            _moduleDir             = resourceDir;
            _userResourceSet       = usingResourceSet;
            _resourceSets          = new Dictionary <string, ResourceSet>();
            _lastUsedResourceCache = new CultureNameResourceSetPair();
            _useManifest           = false;

            ResourceManagerMediator mediator = new ResourceManagerMediator(this);

            _resourceGroveler = new FileBasedResourceGroveler(mediator);
        }
コード例 #7
0
        // Tells the ResourceManager to call Close on all ResourceSets and 
        // release all resources.  This will shrink your working set by
        // potentially a substantial amount in a running application.  Any
        // future resource lookups on this ResourceManager will be as 
        // expensive as the very first lookup, since it will need to search
        // for files and load resources again.
        // 
        // This may be useful in some complex threading scenarios, where 
        // creating a new ResourceManager isn't quite the correct behavior.
        public virtual void ReleaseAllResources()
        {
#if !FEATURE_CORECLR
            if (FrameworkEventSource.IsInitialized)
            {
                FrameworkEventSource.Log.ResourceManagerReleasingResources(BaseNameField, MainAssembly);
            }
#endif
            Dictionary<String, ResourceSet> localResourceSets = _resourceSets;

            // If any calls to Close throw, at least leave ourselves in a
            // consistent state.
            _resourceSets = new Dictionary<String,ResourceSet>();
            _lastUsedResourceCache = new CultureNameResourceSetPair();
            
            lock(localResourceSets) {
                IDictionaryEnumerator setEnum = localResourceSets.GetEnumerator();

#if !FEATURE_CORECLR
                IDictionaryEnumerator setEnum2 = null;
#pragma warning disable 618
                if (ResourceSets != null) {
                    setEnum2 = ResourceSets.GetEnumerator();
                }
                ResourceSets = new Hashtable(); // for backwards compat
#pragma warning restore 618
#endif

                while (setEnum.MoveNext()) {
                    ((ResourceSet)setEnum.Value).Close();
                }

#if !FEATURE_CORECLR
                if (setEnum2 != null) {
                    while (setEnum2.MoveNext()) {
                        ((ResourceSet)setEnum2.Value).Close();
                    }
                }
#endif
            }
        }
コード例 #8
0
        private void CommonAssemblyInit()
        {
            if (_bUsingModernResourceManagement == false)
            {
                UseManifest = true;
        
                _resourceSets = new Dictionary<String,ResourceSet>();
                _lastUsedResourceCache = new CultureNameResourceSetPair();

                _fallbackLoc = UltimateResourceFallbackLocation.MainAssembly;

                ResourceManagerMediator mediator = new ResourceManagerMediator(this);
                resourceGroveler = new ManifestBasedResourceGroveler(mediator);
            }

            _neutralResourcesCulture = ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(MainAssembly, ref _fallbackLoc);

#if !FEATURE_CORECLR   // PAL doesn't support eventing, and we don't compile event providers for coreclr
            if (_bUsingModernResourceManagement == false)
            {
                if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled()) {
                    CultureInfo culture = CultureInfo.InvariantCulture;
                    String defaultResName = GetResourceFileName(culture);

                    if (resourceGroveler.HasNeutralResources(culture, defaultResName)) {
                        FrameworkEventSource.Log.ResourceManagerNeutralResourcesFound(BaseNameField, MainAssembly, defaultResName);
                    }
                    else {
                        String outputResName = defaultResName;
                        if (_locationInfo != null && _locationInfo.Namespace != null)
                            outputResName = _locationInfo.Namespace + Type.Delimiter + defaultResName;
                        FrameworkEventSource.Log.ResourceManagerNeutralResourcesNotFound(BaseNameField, MainAssembly, outputResName);
                    }
                }

#pragma warning disable 618
                ResourceSets = new Hashtable(); // for backward compatibility
#pragma warning restore 618
            }
#endif
        }
コード例 #9
0
        private void OnDeserialized(StreamingContext ctx)
        {
            _resourceSets = new Dictionary<String, ResourceSet>();
            _lastUsedResourceCache = new CultureNameResourceSetPair();
            // set up resource groveler, depending on whether this ResourceManager
            // is looking for files or assemblies
            ResourceManagerMediator mediator = new ResourceManagerMediator(this);
            if (UseManifest)
            {
                resourceGroveler = new ManifestBasedResourceGroveler(mediator);
            }
            else
            {
                resourceGroveler = new FileBasedResourceGroveler(mediator);
            }

            // correct callingAssembly for v2
            if (this.m_callingAssembly == null)
            {
                this.m_callingAssembly = (RuntimeAssembly)_callingAssembly;
            }

            // v2 does this lazily
            if (UseManifest && this._neutralResourcesCulture == null)
            {
                _neutralResourcesCulture = ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(MainAssembly, ref _fallbackLoc);
            }
        }
コード例 #10
0
 private void OnDeserializing(StreamingContext ctx)
 {
     this._resourceSets = null;
     this.resourceGroveler = null;
     this._lastUsedResourceCache = null;
 }
コード例 #11
0
        // Constructs a Resource Manager for files beginning with 
        // baseName in the directory specified by resourceDir
        // or in the current directory.  This Assembly-ignorant constructor is 
        // mostly useful for testing your own ResourceSet implementation.
        //
        // A good example of a baseName might be "Strings".  BaseName 
        // should not end in ".resources".
        //
        // Note: System.Windows.Forms uses this method at design time.
        // 
        private ResourceManager(String baseName, String resourceDir, Type usingResourceSet) {
            if (null==baseName)
                throw new ArgumentNullException("baseName");
            if (null==resourceDir)
                throw new ArgumentNullException("resourceDir");
            Contract.EndContractBlock();

#if !FEATURE_CORECLR
            // This constructor is not designed to be used under AppX and is not in the Win8 profile.
            // However designers may use them even if they are running under AppX since they are
            // not subject to the restrictions of the Win8 profile.
            Contract.Assert(!AppDomain.IsAppXModel() || AppDomain.IsAppXDesignMode());
#endif

            BaseNameField = baseName;

            moduleDir = resourceDir;
            _userResourceSet = usingResourceSet;
#pragma warning disable 618
            ResourceSets = new Hashtable(); // for backward compatibility
#pragma warning restore 618
            _resourceSets = new Dictionary<String, ResourceSet>();
            _lastUsedResourceCache = new CultureNameResourceSetPair();
            UseManifest = false;

            ResourceManagerMediator mediator = new ResourceManagerMediator(this);
            resourceGroveler = new FileBasedResourceGroveler(mediator);

#if !FEATURE_CORECLR   // PAL doesn't support eventing, and we don't compile event providers for coreclr
            if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled()) {
                CultureInfo culture = CultureInfo.InvariantCulture;
                String defaultResName = GetResourceFileName(culture);

                if (resourceGroveler.HasNeutralResources(culture, defaultResName)) {
                    FrameworkEventSource.Log.ResourceManagerNeutralResourcesFound(BaseNameField, MainAssembly, defaultResName);
                }
                else {
                    FrameworkEventSource.Log.ResourceManagerNeutralResourcesNotFound(BaseNameField, MainAssembly, defaultResName);
                }
            }           
#endif
        }
コード例 #12
0
        protected ResourceManager() 
        {
#if !FEATURE_CORECLR
            // This constructor is not designed to be used under AppX and is not in the Win8 profile.
            // However designers may use them even if they are running under AppX since they are
            // not subject to the restrictions of the Win8 profile.
            Contract.Assert(!AppDomain.IsAppXModel() || AppDomain.IsAppXDesignMode());
#endif

            Init();

            _lastUsedResourceCache = new CultureNameResourceSetPair();
            ResourceManagerMediator mediator = new ResourceManagerMediator(this);
            resourceGroveler = new ManifestBasedResourceGroveler(mediator);
        }
コード例 #13
0
ファイル: ResourceManager.cs プロジェクト: kouvel/coreclr
        // Tells the ResourceManager to call Close on all ResourceSets and 
        // release all resources.  This will shrink your working set by
        // potentially a substantial amount in a running application.  Any
        // future resource lookups on this ResourceManager will be as 
        // expensive as the very first lookup, since it will need to search
        // for files and load resources again.
        // 
        // This may be useful in some complex threading scenarios, where 
        // creating a new ResourceManager isn't quite the correct behavior.
        public virtual void ReleaseAllResources()
        {
            Dictionary<String, ResourceSet> localResourceSets = _resourceSets;

            // If any calls to Close throw, at least leave ourselves in a
            // consistent state.
            _resourceSets = new Dictionary<String,ResourceSet>();
            _lastUsedResourceCache = new CultureNameResourceSetPair();
            
            lock(localResourceSets) {
                IDictionaryEnumerator setEnum = localResourceSets.GetEnumerator();

                while (setEnum.MoveNext()) {
                    ((ResourceSet)setEnum.Value).Close();
                }
            }
        }
コード例 #14
0
ファイル: ResourceManager.cs プロジェクト: kouvel/coreclr
        // Trying to unify code as much as possible, even though having to do a
        // security check in each constructor prevents it.
        private void CommonAssemblyInit()
        {
            if (_bUsingModernResourceManagement == false)
            {
                UseManifest = true;
        
                _resourceSets = new Dictionary<String,ResourceSet>();
                _lastUsedResourceCache = new CultureNameResourceSetPair();

                _fallbackLoc = UltimateResourceFallbackLocation.MainAssembly;

                ResourceManagerMediator mediator = new ResourceManagerMediator(this);
                resourceGroveler = new ManifestBasedResourceGroveler(mediator);
            }

            _neutralResourcesCulture = ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(MainAssembly, ref _fallbackLoc);
        }
コード例 #15
0
ファイル: ResourceManager.cs プロジェクト: kouvel/coreclr
        // Constructs a Resource Manager for files beginning with 
        // baseName in the directory specified by resourceDir
        // or in the current directory.  This Assembly-ignorant constructor is 
        // mostly useful for testing your own ResourceSet implementation.
        //
        // A good example of a baseName might be "Strings".  BaseName 
        // should not end in ".resources".
        //
        // Note: System.Windows.Forms uses this method at design time.
        // 
        private ResourceManager(String baseName, String resourceDir, Type usingResourceSet) {
            if (null==baseName)
                throw new ArgumentNullException(nameof(baseName));
            if (null==resourceDir)
                throw new ArgumentNullException(nameof(resourceDir));
            Contract.EndContractBlock();

            BaseNameField = baseName;

            moduleDir = resourceDir;
            _userResourceSet = usingResourceSet;
#pragma warning disable 618
            ResourceSets = new Hashtable(); // for backward compatibility
#pragma warning restore 618
            _resourceSets = new Dictionary<String, ResourceSet>();
            _lastUsedResourceCache = new CultureNameResourceSetPair();
            UseManifest = false;

            ResourceManagerMediator mediator = new ResourceManagerMediator(this);
            resourceGroveler = new FileBasedResourceGroveler(mediator);
        }
コード例 #16
0
ファイル: ResourceManager.cs プロジェクト: kouvel/coreclr
        protected ResourceManager() 
        {
            Init();

            _lastUsedResourceCache = new CultureNameResourceSetPair();
            ResourceManagerMediator mediator = new ResourceManagerMediator(this);
            resourceGroveler = new ManifestBasedResourceGroveler(mediator);
        }