Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	Extensions/Signum.Mailing/Templates/EmailTemplateLogic.cs
#	Extensions/Signum.Word/WordTemplateLogic.cs
  • Loading branch information
olmobrutall committed Feb 12, 2024
2 parents b610347 + f7626dc commit 3d4cb33
Show file tree
Hide file tree
Showing 30 changed files with 183 additions and 137 deletions.
15 changes: 8 additions & 7 deletions Extensions/Signum.Authorization/AuthLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Signum.Authorization.Rules;
using Signum.Utilities.DataStructures;
using Signum.Utilities.Reflection;
using System.Collections.Frozen;
using System.IO;
using System.Xml.Linq;

Expand Down Expand Up @@ -45,8 +46,8 @@ public static IQueryable<UserEntity> Users(this RoleEntity r) =>

static ResetLazy<DirectedGraph<Lite<RoleEntity>>> rolesGraph = null!;
static ResetLazy<DirectedGraph<Lite<RoleEntity>>> rolesInverse = null!;
static ResetLazy<Dictionary<string, Lite<RoleEntity>>> rolesByName = null!;
public static ResetLazy<Dictionary<Lite<RoleEntity>, RoleEntity>> RolesByLite = null!;
static ResetLazy<FrozenDictionary<string, Lite<RoleEntity>>> rolesByName = null!;
public static ResetLazy<FrozenDictionary<Lite<RoleEntity>, RoleEntity>> RolesByLite = null!;



Expand All @@ -56,7 +57,7 @@ class RoleData
public MergeStrategy MergeStrategy;
}

static ResetLazy<Dictionary<Lite<RoleEntity>, RoleData>> mergeStrategies = null!;
static ResetLazy<FrozenDictionary<Lite<RoleEntity>, RoleData>> mergeStrategies = null!;

public static void AssertStarted(SchemaBuilder sb)
{
Expand Down Expand Up @@ -108,8 +109,8 @@ public static void Start(SchemaBuilder sb, string? systemUserName, string? anony



RolesByLite = sb.GlobalLazy(() => Database.Query<RoleEntity>().ToDictionaryEx(a => a.ToLite()), new InvalidateWith(typeof(RoleEntity)), AuthLogic.NotifyRulesChanged);
rolesByName = sb.GlobalLazy(() => RolesByLite.Value.Keys.ToDictionaryEx(a => a.ToString()!), new InvalidateWith(typeof(RoleEntity)));
RolesByLite = sb.GlobalLazy(() => Database.Query<RoleEntity>().ToFrozenDictionaryEx(a => a.ToLite()), new InvalidateWith(typeof(RoleEntity)), AuthLogic.NotifyRulesChanged);
rolesByName = sb.GlobalLazy(() => RolesByLite.Value.Keys.ToFrozenDictionaryEx(a => a.ToString()!), new InvalidateWith(typeof(RoleEntity)));
rolesGraph = sb.GlobalLazy(() => CacheRoles(RolesByLite.Value), new InvalidateWith(typeof(RoleEntity)));
rolesInverse = sb.GlobalLazy(() => rolesGraph.Value.Inverse(), new InvalidateWith(typeof(RoleEntity)));
mergeStrategies = sb.GlobalLazy(() =>
Expand All @@ -132,7 +133,7 @@ public static void Start(SchemaBuilder sb, string? systemUserName, string? anony
});
}

return result;
return result.ToFrozenDictionary();
}, new InvalidateWith(typeof(RoleEntity)));

sb.Schema.EntityEvents<RoleEntity>().Saving += Schema_Saving;
Expand Down Expand Up @@ -259,7 +260,7 @@ static void Schema_Saving(RoleEntity role)
}
}

