Bugfix/1532 1539 fix manual search circular reference (#1543)

* Line endings...

* Encoding Encoding in a reasonable way

Sadly Encoding contains a self-reference somewhere, which makes it
really hard for the json serializer to automatically encode it...
Probably there's no value in sending it over especially since no one is
using it, however just for the sake of the argument, let's just
serialize it in a reasonable way. Maybe someday there will be someone
expecting this. Or we clearly separate DTOs and models...

- Fixes Jackett/Jackett#1532
- Fixes Jackett/Jackett#1539

* Seriously... Please port this to dotnet Core so that I can use something other than @drunkvs on my MacBook

* Fix autofac registration after merge

* "Implement" new function of interface in test project
This commit is contained in:
chibidev
2017-07-11 22:32:56 +02:00
committed by kaso17
parent fb59e84def
commit 17f544be36
6 changed files with 164 additions and 85 deletions

View File

@@ -28,6 +28,11 @@ namespace JackettTest
throw new NotImplementedException();
}
public IWebIndexer GetWebIndexer(string name)
{
throw new NotImplementedException();
}
public void InitIndexers()
{
throw new NotImplementedException();

View File

@@ -96,11 +96,25 @@ Global
$2.SpacesBeforeBrackets = False
$2.scope = text/x-csharp
$2.IndentSwitchSection = True
$2.NewLinesForBracesInProperties = True
$2.NewLinesForBracesInAccessors = True
$2.NewLinesForBracesInAnonymousMethods = True
$2.NewLinesForBracesInControlBlocks = True
$2.NewLinesForBracesInAnonymousTypes = True
$2.NewLinesForBracesInObjectCollectionArrayInitializers = True
$2.NewLinesForBracesInLambdaExpressionBody = True
$2.NewLineForElse = True
$2.NewLineForCatch = True
$2.NewLineForFinally = True
$2.NewLineForMembersInObjectInit = True
$2.NewLineForMembersInAnonymousTypes = True
$2.NewLineForClausesInQuery = True
$2.SpacingAfterMethodDeclarationName = False
$2.SpaceAfterMethodCallName = False
$2.SpaceBeforeOpenSquareBracket = False
$0.DotNetNamingPolicy = $3
$3.DirectoryNamespaceAssociation = PrefixedHierarchical
$0.StandardHeader = $4
$0.TextStylePolicy = $3
$3.FileWidth = 80
$3.TabsToSpaces = True
$3.scope = text/plain
EndGlobalSection
EndGlobal

View File

@@ -12,6 +12,7 @@ using Jackett.Utils.Clients;
using AutoMapper;
using Jackett.Models.IndexerConfig;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
namespace Jackett.Indexers
{
@@ -691,6 +692,8 @@ namespace Jackett.Indexers
}
public override TorznabCapabilities TorznabCaps { get; protected set; }
[JsonConverter(typeof(EncodingJsonConverter))]
public Encoding Encoding { get; protected set; }
private List<CategoryMapping> categoryMapping = new List<CategoryMapping>();

View File

@@ -377,6 +377,7 @@
<Compile Include="Indexers\Meta\ResultFilters.cs" />
<Compile Include="Services\ImdbResolver.cs" />
<Compile Include="Utils\Extensions.cs" />
<Compile Include="Utils\JsonUtil.cs" />
<Compile Include="Services\IndexerConfigurationService.cs" />
<Compile Include="Models\IndexerDefinition.cs" />
</ItemGroup>

View File

@@ -42,7 +42,8 @@ namespace Jackett
builder.RegisterType<HttpWebClient>();
// Register the best web client for the platform or the override
switch (Startup.ClientOverride) {
switch (Startup.ClientOverride)
{
case "httpclient":
builder.RegisterType<HttpWebClient>().As<IWebClient>();
break;
@@ -57,27 +58,36 @@ namespace Jackett
break;
case "automatic":
default:
if (System.Environment.OSVersion.Platform == PlatformID.Unix) {
if (System.Environment.OSVersion.Platform == PlatformID.Unix)
{
var usehttpclient = false;
try {
try
{
Type monotype = Type.GetType("Mono.Runtime");
if (monotype != null) {
if (monotype != null)
{
MethodInfo displayName = monotype.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
if (displayName != null) {
if (displayName != null)
{
var monoVersion = displayName.Invoke(null, null).ToString();
var monoVersionO = new Version(monoVersion.Split(' ')[0]);
if ((monoVersionO.Major >= 4 && monoVersionO.Minor >= 8) || monoVersionO.Major >= 5) {
if ((monoVersionO.Major >= 4 && monoVersionO.Minor >= 8) || monoVersionO.Major >= 5)
{
// check if btls is supported
var monoSecurity = Assembly.Load("Mono.Security");
Type monoTlsProviderFactory = monoSecurity.GetType("Mono.Security.Interface.MonoTlsProviderFactory");
if (monoTlsProviderFactory != null) {
if (monoTlsProviderFactory != null)
{
MethodInfo isProviderSupported = monoTlsProviderFactory.GetMethod("IsProviderSupported");
if (isProviderSupported != null) {
if (isProviderSupported != null)
{
var btlsSupported = (bool)isProviderSupported.Invoke(null, new string[] { "btls" });
if (btlsSupported) {
if (btlsSupported)
{
// initialize btls
MethodInfo initialize = monoTlsProviderFactory.GetMethod("Initialize", new[] { typeof(string) });
if (initialize != null) {
if (initialize != null)
{
initialize.Invoke(null, new string[] { "btls" });
usehttpclient = true;
}
@@ -87,7 +97,9 @@ namespace Jackett
}
}
}
} catch (Exception e) {
}
catch (Exception e)
{
Console.Out.WriteLine("Error while deciding which HttpWebClient to use: " + e);
}
@@ -95,24 +107,34 @@ namespace Jackett
builder.RegisterType<HttpWebClient>().As<IWebClient>();
else
builder.RegisterType<UnixLibCurlWebClient>().As<IWebClient>();
} else {
}
else
{
builder.RegisterType<HttpWebClient>().As<IWebClient>();
}
break;
}
// Register indexers
var indexerTypes = thisAssembly.GetTypes ().Where (p => typeof (IIndexer).IsAssignableFrom (p) && !p.IsInterface && !p.IsInNamespace ("Jackett.Indexers.Meta"));
foreach (var indexer in indexerTypes) {
var allTypes = thisAssembly.GetTypes();
var allIndexerTypes = allTypes.Where(p => typeof(IIndexer).IsAssignableFrom(p));
var allInstantiatableIndexerTypes = allIndexerTypes.Where(p => !p.IsInterface && !p.IsAbstract);
var allNonMetaInstantiatableIndexerTypes = allInstantiatableIndexerTypes.Where(p => !typeof(BaseMetaIndexer).IsAssignableFrom(p));
var indexerTypes = allNonMetaInstantiatableIndexerTypes.Where(p => p.Name != "CardigannIndexer");
foreach (var indexer in indexerTypes)
{
builder.RegisterType(indexer).Named<IIndexer>(BaseIndexer.GetIndexerID(indexer));
}
Mapper.CreateMap<WebClientByteResult, WebClientStringResult> ().ForMember (x => x.Content, opt => opt.Ignore ()).AfterMap ((be, str) => {
Mapper.CreateMap<WebClientByteResult, WebClientStringResult>().ForMember(x => x.Content, opt => opt.Ignore()).AfterMap((be, str) =>
{
str.Content = Encoding.UTF8.GetString(be.Content);
});
Mapper.CreateMap<WebClientStringResult, WebClientByteResult> ().ForMember (x => x.Content, opt => opt.Ignore ()).AfterMap ((str, be) => {
if (!string.IsNullOrEmpty (str.Content)) {
Mapper.CreateMap<WebClientStringResult, WebClientByteResult>().ForMember(x => x.Content, opt => opt.Ignore()).AfterMap((str, be) =>
{
if (!string.IsNullOrEmpty(str.Content))
{
be.Content = Encoding.UTF8.GetBytes(str.Content);
}
});
@@ -121,11 +143,15 @@ namespace Jackett
Mapper.CreateMap<WebClientByteResult, WebClientByteResult>();
Mapper.CreateMap<ReleaseInfo, ReleaseInfo>();
Mapper.CreateMap<ReleaseInfo, TrackerCacheResult> ().AfterMap ((r, t) => {
if (r.Category != null) {
Mapper.CreateMap<ReleaseInfo, TrackerCacheResult>().AfterMap((r, t) =>
{
if (r.Category != null)
{
var CategoryDesc = string.Join(", ", r.Category.Select(x => TorznabCatType.GetCatDesc(x)).Where(x => !string.IsNullOrEmpty(x)));
t.CategoryDesc = CategoryDesc;
} else {
}
else
{
t.CategoryDesc = "";
}
});

View File

@@ -0,0 +1,30 @@
using System;
using System.Text;
using Newtonsoft.Json;
namespace Jackett.Utils
{
public class EncodingJsonConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return true;
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var obj = value as Encoding;
writer.WriteValue(obj.WebName);
}
public override bool CanRead
{
get { return false; }
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
throw new NotImplementedException();
}
}
}