Esempio n. 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));
        }
        private static Uri GetStructureUriFromRelationship(Uri contentUri, string relationshipName)
        {
            Uri result = null;

            if (contentUri != null && relationshipName != null)
            {
                Uri partUri = PackUriHelper.GetPartUri(contentUri);
                if (partUri != null)
                {
                    Uri     packageUri = PackUriHelper.GetPackageUri(contentUri);
                    Package package    = PreloadedPackages.GetPackage(packageUri);
                    if (package == null && SecurityHelper.CheckEnvironmentPermission())
                    {
                        package = PackageStore.GetPackage(packageUri);
                    }
                    if (package != null)
                    {
                        PackagePart part = package.GetPart(partUri);
                        PackageRelationshipCollection relationshipsByType = part.GetRelationshipsByType(relationshipName);
                        Uri uri = null;
                        foreach (PackageRelationship packageRelationship in relationshipsByType)
                        {
                            uri = PackUriHelper.ResolvePartUri(partUri, packageRelationship.TargetUri);
                        }
                        if (uri != null)
                        {
                            result = PackUriHelper.Create(packageUri, uri);
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 3
0
        ///<summary>
        /// <see cref="XmlUrlResolver.GetEntity"/>
        ///</summary>
        public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
        {
            ofObjectToReturn.DbC_Assure(value => value == typeof(Stream));

            switch (absoluteUri.Scheme)
            {
            case "resource":
                return(Resources.GetStream(absoluteUri.AbsolutePath));

            case "dynamic":
                string ResourceName = absoluteUri.Host;
                if (this.dynamicContent.ContainsKey(ResourceName))
                {
                    return(new MemoryStream(Encoding.Unicode.GetBytes(this.dynamicContent[ResourceName])));
                }
                else
                {
                    throw new ArgumentException($"Dynamic content not found: {ResourceName}");
                }

            case "pack":
                return(Package
                       .Open((Stream)this.GetEntity(PackUriHelper.GetPackageUri(absoluteUri), null, typeof(Stream)))
                       .GetPart(PackUriHelper.GetPartUri(absoluteUri)).GetStream());

            default:
                return(base.GetEntity(absoluteUri, role, ofObjectToReturn));
            }
        }
Esempio n. 4
0
        public void GetPartUriTest()
        {
            var pack      = PackUriHelper.Create(new Uri("http://www.test.com/pack1.pkg"));
            var part      = new Uri("/main.html", UriKind.Relative);
            var pack_part = new Uri(@"pack://pack:,,http:%2C%2Cwww.test.com%2Cpack1.pkg,/main.html");

            Assert.IsNull(PackUriHelper.GetPartUri(pack), "#1");
            Assert.AreEqual(pack_part, PackUriHelper.Create(pack, part), "#2");
            Assert.AreEqual(part, PackUriHelper.GetPartUri(PackUriHelper.Create(pack, part)), "#3");
        }
Esempio n. 5
0
        private static object LoadComponentFromAssembly(Uri uri)
        {
#if NETCOREAPP3_0
            var method = typeof(PackUriHelper).GetMethod("ValidateAndGetPackUriComponents",
                                                         BindingFlags.NonPublic | BindingFlags.Static);
            var args = new object[3];
            args[0] = uri;
            method.Invoke(null, args);
            var partUri = (Uri)args[2];
            return(partUri);
#else
            return(Application.LoadComponent(PackUriHelper.GetPartUri(uri)));
#endif
        }
Esempio n. 6
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
            }));
        }
Esempio n. 7
0
 private static object LoadComponentFromAssembly(Uri uri)
 {
     return(Application.LoadComponent(PackUriHelper.GetPartUri(uri)));
 }
Esempio n. 8
0
 public void GetPartUriTest3()
 {
     PackUriHelper.GetPartUri(part1);
 }
Esempio n. 9
0
 public void GetPartUriTest2()
 {
     PackUriHelper.GetPartUri(null);
 }
Esempio n. 10
0
 public void GetPartUriTest()
 {
     Assert.IsNull(PackUriHelper.GetPartUri(a), "#1");
     Assert.AreEqual(main, PackUriHelper.GetPartUri(PackUriHelper.Create(a, main)), "#2");
 }
Esempio n. 11
0
 public void DeletePart(Uri packUri)
 {
     this.package.DeletePart(PackUriHelper.GetPartUri(packUri));
 }
Esempio n. 12
0
 protected override IEnumerable <string> GetPaths()
 {
     return(_package.GetParts()
            .Select(p => PackUriHelper.GetPartUri(p.Uri).ToString().TrimStart('\\'))
            .Where(p => !string.Equals(p, _manifestPath, StringComparison.OrdinalIgnoreCase)));
 }