1
0
Fork 0
mirror of https://github.com/sbrl/PolyFeed.git synced 2024-12-24 10:45:02 +00:00

Start on a JSON provider, but it's not finished yet

This commit is contained in:
Starbeamrainbowlabs 2019-08-11 16:14:25 +01:00
parent 6944d87726
commit a15f1157f0
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
4 changed files with 48 additions and 4 deletions

View file

@ -26,6 +26,7 @@ namespace PolyFeed.ParserProviders
/// <param name="feed">The output feed writer that output should be written to.</param>
/// <param name="xml">The underlying XML feed try not to use this unless you *really* have to.</param>
void SetOutputFeed(AtomFeedWriter feed, XmlWriter xml);
/// <summary>
/// Parses a web response that's paired with a given <see cref="FeedSource" />.
/// </summary>

View file

@ -0,0 +1,45 @@
using System;
using System.Net;
using System.Threading.Tasks;
using System.Xml;
using Microsoft.SyndicationFeed.Atom;
using System.Json;
using System.IO;
namespace PolyFeed.ParserProviders
{
public class JsonParserProvider : IParserProvider
{
private XmlWriter xml = null;
private AtomFeedWriter feed = null;
public string Identifier => "json";
public JsonParserProvider() {
}
public void SetOutputFeed(AtomFeedWriter inFeed, XmlWriter inXml) {
xml = inXml;
feed = inFeed;
}
public async Task ParseWebResponse(FeedSource source, WebResponse response)
{
string jsonText;
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
jsonText = await reader.ReadToEndAsync();
JsonValue jsonValue = JsonValue.Parse(jsonText);
JsonObject json = jsonValue as JsonObject;
if (json == null)
throw new ApplicationException("Error: Failed to parse the JSON into an object.");
throw new NotImplementedException("Error %01: Not implemented :-/");
}
}
}

View file

@ -126,15 +126,13 @@
<Reference Include="Fizzler.Systems.HtmlAgilityPack">
<HintPath>..\packages\Fizzler.Systems.HtmlAgilityPack.1.2.0\lib\netstandard1.3\Fizzler.Systems.HtmlAgilityPack.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Microsoft.SyndicationFeed.ReaderWriter">
<HintPath>..\packages\Microsoft.SyndicationFeed.ReaderWriter.1.0.2\lib\netstandard1.3\Microsoft.SyndicationFeed.ReaderWriter.dll</HintPath>
</Reference>
<Reference Include="Nett">
<HintPath>..\packages\Nett.0.13.0\lib\net40\Nett.dll</HintPath>
</Reference>
<Reference Include="System.Json" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
@ -154,6 +152,7 @@
<Compile Include="Helpers\ReflectionHelpers.cs" />
<Compile Include="ParserProviders\IParserProvider.cs" />
<Compile Include="ParserProviders\HtmlParserProvider.cs" />
<Compile Include="ParserProviders\JsonParserProvider.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

View file

@ -8,7 +8,6 @@
<package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net47" />
<package id="NETStandard.Library" version="2.0.3" targetFramework="net47" />
<package id="Nett" version="0.13.0" targetFramework="net47" />
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net47" />
<package id="System.AppContext" version="4.3.0" targetFramework="net47" />
<package id="System.Collections" version="4.3.0" targetFramework="net47" />
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net47" />