Beispiel #1
0
        private string GetString(StringResourceReference resourceReference)
        {
            LoadingResult         result;
            AssemblyBindingStatus bindingStatus;

            return(GetStringHelper(resourceReference, out result, out bindingStatus));
        }
 internal void VerifyResource(
     StringResourceReference resourceReference,
     out DisplayResourceManagerCache.LoadingResult result,
     out DisplayResourceManagerCache.AssemblyBindingStatus bindingStatus)
 {
     this.GetStringHelper(resourceReference, out result, out bindingStatus);
 }
Beispiel #3
0
 /// <summary>
 /// Get a reference to an assembly object by looking up the currently loaded assemblies.
 /// </summary>
 /// <param name="resourceReference">the string resource reference object containing
 /// the name of the assembly to load</param>
 /// <param name="foundInGac"> true if assembly was found in the GAC. NOTE: the current
 /// implementation always return FALSE</param>
 /// <returns></returns>
 private Assembly LoadAssemblyFromResourceReference(StringResourceReference resourceReference, out bool foundInGac)
 {
     // NOTE: we keep the function signature as and the calling code is able do deal
     // with dynamically loaded assemblies. If this functionality is implemented, this
     // method will have to be changed accordingly
     foundInGac = false; // it always be false, since we return already loaded assemblies
     return(_assemblyNameResolver.ResolveAssemblyName(resourceReference.assemblyName));
 }
