1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-30 07:22:35 +01:00

splited MVC and nancy application

backbone app is now fully served from nancy including css,js,html
This commit is contained in:
kay.one 2013-02-17 18:10:21 -08:00
parent fd4ffa0fa2
commit 7093f352fe
184 changed files with 497 additions and 1959 deletions

View File

@ -56,30 +56,14 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\MVC3\System.Web.Helpers.dll</HintPath>
</Reference>
<Reference Include="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\MVC3\System.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\MVC3\System.Web.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\MVC3\System.Web.WebPages.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\MVC3\System.Web.WebPages.Deployment.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\MVC3\System.Web.WebPages.Razor.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AutofacDependencyResolver.cs" />

View File

@ -5,6 +5,8 @@ using Autofac;
using NLog;
using Nancy.Bootstrapper;
using Nancy.Bootstrappers.Autofac;
using Nancy.Conventions;
using Nancy.Diagnostics;
using NzbDrone.Api.ErrorManagment;
using NzbDrone.Api.Extentions;
using NzbDrone.Api.QualityProfiles;
@ -14,6 +16,7 @@ using NzbDrone.Api.Series;
using NzbDrone.Core;
using NzbDrone.Core.Helpers;
using NzbDrone.Core.Repository.Quality;
using ErrorPipeline = NzbDrone.Api.ErrorManagment.ErrorPipeline;
namespace NzbDrone.Api
{
@ -27,6 +30,14 @@ namespace NzbDrone.Api
_logger = LogManager.GetCurrentClassLogger();
}
protected override Nancy.IRootPathProvider RootPathProvider
{
get
{
return new RootPathProvider();
}
}
protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
{
InitializeAutomapper();
@ -100,5 +111,18 @@ namespace NzbDrone.Api
return internalConfig;
}
}
protected override DiagnosticsConfiguration DiagnosticsConfiguration
{
get { return new DiagnosticsConfiguration { Password = @"password" }; }
}
protected override void ConfigureConventions(Nancy.Conventions.NancyConventions nancyConventions)
{
base.ConfigureConventions(nancyConventions);
Conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("static", @"NzbDrone.Backbone",new string[]{".css",".js",".html",".htm",".jpg",".jpeg",".icon",".gif",".png",".woff",".ttf"}));
}
}
}

View File

@ -0,0 +1,14 @@
using System.IO;
using System.Linq;
using Nancy;
namespace NzbDrone.Api.Extentions
{
public class RootPathProvider : IRootPathProvider
{
public string GetRootPath()
{
return Directory.GetCurrentDirectory();
}
}
}

View File

@ -1,4 +1,5 @@
using System.Linq;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

View File

@ -0,0 +1,43 @@
using System;
using System.IO;
using System.Linq;
using Nancy;
using Nancy.Responses;
namespace NzbDrone.Api.FrontendModule
{
public class BootstrapModule : NancyModule
{
private readonly ICompileLess _lessCompiler;
public BootstrapModule(ICompileLess lessCompiler)
{
_lessCompiler = lessCompiler;
Get[@"static/content/bootstrap/bootstrap.less"] = x => OnGet();
}
private Response OnGet()
{
/* var urlParts = Request.Path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
if (urlParts.Length < 2)
{
return new NotFoundResponse();
}
urlParts[0] = "NzbDrone.Backbone";
var filePath = Path.Combine(urlParts);
if (!File.Exists(filePath))
{
return new NotFoundResponse();
}*/
var css = _lessCompiler.Compile(Path.Combine("NzbDrone.Backbone","Content","Bootstrap","bootstrap.less"));
return new TextResponse(HttpStatusCode.OK, css) { ContentType = "text/css" };
}
}
}

View File

@ -0,0 +1,13 @@
using System.Linq;
using Nancy;
namespace NzbDrone.Api.FrontendModule
{
public class IndexModule : NancyModule
{
public IndexModule()
{
Get[@"/"] = x => View["NzbDrone.Backbone/index.html"];
}
}
}

View File

@ -0,0 +1,56 @@
using System.IO;
using System.Linq;
using dotless.Core;
using dotless.Core.Importers;
using dotless.Core.Input;
using dotless.Core.Parser;
namespace NzbDrone.Api.FrontendModule
{
public interface ICompileLess
{
string Compile(string filePath);
}
public class LessCompiler : ICompileLess
{
public string Compile(string filePath)
{
var parser = new Parser()
{
Importer = new Importer(new LessFileReader(filePath))
};
var lessEngine = new LessEngine(parser, null, false, true);
var lessContent = File.ReadAllText(filePath);
return lessEngine.TransformToCss(lessContent, filePath);
}
class LessFileReader : IFileReader
{
private readonly string _rootFolders;
public LessFileReader(string masterFile)
{
_rootFolders = new FileInfo(masterFile).Directory.FullName;
}
public byte[] GetBinaryFileContents(string fileName)
{
return File.ReadAllBytes(Path.Combine(_rootFolders, fileName));
}
public string GetFileContents(string fileName)
{
return File.ReadAllText(Path.Combine(_rootFolders, fileName));
}
public bool DoesFileExist(string fileName)
{
return File.Exists(Path.Combine(_rootFolders, fileName));
}
}
}
}

View File

