Ejemplo n.º 1
0
        //------------------------------------------------------
        //
        //  Internal Constructors
        //
        //------------------------------------------------------
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="obfuscatedStream">stream that holds obfuscated resource</param>
        /// <param name="streamUri">the original Uri which is used to obtain obfuscatedStream; it holds
        ///                         the GUID information which is used to obfuscate the resources</param>
        /// <param name="leaveOpen">if it is false, obfuscatedStream will be also disposed when
        ///                         DeobfuscatingStream is disposed</param>
        /// <remarks>streamUri has to be a pack Uri</remarks>
        internal DeobfuscatingStream(Stream obfuscatedStream, Uri streamUri, bool leaveOpen)
        {
            if (obfuscatedStream == null)
            {
                throw new ArgumentNullException("obfuscatedStream");
            }

            // Make sure streamUri is in the correct form; getting partUri from it will do all necessary checks for error
            //    conditions; We also have to make sure that it has a part name
            Uri partUri = PackUriHelper.GetPartUri(streamUri);

            if (partUri == null)
            {
                throw new InvalidOperationException(SR.Get(SRID.InvalidPartName));
            }

            // Normally we should use PackUriHelper.GetStringForPartUri to get the string representation of part Uri
            //    however, since we already made sure that streamUris is in the correct form (such as to check if it is an absolute Uri
            //    and there is a correct authority (package)), it doesn't have to be fully validated again.
            // Get the escaped string for the part name as part names should have only ascii characters
            String guid = Path.GetFileNameWithoutExtension(
                streamUri.GetComponents(UriComponents.Path | UriComponents.KeepDelimiter, UriFormat.UriEscaped));

            _guid                = GetGuidByteArray(guid);
            _obfuscatedStream    = obfuscatedStream;
            _ownObfuscatedStream = !leaveOpen;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Resolves the target uri in the relationship against the source part or the
        /// package root. This resolved Uri is then used by the Add method to figure
        /// out if a relationship is being created to another relationship part.
        /// </summary>
        /// <param name="target">PackageRelationship target uri</param>
        /// <param name="targetMode"> Enum value specifying the interpretation of the base uri
        /// for the relationship target uri</param>
        /// <returns>Resolved Uri</returns>
        private Uri GetResolvedTargetUri(Uri target, TargetMode targetMode)
        {
            if (targetMode == TargetMode.Internal)
            {
                Debug.Assert(!target.IsAbsoluteUri, "Uri should be relative at this stage");

                if (_sourcePart == null) //indicates that the source is the package root
                {
                    return(PackUriHelper.ResolvePartUri(PackUriHelper.PackageRootUri, target));
                }
                else
                {
                    return(PackUriHelper.ResolvePartUri(_sourcePart.Uri, target));
                }
            }
            else
            {
                if (target.IsAbsoluteUri)
                {
                    if (String.CompareOrdinal(target.Scheme, PackUriHelper.UriSchemePack) == 0)
                    {
                        return(PackUriHelper.GetPartUri(target));
                    }
                }
                else
                {
                    Debug.Assert(false, "Uri should not be relative at this stage");
                }
            }
            // relative to the location of the package.
            return(target);
        }