Esempio n. 1
0
 public void CanCreateFlatOpcPresentationDocuments()
 {
     using (var inputStream = GetStream(TestFiles.Presentation))
         using (var source = PresentationDocument.Open(inputStream, false))
         {
             var flatOpcDoc = source.ToFlatOpcDocument();
             using (var dest = PresentationDocument.FromFlatOpcDocument(flatOpcDoc))
             {
                 PackageAssert.Equal(source, dest);
             }
         }
 }
        public void CanCreateFlatOpcPresentationDocuments()
        {
            using (var source = PresentationDocument.Open(Path.Combine(TestUtil.TestResultsDirectory, PresentationPath), true))
            {
                // Test FlatOpcDocument methods.
                // Check ToFlatOpcDocument() and FromFlatOpcDocument(XDocument).
                var flatOpcDoc = source.ToFlatOpcDocument();
                using (var dest = PresentationDocument.FromFlatOpcDocument(flatOpcDoc))
                    AssertThatPackagesAreEqual(source, dest);

                // Check FromFlatOpcDocument(XDocument, Stream, bool).
                using (Stream stream = new MemoryStream())
                    using (PresentationDocument.FromFlatOpcDocument(flatOpcDoc, stream, false))
                        using (var dest = PresentationDocument.Open(stream, false))
                            AssertThatPackagesAreEqual(source, dest);

                // Check FromFlatOpcDocument(XDocument, string, bool).
                using (PresentationDocument.FromFlatOpcDocument(flatOpcDoc, Path.Combine(TestUtil.TestResultsDirectory, PresentationClonePath), false))
                    using (var dest = PresentationDocument.Open(Path.Combine(TestUtil.TestResultsDirectory, PresentationClonePath), false))
                        AssertThatPackagesAreEqual(source, dest);

                // Check FromFlatOpcDocument(XDocument, Package).
                using (var stream = new MemoryStream())
                    using (var package = Package.Open(stream, FileMode.Create, FileAccess.ReadWrite))
                        using (var dest = PresentationDocument.FromFlatOpcDocument(flatOpcDoc, package))
                            AssertThatPackagesAreEqual(source, dest);

                // Test FlatOpcString methods.
                // Check ToFlatOpcString() and FromFlatOpcString(string).
                var flatOpcString = source.ToFlatOpcString();
                using (var dest = PresentationDocument.FromFlatOpcString(flatOpcString))
                    AssertThatPackagesAreEqual(source, dest);

                // Check FromFlatOpcString(string, Stream, bool).
                using (Stream stream = new MemoryStream())
                    using (PresentationDocument.FromFlatOpcString(flatOpcString, stream, false))
                        using (var dest = PresentationDocument.Open(stream, false))
                            AssertThatPackagesAreEqual(source, dest);

                // Check FromFlatOpcString(string, string, bool).
                using (PresentationDocument.FromFlatOpcString(flatOpcString, Path.Combine(TestUtil.TestResultsDirectory, PresentationClonePath), false))
                    using (var dest = PresentationDocument.Open(Path.Combine(TestUtil.TestResultsDirectory, PresentationClonePath), false))
                        AssertThatPackagesAreEqual(source, dest);

                // Check FromFlatOpcString(string, Package).
                using (var stream = new MemoryStream())
                    using (var package = Package.Open(stream, FileMode.Create, FileAccess.ReadWrite))
                        using (var dest = PresentationDocument.FromFlatOpcString(flatOpcString, package))
                            AssertThatPackagesAreEqual(source, dest);
            }
        }
Esempio n. 3
0
        public void CanCreateFlatOpcPresentationDocuments4()
        {
            using (var inputStream = GetStream(TestFiles.Presentation))
                using (var source = PresentationDocument.Open(inputStream, false))
                {
                    using (var stream = new MemoryStream())
                        using (var package = Package.Open(stream, FileMode.Create, FileAccess.ReadWrite))
                        {
                            var flatOpcDoc = source.ToFlatOpcDocument();

                            using (var dest = PresentationDocument.FromFlatOpcDocument(flatOpcDoc, package))
                            {
                                PackageAssert.Equal(source, dest);
                            }
                        }
                }
        }
        /// <summary>
        /// Creates a new instance of DocumentType from a Flat OPC <see cref="XDocument" />.
        /// </summary>
        /// <param name="document">The Flat OPC <see cref="XDocument" />.</param>
        /// <typeparam name="TDocument">A subclass of <see cref="OpenXmlPackage" />.</typeparam>
        /// <returns>A new instance of DocumentType</returns>
        public static TDocument FromFlatOpcDocument <TDocument>(XDocument document)
            where TDocument : OpenXmlPackage
        {
            var t = typeof(TDocument);

            if (t == typeof(WordprocessingDocument))
            {
                return(WordprocessingDocument.FromFlatOpcDocument(document) as TDocument);
            }
            if (t == typeof(SpreadsheetDocument))
            {
                return(SpreadsheetDocument.FromFlatOpcDocument(document) as TDocument);
            }
            if (t == typeof(PresentationDocument))
            {
                return(PresentationDocument.FromFlatOpcDocument(document) as TDocument);
            }
            throw new OpenXmlTransformationException("Unsupported document type: " + t);
        }