@ -82,6 +82,9 @@
<Reference Include="AutoMapper">
<HintPath>..\packages\AutoMapper.2.2.0\lib\net40\AutoMapper.dll</HintPath>
</Reference>
<Reference Include="dotless.ClientOnly">
<HintPath>..\packages\DotlessClientOnly.1.3.1.0\lib\dotless.ClientOnly.dll</HintPath>
</Reference>
<Reference Include="FluentValidation">
<HintPath>..\packages\FluentValidation.3.4.6.0\lib\Net40\FluentValidation.dll</HintPath>
</Reference>
@ -89,13 +92,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Nancy.0.16.1\lib\net40\Nancy.dll</HintPath>
</Reference>
<Reference Include="Nancy.Bootstrappers.Autofac, Version=0.15.3.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="Nancy.Bootstrappers.Autofac, Version=0.16.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\NzbDrone.Services.Api\bin\Nancy.Bootstrappers.Autofac.dll</HintPath>
</Reference>
<Reference Include="Nancy.Hosting.Aspnet, Version=0.16.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Nancy.Hosting.Aspnet.0.16.1\lib\net40\Nancy.Hosting.Aspnet.dll</HintPath>
<HintPath>..\packages\Nancy.Bootstrappers.Autofac.0.16.1\lib\net40\Nancy.Bootstrappers.Autofac.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@ -121,9 +120,13 @@
<Compile Include="Directories\DirectoryModule.cs" />
<Compile Include="Extentions\NancyJsonSerializer.cs" />
<Compile Include="Extentions\Serializer.cs" />
<Compile Include="FrontendModule\IndexModule.cs" />
<Compile Include="FrontendModule\BootstrapModule.cs" />
<Compile Include="FrontendModule\LessService.cs" />
<Compile Include="Resolvers\NextAiringResolver.cs" />
<Compile Include="Resolvers\NullableDatetimeToString.cs" />
<Compile Include="RootFolders\RootFolderModule.cs" />
<Compile Include="Extentions\RootPathProvider.cs" />
<Compile Include="Series\SeriesResource.cs" />
<Compile Include="Series\SeriesModule.cs" />
<Compile Include="Series\SeriesLookupModule.cs" />

View File

@ -2,9 +2,10 @@
<packages>
<package id="Autofac" version="3.0.1" targetFramework="net40" />
<package id="AutoMapper" version="2.2.0" targetFramework="net40" />
<package id="DotlessClientOnly" version="1.3.1.0" targetFramework="net40" />
<package id="FluentValidation" version="3.4.6.0" targetFramework="net40" />
<package id="Nancy" version="0.16.1" targetFramework="net40" />
<package id="Nancy.Hosting.Aspnet" version="0.16.1" targetFramework="net40" />
<package id="Nancy.Bootstrappers.Autofac" version="0.16.1" targetFramework="net40" />
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" />
<package id="NLog" version="2.0.0.2000" targetFramework="net40" />
</packages>

View File

Before

Width:  |  Height:  |  Size: 152 B

After

Width:  |  Height:  |  Size: 152 B

View File

Before

Width:  |  Height:  |  Size: 172 B

After

Width:  |  Height:  |  Size: 172 B

View File

Before

Width:  |  Height:  |  Size: 198 B

After

Width:  |  Height:  |  Size: 198 B

View File

Before

Width:  |  Height:  |  Size: 250 B

After

Width:  |  Height:  |  Size: 250 B

View File

Before

Width:  |  Height:  |  Size: 136 B

After

Width:  |  Height:  |  Size: 136 B

View File

Before

Width:  |  Height:  |  Size: 603 B

After

Width:  |  Height:  |  Size: 603 B

View File

Before

Width:  |  Height:  |  Size: 260 B

After

Width:  |  Height:  |  Size: 260 B

View File

Before

Width:  |  Height:  |  Size: 264 B

After

Width:  |  Height:  |  Size: 264 B

View File

Before

Width:  |  Height:  |  Size: 816 B

After

Width:  |  Height:  |  Size: 816 B

View File

Before

Width:  |  Height:  |  Size: 385 B

After

Width:  |  Height:  |  Size: 385 B

View File

Before

Width:  |  Height:  |  Size: 665 B

After

Width:  |  Height:  |  Size: 665 B

View File

Before

Width:  |  Height:  |  Size: 491 B

After

Width:  |  Height:  |  Size: 491 B

View File

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 63 KiB

After

Width:  |  Height:  |  Size: 63 KiB

View File

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 752 B

After

Width:  |  Height:  |  Size: 752 B

View File

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

Before

Width:  |  Height:  |  Size: 440 B

After

Width:  |  Height:  |  Size: 440 B

View File

Before

Width:  |  Height:  |  Size: 418 B

After

Width:  |  Height:  |  Size: 418 B

View File

Before

Width:  |  Height:  |  Size: 554 B

After

Width:  |  Height:  |  Size: 554 B

View File

Before

Width:  |  Height:  |  Size: 447 B

After

Width:  |  Height:  |  Size: 447 B

View File

Before

Width:  |  Height:  |  Size: 411 B

After

Width:  |  Height:  |  Size: 411 B

View File

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 59 KiB

View File

Before

Width:  |  Height:  |  Size: 541 B

After

Width:  |  Height:  |  Size: 541 B

Some files were not shown because too many files have changed in this diff Show More