Exemplo n.º 1
0
 public virtual bool Initialize(string libpath, string reswFilename, out PRIExceptionInfo exceptionInfo){exceptionInfo = null; return false;}
Exemplo n.º 2
0
        // Obtain instances of the Resource Map and Resource Context provided by
        // the Windows Modern Resource Manager (MRM).

        // Not thread-safe. Only call this once on one thread for each object instance.
        // For example, System.Runtime.ResourceManager only calls this from its constructors,
        // guaranteeing that this only gets called once, on one thread, for each new instance
        // of System.Runtime.ResourceManager.

        // Throws exceptions
        // Only returns true if the function succeeded completely.
        // Outputs exceptionInfo since it may be needed for debugging purposes
        // if an exception is thrown by one of Initialize's callees.
        public override bool Initialize(string libpath, string reswFilename, out PRIExceptionInfo exceptionInfo)
        {
            Debug.Assert(libpath != null);
            Debug.Assert(reswFilename != null);
            exceptionInfo = null;

            if (InitializeStatics())
            {
                // AllResourceMaps can throw ERROR_MRM_MAP_NOT_FOUND,
                // although in that case we are not sure for which package it failed to find
                // resources (if we are looking for resources for a framework package,
                // it might throw ERROR_MRM_MAP_NOT_FOUND if the app package
                // resources could not be loaded, even if the framework package
                // resources are properly configured). So we will not fill in the
                // exceptionInfo structure at this point since we don't have any
                // reliable information to include in it.

                IReadOnlyDictionary <String, ResourceMap>
                resourceMapDictionary = s_globalResourceManager.AllResourceMaps;

                if (resourceMapDictionary != null)
                {
                    string packageSimpleName = FindPackageSimpleNameForFilename(libpath);

#if netstandard
                    // If we have found a simple package name for the assembly, lets make sure it is not *.resource.dll that
                    // an application may have packaged in its AppX. This is to enforce AppX apps to use PRI resources.
                    if (packageSimpleName != null)
                    {
                        if (packageSimpleName.EndsWith(".resources.dll", StringComparison.CurrentCultureIgnoreCase))
                        {
                            // Pretend we didn't get a package name. When an attempt is made to get resource string, GetString implementation
                            // will see that we are going to use modern resource manager but we don't have PRI and will thrown an exception indicating
                            // so. This will force the developer to have a valid PRI based resource.
                            packageSimpleName = null;
                        }
                    }
#endif //  netstandard
                    if (packageSimpleName != null)
                    {
                        ResourceMap packageResourceMap = null;

                        // Win8 enforces that package simple names are unique (for example, the App Store will not
                        // allow two apps with the same package simple name). That is why the Modern Resource Manager
                        // keys access to resources based on the package simple name.
                        if (resourceMapDictionary.TryGetValue(packageSimpleName, out packageResourceMap))
                        {
                            if (packageResourceMap != null)
                            {
                                // GetSubtree returns null when it cannot find resource strings
                                // named "reswFilename/*" for the package we are looking up.

                                reswFilename = UriUtility.UriEncode(reswFilename);
                                _resourceMap = packageResourceMap.GetSubtree(reswFilename);

                                if (_resourceMap == null)
                                {
                                    exceptionInfo = new PRIExceptionInfo();
                                    exceptionInfo._PackageSimpleName = packageSimpleName;
                                    exceptionInfo._ResWFile          = reswFilename;
                                }
                                else
                                {
                                    _clonedResourceContext = s_globalResourceContext.Clone();

                                    if (_clonedResourceContext != null)
                                    {
                                        // Will need to be changed the first time it is used. But we can't set it to "" since we will take a lock on it.
                                        _clonedResourceContextFallBackList = ReadOnlyListToString(_clonedResourceContext.Languages);

                                        if (_clonedResourceContextFallBackList != null)
                                        {
                                            return(true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }
        // Obtain instances of the Resource Map and Resource Context provided by
        // the Windows Modern Resource Manager (MRM).

        // Not thread-safe. Only call this once on one thread for each object instance.
        // For example, System.Runtime.ResourceManager only calls this from its constructors,
        // guaranteeing that this only gets called once, on one thread, for each new instance
        // of System.Runtime.ResourceManager.

        // Throws exceptions
        // Only returns true if the function succeeded completely.
        // Outputs exceptionInfo since it may be needed for debugging purposes
        // if an exception is thrown by one of Initialize's callees.
        public override bool Initialize(string libpath, string reswFilename, out PRIExceptionInfo exceptionInfo)
        {
            Debug.Assert(libpath != null);
            Debug.Assert(reswFilename != null);
            exceptionInfo = null;

            if (InitializeStatics())
            {
                // AllResourceMaps can throw ERROR_MRM_MAP_NOT_FOUND,
                // although in that case we are not sure for which package it failed to find
                // resources (if we are looking for resources for a framework package,
                // it might throw ERROR_MRM_MAP_NOT_FOUND if the app package
                // resources could not be loaded, even if the framework package
                // resources are properly configured). So we will not fill in the
                // exceptionInfo structure at this point since we don't have any
                // reliable information to include in it.

                IReadOnlyDictionary<String, ResourceMap>
                    resourceMapDictionary = s_globalResourceManager.AllResourceMaps;

                if (resourceMapDictionary != null)
                {
                    string packageSimpleName = FindPackageSimpleNameForFilename(libpath);

#if netstandard
                    // If we have found a simple package name for the assembly, lets make sure it is not *.resource.dll that
                    // an application may have packaged in its AppX. This is to enforce AppX apps to use PRI resources.
                    if (packageSimpleName != null)
                    {
                        if (packageSimpleName.EndsWith(".resources.dll", StringComparison.CurrentCultureIgnoreCase))
                        {
                            // Pretend we didnt get a package name. When an attempt is made to get resource string, GetString implementation
                            // will see that we are going to use modern resource manager but we dont have PRI and will thrown an exception indicating
                            // so. This will force the developer to have a valid PRI based resource.
                            packageSimpleName = null;
                        }
                    }
#endif //  netstandard
                    if (packageSimpleName != null)
                    {
                        ResourceMap packageResourceMap = null;

                        // Win8 enforces that package simple names are unique (for example, the App Store will not
                        // allow two apps with the same package simple name). That is why the Modern Resource Manager
                        // keys access to resources based on the package simple name.
                        if (resourceMapDictionary.TryGetValue(packageSimpleName, out packageResourceMap))
                        {
                            if (packageResourceMap != null)
                            {
                                // GetSubtree returns null when it cannot find resource strings
                                // named "reswFilename/*" for the package we are looking up.

                                reswFilename = UriUtility.UriEncode(reswFilename);
                                _resourceMap = packageResourceMap.GetSubtree(reswFilename);

                                if (_resourceMap == null)
                                {
                                    exceptionInfo = new PRIExceptionInfo();
                                    exceptionInfo._PackageSimpleName = packageSimpleName;
                                    exceptionInfo._ResWFile = reswFilename;
                                }
                                else
                                {
                                    _clonedResourceContext = s_globalResourceContext.Clone();

                                    if (_clonedResourceContext != null)
                                    {
                                        // Will need to be changed the first time it is used. But we can't set it to "" since we will take a lock on it.
                                        _clonedResourceContextFallBackList = ReadOnlyListToString(_clonedResourceContext.Languages);

                                        if (_clonedResourceContextFallBackList != null)
                                            return true;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return false;
        }
Exemplo n.º 4
0
 public virtual bool Initialize(string libpath, string reswFilename, out PRIExceptionInfo exceptionInfo)
 {
     exceptionInfo = (PRIExceptionInfo)null;
     return(false);
 }