// <summary> // Creates an object instance from a Baml stream and it's Uri // </summary> internal static object BamlConverter(Stream stream, Uri baseUri, bool canUseTopLevelBrowser, bool sandboxExternalContent, bool allowAsync, bool isJournalNavigation, out XamlReader asyncObjectConverter) { asyncObjectConverter = null; // If this stream comes from outside the application throw // if (!BaseUriHelper.IsPackApplicationUri(baseUri)) { throw new InvalidOperationException(SR.Get(SRID.BamlIsNotSupportedOutsideOfApplicationResources)); } // If this stream comes from a content file also throw Uri partUri = PackUriHelper.GetPartUri(baseUri); string partName, assemblyName, assemblyVersion, assemblyKey; BaseUriHelper.GetAssemblyNameAndPart(partUri, out partName, out assemblyName, out assemblyVersion, out assemblyKey); if (ContentFileHelper.IsContentFile(partName)) { throw new InvalidOperationException(SR.Get(SRID.BamlIsNotSupportedOutsideOfApplicationResources)); } ParserContext pc = new ParserContext(); pc.BaseUri = baseUri; pc.SkipJournaledProperties = isJournalNavigation; return(Application.LoadBamlStreamWithSyncInfo(stream, pc)); }
// <summary> // Searches the available ResourceManagerWrapper list for one that matches the given Uri. // It could be either ResourceManagerWrapper for specific libary assembly or Application // main assembly. Package enforces that all Uri will be correctly formated. // </summary> // <param name="uri">Assumed to be relative</param> // <param name="partName">The name of the file in the resource manager</param> // <param name="isContentFile">A flag to indicate that this path is a known loose file at compile time</param> // <returns></returns> private ResourceManagerWrapper GetResourceManagerWrapper(Uri uri, out string partName, out bool isContentFile) { string assemblyName; string assemblyVersion; string assemblyKey; ResourceManagerWrapper rmwResult = ApplicationResourceManagerWrapper; isContentFile = false; BaseUriHelper.GetAssemblyNameAndPart(uri, out partName, out assemblyName, out assemblyVersion, out assemblyKey); if (!String.IsNullOrEmpty(assemblyName)) { string key = assemblyName + assemblyVersion + assemblyKey; _registeredResourceManagers.TryGetValue(key.ToLowerInvariant(), out rmwResult); // first time. Add this to the hash table if (rmwResult == null) { Assembly assembly; assembly = BaseUriHelper.GetLoadedAssembly(assemblyName, assemblyVersion, assemblyKey); if (assembly.Equals(Application.ResourceAssembly)) { // This Uri maps to Application Entry assembly even though it has ";component". rmwResult = ApplicationResourceManagerWrapper; } else { rmwResult = new ResourceManagerWrapper(assembly); } _registeredResourceManagers[key.ToLowerInvariant()] = rmwResult; } } if ((rmwResult == ApplicationResourceManagerWrapper)) { if (rmwResult != null) { // If this is not a resource from a component then it might be // a content file and not an application resource. if (ContentFileHelper.IsContentFile(partName)) { isContentFile = true; rmwResult = null; } } else { // Throw when Application.ResourceAssembly is null. throw new IOException(SR.Get(SRID.EntryAssemblyIsNull)); } } return(rmwResult); }
protected override Stream GetStreamCore(FileMode mode, FileAccess access) { Stream stream = null; if (_fullPath == null) { // File name will be a path relative to the applications directory. // - We do not want to use SiteOfOriginContainer.SiteOfOrigin because // for deployed files the <Content> files are deployed with the application. Uri codeBase = GetEntryAssemblyLocation(); string assemblyName, assemblyVersion, assemblyKey; string filePath; // For now, only Application assembly supports content files, // so we can simply ignore the assemblyname etc. // In the future, we may extend this support for regular library assembly, // assemblyName will be used to predict the right file path. BaseUriHelper.GetAssemblyNameAndPart(Uri, out filePath, out assemblyName, out assemblyVersion, out assemblyKey); // filePath should not have leading slash. GetAssemblyNameAndPart( ) can guarantee it. Uri file = new Uri(codeBase, filePath); _fullPath = file.LocalPath; } stream = CriticalOpenFile(_fullPath); if (stream == null) { throw new IOException(SR.Get(SRID.UnableToLocateResource, Uri.ToString())); } return(stream); }
// Token: 0x06007A52 RID: 31314 RVA: 0x0022AA1C File Offset: 0x00228C1C private ResourceManagerWrapper GetResourceManagerWrapper(Uri uri, out string partName, out bool isContentFile) { ResourceManagerWrapper resourceManagerWrapper = ResourceContainer.ApplicationResourceManagerWrapper; isContentFile = false; string text; string text2; string text3; BaseUriHelper.GetAssemblyNameAndPart(uri, out partName, out text, out text2, out text3); if (!string.IsNullOrEmpty(text)) { string text4 = text + text2 + text3; ResourceContainer._registeredResourceManagers.TryGetValue(text4.ToLowerInvariant(), out resourceManagerWrapper); if (resourceManagerWrapper == null) { Assembly loadedAssembly = BaseUriHelper.GetLoadedAssembly(text, text2, text3); if (loadedAssembly.Equals(Application.ResourceAssembly)) { resourceManagerWrapper = ResourceContainer.ApplicationResourceManagerWrapper; } else { resourceManagerWrapper = new ResourceManagerWrapper(loadedAssembly); } ResourceContainer._registeredResourceManagers[text4.ToLowerInvariant()] = resourceManagerWrapper; } } if (resourceManagerWrapper == ResourceContainer.ApplicationResourceManagerWrapper) { if (resourceManagerWrapper == null) { throw new IOException(SR.Get("EntryAssemblyIsNull")); } if (ContentFileHelper.IsContentFile(partName)) { isContentFile = true; resourceManagerWrapper = null; } } return(resourceManagerWrapper); }
// Token: 0x06007A63 RID: 31331 RVA: 0x0022AD08 File Offset: 0x00228F08 internal static object BamlConverter(Stream stream, Uri baseUri, bool canUseTopLevelBrowser, bool sandboxExternalContent, bool allowAsync, bool isJournalNavigation, out XamlReader asyncObjectConverter) { asyncObjectConverter = null; if (!BaseUriHelper.IsPackApplicationUri(baseUri)) { throw new InvalidOperationException(SR.Get("BamlIsNotSupportedOutsideOfApplicationResources")); } Uri partUri = PackUriHelper.GetPartUri(baseUri); string partName; string text; string text2; string text3; BaseUriHelper.GetAssemblyNameAndPart(partUri, out partName, out text, out text2, out text3); if (ContentFileHelper.IsContentFile(partName)) { throw new InvalidOperationException(SR.Get("BamlIsNotSupportedOutsideOfApplicationResources")); } return(Application.LoadBamlStreamWithSyncInfo(stream, new ParserContext { BaseUri = baseUri, SkipJournaledProperties = isJournalNavigation })); }
protected override Stream GetStreamCore(FileMode mode, FileAccess access) { if (this._fullPath == null) { Uri entryAssemblyLocation = this.GetEntryAssemblyLocation(); string relativeUri; string text; string text2; string text3; BaseUriHelper.GetAssemblyNameAndPart(base.Uri, out relativeUri, out text, out text2, out text3); Uri uri = new Uri(entryAssemblyLocation, relativeUri); this._fullPath = uri.LocalPath; } Stream stream = this.CriticalOpenFile(this._fullPath); if (stream == null) { throw new IOException(SR.Get("UnableToLocateResource", new object[] { base.Uri.ToString() })); } return(stream); }