[XmlRoot(ElementName = App10Constants.Service, Namespace = App10Constants.Namespace)]
public class AtomPub10ServiceDocumentFormatter : ServiceDocumentFormatter, IXmlSerializable
{
- private bool _preserveAttributeExtensions;
- private bool _preserveElementExtensions;
private readonly Type _documentType;
private readonly int _maxExtensionSize;
}
_maxExtensionSize = int.MaxValue;
- _preserveAttributeExtensions = true;
- _preserveElementExtensions = true;
_documentType = documentTypeToCreate;
}
public AtomPub10ServiceDocumentFormatter(ServiceDocument documentToWrite) : base(documentToWrite)
{
_maxExtensionSize = int.MaxValue;
- _preserveAttributeExtensions = true;
- _preserveElementExtensions = true;
_documentType = documentToWrite.GetType();
}
writer.WriteEndElement();
}
- internal static CategoriesDocument ReadCategories(XmlReader reader, Uri baseUri, CreateInlineCategoriesDelegate inlineCategoriesFactory, CreateReferencedCategoriesDelegate referencedCategoriesFactory, string version, bool preserveElementExtensions, bool preserveAttributeExtensions, int maxExtensionSize)
+ internal static CategoriesDocument ReadCategories(XmlReader reader, Uri baseUri, CreateInlineCategoriesDelegate inlineCategoriesFactory, CreateReferencedCategoriesDelegate referencedCategoriesFactory, string version, int maxExtensionSize)
{
string link = reader.GetAttribute(App10Constants.Href, string.Empty);
if (string.IsNullOrEmpty(link))
{
InlineCategoriesDocument inlineCategories = inlineCategoriesFactory();
- ReadInlineCategories(reader, inlineCategories, baseUri, version, preserveElementExtensions, preserveAttributeExtensions, maxExtensionSize);
+ ReadInlineCategories(reader, inlineCategories, baseUri, version, maxExtensionSize);
return inlineCategories;
}
else
{
ReferencedCategoriesDocument referencedCategories = referencedCategoriesFactory();
- ReadReferencedCategories(reader, referencedCategories, baseUri, new Uri(link, UriKind.RelativeOrAbsolute), version, preserveElementExtensions, preserveAttributeExtensions, maxExtensionSize);
+ ReadReferencedCategories(reader, referencedCategories, baseUri, new Uri(link, UriKind.RelativeOrAbsolute), version, maxExtensionSize);
return referencedCategories;
}
}
}
}
- private static void ReadInlineCategories(XmlReader reader, InlineCategoriesDocument inlineCategories, Uri baseUri, string version, bool preserveElementExtensions, bool preserveAttributeExtensions, int maxExtensionSize)
+ private static void ReadInlineCategories(XmlReader reader, InlineCategoriesDocument inlineCategories, Uri baseUri, string version, int maxExtensionSize)
{
inlineCategories.BaseUri = baseUri;
if (reader.HasAttributes)
string val = reader.Value;
if (!TryParseAttribute(name, ns, val, inlineCategories, version))
{
- if (preserveAttributeExtensions)
- {
- inlineCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
- }
+ inlineCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
}
}
}
if (reader.IsStartElement(Atom10Constants.CategoryTag, Atom10Constants.Atom10Namespace))
{
SyndicationCategory category = CreateCategory(inlineCategories);
- Atom10FeedFormatter.ReadCategory(reader, category, version, preserveAttributeExtensions, preserveElementExtensions, maxExtensionSize);
+ Atom10FeedFormatter.ReadCategory(reader, category, version, preserveAttributeExtensions: true, preserveElementExtensions: true, maxExtensionSize);
if (category.Scheme == null)
{
category.Scheme = inlineCategories.Scheme;
}
else if (!TryParseElement(reader, inlineCategories, version))
{
- if (preserveElementExtensions)
- {
- SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize);
- }
+ SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize);
}
}
LoadElementExtensions(buffer, extWriter, inlineCategories);
}
}
- private static void ReadReferencedCategories(XmlReader reader, ReferencedCategoriesDocument referencedCategories, Uri baseUri, Uri link, string version, bool preserveElementExtensions, bool preserveAttributeExtensions, int maxExtensionSize)
+ private static void ReadReferencedCategories(XmlReader reader, ReferencedCategoriesDocument referencedCategories, Uri baseUri, Uri link, string version, int maxExtensionSize)
{
referencedCategories.BaseUri = baseUri;
referencedCategories.Link = link;
string val = reader.Value;
if (!TryParseAttribute(name, ns, val, referencedCategories, version))
{
- if (preserveAttributeExtensions)
- {
- referencedCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
- }
+ referencedCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
}
}
}
{
if (!TryParseElement(reader, referencedCategories, version))
{
- if (preserveElementExtensions)
- {
- SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize);
- }
+ SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize);
}
}
LoadElementExtensions(buffer, extWriter, referencedCategories);
string val = reader.Value;
if (!TryParseAttribute(name, ns, val, result, Version))
{
- if (_preserveAttributeExtensions)
- {
- result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
- }
+ result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
}
}
}
{
if (reader.IsStartElement(Atom10Constants.TitleTag, Atom10Constants.Atom10Namespace))
{
- result.Title = Atom10FeedFormatter.ReadTextContentFrom(reader, "//app:service/app:workspace/app:collection/atom:title[@type]", _preserveAttributeExtensions);
+ result.Title = Atom10FeedFormatter.ReadTextContentFrom(reader, "//app:service/app:workspace/app:collection/atom:title[@type]", preserveAttributeExtensions: true);
}
else if (reader.IsStartElement(App10Constants.Categories, App10Constants.Namespace))
{
result.Categories.Add(ReadCategories(reader,
result.BaseUri,
- _preserveElementExtensions,
- _preserveAttributeExtensions,
() => CreateInlineCategories(result),
() => CreateReferencedCategories(result),
Version,
}
else if (!TryParseElement(reader, result, Version))
{
- if (_preserveElementExtensions)
- {
- SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, _maxExtensionSize);
- }
+ SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, _maxExtensionSize);
}
}
LoadElementExtensions(buffer, extWriter, result);
string val = reader.Value;
if (!TryParseAttribute(name, ns, val, result, Version))
{
- if (_preserveAttributeExtensions)
- {
- result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
- }
+ result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
}
}
}
}
else if (!TryParseElement(reader, result, Version))
{
- if (_preserveElementExtensions)
- {
- SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, _maxExtensionSize);
- }
+ SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, _maxExtensionSize);
}
}
LoadElementExtensions(buffer, extWriter, result);