forked from neo-project/neo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.cs
75 lines (66 loc) · 2.77 KB
/
Settings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (C) 2015-2024 The Neo Project.
//
// Settings.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
using Akka.Util.Internal;
using Microsoft.Extensions.Configuration;
using System;
using System.Linq;
namespace Neo.Plugins.OracleService
{
class HttpsSettings
{
public TimeSpan Timeout { get; }
public HttpsSettings(IConfigurationSection section)
{
Timeout = TimeSpan.FromMilliseconds(section.GetValue("Timeout", 5000));
}
}
class NeoFSSettings
{
public string EndPoint { get; }
public TimeSpan Timeout { get; }
public NeoFSSettings(IConfigurationSection section)
{
EndPoint = section.GetValue("EndPoint", "127.0.0.1:8080");
Timeout = TimeSpan.FromMilliseconds(section.GetValue("Timeout", 15000));
}
}
class Settings : PluginSettings
{
public uint Network { get; }
public Uri[] Nodes { get; }
public TimeSpan MaxTaskTimeout { get; }
public TimeSpan MaxOracleTimeout { get; }
public bool AllowPrivateHost { get; }
public string[] AllowedContentTypes { get; }
public HttpsSettings Https { get; }
public NeoFSSettings NeoFS { get; }
public bool AutoStart { get; }
public static Settings Default { get; private set; }
private Settings(IConfigurationSection section) : base(section)
{
Network = section.GetValue("Network", 5195086u);
Nodes = section.GetSection("Nodes").GetChildren().Select(p => new Uri(p.Get<string>(), UriKind.Absolute)).ToArray();
MaxTaskTimeout = TimeSpan.FromMilliseconds(section.GetValue("MaxTaskTimeout", 432000000));
MaxOracleTimeout = TimeSpan.FromMilliseconds(section.GetValue("MaxOracleTimeout", 15000));
AllowPrivateHost = section.GetValue("AllowPrivateHost", false);
AllowedContentTypes = section.GetSection("AllowedContentTypes").GetChildren().Select(p => p.Get<string>()).ToArray();
if (AllowedContentTypes.Count() == 0)
AllowedContentTypes = AllowedContentTypes.Concat("application/json").ToArray();
Https = new HttpsSettings(section.GetSection("Https"));
NeoFS = new NeoFSSettings(section.GetSection("NeoFS"));
AutoStart = section.GetValue("AutoStart", false);
}
public static void Load(IConfigurationSection section)
{
Default = new Settings(section);
}
}
}