Skip to content

Commit 3d4cb33

Browse files
committed
Merge remote-tracking branch 'github/master'
# Conflicts: # Extensions/Signum.Mailing/Templates/EmailTemplateLogic.cs # Extensions/Signum.Word/WordTemplateLogic.cs
2 parents b610347 + f7626dc commit 3d4cb33

30 files changed

Lines changed: 183 additions & 137 deletions

File tree

Extensions/Signum.Authorization/AuthLogic.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Signum.Authorization.Rules;
44
using Signum.Utilities.DataStructures;
55
using Signum.Utilities.Reflection;
6+
using System.Collections.Frozen;
67
using System.IO;
78
using System.Xml.Linq;
89

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

4647
static ResetLazy<DirectedGraph<Lite<RoleEntity>>> rolesGraph = null!;
4748
static ResetLazy<DirectedGraph<Lite<RoleEntity>>> rolesInverse = null!;
48-
static ResetLazy<Dictionary<string, Lite<RoleEntity>>> rolesByName = null!;
49-
public static ResetLazy<Dictionary<Lite<RoleEntity>, RoleEntity>> RolesByLite = null!;
49+
static ResetLazy<FrozenDictionary<string, Lite<RoleEntity>>> rolesByName = null!;
50+
public static ResetLazy<FrozenDictionary<Lite<RoleEntity>, RoleEntity>> RolesByLite = null!;
5051

5152

5253

@@ -56,7 +57,7 @@ class RoleData
5657
public MergeStrategy MergeStrategy;
5758
}
5859

59-
static ResetLazy<Dictionary<Lite<RoleEntity>, RoleData>> mergeStrategies = null!;
60+
static ResetLazy<FrozenDictionary<Lite<RoleEntity>, RoleData>> mergeStrategies = null!;
6061

6162
public static void AssertStarted(SchemaBuilder sb)
6263
{
@@ -108,8 +109,8 @@ public static void Start(SchemaBuilder sb, string? systemUserName, string? anony
108109

109110

110111

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

135-
return result;
136+
return result.ToFrozenDictionary();
136137
}, new InvalidateWith(typeof(RoleEntity)));
137138

138139
sb.Schema.EntityEvents<RoleEntity>().Saving += Schema_Saving;
@@ -259,7 +260,7 @@ static void Schema_Saving(RoleEntity role)
259260
}
260261
}
261262

262-
static DirectedGraph<Lite<RoleEntity>> CacheRoles(Dictionary<Lite<RoleEntity>, RoleEntity> rolesLite)
263+
static DirectedGraph<Lite<RoleEntity>> CacheRoles(FrozenDictionary<Lite<RoleEntity>, RoleEntity> rolesLite)
263264
{
264265
var graph = DirectedGraph<Lite<RoleEntity>>.Generate(rolesLite.Keys, r => rolesLite.GetOrThrow(r).InheritsFrom);
265266

Extensions/Signum.Authorization/AuthServer.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Runtime.InteropServices;
1212
using System.Collections.Concurrent;
1313
using System.Reflection;
14+
using System.Collections.Frozen;
1415

1516
namespace Signum.Authorization;
1617

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

265266
}
266267

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

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

Extensions/Signum.Chart/ColorPalette/ChartColorLogic.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
using System.Collections.Frozen;
2+
13
namespace Signum.Chart.ColorPalette;
24

35
public static class ColorPaletteLogic
46
{
5-
public static ResetLazy<Dictionary<Type, ColorPaletteEntity>> ColorPaletteCache = null!;
7+
public static ResetLazy<FrozenDictionary<Type, ColorPaletteEntity>> ColorPaletteCache = null!;
68

79
public static readonly int Limit = 360;
810

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

2527
ColorPaletteCache = sb.GlobalLazy(() =>
2628
Database.Query<ColorPaletteEntity>()
27-
.ToDictionaryEx(cc => cc.Type.ToType()),
29+
.ToFrozenDictionaryEx(cc => cc.Type.ToType()),
2830
new InvalidateWith(typeof(ColorPaletteEntity)));
2931
}
3032
}

