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); }
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); }
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")); }
protected OptionalDocumentPartWrapper(PackagePart?packagePart, WordDocumentPackage package) { PackagePart = packagePart; Package = package; if (PackagePart != null) { XmlDocument = PackagePartHelper.ReadPackagePart(PackagePart); } }
protected DocumentPartWrapper(PackagePart packagePart) { PackagePart = packagePart; XmlDocument = PackagePartHelper.ReadPackagePart(PackagePart); }