예제 #1
0
        // <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));
        }
예제 #2
0
        internal static bool IsEnumerableFontUriScheme(Uri fontLocation)
        {
            bool isEnumerable = false;

            // We only support file:// and pack:// application Uris to reference logical fonts.
            if (fontLocation.IsAbsoluteUri)
            {
                if (fontLocation.IsFile)
                {
                    // file scheme is always enumerable
                    isEnumerable = true;
                }
                else if (fontLocation.Scheme == PackUriHelper.UriSchemePack)
                {
                    // This is just an arbitrary file name which we use to construct a file URI.
                    const string fakeFileName = "X";

                    // The fontLocation could be a folder-like URI even though the pack scheme does not allow this.
                    // We simulate the concept of subfolders for packaged fonts. Before calling any PackUriHelper
                    // methods, create a Uri which we know to be a file-like (rather than folder-like) URI.
                    Uri fileUri;
                    if (Uri.TryCreate(fontLocation, fakeFileName, out fileUri))
                    {
                        isEnumerable = BaseUriHelper.IsPackApplicationUri(fileUri);
                    }
                }
            }

            return(isEnumerable);
        }
예제 #3
0
        // 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
            }));
        }
예제 #4
0
        internal static List <string> LookupFolder(Uri uri)
        {
            // The input URI may specify a folder which is invalid for pack URIs. If so,
            // create a valid pack URI by adding a fake filename.
            bool isFolder = IsFolderUri(uri);

            if (isFolder)
            {
                uri = new Uri(uri, FakeFileName);
            }

            // The input Uri should now be a valid absolute pack application Uri.
            // The caller (FontSourceCollection) guarantees that.
            // Perform a sanity check to make sure the assumption stays the same.
            Debug.Assert(uri.IsAbsoluteUri && uri.Scheme == PackUriHelper.UriSchemePack && BaseUriHelper.IsPackApplicationUri(uri));

            Assembly uriAssembly;
            string   escapedPath;

            BaseUriHelper.GetAssemblyAndPartNameFromPackAppUri(uri, out uriAssembly, out escapedPath);

            if (uriAssembly == null)
            {
                return(null);
            }

            // If we added a fake filename to the uri, remove it from the escaped path.
            if (isFolder)
            {
                Debug.Assert(escapedPath.EndsWith(FakeFileName, StringComparison.OrdinalIgnoreCase));
                escapedPath = escapedPath.Substring(0, escapedPath.Length - FakeFileName.Length);
            }

            Dictionary <string, List <string> > folderResourceMap;

            lock (_assemblyCaches)
            {
                if (!_assemblyCaches.TryGetValue(uriAssembly, out folderResourceMap))
                {
                    folderResourceMap = new Dictionary <string, List <string> >(StringComparer.OrdinalIgnoreCase);
                    ConstructFontResourceCache(uriAssembly, folderResourceMap);
                    _assemblyCaches.Add(uriAssembly, folderResourceMap);
                }
            }

            List <string> ret;

            folderResourceMap.TryGetValue(escapedPath, out ret);
            return(ret);
        }