mirror of https://github.com/Sonarr/Sonarr
Updated PetaPoco
Upped IIS's priority Added Byte multiplier to extention method.
This commit is contained in:
parent
276e01166a
commit
b11a449f65
|
@ -1,144 +0,0 @@
|
|||
<Configuration>
|
||||
<CodeStyleSettings>
|
||||
<ExternalPath IsNull="False">
|
||||
</ExternalPath>
|
||||
<Sharing>SOLUTION</Sharing>
|
||||
<CSharp>
|
||||
<FormatSettings>
|
||||
<MODIFIERS_ORDER IsNull="False">
|
||||
<Item>public</Item>
|
||||
<Item>protected</Item>
|
||||
<Item>internal</Item>
|
||||
<Item>private</Item>
|
||||
<Item>new</Item>
|
||||
<Item>abstract</Item>
|
||||
<Item>virtual</Item>
|
||||
<Item>override</Item>
|
||||
<Item>sealed</Item>
|
||||
<Item>static</Item>
|
||||
<Item>readonly</Item>
|
||||
<Item>extern</Item>
|
||||
<Item>unsafe</Item>
|
||||
<Item>volatile</Item>
|
||||
</MODIFIERS_ORDER>
|
||||
<WRAP_LIMIT>140</WRAP_LIMIT>
|
||||
</FormatSettings>
|
||||
<UsingsSettings />
|
||||
<Naming2>
|
||||
<EventHandlerPatternLong>$object$_On$event$</EventHandlerPatternLong>
|
||||
<EventHandlerPatternShort>$event$Handler</EventHandlerPatternShort>
|
||||
</Naming2>
|
||||
</CSharp>
|
||||
<VB>
|
||||
<FormatSettings />
|
||||
<ImportsSettings />
|
||||
<Naming2>
|
||||
<EventHandlerPatternLong>$object$_On$event$</EventHandlerPatternLong>
|
||||
<EventHandlerPatternShort>$event$Handler</EventHandlerPatternShort>
|
||||
</Naming2>
|
||||
</VB>
|
||||
<Web>
|
||||
<Naming2 />
|
||||
</Web>
|
||||
<Xaml>
|
||||
<Naming2 />
|
||||
</Xaml>
|
||||
<XML>
|
||||
<FormatSettings />
|
||||
</XML>
|
||||
<GenerateMemberBody />
|
||||
<Naming2>
|
||||
<EventHandlerPatternLong>$object$_On$event$</EventHandlerPatternLong>
|
||||
<EventHandlerPatternShort>$event$Handler</EventHandlerPatternShort>
|
||||
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PrivateStaticReadonly" />
|
||||
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="TypesAndNamespaces" />
|
||||
<PredefinedRule Inspect="True" Prefix="I" Suffix="" Style="AaBb" ElementKind="Interfaces" />
|
||||
<PredefinedRule Inspect="True" Prefix="T" Suffix="" Style="AaBb" ElementKind="TypeParameters" />
|
||||
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="MethodPropertyEvent" />
|
||||
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="Locals" />
|
||||
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="LocalConstants" />
|
||||
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="Parameters" />
|
||||
<PredefinedRule Inspect="True" Prefix="_" Suffix="" Style="aaBb" ElementKind="PublicFields" />
|
||||
<PredefinedRule Inspect="True" Prefix="_" Suffix="" Style="aaBb" ElementKind="PrivateInstanceFields" />
|
||||
<PredefinedRule Inspect="True" Prefix="_" Suffix="" Style="aaBb" ElementKind="PrivateStaticFields" />
|
||||
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="Constants" />
|
||||
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PrivateConstants" />
|
||||
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="StaticReadonly" />
|
||||
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="EnumMember" />
|
||||
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="Other" />
|
||||
<Abbreviation Text="IIS" />
|
||||
<Abbreviation Text="SQ" />
|
||||
</Naming2>
|
||||
</CodeStyleSettings>
|
||||
<CustomStructuralPatterns>
|
||||
<Pattern Severity="SUGGESTION">
|
||||
<Comment>Replace with FluentAssertion</Comment>
|
||||
<ReplacePattern>$arg$.Should().BeTrue();</ReplacePattern>
|
||||
<SearchPattern><![CDATA[Assert.IsTrue($arg$);
|
||||
]]></SearchPattern>
|
||||
<Params />
|
||||
<Placeholders>
|
||||
<ArgumentPlaceholder Name="excpected" Minimal="1" Maximal="1" />
|
||||
</Placeholders>
|
||||
</Pattern>
|
||||
<Pattern Severity="SUGGESTION">
|
||||
<Comment>Replace with FluentAssertion</Comment>
|
||||
<ReplacePattern>$arg$.Should().BeFalse();</ReplacePattern>
|
||||
<SearchPattern><![CDATA[Assert.IsFalse($arg$);
|
||||
]]></SearchPattern>
|
||||
<Params />
|
||||
<Placeholders>
|
||||
<ArgumentPlaceholder Name="excpected" Minimal="1" Maximal="1" />
|
||||
</Placeholders>
|
||||
</Pattern>
|
||||
<Pattern Severity="SUGGESTION">
|
||||
<ReplacePattern>$actual$.Should().Be($excpected$);</ReplacePattern>
|
||||
<SearchPattern><![CDATA[Assert.AreEqual($actual$, $excpected$);
|
||||
]]></SearchPattern>
|
||||
<Params>
|
||||
<IgnoreBracesInSingleStatementBlocks>False</IgnoreBracesInSingleStatementBlocks>
|
||||
<IgnoreParanthesisInExpressions>False</IgnoreParanthesisInExpressions>
|
||||
<SmartMatchAssociativeExpressions>False</SmartMatchAssociativeExpressions>
|
||||
<TreatReversedBinaryExpressionsEquivalent>Never</TreatReversedBinaryExpressionsEquivalent>
|
||||
</Params>
|
||||
<Placeholders>
|
||||
<ArgumentPlaceholder Name="excpected" Minimal="1" Maximal="1" />
|
||||
<ArgumentPlaceholder Name="actual" Minimal="1" Maximal="1" />
|
||||
</Placeholders>
|
||||
</Pattern>
|
||||
<Pattern Severity="HINT">
|
||||
<ReplacePattern>$excpected$.Should().Be($actual$);</ReplacePattern>
|
||||
<SearchPattern><![CDATA[$actual$.Should().Be($excpected$);
|
||||
]]></SearchPattern>
|
||||
<Params />
|
||||
<Placeholders>
|
||||
<ArgumentPlaceholder Name="excpected" Minimal="1" Maximal="1" />
|
||||
<ArgumentPlaceholder Name="actual" Minimal="1" Maximal="1" />
|
||||
</Placeholders>
|
||||
</Pattern>
|
||||
<Pattern Severity="SUGGESTION">
|
||||
<ReplacePattern>$arg$.Should().NotBeNull();</ReplacePattern>
|
||||
<SearchPattern>Assert.IsNotNull($arg$);</SearchPattern>
|
||||
<Params />
|
||||
<Placeholders>
|
||||
<ArgumentPlaceholder Name="arg" Minimal="1" Maximal="1" />
|
||||
</Placeholders>
|
||||
</Pattern>
|
||||
<Pattern Severity="SUGGESTION">
|
||||
<ReplacePattern>$arg$.Should().NotBeEmpty();</ReplacePattern>
|
||||
<SearchPattern>Assert.IsNotEmpty($arg$);</SearchPattern>
|
||||
<Params />
|
||||
<Placeholders>
|
||||
<ArgumentPlaceholder Name="arg" Minimal="1" Maximal="1" />
|
||||
</Placeholders>
|
||||
</Pattern>
|
||||
<Pattern Severity="SUGGESTION">
|
||||
<ReplacePattern>$arg$.Should().BeEmpty();</ReplacePattern>
|
||||
<SearchPattern>Assert.IsEmpty($arg$);</SearchPattern>
|
||||
<Params />
|
||||
<Placeholders>
|
||||
<ArgumentPlaceholder Name="arg" Minimal="1" Maximal="1" />
|
||||
</Placeholders>
|
||||
</Pattern>
|
||||
</CustomStructuralPatterns>
|
||||
</Configuration>
|
|
@ -53,7 +53,7 @@ namespace NzbDrone.Core.Datastore
|
|||
connection = ProfiledDbConnection.Get(sqliteConnection);
|
||||
}
|
||||
|
||||
var db = new Database(connection);
|
||||
var db = new Database(connection, Database.DBType.SqlServerCE);
|
||||
db.ForceDateTimesToUtc = false;
|
||||
|
||||
if (connection.State != ConnectionState.Open)
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* and Adam Schroder (@schotime) for lots of suggestions, improvements and Oracle support
|
||||
*/
|
||||
|
||||
#define PETAPOCO_NO_DYNAMIC //in your project settings on .NET 3.5
|
||||
//#define PETAPOCO_NO_DYNAMIC //in your project settings on .NET 3.5
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
@ -128,7 +128,7 @@ namespace PetaPoco
|
|||
{
|
||||
void GetTableInfo(Type t, TableInfo ti);
|
||||
bool MapPropertyToColumn(PropertyInfo pi, ref string columnName, ref bool resultColumn);
|
||||
Func<object, object> GetFromDbConverter(PropertyInfo pi, Type sourceType);
|
||||
Func<object, object> GetFromDbConverter(PropertyInfo pi, Type SourceType);
|
||||
Func<object, object> GetToDbConverter(Type SourceType);
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ namespace PetaPoco
|
|||
{
|
||||
return true;
|
||||
}
|
||||
public virtual Func<object, object> GetFromDbConverter(PropertyInfo pi, Type sourceType)
|
||||
public virtual Func<object, object> GetFromDbConverter(PropertyInfo pi, Type SourceType)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -240,7 +240,9 @@ namespace PetaPoco
|
|||
void Dispose();
|
||||
IDbConnection Connection { get; }
|
||||
ITransaction GetTransaction();
|
||||
Transaction GetTransaction(IsolationLevel? isolationLevel);
|
||||
void BeginTransaction();
|
||||
void BeginTransaction(IsolationLevel? isolationLevel);
|
||||
void AbortTransaction();
|
||||
void CompleteTransaction();
|
||||
object Insert(string tableName, string primaryKeyName, bool autoIncrement, object poco);
|
||||
|
@ -274,11 +276,14 @@ namespace PetaPoco
|
|||
{
|
||||
public const string MsSqlClientProvider = "System.Data.SqlClient";
|
||||
|
||||
public Database(IDbConnection connection)
|
||||
public Database(IDbConnection connection) : this(connection, DBType.NotSet) { }
|
||||
|
||||
public Database(IDbConnection connection, DBType dbType)
|
||||
{
|
||||
_sharedConnection = connection;
|
||||
_connectionString = connection.ConnectionString;
|
||||
_sharedConnectionDepth = 2; // Prevent closing external connection
|
||||
_dbType = dbType;
|
||||
CommonConstruct();
|
||||
}
|
||||
|
||||
|
@ -320,8 +325,9 @@ namespace PetaPoco
|
|||
CommonConstruct();
|
||||
}
|
||||
|
||||
enum DBType
|
||||
public enum DBType
|
||||
{
|
||||
NotSet,
|
||||
SqlServer,
|
||||
SqlServerCE,
|
||||
MySql,
|
||||
|
@ -329,7 +335,8 @@ namespace PetaPoco
|
|||
Oracle,
|
||||
SQLite
|
||||
}
|
||||
DBType _dbType = DBType.SqlServerCE;
|
||||
|
||||
private DBType _dbType = DBType.NotSet;
|
||||
|
||||
// Common initialization
|
||||
private void CommonConstruct()
|
||||
|
@ -341,12 +348,21 @@ namespace PetaPoco
|
|||
if (_providerName != null)
|
||||
_factory = DbProviderFactories.GetFactory(_providerName);
|
||||
|
||||
if (_dbType == DBType.NotSet)
|
||||
{
|
||||
_dbType = DBType.SqlServer;
|
||||
string dbtype = (_factory == null ? _sharedConnection.GetType() : _factory.GetType()).Name;
|
||||
if (dbtype.StartsWith("MySql")) _dbType = DBType.MySql;
|
||||
else if (dbtype.StartsWith("SqlCe")) _dbType = DBType.SqlServerCE;
|
||||
else if (dbtype.StartsWith("Npgsql")) _dbType = DBType.PostgreSQL;
|
||||
else if (dbtype.StartsWith("Oracle")) _dbType = DBType.Oracle;
|
||||
else if (dbtype.StartsWith("SQLite")) _dbType = DBType.SQLite;
|
||||
if (dbtype.StartsWith("MySql"))
|
||||
_dbType = DBType.MySql;
|
||||
else if (dbtype.StartsWith("SqlCe"))
|
||||
_dbType = DBType.SqlServerCE;
|
||||
else if (dbtype.StartsWith("Npgsql"))
|
||||
_dbType = DBType.PostgreSQL;
|
||||
else if (dbtype.StartsWith("Oracle"))
|
||||
_dbType = DBType.Oracle;
|
||||
else if (dbtype.StartsWith("SQLite"))
|
||||
_dbType = DBType.SQLite;
|
||||
}
|
||||
|
||||
if (_dbType == DBType.MySql && _connectionString != null && _connectionString.IndexOf("Allow User Variables=true") >= 0)
|
||||
_paramPrefix = "?";
|
||||
|
@ -409,24 +425,34 @@ namespace PetaPoco
|
|||
// Helper to create a transaction scope
|
||||
public ITransaction GetTransaction()
|
||||
{
|
||||
return new Transaction(this);
|
||||
return GetTransaction(null);
|
||||
}
|
||||
|
||||
public Transaction GetTransaction(IsolationLevel? isolationLevel)
|
||||
{
|
||||
return new Transaction(this, isolationLevel);
|
||||
}
|
||||
|
||||
// Use by derived repo generated by T4 templates
|
||||
public virtual void OnBeginTransaction() { }
|
||||
public virtual void OnEndTransaction() { }
|
||||
|
||||
public void BeginTransaction()
|
||||
{
|
||||
BeginTransaction(null);
|
||||
}
|
||||
|
||||
// Start a new transaction, can be nested, every call must be
|
||||
// matched by a call to AbortTransaction or CompleteTransaction
|
||||
// Use `using (var scope=db.Transaction) { scope.Complete(); }` to ensure correct semantics
|
||||
public void BeginTransaction()
|
||||
public void BeginTransaction(IsolationLevel? isolationLevel)
|
||||
{
|
||||
_transactionDepth++;
|
||||
|
||||
if (_transactionDepth == 1)
|
||||
{
|
||||
OpenSharedConnection();
|
||||
_transaction = _sharedConnection.BeginTransaction();
|
||||
_transaction = isolationLevel == null ? _sharedConnection.BeginTransaction() : _sharedConnection.BeginTransaction(isolationLevel.Value);
|
||||
_transactionCancelled = false;
|
||||
OnBeginTransaction();
|
||||
}
|
||||
|
@ -898,6 +924,43 @@ namespace PetaPoco
|
|||
return SkipTake<T>(skip, take, sql.SQL, sql.Arguments);
|
||||
}
|
||||
|
||||
public Dictionary<TKey, TValue> Dictionary<TKey, TValue>(Sql Sql)
|
||||
{
|
||||
return Dictionary<TKey, TValue>(Sql.SQL, Sql.Arguments);
|
||||
}
|
||||
|
||||
public Dictionary<TKey, TValue> Dictionary<TKey, TValue>(string sql, params object[] args)
|
||||
{
|
||||
var newDict = new Dictionary<TKey, TValue>();
|
||||
bool isConverterSet = false;
|
||||
Func<object, object> converter1 = x => x, converter2 = x => x;
|
||||
|
||||
foreach (var line in Query<Dictionary<string, object>>(sql, args))
|
||||
{
|
||||
object key = line.ElementAt(0).Value;
|
||||
object value = line.ElementAt(1).Value;
|
||||
|
||||
if (isConverterSet == false)
|
||||
{
|
||||
converter1 = PocoData.GetConverter(ForceDateTimesToUtc, null, typeof(TKey), key.GetType()) ?? (x => x);
|
||||
converter2 = PocoData.GetConverter(ForceDateTimesToUtc, null, typeof(TValue), value.GetType()) ?? (x => x);
|
||||
isConverterSet = true;
|
||||
}
|
||||
|
||||
var keyConverted = (TKey)Convert.ChangeType(converter1(key), typeof(TKey));
|
||||
|
||||
var valueType = Nullable.GetUnderlyingType(typeof(TValue)) ?? typeof(TValue);
|
||||
var valConv = converter2(value);
|
||||
var valConverted = valConv != null ? (TValue)Convert.ChangeType(valConv, valueType) : default(TValue);
|
||||
|
||||
if (keyConverted != null)
|
||||
{
|
||||
newDict.Add(keyConverted, valConverted);
|
||||
}
|
||||
}
|
||||
return newDict;
|
||||
}
|
||||
|
||||
// Return an enumerable collection of pocos
|
||||
public IEnumerable<T> Query<T>(string sql, params object[] args)
|
||||
{
|
||||
|
@ -1653,7 +1716,8 @@ namespace PetaPoco
|
|||
OnExecutedCommand(cmd);
|
||||
|
||||
// Set Version
|
||||
if (!string.IsNullOrEmpty(versionName)) {
|
||||
if (!string.IsNullOrEmpty(versionName))
|
||||
{
|
||||
PocoColumn pc;
|
||||
if (pd.Columns.TryGetValue(versionName, out pc))
|
||||
{
|
||||
|
@ -2254,6 +2318,25 @@ namespace PetaPoco
|
|||
il.MarkLabel(lblFin);
|
||||
il.Emit(OpCodes.Unbox_Any, type); // value converted
|
||||
}
|
||||
else if (type == typeof(Dictionary<string, object>))
|
||||
{
|
||||
Func<IDataReader, Dictionary<string, object>> func = reader =>
|
||||
{
|
||||
var dict = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
|
||||
for (int i = firstColumn; i < firstColumn + countColumns; i++)
|
||||
{
|
||||
var value = reader.IsDBNull(i) ? null : reader.GetValue(i);
|
||||
var name = reader.GetName(i);
|
||||
if (!dict.ContainsKey(name))
|
||||
dict.Add(name, value);
|
||||
}
|
||||
return dict;
|
||||
};
|
||||
|
||||
var localDel = Delegate.CreateDelegate(typeof(Func<IDataReader, Dictionary<string, object>>), func.Target, func.Method);
|
||||
PocoFactories.Add(key, localDel);
|
||||
return localDel;
|
||||
}
|
||||
else
|
||||
{
|
||||
// var poco=new T()
|
||||
|
@ -2368,7 +2451,7 @@ namespace PetaPoco
|
|||
}
|
||||
}
|
||||
|
||||
private static Func<object, object> GetConverter(bool forceDateTimesToUtc, PocoColumn pc, Type srcType, Type dstType)
|
||||
public static Func<object, object> GetConverter(bool forceDateTimesToUtc, PocoColumn pc, Type srcType, Type dstType)
|
||||
{
|
||||
Func<object, object> converter = null;
|
||||
|
||||
|
@ -2463,10 +2546,12 @@ namespace PetaPoco
|
|||
|
||||
public class Transaction : ITransaction
|
||||
{
|
||||
public Transaction(Database db)
|
||||
public Transaction(Database db) : this(db, null) { }
|
||||
|
||||
public Transaction(Database db, IsolationLevel? isolationLevel)
|
||||
{
|
||||
_db = db;
|
||||
_db.BeginTransaction();
|
||||
_db.BeginTransaction(isolationLevel);
|
||||
}
|
||||
|
||||
public virtual void Complete()
|
||||
|
|
|
@ -18,5 +18,11 @@ namespace NzbDrone.Core
|
|||
|
||||
return actual;
|
||||
}
|
||||
|
||||
|
||||
public static double Megabytes(this int megabytes)
|
||||
{
|
||||
return megabytes * 1048576;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,8 +87,8 @@ namespace NzbDrone.Core.Providers.Jobs
|
|||
importedFiles.ForEach(file => _diskScanProvider.MoveEpisodeFile(file));
|
||||
|
||||
//Delete the folder only if all files were removed
|
||||
if (_diskProvider.GetFiles(subfolder, SearchOption.AllDirectories).Length == 0)
|
||||
_diskProvider.DeleteFolder(subfolder, false);
|
||||
if (_diskProvider.GetDirectorySize(subfolder) < 1.Megabytes())
|
||||
_diskProvider.DeleteFolder(subfolder, true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace NzbDrone
|
|||
Logger.Info("Starting process. [{0}]", IISProcess.StartInfo.FileName);
|
||||
|
||||
|
||||
|
||||
IISProcess.PriorityClass = ProcessPriorityClass.AboveNormal;
|
||||
IISProcess.Start();
|
||||
|
||||
IISProcess.BeginErrorReadLine();
|
||||
|
|
Loading…
Reference in New Issue