static DirectedGraph<Lite<RoleEntity>> CacheRoles(Dictionary<Lite<RoleEntity>, RoleEntity> rolesLite)
static DirectedGraph<Lite<RoleEntity>> CacheRoles(FrozenDictionary<Lite<RoleEntity>, RoleEntity> rolesLite)
{
var graph = DirectedGraph<Lite<RoleEntity>>.Generate(rolesLite.Keys, r => rolesLite.GetOrThrow(r).InheritsFrom);

Expand Down
5 changes: 3 additions & 2 deletions Extensions/Signum.Authorization/AuthServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Runtime.InteropServices;
using System.Collections.Concurrent;
using System.Reflection;
using System.Collections.Frozen;

namespace Signum.Authorization;

Expand Down Expand Up @@ -264,8 +265,8 @@ public static void Start(Func<AuthTokenConfigurationEmbedded> tokenConfig, strin

}

public static ResetLazy<Dictionary<string, List<Type>>> entitiesByNamespace =
new ResetLazy<Dictionary<string, List<Type>>>(() => Schema.Current.Tables.Keys.Where(t => !EnumEntity.IsEnumEntity(t)).GroupToDictionary(t => t.Namespace!));
public static ResetLazy<FrozenDictionary<string, List<Type>>> entitiesByNamespace =
new(() => Schema.Current.Tables.Keys.Where(t => !EnumEntity.IsEnumEntity(t)).GroupToDictionary(t => t.Namespace!).ToFrozenDictionary());

public static ConcurrentDictionary<string, bool> NamespaceNoLoaded = new ConcurrentDictionary<string, bool>();

Expand Down
6 changes: 4 additions & 2 deletions Extensions/Signum.Chart/ColorPalette/ChartColorLogic.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Collections.Frozen;

namespace Signum.Chart.ColorPalette;

public static class ColorPaletteLogic
{
public static ResetLazy<Dictionary<Type, ColorPaletteEntity>> ColorPaletteCache = null!;
public static ResetLazy<FrozenDictionary<Type, ColorPaletteEntity>> ColorPaletteCache = null!;

public static readonly int Limit = 360;

Expand All @@ -24,7 +26,7 @@ internal static void Start(SchemaBuilder sb)

ColorPaletteCache = sb.GlobalLazy(() =>
Database.Query<ColorPaletteEntity>()
.ToDictionaryEx(cc => cc.Type.ToType()),
.ToFrozenDictionaryEx(cc => cc.Type.ToType()),
new InvalidateWith(typeof(ColorPaletteEntity)));
}
}
Expand Down
13 changes: 7 additions & 6 deletions Extensions/Signum.Chart/UserChart/UserChartLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
using Signum.UserAssets.QueryTokens;
using Signum.UserQueries;
using Signum.ViewLog;
using System.Collections.Frozen;

namespace Signum.Chart.UserChart;

