1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00

Goodbye EF!

This commit is contained in:
Mark McDowall 2013-01-08 00:57:38 -08:00
parent 165600301c
commit b8fff306bf
16 changed files with 52 additions and 134 deletions

View File

@ -1,9 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<appSettings>
<!-- Supported values: nunit, xunit and mstest -->

View File

@ -69,10 +69,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\DeskMetrics\DeskMetrics.NET.dll</HintPath>
</Reference>
<Reference Include="EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\EntityFramework.4.3.1\lib\net40\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="FizzWare.NBuilder, Version=3.0.1.0, Culture=neutral, PublicKeyToken=5651b03e12e42c12, processorArchitecture=MSIL">
<HintPath>..\packages\NBuilder.3.0.1.1\lib\FizzWare.NBuilder.dll</HintPath>
</Reference>
@ -127,10 +123,6 @@
<Private>True</Private>
<HintPath>..\packages\Microsoft.SqlServer.Compact.4.0.8876.1\lib\net40\System.Data.SqlServerCe.dll</HintPath>
</Reference>
<Reference Include="System.Data.SqlServerCe.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\EntityFramework.SqlServerCompact.4.3.6\lib\net40\System.Data.SqlServerCe.Entity.dll</HintPath>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Transactions" />

View File

@ -19,7 +19,6 @@ public class LogProviderFixture : CoreTest
{
private const string LOGGER_NAME = "Core.Test.ProviderTests.LogProviderTests.LogProviderFixture";
private static LogDbContext dbContext;
private static string UniqueMessage;
Logger Logger;
@ -29,10 +28,6 @@ public void Setup()
{
WithRealDb();
dbContext = Connection.GetLogDbContext(TestDbHelper.ConnectionString);
Mocker.SetConstant(dbContext);
new DatabaseTarget(Db).Register();
Logger = LogManager.GetCurrentClassLogger();

View File

@ -3,8 +3,6 @@
<package id="Autofac" version="2.6.3.862" targetFramework="net40" />
<package id="AutoMoq" version="1.6.1" targetFramework="net40" />
<package id="CommonServiceLocator" version="1.0" targetFramework="net40" />
<package id="EntityFramework" version="4.3.1" targetFramework="net40" />
<package id="EntityFramework.SqlServerCompact" version="4.3.6" targetFramework="net40" />
<package id="FluentAssertions" version="1.7.0" />
<package id="Microsoft.SqlServer.Compact" version="4.0.8876.1" targetFramework="net40" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" />

View File

@ -1,9 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">

View File

@ -63,10 +63,6 @@ private void InitDatabase()
ContainerBuilder.Register(c => c.Resolve<Connection>().GetLogPetaPocoDb())
.Named<IDatabase>("LogProvider");
ContainerBuilder.Register(c => c.Resolve<Connection>().GetLogEfContext())
.As<LogDbContext>()
.SingleInstance();
ContainerBuilder.RegisterType<DatabaseTarget>().WithParameter(ResolvedParameter.ForNamed<IDatabase>("DatabaseTarget"));
ContainerBuilder.RegisterType<LogProvider>().WithParameter(ResolvedParameter.ForNamed<IDatabase>("LogProvider"));
}

View File

@ -59,11 +59,6 @@ public IDatabase GetLogPetaPocoDb(Boolean profiled = true)
return GetPetaPocoDb(LogConnectionString, profiled);
}
public LogDbContext GetLogEfContext()
{
return GetLogDbContext(LogConnectionString);
}
public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled = true)
{
MigrationsHelper.Run(connectionString, true);
@ -81,13 +76,5 @@ public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled
return db;
}
public static LogDbContext GetLogDbContext(string connectionString)
{
MigrationsHelper.Run(connectionString, true);
DbConnection connection = new SqlCeConnection(connectionString);
return new LogDbContext(connection);
}
}
}

View File

@ -1,20 +0,0 @@
using System.Data.Common;
using System.Data.Entity;
using System.Linq;
namespace NzbDrone.Core.Instrumentation
{
public class LogDbContext : DbContext
{
public LogDbContext(DbConnection connection)
: base(connection, false)
{
}
public LogDbContext()
{
}
public DbSet<Log> Logs { get; set; }
}
}

