GetPackageUri() public static method

public static GetPackageUri ( Uri packUri ) : Uri
packUri Uri
return Uri
Esempio n. 1
0
 static BaseUriHelper()
 {
     _baseUri = new SecurityCriticalDataForSet <Uri>(_packAppBaseUri);
     // Add an instance of the ResourceContainer to PreloadedPackages so that PackWebRequestFactory can find it
     // and mark it as thread-safe so PackWebResponse won't protect returned streams with a synchronizing wrapper
     PreloadedPackages.AddPackage(PackUriHelper.GetPackageUri(SiteOfOriginBaseUri), new SiteOfOriginContainer(), true);
 }
Esempio n. 2
0
        static internal Uri MakeRelativeToSiteOfOriginIfPossible(Uri sUri)
        {
            if (Uri.Compare(sUri, SiteOfOriginBaseUri, UriComponents.Scheme, UriFormat.UriEscaped, StringComparison.OrdinalIgnoreCase) == 0)
            {
                Uri packageUri = PackUriHelper.GetPackageUri(sUri);
                if (String.Compare(packageUri.GetComponents(UriComponents.AbsoluteUri, UriFormat.UriEscaped), _packageSiteOfOriginBaseUriEscaped, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return((new Uri(sUri.GetComponents(UriComponents.SchemeAndServer, UriFormat.UriEscaped))).MakeRelativeUri(sUri));
                }
            }

            return(sUri);
        }
Esempio n. 3
0
        /// <summary>
        /// Checks whether the input uri is in the "pack://application:,,," form
        /// </summary>
        internal static bool IsPackApplicationUri(Uri uri)
        {
            return
                // Is the "outer" URI absolute?
                (uri.IsAbsoluteUri &&

                 // Does the "outer" URI have the pack: scheme?
                 SecurityHelper.AreStringTypesEqual(uri.Scheme, System.IO.Packaging.PackUriHelper.UriSchemePack) &&

                 // Does the "inner" URI have the application: scheme
                 SecurityHelper.AreStringTypesEqual(
                     PackUriHelper.GetPackageUri(uri).GetComponents(UriComponents.AbsoluteUri, UriFormat.UriEscaped),
                     _packageApplicationBaseUriEscaped));
        }
Esempio n. 4
0
        /// <summary>
        /// rootElement == null: Load elements, validation of root element will occur in caller by checking object type or casting
        /// rootElement != null: Only perform validation, and expect rootElement at root of markup
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="parentUri"></param>
        /// <param name="pc"></param>
        /// <param name="mimeType"></param>
        /// <param name="rootElement"></param>
        /// <returns></returns>
        private object Load(Stream stream, Uri parentUri, ParserContext pc, ContentType mimeType, string rootElement)
        {
            object obj = null;

            if (!DocumentMode)
            {                       // Loose XAML, just check against schema, don't check content type
                if (rootElement == null)
                {
                    obj = XamlReader.Load(stream, pc);
                }
            }
            else
            {                       // inside an XPS Document. Perform maximum validation
                XpsSchema schema = XpsSchema.GetSchema(mimeType);
                Uri       uri    = pc.BaseUri;

                Uri packageUri = PackUriHelper.GetPackageUri(uri);
                Uri partUri    = PackUriHelper.GetPartUri(uri);

                Package package = PreloadedPackages.GetPackage(packageUri);

                Uri parentPackageUri = null;

                if (parentUri != null)
                {
                    parentPackageUri = PackUriHelper.GetPackageUri(parentUri);
                    if (!parentPackageUri.Equals(packageUri))
                    {
                        throw new FileFormatException(SR.Get(SRID.XpsValidatingLoaderUriNotInSamePackage));
                    }
                }

                schema.ValidateRelationships(new SecurityCriticalData <Package>(package), packageUri, partUri, mimeType);

                if (schema.AllowsMultipleReferencesToSameUri(mimeType))
                {
                    _uniqueUriRef = null;
                }
                else
                {
                    _uniqueUriRef = new Hashtable(11);
                }

                Hashtable validResources = (_validResources.Count > 0 ? _validResources.Peek() : null);
                if (schema.HasRequiredResources(mimeType))
                {
                    validResources = new Hashtable(11);

                    PackagePart part = package.GetPart(partUri);
                    PackageRelationshipCollection requiredResources = part.GetRelationshipsByType(_requiredResourceRel);

                    foreach (PackageRelationship relationShip in requiredResources)
                    {
                        Uri targetUri    = PackUriHelper.ResolvePartUri(partUri, relationShip.TargetUri);
                        Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri);

                        PackagePart targetPart = package.GetPart(targetUri);

                        if (schema.IsValidRequiredResourceMimeType(targetPart.ValidatedContentType()))
                        {
                            if (!validResources.ContainsKey(absTargetUri))
                            {
                                validResources.Add(absTargetUri, true);
                            }
                        }
                        else
                        {
                            if (!validResources.ContainsKey(absTargetUri))
                            {
                                validResources.Add(absTargetUri, false);
                            }
                        }
                    }
                }

                XpsSchemaValidator xpsSchemaValidator = new XpsSchemaValidator(this, schema, mimeType,
                                                                               stream, packageUri, partUri);
                _validResources.Push(validResources);
                if (rootElement != null)
                {
                    xpsSchemaValidator.XmlReader.MoveToContent();

                    if (!rootElement.Equals(xpsSchemaValidator.XmlReader.Name))
                    {
                        throw new FileFormatException(SR.Get(SRID.XpsValidatingLoaderUnsupportedMimeType));
                    }

                    while (xpsSchemaValidator.XmlReader.Read())
                    {
                        ;
                    }
                }
                else
                {
                    obj = XamlReader.Load(xpsSchemaValidator.XmlReader,
                                          pc,
                                          XamlParseMode.Synchronous);
                }
                _validResources.Pop();
            }

            return(obj);
        }