Skip to content

Commit 0db7b6a

Browse files
Merge pull request #44 from aspnet/Doc-Updates
Doc updates and nupkg packing refinement.
2 parents 1bab0d1 + 8b8821a commit 0db7b6a

10 files changed

Lines changed: 265 additions & 44 deletions

File tree

README.md

Lines changed: 164 additions & 24 deletions
Large diffs are not rendered by default.

src/Azure/AzureKeyVaultConfigBuilder.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class AzureKeyVaultConfigBuilder : KeyValueConfigBuilder
4545
/// <param name="config">A collection of the name/value pairs representing builder-specific attributes specified in the configuration for this provider.</param>
4646
protected override void LazyInitialize(string name, NameValueCollection config)
4747
{
48-
// Default 'Optional' to false. base.Initialize() will override if specified in config.
48+
// Default 'Optional' to false. base.LazyInitialize() will override if specified in config.
4949
Optional = false;
5050

5151
base.LazyInitialize(name, config);
@@ -133,12 +133,22 @@ public override ICollection<KeyValuePair<string, string>> GetAllValues(string pr
133133
return d;
134134
}
135135

136+
/// <summary>
137+
/// Makes a determination about whether the input key is valid for this builder and backing store.
138+
/// </summary>
139+
/// <param name="key">The string to be validated. May be partial.</param>
140+
/// <returns>True if the string is valid. False if the string is not a valid key.</returns>
136141
public override bool ValidateKey(string key)
137142
{
138143
// Key Vault only allows alphanumerics and '-'. This builder also allows for one '/'.
139144
return Regex.IsMatch(key, "^[a-zA-Z0-9-]+(/?[a-zA-Z0-9-]+)?$");
140145
}
141146

147+
/// <summary>
148+
/// Transforms the raw key to a new string just before updating items in Strict and Greedy modes.
149+
/// </summary>
150+
/// <param name="rawKey">The key as read from the incoming config section.</param>
151+
/// <returns>The key string that will be left in the processed config section.</returns>
142152
public override string UpdateKey(string rawKey)
143153
{
144154
// Remove the version segment if it's there.

src/Base/KeyValueConfigBuilder.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public abstract class KeyValueConfigBuilder : ConfigurationBuilder
2727

2828
private NameValueCollection _config = null;
2929
private IDictionary<string, string> _cachedValues;
30+
private bool _lazyInitializeStarted = false;
3031
private bool _lazyInitialized = false;
3132
private bool _greedyInitialized = false;
3233
private bool _inAppSettings = false;
@@ -74,9 +75,9 @@ public abstract class KeyValueConfigBuilder : ConfigurationBuilder
7475
/// <returns>True if the string is valid. False if the string is not a valid key.</returns>
7576
public virtual bool ValidateKey(string key) { return true; }
7677
/// <summary>
77-
/// Transforms the raw key read from the config file to a new string when updating items in Strict and Greedy modes.
78+
/// Transforms the raw key to a new string just before updating items in Strict and Greedy modes.
7879
/// </summary>
79-
/// <param name="rawKey">The key as read from the incomming config section.</param>
80+
/// <param name="rawKey">The key as read from the incoming config section.</param>
8081
/// <returns>The key string that will be left in the processed config section.</returns>
8182
public virtual string UpdateKey(string rawKey) { return rawKey; }
8283

@@ -107,6 +108,7 @@ public override void Initialize(string name, NameValueCollection config)
107108
protected virtual void LazyInitialize(string name, NameValueCollection config)
108109
{
109110
// Use pre-assigned defaults if not specified. Non-freeform options should throw on unrecognized values.
111+
_lazyInitializeStarted = true;
110112
_tokenPattern = config[tokenPatternTag] ?? _tokenPattern;
111113
_keyPrefix = UpdateConfigSettingWithAppSettings(prefixTag) ?? _keyPrefix;
112114
_stripPrefix = (UpdateConfigSettingWithAppSettings(stripPrefixTag) != null) ? Boolean.Parse(config[stripPrefixTag]) : _stripPrefix;
@@ -116,11 +118,16 @@ protected virtual void LazyInitialize(string name, NameValueCollection config)
116118
_lazyInitialized = true;
117119
}
118120

121+
/// <summary>
122+
/// Perform token substitution on a config parameter passed through builder initialization using token values from appSettings.
123+
/// </summary>
124+
/// <param name="configName">The name of the parameter to be retrieved.</param>
125+
/// <returns>The updated parameter value if it exists. Null otherwise.</returns>
119126
protected string UpdateConfigSettingWithAppSettings(string configName)
120127
{
121128
string configValue = _config[configName];
122129

123-
if (String.IsNullOrWhiteSpace(configValue))
130+
if (!_lazyInitializeStarted || String.IsNullOrWhiteSpace(configValue))
124131
return configValue;
125132

126133
// If we are processing appSettings in ProcessConfigurationSection(), then we can use that. Other config builders in

src/Base/SectionHandler.cs

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,49 @@ internal interface ISectionHandler
1313
IEnumerator<KeyValuePair<string, object>> GetEnumerator();
1414
}
1515

16+
/// <summary>
17+
/// A class to be used by <see cref="KeyValueConfigBuilder"/>s to apply key/value config pairs to .Net configuration sections.
18+
/// </summary>
19+
/// <typeparam name="T">The type of <see cref="ConfigurationSection"/> that the implementing class can process.</typeparam>
1620
public abstract class SectionHandler<T> : ISectionHandler where T : ConfigurationSection
1721
{
22+
/// <summary>
23+
/// The <see cref="ConfigurationSection"/> instance being processed by this <see cref="SectionHandler{T}"/>.
24+
/// </summary>
1825
public T ConfigSection { get; private set; }
19-
public abstract void InsertOrUpdate(string newKey, string newValue, string oldKey = null, object oldItem = null);
26+
27+
/// <summary>
28+
/// Gets an <see cref="IEnumerator{T}"/> that iterates over the key/value pairs contained in the assigned <see cref="ConfigSection"/>. />
29+
/// </summary>
30+
/// <returns>An enumerator over pairs consisting of the existing key for a config value in the config section, and an object reference
31+
/// for the key/value pair to be passed in to <see cref="InsertOrUpdate(string, string, string, object)"/> while processing the config section.</returns>
2032
public abstract IEnumerator<KeyValuePair<string, object>> GetEnumerator();
33+
34+
/// <summary>
35+
/// Updates an existing config value in the assigned <see cref="ConfigSection"/> with a new key and a new value. The old config value
36+
/// can be located using the <paramref name="oldKey"/> or <paramref name="oldItem"/> parameters. If an old config value is not
37+
/// found, a new config value should be inserted.
38+
/// </summary>
39+
/// <param name="newKey">The updated key name for the config item.</param>
40+
/// <param name="newValue">The updated value for the config item.</param>
41+
/// <param name="oldKey">The old key name for the config item, or null.</param>
42+
/// <param name="oldItem">A reference to the old key/value pair obtained by <see cref="GetEnumerator"/>, or null.</param>
43+
public abstract void InsertOrUpdate(string newKey, string newValue, string oldKey = null, object oldItem = null);
2144
}
2245

46+
/// <summary>
47+
/// A class that can be used by <see cref="KeyValueConfigBuilder"/>s to apply key/value config pairs to <see cref="AppSettingsSection"/>.
48+
/// </summary>
2349
public class AppSettingsSectionHandler : SectionHandler<AppSettingsSection>
2450
{
51+
/// <summary>
52+
/// Updates an existing app setting in the assigned <see cref="SectionHandler{T}.ConfigSection"/> with a new key and a new value. The old setting
53+
/// can be located using the <paramref name="oldKey"/> parameter. If an old setting is not found, a new setting should be inserted.
54+
/// </summary>
55+
/// <param name="newKey">The updated key name for the app setting.</param>
56+
/// <param name="newValue">The updated value for the app setting.</param>
57+
/// <param name="oldKey">The old key name for the app setting, or null.</param>
58+
/// <param name="oldItem">The old key name for the app setting, or null., or null.</param>
2559
public override void InsertOrUpdate(string newKey, string newValue, string oldKey = null, object oldItem = null)
2660
{
2761
if (newValue != null)
@@ -34,6 +68,10 @@ public override void InsertOrUpdate(string newKey, string newValue, string oldKe
3468
}
3569
}
3670

71+
/// <summary>
72+
/// Gets an <see cref="IEnumerator{T}"/> that iterates over the key/value pairs contained in the assigned <see cref="SectionHandler{T}.ConfigSection"/>. />
73+
/// </summary>
74+
/// <returns>An enumerator over pairs where both values of the pair are the existing key for each setting in the appSettings section.</returns>
3775
public override IEnumerator<KeyValuePair<string, object>> GetEnumerator()
3876
{
3977
// Grab a copy of the keys array since we are using 'yield' and the Settings collection may change on us.
@@ -43,14 +81,26 @@ public override IEnumerator<KeyValuePair<string, object>> GetEnumerator()
4381
}
4482
}
4583

84+
/// <summary>
85+
/// A class that can be used by <see cref="KeyValueConfigBuilder"/>s to apply key/value config pairs to <see cref="ConnectionStringsSection"/>.
86+
/// </summary>
4687
public class ConnectionStringsSectionHandler : SectionHandler<ConnectionStringsSection>
4788
{
48-
public override void InsertOrUpdate(string newKey, string newValue, string oldKey = null, object oldValue = null)
89+
/// <summary>
90+
/// Updates an existing connection string in the assigned <see cref="SectionHandler{T}.ConfigSection"/> with a new name and a new value. The old
91+
/// connection string can be located using the <paramref name="oldItem"/> parameter. If an old connection string is not found, a new connection
92+
/// string should be inserted.
93+
/// </summary>
94+
/// <param name="newKey">The updated key name for the connection string.</param>
95+
/// <param name="newValue">The updated value for the connection string.</param>
96+
/// <param name="oldKey">The old key name for the connection string, or null.</param>
97+
/// <param name="oldItem">A reference to the old <see cref="ConnectionStringSettings"/> object obtained by <see cref="GetEnumerator"/>, or null.</param>
98+
public override void InsertOrUpdate(string newKey, string newValue, string oldKey = null, object oldItem = null)
4999
{
50100
if (newValue != null)
51101
{
52102
// Preserve the old entry if it exists, as it might have more than just name/connectionString attributes.
53-
ConnectionStringSettings cs = (oldValue as ConnectionStringSettings) ?? new ConnectionStringSettings();
103+
ConnectionStringSettings cs = (oldItem as ConnectionStringSettings) ?? new ConnectionStringSettings();
54104

55105
// Make sure there are no entries using the old or new name other than this one
56106
ConfigSection.ConnectionStrings.Remove(oldKey);
@@ -63,6 +113,11 @@ public override void InsertOrUpdate(string newKey, string newValue, string oldKe
63113
}
64114
}
65115

116+
/// <summary>
117+
/// Gets an <see cref="IEnumerator{T}"/> that iterates over the key/value pairs contained in the assigned <see cref="SectionHandler{T}.ConfigSection"/>. />
118+
/// </summary>
119+
/// <returns>An enumerator over pairs where the key is the existing name for each setting in the connectionStrings section, and the value
120+
/// is a reference to the <see cref="ConnectionStringSettings"/> object referred to by that name.</returns>
66121
public override IEnumerator<KeyValuePair<string, object>> GetEnumerator()
67122
{
68123
// The ConnectionStrings collection may change on us while we enumerate. :/

src/Base/SectionHandlerSection.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,25 @@
66

77
namespace Microsoft.Configuration.ConfigurationBuilders
88
{
9-
public class SectionHandlersSection : ConfigurationSection
9+
/// <summary>
10+
/// Provides programmatic access to the 'sectionHandlers' config section. This class can't be inherited.
11+
/// </summary>
12+
public sealed class SectionHandlersSection : ConfigurationSection
1013
{
1114
static readonly string handlerSectionName = "Microsoft.Configuration.ConfigurationBuilders.SectionHandlers";
1215

16+
/// <summary>
17+
/// Gets the collection of <see cref="SectionHandler{T}" />s defined for processing config sections with <see cref="KeyValueConfigBuilder"/>s./>
18+
/// </summary>
1319
[ConfigurationProperty("handlers", IsDefaultCollection = true, Options = ConfigurationPropertyOptions.IsDefaultCollection)]
14-
protected ProviderSettingsCollection Handlers
20+
public ProviderSettingsCollection Handlers
1521
{
1622
get { return (ProviderSettingsCollection)base["handlers"]; }
1723
}
1824

25+
/// <summary>
26+
/// Used to initialize a default set of section handlers. (For the appSettings and connectionStrings sections.)
27+
/// </summary>
1928
protected override void InitializeDefault()
2029
{
2130
// This only runs once at the top "parent" level of the config stack. If there is already an

src/packages/ConfigurationBuilders.Base.nupkg/shared/tools/Net471/KeyValueConfigBuildersCommon.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ $keyValueCommonParameters = @(
3232
[ParameterDescription]@{ Name="mode"; IsRequired=$false },
3333
[ParameterDescription]@{ Name="prefix"; IsRequired=$false },
3434
[ParameterDescription]@{ Name="stripPrefix"; IsRequired=$false },
35-
[ParameterDescription]@{ Name="tokenPattern"; IsRequired=$false });
35+
[ParameterDescription]@{ Name="tokenPattern"; IsRequired=$false },
36+
[ParameterDescription]@{ Name="optional"; IsRequired=$false });
3637

3738

3839
function CommonInstall($builderDescription) {

src/packages/ConfigurationBuilders.Json.nupkg/tools/Net471/Install.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ $jsonConfigBuilder = [BuilderDescription]@{
1313
DefaultName="SimpleJson";
1414
AllowedParameters=@( $keyValueCommonParameters +
1515
[ParameterDescription]@{ Name="jsonFile"; IsRequired=$true; DefaultValue="~/App_Data/settings.json" },
16-
[ParameterDescription]@{ Name="jsonMode"; IsRequired=$false },
17-
[ParameterDescription]@{ Name="optional"; IsRequired=$false });
16+
[ParameterDescription]@{ Name="jsonMode"; IsRequired=$false });
1817
}
1918

2019
CommonInstall $jsonConfigBuilder

src/packages/ConfigurationBuilders.KeyPerFile.nupkg/tools/Net471/Install.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ $keyPerFileConfigBuilder = [BuilderDescription]@{
1414
AllowedParameters=@( $keyValueCommonParameters +
1515
[ParameterDescription]@{ Name="directoryPath"; IsRequired=$true; DefaultValue="[PathToSourceDirectory]" },
1616
[ParameterDescription]@{ Name="keyDelimiter"; IsRequired=$false },
17-
[ParameterDescription]@{ Name="ignorePrefix"; IsRequired=$false },
18-
[ParameterDescription]@{ Name="optional"; IsRequired=$false });
17+
[ParameterDescription]@{ Name="ignorePrefix"; IsRequired=$false });
1918
}
2019

2120
CommonInstall $keyPerFileConfigBuilder

src/packages/ConfigurationBuilders.UserSecrets.nupkg/tools/Net471/Install.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ $secretsConfigBuilder = [BuilderDescription]@{
1414
DefaultName="Secrets";
1515
AllowedParameters=@( $keyValueCommonParameters +
1616
[ParameterDescription]@{ Name="userSecretsId"; IsRequired=$false; DefaultValue=$userSecretsId },
17-
[ParameterDescription]@{ Name="userSecretsFile"; IsRequired=$false },
18-
[ParameterDescription]@{ Name="optional"; IsRequired=$false });
17+
[ParameterDescription]@{ Name="userSecretsFile"; IsRequired=$false });
1918
}
2019

2120
CommonInstall $secretsConfigBuilder

tools/MicrosoftConfigurationBuilders.settings.targets

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,23 @@
2424
Update package and file without touching assembly, except for major releases.
2525
-->
2626
<BuildQuality Condition="'$(BuildQuality)' == ''">preview</BuildQuality>
27+
<VersionStartYear Condition="'$(VersionStartYear)' == ''">2019</VersionStartYear>
2728
<VersionMajor>2</VersionMajor>
2829
<VersionMinor>0</VersionMinor>
2930
<VersionRevision>0</VersionRevision>
3031
<VersionRelease>0</VersionRelease>
31-
<VersionRelease Condition="'$(BuildQuality)' != 'rtm'">$(VersionRelease)-$(BuildQuality)</VersionRelease>
32-
<VersionStartYear Condition="'$(VersionStartYear)' == ''">2019</VersionStartYear>
32+
<VersionBuild Condition="'$(VersionBuild)' == '' OR '$(VersionBuild)' == '0'">$([MSBuild]::Add(1, $([MSBuild]::Subtract($([System.DateTime]::Now.Year), $(VersionStartYear)))))$([System.DateTime]::Now.ToString("MMdd"))</VersionBuild>
3333
</PropertyGroup>
3434

3535
<PropertyGroup Label="NuGet package dependencies">
3636
<NuGetPackageVersion>$(VersionMajor).$(VersionMinor).$(VersionRelease)</NuGetPackageVersion>
3737
<NuGetPackageBaseDependencyVersion>$(VersionMajor).$(VersionMinor).$(VersionRelease)</NuGetPackageBaseDependencyVersion>
3838
</PropertyGroup>
3939

40-
<PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.nuproj'">
41-
<NuGetPackageVersion Condition="'$(UpdateNightlyPackages)' == 'true'">$(NuGetPackageVersion)-b$(VersionBuild)</NuGetPackageVersion>
40+
<PropertyGroup Label="Prerelease version adjustments" Condition="'$(BuildQuality)' != 'rtm'">
41+
<VersionRelease>$(VersionRelease)-$(BuildQuality)</VersionRelease>
42+
<NuGetPackageVersion>$(VersionMajor).$(VersionMinor).$(VersionRelease)$(VersionBuild)</NuGetPackageVersion>
43+
<NuGetPackageBaseDependencyVersion>$(VersionMajor).$(VersionMinor).$(VersionRelease)$(VersionBuild)</NuGetPackageBaseDependencyVersion>
4244
</PropertyGroup>
4345

4446
<!-- Default properties -->

0 commit comments

Comments
 (0)