Extensions/Signum.Chart/UserChart/UserChartLogic.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
using Signum.UserAssets.QueryTokens;
99
using Signum.UserQueries;
1010
using Signum.ViewLog;
11+
using System.Collections.Frozen;
1112

1213
namespace Signum.Chart.UserChart;
1314

1415
public static class UserChartLogic
1516
{
16-
public static ResetLazy<Dictionary<Lite<UserChartEntity>, UserChartEntity>> UserCharts = null!;
17-
public static ResetLazy<Dictionary<Type, List<Lite<UserChartEntity>>>> UserChartsByType = null!;
18-
public static ResetLazy<Dictionary<object, List<Lite<UserChartEntity>>>> UserChartsByQuery = null!;
17+
public static ResetLazy<FrozenDictionary<Lite<UserChartEntity>, UserChartEntity>> UserCharts = null!;
18+
public static ResetLazy<FrozenDictionary<Type, List<Lite<UserChartEntity>>>> UserChartsByType = null!;
19+
public static ResetLazy<FrozenDictionary<object, List<Lite<UserChartEntity>>>> UserChartsByQuery = null!;
1920

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

149150

150-
UserCharts = sb.GlobalLazy(() => Database.Query<UserChartEntity>().ToDictionary(a => a.ToLite()),
151+
UserCharts = sb.GlobalLazy(() => Database.Query<UserChartEntity>().ToFrozenDictionaryEx(a => a.ToLite()),
151152
new InvalidateWith(typeof(UserChartEntity)));
152153

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

156157
UserChartsByType = sb.GlobalLazy(() => UserCharts.Value.Values.Where(a => a.EntityType != null)
157158
.SelectCatch(a => KeyValuePair.Create(TypeLogic.IdToType.GetOrThrow(a.EntityType!.Id), a.ToLite()))
158-
.GroupToDictionary(),
159+
.GroupToDictionary().ToFrozenDictionary(),
159160
new InvalidateWith(typeof(UserChartEntity)));
160161
}
161162
}

Extensions/Signum.Dashboard/DashboardLogic.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
using Signum.Toolbar;
1717
using Signum.API;
1818
using Signum.Omnibox;
19+
using System.Collections.Frozen;
1920

2021
namespace Signum.Dashboard;
2122

2223
public static class DashboardLogic
2324
{
24-
public static ResetLazy<Dictionary<Lite<DashboardEntity>, DashboardEntity>> Dashboards = null!;
25-
public static ResetLazy<Dictionary<Lite<DashboardEntity>, List<CachedQueryEntity>>> CachedQueriesCache = null!;
26-
public static ResetLazy<Dictionary<Type, List<Lite<DashboardEntity>>>> DashboardsByType = null!;
25+
public static ResetLazy<FrozenDictionary<Lite<DashboardEntity>, DashboardEntity>> Dashboards = null!;
26+
public static ResetLazy<FrozenDictionary<Lite<DashboardEntity>, List<CachedQueryEntity>>> CachedQueriesCache = null!;
27+
public static ResetLazy<FrozenDictionary<Type, List<Lite<DashboardEntity>>>> DashboardsByType = null!;
2728

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

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

109110

110-
Dashboards = sb.GlobalLazy(() => Database.Query<DashboardEntity>().ToDictionary(a => a.ToLite()),
111+
Dashboards = sb.GlobalLazy(() => Database.Query<DashboardEntity>().ToFrozenDictionary(a => a.ToLite()),
111112
new InvalidateWith(typeof(DashboardEntity)));
112113

113-
CachedQueriesCache = sb.GlobalLazy(() => Database.Query<CachedQueryEntity>().GroupToDictionary(a => a.Dashboard),
114+
CachedQueriesCache = sb.GlobalLazy(() => Database.Query<CachedQueryEntity>().GroupToDictionary(a => a.Dashboard).ToFrozenDictionary(),
114115
new InvalidateWith(typeof(CachedQueryEntity)));
115116

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

121122
if (sb.WebServerBuilder != null)

Extensions/Signum.Eval/TypeHelp/TypeHelpLogic.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Signum.API;
22
using System;
3+
using System.Collections.Frozen;
34
using System.Collections.Generic;
45
using System.Linq;
56
using System.Text;
@@ -10,8 +11,8 @@ namespace Signum.Eval.TypeHelp;
1011

1112
public static class TypeHelpLogic
1213
{
13-
public static ResetLazy<HashSet<Type>> AvailableEmbeddedEntities = null!;
14-
public static ResetLazy<HashSet<Type>> AvailableModelEntities = null!;
14+
public static ResetLazy<FrozenSet<Type>> AvailableEmbeddedEntities = null!;
15+
public static ResetLazy<FrozenSet<Type>> AvailableModelEntities = null!;
1516

1617
public static void Start(SchemaBuilder sb)
1718
{
@@ -25,7 +26,7 @@ public static void Start(SchemaBuilder sb)
2526
.Distinct()
2627
.SelectMany(a => a.GetTypes())
2728
.Where(t => typeof(EmbeddedEntity).IsAssignableFrom(t) && namespaces.Contains(t.Namespace!))
28-
.ToHashSet();
29+
.ToFrozenSet();
2930

3031
}, new InvalidateWith());
3132

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

4243
}, new InvalidateWith());
4344

Extensions/Signum.Mailing/EmailModelLogic.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Signum.Templating;
55
using Signum.UserAssets;
66
using Signum.Authorization;
7+
using System.Collections.Frozen;
78

89
namespace Signum.Mailing;
910

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

76-
public virtual List<Order> GetOrders(QueryDescription queryDescription)
77+
public virtual List<Order> GetOrders(QueryDescription qd)
7778
{
7879
return new List<Order>();
7980
}
@@ -134,10 +135,10 @@ public EmailModelInfo(object queryName)
134135
}
135136
}
136137

