Skip to content

Commit f6d0f2e

Browse files
authored
Syndication Feed async wrapper improvements (dotnet/corefx#24613)
* Fixed XmlWriterWrapper and XmlReaderWrapper so they don't wrap unnecessarily * Removing unnecessary this. prefixes plus some minor formatting cleanup * String resource cleanup and string.Format -> SR.Format * Improved DateTime parsers and moved parser properties to base FeedFormatter * Small fixes for CR feedback Commit migrated from dotnet/corefx@1b2646e
1 parent 6c024af commit f6d0f2e

26 files changed

+803
-8683
lines changed

src/libraries/System.ServiceModel.Syndication/ref/System.ServiceModel.Syndication.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ public static partial class Atom10Constants
5353
}
5454
public partial class Atom10FeedFormatter : System.ServiceModel.Syndication.SyndicationFeedFormatter
5555
{
56-
public System.Func<string, string, string, System.DateTimeOffset> dateParser;
57-
public System.Func<string, string, string, string> stringParser;
58-
public System.Func<string, System.UriKind, string, string, System.Uri> uriParser;
5956
public Atom10FeedFormatter() { }
6057
public Atom10FeedFormatter(System.ServiceModel.Syndication.SyndicationFeed feedToWrite) { }
6158
public Atom10FeedFormatter(System.Type feedTypeToCreate) { }
@@ -201,17 +198,13 @@ public Rss20FeedFormatter() { }
201198
public Rss20FeedFormatter(System.ServiceModel.Syndication.SyndicationFeed feedToWrite) { }
202199
public Rss20FeedFormatter(System.ServiceModel.Syndication.SyndicationFeed feedToWrite, bool serializeExtensionsAsAtom) { }
203200
public Rss20FeedFormatter(System.Type feedTypeToCreate) { }
204-
public System.Func<string, string, string, System.DateTimeOffset> DateParser { get { throw null; } set { } }
205201
protected System.Type FeedType { get { throw null; } }
206202
public bool PreserveAttributeExtensions { get { throw null; } set { } }
207203
public bool PreserveElementExtensions { get { throw null; } set { } }
208204
public bool SerializeExtensionsAsAtom { get { throw null; } set { } }
209-
public System.Func<string, string, string, string> StringParser { get { throw null; } set { } }
210-
public System.Func<string, string, string, System.Uri> UriParser { get { throw null; } set { } }
211205
public override string Version { get { throw null; } }
212206
public override bool CanRead(System.Xml.XmlReader reader) { throw null; }
213207
protected override System.ServiceModel.Syndication.SyndicationFeed CreateFeedInstance() { throw null; }
214-
public static System.DateTimeOffset DefaultDateParser(string dateTimeString, string localName, string ns) { throw null; }
215208
public override System.Threading.Tasks.Task ReadFromAsync(System.Xml.XmlReader reader, System.Threading.CancellationToken ct) { throw null; }
216209
protected virtual System.Threading.Tasks.Task<System.ServiceModel.Syndication.SyndicationItem> ReadItemAsync(System.Xml.XmlReader reader, System.ServiceModel.Syndication.SyndicationFeed feed) { throw null; }
217210
protected internal override void SetFeed(System.ServiceModel.Syndication.SyndicationFeed feed) { }
@@ -434,6 +427,9 @@ public abstract partial class SyndicationFeedFormatter
434427
{
435428
protected SyndicationFeedFormatter() { }
436429
protected SyndicationFeedFormatter(System.ServiceModel.Syndication.SyndicationFeed feedToWrite) { }
430+
public System.Func<string, string, string, System.DateTimeOffset> DateTimeParser { get { throw null; } set { } }
431+
public System.Func<string, string, string, string> StringParser { get { throw null; } set { } }
432+
public System.Func<string, System.UriKind, string, string, System.Uri> UriParser { get { throw null; } set { } }
437433
public System.ServiceModel.Syndication.SyndicationFeed Feed { get { throw null; } }
438434
public abstract string Version { get; }
439435
public abstract bool CanRead(System.Xml.XmlReader reader);

src/libraries/System.ServiceModel.Syndication/src/Resources/Strings.resx

Lines changed: 76 additions & 7764 deletions
Large diffs are not rendered by default.

src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Channels/UriGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public UriGenerator(string scheme, string delimiter)
3030
//throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("scheme"));
3131

3232
if (scheme.Length == 0)
33-
throw new ArgumentException(string.Format(SR.UriGeneratorSchemeMustNotBeEmpty, "scheme"));
33+
throw new ArgumentException(SR.Format(SR.UriGeneratorSchemeMustNotBeEmpty, "scheme"));
3434

3535
_prefix = string.Concat(scheme, ":", Guid.NewGuid().ToString(), delimiter, "id=");
3636
}

src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/Atom10FeedFormatter.cs

Lines changed: 79 additions & 151 deletions
Large diffs are not rendered by default.

src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/Atom10ItemFormatter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public Atom10ItemFormatter(Type itemTypeToCreate)
4040
}
4141
if (!typeof(SyndicationItem).IsAssignableFrom(itemTypeToCreate))
4242
{
43-
throw new ArgumentException(string.Format(SR.InvalidObjectTypePassed, nameof(itemTypeToCreate), nameof(SyndicationItem)));
43+
throw new ArgumentException(SR.Format(SR.InvalidObjectTypePassed, nameof(itemTypeToCreate), nameof(SyndicationItem)));
4444
}
4545
_feedSerializer = new Atom10FeedFormatter();
4646
_feedSerializer.PreserveAttributeExtensions = _preserveAttributeExtensions = true;
@@ -104,7 +104,7 @@ public override Task ReadFromAsync(XmlReader reader)
104104
{
105105
if (!CanRead(reader))
106106
{
107-
throw new XmlException(string.Format(SR.UnknownItemXml, reader.LocalName, reader.NamespaceURI));
107+
throw new XmlException(SR.Format(SR.UnknownItemXml, reader.LocalName, reader.NamespaceURI));
108108
}
109109

110110
return ReadItemAsync(reader);
@@ -132,17 +132,17 @@ protected override SyndicationItem CreateItemInstance()
132132
private Task ReadItemAsync(XmlReader reader)
133133
{
134134
SetItem(CreateItemInstance());
135-
return _feedSerializer.ReadItemFromAsync(XmlReaderWrapper.CreateFromReader(XmlDictionaryReader.CreateDictionaryReader(reader)), this.Item);
135+
return _feedSerializer.ReadItemFromAsync(XmlReaderWrapper.CreateFromReader(XmlDictionaryReader.CreateDictionaryReader(reader)), Item);
136136
}
137137

138138
private Task WriteItemAsync(XmlWriter writer)
139139
{
140-
if (this.Item == null)
140+
if (Item == null)
141141
{
142142
throw new InvalidOperationException(SR.ItemFormatterDoesNotHaveItem);
143143
}
144144
XmlDictionaryWriter w = XmlDictionaryWriter.CreateDictionaryWriter(writer);
145-
return _feedSerializer.WriteItemContentsAsync(w, this.Item);
145+
return _feedSerializer.WriteItemContentsAsync(w, Item);
146146
}
147147
}
148148