View File

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DataTables.Mvc.Core.Helpers;
using DataTables.Mvc.Core.Models;
using NLog;
using NzbDrone.Common;
using PetaPoco;
@ -10,24 +12,20 @@ namespace NzbDrone.Core.Instrumentation
public class LogProvider
{
private readonly IDatabase _database;
private readonly LogDbContext _logDbContext;
private readonly DiskProvider _diskProvider;
private readonly EnvironmentProvider _environmentProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public LogProvider(IDatabase database, LogDbContext logDbContext, DiskProvider diskProvider, EnvironmentProvider environmentProvider)
public LogProvider(IDatabase database, DiskProvider diskProvider, EnvironmentProvider environmentProvider)
{
_database = database;
_logDbContext = logDbContext;
_diskProvider = diskProvider;
_environmentProvider = environmentProvider;
}
public IQueryable<Log> GetAllLogs()
public List<Log> GetAllLogs()
{
return _logDbContext.Logs;
return _database.Fetch<Log>();
}
public IList<Log> TopLogs(int count)
@ -44,9 +42,35 @@ public IList<Log> TopLogs(int count)
return logs;
}
public Page<Log> GetPagedLogs(int pageNumber, int pageSize)
public virtual Page<Log> GetPagedItems(DataTablesPageRequest pageRequest)
{
return _database.Page<Log>(pageNumber, pageSize, "SELECT * FROM Logs ORDER BY Time DESC");
var query = Sql.Builder
.Select(@"*")
.From("Logs");
var startPage = (pageRequest.DisplayLength == 0) ? 1 : pageRequest.DisplayStart / pageRequest.DisplayLength + 1;
if (!string.IsNullOrEmpty(pageRequest.Search))
{
var whereClause = string.Join(" OR ", SqlBuilderHelper.GetSearchClause(pageRequest));
if (!string.IsNullOrEmpty(whereClause))
query.Append("WHERE " + whereClause, "%" + pageRequest.Search + "%");
}
var orderBy = string.Join(",", SqlBuilderHelper.GetOrderByClause(pageRequest));
if (!string.IsNullOrEmpty(orderBy))
{
query.Append("ORDER BY " + orderBy);
}
return _database.Page<Log>(startPage, pageRequest.DisplayLength, query);
}
public virtual long Count()
{
return _database.Single<long>(@"SELECT COUNT(*) from Logs");
}
public void DeleteAll()

View File

@ -136,10 +136,6 @@
<Reference Include="DeskMetrics.NET">
<HintPath>..\Libraries\DeskMetrics\DeskMetrics.NET.dll</HintPath>
</Reference>
<Reference Include="EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\EntityFramework.4.3.1\lib\net40\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="Growl.Connector">
<HintPath>..\packages\Growl.0.6\lib\Growl.Connector.dll</HintPath>
</Reference>
@ -199,10 +195,6 @@
<Private>True</Private>
<HintPath>..\packages\Microsoft.SqlServer.Compact.4.0.8876.1\lib\net40\System.Data.SqlServerCe.dll</HintPath>
</Reference>
<Reference Include="System.Data.SqlServerCe.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\EntityFramework.SqlServerCompact.4.3.6\lib\net40\System.Data.SqlServerCe.Entity.dll</HintPath>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Transactions" />
@ -279,7 +271,6 @@
<Compile Include="Jobs\SearchHistoryCleanupJob.cs" />
<Compile Include="Model\HistoryQueryModel.cs" />
<Compile Include="Model\DownloadClientType.cs" />
<Compile Include="Instrumentation\LogDbContext.cs" />
<Compile Include="Instrumentation\LogProvider.cs" />
<Compile Include="Instrumentation\DatabaseTarget.cs" />
<Compile Include="Datastore\PetaPoco\PetaPoco.cs" />

View File

@ -3,8 +3,6 @@
<package id="Autofac" version="2.6.3.862" targetFramework="net40" />
<package id="DataTables.Mvc.Core" version="0.1.0.85" />
<package id="DotNetZip" version="1.9.1.8" />
<package id="EntityFramework" version="4.3.1" targetFramework="net40" />
<package id="EntityFramework.SqlServerCompact" version="4.3.6" targetFramework="net40" />
<package id="Growl" version="0.6" />
<package id="Microsoft.SqlServer.Compact" version="4.0.8876.1" targetFramework="net40" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" />

View File