Beispiel #4
0
        private string GetStringHelper(StringResourceReference resourceReference, out LoadingResult result, out AssemblyBindingStatus bindingStatus)
        {
            result        = LoadingResult.AssemblyNotFound;
            bindingStatus = AssemblyBindingStatus.NotFound;
            AssemblyLoadResult result2 = null;

            if (this._resourceReferenceToAssemblyCache.Contains(resourceReference))
            {
                result2       = this._resourceReferenceToAssemblyCache[resourceReference] as AssemblyLoadResult;
                bindingStatus = result2.status;
            }
            else
            {
                bool flag;
                result2 = new AssemblyLoadResult {
                    a = this.LoadAssemblyFromResourceReference(resourceReference, out flag)
                };
                if (result2.a == null)
                {
                    result2.status = AssemblyBindingStatus.NotFound;
                }
                else
                {
                    result2.status = flag ? AssemblyBindingStatus.FoundInGac : AssemblyBindingStatus.FoundInPath;
                }
                this._resourceReferenceToAssemblyCache.Add(resourceReference, result2);
            }
            bindingStatus = result2.status;
            if (result2.a == null)
            {
                result = LoadingResult.AssemblyNotFound;
                return(null);
            }
            try
            {
                string str = ResourceManagerCache.GetResourceString(result2.a, resourceReference.baseName, resourceReference.resourceId);
                if (str == null)
                {
                    result = LoadingResult.StringNotFound;
                    return(null);
                }
                result = LoadingResult.NoError;
                return(str);
            }
            catch (InvalidOperationException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (MissingManifestResourceException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }
 private string GetStringHelper(StringResourceReference resourceReference, out LoadingResult result, out AssemblyBindingStatus bindingStatus)
 {
     result = LoadingResult.AssemblyNotFound;
     bindingStatus = AssemblyBindingStatus.NotFound;
     AssemblyLoadResult result2 = null;
     if (this._resourceReferenceToAssemblyCache.Contains(resourceReference))
     {
         result2 = this._resourceReferenceToAssemblyCache[resourceReference] as AssemblyLoadResult;
         bindingStatus = result2.status;
     }
     else
     {
         bool flag;
         result2 = new AssemblyLoadResult {
             a = this.LoadAssemblyFromResourceReference(resourceReference, out flag)
         };
         if (result2.a == null)
         {
             result2.status = AssemblyBindingStatus.NotFound;
         }
         else
         {
             result2.status = flag ? AssemblyBindingStatus.FoundInGac : AssemblyBindingStatus.FoundInPath;
         }
         this._resourceReferenceToAssemblyCache.Add(resourceReference, result2);
     }
     bindingStatus = result2.status;
     if (result2.a == null)
     {
         result = LoadingResult.AssemblyNotFound;
         return null;
     }
     try
     {
         string str = ResourceManagerCache.GetResourceString(result2.a, resourceReference.baseName, resourceReference.resourceId);
         if (str == null)
         {
             result = LoadingResult.StringNotFound;
             return null;
         }
         result = LoadingResult.NoError;
         return str;
     }
     catch (InvalidOperationException)
     {
         result = LoadingResult.ResourceNotFound;
     }
     catch (MissingManifestResourceException)
     {
         result = LoadingResult.ResourceNotFound;
     }
     catch (Exception)
     {
         throw;
     }
     return null;
 }
        private void ReportStringResourceFailure(StringResourceReference resource, DisplayResourceManagerCache.LoadingResult result, DisplayResourceManagerCache.AssemblyBindingStatus bindingStatus)
        {
            string assemblyName;
            switch (bindingStatus)
            {
                case DisplayResourceManagerCache.AssemblyBindingStatus.FoundInGac:
                    assemblyName = StringUtil.Format(FormatAndOutXmlLoadingStrings.AssemblyInGAC, resource.assemblyName);
                    break;

                case DisplayResourceManagerCache.AssemblyBindingStatus.FoundInPath:
                    assemblyName = Path.Combine(resource.loadingInfo.fileDirectory, resource.assemblyName);
                    break;

                default:
                    assemblyName = resource.assemblyName;
                    break;
            }
            string message = null;
            switch (result)
            {
                case DisplayResourceManagerCache.LoadingResult.AssemblyNotFound:
                    message = StringUtil.Format(FormatAndOutXmlLoadingStrings.AssemblyNotFound, new object[] { base.ComputeCurrentXPath(), base.FilePath, assemblyName });
                    break;

                case DisplayResourceManagerCache.LoadingResult.ResourceNotFound:
                    message = StringUtil.Format(FormatAndOutXmlLoadingStrings.ResourceNotFound, new object[] { base.ComputeCurrentXPath(), base.FilePath, resource.baseName, assemblyName });
                    break;

                case DisplayResourceManagerCache.LoadingResult.StringNotFound:
                    message = StringUtil.Format(FormatAndOutXmlLoadingStrings.StringResourceNotFound, new object[] { base.ComputeCurrentXPath(), base.FilePath, resource.resourceId, resource.baseName, assemblyName });
                    break;
            }
            base.ReportError(message);
        }
 private bool LoadStringResourceReference(System.Xml.XmlNode n, out StringResourceReference resource)
 {
     resource = null;
     XmlElement element = n as XmlElement;
     if (element == null)
     {
         base.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.NonXmlElementNode, base.ComputeCurrentXPath(), base.FilePath));
         return false;
     }
     if (element.Attributes.Count <= 0)
     {
         return true;
     }
     resource = this.LoadResourceAttributes(element.Attributes);
     return (resource != null);
 }
 private StringResourceReference LoadResourceAttributes(XmlAttributeCollection attributes)
 {
     StringResourceReference resourceReference = new StringResourceReference();
     foreach (System.Xml.XmlAttribute attribute in attributes)
     {
         if (base.MatchAttributeName(attribute, "AssemblyName"))
         {
             resourceReference.assemblyName = base.GetMandatoryAttributeValue(attribute);
             if (resourceReference.assemblyName == null)
             {
                 return null;
             }
         }
         else if (base.MatchAttributeName(attribute, "BaseName"))
         {
             resourceReference.baseName = base.GetMandatoryAttributeValue(attribute);
             if (resourceReference.baseName == null)
             {
                 return null;
             }
         }
         else if (base.MatchAttributeName(attribute, "ResourceId"))
         {
             resourceReference.resourceId = base.GetMandatoryAttributeValue(attribute);
             if (resourceReference.resourceId == null)
             {
                 return null;
             }
         }
         else
         {
             base.ProcessUnknownAttribute(attribute);
             return null;
         }
     }
     if (resourceReference.assemblyName == null)
     {
         base.ReportMissingAttribute("AssemblyName");
         return null;
     }
     if (resourceReference.baseName == null)
     {
         base.ReportMissingAttribute("BaseName");
         return null;
     }
     if (resourceReference.resourceId == null)
     {
         base.ReportMissingAttribute("ResourceId");
         return null;
     }
     resourceReference.loadingInfo = base.LoadingInfo;
     if (base.VerifyStringResources)
     {
         DisplayResourceManagerCache.LoadingResult result;
         DisplayResourceManagerCache.AssemblyBindingStatus status;
         base.displayResourceManagerCache.VerifyResource(resourceReference, out result, out status);
         if (result != DisplayResourceManagerCache.LoadingResult.NoError)
         {
             this.ReportStringResourceFailure(resourceReference, result, status);
             return null;
         }
     }
     return resourceReference;
 }
