@ -48,7 +48,7 @@ namespace Emby.Server.Implementations.Security
}
}
private void TryMigrate ( Managed Connection connection , bool tableNewlyCreated )
private void TryMigrate ( SQLiteDatabase Connection connection , bool tableNewlyCreated )
{
try
{
@ -87,31 +87,28 @@ namespace Emby.Server.Implementations.Security
throw new ArgumentNullException ( nameof ( info ) ) ;
}
using ( WriteLock . Write ( ) )
using ( var connection = CreateConnection ( ) )
{
using ( var connection = CreateConnection ( ) )
connection . RunInTransaction ( db = >
{
connection . RunInTransaction ( db = >
using ( var statement = db . PrepareStatement ( "insert into Tokens (AccessToken, DeviceId, AppName, AppVersion, DeviceName, UserId, UserName, IsActive, DateCreated, DateLastActivity) values (@AccessToken, @DeviceId, @AppName, @AppVersion, @DeviceName, @UserId, @UserName, @IsActive, @DateCreated, @DateLastActivity)" ) )
{
using ( var statement = db . PrepareStatement ( "insert into Tokens (AccessToken, DeviceId, AppName, AppVersion, DeviceName, UserId, UserName, IsActive, DateCreated, DateLastActivity) values (@AccessToken, @DeviceId, @AppName, @AppVersion, @DeviceName, @UserId, @UserName, @IsActive, @DateCreated, @DateLastActivity)" ) )
{
statement . TryBind ( "@AccessToken" , info . AccessToken ) ;
statement . TryBind ( "@DeviceId" , info . DeviceId ) ;
statement . TryBind ( "@AppName" , info . AppName ) ;
statement . TryBind ( "@AppVersion" , info . AppVersion ) ;
statement . TryBind ( "@DeviceName" , info . DeviceName ) ;
statement . TryBind ( "@UserId" , ( info . UserId . Equals ( Guid . Empty ) ? null : info . UserId . ToString ( "N" ) ) ) ;
statement . TryBind ( "@UserName" , info . UserName ) ;
statement . TryBind ( "@IsActive" , true ) ;
statement . TryBind ( "@DateCreated" , info . DateCreated . ToDateTimeParamValue ( ) ) ;
statement . TryBind ( "@DateLastActivity" , info . DateLastActivity . ToDateTimeParamValue ( ) ) ;
statement . MoveNext ( ) ;
}
} , TransactionMode ) ;
}
statement . TryBind ( "@AccessToken" , info . AccessToken ) ;
statement . TryBind ( "@DeviceId" , info . DeviceId ) ;
statement . TryBind ( "@AppName" , info . AppName ) ;
statement . TryBind ( "@AppVersion" , info . AppVersion ) ;
statement . TryBind ( "@DeviceName" , info . DeviceName ) ;
statement . TryBind ( "@UserId" , ( info . UserId . Equals ( Guid . Empty ) ? null : info . UserId . ToString ( "N" ) ) ) ;
statement . TryBind ( "@UserName" , info . UserName ) ;
statement . TryBind ( "@IsActive" , true ) ;
statement . TryBind ( "@DateCreated" , info . DateCreated . ToDateTimeParamValue ( ) ) ;
statement . TryBind ( "@DateLastActivity" , info . DateLastActivity . ToDateTimeParamValue ( ) ) ;
statement . MoveNext ( ) ;
}
} , TransactionMode ) ;
}
}
@ -122,31 +119,28 @@ namespace Emby.Server.Implementations.Security
throw new ArgumentNullException ( nameof ( info ) ) ;
}
using ( WriteLock . Write ( ) )
using ( var connection = CreateConnection ( ) )
{
using ( var connection = CreateConnection ( ) )
connection . RunInTransaction ( db = >
{
connection . RunInTransaction ( db = >
using ( var statement = db . PrepareStatement ( "Update Tokens set AccessToken=@AccessToken, DeviceId=@DeviceId, AppName=@AppName, AppVersion=@AppVersion, DeviceName=@DeviceName, UserId=@UserId, UserName=@UserName, DateCreated=@DateCreated, DateLastActivity=@DateLastActivity where Id=@Id" ) )
{
using ( var statement = db . PrepareStatement ( "Update Tokens set AccessToken=@AccessToken, DeviceId=@DeviceId, AppName=@AppName, AppVersion=@AppVersion, DeviceName=@DeviceName, UserId=@UserId, UserName=@UserName, DateCreated=@DateCreated, DateLastActivity=@DateLastActivity where Id=@Id" ) )
{
statement . TryBind ( "@Id" , info . Id ) ;
statement . TryBind ( "@AccessToken" , info . AccessToken ) ;
statement . TryBind ( "@DeviceId" , info . DeviceId ) ;
statement . TryBind ( "@AppName" , info . AppName ) ;
statement . TryBind ( "@AppVersion" , info . AppVersion ) ;
statement . TryBind ( "@DeviceName" , info . DeviceName ) ;
statement . TryBind ( "@UserId" , ( info . UserId . Equals ( Guid . Empty ) ? null : info . UserId . ToString ( "N" ) ) ) ;
statement . TryBind ( "@UserName" , info . UserName ) ;
statement . TryBind ( "@DateCreated" , info . DateCreated . ToDateTimeParamValue ( ) ) ;
statement . TryBind ( "@DateLastActivity" , info . DateLastActivity . ToDateTimeParamValue ( ) ) ;
statement . MoveNext ( ) ;
}
} , TransactionMode ) ;
}
statement . TryBind ( "@Id" , info . Id ) ;
statement . TryBind ( "@AccessToken" , info . AccessToken ) ;
statement . TryBind ( "@DeviceId" , info . DeviceId ) ;
statement . TryBind ( "@AppName" , info . AppName ) ;
statement . TryBind ( "@AppVersion" , info . AppVersion ) ;
statement . TryBind ( "@DeviceName" , info . DeviceName ) ;
statement . TryBind ( "@UserId" , ( info . UserId . Equals ( Guid . Empty ) ? null : info . UserId . ToString ( "N" ) ) ) ;
statement . TryBind ( "@UserName" , info . UserName ) ;
statement . TryBind ( "@DateCreated" , info . DateCreated . ToDateTimeParamValue ( ) ) ;
statement . TryBind ( "@DateLastActivity" , info . DateLastActivity . ToDateTimeParamValue ( ) ) ;
statement . MoveNext ( ) ;
}
} , TransactionMode ) ;
}
}
@ -157,20 +151,17 @@ namespace Emby.Server.Implementations.Security
throw new ArgumentNullException ( nameof ( info ) ) ;
}
using ( WriteLock . Write ( ) )
using ( var connection = CreateConnection ( ) )
{
using ( var connection = CreateConnection ( ) )
connection . RunInTransaction ( db = >
{
connection . RunInTransaction ( db = >
using ( var statement = db . PrepareStatement ( "Delete from Tokens where Id=@Id" ) )
{
using ( var statement = db . PrepareStatement ( "Delete from Tokens where Id=@Id" ) )
{
statement . TryBind ( "@Id" , info . Id ) ;
statement . TryBind ( "@Id" , info . Id ) ;
statement . MoveNext ( ) ;
}
} , TransactionMode ) ;
}
statement . MoveNext ( ) ;
}
} , TransactionMode ) ;
}
}
@ -257,45 +248,42 @@ namespace Emby.Server.Implementations.Security
var list = new List < AuthenticationInfo > ( ) ;
using ( WriteLock . Read ( ) )
using ( var connection = CreateConnection ( true ) )
{
using ( var connection = CreateConnection ( true ) )
return connection . RunInTransaction ( db = >
{
return connection . RunInTransaction ( db = >
{
var result = new QueryResult < AuthenticationInfo > ( ) ;
var result = new QueryResult < AuthenticationInfo > ( ) ;
var statementTexts = new List < string > ( ) ;
statementTexts . Add ( commandText ) ;
statementTexts . Add ( "select count (Id) from Tokens" + whereTextWithoutPaging ) ;
var statementTexts = new List < string > ( ) ;
statementTexts . Add ( commandText ) ;
statementTexts . Add ( "select count (Id) from Tokens" + whereTextWithoutPaging ) ;
var statements = PrepareAllSafe ( db , statementTexts )
. ToList ( ) ;
var statements = PrepareAllSafe ( db , statementTexts )
. ToList ( ) ;
using ( var statement = statements [ 0 ] )
{
BindAuthenticationQueryParams ( query , statement ) ;
using ( var statement = statements [ 0 ] )
{
BindAuthenticationQueryParams ( query , statement ) ;
foreach ( var row in statement . ExecuteQuery ( ) )
{
list . Add ( Get ( row ) ) ;
}
foreach ( var row in statement . ExecuteQuery ( ) )
{
list . Add ( Get ( row ) ) ;
}
using ( var totalCountStatement = statements [ 1 ] )
{
BindAuthenticationQueryParams ( query , totalCountStatement ) ;
using ( var totalCountStatement = statements [ 1 ] )
{
BindAuthenticationQueryParams ( query , totalCountStatement ) ;
result . TotalRecordCount = totalCountStatement . ExecuteQuery ( )
. SelectScalarInt ( )
. First ( ) ;
}
result . TotalRecordCount = totalCountStatement . ExecuteQuery ( )
. SelectScalarInt ( )
. First ( ) ;
}
}
result . Items = list . ToArray ( ) ;
return result ;
result . Items = list . ToArray ( ) ;
return result ;
} , ReadTransactionMode ) ;
}
} , ReadTransactionMode ) ;
}
}
@ -358,31 +346,28 @@ namespace Emby.Server.Implementations.Security
public DeviceOptions GetDeviceOptions ( string deviceId )
{
using ( WriteLock . Read ( ) )
using ( var connection = CreateConnection ( true ) )
{
using ( var connection = CreateConnection ( true ) )
return connection . RunInTransaction ( db = >
{
return connection . RunInTransaction ( db = >
using ( var statement = PrepareStatementSafe ( db , "select CustomName from Devices where Id=@DeviceId" ) )
{
using ( var statement = PrepareStatementSafe ( db , "select CustomName from Devices where Id=@DeviceId" ) )
{
statement . TryBind ( "@DeviceId" , deviceId ) ;
statement . TryBind ( "@DeviceId" , deviceId ) ;
var result = new DeviceOptions ( ) ;
var result = new DeviceOptions ( ) ;
foreach ( var row in statement . ExecuteQuery ( ) )
foreach ( var row in statement . ExecuteQuery ( ) )
{
if ( row [ 0 ] . SQLiteType ! = SQLiteType . Null )
{
if ( row [ 0 ] . SQLiteType ! = SQLiteType . Null )
{
result . CustomName = row [ 0 ] . ToString ( ) ;
}
result . CustomName = row [ 0 ] . ToString ( ) ;
}
return result ;
}
} , ReadTransactionMode ) ;
}
return result ;
}
} , ReadTransactionMode ) ;
}
}
@ -393,30 +378,27 @@ namespace Emby.Server.Implementations.Security
throw new ArgumentNullException ( nameof ( options ) ) ;
}
using ( WriteLock . Write ( ) )
using ( var connection = CreateConnection ( ) )
{
using ( var connection = CreateConnection ( ) )
connection . RunInTransaction ( db = >
{
connection . RunInTransaction ( db = >
using ( var statement = db . PrepareStatement ( "replace into devices (Id, CustomName, Capabilities) VALUES (@Id, @CustomName, (Select Capabilities from Devices where Id=@Id))" ) )
{
using ( var statement = db . PrepareStatement ( "replace into devices (Id, CustomName, Capabilities) VALUES (@Id, @CustomName, (Select Capabilities from Devices where Id=@Id))" ) )
{
statement . TryBind ( "@Id" , deviceId ) ;
if ( string . IsNullOrWhiteSpace ( options . CustomName ) )
{
statement . TryBindNull ( "@CustomName" ) ;
}
else
{
statement . TryBind ( "@CustomName" , options . CustomName ) ;
}
statement . TryBind ( "@Id" , deviceId ) ;
statement . MoveNext ( ) ;
if ( string . IsNullOrWhiteSpace ( options . CustomName ) )
{
statement . TryBindNull ( "@CustomName" ) ;
}
else
{
statement . TryBind ( "@CustomName" , options . CustomName ) ;
}
} , TransactionMode ) ;
}
statement . MoveNext ( ) ;
}
} , TransactionMode ) ;
}
}
}