Beispiel #1
0
        /// <summary>
        /// <see cref="MS.Internal.Documents.Application.IDocumentController"/>
        /// </summary>
        bool IDocumentController.Open(Document document)
        {
            PackageDocument doc = (PackageDocument)document;

            TransactionalPackage package = new RestrictedTransactionalPackage(
                doc.Source);

            doc.Package = package;

            DocumentProperties.Current.SetXpsProperties(package.PackageProperties);

            DocumentSignatureManager.Initialize(new DigitalSignatureProvider(package));

            // when signatures change (are added or removed) we can no longer simply copy bits on disk
            DocumentSignatureManager.Current.SignaturesChanged +=
                new EventHandler(
                    delegate(
                        object sender,
                        EventArgs args)
            {
                if (doc.IsFileCopySafe)
                {
                    Trace.SafeWrite(
                        Trace.Signatures,
                        "Disabling file copy for current document.");
                    doc.IsFileCopySafe = false;
                }
            });

            return(true);
        }
Beispiel #2
0
        //--------------------------------------------------------------------------
        // IDocumentController Members
        //--------------------------------------------------------------------------

        /// <summary>
        /// <see cref="MS.Internal.Documents.Application.IDocumentController"/>
        /// </summary>
        bool IDocumentController.EnableEdit(Document document)
        {
            PackageDocument doc = (PackageDocument)document;

            if (doc.Workspace != null)
            {
                doc.Package.EnableEditMode(doc.Workspace);
            }

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Creates the default chain of documents.  (PackageDocument,
        /// RightsDocument and FileDocument)
        /// </summary>
        /// <returns>A Document.</returns>
        internal static PackageDocument CreateDefaultDocument(
            Uri source, Stream stream)
        {
            PackageDocument doc = new PackageDocument(
                new RightsDocument(
                    new FileDocument(stream)));

            doc.Uri = source;

            return(doc);
        }
Beispiel #4
0
        /// <summary>
        /// <see cref="MS.Internal.Documents.Application.IDocumentController"/>
        /// </summary>
        bool IDocumentController.Rebind(Document document)
        {
            PackageDocument doc = (PackageDocument)document;

            if (doc.IsRebindNeeded)
            {
                doc.Package.Rebind(doc.Source);

                // no rebinds are needed above us for documents as package
                doc.IsRebindNeeded = false;
            }

            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// Creates the default chain of documents.  (PackageDocument,
        /// RightsDocument and FileDocument)
        /// </summary>
        /// <returns>A Document.</returns>
        internal static PackageDocument CreateDefaultDocument(
            Uri source, CriticalFileToken fileToken)
        {
            // because we have a fileToken we might be able to save
            _canSave = true;

            PackageDocument doc = new PackageDocument(
                new RightsDocument(
                    new FileDocument(fileToken)));

            doc.Uri = source;

            return(doc);
        }
Beispiel #6
0
        /// <summary>
        /// <see cref="MS.Internal.Documents.Application.IDocumentController"/>
        /// </summary>
        /// <remarks>
        /// This method severely breaks encapsulating the chain, however it does
        /// so because the requirement breaks encapsulation and the original design
        /// of the class only consider streams not properties.  The requirement is
        /// that as we transition to/from a protected document we copy properties
        /// between the layers.  It was least risk to compromise the design here
        /// then extend it.
        /// </remarks>
        bool IDocumentController.SavePreperation(Document document)
        {
            // we don't have to check packageDoc for because we are only responsible
            // for PackageDocuments
            PackageDocument packageDoc = (PackageDocument)document;
            RightsDocument  rightsDoc  = document.Dependency as RightsDocument;

            if (rightsDoc != null)
            {
                bool isDestinationProtected = rightsDoc.IsDestinationProtected();
                bool isSourceProtected      = rightsDoc.IsSourceProtected();

                // the only time we don't need to copy properties is when
                // neither source nor destination is protected as OPC properties
                // are copied as parts

                // if the source was protected and the destination is not
                // then we need to copy properties to the package
                if (isSourceProtected && !isDestinationProtected)
                {
                    DocumentProperties.Copy(
                        new SuppressedProperties(rightsDoc.SourcePackage),
                        packageDoc.Package.PackageProperties);
                }

                // if the source was not protected and the destination is
                // then we need to copy properties from the package to the envelope
                if (!isSourceProtected && isDestinationProtected)
                {
                    DocumentProperties.Copy(
                        packageDoc.Package.PackageProperties,
                        new SuppressedProperties(rightsDoc.DestinationPackage));
                }

                // if they were both protected we need to copy properties
                // from the old envelope to the new
                if (isDestinationProtected && isSourceProtected)
                {
                    DocumentProperties.Copy(
                        new SuppressedProperties(rightsDoc.SourcePackage),
                        new SuppressedProperties(rightsDoc.DestinationPackage));
                }
            }
            return(true);
        }
Beispiel #7
0
        /// <summary>
        /// <see cref="MS.Internal.Documents.Application.IDocumentController"/>
        /// <exception cref="System.InvalidOperationException"/>
        /// </summary>
        bool IDocumentController.SaveCommit(Document document)
        {
            PackageDocument doc = (PackageDocument)document;

            if (doc.Destination == null)
            {
                return(false);
            }

            if (doc.Package.IsDirty || !doc.IsDestinationIdenticalToSource)
            {
                StreamProxy source      = doc.Source as StreamProxy;
                StreamProxy destination = doc.Destination as StreamProxy;

                // this will catch the case where our source stream is our destination
                // stream, which would cause corruption of the package
                if (source.GetHashCode() == destination.GetHashCode())
                {
                    throw new InvalidOperationException(
                              SR.Get(SRID.PackageControllerStreamCorruption));
                }

                // this will catch the case where no one was able to copy the stream
                // thus the lengths will not match
                if (doc.Source.Length != doc.Destination.Length)
                {
                    throw new InvalidOperationException(
                              SR.Get(SRID.PackageControllerStreamCorruption));
                }

                // Flush the package to ensure that the relationship parts are
                // written out before changes are merged
                doc.Package.Flush();

                doc.Package.MergeChanges(doc.Destination);
                Trace.SafeWrite(Trace.File, "Destination Merged.");
            }
            else
            {
                Trace.SafeWrite(Trace.File, "Destination Merge Skipped (nothing to do).");
            }
            return(true);
        }