Merge pull request #2300 from MediaBrowser/dev

Dev
This commit is contained in:
Luke 2016-11-21 13:50:14 -05:00 committed by GitHub
commit e439bbba42
10 changed files with 170 additions and 71 deletions

View File

@ -58,31 +58,37 @@ namespace Emby.Server.Implementations.Data
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
using (var connection = CreateConnection()) using (var connection = CreateConnection())
{
using (WriteLock.Write())
{ {
connection.RunInTransaction(db => connection.RunInTransaction(db =>
{ {
var paramList = new List<object>(); var commandText = "replace into FileOrganizerResults (ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths) values (@ResultId, @OriginalPath, @TargetPath, @FileLength, @OrganizationDate, @Status, @OrganizationType, @StatusMessage, @ExtractedName, @ExtractedYear, @ExtractedSeasonNumber, @ExtractedEpisodeNumber, @ExtractedEndingEpisodeNumber, @DuplicatePaths)";
var commandText = "replace into FileOrganizerResults (ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
paramList.Add(result.Id.ToGuidParamValue()); using (var statement = db.PrepareStatement(commandText))
paramList.Add(result.OriginalPath); {
paramList.Add(result.TargetPath); statement.TryBind("@ResultId", result.Id.ToGuidParamValue());
paramList.Add(result.FileSize); statement.TryBind("@OriginalPath", result.OriginalPath);
paramList.Add(result.Date.ToDateTimeParamValue());
paramList.Add(result.Status.ToString());
paramList.Add(result.Type.ToString());
paramList.Add(result.StatusMessage);
paramList.Add(result.ExtractedName);
paramList.Add(result.ExtractedSeasonNumber);
paramList.Add(result.ExtractedEpisodeNumber);
paramList.Add(result.ExtractedEndingEpisodeNumber);
paramList.Add(string.Join("|", result.DuplicatePaths.ToArray()));
statement.TryBind("@TargetPath", result.TargetPath);
statement.TryBind("@FileLength", result.FileSize);
statement.TryBind("@OrganizationDate", result.Date.ToDateTimeParamValue());
statement.TryBind("@Status", result.Status.ToString());
statement.TryBind("@OrganizationType", result.Type.ToString());
statement.TryBind("@StatusMessage", result.StatusMessage);
statement.TryBind("@ExtractedName", result.ExtractedName);
statement.TryBind("@ExtractedYear", result.ExtractedYear);
statement.TryBind("@ExtractedSeasonNumber", result.ExtractedSeasonNumber);
statement.TryBind("@ExtractedEpisodeNumber", result.ExtractedEpisodeNumber);
statement.TryBind("@ExtractedEndingEpisodeNumber", result.ExtractedEndingEpisodeNumber);
statement.TryBind("@DuplicatePaths", string.Join("|", result.DuplicatePaths.ToArray()));
db.Execute(commandText, paramList.ToArray()); statement.MoveNext();
}
}); });
} }
} }
}
public async Task Delete(string id) public async Task Delete(string id)
{ {
@ -92,22 +98,26 @@ namespace Emby.Server.Implementations.Data
} }
using (var connection = CreateConnection()) using (var connection = CreateConnection())
{
using (WriteLock.Write())
{ {
connection.RunInTransaction(db => connection.RunInTransaction(db =>
{ {
var paramList = new List<object>(); using (var statement = db.PrepareStatement("delete from FileOrganizerResults where ResultId = @ResultId"))
var commandText = "delete from FileOrganizerResults where ResultId = ?"; {
statement.TryBind("@ResultId", id.ToGuidParamValue());
paramList.Add(id.ToGuidParamValue()); statement.MoveNext();
}
db.Execute(commandText, paramList.ToArray());
}); });
} }
} }
}
public async Task DeleteAll() public async Task DeleteAll()
{ {
using (var connection = CreateConnection()) using (var connection = CreateConnection())
{
using (WriteLock.Write())
{ {
connection.RunInTransaction(db => connection.RunInTransaction(db =>
{ {
@ -117,6 +127,7 @@ namespace Emby.Server.Implementations.Data
}); });
} }
} }
}
public QueryResult<FileOrganizationResult> GetResults(FileOrganizationResultQuery query) public QueryResult<FileOrganizationResult> GetResults(FileOrganizationResultQuery query)
{ {
@ -126,6 +137,8 @@ namespace Emby.Server.Implementations.Data
} }
using (var connection = CreateConnection(true)) using (var connection = CreateConnection(true))
{
using (WriteLock.Read())
{ {
var commandText = "SELECT ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths from FileOrganizerResults"; var commandText = "SELECT ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths from FileOrganizerResults";
@ -143,12 +156,20 @@ namespace Emby.Server.Implementations.Data
} }
var list = new List<FileOrganizationResult>(); var list = new List<FileOrganizationResult>();
var count = connection.Query("select count (ResultId) from FileOrganizerResults").SelectScalarInt().First();
foreach (var row in connection.Query(commandText)) using (var statement = connection.PrepareStatement(commandText))
{
foreach (var row in statement.ExecuteQuery())
{ {
list.Add(GetResult(row)); list.Add(GetResult(row));
} }
}
int count;
using (var statement = connection.PrepareStatement("select count (ResultId) from FileOrganizerResults"))
{
count = statement.ExecuteQuery().SelectScalarInt().First();
}
return new QueryResult<FileOrganizationResult>() return new QueryResult<FileOrganizationResult>()
{ {
@ -157,6 +178,7 @@ namespace Emby.Server.Implementations.Data
}; };
} }
} }
}
public FileOrganizationResult GetResult(string id) public FileOrganizationResult GetResult(string id)
{ {
@ -167,18 +189,23 @@ namespace Emby.Server.Implementations.Data
using (var connection = CreateConnection(true)) using (var connection = CreateConnection(true))
{ {
var paramList = new List<object>(); using (WriteLock.Read())
{
using (var statement = connection.PrepareStatement("select ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths from FileOrganizerResults where ResultId=@ResultId"))
{
statement.TryBind("@ResultId", id.ToGuidParamValue());
statement.MoveNext();
paramList.Add(id.ToGuidParamValue()); foreach (var row in statement.ExecuteQuery())
foreach (var row in connection.Query("select ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths from FileOrganizerResults where ResultId=?", paramList.ToArray()))
{ {
return GetResult(row); return GetResult(row);
} }
}
return null; return null;
} }
} }
}
public FileOrganizationResult GetResult(IReadOnlyList<IResultSetValue> reader) public FileOrganizationResult GetResult(IReadOnlyList<IResultSetValue> reader)
{ {

View File

@ -159,8 +159,8 @@ namespace Emby.Server.Implementations.Data
{ {
using (var statement = db.PrepareStatement("replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)")) using (var statement = db.PrepareStatement("replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)"))
{ {
statement.TryBind("@UserId", userId.ToGuidParamValue()); statement.TryBind("@userId", userId.ToGuidParamValue());
statement.TryBind("@Key", key); statement.TryBind("@key", key);
if (userData.Rating.HasValue) if (userData.Rating.HasValue)
{ {

View File

@ -31,6 +31,15 @@ namespace MediaBrowser.Controller.Entities.Audio
get { return true; } get { return true; }
} }
[IgnoreDataMember]
public override bool SupportsAncestors
{
get
{
return false;
}
}
/// <summary> /// <summary>
/// Returns the folder containing the item. /// Returns the folder containing the item.
/// If the item is a folder, it returns the folder itself /// If the item is a folder, it returns the folder itself

View File

@ -37,6 +37,15 @@ namespace MediaBrowser.Controller.Entities
} }
} }
[IgnoreDataMember]
public override bool SupportsAncestors
{
get
{
return false;
}
}
/// <summary> /// <summary>
/// Gets a value indicating whether this instance is owned item. /// Gets a value indicating whether this instance is owned item.
/// </summary> /// </summary>

View File

@ -40,6 +40,15 @@ namespace MediaBrowser.Controller.Entities
} }
} }
[IgnoreDataMember]
public override bool SupportsAncestors
{
get
{
return false;
}
}
public override bool IsSaveLocalMetadataEnabled() public override bool IsSaveLocalMetadataEnabled()
{ {
return true; return true;

View File

@ -39,6 +39,15 @@ namespace MediaBrowser.Controller.Entities
} }
} }
[IgnoreDataMember]
public override bool SupportsAncestors
{
get
{
return false;
}
}
public override bool CanDelete() public override bool CanDelete()
{ {
return false; return false;

View File

@ -33,6 +33,15 @@ namespace MediaBrowser.Controller.Entities
} }
} }
[IgnoreDataMember]
public override bool SupportsAncestors
{
get
{
return false;
}
}
public override bool CanDelete() public override bool CanDelete()
{ {
return false; return false;

View File

@ -88,15 +88,16 @@
<HintPath>..\packages\SQLitePCLRaw.core.1.1.1-pre20161109081005\lib\net45\SQLitePCLRaw.core.dll</HintPath> <HintPath>..\packages\SQLitePCLRaw.core.1.1.1-pre20161109081005\lib\net45\SQLitePCLRaw.core.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="SQLitePCLRaw.provider.sqlite3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=62684c7b4f184e3f, processorArchitecture=MSIL">
<HintPath>..\packages\SQLitePCLRaw.provider.sqlite3.net45.1.1.1-pre20161109081005\lib\net45\SQLitePCLRaw.provider.sqlite3.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="MediaBrowser.IsoMounting.Linux"> <Reference Include="MediaBrowser.IsoMounting.Linux">
<HintPath>..\ThirdParty\MediaBrowser.IsoMounting.Linux\MediaBrowser.IsoMounting.Linux.dll</HintPath> <HintPath>..\ThirdParty\MediaBrowser.IsoMounting.Linux\MediaBrowser.IsoMounting.Linux.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Data.SQLite">
<HintPath>..\ThirdParty\SQLitePCLRaw.provider.sqlite3.net45\System.Data.SQLite.dll</HintPath>
</Reference>
<Reference Include="System.IO.Compression" /> <Reference Include="System.IO.Compression" />
<Reference Include="System.Runtime.Serialization" /> <Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" /> <Reference Include="System.ServiceModel" />
@ -222,6 +223,10 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="SQLitePCLRaw.provider.sqlite3.dll.config">
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="System.Data.SQLite.dll.config"> <None Include="System.Data.SQLite.dll.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType> <SubType>Designer</SubType>

View File

@ -35,9 +35,11 @@ namespace MediaBrowser.Server.Mono
public static void Main(string[] args) public static void Main(string[] args)
{ {
SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3());
var applicationPath = Assembly.GetEntryAssembly().Location; var applicationPath = Assembly.GetEntryAssembly().Location;
var appFolderPath = Path.GetDirectoryName(applicationPath);
TryCopySqliteConfigFile(appFolderPath);
SetSqliteProvider();
var options = new StartupOptions(Environment.GetCommandLineArgs()); var options = new StartupOptions(Environment.GetCommandLineArgs());
@ -68,6 +70,25 @@ namespace MediaBrowser.Server.Mono
} }
} }
private static void TryCopySqliteConfigFile(string appFolderPath)
{
try
{
File.Copy(Path.Combine(appFolderPath, "System.Data.SQLite.dll.config"),
Path.Combine(appFolderPath, "SQLitePCLRaw.provider.sqlite3.dll.config"),
true);
}
catch
{
}
}
private static void SetSqliteProvider()
{
SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3());
}
private static ServerApplicationPaths CreateApplicationPaths(string applicationPath, string programDataPath) private static ServerApplicationPaths CreateApplicationPaths(string applicationPath, string programDataPath)
{ {
if (string.IsNullOrEmpty(programDataPath)) if (string.IsNullOrEmpty(programDataPath))

View File

@ -6,4 +6,5 @@
<package id="SharpCompress" version="0.14.0" targetFramework="net46" /> <package id="SharpCompress" version="0.14.0" targetFramework="net46" />
<package id="SimpleInjector" version="3.2.4" targetFramework="net46" /> <package id="SimpleInjector" version="3.2.4" targetFramework="net46" />
<package id="SQLitePCLRaw.core" version="1.1.1-pre20161109081005" targetFramework="net46" /> <package id="SQLitePCLRaw.core" version="1.1.1-pre20161109081005" targetFramework="net46" />
<package id="SQLitePCLRaw.provider.sqlite3.net45" version="1.1.1-pre20161109081005" targetFramework="net46" />
</packages> </packages>