/// <summary> /// Constructs and Initializes the static 'Current' DocumentProperties object which /// is the singleton instance. /// </summary> /// <param name="uri">The URI for the package.</param> internal static void InitializeCurrentDocumentProperties(Uri uri) { // Ensure that DocumentProperties has not been constructed yet, and initialize a // new instance. System.Diagnostics.Debug.Assert( Current == null, "DocumentProperties initialized twice."); if (Current == null) { _current = new DocumentProperties(uri); } }
/// <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); }
/// <summary> /// <see cref="MS.Internal.Documents.Application.IDocumentController"/> /// </summary> bool IDocumentController.Open(Document document) { FileDocument doc = (FileDocument)document; if (doc.Source == null) { try { doc.SourceProxy = DocumentStream.Open(doc, false); } catch (UnauthorizedAccessException uae) { FilePresentation.ShowNoAccessToSource(); doc.SourceProxy = null; Trace.SafeWrite( Trace.File, "Unable to open specified location.\nException: {0}", uae); return(false); } catch (IOException ioe) { FilePresentation.ShowNoAccessToSource(); doc.SourceProxy = null; Trace.SafeWrite( Trace.File, "Unable to open specified location.\nException: {0}", ioe); return(false); } } DocumentProperties.InitializeCurrentDocumentProperties(doc.Uri); return(true); }