public static class UserChartLogic
{
public static ResetLazy<Dictionary<Lite<UserChartEntity>, UserChartEntity>> UserCharts = null!;
public static ResetLazy<Dictionary<Type, List<Lite<UserChartEntity>>>> UserChartsByType = null!;
public static ResetLazy<Dictionary<object, List<Lite<UserChartEntity>>>> UserChartsByQuery = null!;
public static ResetLazy<FrozenDictionary<Lite<UserChartEntity>, UserChartEntity>> UserCharts = null!;
public static ResetLazy<FrozenDictionary<Type, List<Lite<UserChartEntity>>>> UserChartsByType = null!;
public static ResetLazy<FrozenDictionary<object, List<Lite<UserChartEntity>>>> UserChartsByQuery = null!;

[AutoExpressionField]
public static IQueryable<CachedQueryEntity> CachedQueries(this UserChartEntity uc) =>
Expand Down Expand Up @@ -147,15 +148,15 @@ public static void Start(SchemaBuilder sb)
Administrator.UnsafeDeletePreCommand(Database.Query<UserChartEntity>().Where(a => a.Query.Is(e)));


UserCharts = sb.GlobalLazy(() => Database.Query<UserChartEntity>().ToDictionary(a => a.ToLite()),
UserCharts = sb.GlobalLazy(() => Database.Query<UserChartEntity>().ToFrozenDictionaryEx(a => a.ToLite()),
new InvalidateWith(typeof(UserChartEntity)));

UserChartsByQuery = sb.GlobalLazy(() => UserCharts.Value.Values.Where(a => a.EntityType == null).SelectCatch(uc => KeyValuePair.Create(uc.Query.ToQueryName(), uc.ToLite())).GroupToDictionary(),
UserChartsByQuery = sb.GlobalLazy(() => UserCharts.Value.Values.Where(a => a.EntityType == null).SelectCatch(uc => KeyValuePair.Create(uc.Query.ToQueryName(), uc.ToLite())).GroupToDictionary().ToFrozenDictionary(),
new InvalidateWith(typeof(UserChartEntity)));

UserChartsByType = sb.GlobalLazy(() => UserCharts.Value.Values.Where(a => a.EntityType != null)
.SelectCatch(a => KeyValuePair.Create(TypeLogic.IdToType.GetOrThrow(a.EntityType!.Id), a.ToLite()))
.GroupToDictionary(),
.GroupToDictionary().ToFrozenDictionary(),
new InvalidateWith(typeof(UserChartEntity)));
}
}
Expand Down
13 changes: 7 additions & 6 deletions Extensions/Signum.Dashboard/DashboardLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
using Signum.Toolbar;
using Signum.API;
using Signum.Omnibox;
using System.Collections.Frozen;

namespace Signum.Dashboard;

public static class DashboardLogic
{
public static ResetLazy<Dictionary<Lite<DashboardEntity>, DashboardEntity>> Dashboards = null!;
public static ResetLazy<Dictionary<Lite<DashboardEntity>, List<CachedQueryEntity>>> CachedQueriesCache = null!;
public static ResetLazy<Dictionary<Type, List<Lite<DashboardEntity>>>> DashboardsByType = null!;
public static ResetLazy<FrozenDictionary<Lite<DashboardEntity>, DashboardEntity>> Dashboards = null!;
public static ResetLazy<FrozenDictionary<Lite<DashboardEntity>, List<CachedQueryEntity>>> CachedQueriesCache = null!;
public static ResetLazy<FrozenDictionary<Type, List<Lite<DashboardEntity>>>> DashboardsByType = null!;

public static Polymorphic<Func<IPartEntity, PanelPartEmbedded, IEnumerable<CachedQueryDefinition>>> OnGetCachedQueryDefinition = new();

Expand Down Expand Up @@ -107,15 +108,15 @@ public static void Start(SchemaBuilder sb, IFileTypeAlgorithm cachedQueryAlgorit
DashboardGraph.Register();


Dashboards = sb.GlobalLazy(() => Database.Query<DashboardEntity>().ToDictionary(a => a.ToLite()),
Dashboards = sb.GlobalLazy(() => Database.Query<DashboardEntity>().ToFrozenDictionary(a => a.ToLite()),
new InvalidateWith(typeof(DashboardEntity)));

CachedQueriesCache = sb.GlobalLazy(() => Database.Query<CachedQueryEntity>().GroupToDictionary(a => a.Dashboard),
CachedQueriesCache = sb.GlobalLazy(() => Database.Query<CachedQueryEntity>().GroupToDictionary(a => a.Dashboard).ToFrozenDictionary(),
new InvalidateWith(typeof(CachedQueryEntity)));

DashboardsByType = sb.GlobalLazy(() => Dashboards.Value.Values.Where(a => a.EntityType != null)
.SelectCatch(d => KeyValuePair.Create(TypeLogic.IdToType.GetOrThrow(d.EntityType!.Id), d.ToLite()))
.GroupToDictionary(),
.GroupToDictionary().ToFrozenDictionary(),
new InvalidateWith(typeof(DashboardEntity)));

if (sb.WebServerBuilder != null)
Expand Down
9 changes: 5 additions & 4 deletions Extensions/Signum.Eval/TypeHelp/TypeHelpLogic.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Signum.API;
using System;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -10,8 +11,8 @@ namespace Signum.Eval.TypeHelp;

public static class TypeHelpLogic
{
public static ResetLazy<HashSet<Type>> AvailableEmbeddedEntities = null!;
public static ResetLazy<HashSet<Type>> AvailableModelEntities = null!;
public static ResetLazy<FrozenSet<Type>> AvailableEmbeddedEntities = null!;
public static ResetLazy<FrozenSet<Type>> AvailableModelEntities = null!;

public static void Start(SchemaBuilder sb)
{
Expand All @@ -25,7 +26,7 @@ public static void Start(SchemaBuilder sb)
.Distinct()
.SelectMany(a => a.GetTypes())
.Where(t => typeof(EmbeddedEntity).IsAssignableFrom(t) && namespaces.Contains(t.Namespace!))
.ToHashSet();
.ToFrozenSet();

}, new InvalidateWith());

Expand All @@ -37,7 +38,7 @@ public static void Start(SchemaBuilder sb)
.Distinct()
.SelectMany(a => a.GetTypes())
.Where(t => typeof(ModelEntity).IsAssignableFrom(t) && namespaces.Contains(t.Namespace!))
.ToHashSet();
.ToFrozenSet();

}, new InvalidateWith());

Expand Down
15 changes: 8 additions & 7 deletions Extensions/Signum.Mailing/EmailModelLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Signum.Templating;
using Signum.UserAssets;
using Signum.Authorization;
using System.Collections.Frozen;

namespace Signum.Mailing;

Expand Down Expand Up @@ -73,7 +74,7 @@ public virtual List<Filter> GetFilters(QueryDescription qd)
throw new InvalidOperationException($"Since {typeof(T).Name} is not in {imp}, it's necessary to override ${nameof(GetFilters)} in ${this.GetType().Name}");
}

public virtual List<Order> GetOrders(QueryDescription queryDescription)
public virtual List<Order> GetOrders(QueryDescription qd)
{
return new List<Order>();
}
Expand Down Expand Up @@ -134,10 +135,10 @@ public EmailModelInfo(object queryName)
}
}