Beispiel #9
0
        private void ReportStringResourceFailure(StringResourceReference resource,
                                                    DisplayResourceManagerCache.LoadingResult result,
                                                    DisplayResourceManagerCache.AssemblyBindingStatus bindingStatus)
        {
            string assemblyDisplayName;
            switch (bindingStatus)
            {
                case DisplayResourceManagerCache.AssemblyBindingStatus.FoundInPath:
                    {
                        assemblyDisplayName =
                            System.IO.Path.Combine(resource.loadingInfo.fileDirectory, resource.assemblyName);
                    }
                    break;
                case DisplayResourceManagerCache.AssemblyBindingStatus.FoundInGac:
                    {
                        //"(Global Assembly Cache) {0}"
                        assemblyDisplayName = StringUtil.Format(FormatAndOutXmlLoadingStrings.AssemblyInGAC, resource.assemblyName);
                    }
                    break;
                default:
                    {
                        assemblyDisplayName = resource.assemblyName;
                    }
                    break;
            }

            string msg = null;
            switch (result)
            {
                case DisplayResourceManagerCache.LoadingResult.AssemblyNotFound:
                    {
                        //Error at XPath {0} in file {1}: Assembly {2} is not found.
                        msg = StringUtil.Format(FormatAndOutXmlLoadingStrings.AssemblyNotFound, ComputeCurrentXPath(), FilePath, assemblyDisplayName);
                    }
                    break;
                case DisplayResourceManagerCache.LoadingResult.ResourceNotFound:
                    {
                        //Error at XPath {0} in file {1}: Resource {2} in assembly {3} is not found.
                        msg = StringUtil.Format(FormatAndOutXmlLoadingStrings.ResourceNotFound, ComputeCurrentXPath(), FilePath, resource.baseName, assemblyDisplayName);
                    }
                    break;
                case DisplayResourceManagerCache.LoadingResult.StringNotFound:
                    {
                        //Error at XPath {0} in file {1}: String {2} from resource {3} in assembly {4} is not found.
                        msg = StringUtil.Format(FormatAndOutXmlLoadingStrings.StringResourceNotFound, ComputeCurrentXPath(), FilePath,
                            resource.resourceId, resource.baseName, assemblyDisplayName);
                    }
                    break;
            }
            this.ReportError(msg);
        }
