/// <summary> /// Resolves the <see cref="ExportProvider"/> for the given <see cref="XDocument"/>. /// </summary> /// <param name="self"></param> /// <returns></returns> public static ExportProvider Exports(this XDocument self) { Contract.Requires <ArgumentNullException>(self != null); Contract.Ensures(Contract.Result <ExportProvider>() != null); return(self.Annotation <ExportProvider>()); }
private static string GetDefaultParagraphStyleName(XDocument stylesXDoc) { XElement defaultParagraphStyle; string? defaultParagraphStyleName = null; var stylesInfo = stylesXDoc.Annotation <StylesInfo>(); if (stylesInfo != null) { defaultParagraphStyleName = stylesInfo.DefaultParagraphStyleName; } else { defaultParagraphStyle = stylesXDoc .Root .Elements(W.style) .FirstOrDefault(s => { if ((string)s.Attribute(W.type) != "paragraph") { return(false); } var defaultAttribute = s.Attribute(W._default); if (defaultAttribute != null && s.Attribute(W._default).ToBoolean().HasValue) { return(s.Attribute(W._default)?.ToBoolean() ?? false); } return(false); }); defaultParagraphStyleName = null; if (defaultParagraphStyle != null) { defaultParagraphStyleName = (string)defaultParagraphStyle.Attribute(W.styleId); } stylesInfo = new StylesInfo() { DefaultParagraphStyleName = defaultParagraphStyleName, }; stylesXDoc.AddAnnotation(stylesInfo); } return(defaultParagraphStyleName); }
public ValidationResult Validate(XDocument compositeDefinition) { ValidationResult validationResult = null; compositeDefinition.Validate( GetValidationSchemaSet(), (sender, args) => { validationResult = new ValidationResult( new[] { new ValidationFailure( string.Empty, $"The composite definition '{compositeDefinition.Annotation<string>()}' assembly failed schema validation:{Environment.NewLine}{args.Message}") }); }); return(validationResult ?? new ValidationResult()); }
private static void FlushPart(OpenXmlPart part, HashSet <OpenXmlPart> visited) { visited.Add(part); XDocument xdoc = part.Annotation <XDocument>(); if (xdoc != null && xdoc.Annotation <ChangedSemaphore>() != null) { using (XmlWriter xw = XmlWriter.Create(part.GetStream(FileMode.Create, FileAccess.Write))) { xdoc.Save(xw); } xdoc.RemoveAnnotations <ChangedSemaphore>(); xdoc.Changing += ElementChanged; xdoc.Changed += ElementChanged; } foreach (IdPartPair item in part.Parts) { if (!visited.Contains(item.OpenXmlPart)) { FlushPart(item.OpenXmlPart, visited); } } }