Skip to content

Commit

Permalink
more on .net core 3
Browse files Browse the repository at this point in the history
  • Loading branch information
olmobrutall committed Aug 30, 2019
1 parent f929278 commit a4abea6
Show file tree
Hide file tree
Showing 117 changed files with 896 additions and 577 deletions.
6 changes: 3 additions & 3 deletions Signum.Engine/Administrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public static void CreateTemporaryIndex<T>(Expression<Func<T, object>> fields, b
IColumn[] columns = IndexKeyColumns.Split(view, fields);

var index = unique ?
new UniqueIndex(view, columns) :
new Index(view, columns);
new UniqueTableIndex(view, columns) :
new TableIndex(view, columns);

SqlBuilder.CreateIndex(index, checkUnique: null).ExecuteLeaves();
}
Expand Down Expand Up @@ -478,7 +478,7 @@ from ifk in targetTable.IncommingForeignKeys()
});
}

public static IDisposable DisableUniqueIndex(UniqueIndex index)
public static IDisposable DisableUniqueIndex(UniqueTableIndex index)
{
SafeConsole.WriteLineColor(ConsoleColor.DarkMagenta, " DISABLE Unique Index " + index.IndexName);
SqlBuilder.DisableIndex(index.Table.Name, index.IndexName).ExecuteLeaves();
Expand Down
12 changes: 6 additions & 6 deletions Signum.Engine/Basics/ExceptionLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Signum.Engine.Basics
{
public static class ExceptionLogic
{
public static Func<string> GetCurrentVersion;
public static Func<string>? GetCurrentVersion;

public static void Start(SchemaBuilder sb)
{
Expand Down Expand Up @@ -111,21 +111,21 @@ static ExceptionEntity SaveForceNew(this ExceptionEntity entity)
}
}

public static string DefaultEnvironment { get; set; }
public static string? DefaultEnvironment { get; set; }

public static string CurrentEnvironment { get { return overridenEnvironment.Value ?? DefaultEnvironment; } }
public static string? CurrentEnvironment { get { return overridenEnvironment.Value ?? DefaultEnvironment; } }

static readonly Variable<string> overridenEnvironment = Statics.ThreadVariable<string>("exceptionEnviroment");
static readonly Variable<string?> overridenEnvironment = Statics.ThreadVariable<string?>("exceptionEnviroment");

public static IDisposable OverrideEnviroment(string newEnviroment)
{
string oldEnviroment = overridenEnvironment.Value;
string? oldEnviroment = overridenEnvironment.Value;
overridenEnvironment.Value = newEnviroment;
return new Disposable(() => overridenEnvironment.Value = oldEnviroment);
}


public static event Action<DeleteLogParametersEmbedded, StringBuilder, CancellationToken> DeleteLogs;
public static event Action<DeleteLogParametersEmbedded, StringBuilder, CancellationToken>? DeleteLogs;

public static int DeleteLogsTimeOut = 10 * 60 * 1000;

Expand Down
2 changes: 1 addition & 1 deletion Signum.Engine/Basics/PropertyRouteLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class PropertyRouteLogic
public static bool IsPropertyRoute(this PropertyRouteEntity prdn, PropertyRoute pr) =>
As.Expression(() => prdn.RootType == pr.RootType.ToTypeEntity() && prdn.Path == pr.PropertyString());

public static ResetLazy<Dictionary<TypeEntity, Dictionary<string, PropertyRouteEntity>>> Properties;
public static ResetLazy<Dictionary<TypeEntity, Dictionary<string, PropertyRouteEntity>>> Properties = null!;

public static void Start(SchemaBuilder sb)
{
Expand Down
4 changes: 2 additions & 2 deletions Signum.Engine/Basics/QueryLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ namespace Signum.Engine.Basics
{
public static class QueryLogic
{
static ResetLazy<Dictionary<string, object>> queryNamesLazy;
static ResetLazy<Dictionary<string, object>> queryNamesLazy = null!;
public static Dictionary<string, object> QueryNames => queryNamesLazy.Value;

static ResetLazy<Dictionary<object, QueryEntity>> queryNameToEntityLazy;
static ResetLazy<Dictionary<object, QueryEntity>> queryNameToEntityLazy = null!;
public static Dictionary<object, QueryEntity> QueryNameToEntity => queryNameToEntityLazy.Value;

public static DynamicQueryContainer Queries { get; } = new DynamicQueryContainer();
Expand Down
4 changes: 2 additions & 2 deletions Signum.Engine/Basics/SemiSymbolLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace Signum.Engine.Extensions.Basics
public static class SemiSymbolLogic<T>
where T : SemiSymbol
{
static ResetLazy<Dictionary<string, T>> lazy;
static Func<IEnumerable<T>> getSemiSymbols;
static ResetLazy<Dictionary<string, T>> lazy = null!;
static Func<IEnumerable<T>> getSemiSymbols = null!;

[ThreadStatic]
static bool avoidCache;
Expand Down
6 changes: 3 additions & 3 deletions Signum.Engine/Basics/SymbolLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Signum.Engine

public static class SymbolLogic
{
public static event Action OnLoadAll;
public static event Action? OnLoadAll;

public static void LoadAll()
{
Expand All @@ -23,8 +23,8 @@ public static void LoadAll()
public static class SymbolLogic<T>
where T: Symbol
{
static ResetLazy<Dictionary<string, T>> lazy;
static Func<IEnumerable<T>> getSymbols;
static ResetLazy<Dictionary<string, T>> lazy = null!;
static Func<IEnumerable<T>> getSymbols = null!;

[ThreadStatic]
static bool avoidCache;
Expand Down
2 changes: 1 addition & 1 deletion Signum.Engine/Basics/TypeLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ internal static List<TypeEntity> GenerateSchemaTypes()
{
TableName = tab.Name.ToString(),
CleanName = Reflector.CleanTypeName(type),
Namespace = type.Namespace,
Namespace = type.Namespace!,
ClassName = type.Name,
}).ToList();
return list;
Expand Down
4 changes: 2 additions & 2 deletions Signum.Engine/CodeGeneration/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ public static IEnumerable<Module> GetModules(Dictionary<Type, bool> types, strin
foreach (var item in selected)
{
if (name == null)
name = item.FullName.RemovePrefix(solutionName + ".Entities");
name = item.FullName!.RemovePrefix(solutionName + ".Entities");
else
{
int length = sd.LongestCommonSubstring(name, item.FullName, out int startName, out int rubbish);
int length = sd.LongestCommonSubstring(name, item.FullName!, out int startName, out int rubbish);

name = name.Substring(startName, length);

Expand Down
49 changes: 13 additions & 36 deletions Signum.Engine/CodeGeneration/LogicCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected virtual IEnumerable<Module> GetModules()

protected virtual List<Type> CandidateTypes()
{
var assembly = Assembly.Load(Assembly.GetEntryAssembly().GetReferencedAssemblies().Single(a => a.Name == this.SolutionName + ".Entities"));
var assembly = Assembly.Load(Assembly.GetEntryAssembly()!.GetReferencedAssemblies().Single(a => a.Name == this.SolutionName + ".Entities"));

return assembly.GetTypes().Where(t => t.IsEntity() && !t.IsAbstract).ToList();
}
Expand Down Expand Up @@ -141,7 +141,7 @@ protected virtual List<string> GetUsingNamespaces(Module mod, List<ExpressionInf
"Signum.Engine.DynamicQuery",
};

result.AddRange(mod.Types.Concat(expressions.Select(e => e.FromType)).Select(t => t.Namespace).Distinct());
result.AddRange(mod.Types.Concat(expressions.Select(e => e.FromType)).Select(t => t.Namespace!).Distinct());

return result;
}
Expand Down Expand Up @@ -277,8 +277,7 @@ protected internal class ExpressionInfo
public Type ToType;
public PropertyInfo Property;
public bool IsUnique;
public string? Name;
public string? ExpressionName;
public string Name = null!;

public ExpressionInfo(Type fromType, Type toType, PropertyInfo property, bool isUnique)
{
Expand Down Expand Up @@ -309,16 +308,6 @@ where fromType.IsEntity() && !fromType.IsAbstract

result = result.Where(ShouldWriteExpression).ToList();

var groups = result.Select(a => a.Name).GroupCount();

foreach (var ei in result)
{
if (groups[ei.Name] == 1)
ei.ExpressionName = ei.Name + "Expression";
else
ei.ExpressionName = ei.Name + Reflector.CleanTypeName(ei.Property.PropertyType.CleanType()) + "Expresion";
}

return result;
}

Expand Down Expand Up @@ -357,31 +346,19 @@ protected virtual string WriteExpressionMethod(ExpressionInfo info)
string filter = info.Property.PropertyType.IsLite() ? "{t} => {t}.{prop}.Is({f})" : "{t} => {t}.{prop} == {f}";

string str = info.IsUnique?
@"static Expression<Func<{from}, {to}>> {MethodExpression} =
{f} => Database.Query<{to}>().SingleOrDefaultEx({filter});
[ExpressionField]
public static {to} {Method}(this {from} e)
{
return {MethodExpression}.Evaluate(e);
}
@"[AutoExpressionField]
public static {to} {Method}(this {from} {f}) => As.Expression(() => Database.Query<{to}>().SingleOrDefaultEx({filter}));
" :
@"static Expression<Func<{from}, IQueryable<{to}>>> {MethodExpression} =
{f} => Database.Query<{to}>().Where({filter});
[ExpressionField]
public static IQueryable<{to}> {Method}(this {from} e)
{
return {MethodExpression}.Evaluate(e);
}
@"[AutoExpressionField]
public static IQueryable<{to}> {Method}(this {from} {f}) => As.Expression(() => Database.Query<{to}>().Where({filter}));
";

return str.Replace("{filter}", filter)
.Replace("{from}", from.Name)
.Replace("{to}", info.ToType.Name)
.Replace("{t}", varTo)
.Replace("{f}", varFrom)
.Replace("{prop}", info.Property.Name)
.Replace("{Method}", info.Name)
.Replace("{MethodExpression}", info.ExpressionName);
.Replace("{Method}", info.Name);
}

protected virtual IEnumerable<PropertyInfo> GetQueryProperties(Type type)
Expand All @@ -408,7 +385,7 @@ protected virtual string GetWithVirtualMList(Type type, PropertyInfo p, Property
if (p1 == p2)
p2 += "2";

var cast = p.DeclaringType == bp.PropertyType.CleanType() ? "" : $"(Lite<{p.DeclaringType.Name}>)";
var cast = p.DeclaringType == bp.PropertyType.CleanType() ? "" : $"(Lite<{p.DeclaringType!.Name}>)";

return $" .WithVirtualMList({p1} => {p1}.{p.Name}, {p2} => {cast}{p2}.{bp.Name})";
}
Expand All @@ -426,7 +403,7 @@ protected virtual string GetWithVirtualMList(Type type, PropertyInfo p, Property

var t = pi.PropertyType.ElementType()!;

var backProperty = Reflector.PublicInstancePropertiesInOrder(t).SingleOrDefaultEx(bp => IsVirtualMListBackReference(bp, pi.DeclaringType));
var backProperty = Reflector.PublicInstancePropertiesInOrder(t).SingleOrDefaultEx(bp => IsVirtualMListBackReference(bp, pi.DeclaringType!));

return backProperty;
}
Expand Down Expand Up @@ -537,7 +514,7 @@ private bool ShouldWriteSimpleOperations(IOperationSymbolContainer oper)

protected virtual bool IsSave(IOperationSymbolContainer oper)
{
return oper.ToString().Contains("Save"); ;
return oper.ToString()!.Contains("Save"); ;
}

protected virtual string? WriteDeleteOperation(IOperationSymbolContainer oper)
Expand Down Expand Up @@ -606,15 +583,15 @@ protected virtual string WriteConstructFromMany(IOperationSymbolContainer oper)

protected virtual IEnumerable<IOperationSymbolContainer> GetOperationsSymbols(Type type)
{
string name = type.FullName.RemoveSuffix("Entity") + "Operation";
string name = type.FullName!.RemoveSuffix("Entity") + "Operation";

var operType = type.Assembly.GetType(name);

if (operType == null)
return Enumerable.Empty<IOperationSymbolContainer>();

return (from fi in operType.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly)
select (IOperationSymbolContainer)fi.GetValue(null)).ToList();
select (IOperationSymbolContainer)fi.GetValue(null)!).ToList();
}
}
}
8 changes: 4 additions & 4 deletions Signum.Engine/CodeGeneration/ReactCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public IEnumerable<Module> ReactGetModules(Dictionary<Type, bool> types, string
if (selectedTypes.IsNullOrEmpty())
yield break;

var directories = Directory.GetDirectories(GetProjectFolder(), "App\\").Select(a => Path.GetFileName(a));
var directories = Directory.GetDirectories(GetProjectFolder(), "App\\").Select(a => Path.GetFileName(a)!);

string? moduleName;
if (directories.IsEmpty())
Expand Down Expand Up @@ -185,7 +185,7 @@ private static string AskModuleName(string solutionName, Type[] selected)

protected virtual List<Type> CandidateTypes()
{
var assembly = Assembly.Load(Assembly.GetEntryAssembly().GetReferencedAssemblies().Single(a => a.Name == this.SolutionName + ".Entities"));
var assembly = Assembly.Load(Assembly.GetEntryAssembly()!.GetReferencedAssemblies().Single(a => a.Name == this.SolutionName + ".Entities"));

return assembly.GetTypes().Where(t => t.IsModifiableEntity() && !t.IsAbstract && !typeof(MixinEntity).IsAssignableFrom(t)).ToList();
}
Expand Down Expand Up @@ -308,7 +308,7 @@ protected virtual List<string> GetServerUsingNamespaces(Module mod)
"Signum.React",
};

result.AddRange(mod.Types.Select(t => t.Namespace).Distinct());
result.AddRange(mod.Types.Select(t => t.Namespace!).Distinct());

return result;
}
Expand Down Expand Up @@ -497,7 +497,7 @@ protected virtual string WriteMListProperty(PropertyInfo pi, string v)

var eka = elementType.GetCustomAttribute<EntityKindAttribute>();

if (elementType.IsEmbeddedEntity() || (eka.EntityKind == EntityKind.Part || eka.EntityKind == EntityKind.SharedPart))
if (elementType.IsEmbeddedEntity() || (eka!.EntityKind == EntityKind.Part || eka!.EntityKind == EntityKind.SharedPart))
if (pi.GetCustomAttribute<ImplementedByAttribute>()?.ImplementedTypes.Length > 1)
return "<EntityRepeater ctx={{ctx.subCtx({0} => {0}.{1})}} />".FormatWith(v, pi.Name.FirstLower());
else
Expand Down
7 changes: 1 addition & 6 deletions Signum.Engine/Connection/Connector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ public static Connector Current
get { return currentConnector.Value ?? Default; }
}

static Connector @default;
public static Connector Default
{
get { return @default; }
set { @default = value; }
}
public static Connector Default { get; set; } = null!;

static readonly Variable<int?> scopeTimeout = Statics.ThreadVariable<int?>("scopeTimeout");
public static int? ScopeTimeout { get { return scopeTimeout.Value; } }
Expand Down
2 changes: 1 addition & 1 deletion Signum.Engine/Connection/FieldReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ public override string Message
get
{
string text = "{0}\r\nOrdinal: {1}\r\nColumnName: {2}\r\nRow: {3}".FormatWith(
InnerException.Message, Ordinal, ColumnName, Row);
InnerException!.Message, Ordinal, ColumnName, Row);

if (Projector != null)
{
Expand Down
2 changes: 1 addition & 1 deletion Signum.Engine/Connection/SqlConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ protected internal override void BulkCopy(DataTable dt, ObjectName destinationTa
{
bulkCopy.BulkCopyTimeout = timeout ?? Connector.ScopeTimeout ?? this.CommandTimeout ?? bulkCopy.BulkCopyTimeout;

foreach (DataColumn c in dt.Columns)
foreach (var c in dt.Columns.Cast<DataColumn>())
bulkCopy.ColumnMappings.Add(new SqlBulkCopyColumnMapping(c.ColumnName, c.ColumnName));

bulkCopy.DestinationTableName = destinationTable.ToString();
Expand Down
18 changes: 9 additions & 9 deletions Signum.Engine/Connection/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ class RealTransaction : ICoreTransaction
public DbTransaction? Transaction { get; private set; }
public Exception? IsRolledback { get; private set; }
public bool Started { get; private set; }
public event Action<Dictionary<string, object>?> PostRealCommit;
public event Action<Dictionary<string, object>?> PreRealCommit;
public event Action<Dictionary<string, object>?> Rolledback;
public event Action<Dictionary<string, object>?>? PostRealCommit;
public event Action<Dictionary<string, object>?>? PreRealCommit;
public event Action<Dictionary<string, object>?>? Rolledback;

IsolationLevel? IsolationLevel;

Expand Down Expand Up @@ -219,10 +219,10 @@ class NamedTransaction : ICoreTransaction
string savePointName;
public Exception? IsRolledback { get; private set; }
public bool Started { get; private set; }
public event Action<Dictionary<string, object>?> PostRealCommit;
public event Action<Dictionary<string, object>?>? PostRealCommit;

public event Action<Dictionary<string, object>?> PreRealCommit;
public event Action<Dictionary<string, object>?> Rolledback;
public event Action<Dictionary<string, object>?>? PreRealCommit;
public event Action<Dictionary<string, object>?>? Rolledback;

public NamedTransaction(ICoreTransaction parent, string savePointName)
{
Expand Down Expand Up @@ -297,9 +297,9 @@ class NoneTransaction : ICoreTransaction
public DbTransaction? Transaction { get { return null; } }
public Exception? IsRolledback { get; private set; }
public bool Started { get; private set; }
public event Action<Dictionary<string, object>?> PostRealCommit;
public event Action<Dictionary<string, object>?> PreRealCommit;
public event Action<Dictionary<string, object>?> Rolledback;
public event Action<Dictionary<string, object>?>? PostRealCommit;
public event Action<Dictionary<string, object>?>? PreRealCommit;
public event Action<Dictionary<string, object>?>? Rolledback;

public NoneTransaction(ICoreTransaction? parent)
{
Expand Down
Loading

0 comments on commit a4abea6

Please sign in to comment.