//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ // None //------------------------------------------------------ // // Internal Events // //------------------------------------------------------ // None //------------------------------------------------------ // // Protected Constructors // //------------------------------------------------------ // None //------------------------------------------------------ // // Protected Methods // //------------------------------------------------------ #region Protected Methods // <summary> // This method creates a part containing the name of the resource and // the resource manager that should contain it. If the resource manager // does not contain the requested part then when GetStream() is called on // the part it will return null. // </summary> // <param name="uri"></param> // <returns></returns> protected override PackagePart GetPartCore(Uri uri) { string partName; bool isContentFile; // AppDomain.AssemblyLoad event handler for standalone apps. This is added specifically for designer (Sparkle) scenario. // We use the assembly name to fetch the cached resource manager. With this mechanism we will still get resource from the // old version dll when a newer one is loaded. So whenever the AssemblyLoad event is fired, we will need to update the cache // with the newly loaded assembly. This is currently only for designer so not needed for browser hosted apps. // Attach the event handler before the first time we get the ResourceManagerWrapper. if (!assemblyLoadhandlerAttached) { AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(OnAssemblyLoadEventHandler); assemblyLoadhandlerAttached = true; } ResourceManagerWrapper rmWrapper = GetResourceManagerWrapper(uri, out partName, out isContentFile); // If the part name was specified as Content at compile time then we will try to load // the file directly. Otherwise we assume the user is looking for a resource. if (isContentFile) { return(new ContentFilePart(this, uri)); } else { // Uri mapps to a resource stream. // Make sure the resource id is exactly same as the one we used to create Resource // at compile time. partName = ResourceIDHelper.GetResourceIDFromRelativePath(partName); return(new ResourcePart(this, uri, partName, rmWrapper)); } }
protected override PackagePart GetPartCore(Uri uri) { if (!ResourceContainer.assemblyLoadhandlerAttached && !BrowserInteropHelper.IsBrowserHosted) { AppDomain.CurrentDomain.AssemblyLoad += this.OnAssemblyLoadEventHandler; ResourceContainer.assemblyLoadhandlerAttached = true; } string resourceIDFromRelativePath; bool flag; ResourceManagerWrapper resourceManagerWrapper = this.GetResourceManagerWrapper(uri, out resourceIDFromRelativePath, out flag); if (flag) { return(new ContentFilePart(this, uri)); } resourceIDFromRelativePath = ResourceIDHelper.GetResourceIDFromRelativePath(resourceIDFromRelativePath); return(new ResourcePart(this, uri, resourceIDFromRelativePath, resourceManagerWrapper)); }
// This is 200-300 ms slower than Assembly.GetManifestResourceStream() but works with localization. private UnmanagedMemoryStream GetResourceStream() { // Try to get the stream with the string the developer supplied, in the app.g.cs case // this will always work. UnmanagedMemoryStream stream = _resourceManager.GetStream(_resourceName, System.Globalization.CultureInfo.CurrentUICulture); if (stream != null) { return(stream); } // IF that fails then the resource name had special characters in it which would not // be encoded literally into the resource stream. Unfortunately we need to rely on the // slow URI class to get the correct name. We try to avoid doing this in the common case // since URI has quite a bit of code associated with it. string resourceName = ResourceIDHelper.GetResourceIDFromRelativePath(_resourceName); return(_resourceManager.GetStream(resourceName, System.Globalization.CultureInfo.CurrentUICulture)); }
internal static string GetResourceIdForResourceFile( string filePath, string linkAlias, string logicalName, string outputPath, string sourceDir, bool requestExtensionChange) { string relPath = String.Empty; // Please note the subtle distinction between <Link /> and <LogicalName />. // <Link /> is treated as a fully resolvable path and is put through the same // transformations as the original file path. <LogicalName /> on the other hand // is treated as an alias for the given resource and is used as is. Whether <Link /> // was meant to be treated thus is debatable. Nevertheless in .Net 4.5 it would // amount to a breaking change to have to change the behavior of <Link /> and // hence the choice to support <LogicalName /> with the desired semantics. All // said in most of the regular scenarios using <Link /> or <Logical /> will result in // the same resourceId being picked. if (!String.IsNullOrEmpty(logicalName)) { // Use the LogicalName when there is one logicalName = ReplaceXAMLWithBAML(filePath, logicalName, requestExtensionChange); relPath = logicalName; } else { // Always use the Link tag if it's specified. // This is the way the resource appears in the project. linkAlias = ReplaceXAMLWithBAML(filePath, linkAlias, requestExtensionChange); filePath = !string.IsNullOrEmpty(linkAlias) ? linkAlias : filePath; string fullFilePath = Path.GetFullPath(filePath); // // If the resFile, or it's perceived path, is relative to the StagingDir // (OutputPath here) take the relative path as resource id. // If the resFile is not relative to StagingDir, but relative // to the project directory, take this relative path as resource id. // Otherwise, just take the file name as resource id. // relPath = TaskHelper.GetRootRelativePath(outputPath, fullFilePath); if (string.IsNullOrEmpty(relPath)) { relPath = TaskHelper.GetRootRelativePath(sourceDir, fullFilePath); } if (string.IsNullOrEmpty(relPath)) { relPath = Path.GetFileName(fullFilePath); } } // Modify resource ID to correspond to canonicalized Uri format // i.e. - all lower case, use "/" as separator // ' ' is converted to escaped version %20 // string resourceId = ResourceIDHelper.GetResourceIDFromRelativePath(relPath); return(resourceId); }