コード例 #1
0
        public void Recomposition_PartDefWithNonRecomposableImportIsRemoved_ExportsMatchingImportChanged_ShouldNotBeRejected()
        {
            string dependencyContractName = "dependency";
            var    exportValue            = new object();

            var exporterPart = PartFactory.CreateExporter(dependencyContractName, exportValue);
            var importerPart = PartFactory.CreateImporter(dependencyContractName, false);

            var exporterCatalog = CatalogFactory.Create(exporterPart);
            var importerCatalog = CatalogFactory.Create(importerPart);

            var aggregateCatalog = CatalogFactory.CreateAggregateCatalog(importerCatalog, exporterCatalog);

            var provider = new CatalogExportProvider(aggregateCatalog);

            provider.SourceProvider = provider;

            var exports = provider.GetExports(importerPart.ImportDefinitions.Single());

            Assert.AreEqual(exportValue, importerPart.Value, "Importer was not composed");

            aggregateCatalog.Catalogs.Remove(importerCatalog);
            aggregateCatalog.Catalogs.Remove(exporterCatalog);

            Assert.AreEqual(exportValue, importerPart.Value, "Importer was unexpectedly recomposed");
        }
コード例 #2
0
        public void Dispose_CanBeCalledMultipleTimes()
        {
            var catalog = CatalogFactory.Create();

            catalog.Dispose();
            catalog.Dispose();
            catalog.Dispose();
        }
コード例 #3
0
        public void GetExports_NullAsConstraintArgument_ShouldThrowArgumentNull()
        {
            var catalog = CatalogFactory.Create();

            Assert.Throws <ArgumentNullException>("definition", () =>
            {
                catalog.GetExports((ImportDefinition)null);
            });
        }
コード例 #4
0
        private static CompositionContainer GetContainer(Dependency partADependency, Dependency partBDependency)
        {
            var partA = CreatePartA(partADependency);
            var partB = CreatePartB(partBDependency);

            var catalog = CatalogFactory.Create(partA, partB);

            return(ContainerFactory.Create(catalog));
        }
コード例 #5
0
        public void GetExports_WhenDisposed_ShouldThrowObjectDisposed()
        {
            var catalog = CatalogFactory.Create();

            catalog.Dispose();
            var definition = ImportDefinitionFactory.Create();

            ExceptionAssert.ThrowsDisposed(catalog, () =>
            {
                catalog.GetExports(definition);
            });
        }
コード例 #6
0
        /// <summary>
        /// Merge the set of PDF documents.
        /// </summary>
        public static byte[] Merge(IReadOnlyList <byte[]> files, IReadOnlyList <IReadOnlyList <int> > pagesBundle = null)
        {
            if (files == null)
            {
                throw new ArgumentNullException(nameof(files));
            }

            const bool isLenientParsing = false;

            var documentBuilder = new DocumentMerger();

            foreach (var fileIndex in Enumerable.Range(0, files.Count))
            {
                var file = files[fileIndex];

                IReadOnlyList <int> pages = null;
                if (pagesBundle != null && fileIndex < pagesBundle.Count)
                {
                    pages = pagesBundle[fileIndex];
                }

                var inputBytes  = new ByteArrayInputBytes(file);
                var coreScanner = new CoreTokenScanner(inputBytes);

                var version = FileHeaderParser.Parse(coreScanner, isLenientParsing, Log);

                var crossReferenceParser = new CrossReferenceParser(Log, new XrefOffsetValidator(Log),
                                                                    new Parser.Parts.CrossReference.CrossReferenceStreamParser(FilterProvider));

                CrossReferenceTable crossReference = null;

                // ReSharper disable once AccessToModifiedClosure
                var locationProvider = new ObjectLocationProvider(() => crossReference, inputBytes);

                var pdfScanner = new PdfTokenScanner(inputBytes, locationProvider, FilterProvider, NoOpEncryptionHandler.Instance);

                var crossReferenceOffset = FileTrailerParser.GetFirstCrossReferenceOffset(inputBytes, coreScanner, isLenientParsing);
                crossReference = crossReferenceParser.Parse(inputBytes, isLenientParsing, crossReferenceOffset, version.OffsetInFile, pdfScanner, coreScanner);

                var catalogDictionaryToken = ParseCatalog(crossReference, pdfScanner, out var encryptionDictionary);
                if (encryptionDictionary != null)
                {
                    throw new PdfDocumentEncryptedException("Unable to merge document with password");
                }

                var documentCatalog = CatalogFactory.Create(crossReference.Trailer.Root, catalogDictionaryToken, pdfScanner, isLenientParsing);

                documentBuilder.AppendDocument(documentCatalog, version.Version, pdfScanner, pages);
            }

            return(documentBuilder.Build());
        }
コード例 #7
0
        public static IEnumerable <ComposablePartCatalog> GetCatalogs()
        {
            yield return(CatalogFactory.Create());

            yield return(CatalogFactory.CreateDefaultAttributed());
        }
コード例 #8
0
        public void Dispose_ShouldNotThrow()
        {
            var catalog = CatalogFactory.Create();

            catalog.Dispose();
        }
コード例 #9
0
 private static CatalogExportProvider CreateCatalogExportProvider(params ComposablePart[] parts)
 {
     return(CreateCatalogExportProvider(CatalogFactory.Create(parts)));
 }
コード例 #10
0
 private static CatalogExportProvider CreateCatalogExportProvider(params ComposablePartDefinition[] definitions)
 {
     return(CreateCatalogExportProvider(CatalogFactory.Create(definitions)));
 }
コード例 #11
0
 private static CatalogExportProvider CreateCatalogExportProvider()
 {
     return(CreateCatalogExportProvider(CatalogFactory.Create()));
 }