Skip to content

Commit 62319d1

Browse files
committed
Minor changes
- summaries for files, types, type members - small code improvements
1 parent 0bed3fe commit 62319d1

15 files changed

+170
-131
lines changed

Extensions/Xtensive.Orm.Localization/Configuration/LocalizationConfiguration.cs

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2011-2024 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2012-2024 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Dmitri Maximov
55
// Created: 2012.07.06
66

@@ -132,7 +132,7 @@ private static LocalizationConfiguration GetConfigurationFromSection(Configurati
132132
}
133133

134134
/// <summary>
135-
/// Loads <see cref="LocalizationConfiguration"/> from given configuration section of <paramref name="configurationRoot"/>.
135+
/// Loads <see cref="LocalizationConfiguration"/> from given configuration section of <paramref name="configuration"/>.
136136
/// If section name is not provided <see cref="LocalizationConfiguration.DefaultSectionName"/> is used.
137137
/// </summary>
138138
/// <param name="configuration"><see cref="IConfiguration"/> of sections.</param>
@@ -142,17 +142,16 @@ public static LocalizationConfiguration Load(IConfiguration configuration, strin
142142
{
143143
ArgumentValidator.EnsureArgumentNotNull(configuration, nameof(configuration));
144144

145-
if (configuration is IConfigurationRoot configurationRoot)
145+
if (configuration is IConfigurationRoot configurationRoot) {
146146
return new LocalizationConfigurationReader().Read(configurationRoot, sectionName ?? DefaultSectionName);
147+
}
147148
else if (configuration is IConfigurationSection configurationSection) {
148-
if (sectionName.IsNullOrEmpty())
149-
return new LocalizationConfigurationReader().Read(configurationSection);
150-
else {
151-
return new LocalizationConfigurationReader().Read(configurationSection.GetSection(sectionName));
152-
}
149+
return sectionName.IsNullOrEmpty()
150+
? new LocalizationConfigurationReader().Read(configurationSection)
151+
: new LocalizationConfigurationReader().Read(configurationSection.GetSection(sectionName));
153152
}
154153

155-
throw new NotSupportedException("Type of configuration is not supported");
154+
throw new NotSupportedException("Type of configuration is not supported.");
156155
}
157156

158157
/// <summary>

Extensions/Xtensive.Orm.Localization/Configuration/LocalizationConfigurationReader.cs

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
// Copyright (C) 2011-2024 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
4-
// Created by: Dmitri Maximov
5-
// Created: 2012.07.06
1+
// Copyright (C) 2024 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
64

75
using System;
86
using System.Globalization;
@@ -16,6 +14,9 @@ namespace Xtensive.Orm.Localization.Configuration
1614
{
1715
internal sealed class LocalizationConfigurationReader : IConfigurationSectionReader<LocalizationConfiguration>
1816
{
17+
private const string DefaultCultureElementName = "DefaultCulture";
18+
private const string CultureNameAttributeName = "name";
19+
1920
public LocalizationConfiguration Read(IConfigurationSection configurationSection) => ReadInternal(configurationSection);
2021

2122
public LocalizationConfiguration Read(IConfigurationSection configurationSection, string nameOfConfiguration) =>
@@ -33,14 +34,13 @@ public LocalizationConfiguration Read(IConfigurationRoot configurationRoot, stri
3334
public LocalizationConfiguration Read(IConfigurationRoot configurationRoot, string sectionName, string nameOfConfiguration) =>
3435
throw new NotSupportedException();
3536

36-
private const string DefaultCultureElementName = "DefaultCulture";
37-
private const string CultureNameAttributeName = "name";
38-
3937
private LocalizationConfiguration ReadInternal(IConfigurationSection configurationSection)
4038
{
4139
var defaultCultureSection = configurationSection.GetSection(DefaultCultureElementName);
42-
if (defaultCultureSection == null)
43-
return new LocalizationConfiguration() { DefaultCulture = Thread.CurrentThread.CurrentCulture };
40+
var defaultCulture = Thread.CurrentThread.CurrentCulture;
41+
if (defaultCultureSection == null) {
42+
return new LocalizationConfiguration() { DefaultCulture = defaultCulture };
43+
}
4444

4545
var cultureName = defaultCultureSection.Value;
4646
if (cultureName == null) {
@@ -52,15 +52,16 @@ private LocalizationConfiguration ReadInternal(IConfigurationSection configurati
5252
}
5353
}
5454
}
55-
56-
if (cultureName.IsNullOrEmpty())
57-
return new LocalizationConfiguration() { DefaultCulture = Thread.CurrentThread.CurrentCulture };
58-
try {
59-
return new LocalizationConfiguration() { DefaultCulture = new CultureInfo(cultureName) };
60-
}
61-
catch (CultureNotFoundException) {
62-
return new LocalizationConfiguration() { DefaultCulture = Thread.CurrentThread.CurrentCulture };
55+
if(!cultureName.IsNullOrEmpty()) {
56+
try {
57+
defaultCulture = CultureInfo.GetCultureInfo(cultureName);
58+
}
59+
catch(CultureNotFoundException) {
60+
// swallow it, this is mark wrong culture name;
61+
}
6362
}
63+
64+
return new LocalizationConfiguration() { DefaultCulture = defaultCulture };
6465
}
6566
}
6667
}

Extensions/Xtensive.Orm.Reprocessing/Configuration/ConfigurationSection.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.ComponentModel;
33
using System.Configuration;
44

@@ -11,8 +11,9 @@ public class ConfigurationSection : System.Configuration.ConfigurationSection
1111
{
1212
/// <summary>
1313
/// Gets default section name for reprocessing configuration.
14-
/// Value is "Xtensive.Reprocessing".
14+
/// Value is "Xtensive.Orm.Reprocessing".
1515
/// </summary>
16+
[Obsolete("Use ReprocessingConfiguration.DefaultSectionName instead")]
1617
public static readonly string DefaultSectionName = "Xtensive.Orm.Reprocessing";
1718

1819
/// <summary>

Extensions/Xtensive.Orm.Reprocessing/Configuration/ReprocessingConfiguration.cs

+11-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ namespace Xtensive.Orm.Reprocessing.Configuration
1111
/// </summary>
1212
public class ReprocessingConfiguration : ConfigurationBase
1313
{
14+
/// <summary>
15+
/// Gets default section name for reprocessing configuration.
16+
/// Value is "Xtensive.Orm.Reprocessing".
17+
/// </summary>
18+
public static readonly string DefaultSectionName = "Xtensive.Orm.Reprocessing";
19+
1420
/// <summary>
1521
/// Gets default value of the <see cref="DefaultTransactionOpenMode"/> property.
1622
/// </summary>
@@ -68,7 +74,7 @@ protected override void CopyFrom(ConfigurationBase source)
6874
/// <returns>The reprocessing configuration.</returns>
6975
public static ReprocessingConfiguration Load()
7076
{
71-
return Load(ConfigurationSection.DefaultSectionName);
77+
return Load(DefaultSectionName);
7278
}
7379

7480
/// <summary>
@@ -89,7 +95,7 @@ public static ReprocessingConfiguration Load(string sectionName)
8995
/// <returns>The reprocessing configuration.</returns>
9096
public static ReprocessingConfiguration Load(System.Configuration.Configuration configuration)
9197
{
92-
return Load(configuration, ConfigurationSection.DefaultSectionName);
98+
return Load(configuration, DefaultSectionName);
9399
}
94100

95101
/// <summary>
@@ -125,13 +131,13 @@ public static ReprocessingConfiguration Load(IConfiguration configuration, strin
125131
ArgumentValidator.EnsureArgumentNotNull(configuration, nameof(configuration));
126132

127133
if (configuration is IConfigurationRoot configurationRoot) {
128-
return new ReprocessingConfigurationReader().Read(configurationRoot, sectionName ?? ConfigurationSection.DefaultSectionName);
134+
return new ReprocessingConfigurationReader().Read(configurationRoot, sectionName ?? DefaultSectionName);
129135
}
130136
else if (configuration is IConfigurationSection configurationSection) {
131137
return new ReprocessingConfigurationReader().Read(configurationSection);
132138
}
133139

134-
throw new NotSupportedException("Type of configuration is not supported");
140+
throw new NotSupportedException("Type of configuration is not supported.");
135141
}
136142

137143

@@ -145,7 +151,7 @@ public static ReprocessingConfiguration Load(IConfigurationRoot configurationRoo
145151
{
146152
ArgumentValidator.EnsureArgumentNotNull(configurationRoot, nameof(configurationRoot));
147153

148-
return new ReprocessingConfigurationReader().Read(configurationRoot, sectionName ?? ConfigurationSection.DefaultSectionName);
154+
return new ReprocessingConfigurationReader().Read(configurationRoot, sectionName ?? DefaultSectionName);
149155
}
150156

151157
/// <summary>
@@ -160,8 +166,6 @@ public static ReprocessingConfiguration Load(IConfigurationSection configuration
160166
return new ReprocessingConfigurationReader().Read(configurationSection);
161167
}
162168

163-
164-
165169
/// <summary>
166170
/// Initializes a new instance of the <see cref="ReprocessingConfiguration"/> class.
167171
/// </summary>

Extensions/Xtensive.Orm.Reprocessing/Configuration/ReprocessingConfigurationReader.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using System;
1+
// Copyright (C) 2024 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
4+
5+
using System;
26
using Microsoft.Extensions.Configuration;
37
using Xtensive.Orm.Configuration;
48

@@ -20,7 +24,7 @@ public ReprocessingConfiguration Read(IConfigurationSection configurationSection
2024
throw new NotSupportedException();
2125

2226
public ReprocessingConfiguration Read(IConfigurationRoot configurationRoot) =>
23-
Read(configurationRoot, ConfigurationSection.DefaultSectionName);
27+
Read(configurationRoot, ReprocessingConfiguration.DefaultSectionName);
2428

2529
public ReprocessingConfiguration Read(IConfigurationRoot configurationRoot, string sectionName)
2630
{

Extensions/Xtensive.Orm.Reprocessing/DomainConfigurationExtensions.cs

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright (C) 2024 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
4+
15
using Microsoft.Extensions.Configuration;
26
using Xtensive.Orm.Configuration;
37
using Xtensive.Orm.Reprocessing.Configuration;

Extensions/Xtensive.Orm.Security/Configuration/SecurityConfiguration.cs

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (C) 2011-2024 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Dmitri Maximov
55
// Created: 2011.06.10
66

@@ -21,8 +21,7 @@ namespace Xtensive.Orm.Security.Configuration
2121
public class SecurityConfiguration : ConfigurationBase
2222
{
2323
/// <summary>
24-
/// Default SectionName value:
25-
/// "<see langword="Xtensive.Orm.Security" />".
24+
/// Default section in configuration. Used if custom name is not provided.
2625
/// </summary>
2726
public const string DefaultSectionName = "Xtensive.Orm.Security";
2827

@@ -119,14 +118,16 @@ private static SecurityConfiguration GetConfigurationFromSection(ConfigurationSe
119118
var hashingService = configurationSection == null
120119
? string.Empty
121120
: configurationSection.HashingService.Name;
122-
if (!string.IsNullOrEmpty(hashingService))
121+
if (!string.IsNullOrEmpty(hashingService)) {
123122
result.HashingServiceName = hashingService.ToLowerInvariant();
123+
}
124124

125125
var authenticationService = configurationSection == null
126126
? string.Empty
127127
: configurationSection.AuthenticationService.Name;
128-
if (!string.IsNullOrEmpty(authenticationService))
128+
if (!string.IsNullOrEmpty(authenticationService)) {
129129
result.AuthenticationServiceName = authenticationService.ToLowerInvariant();
130+
}
130131

131132
return result;
132133
}
@@ -148,7 +149,7 @@ public static SecurityConfiguration Load(IConfiguration configuration, string se
148149
return Load(configurationSection);
149150
}
150151

151-
throw new NotSupportedException("Type of configuration is not supported");
152+
throw new NotSupportedException("Type of configuration is not supported.");
152153
}
153154

154155

@@ -163,13 +164,12 @@ public static SecurityConfiguration Load(IConfigurationRoot configurationRoot, s
163164
ArgumentValidator.EnsureArgumentNotNull(configurationRoot, nameof(configurationRoot));
164165

165166
var configuration = new NamelessFormatSecurityConfigurationReader().Read(configurationRoot, sectionName ?? DefaultSectionName);
166-
if (configuration != null)
167+
if (configuration != null) {
167168
return configuration;
169+
}
168170

169171
configuration = new BasedOnNamesFormatSecurityConfigurationReader().Read(configurationRoot, sectionName ?? DefaultSectionName);
170-
if (configuration != null)
171-
return configuration;
172-
return new SecurityConfiguration(true);
172+
return configuration ?? new SecurityConfiguration(true);
173173
}
174174

175175
/// <summary>
@@ -182,13 +182,12 @@ public static SecurityConfiguration Load(IConfigurationSection configurationSect
182182
ArgumentValidator.EnsureArgumentNotNull(configurationSection, nameof(configurationSection));
183183

184184
var configuration = new NamelessFormatSecurityConfigurationReader().Read(configurationSection);
185-
if (configuration != null)
185+
if (configuration != null) {
186186
return configuration;
187+
}
187188

188189
configuration = new BasedOnNamesFormatSecurityConfigurationReader().Read(configurationSection);
189-
if (configuration != null)
190-
return configuration;
191-
return new SecurityConfiguration(true);
190+
return configuration ?? new SecurityConfiguration(true);
192191
}
193192

194193
/// <summary>

Extensions/Xtensive.Orm.Security/Configuration/SecurityConfigurationReaders.cs

+14-22
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
// Copyright (C) 2024 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
4+
15
using System;
2-
using System.Collections.Generic;
36
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
67
using Microsoft.Extensions.Configuration;
8+
using Xtensive.Core;
79
using Xtensive.Orm.Configuration;
810

911
namespace Xtensive.Orm.Security.Configuration
@@ -12,16 +14,6 @@ internal sealed class NamelessFormatSecurityConfigurationReader : SecurityConfig
1214
{
1315
protected override SecurityConfiguration ReadInternal(IConfigurationSection configuration)
1416
{
15-
// <Xtensive.Orm.Security>
16-
// <hashingService>sha1</hashingService>
17-
// <authenticationService>SomeServiceName</authenticationService>
18-
// </Xtensive.Orm.Security>
19-
// or
20-
// "Xtensive.Orm.Security" : {
21-
// "hashingService" :"sha1",
22-
// "authenticationService" : "SomeServiceName"
23-
// }
24-
2517
try {
2618
var configAsIs = configuration.Get<SecurityConfiguration>();
2719
if (configAsIs != null && (configAsIs.AuthenticationServiceName ?? configAsIs.HashingServiceName) != null) {
@@ -38,13 +30,10 @@ protected override SecurityConfiguration ReadInternal(IConfigurationSection conf
3830
return null;
3931
}
4032

41-
var children = configuration.GetChildren().ToList();
42-
if (!children.Any()) {
43-
return new SecurityConfiguration(true);
44-
}
45-
else {
46-
return null;
47-
}
33+
var children = configuration.GetChildren();
34+
return !children.Any()
35+
? new SecurityConfiguration(true)
36+
: null;
4837
}
4938
}
5039

@@ -79,10 +68,13 @@ protected override SecurityConfiguration ReadInternal(IConfigurationSection conf
7968
}
8069
if ((hashingServiceName ?? authenticationServiceName) != null) {
8170
var securityConfiguration = new SecurityConfiguration(true);
82-
if (!string.IsNullOrEmpty(hashingServiceName))
71+
if (!hashingServiceName.IsNullOrEmpty()) {
8372
securityConfiguration.HashingServiceName = hashingServiceName.ToLowerInvariant();
84-
if (!string.IsNullOrEmpty(authenticationServiceName))
73+
}
74+
75+
if (!authenticationServiceName.IsNullOrEmpty()) {
8576
securityConfiguration.AuthenticationServiceName = authenticationServiceName.ToLowerInvariant();
77+
}
8678

8779
return securityConfiguration;
8880
}

Orm/Xtensive.Orm/Orm/Configuration/DomainConfiguration.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@
99
using System.Linq;
1010
using JetBrains.Annotations;
1111
using Microsoft.Extensions.Configuration;
12-
using Xtensive.Collections;
1312
using Xtensive.Core;
14-
using Xtensive.Orm.Configuration.Internals;
1513
using Xtensive.Orm.Internals;
1614
using ConfigurationSection = Xtensive.Orm.Configuration.Elements.ConfigurationSection;
1715

1816
namespace Xtensive.Orm.Configuration
1917
{
2018
/// <summary>
2119
/// The configuration of the <see cref="Domain"/>.
22-
/// </summary>
20+
/// </summary>
2321
[Serializable]
2422
public class DomainConfiguration : ConfigurationBase
2523
{

0 commit comments

Comments
 (0)