Skip to content

Commit d40c0e7

Browse files
ExMAnatoliy Koperin
authored andcommitted
migrate to netstandard2.0
1 parent 106d212 commit d40c0e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+877
-2567
lines changed

.config/dotnet-tools.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"paket": {
6+
"version": "5.242.2",
7+
"commands": [
8+
"paket"
9+
]
10+
}
11+
}
12+
}

.paket/Paket.Restore.targets

Lines changed: 290 additions & 39 deletions
Large diffs are not rendered by default.

Demo/Additional.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<additionalConfig f="InAppDirectory"/>
4+
</configuration>

Demo/App.config

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<ExtConfigure>
4+
<MyXmlCfg AttrField="attr field text">
5+
<ElemField>elem field text</ElemField>
6+
</MyXmlCfg>
7+
<IncludeFile Path="testConfig1.xml" Search="All" Include="First" Required="true"/>
8+
<IncludeXmlFile Path='Additional.config' Search='Exact' Include='First' Required='true'/>
9+
</ExtConfigure>
10+
</configuration>

Demo/Demo.csproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFrameworks>net472;netcoreapp2.2</TargetFrameworks>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<ProjectReference Include="..\NConfiguration\NConfiguration.csproj" />
9+
</ItemGroup>
10+
<ItemGroup>
11+
<None Update="NLog.config">
12+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
13+
</None>
14+
<None Update="testConfig1.xml">
15+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
16+
</None>
17+
<None Update="Additional.config">
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
</None>
20+
</ItemGroup>
21+
<Import Project="..\.paket\Paket.Restore.targets" />
22+
</Project>

Demo/MyXmlConfig.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace Demo
4+
{
5+
[DataContract(Name = "MyXmlCfg")]
6+
public class MyXmlConfig
7+
{
8+
[DataMember]
9+
public string AttrField = "default";
10+
11+
[DataMember]
12+
public string ElemField = null;
13+
}
14+
}
15+

Demo/NLog.config

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<nlog
3+
xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
6+
<targets async="true">
7+
<target name="Console" type="Console" layout="${longdate}, Th:${threadid}, ${level}, ${logger}, ${message}" />
8+
</targets>
9+
10+
<rules>
11+
<logger name="*" writeTo="Console" minlevel="Trace" />
12+
</rules>
13+
</nlog>

Demo/Program.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Linq;
5+
using System.Reflection;
6+
using NConfiguration;
7+
using NConfiguration.Joining;
8+
using NConfiguration.Monitoring;
9+
using NConfiguration.Xml;
10+
using NLog;
11+
12+
namespace Demo
13+
{
14+
class Program
15+
{
16+
static void Main(string[] args)
17+
{
18+
var path = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location).FilePath;
19+
20+
var loader = new SettingsLoader();
21+
loader.XmlFileByExtension().FindingSettings += onFindingSettings;
22+
loader.XmlFileBySection().FindingSettings += onFindingSettings;
23+
loader.Loaded += (s, e) => _log.Info("Loaded: {0} ({1})", e.Settings.GetType(), e.Settings.Identity);
24+
25+
var systemSettings = new XmlFileSettings(path, "ExtConfigure");
26+
27+
systemSettings.ToAppSettings();
28+
29+
var loaded = loader.LoadSettings(systemSettings);
30+
monitoringFirstFileChange(loaded.Sources);
31+
32+
var appSettings = loaded.Joined.ToAppSettings();
33+
34+
var cfg = appSettings.First<MyXmlConfig>();
35+
36+
Console.WriteLine("AttrField: {0}", cfg.AttrField);
37+
Console.WriteLine("ElemField: {0}", cfg.ElemField);
38+
Console.WriteLine("Press any key...");
39+
Console.ReadKey();
40+
}
41+
42+
private static void onFindingSettings(object sender, FindingSettingsArgs args)
43+
{
44+
var sourceIdentity = args.Source as IIdentifiedSource;
45+
_log.Debug("Find settings '{0}' in directory: '{1}' (customer: {2})",
46+
args.IncludeFile.Path,
47+
args.SearchPath,
48+
sourceIdentity == null ? "unknown" : sourceIdentity.Identity);
49+
}
50+
51+
private static void monitoringFirstFileChange(IEnumerable<IIdentifiedSource> sources)
52+
{
53+
var fileCheckers = FileChecker.TryCreate(sources).ToArray();
54+
_log.Info("Setup monitoring for {0} files...", fileCheckers.Length);
55+
var fCh = new FirstChange(fileCheckers);
56+
fCh.Changed += (s, e) =>
57+
{
58+
foreach (var fileChecker in fileCheckers)
59+
fileChecker.Dispose();
60+
61+
_log.Info("Config files is changed.");
62+
};
63+
}
64+
65+
private static readonly Logger _log = LogManager.GetCurrentClassLogger();
66+
}
67+
}

Demo/paket.references

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
System.Configuration.ConfigurationManager
2+
NLog

Demo/testConfig1.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<Config>
3+
<WatchFile Mode="Auto" />
4+
<MyXmlCfg AttrField="attr field text">
5+
<ElemField>elem field text</ElemField>
6+
</MyXmlCfg>
7+
<MyCfg2 AttrField="2" />
8+
</Config>

0 commit comments

Comments
 (0)