Пример #1
0
        public Fooder Create(FooderType fooderType, FooderDesignation fooderDesignation)
        {
            var(part, relationship) = fooderType switch
            {
                FooderType.Header => package.AddHeaderPart(),
                FooderType.Footer => package.AddFooterPart(),
                _ => throw new ArgumentOutOfRangeException(nameof(fooderType))
            };

            var document = PackagePartHelper.ReadPackagePart(part);

            Fooder fooder = fooderType switch
            {
                FooderType.Header => new Header(part, document, relationship, fooderDesignation, wordDocument),
                FooderType.Footer => new Footer(part, document, relationship, fooderDesignation, wordDocument),
                _ => throw new ArgumentOutOfRangeException(nameof(fooderType))
            };

            var packagePartUri = PackagePartHelper.EnsureCorrectUri(relationship.TargetUri);

            fooders[packagePartUri] = fooder;

            EnsureDefaultStyles(fooderType);

            return(fooder);
        }
Пример #2
0
        public Fooder Get(PackageRelationship relationship, FooderType fooderType, FooderDesignation fooderDesignation)
        {
            var packagePartUri = PackagePartHelper.EnsureCorrectUri(relationship.TargetUri);

            if (fooders.ContainsKey(packagePartUri))
            {
                var cachedFooder = fooders[packagePartUri];

                return(cachedFooder.FooderType == fooderType
                                        ? cachedFooder
                                        : throw new Exception($"Requested fooder is not of type {fooderType}"));
            }

            var packagePart = package.GetPart(relationship);

            var document = PackagePartHelper.ReadPackagePart(packagePart);

            var fooder = fooderType switch
            {
                FooderType.Header => (Fooder) new Header(packagePart, document, relationship, fooderDesignation, wordDocument),
                FooderType.Footer => new Footer(packagePart, document, relationship, fooderDesignation, wordDocument),
                _ => throw new ArgumentOutOfRangeException(nameof(fooderType))
            };

            fooders[packagePartUri] = fooder;
            return(fooder);
        }
Пример #3
0
        protected override XElement GetOrCreatePackagePartAndDocumentRoot()
        {
            if (PackagePart == null)
            {
                PackagePart = Package.CreateDefaultNumberingPart();
                XmlDocument = PackagePartHelper.ReadPackagePart(PackagePart);
            }

            return(XmlDocument?.Root ?? throw new Exception("The XML document must be initialized and have root"));
        }
Пример #4
0
        protected OptionalDocumentPartWrapper(PackagePart?packagePart, WordDocumentPackage package)
        {
            PackagePart = packagePart;
            Package     = package;

            if (PackagePart != null)
            {
                XmlDocument = PackagePartHelper.ReadPackagePart(PackagePart);
            }
        }
Пример #5
0
 protected DocumentPartWrapper(PackagePart packagePart)
 {
     PackagePart = packagePart;
     XmlDocument = PackagePartHelper.ReadPackagePart(PackagePart);
 }