@ -49,53 +49,26 @@ public JsonResult Clear()
public ActionResult AjaxBinding(DataTablesPageRequest pageRequest)
{
var logs = _logProvider.GetAllLogs();
var totalCount = logs.Count();
var pageResult = _logProvider.GetPagedItems(pageRequest);
var totalItems = _logProvider.Count();
IQueryable<Log> q = logs;
if (!string.IsNullOrEmpty(pageRequest.Search))
var items = pageResult.Items.Select(l => new LogModel
{
q = q.Where(b => b.Logger.Contains(pageRequest.Search)
|| b.Exception.Contains(pageRequest.Search)
|| b.Message.Contains(pageRequest.Search));
}
int filteredCount = q.Count();
IQueryable<Log> sorted = q;
for (int i = 0; i < pageRequest.SortingCols; i++)
{
int sortCol = pageRequest.SortCol[i];
var sortColName = sortCol == 0 ? "Time" : sortCol == 1 ? "Level" : "Logger";
var sortExpression = String.Format("{0} {1}", sortColName, pageRequest.SortDir[i]);
sorted = sorted.OrderBy(sortExpression);
}
IQueryable<Log> filteredAndSorted = sorted;
if (filteredCount > pageRequest.DisplayLength)
{
filteredAndSorted = sorted.Skip(pageRequest.DisplayStart).Take(pageRequest.DisplayLength);
}
var logModels = filteredAndSorted.ToList().Select(s => new LogModel
{
Time = s.Time.ToString(),
Level = s.Level,
Source = s.Logger,
Message = s.Message,
Method = s.Method,
ExceptionType = s.ExceptionType,
Exception = s.Exception
Time = l.Time.ToString(),
Level = l.Level,
Source = l.Logger,
Message = l.Message,
Method = l.Method,
ExceptionType = l.ExceptionType,
Exception = l.Exception
});
return Json(new
{
sEcho = pageRequest.Echo,
iTotalRecords = totalCount,
iTotalDisplayRecords = filteredCount,
aaData = logModels
iTotalRecords = totalItems,
iTotalDisplayRecords = pageResult.TotalItems,
aaData = items
},
JsonRequestBehavior.AllowGet);
}

View File

@ -69,10 +69,6 @@
<Reference Include="Dynamic">
<HintPath>..\packages\DynamicQuery.1.0\lib\35\Dynamic.dll</HintPath>
</Reference>
<Reference Include="EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\EntityFramework.4.3.1\lib\net40\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="LowercaseRoutesMVC">
<HintPath>..\packages\LowercaseRoutesMVC.1.0.3\lib\LowercaseRoutesMVC.dll</HintPath>
</Reference>
@ -151,10 +147,6 @@
<Private>True</Private>
<HintPath>..\packages\Microsoft.SqlServer.Compact.4.0.8876.1\lib\net40\System.Data.SqlServerCe.dll</HintPath>
</Reference>
<Reference Include="System.Data.SqlServerCe.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\EntityFramework.SqlServerCompact.4.3.6\lib\net40\System.Data.SqlServerCe.Entity.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Transactions" />
<Reference Include="System.Web" />

View File

@ -62,11 +62,11 @@
"iDisplayLength": 50,
"sPaginationType": "four_button",
"aoColumns": [
{ sWidth: '150px', "mDataProp": "Time" }, //Time
{sWidth: '60px', "mDataProp": "Level" }, //Level
{sWidth: '240px', "mDataProp": "Source" }, //Source
{sWidth: 'auto', "mDataProp": "Message", "bSortable": false }, //Message
{sWidth: 'auto', "mDataProp": "Details", "bSortable": false, "bVisible": false, "fnRender": function (row) {
{ sName: "Time", sWidth: '150px', "mDataProp": "Time", bSearchable: false }, //Time
{ sName: "Level", sWidth: '60px', "mDataProp": "Level" }, //Level
{ sName: "Logger", sWidth: '240px', "mDataProp": "Source" }, //Source
{ sName: "Message", sWidth: 'auto', "mDataProp": "Message", "bSortable": false }, //Message
{ sName: "Exception", sWidth: 'auto', "mDataProp": "Details", "bSortable": false, "bVisible": false, "fnRender": function (row) {
var result = "<div>Method: " + row.aData["Method"] + "</div>";
if (row.aData["ExceptionType"] !== null) {

View File

@ -1,9 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />

View File

@ -6,8 +6,6 @@
<package id="DataTables.Mvc" version="0.1.0.85" />
<package id="DataTables.Mvc.Core" version="0.1.0.85" />
<package id="DynamicQuery" version="1.0" />
<package id="EntityFramework" version="4.3.1" targetFramework="net40" />
<package id="EntityFramework.SqlServerCompact" version="4.3.6" targetFramework="net40" />
<package id="FontAwesome" version="2.0.2" targetFramework="net40" />
<package id="jQuery" version="1.8.2" targetFramework="net40" />
<package id="jQuery.Ajax.Unobtrusive" version="2.0.20710.0" targetFramework="net40" />