src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/AtomPub10CategoriesDocumentFormatter.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public AtomPub10CategoriesDocumentFormatter(Type inlineDocumentType, Type refere
3535

3636
if (!typeof(InlineCategoriesDocument).IsAssignableFrom(inlineDocumentType))
3737
{
38-
throw new ArgumentException(string.Format(SR.InvalidObjectTypePassed, nameof(inlineDocumentType), nameof(InlineCategoriesDocument)));
38+
throw new ArgumentException(SR.Format(SR.InvalidObjectTypePassed, nameof(inlineDocumentType), nameof(InlineCategoriesDocument)));
3939
}
4040

4141
if (referencedDocumentType == null)
@@ -45,7 +45,7 @@ public AtomPub10CategoriesDocumentFormatter(Type inlineDocumentType, Type refere
4545

4646
if (!typeof(ReferencedCategoriesDocument).IsAssignableFrom(referencedDocumentType))
4747
{
48-
throw new ArgumentException(string.Format(SR.InvalidObjectTypePassed, nameof(referencedDocumentType), nameof(ReferencedCategoriesDocument)));
48+
throw new ArgumentException(SR.Format(SR.InvalidObjectTypePassed, nameof(referencedDocumentType), nameof(ReferencedCategoriesDocument)));
4949
}
5050

5151
_maxExtensionSize = int.MaxValue;
@@ -86,13 +86,11 @@ public override Task<bool> CanReadAsync(XmlReader reader)
8686
throw new ArgumentNullException(nameof(reader));
8787
}
8888

89-
XmlReaderWrapper wrappedReader = XmlReaderWrapper.CreateFromReader(reader);
90-
return wrappedReader.IsStartElementAsync(App10Constants.Categories, App10Constants.Namespace);
89+
reader = XmlReaderWrapper.CreateFromReader(reader);
90+
return reader.IsStartElementAsync(App10Constants.Categories, App10Constants.Namespace);
9191
}
9292