137-
static ResetLazy<Dictionary<Lite<EmailModelEntity>, List<EmailTemplateEntity>>> EmailModelToTemplates = null!;
138+
static ResetLazy<FrozenDictionary<Lite<EmailModelEntity>, List<EmailTemplateEntity>>> EmailModelToTemplates = null!;
138139
static Dictionary<Type, EmailModelInfo> registeredModels = new Dictionary<Type, EmailModelInfo>();
139-
public static ResetLazy<Dictionary<Type, EmailModelEntity>> TypeToEntity = null!;
140-
public static ResetLazy<Dictionary<EmailModelEntity, Type>> EntityToType = null!;
140+
public static ResetLazy<FrozenDictionary<Type, EmailModelEntity>> TypeToEntity = null!;
141+
public static ResetLazy<FrozenDictionary<EmailModelEntity, Type>> EntityToType = null!;
141142

142143
public static void Start(SchemaBuilder sb)
143144
{
@@ -165,7 +166,7 @@ public static void Start(SchemaBuilder sb)
165166
from et in Database.Query<EmailTemplateEntity>()
166167
where et.Model != null
167168
select new { se = et.Model, et })
168-
.GroupToDictionary(pair => pair.se.ToLite(), pair => pair.et),
169+
.GroupToDictionary(pair => pair.se.ToLite(), pair => pair.et).ToFrozenDictionary(),
169170
new InvalidateWith(typeof(EmailModelEntity), typeof(EmailTemplateEntity)));
170171

171172
TypeToEntity = sb.GlobalLazy(() =>
@@ -178,13 +179,13 @@ from et in Database.Query<EmailTemplateEntity>()
178179
type => type.FullName!,
179180
(entity, type) => KeyValuePair.Create(type, entity),
180181
"caching " + nameof(EmailModelEntity))
181-
.ToDictionary();
182+
.ToFrozenDictionaryEx();
182183
}, new InvalidateWith(typeof(EmailModelEntity)));
183184

184185

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

187-
EntityToType = sb.GlobalLazy(() => TypeToEntity.Value.Inverse(),
188+
EntityToType = sb.GlobalLazy(() => TypeToEntity.Value.Inverse().ToFrozenDictionaryEx(),
188189
new InvalidateWith(typeof(EmailModelEntity)));
189190
}
190191
}