static ResetLazy<Dictionary<Lite<EmailModelEntity>, List<EmailTemplateEntity>>> EmailModelToTemplates = null!;
static ResetLazy<FrozenDictionary<Lite<EmailModelEntity>, List<EmailTemplateEntity>>> EmailModelToTemplates = null!;
static Dictionary<Type, EmailModelInfo> registeredModels = new Dictionary<Type, EmailModelInfo>();
public static ResetLazy<Dictionary<Type, EmailModelEntity>> TypeToEntity = null!;
public static ResetLazy<Dictionary<EmailModelEntity, Type>> EntityToType = null!;
public static ResetLazy<FrozenDictionary<Type, EmailModelEntity>> TypeToEntity = null!;
public static ResetLazy<FrozenDictionary<EmailModelEntity, Type>> EntityToType = null!;

public static void Start(SchemaBuilder sb)
{
Expand Down Expand Up @@ -165,7 +166,7 @@ public static void Start(SchemaBuilder sb)
from et in Database.Query<EmailTemplateEntity>()
where et.Model != null
select new { se = et.Model, et })
.GroupToDictionary(pair => pair.se.ToLite(), pair => pair.et),
.GroupToDictionary(pair => pair.se.ToLite(), pair => pair.et).ToFrozenDictionary(),
new InvalidateWith(typeof(EmailModelEntity), typeof(EmailTemplateEntity)));

TypeToEntity = sb.GlobalLazy(() =>
Expand All @@ -178,13 +179,13 @@ from et in Database.Query<EmailTemplateEntity>()
type => type.FullName!,
(entity, type) => KeyValuePair.Create(type, entity),
"caching " + nameof(EmailModelEntity))
.ToDictionary();
.ToFrozenDictionaryEx();
}, new InvalidateWith(typeof(EmailModelEntity)));


sb.Schema.Initializing += () => TypeToEntity.Load();