93-
94-
95-
private Task ReadXmlAsync(XmlReaderWrapper reader)
93+
Task ReadXmlAsync(XmlReader reader)
9694
{
9795
if (reader == null)
9896
{
@@ -109,7 +107,7 @@ private Task WriteXmlAsync(XmlWriter writer)
109107
throw new ArgumentNullException(nameof(writer));
110108
}
111109

112-
if (this.Document == null)
110+
if (Document == null)
113111
{
114112
throw new InvalidOperationException(SR.DocumentFormatterDoesNotHaveDocument);
115113
}
@@ -126,7 +124,7 @@ public override async Task ReadFromAsync(XmlReader reader)
126124

127125
if (!await CanReadAsync(reader))
128126
{
129-
throw new XmlException(string.Format(SR.UnknownDocumentXml, reader.LocalName, reader.NamespaceURI));
127+
throw new XmlException(SR.Format(SR.UnknownDocumentXml, reader.LocalName, reader.NamespaceURI));
130128
}
131129

132130
await ReadDocumentAsync(XmlReaderWrapper.CreateFromReader(reader));
@@ -139,7 +137,7 @@ public override async Task WriteTo(XmlWriter writer)
139137
throw new ArgumentNullException(nameof(writer));
140138
}
141139

142-
if (this.Document == null)
140+
if (Document == null)
143141
{
144142
throw new InvalidOperationException(SR.DocumentFormatterDoesNotHaveDocument);
145143
}
@@ -173,22 +171,22 @@ protected override ReferencedCategoriesDocument CreateReferencedCategoriesDocume
173171
}
174172
}
175173

176-
private async Task ReadDocumentAsync(XmlReaderWrapper reader)
174+
private async Task ReadDocumentAsync(XmlReader reader)
177175
{
178176
try
179177
{
180178
await SyndicationFeedFormatter.MoveToStartElementAsync(reader);
181179
SetDocument(await AtomPub10ServiceDocumentFormatter.ReadCategories(reader, null,
182180
delegate ()
183181
{
184-
return this.CreateInlineCategoriesDocument();
182+
return CreateInlineCategoriesDocument();
185183
},
186184

187185
delegate ()
188186
{
189-
return this.CreateReferencedCategoriesDocument();
187+
return CreateReferencedCategoriesDocument();
190188
},
191-
this.Version,
189+
Version,
192190
_preserveElementExtensions,
193191
_preserveAttributeExtensions,
194192
_maxExtensionSize));
@@ -207,7 +205,7 @@ private Task WriteDocumentAsync(XmlWriter writer)
207205
{
208206
// declare the atom10 namespace upfront for compactness
209207
writer.WriteAttributeString(Atom10Constants.Atom10Prefix, Atom10FeedFormatter.XmlNsNs, Atom10Constants.Atom10Namespace);
210-
return AtomPub10ServiceDocumentFormatter.WriteCategoriesInnerXml(writer, this.Document, null, this.Version);
208+
return AtomPub10ServiceDocumentFormatter.WriteCategoriesInnerXml(writer, Document, null, Version);
211209
}
212210
}
213211
}

0 commit comments

Comments
 (0)