Extensions/Signum.Mailing/EmailSenderConfigurationLogic.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using System.Net.Mail;
22
using System.Net;
33
using System.Security.Cryptography.X509Certificates;
4+
using System.Collections.Frozen;
45

56
namespace Signum.Mailing;
67

78
public static class EmailSenderConfigurationLogic
89
{
9-
public static ResetLazy<Dictionary<Lite<EmailSenderConfigurationEntity>, EmailSenderConfigurationEntity>> EmailSenderCache = null!;
10+
public static ResetLazy<FrozenDictionary<Lite<EmailSenderConfigurationEntity>, EmailSenderConfigurationEntity>> EmailSenderCache = null!;
1011

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

36-
EmailSenderCache = sb.GlobalLazy(() => Database.Query<EmailSenderConfigurationEntity>().ToDictionary(a => a.ToLite()),
37+
EmailSenderCache = sb.GlobalLazy(() => Database.Query<EmailSenderConfigurationEntity>().ToFrozenDictionaryEx(a => a.ToLite()),
3738
new InvalidateWith(typeof(EmailSenderConfigurationEntity)));
3839

3940
new Graph<EmailSenderConfigurationEntity>.Execute(EmailSenderConfigurationOperation.Save)

Extensions/Signum.Mailing/Templates/EmailTemplateLogic.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Signum.UserAssets.Queries;
99
using Signum.API;
1010
using Signum.Authorization;
11+
using System.Collections.Frozen;
1112

1213
namespace Signum.Mailing.Templates;
1314

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

30-
public static ResetLazy<Dictionary<Lite<EmailTemplateEntity>, EmailTemplateEntity>> EmailTemplatesLazy = null!;
31-
public static ResetLazy<Dictionary<object, List<EmailTemplateEntity>>> TemplatesByQueryName = null!;
31+
public static ResetLazy<FrozenDictionary<Lite<EmailTemplateEntity>, EmailTemplateEntity>> EmailTemplatesLazy = null!;
32+
public static ResetLazy<FrozenDictionary<object, List<EmailTemplateEntity>>> TemplatesByQueryName = null!;
3233

3334

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

9394

9495
EmailTemplatesLazy = sb.GlobalLazy(() =>
95-
Database.Query<EmailTemplateEntity>().ToDictionary(et => et.ToLite())
96+
Database.Query<EmailTemplateEntity>().ToFrozenDictionaryEx(et => et.ToLite())
9697
, new InvalidateWith(typeof(EmailTemplateEntity)));
9798

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

103104
EmailModelLogic.Start(sb);

Extensions/Signum.Scheduler/SchedulerLogic.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Signum.Authorization;
66
using Signum.Authorization.Rules;
77
using Signum.API;
8+
using System.Collections.ObjectModel;
89

910
namespace Signum.Scheduler;
1011

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

3334
public static Action<ScheduledTaskLogEntity>? OnFinally;
3435

35-
public static ResetLazy<List<ScheduledTaskEntity>> ScheduledTasksLazy = null!;
36+
public static ResetLazy<ReadOnlyCollection<ScheduledTaskEntity>> ScheduledTasksLazy = null!;
3637

3738
public static void Start(SchemaBuilder sb)
3839
{
@@ -151,7 +152,7 @@ public static void Start(SchemaBuilder sb)
151152

152153
ScheduledTasksLazy = sb.GlobalLazy(() =>
153154
Database.Query<ScheduledTaskEntity>().Where(a => !a.Suspended &&
154-
(a.MachineName == ScheduledTaskEntity.None || a.MachineName == Schema.Current.MachineName && a.ApplicationName == Schema.Current.ApplicationName)).ToList(),
155+
(a.MachineName == ScheduledTaskEntity.None || a.MachineName == Schema.Current.MachineName && a.ApplicationName == Schema.Current.ApplicationName)).ToReadOnly(),
155156
new InvalidateWith(typeof(ScheduledTaskEntity)));
156157

157158
ScheduledTasksLazy.OnReset += ScheduleTaskRunner.ScheduledTasksLazy_OnReset;

0 commit comments

Comments
 (0)