Beispiel #10
0
        private StringResourceReference LoadResourceAttributes(XmlAttributeCollection attributes)
        {
            StringResourceReference resource = new StringResourceReference();
            foreach (XmlAttribute a in attributes)
            {
                if (MatchAttributeName(a, XmlTags.AssemblyNameAttribute))
                {
                    resource.assemblyName = GetMandatoryAttributeValue(a);
                    if (resource.assemblyName == null)
                        return null;
                }
                else if (MatchAttributeName(a, XmlTags.BaseNameAttribute))
                {
                    resource.baseName = GetMandatoryAttributeValue(a);
                    if (resource.baseName == null)
                        return null;
                }
                else if (MatchAttributeName(a, XmlTags.ResourceIdAttribute))
                {
                    resource.resourceId = GetMandatoryAttributeValue(a);
                    if (resource.resourceId == null)
                        return null;
                }
                else
                {
                    ProcessUnknownAttribute(a);
                    return null;
                }
            }

            // make sure we got all the attributes, since allof them are mandatory
            if (resource.assemblyName == null)
            {
                ReportMissingAttribute(XmlTags.AssemblyNameAttribute);
                return null;
            }
            if (resource.baseName == null)
            {
                ReportMissingAttribute(XmlTags.BaseNameAttribute);
                return null;
            }
            if (resource.resourceId == null)
            {
                ReportMissingAttribute(XmlTags.ResourceIdAttribute);
                return null;
            }

            // success in loading
            resource.loadingInfo = this.LoadingInfo;


            // optional pre-load and binding verification
            if (this.VerifyStringResources)
            {
                DisplayResourceManagerCache.LoadingResult result;
                DisplayResourceManagerCache.AssemblyBindingStatus bindingStatus;
                this.displayResourceManagerCache.VerifyResource(resource, out result, out bindingStatus);
                if (result != DisplayResourceManagerCache.LoadingResult.NoError)
                {
                    ReportStringResourceFailure(resource, result, bindingStatus);
                    return null;
                }
            }

            return resource;
        }
 private Assembly LoadAssemblyFromResourceReference(StringResourceReference resourceReference, out bool foundInGac)
 {
     foundInGac = false;
     return this._assemblyNameResolver.ResolveAssemblyName(resourceReference.assemblyName);
 }
 private string GetString(StringResourceReference resourceReference)
 {
     LoadingResult result;
     AssemblyBindingStatus bindingStatus;
     return GetStringHelper(resourceReference, out result, out bindingStatus);
 }
 internal void VerifyResource(StringResourceReference resourceReference, out LoadingResult result, out AssemblyBindingStatus bindingStatus)
 {
     GetStringHelper(resourceReference, out result, out bindingStatus);
 }
 /// <summary>
 /// Get a reference to an assembly object by looking up the currently loaded assemblies
 /// </summary>
 /// <param name="resourceReference">the string resource reference object containing
 /// the name of the assembly to load</param>
 /// <param name="foundInGac"> true if assembly was found in the GAC. NOTE: the current
 /// implementation always return FALSE</param>
 /// <returns></returns>
 private Assembly LoadAssemblyFromResourceReference(StringResourceReference resourceReference, out bool foundInGac)
 {
     // NOTE: we keep the function signature as and the calling code is able do deal
     // with dynamically loaded assemblies. If this functionality is implemented, this
     // method will have to be changed accordingly
     foundInGac = false; // it always be false, since we return already loaded assemblies
     return _assemblyNameResolver.ResolveAssemblyName(resourceReference.assemblyName);
 }
Beispiel #15
0
 private Assembly LoadAssemblyFromResourceReference(StringResourceReference resourceReference, out bool foundInGac)
 {
     foundInGac = false;
     return(this._assemblyNameResolver.ResolveAssemblyName(resourceReference.assemblyName));
 }
 private string GetString(StringResourceReference resourceReference) => this.GetStringHelper(resourceReference, out DisplayResourceManagerCache.LoadingResult _, out DisplayResourceManagerCache.AssemblyBindingStatus _);