EntityToType = sb.GlobalLazy(() => TypeToEntity.Value.Inverse(),
EntityToType = sb.GlobalLazy(() => TypeToEntity.Value.Inverse().ToFrozenDictionaryEx(),
new InvalidateWith(typeof(EmailModelEntity)));
}
}
Expand Down
5 changes: 3 additions & 2 deletions Extensions/Signum.Mailing/EmailSenderConfigurationLogic.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System.Net.Mail;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Collections.Frozen;

namespace Signum.Mailing;

public static class EmailSenderConfigurationLogic
{
public static ResetLazy<Dictionary<Lite<EmailSenderConfigurationEntity>, EmailSenderConfigurationEntity>> EmailSenderCache = null!;
public static ResetLazy<FrozenDictionary<Lite<EmailSenderConfigurationEntity>, EmailSenderConfigurationEntity>> EmailSenderCache = null!;

public static Func<string, string> EncryptPassword = s => s;
public static Func<string, string> DecryptPassword = s => s;
Expand All @@ -33,7 +34,7 @@ public static void Start(SchemaBuilder sb, Func<string, string>? encryptPassword
s.Service
});

EmailSenderCache = sb.GlobalLazy(() => Database.Query<EmailSenderConfigurationEntity>().ToDictionary(a => a.ToLite()),
EmailSenderCache = sb.GlobalLazy(() => Database.Query<EmailSenderConfigurationEntity>().ToFrozenDictionaryEx(a => a.ToLite()),
new InvalidateWith(typeof(EmailSenderConfigurationEntity)));

new Graph<EmailSenderConfigurationEntity>.Execute(EmailSenderConfigurationOperation.Save)
Expand Down
9 changes: 5 additions & 4 deletions Extensions/Signum.Mailing/Templates/EmailTemplateLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Signum.UserAssets.Queries;
using Signum.API;
using Signum.Authorization;
using System.Collections.Frozen;

namespace Signum.Mailing.Templates;

Expand All @@ -27,8 +28,8 @@ public static class EmailTemplateLogic
public static IQueryable<EmailTemplateEntity> EmailTemplates(this EmailModelEntity se) =>
As.Expression(() => Database.Query<EmailTemplateEntity>().Where(et => et.Model.Is(se)));

public static ResetLazy<Dictionary<Lite<EmailTemplateEntity>, EmailTemplateEntity>> EmailTemplatesLazy = null!;
public static ResetLazy<Dictionary<object, List<EmailTemplateEntity>>> TemplatesByQueryName = null!;
public static ResetLazy<FrozenDictionary<Lite<EmailTemplateEntity>, EmailTemplateEntity>> EmailTemplatesLazy = null!;
public static ResetLazy<FrozenDictionary<object, List<EmailTemplateEntity>>> TemplatesByQueryName = null!;


public static Polymorphic<Action<IAttachmentGeneratorEntity, FillAttachmentTokenContext>> FillAttachmentTokens =
Expand Down Expand Up @@ -92,12 +93,12 @@ public static void Start(SchemaBuilder sb, Func<EmailTemplateEntity, Lite<Entity


EmailTemplatesLazy = sb.GlobalLazy(() =>
Database.Query<EmailTemplateEntity>().ToDictionary(et => et.ToLite())
Database.Query<EmailTemplateEntity>().ToFrozenDictionaryEx(et => et.ToLite())
, new InvalidateWith(typeof(EmailTemplateEntity)));

TemplatesByQueryName = sb.GlobalLazy(() =>
{
return EmailTemplatesLazy.Value.Values.Where(a => a.Query != null).SelectCatch(et => KeyValuePair.Create(et.Query!.ToQueryName(), et)).GroupToDictionary();
return EmailTemplatesLazy.Value.Values.Where(a => a.Query != null).SelectCatch(et => KeyValuePair.Create(et.Query!.ToQueryName(), et)).GroupToDictionary().ToFrozenDictionary();
}, new InvalidateWith(typeof(EmailTemplateEntity)));

EmailModelLogic.Start(sb);
Expand Down
5 changes: 3 additions & 2 deletions Extensions/Signum.Scheduler/SchedulerLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Signum.Authorization;
using Signum.Authorization.Rules;
using Signum.API;
using System.Collections.ObjectModel;

namespace Signum.Scheduler;

Expand Down Expand Up @@ -32,7 +33,7 @@ public static IQueryable<SchedulerTaskExceptionLineEntity> ExceptionLines(this S

public static Action<ScheduledTaskLogEntity>? OnFinally;

public static ResetLazy<List<ScheduledTaskEntity>> ScheduledTasksLazy = null!;
public static ResetLazy<ReadOnlyCollection<ScheduledTaskEntity>> ScheduledTasksLazy = null!;

public static void Start(SchemaBuilder sb)
{
Expand Down Expand Up @@ -151,7 +152,7 @@ public static void Start(SchemaBuilder sb)

ScheduledTasksLazy = sb.GlobalLazy(() =>
Database.Query<ScheduledTaskEntity>().Where(a => !a.Suspended &&
(a.MachineName == ScheduledTaskEntity.None || a.MachineName == Schema.Current.MachineName && a.ApplicationName == Schema.Current.ApplicationName)).ToList(),
(a.MachineName == ScheduledTaskEntity.None || a.MachineName == Schema.Current.MachineName && a.ApplicationName == Schema.Current.ApplicationName)).ToReadOnly(),
new InvalidateWith(typeof(ScheduledTaskEntity)));

ScheduledTasksLazy.OnReset += ScheduleTaskRunner.ScheduledTasksLazy_OnReset;
Expand Down
9 changes: 5 additions & 4 deletions Extensions/Signum.Toolbar/ToolbarLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
using Signum.Authorization.Rules;
using Signum.UserAssets;
using Signum.Utilities.DataStructures;
using System.Collections.Frozen;
using System.Text.Json.Serialization;

namespace Signum.Toolbar;

public static class ToolbarLogic
{
public static ResetLazy<Dictionary<Lite<ToolbarEntity>, ToolbarEntity>> Toolbars = null!;
public static ResetLazy<Dictionary<Lite<ToolbarMenuEntity>, ToolbarMenuEntity>> ToolbarMenus = null!;
public static ResetLazy<FrozenDictionary<Lite<ToolbarEntity>, ToolbarEntity>> Toolbars = null!;
public static ResetLazy<FrozenDictionary<Lite<ToolbarMenuEntity>, ToolbarMenuEntity>> ToolbarMenus = null!;

public static Dictionary<PermissionSymbol, Func<List<ToolbarResponse>>> CustomPermissionResponse =
new Dictionary<PermissionSymbol, Func<List<ToolbarResponse>>>();
Expand Down Expand Up @@ -103,10 +104,10 @@ public static void Start(SchemaBuilder sb)
//{ typeof(WorkflowEntity), a => { var wf = WorkflowLogic.WorkflowGraphLazy.Value.GetOrCreate((Lite<WorkflowEntity>)a); return InMemoryFilter(wf.Workflow) && wf.IsStartCurrentUser(); } },


Toolbars = sb.GlobalLazy(() => Database.Query<ToolbarEntity>().ToDictionary(a => a.ToLite()),
Toolbars = sb.GlobalLazy(() => Database.Query<ToolbarEntity>().ToFrozenDictionaryEx(a => a.ToLite()),
new InvalidateWith(typeof(ToolbarEntity)));

ToolbarMenus = sb.GlobalLazy(() => Database.Query<ToolbarMenuEntity>().ToDictionary(a => a.ToLite()),
ToolbarMenus = sb.GlobalLazy(() => Database.Query<ToolbarMenuEntity>().ToFrozenDictionaryEx(a => a.ToLite()),
new InvalidateWith(typeof(ToolbarMenuEntity)));
}
}
Expand Down
Loading

0 comments on commit 3d4cb33

Please sign in to comment.