Feature/netcore preparation (#2072)

* Use platform detection that works on mono 4.6+

* Move to use package reference for restoring nuget packages.

* DateTimeRoutines does not have Nuget packages that support .NET Standard (and therefore .NET Core). We will have to include them for now until we can get rid of this dependency.

* Start spliting some interfaces into their own files - this will help by allowing us to split them out in the future into a seperate project so the actual implementations can stay within their respective architectures when required

* Move out common libraries

* Few more tidy up tasks to get things working with .NET Standard

* Restructure the solution layout

* Encoding work to reduce rework later on platforms without Windows codepages (or require compliance with RFC1345)

* Move folder structure around to have more natural layout of the solutions

* DI server configuration to get rid of "temporary" hack and dependency circle for serverservice

* Make all encoding consistent to match the expected encoding casing for earlier versions of mono.
This commit is contained in:
Nathan Holland
2017-11-05 22:42:03 +13:00
committed by flightlevel
parent 47a2ffa313
commit 571c52a0f2
235 changed files with 967 additions and 1001 deletions

View File

@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
namespace Jackett.Models
{
public class ResultPage
{
static XNamespace atomNs = "http://www.w3.org/2005/Atom";
static XNamespace torznabNs = "http://torznab.com/schemas/2015/feed";
public ChannelInfo ChannelInfo { get; private set; }
public IEnumerable<ReleaseInfo> Releases { get; set; }
public ResultPage(ChannelInfo channelInfo)
{
ChannelInfo = channelInfo;
Releases = new List<ReleaseInfo>();
}
string xmlDateFormat(DateTime dt)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
//Sat, 14 Mar 2015 17:10:42 -0400
var f = string.Format(@"{0:ddd, dd MMM yyyy HH:mm:ss }{1}", dt, string.Format("{0:zzz}", dt).Replace(":", ""));
return f;
}
XElement getTorznabElement(string name, object value)
{
return value == null ? null : new XElement(torznabNs + "attr", new XAttribute("name", name), new XAttribute("value", value));
}
public string ToXml(Uri selfAtom)
{
var xdoc = new XDocument(
new XDeclaration("1.0", "UTF-8", null),
new XElement("rss",
new XAttribute("version", "1.0"),
new XAttribute(XNamespace.Xmlns + "atom", atomNs.NamespaceName),
new XAttribute(XNamespace.Xmlns + "torznab", torznabNs.NamespaceName),
new XElement("channel",
new XElement(atomNs + "link",
new XAttribute("href", selfAtom.ToString()),
new XAttribute("rel", "self"),
new XAttribute("type", "application/rss+xml")
),
new XElement("title", ChannelInfo.Title),
new XElement("description", ChannelInfo.Description),
new XElement("link", ChannelInfo.Link),
new XElement("lanuage", ChannelInfo.Language),
new XElement("category", ChannelInfo.Category),
new XElement("image",
new XElement("url", ChannelInfo.ImageUrl.ToString()),
new XElement("title", ChannelInfo.ImageTitle),
new XElement("link", ChannelInfo.ImageLink.ToString()),
new XElement("description", ChannelInfo.ImageDescription)
),
from r in Releases
select new XElement("item",
new XElement("title", r.Title),
new XElement("guid", r.Guid),
r.Comments == null ? null : new XElement("comments", r.Comments.ToString()),
r.PublishDate == DateTime.MinValue ? new XElement("pubDate", DateTime.Now) : new XElement("pubDate", xmlDateFormat(r.PublishDate)),
r.Size == null ? null : new XElement("size", r.Size),
r.Files == null ? null : new XElement("files", r.Files),
r.Grabs == null ? null : new XElement("grabs", r.Grabs),
new XElement("description", r.Description),
new XElement("link", r.Link ?? r.MagnetUri),
r.Category == null ? null : from c in r.Category select new XElement("category", c),
new XElement(
"enclosure",
new XAttribute("url", r.Link ?? r.MagnetUri),
r.Size == null ? null : new XAttribute("length", r.Size),
new XAttribute("type", "application/x-bittorrent")
),
r.Category == null ? null : from c in r.Category select getTorznabElement("category", c),
getTorznabElement("magneturl", r.MagnetUri),
getTorznabElement("rageid", r.RageID),
getTorznabElement("thetvdb", r.TVDBId),
getTorznabElement("imdb", r.Imdb),
getTorznabElement("seeders", r.Seeders),
getTorznabElement("peers", r.Peers),
getTorznabElement("infohash", r.InfoHash),
getTorznabElement("minimumratio", r.MinimumRatio),
getTorznabElement("minimumseedtime", r.MinimumSeedTime),
getTorznabElement("downloadvolumefactor", r.DownloadVolumeFactor),
getTorznabElement("uploadvolumefactor", r.UploadVolumeFactor)
)
)
)
);
return xdoc.Declaration.ToString() + Environment.NewLine + xdoc.ToString();
}
}
}