Beispiel #17
0
 internal void VerifyResource(StringResourceReference resourceReference, out LoadingResult result, out AssemblyBindingStatus bindingStatus)
 {
     GetStringHelper(resourceReference, out result, out bindingStatus);
 }
        private string GetStringHelper(StringResourceReference resourceReference, out LoadingResult result, out AssemblyBindingStatus bindingStatus)
        {
            result = LoadingResult.AssemblyNotFound;
            bindingStatus = AssemblyBindingStatus.NotFound;

            AssemblyLoadResult loadResult = null;
            // try first to see if we have an assembly reference in the cache
            if (_resourceReferenceToAssemblyCache.Contains(resourceReference))
            {
                loadResult = _resourceReferenceToAssemblyCache[resourceReference] as AssemblyLoadResult;
                bindingStatus = loadResult.status;
            }
            else
            {
                loadResult = new AssemblyLoadResult();
                // we do not have an assembly, we try to load it
                bool foundInGac;
                loadResult.a = LoadAssemblyFromResourceReference(resourceReference, out foundInGac);
                if (loadResult.a == null)
                {
                    loadResult.status = AssemblyBindingStatus.NotFound;
                }
                else
                {
                    loadResult.status = foundInGac ? AssemblyBindingStatus.FoundInGac : AssemblyBindingStatus.FoundInPath;
                }

                // add to the cache even if null
                _resourceReferenceToAssemblyCache.Add(resourceReference, loadResult);
            }

            bindingStatus = loadResult.status;

            if (loadResult.a == null)
            {
                // we failed the assembly loading
                result = LoadingResult.AssemblyNotFound;
                return null;
            }


            // load now the resource from the resource manager cache
            try
            {
                string val = ResourceManagerCache.GetResourceString(loadResult.a, resourceReference.baseName, resourceReference.resourceId);
                if (val == null)
                {
                    result = LoadingResult.StringNotFound;
                    return null;
                }
                else
                {
                    result = LoadingResult.NoError;
                    return val;
                }
            }
            catch (InvalidOperationException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (MissingManifestResourceException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (Exception e) // will rethrow
            {
                Diagnostics.Assert(false, "ResourceManagerCache.GetResourceString unexpected exception " + e.GetType().FullName);
                throw;
            }
            return null;
        }
Beispiel #19
0
        private string GetStringHelper(StringResourceReference resourceReference, out LoadingResult result, out AssemblyBindingStatus bindingStatus)
        {
            result        = LoadingResult.AssemblyNotFound;
            bindingStatus = AssemblyBindingStatus.NotFound;

            AssemblyLoadResult loadResult = null;

            // try first to see if we have an assembly reference in the cache
            if (_resourceReferenceToAssemblyCache.Contains(resourceReference))
            {
                loadResult    = _resourceReferenceToAssemblyCache[resourceReference] as AssemblyLoadResult;
                bindingStatus = loadResult.status;
            }
            else
            {
                loadResult = new AssemblyLoadResult();
                // we do not have an assembly, we try to load it
                bool foundInGac;
                loadResult.a = LoadAssemblyFromResourceReference(resourceReference, out foundInGac);
                if (loadResult.a == null)
                {
                    loadResult.status = AssemblyBindingStatus.NotFound;
                }
                else
                {
                    loadResult.status = foundInGac ? AssemblyBindingStatus.FoundInGac : AssemblyBindingStatus.FoundInPath;
                }

                // add to the cache even if null
                _resourceReferenceToAssemblyCache.Add(resourceReference, loadResult);
            }

            bindingStatus = loadResult.status;

            if (loadResult.a == null)
            {
                // we failed the assembly loading
                result = LoadingResult.AssemblyNotFound;
                return(null);
            }
            else
            {
                resourceReference.assemblyLocation = loadResult.a.Location;
            }

            // load now the resource from the resource manager cache
            try
            {
                string val = ResourceManagerCache.GetResourceString(loadResult.a, resourceReference.baseName, resourceReference.resourceId);
                if (val == null)
                {
                    result = LoadingResult.StringNotFound;
                    return(null);
                }
                else
                {
                    result = LoadingResult.NoError;
                    return(val);
                }
            }
            catch (InvalidOperationException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (MissingManifestResourceException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (Exception e) // will rethrow
            {
                Diagnostics.Assert(false, "ResourceManagerCache.GetResourceString unexpected exception " + e.GetType().FullName);
                throw;
            }

            return(null);
        }
Beispiel #20
0
        private bool LoadStringResourceReference(XmlNode n, out StringResourceReference resource)
        {
            resource = null;
            XmlElement e = n as XmlElement;

            if (e == null)
            {
                //Error at XPath {0} in file {1}: Node should be an XmlElement.
                this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.NonXmlElementNode, ComputeCurrentXPath(), FilePath));
                return false;
            }

            if (e.Attributes.Count <= 0)
            {
                // no resources to load
                return true;
            }

            // need to find mandatory attributes
            resource = LoadResourceAttributes(e.Attributes);

            // we committed to having resources, if not obtained, it's an error
            return resource != null;
        }