Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
update to .Net 5
Browse files Browse the repository at this point in the history
  • Loading branch information
olmobrutall committed Oct 18, 2020
1 parent 2ca029b commit cdba46f
Show file tree
Hide file tree
Showing 89 changed files with 566 additions and 566 deletions.
14 changes: 7 additions & 7 deletions Signum.Engine.Extensions/Authorization/AuthCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ internal XElement ExportXml(XName rootName, XName elementName, Func<K, string> r
(from r in AuthLogic.RolesInOrder()
let rac = rules.GetOrThrow(r)
select new XElement("Role",
new XAttribute("Name", r.ToString()),
new XAttribute("Name", r.ToString()!),
from k in allKeys ?? (rac.DefaultDictionary().OverrideDictionary?.Keys).EmptyIfNull()
let allowedBase = rac.GetAllowedBase(k)
let allowed = rac.GetAllowed(k)
Expand All @@ -311,17 +311,17 @@ orderby resource
{
var current = Database.RetrieveAll<RT>().GroupToDictionary(a => a.Role);
var xRoles = (element.Element(rootName)?.Elements("Role")).EmptyIfNull();
var should = xRoles.ToDictionary(x => roles.GetOrThrow(x.Attribute("Name").Value));
var should = xRoles.ToDictionary(x => roles.GetOrThrow(x.Attribute("Name")!.Value));

Table table = Schema.Current.Table(typeof(RT));

return Synchronizer.SynchronizeScript(Spacing.Double, should, current,
createNew: (role, x) =>
{
var dic = (from xr in x.Elements(elementName)
let r = toResource(xr.Attribute("Resource").Value)
let r = toResource(xr.Attribute("Resource")!.Value)
where r != null
select KeyValuePair.Create(r, parseAllowed(xr.Attribute("Allowed").Value)))
select KeyValuePair.Create(r, parseAllowed(xr.Attribute("Allowed")!.Value)))
.ToDictionaryEx("{0} rules for {1}".FormatWith(typeof(R).NiceName(), role));

SqlPreCommand? restSql = dic.Select(kvp => table.InsertSqlSync(new RT
Expand All @@ -339,7 +339,7 @@ select KeyValuePair.Create(r, parseAllowed(xr.Attribute("Allowed").Value)))
var def = list.SingleOrDefaultEx(a => a.Resource == null);

var shouldResources = (from xr in x.Elements(elementName)
let r = toResource(xr.Attribute("Resource").Value)
let r = toResource(xr.Attribute("Resource")!.Value)
where r != null
select KeyValuePair.Create(ToKey(r), xr))
.ToDictionaryEx("{0} rules for {1}".FormatWith(typeof(R).NiceName(), role));
Expand All @@ -349,14 +349,14 @@ select KeyValuePair.Create(ToKey(r), xr))
SqlPreCommand? restSql = Synchronizer.SynchronizeScript(Spacing.Simple, shouldResources, currentResources,
(r, xr) =>
{
var a = parseAllowed(xr.Attribute("Allowed").Value);
var a = parseAllowed(xr.Attribute("Allowed")!.Value);
return table.InsertSqlSync(new RT { Resource = ToEntity(r), Role = role, Allowed = a }, comment: Comment(role, ToEntity(r), a));
},
(r, rt) => table.DeleteSqlSync(rt, null, Comment(role, ToEntity(r), rt.Allowed)),
(r, xr, rt) =>
{
var oldA = rt.Allowed;
rt.Allowed = parseAllowed(xr.Attribute("Allowed").Value);
rt.Allowed = parseAllowed(xr.Attribute("Allowed")!.Value);
return table.UpdateSqlSync(rt, null, comment: Comment(role, ToEntity(r), oldA, rt.Allowed));
})?.Do(p => p.GoBefore = true);

Expand Down
24 changes: 12 additions & 12 deletions Signum.Engine.Extensions/Authorization/AuthLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,18 +375,18 @@ public static XDocument ExportRules(bool exportAll = false)
new XElement("Auth",
new XElement("Roles",
RolesInOrder().Select(r => new XElement("Role",
new XAttribute("Name", r.ToString()),
GetMergeStrategy(r) == MergeStrategy.Intersection? new XAttribute("MergeStrategy", MergeStrategy.Intersection) : null,
new XAttribute("Name", r.ToString()!),
GetMergeStrategy(r) == MergeStrategy.Intersection? new XAttribute("MergeStrategy", MergeStrategy.Intersection) : null!,
new XAttribute("Contains", roles.Value.RelatedTo(r).ToString(","))))),
ExportToXml?.GetInvocationListTyped().Select(a => a(exportAll)).NotNull().OrderBy(a => a.Name.ToString())));
ExportToXml?.GetInvocationListTyped().Select(a => a(exportAll)).NotNull().OrderBy(a => a.Name.ToString())!));
}

public static SqlPreCommand? ImportRulesScript(XDocument doc, bool interactive)
{
Replacements replacements = new Replacements { Interactive = interactive };

Dictionary<string, Lite<RoleEntity>> rolesDic = roles.Value.ToDictionary(a => a.ToString()!);
Dictionary<string, XElement> rolesXml = doc.Root.Element("Roles").Elements("Role").ToDictionary(x => x.Attribute("Name").Value);
Dictionary<string, XElement> rolesXml = doc.Root!.Element("Roles")!.Elements("Role").ToDictionary(x => x.Attribute("Name")!.Value);

replacements.AskForReplacements(rolesXml.Keys.ToHashSet(), rolesDic.Keys.ToHashSet(), "Roles");

Expand All @@ -410,9 +410,9 @@ public static XDocument ExportRules(bool exportAll = false)

EnumerableExtensions.JoinStrict(
roles.Value.RelatedTo(r),
kvp.Value.Attribute("Contains").Value.Split(new []{','}, StringSplitOptions.RemoveEmptyEntries),
sr => sr.ToString(),
s => rolesDic[s].ToString(),
kvp.Value.Attribute("Contains")!.Value.Split(new []{','}, StringSplitOptions.RemoveEmptyEntries),
sr => sr.ToString()!,
s => rolesDic[s].ToString()!,
(sr, s) => 0,
"subRoles of {0}".FormatWith(r));
}
Expand Down Expand Up @@ -448,11 +448,11 @@ public static XDocument ExportRules(bool exportAll = false)

public static void LoadRoles(XDocument doc)
{
var roleInfos = doc.Root.Element("Roles").Elements("Role").Select(x => new
var roleInfos = doc.Root!.Element("Roles")!.Elements("Role").Select(x => new
{
Name = x.Attribute("Name").Value,
Name = x.Attribute("Name")!.Value,
MergeStrategy = x.Attribute("MergeStrategy")?.Let(ms => ms.Value.ToEnum<MergeStrategy>()) ?? MergeStrategy.Union,
SubRoles = x.Attribute("Contains").Value.SplitNoEmpty(',' )
SubRoles = x.Attribute("Contains")!.Value.SplitNoEmpty(',' )
}).ToList();

var roles = roleInfos.ToDictionary(a => a.Name!, a => new RoleEntity { Name = a.Name!, MergeStrategy = a.MergeStrategy }); /*CSBUG*/
Expand All @@ -471,7 +471,7 @@ public static void SynchronizeRoles(XDocument doc)
Table table = Schema.Current.Table(typeof(RoleEntity));
TableMList relationalTable = table.TablesMList().Single();

Dictionary<string, XElement> rolesXml = doc.Root.Element("Roles").Elements("Role").ToDictionary(x => x.Attribute("Name").Value);
Dictionary<string, XElement> rolesXml = doc.Root!.Element("Roles")!.Elements("Role").ToDictionary(x => x.Attribute("Name")!.Value);

{
Dictionary<string, RoleEntity> rolesDic = Database.Query<RoleEntity>().ToDictionary(a => a.ToString());
Expand Down Expand Up @@ -522,7 +522,7 @@ public static void SynchronizeRoles(XDocument doc)
removeOld: (name, role) => { throw new InvalidOperationException("No old roles should be at this stage. Did you execute the script?"); },
mergeBoth: (name, xElement, role) =>
{
var should = xElement.Attribute("Contains").Value.Split(new []{','}, StringSplitOptions.RemoveEmptyEntries);
var should = xElement.Attribute("Contains")!.Value.Split(new []{','}, StringSplitOptions.RemoveEmptyEntries);
var current = role.Roles.Select(a => a.ToString()!);

if(should.OrderBy().SequenceEqual(current.OrderBy()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static void Start(SchemaBuilder sb)

AuthLogic.ImportFromXml += (x, roles, replacements) =>
{
var allResources = x.Element("Operations").Elements("Role").SelectMany(r => r.Elements("Operation")).Select(p => p.Attribute("Resource").Value).ToHashSet();
var allResources = x.Element("Operations")!.Elements("Role").SelectMany(r => r.Elements("Operation")).Select(p => p.Attribute("Resource")!.Value).ToHashSet();

replacements.AskForReplacements(
allResources.Select(a => a.TryBefore("/") ?? a).ToHashSet(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static void Start(SchemaBuilder sb)
string replacementKey = "AuthRules:" + typeof(PermissionSymbol).Name;

replacements.AskForReplacements(
x.Element("Permissions").Elements("Role").SelectMany(r => r.Elements("Permission")).Select(p => p.Attribute("Resource").Value).ToHashSet(),
x.Element("Permissions")!.Elements("Role").SelectMany(r => r.Elements("Permission")).Select(p => p.Attribute("Resource")!.Value).ToHashSet(),
SymbolLogic<PermissionSymbol>.Symbols.Select(s=>s.Key).ToHashSet(),
replacementKey);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void Start(SchemaBuilder sb)
{
Dictionary<Type, Dictionary<string, PropertyRoute>> routesDicCache = new Dictionary<Type, Dictionary<string, PropertyRoute>>();

var groups = x.Element("Properties").Elements("Role").SelectMany(r => r.Elements("Property")).Select(p => new PropertyPair(p.Attribute("Resource").Value))
var groups = x.Element("Properties")!.Elements("Role").SelectMany(r => r.Elements("Property")).Select(p => new PropertyPair(p.Attribute("Resource")!.Value))
.AgGroupToDictionary(a => a.Type, gr => gr.Select(pp => pp.Property).ToHashSet());

foreach (var item in groups)
Expand Down
2 changes: 1 addition & 1 deletion Signum.Engine.Extensions/Authorization/QueryAuthLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static void Start(SchemaBuilder sb)
string replacementKey = "AuthRules:" + typeof(QueryEntity).Name;

replacements.AskForReplacements(
x.Element("Queries").Elements("Role").SelectMany(r => r.Elements("Query")).Select(p => p.Attribute("Resource").Value).ToHashSet(),
x.Element("Queries")!.Elements("Role").SelectMany(r => r.Elements("Query")).Select(p => p.Attribute("Resource")!.Value).ToHashSet(),
QueryLogic.QueryNames.Keys.ToHashSet(),
replacementKey);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static ResetPasswordRequestEntity ResetPasswordRequestExecute(string code
//Remove old previous requests
var rpr = Database.Query<ResetPasswordRequestEntity>()
.Where(r => r.Code == code && !r.Lapsed)
.SingleOrDefault();
.SingleEx();

using (UserHolder.UserSession(rpr.User))
{
Expand All @@ -94,12 +94,12 @@ public static ResetPasswordRequestEntity ResetPasswordRequestExecute(string code

public static ResetPasswordRequestEntity SendResetPasswordRequestEmail(string email)
{
UserEntity user;
UserEntity? user;
using (AuthLogic.Disable())
{
user = Database.Query<UserEntity>()
.Where(u => u.Email == email && u.State != UserState.Disabled)
.SingleOrDefault();
.SingleOrDefault();

if (user == null)
throw new ApplicationException(AuthEmailMessage.EmailNotFound.NiceToString());
Expand Down
2 changes: 1 addition & 1 deletion Signum.Engine.Extensions/Authorization/SessionLogLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static bool RoleTracked(Lite<RoleEntity> role)
return SessionLogPermission.TrackSession.IsAuthorized(role);
}

public static void SessionStart(string userHostAddress, string userAgent)
public static void SessionStart(string userHostAddress, string? userAgent)
{
var user = UserEntity.Current;
if (SessionLogLogic.RoleTracked(user.Role))
Expand Down
24 changes: 12 additions & 12 deletions Signum.Engine.Extensions/Authorization/TypeAuthCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ internal XElement ExportXml(List<Type>? allTypes)
(from r in AuthLogic.RolesInOrder()
let rac = rules.GetOrThrow(r)
select new XElement("Role",
new XAttribute("Name", r.ToString()),
new XAttribute("Name", r.ToString()!),
from k in allTypes ?? (rac.DefaultDictionary().OverrideDictionary?.Keys).EmptyIfNull()
let allowedBase = rac.GetAllowedBase(k)
let allowed = rac.GetAllowed(k)
Expand All @@ -332,7 +332,7 @@ internal XElement ExportXml(List<Type>? allTypes)
orderby resource
select new XElement("Type",
new XAttribute("Resource", resource),
new XAttribute("Allowed", allowed.Fallback.ToString()),
new XAttribute("Allowed", allowed.Fallback.ToString()!),
from c in allowed.Conditions
select new XElement("Condition",
new XAttribute("Name", c.TypeCondition.Key),
Expand All @@ -349,16 +349,16 @@ from c in allowed.Conditions
{
var current = Database.RetrieveAll<RuleTypeEntity>().GroupToDictionary(a => a.Role);
var xRoles = (element.Element("Types")?.Elements("Role")).EmptyIfNull();
var should = xRoles.ToDictionary(x => roles.GetOrThrow(x.Attribute("Name").Value));
var should = xRoles.ToDictionary(x => roles.GetOrThrow(x.Attribute("Name")!.Value));

Table table = Schema.Current.Table(typeof(RuleTypeEntity));

replacements.AskForReplacements(
xRoles.SelectMany(x => x.Elements("Type")).Select(x => x.Attribute("Resource").Value).ToHashSet(),
xRoles.SelectMany(x => x.Elements("Type")).Select(x => x.Attribute("Resource")!.Value).ToHashSet(),
TypeLogic.NameToType.Where(a => !a.Value.IsEnumEntity()).Select(a => a.Key).ToHashSet(), typeReplacementKey);

replacements.AskForReplacements(
xRoles.SelectMany(x => x.Elements("Type")).SelectMany(t => t.Elements("Condition")).Select(x => x.Attribute("Name").Value).ToHashSet(),
xRoles.SelectMany(x => x.Elements("Type")).SelectMany(t => t.Elements("Condition")).Select(x => x.Attribute("Name")!.Value).ToHashSet(),
SymbolLogic<TypeConditionSymbol>.AllUniqueKeys(),
typeConditionReplacementKey);

Expand All @@ -377,11 +377,11 @@ from c in allowed.Conditions
createNew: (role, x) =>
{
var dic = (from xr in x.Elements("Type")
let t = getResource(xr.Attribute("Resource").Value)
let t = getResource(xr.Attribute("Resource")!.Value)
where t != null
select KeyValuePair.Create(t, new
{
Allowed = xr.Attribute("Allowed").Value.ToEnum<TypeAllowed>(),
Allowed = xr.Attribute("Allowed")!.Value.ToEnum<TypeAllowed>(),
Condition = Conditions(xr, replacements)
})).ToDictionaryEx("Type rules for {0}".FormatWith(role));

Expand All @@ -399,7 +399,7 @@ from c in allowed.Conditions
mergeBoth: (role, x, list) =>
{
var dic = (from xr in x.Elements("Type")
let t = getResource(xr.Attribute("Resource").Value)
let t = getResource(xr.Attribute("Resource")!.Value)
where t != null && !t.ToType().IsEnumEntity()
select KeyValuePair.Create(t, xr)).ToDictionaryEx("Type rules for {0}".FormatWith(role));

Expand All @@ -409,7 +409,7 @@ from c in allowed.Conditions
list.Where(a => a.Resource != null).ToDictionary(a => a.Resource),
createNew: (r, xr) =>
{
var a = xr.Attribute("Allowed").Value.ToEnum<TypeAllowed>();
var a = xr.Attribute("Allowed")!.Value.ToEnum<TypeAllowed>();
var conditions = Conditions(xr, replacements);

return table.InsertSqlSync(new RuleTypeEntity { Resource = r, Role = role, Allowed = a, Conditions = conditions }, comment: Comment(role, r, a));
Expand All @@ -418,7 +418,7 @@ from c in allowed.Conditions
mergeBoth: (r, xr, pr) =>
{
var oldA = pr.Allowed;
pr.Allowed = xr.Attribute("Allowed").Value.ToEnum<TypeAllowed>();
pr.Allowed = xr.Attribute("Allowed")!.Value.ToEnum<TypeAllowed>();
var conditions = Conditions(xr, replacements);

if (!pr.Conditions.SequenceEqual(conditions))
Expand All @@ -434,12 +434,12 @@ from c in allowed.Conditions
private static MList<RuleTypeConditionEmbedded> Conditions(XElement xr, Replacements replacements)
{
return (from xc in xr.Elements("Condition")
let cn = SymbolLogic<TypeConditionSymbol>.TryToSymbol(replacements.Apply(typeConditionReplacementKey, xc.Attribute("Name").Value))
let cn = SymbolLogic<TypeConditionSymbol>.TryToSymbol(replacements.Apply(typeConditionReplacementKey, xc.Attribute("Name")!.Value))
where cn != null
select new RuleTypeConditionEmbedded
{
Condition = cn,
Allowed = xc.Attribute("Allowed").Value.ToEnum<TypeAllowed>()
Allowed = xc.Attribute("Allowed")!.Value.ToEnum<TypeAllowed>()
}).ToMList();
}

Expand Down
Loading

0 comments on commit cdba46f

Please sign in to comment.